Skip to content

Commit

Permalink
refactor: natspec + interfaces
Browse files Browse the repository at this point in the history
docs: `RegistryCoordinator` natspec

chore: forge fmt

refactor: named mapping params

docs: natspec `BLSApkRegistry`

docs: natspec `BLSApkRegistry`

docs: natspec `BLSApkRegistry`

refactor: interface structure

refactor: separate `BLSSignatureChecker` storage

refactor: rename -> `IECDSAStakeRegistry`

docs: natspec

docs: natspec `ECDSAStakeRegistry`

docs: natspec `EjectionManager` + separate storage

docs: natspec

docs: natspec `IndexRegistry`

refactor: remove `IRegistry`

chore: forge fmt
  • Loading branch information
0xClandestine committed Jan 24, 2025
1 parent d2bfd57 commit 8d42bef
Show file tree
Hide file tree
Showing 45 changed files with 2,419 additions and 1,869 deletions.
6 changes: 3 additions & 3 deletions docs/RegistryCoordinator.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ These methods allow operators to register for/deregister from one or more quorum
function registerOperator(
bytes calldata quorumNumbers,
string calldata socket,
IBLSApkRegistry.PubkeyRegistrationParams calldata params,
IBLSApkRegistryTypes.PubkeyRegistrationParams calldata params,
SignatureWithSaltAndExpiry memory operatorSignature
)
external
Expand Down Expand Up @@ -88,7 +88,7 @@ If the Operator was not currently registered for any quorums, this method will r
function registerOperatorWithChurn(
bytes calldata quorumNumbers,
string calldata socket,
IBLSApkRegistry.PubkeyRegistrationParams calldata params,
IBLSApkRegistryTypes.PubkeyRegistrationParams calldata params,
OperatorKickParam[] calldata operatorKickParams,
SignatureWithSaltAndExpiry memory churnApproverSignature,
SignatureWithSaltAndExpiry memory operatorSignature
Expand Down Expand Up @@ -256,7 +256,7 @@ These methods are used by the Owner to configure the `RegistryCoordinator`:
function createQuorum(
OperatorSetParam memory operatorSetParams,
uint96 minimumStake,
IStakeRegistry.StrategyParams[] memory strategyParams
IStakeRegistryTypes.StrategyParams[] memory strategyParams
)
external
virtual
Expand Down
4 changes: 2 additions & 2 deletions docs/storage-report/StakeRegistry.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
|----------------------------------+---------------------------------------------------------------------------+------+--------+-------+-------------------------------------|
| operatorStakeHistory | mapping(bytes32 => mapping(uint8 => struct IStakeRegistry.StakeUpdate[])) | 2 | 0 | 32 | src/StakeRegistry.sol:StakeRegistry |
|----------------------------------+---------------------------------------------------------------------------+------+--------+-------+-------------------------------------|
| strategyParams | mapping(uint8 => struct IStakeRegistry.StrategyParams[]) | 3 | 0 | 32 | src/StakeRegistry.sol:StakeRegistry |
| strategyParams | mapping(uint8 => struct IStakeRegistryTypes.StrategyParams[]) | 3 | 0 | 32 | src/StakeRegistry.sol:StakeRegistry |
|----------------------------------+---------------------------------------------------------------------------+------+--------+-------+-------------------------------------|
| strategiesPerQuorum | mapping(uint8 => contract IStrategy[]) | 4 | 0 | 32 | src/StakeRegistry.sol:StakeRegistry |
|----------------------------------+---------------------------------------------------------------------------+------+--------+-------+-------------------------------------|
| stakeTypePerQuorum | mapping(uint8 => enum StakeType) | 5 | 0 | 32 | src/StakeRegistry.sol:StakeRegistry |
| stakeTypePerQuorum | mapping(uint8 => enum IStakeRegistryTypes.StakeType) | 5 | 0 | 32 | src/StakeRegistry.sol:StakeRegistry |
|----------------------------------+---------------------------------------------------------------------------+------+--------+-------+-------------------------------------|
| slashableStakeLookAheadPerQuorum | mapping(uint8 => uint32) | 6 | 0 | 32 | src/StakeRegistry.sol:StakeRegistry |
|----------------------------------+---------------------------------------------------------------------------+------+--------+-------+-------------------------------------|
Expand Down
4 changes: 2 additions & 2 deletions docs/storage-report/StakeRegistryStorage.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
|----------------------------------+---------------------------------------------------------------------------+------+--------+-------+---------------------------------------------------|
| operatorStakeHistory | mapping(bytes32 => mapping(uint8 => struct IStakeRegistry.StakeUpdate[])) | 2 | 0 | 32 | src/StakeRegistryStorage.sol:StakeRegistryStorage |
|----------------------------------+---------------------------------------------------------------------------+------+--------+-------+---------------------------------------------------|
| strategyParams | mapping(uint8 => struct IStakeRegistry.StrategyParams[]) | 3 | 0 | 32 | src/StakeRegistryStorage.sol:StakeRegistryStorage |
| strategyParams | mapping(uint8 => struct IStakeRegistryTypes.StrategyParams[]) | 3 | 0 | 32 | src/StakeRegistryStorage.sol:StakeRegistryStorage |
|----------------------------------+---------------------------------------------------------------------------+------+--------+-------+---------------------------------------------------|
| strategiesPerQuorum | mapping(uint8 => contract IStrategy[]) | 4 | 0 | 32 | src/StakeRegistryStorage.sol:StakeRegistryStorage |
|----------------------------------+---------------------------------------------------------------------------+------+--------+-------+---------------------------------------------------|
| stakeTypePerQuorum | mapping(uint8 => enum StakeType) | 5 | 0 | 32 | src/StakeRegistryStorage.sol:StakeRegistryStorage |
| stakeTypePerQuorum | mapping(uint8 => enum IStakeRegistryTypes.StakeType) | 5 | 0 | 32 | src/StakeRegistryStorage.sol:StakeRegistryStorage |
|----------------------------------+---------------------------------------------------------------------------+------+--------+-------+---------------------------------------------------|
| slashableStakeLookAheadPerQuorum | mapping(uint8 => uint32) | 6 | 0 | 32 | src/StakeRegistryStorage.sol:StakeRegistryStorage |
|----------------------------------+---------------------------------------------------------------------------+------+--------+-------+---------------------------------------------------|
Expand Down
73 changes: 16 additions & 57 deletions src/BLSApkRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.27;

import {BLSApkRegistryStorage} from "./BLSApkRegistryStorage.sol";
import {BLSApkRegistryStorage, IBLSApkRegistry} from "./BLSApkRegistryStorage.sol";

import {IRegistryCoordinator} from "./interfaces/IRegistryCoordinator.sol";

Expand All @@ -27,17 +27,7 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
*
*/

/**
* @notice Registers the `operator`'s pubkey for the specified `quorumNumbers`.
* @param operator The address of the operator to register.
* @param quorumNumbers The quorum numbers the operator is registering for, where each byte is an 8 bit integer quorumNumber.
* @dev access restricted to the RegistryCoordinator
* @dev Preconditions (these are assumed, not validated in this contract):
* 1) `quorumNumbers` has no duplicates
* 2) `quorumNumbers.length` != 0
* 3) `quorumNumbers` is ordered in ascending order
* 4) the operator is not already registered
*/
/// @inheritdoc IBLSApkRegistry
function registerOperator(
address operator,
bytes memory quorumNumbers
Expand All @@ -49,21 +39,10 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
_processQuorumApkUpdate(quorumNumbers, pubkey);

// Return pubkeyHash, which will become the operator's unique id
emit OperatorAddedToQuorums(operator, getOperatorId(operator), quorumNumbers);
emit OperatorAddedToQuorums(operator, operatorToPubkeyHash[operator], quorumNumbers);
}

/**
* @notice Deregisters the `operator`'s pubkey for the specified `quorumNumbers`.
* @param operator The address of the operator to deregister.
* @param quorumNumbers The quorum numbers the operator is deregistering from, where each byte is an 8 bit integer quorumNumber.
* @dev access restricted to the RegistryCoordinator
* @dev Preconditions (these are assumed, not validated in this contract):
* 1) `quorumNumbers` has no duplicates
* 2) `quorumNumbers.length` != 0
* 3) `quorumNumbers` is ordered in ascending order
* 4) the operator is not already deregistered
* 5) `quorumNumbers` is a subset of the quorumNumbers that the operator is registered for
*/
/// @inheritdoc IBLSApkRegistry
function deregisterOperator(
address operator,
bytes memory quorumNumbers
Expand All @@ -73,13 +52,10 @@ contract BLSApkRegistry is BLSApkRegistryStorage {

// Update each quorum's aggregate pubkey
_processQuorumApkUpdate(quorumNumbers, pubkey.negate());
emit OperatorRemovedFromQuorums(operator, getOperatorId(operator), quorumNumbers);
emit OperatorRemovedFromQuorums(operator, operatorToPubkeyHash[operator], quorumNumbers);
}

/**
* @notice Initializes a new quorum by pushing its first apk update
* @param quorumNumber The number of the new quorum
*/
/// @inheritdoc IBLSApkRegistry
function initializeQuorum(
uint8 quorumNumber
) public virtual onlyRegistryCoordinator {
Expand All @@ -94,12 +70,7 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
);
}

/**
* @notice Called by the RegistryCoordinator register an operator as the owner of a BLS public key.
* @param operator is the operator for whom the key is being registered
* @param params contains the G1 & G2 public keys of the operator, and a signature proving their ownership
* @param pubkeyRegistrationMessageHash is a hash that the operator must sign to prove key ownership
*/
/// @inheritdoc IBLSApkRegistry
function registerBLSPublicKey(
address operator,
PubkeyRegistrationParams calldata params,
Expand Down Expand Up @@ -190,10 +161,8 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
* VIEW FUNCTIONS
*
*/
/**
* @notice Returns the pubkey and pubkey hash of an operator
* @dev Reverts if the operator has not registered a valid pubkey
*/

/// @inheritdoc IBLSApkRegistry
function getRegisteredPubkey(
address operator
) public view returns (BN254.G1Point memory, bytes32) {
Expand All @@ -205,10 +174,7 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
return (pubkey, pubkeyHash);
}

/**
* @notice Returns the indices of the quorumApks index at `blockNumber` for the provided `quorumNumbers`
* @dev Returns the current indices if `blockNumber >= block.number`
*/
/// @inheritdoc IBLSApkRegistry
function getApkIndicesAtBlockNumber(
bytes calldata quorumNumbers,
uint256 blockNumber
Expand Down Expand Up @@ -239,28 +205,22 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
return indices;
}

/// @notice Returns the current APK for the provided `quorumNumber `
/// @inheritdoc IBLSApkRegistry
function getApk(
uint8 quorumNumber
) external view returns (BN254.G1Point memory) {
return currentApk[quorumNumber];
}

/// @notice Returns the `ApkUpdate` struct at `index` in the list of APK updates for the `quorumNumber`
/// @inheritdoc IBLSApkRegistry
function getApkUpdateAtIndex(
uint8 quorumNumber,
uint256 index
) external view returns (ApkUpdate memory) {
return apkHistory[quorumNumber][index];
}

/**
* @notice get hash of the apk of `quorumNumber` at `blockNumber` using the provided `index`;
* called by checkSignatures in BLSSignatureChecker.sol.
* @param quorumNumber is the quorum whose ApkHash is being retrieved
* @param blockNumber is the number of the block for which the latest ApkHash will be retrieved
* @param index is the index of the apkUpdate being retrieved from the list of quorum apkUpdates in storage
*/
/// @inheritdoc IBLSApkRegistry
function getApkHashAtBlockNumberAndIndex(
uint8 quorumNumber,
uint32 blockNumber,
Expand All @@ -283,22 +243,21 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
return quorumApkUpdate.apkHash;
}

/// @notice Returns the length of ApkUpdates for the provided `quorumNumber`
/// @inheritdoc IBLSApkRegistry
function getApkHistoryLength(
uint8 quorumNumber
) external view returns (uint32) {
return uint32(apkHistory[quorumNumber].length);
}

/// @notice Returns the operator address for the given `pubkeyHash`
/// @inheritdoc IBLSApkRegistry
function getOperatorFromPubkeyHash(
bytes32 pubkeyHash
) public view returns (address) {
return pubkeyHashToOperator[pubkeyHash];
}

/// @notice returns the ID used to identify the `operator` within this AVS
/// @dev Returns zero in the event that the `operator` has never registered for the AVS
/// @inheritdoc IBLSApkRegistry
function getOperatorId(
address operator
) public view returns (bytes32) {
Expand Down
36 changes: 20 additions & 16 deletions src/BLSApkRegistryStorage.sol
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.27;

import {IBLSApkRegistry} from "./interfaces/IBLSApkRegistry.sol";
import {IBLSApkRegistry, IBLSApkRegistryTypes} from "./interfaces/IBLSApkRegistry.sol";
import {IRegistryCoordinator} from "./interfaces/IRegistryCoordinator.sol";

import {Initializable} from "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";

import {BN254} from "./libraries/BN254.sol";

abstract contract BLSApkRegistryStorage is Initializable, IBLSApkRegistry {
/// @notice the hash of the zero pubkey aka BN254.G1Point(0,0)
/// @dev Returns the hash of the zero pubkey aka BN254.G1Point(0,0)
bytes32 internal constant ZERO_PK_HASH =
hex"ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5";

/// @notice the registry coordinator contract
/// @inheritdoc IBLSApkRegistry
address public immutable registryCoordinator;

// storage for individual pubkeys
/// @notice maps operator address to pubkey hash
mapping(address => bytes32) public operatorToPubkeyHash;
/// @notice maps pubkey hash to operator address
mapping(bytes32 => address) public pubkeyHashToOperator;
/// @notice maps operator address to pubkeyG1
mapping(address => BN254.G1Point) public operatorToPubkey;
/// INDIVIDUAL PUBLIC KEY STORAGE

// storage for aggregate pubkeys (APKs)
/// @notice maps quorumNumber => historical aggregate pubkey updates
mapping(uint8 => ApkUpdate[]) public apkHistory;
/// @notice maps quorumNumber => current aggregate pubkey of quorum
mapping(uint8 => BN254.G1Point) public currentApk;
/// @inheritdoc IBLSApkRegistry
mapping(address operator => bytes32 operatorId) public operatorToPubkeyHash;

/// @inheritdoc IBLSApkRegistry
mapping(bytes32 pubkeyHash => address operator) public pubkeyHashToOperator;

/// @inheritdoc IBLSApkRegistry
mapping(address operator => BN254.G1Point pubkeyG1) public operatorToPubkey;

/// AGGREGATE PUBLIC KEY STORAGE

/// @inheritdoc IBLSApkRegistry
mapping(uint8 quorumNumber => IBLSApkRegistryTypes.ApkUpdate[]) public apkHistory;

/// @inheritdoc IBLSApkRegistry
mapping(uint8 quorumNumber => BN254.G1Point) public currentApk;

constructor(
IRegistryCoordinator _registryCoordinator
Expand All @@ -38,6 +43,5 @@ abstract contract BLSApkRegistryStorage is Initializable, IBLSApkRegistry {
_disableInitializers();
}

// storage gap for upgradeability
uint256[45] private __GAP;
}
Loading

0 comments on commit 8d42bef

Please sign in to comment.