Skip to content

Commit

Permalink
PubkeyCompendium msgHash update
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0aa0 committed Oct 10, 2023
1 parent b74190f commit eeca1d9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
6 changes: 6 additions & 0 deletions src/contracts/interfaces/IBLSPublicKeyCompendium.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ interface IBLSPublicKeyCompendium {
* @param pubkeyG2 is the corresponding G2 public key of the operator
*/
function registerBLSPublicKey(BN254.G1Point memory signedMessageHash, BN254.G1Point memory pubkeyG1, BN254.G2Point memory pubkeyG2) external;

/**
* @notice Returns the message hash that an operator must sign to register their BLS public key.
* @param operator is the address of the operator registering their BLS public key
*/
function getMessageHash(address operator) external view returns (BN254.G1Point memory);
}
40 changes: 24 additions & 16 deletions src/contracts/middleware/BLSPublicKeyCompendium.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ contract BLSPublicKeyCompendium is IBLSPublicKeyCompendium {
* @param pubkeyG2 is the corresponding G2 public key of the operator
*/
function registerBLSPublicKey(BN254.G1Point memory signedMessageHash, BN254.G1Point memory pubkeyG1, BN254.G2Point memory pubkeyG2) external {
bytes32 pubkeyHash = BN254.hashG1Point(pubkeyG1);
require(
operatorToPubkeyHash[msg.sender] == bytes32(0),
"BLSPublicKeyCompendium.registerBLSPublicKey: operator already registered pubkey"
);
require(
pubkeyHashToOperator[pubkeyHash] == address(0),
"BLSPublicKeyCompendium.registerBLSPublicKey: public key already registered"
);

// H(m)
BN254.G1Point memory messageHash = BN254.hashToG1(keccak256(abi.encodePacked(
msg.sender,
block.chainid,
"EigenLayer_BN254_Pubkey_Registration"
)));
BN254.G1Point memory messageHash = getMessageHash(msg.sender);

// gamma = h(sigma, P, P', H(m))
uint256 gamma = uint256(keccak256(abi.encodePacked(
Expand All @@ -51,20 +57,22 @@ contract BLSPublicKeyCompendium is IBLSPublicKeyCompendium {
pubkeyG2
), "BLSPublicKeyCompendium.registerBLSPublicKey: G1 and G2 private key do not match");

bytes32 pubkeyHash = BN254.hashG1Point(pubkeyG1);

require(
operatorToPubkeyHash[msg.sender] == bytes32(0),
"BLSPublicKeyCompendium.registerBLSPublicKey: operator already registered pubkey"
);
require(
pubkeyHashToOperator[pubkeyHash] == address(0),
"BLSPublicKeyCompendium.registerBLSPublicKey: public key already registered"
);

operatorToPubkeyHash[msg.sender] = pubkeyHash;
pubkeyHashToOperator[pubkeyHash] = msg.sender;

emit NewPubkeyRegistration(msg.sender, pubkeyG1, pubkeyG2);
}

/**
* @notice Returns the message hash that an operator must sign to register their BLS public key.
* @param operator is the address of the operator registering their BLS public key
*/
function getMessageHash(address operator) public view returns (BN254.G1Point memory) {
return BN254.hashToG1(keccak256(abi.encodePacked(
operator,
address(this),
block.chainid,
"EigenLayer_BN254_Pubkey_Registration"
)));
}
}
2 changes: 1 addition & 1 deletion src/test/ffi/BLSPubKeyCompendiumFFI.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract BLSPublicKeyCompendiumFFITests is G2Operations {
}

function _signMessage(address signer) internal view returns(BN254.G1Point memory) {
BN254.G1Point memory messageHash = BN254.hashToG1(keccak256(abi.encodePacked(signer, block.chainid, "EigenLayer_BN254_Pubkey_Registration")));
BN254.G1Point memory messageHash = compendium.getMessageHash(signer);
return BN254.scalar_mul(messageHash, privKey);
}
}
2 changes: 2 additions & 0 deletions src/test/mocks/BLSPublicKeyCompendiumMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ contract BLSPublicKeyCompendiumMock is IBLSPublicKeyCompendium, DSTest {
operatorToPubkeyHash[account] = pubkeyHash;
pubkeyHashToOperator[pubkeyHash] = account;
}

function getMessageHash(address operator) external view returns (BN254.G1Point memory) {}
}
2 changes: 1 addition & 1 deletion src/test/unit/BLSPublicKeyCompendiumUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ contract BLSPublicKeyCompendiumUnitTests is Test {
}

function _signMessage(address signer) internal view returns(BN254.G1Point memory) {
BN254.G1Point memory messageHash = BN254.hashToG1(keccak256(abi.encodePacked(signer, block.chainid, "EigenLayer_BN254_Pubkey_Registration")));
BN254.G1Point memory messageHash = compendium.getMessageHash(signer);
return BN254.scalar_mul(messageHash, privKey);
}

Expand Down

0 comments on commit eeca1d9

Please sign in to comment.