Skip to content

BLS Library

The BLS (Boneh–Lynn–Shacham) library offers a simple way to integrate BLS signature schemes into your DSS. BLS allows for efficient signature aggregation and multi-signature verification. By enabling the aggregation of multiple signatures into a single compact signature, the library reduces on-chain data size and computational overhead, making it ideal for use in threshold signatures and consensus algorithms.

Note: 1. This library was created with reference to the article Optimized BLS multisignatures on EVM
2. This library operates on the curve BN254

Import the BlsSdk library

To get started import the BlsSdk library in your solidity contract file.

import {BlsSdk} from "./BlsSdk.sol";

Initiate storage/registry for BLS library

The library provides a predefined struct that should be initiated in your DSS contract. This struct holds the relevant data for managing operators and their public keys.

contract MyContract {
    using BlsSdk for BlsSdk.State;
 
    BlsSdk.State private blsState;
 
    // Other contract logic...
}

Register an operator

Operators can be registered using the operatorRegistration function. This function takes in the operator's address and extraData, which includes the G1 and G2 public keys, message hash, and signature. The operator's public key is then aggregated into a master public key for all operators.

function registerOperator(address operator, bytes memory extraData) public {
    blsState.operatorRegistration(operator, extraData);
}

The extraData param is decoded as follows:

(BN254.G1Point memory g1Pubkey, BN254.G2Point memory g2Pubkey, bytes32 msgHash, BN254.G1Point memory sign) =
            abi.decode(extraData, (BN254.G1Point, BN254.G2Point, bytes32, BN254.G1Point));

The SDK has provided a binding in our offchain sdk to convert data in the format that is required for extraData

Unregister operator

If an operator needs to be removed, you can call the operatorUnregistration function. This will remove the operator’s public key from the aggregated key and clean up the state.

function unregisterOperator(address operator) public {
    blsState.operatorUnregistration(operator);
}
 

Verify a signature

The verifySignature function allows you to verify the BLS signature of a message. This ensures that the message was signed with a valid key.

function verifyOperatorSignature(
    BN254.G1Point memory g1Key,
    BN254.G2Point memory g2Key,
    BN254.G1Point memory sign,
    bytes32 msgHash
) public view {
    state.verifySignature(g1Key, g2Key, sign, msgHash);
}

View registered operators g1 keys

You can retrieve the list of all registered operators’ g1 public keys by calling the getAllOperators function.

function getAllOperators() public view returns (BN254.G1Point[] memory) {
    return state.allOperatorsG1();
}

Check if operator is registered

To check if a specific operator is registered, use the isOperatorRegistered function.

function checkOperator(address operator) public view returns (bool) {
    return state.isOperatorRegistered(operator);
}