Skip to content

Commit

Permalink
added _operatorIDToBN254Pubkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
Soubhik Deb committed Jul 27, 2023
1 parent 5fc6439 commit f72f104
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/contracts/interfaces/IBLSPublicKeyCompendium.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/contracts/middleware/BLSOperatorStateRetriever.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -16,6 +17,7 @@ contract BLSOperatorStateRetriever {
struct Operator {
bytes32 operatorId;
uint96 stake;
IBLSPublicKeyCompendium.BN254Pubkeys bn254pubkeys;
}

struct CheckSignaturesIndices {
Expand Down Expand Up @@ -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)
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/contracts/middleware/BLSPubkeyRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
10 changes: 10 additions & 0 deletions src/contracts/middleware/BLSPublicKeyCompendium.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity =0.8.12;

import "../interfaces/IBLSPublicKeyCompendium.sol";

import "../libraries/BN254.sol";

/**
Expand All @@ -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`.
Expand Down Expand Up @@ -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];
}

}
5 changes: 5 additions & 0 deletions src/test/mocks/BLSPublicKeyCompendiumMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

0 comments on commit f72f104

Please sign in to comment.