From f72f1041fc6a04b63116af8f8d6d3164be6a9ba7 Mon Sep 17 00:00:00 2001 From: Soubhik Deb Date: Thu, 27 Jul 2023 11:54:00 -0700 Subject: [PATCH] added _operatorIDToBN254Pubkeys --- .../interfaces/IBLSPublicKeyCompendium.sol | 14 ++++++++++++++ .../middleware/BLSOperatorStateRetriever.sol | 7 +++++-- src/contracts/middleware/BLSPubkeyRegistry.sol | 2 ++ .../middleware/BLSPublicKeyCompendium.sol | 10 ++++++++++ src/test/mocks/BLSPublicKeyCompendiumMock.sol | 5 +++++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/contracts/interfaces/IBLSPublicKeyCompendium.sol b/src/contracts/interfaces/IBLSPublicKeyCompendium.sol index 3d692d7b9..e7fab622b 100644 --- a/src/contracts/interfaces/IBLSPublicKeyCompendium.sol +++ b/src/contracts/interfaces/IBLSPublicKeyCompendium.sol @@ -9,6 +9,15 @@ import "../libraries/BN254.sol"; * @notice Terms of Service: https://docs.eigenlayer.xyz/overview/terms-of-service */ interface IBLSPublicKeyCompendium { + + // DATA STRUCTURES + struct BN254Pubkeys { + // G1 public key over BN254 curve for the operator + BN254.G1Point pubkeyG1; + // G2 public key over BN254 curve for the operator + // BN254.G2Point pubkeyG2; + } + /** * @notice mapping from operator address to pubkey hash. * Returns *zero* if the `operator` has never registered, and otherwise returns the hash of the public key of the operator. @@ -22,6 +31,11 @@ interface IBLSPublicKeyCompendium { */ function pubkeyHashToOperator(bytes32 pubkeyHash) external view returns (address); + /** + * @notice mapping from pubkey hash to BN254 pubkeys. + **/ + function getBN254PubkeysFromOperatorID(bytes32 operatorID) external view returns (BN254Pubkeys memory); + /** * @notice Called by an operator to register themselves as the owner of a BLS public key and reveal their G1 and G2 public key. * @param s is the field element of the operator's Schnorr signature diff --git a/src/contracts/middleware/BLSOperatorStateRetriever.sol b/src/contracts/middleware/BLSOperatorStateRetriever.sol index 36b3001a8..68376c435 100644 --- a/src/contracts/middleware/BLSOperatorStateRetriever.sol +++ b/src/contracts/middleware/BLSOperatorStateRetriever.sol @@ -2,11 +2,12 @@ pragma solidity =0.8.12; import "./BLSRegistryCoordinatorWithIndices.sol"; - +import "../libraries/BN254.sol"; import "../interfaces/IStakeRegistry.sol"; import "../interfaces/IBLSPubkeyRegistry.sol"; import "../interfaces/IIndexRegistry.sol"; import "../interfaces/IBLSRegistryCoordinatorWithIndices.sol"; +import "./BLSPubkeyRegistry.sol"; /** * @title BLSOperatorStateRetriever with view functions that allow to retrieve the state of an AVSs registry system. @@ -16,6 +17,7 @@ contract BLSOperatorStateRetriever { struct Operator { bytes32 operatorId; uint96 stake; + IBLSPublicKeyCompendium.BN254Pubkeys bn254pubkeys; } struct CheckSignaturesIndices { @@ -69,7 +71,8 @@ contract BLSOperatorStateRetriever { bytes32 operatorId = bytes32(operatorIds[j]); operators[i][j] = Operator({ operatorId: operatorId, - stake: stakeRegistry.getStakeForOperatorIdForQuorumAtBlockNumber(operatorId, quorumNumber, blockNumber) + stake: stakeRegistry.getStakeForOperatorIdForQuorumAtBlockNumber(operatorId, quorumNumber, blockNumber), + bn254pubkeys: BLSPubkeyRegistry(address(registryCoordinator.blsPubkeyRegistry())).pubkeyCompendium().getBN254PubkeysFromOperatorID(operatorId) }); } } diff --git a/src/contracts/middleware/BLSPubkeyRegistry.sol b/src/contracts/middleware/BLSPubkeyRegistry.sol index a7df73be0..4ba347f92 100644 --- a/src/contracts/middleware/BLSPubkeyRegistry.sol +++ b/src/contracts/middleware/BLSPubkeyRegistry.sol @@ -6,6 +6,8 @@ import "../interfaces/IBLSPubkeyRegistry.sol"; import "../interfaces/IRegistryCoordinator.sol"; import "../interfaces/IBLSPublicKeyCompendium.sol"; + + import "../libraries/BN254.sol"; import "forge-std/Test.sol"; diff --git a/src/contracts/middleware/BLSPublicKeyCompendium.sol b/src/contracts/middleware/BLSPublicKeyCompendium.sol index aa3fc0883..4c0e6f35e 100644 --- a/src/contracts/middleware/BLSPublicKeyCompendium.sol +++ b/src/contracts/middleware/BLSPublicKeyCompendium.sol @@ -2,6 +2,7 @@ pragma solidity =0.8.12; import "../interfaces/IBLSPublicKeyCompendium.sol"; + import "../libraries/BN254.sol"; /** @@ -17,6 +18,8 @@ contract BLSPublicKeyCompendium is IBLSPublicKeyCompendium { mapping(address => bytes32) public operatorToPubkeyHash; /// @notice mapping from pubkey hash to operator address mapping(bytes32 => address) public pubkeyHashToOperator; + /// @notice mapping from operatorID to pubkey + mapping(bytes32 => BN254Pubkeys) internal _operatorIDToBN254Pubkeys; // EVENTS /// @notice Emitted when `operator` registers with the public key `pk`. @@ -73,7 +76,14 @@ contract BLSPublicKeyCompendium is IBLSPublicKeyCompendium { // store updates operatorToPubkeyHash[msg.sender] = pubkeyHash; pubkeyHashToOperator[pubkeyHash] = msg.sender; + _operatorIDToBN254Pubkeys[pubkeyHash].pubkeyG1 = pubkeyG1; + // _operatorIDToBN254Pubkeys[pubkeyHash].pubkeyG2 = pubkeyG2; emit NewPubkeyRegistration(msg.sender, pubkeyG1, pubkeyG2); } + + function getBN254PubkeysFromOperatorID(bytes32 operatorID) external view returns (BN254Pubkeys memory) { + return _operatorIDToBN254Pubkeys[operatorID]; + } + } diff --git a/src/test/mocks/BLSPublicKeyCompendiumMock.sol b/src/test/mocks/BLSPublicKeyCompendiumMock.sol index e55689741..0bee23d51 100644 --- a/src/test/mocks/BLSPublicKeyCompendiumMock.sol +++ b/src/test/mocks/BLSPublicKeyCompendiumMock.sol @@ -27,6 +27,11 @@ contract BLSPublicKeyCompendiumMock is IBLSPublicKeyCompendium, DSTest { function registerBLSPublicKey(uint256 s, BN254.G1Point memory rPoint, BN254.G1Point memory pubkeyG1, BN254.G2Point memory pubkeyG2) external { } + /** + * @notice mapping from pubkey hash to BN254 pubkeys. + **/ + function getBN254PubkeysFromOperatorID(bytes32 operatorID) external view returns (BN254Pubkeys memory) { + } function registerPublicKey(BN254.G1Point memory pk) external {