Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduces BLS signature verification precompile #52

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

ckartik
Copy link

@ckartik ckartik commented Nov 21, 2024

Introduction of BLS Signature Verification Precompile

This PR introduces a new precompiled contract for BLS signature verification using the BLS12-381 curve. The bls12381SignatureVerification struct enables Ethereum smart contracts to efficiently verify BLS signatures (e.g validate a message was signed by a target public key). This will be useful in the context of ensuring that builders who register have access to the BLS key they sign up with.

Details for usage

  • Gas Cost: Is currently set to 150000 wei.
  • Input Format: The input is a concatenation of three components:
+---------------------+---------------------+-----------------------+
|     Public Key      |       Message       |       Signature       |
|     (48 bytes)      |      (32 bytes)     |       (96 bytes)      |
|      G1 Point       | Hash of the Message |       G2 Point        |
+---------------------+---------------------+-----------------------+

Note: We assume the public key is a point on the G1 curve.

Example Usage: Solidity Contract

The following example demonstrates how to interact with the BLS signature verification precompile via a smartcontract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract BLSVerifier {
    // Precompile address
    address constant BLS_VERIFY = address(0xf0);

    /**
     * @dev Verifies a BLS signature using the precompile
     * @param pubKey The public key (48 bytes G1 point)
     * @param message The message hash (32 bytes)
     * @param signature The signature (96 bytes G2 point)
     * @return success True if verification succeeded
     */
    function verifySignature(
        bytes calldata pubKey,
        bytes32 message,
        bytes calldata signature
    ) public view returns (bool) {
        // Input validation
        require(pubKey.length == 48, "Public key must be 48 bytes");
        require(signature.length == 96, "Signature must be 96 bytes");

        // Concatenate inputs in required format:
        // [pubkey (48 bytes) | message (32 bytes) | signature (96 bytes)]
        bytes memory input = bytes.concat(
            pubKey,
            message,
            signature
        );

        // Call precompile
        (bool success, bytes memory result) = BLS_VERIFY.staticcall(input);
        
        // Check if call was successful
        if (!success) {
            return false;
        }

        // If we got a result back and it's not empty, verification succeeded
        return result.length > 0;
    }
}

The video demo can be seen here

@ckartik ckartik requested review from Mikelle and chrmatt November 21, 2024 13:13
@chrmatt
Copy link
Member

chrmatt commented Nov 21, 2024

If the example use case is just in the PR description, it will get lost when merging. Maybe worth putting this somehwere in a readme?

return params.BlsSignVerifyGas
}

func (c *bls12381SignatureVerification) Run(input []byte) ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify what output format is.

@@ -23,6 +23,7 @@ import (
"fmt"
"math/big"

"github.com/cloudflare/circl/sign/bls"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not available for me. Do they implement actual BLS verifcation on top of precompiles? Is this documented somewhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The precompile is implemented by us. They simply implement BLS signatures.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ckartik ckartik merged commit a9bcf58 into master Nov 25, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants