From 72c96cd85838288df213e603e556a22d6b3eee92 Mon Sep 17 00:00:00 2001 From: wadealexc Date: Wed, 18 Oct 2023 14:50:27 +0000 Subject: [PATCH 1/8] Place functions in external -> internal -> view order, consistent with our other repo --- src/BLSPubkeyRegistry.sol | 142 +++++---- src/BLSPublicKeyCompendium.sol | 8 + src/BLSRegistryCoordinatorWithIndices.sol | 228 +++++++------- src/IndexRegistry.sol | 232 +++++++------- src/StakeRegistry.sol | 352 +++++++++++----------- src/VoteWeigherBase.sol | 112 ++++--- 6 files changed, 566 insertions(+), 508 deletions(-) diff --git a/src/BLSPubkeyRegistry.sol b/src/BLSPubkeyRegistry.sol index b76622bc..bb3eea6b 100644 --- a/src/BLSPubkeyRegistry.sol +++ b/src/BLSPubkeyRegistry.sol @@ -22,6 +22,10 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage { IBLSPublicKeyCompendium _pubkeyCompendium ) BLSPubkeyRegistryStorage(_registryCoordinator, _pubkeyCompendium) {} + /******************************************************************************* + EXTERNAL FUNCTIONS + *******************************************************************************/ + /** * @notice Registers the `operator`'s pubkey for the specified `quorumNumbers`. * @param operator The address of the operator to register. @@ -94,71 +98,9 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage { emit OperatorRemovedFromQuorums(operator, quorumNumbers); } - /** - * @notice Returns the indices of the quorumApks index at `blockNumber` for the provided `quorumNumbers` - * @dev Returns the current indices if `blockNumber >= block.number` - */ - function getApkIndicesForQuorumsAtBlockNumber( - bytes calldata quorumNumbers, - uint256 blockNumber - ) external view returns (uint32[] memory) { - uint32[] memory indices = new uint32[](quorumNumbers.length); - for (uint i = 0; i < quorumNumbers.length; i++) { - uint8 quorumNumber = uint8(quorumNumbers[i]); - uint32 quorumApkUpdatesLength = uint32(quorumApkUpdates[quorumNumber].length); - - if (quorumApkUpdatesLength == 0 || blockNumber < quorumApkUpdates[quorumNumber][0].updateBlockNumber) { - revert( - "BLSPubkeyRegistry.getApkIndicesForQuorumsAtBlockNumber: blockNumber is before the first update" - ); - } - - for (uint32 j = 0; j < quorumApkUpdatesLength; j++) { - if (quorumApkUpdates[quorumNumber][quorumApkUpdatesLength - j - 1].updateBlockNumber <= blockNumber) { - indices[i] = quorumApkUpdatesLength - j - 1; - break; - } - } - } - return indices; - } - - /// @notice Returns the current APK for the provided `quorumNumber ` - function getApkForQuorum(uint8 quorumNumber) external view returns (BN254.G1Point memory) { - return quorumApk[quorumNumber]; - } - - /// @notice Returns the `ApkUpdate` struct at `index` in the list of APK updates for the `quorumNumber` - function getApkUpdateForQuorumByIndex(uint8 quorumNumber, uint256 index) external view returns (ApkUpdate memory) { - return quorumApkUpdates[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 - */ - function getApkHashForQuorumAtBlockNumberFromIndex( - uint8 quorumNumber, - uint32 blockNumber, - uint256 index - ) external view returns (bytes24) { - ApkUpdate memory quorumApkUpdate = quorumApkUpdates[quorumNumber][index]; - _validateApkHashForQuorumAtBlockNumber(quorumApkUpdate, blockNumber); - return quorumApkUpdate.apkHash; - } - - /// @notice Returns the length of ApkUpdates for the provided `quorumNumber` - function getQuorumApkHistoryLength(uint8 quorumNumber) external view returns (uint32) { - return uint32(quorumApkUpdates[quorumNumber].length); - } - - /// @notice Returns the operator address for the given `pubkeyHash` - function getOperatorFromPubkeyHash(bytes32 pubkeyHash) public view returns (address) { - return pubkeyCompendium.pubkeyHashToOperator(pubkeyHash); - } + /******************************************************************************* + INTERNAL FUNCTIONS + *******************************************************************************/ function _processQuorumApkUpdate(bytes memory quorumNumbers, BN254.G1Point memory point) internal { BN254.G1Point memory apkAfterUpdate; @@ -230,4 +172,74 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage { "BLSPubkeyRegistry._validateApkHashForQuorumAtBlockNumber: not latest apk update" ); } + + /******************************************************************************* + VIEW FUNCTIONS + *******************************************************************************/ + + /** + * @notice Returns the indices of the quorumApks index at `blockNumber` for the provided `quorumNumbers` + * @dev Returns the current indices if `blockNumber >= block.number` + */ + function getApkIndicesForQuorumsAtBlockNumber( + bytes calldata quorumNumbers, + uint256 blockNumber + ) external view returns (uint32[] memory) { + uint32[] memory indices = new uint32[](quorumNumbers.length); + for (uint i = 0; i < quorumNumbers.length; i++) { + uint8 quorumNumber = uint8(quorumNumbers[i]); + uint32 quorumApkUpdatesLength = uint32(quorumApkUpdates[quorumNumber].length); + + if (quorumApkUpdatesLength == 0 || blockNumber < quorumApkUpdates[quorumNumber][0].updateBlockNumber) { + revert( + "BLSPubkeyRegistry.getApkIndicesForQuorumsAtBlockNumber: blockNumber is before the first update" + ); + } + + for (uint32 j = 0; j < quorumApkUpdatesLength; j++) { + if (quorumApkUpdates[quorumNumber][quorumApkUpdatesLength - j - 1].updateBlockNumber <= blockNumber) { + indices[i] = quorumApkUpdatesLength - j - 1; + break; + } + } + } + return indices; + } + + /// @notice Returns the current APK for the provided `quorumNumber ` + function getApkForQuorum(uint8 quorumNumber) external view returns (BN254.G1Point memory) { + return quorumApk[quorumNumber]; + } + + /// @notice Returns the `ApkUpdate` struct at `index` in the list of APK updates for the `quorumNumber` + function getApkUpdateForQuorumByIndex(uint8 quorumNumber, uint256 index) external view returns (ApkUpdate memory) { + return quorumApkUpdates[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 + */ + function getApkHashForQuorumAtBlockNumberFromIndex( + uint8 quorumNumber, + uint32 blockNumber, + uint256 index + ) external view returns (bytes24) { + ApkUpdate memory quorumApkUpdate = quorumApkUpdates[quorumNumber][index]; + _validateApkHashForQuorumAtBlockNumber(quorumApkUpdate, blockNumber); + return quorumApkUpdate.apkHash; + } + + /// @notice Returns the length of ApkUpdates for the provided `quorumNumber` + function getQuorumApkHistoryLength(uint8 quorumNumber) external view returns (uint32) { + return uint32(quorumApkUpdates[quorumNumber].length); + } + + /// @notice Returns the operator address for the given `pubkeyHash` + function getOperatorFromPubkeyHash(bytes32 pubkeyHash) public view returns (address) { + return pubkeyCompendium.pubkeyHashToOperator(pubkeyHash); + } } diff --git a/src/BLSPublicKeyCompendium.sol b/src/BLSPublicKeyCompendium.sol index 24730fd7..56805b9a 100644 --- a/src/BLSPublicKeyCompendium.sol +++ b/src/BLSPublicKeyCompendium.sol @@ -17,6 +17,10 @@ contract BLSPublicKeyCompendium is IBLSPublicKeyCompendium { /// @notice mapping from pubkey hash to operator address mapping(bytes32 => address) public pubkeyHashToOperator; + /******************************************************************************* + EXTERNAL FUNCTIONS + *******************************************************************************/ + /** * @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 signedMessageHash is the registration message hash signed by the private key of the operator @@ -63,6 +67,10 @@ contract BLSPublicKeyCompendium is IBLSPublicKeyCompendium { emit NewPubkeyRegistration(msg.sender, pubkeyG1, pubkeyG2); } + /******************************************************************************* + VIEW FUNCTIONS + *******************************************************************************/ + /** * @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 diff --git a/src/BLSRegistryCoordinatorWithIndices.sol b/src/BLSRegistryCoordinatorWithIndices.sol index e79bec61..b44f28f3 100644 --- a/src/BLSRegistryCoordinatorWithIndices.sol +++ b/src/BLSRegistryCoordinatorWithIndices.sol @@ -120,117 +120,10 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr _setOperatorSetParams(i, _operatorSetParams[i]); } } - - // VIEW FUNCTIONS - - /// @notice Returns the operator set params for the given `quorumNumber` - function getOperatorSetParams(uint8 quorumNumber) external view returns (OperatorSetParam memory) { - return _quorumOperatorSetParams[quorumNumber]; - } - - /// @notice Returns the operator struct for the given `operator` - function getOperator(address operator) external view returns (Operator memory) { - return _operators[operator]; - } - - /// @notice Returns the operatorId for the given `operator` - function getOperatorId(address operator) external view returns (bytes32) { - return _operators[operator].operatorId; - } - - /// @notice Returns the operator address for the given `operatorId` - function getOperatorFromId(bytes32 operatorId) external view returns (address) { - return blsPubkeyRegistry.getOperatorFromPubkeyHash(operatorId); - } - - /// @notice Returns the status for the given `operator` - function getOperatorStatus(address operator) external view returns (IRegistryCoordinator.OperatorStatus) { - return _operators[operator].status; - } - - /// @notice Returns the indices of the quorumBitmaps for the provided `operatorIds` at the given `blockNumber` - function getQuorumBitmapIndicesByOperatorIdsAtBlockNumber(uint32 blockNumber, bytes32[] memory operatorIds) external view returns (uint32[] memory) { - uint32[] memory indices = new uint32[](operatorIds.length); - for (uint256 i = 0; i < operatorIds.length; i++) { - uint32 length = uint32(_operatorIdToQuorumBitmapHistory[operatorIds[i]].length); - for (uint32 j = 0; j < length; j++) { - if (_operatorIdToQuorumBitmapHistory[operatorIds[i]][length - j - 1].updateBlockNumber <= blockNumber) { - require( - _operatorIdToQuorumBitmapHistory[operatorIds[i]][length - j - 1].nextUpdateBlockNumber == 0 || - _operatorIdToQuorumBitmapHistory[operatorIds[i]][length - j - 1].nextUpdateBlockNumber > blockNumber, - "BLSRegistryCoordinatorWithIndices.getQuorumBitmapIndicesByOperatorIdsAtBlockNumber: operatorId has no quorumBitmaps at blockNumber" - ); - indices[i] = length - j - 1; - break; - } - } - } - return indices; - } - - /** - * @notice Returns the quorum bitmap for the given `operatorId` at the given `blockNumber` via the `index` - * @dev reverts if `index` is incorrect - */ - function getQuorumBitmapByOperatorIdAtBlockNumberByIndex(bytes32 operatorId, uint32 blockNumber, uint256 index) external view returns (uint192) { - QuorumBitmapUpdate memory quorumBitmapUpdate = _operatorIdToQuorumBitmapHistory[operatorId][index]; - require( - quorumBitmapUpdate.updateBlockNumber <= blockNumber, - "BLSRegistryCoordinatorWithIndices.getQuorumBitmapByOperatorIdAtBlockNumberByIndex: quorumBitmapUpdate is from after blockNumber" - ); - // if the next update is at or before the block number, then the quorum provided index is too early - // if the nex update block number is 0, then this is the latest update - require( - quorumBitmapUpdate.nextUpdateBlockNumber > blockNumber || quorumBitmapUpdate.nextUpdateBlockNumber == 0, - "BLSRegistryCoordinatorWithIndices.getQuorumBitmapByOperatorIdAtBlockNumberByIndex: quorumBitmapUpdate is from before blockNumber" - ); - return quorumBitmapUpdate.quorumBitmap; - } - - /// @notice Returns the `index`th entry in the operator with `operatorId`'s bitmap history - function getQuorumBitmapUpdateByOperatorIdByIndex(bytes32 operatorId, uint256 index) external view returns (QuorumBitmapUpdate memory) { - return _operatorIdToQuorumBitmapHistory[operatorId][index]; - } - - /// @notice Returns the current quorum bitmap for the given `operatorId` or 0 if the operator is not registered for any quorum - function getCurrentQuorumBitmapByOperatorId(bytes32 operatorId) external view returns (uint192) { - uint256 quorumBitmapHistoryLength = _operatorIdToQuorumBitmapHistory[operatorId].length; - // the first part of this if statement is met if the operator has never registered. - // the second part is met if the operator has previously registered, but is currently deregistered - if (quorumBitmapHistoryLength == 0 || _operatorIdToQuorumBitmapHistory[operatorId][quorumBitmapHistoryLength - 1].nextUpdateBlockNumber != 0) { - return 0; - } - return _operatorIdToQuorumBitmapHistory[operatorId][quorumBitmapHistoryLength - 1].quorumBitmap; - } - - /// @notice Returns the length of the quorum bitmap history for the given `operatorId` - function getQuorumBitmapUpdateByOperatorIdLength(bytes32 operatorId) external view returns (uint256) { - return _operatorIdToQuorumBitmapHistory[operatorId].length; - } - - /// @notice Returns the number of registries - function numRegistries() external view returns (uint256) { - return registries.length; - } - - /** - * @notice Public function for the the churnApprover signature hash calculation when operators are being kicked from quorums - * @param registeringOperatorId The is of the registering operator - * @param operatorKickParams The parameters needed to kick the operator from the quorums that have reached their caps - * @param salt The salt to use for the churnApprover's signature - * @param expiry The desired expiry time of the churnApprover's signature - */ - function calculateOperatorChurnApprovalDigestHash( - bytes32 registeringOperatorId, - OperatorKickParam[] memory operatorKickParams, - bytes32 salt, - uint256 expiry - ) public view returns (bytes32) { - // calculate the digest hash - return _hashTypedDataV4(keccak256(abi.encode(OPERATOR_CHURN_APPROVAL_TYPEHASH, registeringOperatorId, operatorKickParams, salt, expiry))); - } - // STATE CHANGING FUNCTIONS + /******************************************************************************* + EXTERNAL FUNCTIONS + *******************************************************************************/ /** * @notice Sets parameters of the operator set for the given `quorumNumber` @@ -429,7 +322,9 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr emit OperatorSocketUpdate(_operators[msg.sender].operatorId, socket); } - // INTERNAL FUNCTIONS + /******************************************************************************* + INTERNAL FUNCTIONS + *******************************************************************************/ function _setOperatorSetParams(uint8 quorumNumber, OperatorSetParam memory operatorSetParam) internal { _quorumOperatorSetParams[quorumNumber] = operatorSetParam; @@ -621,4 +516,115 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr // check the churnApprover's signature EIP1271SignatureUtils.checkSignature_EIP1271(churnApprover, calculateOperatorChurnApprovalDigestHash(registeringOperatorId, operatorKickParams, signatureWithSaltAndExpiry.salt, signatureWithSaltAndExpiry.expiry), signatureWithSaltAndExpiry.signature); } + + /******************************************************************************* + VIEW FUNCTIONS + *******************************************************************************/ + + /// @notice Returns the operator set params for the given `quorumNumber` + function getOperatorSetParams(uint8 quorumNumber) external view returns (OperatorSetParam memory) { + return _quorumOperatorSetParams[quorumNumber]; + } + + /// @notice Returns the operator struct for the given `operator` + function getOperator(address operator) external view returns (Operator memory) { + return _operators[operator]; + } + + /// @notice Returns the operatorId for the given `operator` + function getOperatorId(address operator) external view returns (bytes32) { + return _operators[operator].operatorId; + } + + /// @notice Returns the operator address for the given `operatorId` + function getOperatorFromId(bytes32 operatorId) external view returns (address) { + return blsPubkeyRegistry.getOperatorFromPubkeyHash(operatorId); + } + + /// @notice Returns the status for the given `operator` + function getOperatorStatus(address operator) external view returns (IRegistryCoordinator.OperatorStatus) { + return _operators[operator].status; + } + + /// @notice Returns the indices of the quorumBitmaps for the provided `operatorIds` at the given `blockNumber` + function getQuorumBitmapIndicesByOperatorIdsAtBlockNumber(uint32 blockNumber, bytes32[] memory operatorIds) external view returns (uint32[] memory) { + uint32[] memory indices = new uint32[](operatorIds.length); + for (uint256 i = 0; i < operatorIds.length; i++) { + uint32 length = uint32(_operatorIdToQuorumBitmapHistory[operatorIds[i]].length); + for (uint32 j = 0; j < length; j++) { + if (_operatorIdToQuorumBitmapHistory[operatorIds[i]][length - j - 1].updateBlockNumber <= blockNumber) { + require( + _operatorIdToQuorumBitmapHistory[operatorIds[i]][length - j - 1].nextUpdateBlockNumber == 0 || + _operatorIdToQuorumBitmapHistory[operatorIds[i]][length - j - 1].nextUpdateBlockNumber > blockNumber, + "BLSRegistryCoordinatorWithIndices.getQuorumBitmapIndicesByOperatorIdsAtBlockNumber: operatorId has no quorumBitmaps at blockNumber" + ); + indices[i] = length - j - 1; + break; + } + } + } + return indices; + } + + /** + * @notice Returns the quorum bitmap for the given `operatorId` at the given `blockNumber` via the `index` + * @dev reverts if `index` is incorrect + */ + function getQuorumBitmapByOperatorIdAtBlockNumberByIndex(bytes32 operatorId, uint32 blockNumber, uint256 index) external view returns (uint192) { + QuorumBitmapUpdate memory quorumBitmapUpdate = _operatorIdToQuorumBitmapHistory[operatorId][index]; + require( + quorumBitmapUpdate.updateBlockNumber <= blockNumber, + "BLSRegistryCoordinatorWithIndices.getQuorumBitmapByOperatorIdAtBlockNumberByIndex: quorumBitmapUpdate is from after blockNumber" + ); + // if the next update is at or before the block number, then the quorum provided index is too early + // if the nex update block number is 0, then this is the latest update + require( + quorumBitmapUpdate.nextUpdateBlockNumber > blockNumber || quorumBitmapUpdate.nextUpdateBlockNumber == 0, + "BLSRegistryCoordinatorWithIndices.getQuorumBitmapByOperatorIdAtBlockNumberByIndex: quorumBitmapUpdate is from before blockNumber" + ); + return quorumBitmapUpdate.quorumBitmap; + } + + /// @notice Returns the `index`th entry in the operator with `operatorId`'s bitmap history + function getQuorumBitmapUpdateByOperatorIdByIndex(bytes32 operatorId, uint256 index) external view returns (QuorumBitmapUpdate memory) { + return _operatorIdToQuorumBitmapHistory[operatorId][index]; + } + + /// @notice Returns the current quorum bitmap for the given `operatorId` or 0 if the operator is not registered for any quorum + function getCurrentQuorumBitmapByOperatorId(bytes32 operatorId) external view returns (uint192) { + uint256 quorumBitmapHistoryLength = _operatorIdToQuorumBitmapHistory[operatorId].length; + // the first part of this if statement is met if the operator has never registered. + // the second part is met if the operator has previously registered, but is currently deregistered + if (quorumBitmapHistoryLength == 0 || _operatorIdToQuorumBitmapHistory[operatorId][quorumBitmapHistoryLength - 1].nextUpdateBlockNumber != 0) { + return 0; + } + return _operatorIdToQuorumBitmapHistory[operatorId][quorumBitmapHistoryLength - 1].quorumBitmap; + } + + /// @notice Returns the length of the quorum bitmap history for the given `operatorId` + function getQuorumBitmapUpdateByOperatorIdLength(bytes32 operatorId) external view returns (uint256) { + return _operatorIdToQuorumBitmapHistory[operatorId].length; + } + + /// @notice Returns the number of registries + function numRegistries() external view returns (uint256) { + return registries.length; + } + + /** + * @notice Public function for the the churnApprover signature hash calculation when operators are being kicked from quorums + * @param registeringOperatorId The is of the registering operator + * @param operatorKickParams The parameters needed to kick the operator from the quorums that have reached their caps + * @param salt The salt to use for the churnApprover's signature + * @param expiry The desired expiry time of the churnApprover's signature + */ + function calculateOperatorChurnApprovalDigestHash( + bytes32 registeringOperatorId, + OperatorKickParam[] memory operatorKickParams, + bytes32 salt, + uint256 expiry + ) public view returns (bytes32) { + // calculate the digest hash + return _hashTypedDataV4(keccak256(abi.encode(OPERATOR_CHURN_APPROVAL_TYPEHASH, registeringOperatorId, operatorKickParams, salt, expiry))); + } } diff --git a/src/IndexRegistry.sol b/src/IndexRegistry.sol index 743a1043..6a4df5a7 100644 --- a/src/IndexRegistry.sol +++ b/src/IndexRegistry.sol @@ -21,6 +21,10 @@ contract IndexRegistry is IndexRegistryStorage { IRegistryCoordinator _registryCoordinator ) IndexRegistryStorage(_registryCoordinator) {} + /******************************************************************************* + EXTERNAL FUNCTIONS + *******************************************************************************/ + /** * @notice Registers the operator with the specified `operatorId` for the quorums specified by `quorumNumbers`. * @param operatorId is the id of the operator that is being registered @@ -91,116 +95,9 @@ contract IndexRegistry is IndexRegistryStorage { _afterDeregisterOperator(operatorId, quorumNumbers); } - /// @notice Returns the length of the globalOperatorList - function getGlobalOperatorListLength() external view returns (uint256) { - return globalOperatorList.length; - } - - /// @notice Returns the _operatorIdToIndexHistory entry for the specified `operatorId` and `quorumNumber` at the specified `index` - function getOperatorIndexUpdateOfOperatorIdForQuorumAtIndex( - bytes32 operatorId, - uint8 quorumNumber, - uint32 index - ) external view returns (OperatorIndexUpdate memory) { - return _operatorIdToIndexHistory[operatorId][quorumNumber][index]; - } - - /// @notice Returns the _totalOperatorsHistory entry for the specified `quorumNumber` at the specified `index` - function getTotalOperatorsUpdateForQuorumAtIndex( - uint8 quorumNumber, - uint32 index - ) external view returns (OperatorIndexUpdate memory) { - return _totalOperatorsHistory[quorumNumber][index]; - } - - /** - * @notice Looks up the `operator`'s index in the set of operators for `quorumNumber` at the specified `blockNumber` using the `index`. - * @param operatorId is the id of the operator for which the index is desired - * @param quorumNumber is the quorum number for which the operator index is desired - * @param blockNumber is the block number at which the index of the operator is desired - * @param index Used to specify the entry within the dynamic array `_operatorIdToIndexHistory[operatorId]` to - * read data from - * @dev Function will revert in the event that the specified `index` input does not identify the appropriate entry in the - * array `_operatorIdToIndexHistory[operatorId][quorumNumber]` to pull the info from. - */ - function getOperatorIndexForQuorumAtBlockNumberByIndex( - bytes32 operatorId, - uint8 quorumNumber, - uint32 blockNumber, - uint32 index - ) external view returns (uint32) { - OperatorIndexUpdate memory operatorIndexToCheck = _operatorIdToIndexHistory[operatorId][quorumNumber][index]; - - // blocknumber must be at or after the "index'th" entry's fromBlockNumber - require( - blockNumber >= operatorIndexToCheck.fromBlockNumber, - "IndexRegistry.getOperatorIndexForQuorumAtBlockNumberByIndex: provided index is too far in the past for provided block number" - ); - - // if there is an index update after the "index'th" update, the blocknumber must be before the next entry's fromBlockNumber - if (index != _operatorIdToIndexHistory[operatorId][quorumNumber].length - 1) { - OperatorIndexUpdate memory nextOperatorIndex = _operatorIdToIndexHistory[operatorId][quorumNumber][index + 1]; - require( - blockNumber < nextOperatorIndex.fromBlockNumber, - "IndexRegistry.getOperatorIndexForQuorumAtBlockNumberByIndex: provided index is too far in the future for provided block number" - ); - } - return operatorIndexToCheck.index; - } - - /** - * @notice Looks up the number of total operators for `quorumNumber` at the specified `blockNumber`. - * @param quorumNumber is the quorum number for which the total number of operators is desired - * @param blockNumber is the block number at which the total number of operators is desired - * @param index is the index of the entry in the dynamic array `_totalOperatorsHistory[quorumNumber]` to read data from - * @dev Function will revert in the event that the specified `index` input is outisde the bounds of the provided `blockNumber` - */ - function getTotalOperatorsForQuorumAtBlockNumberByIndex( - uint8 quorumNumber, - uint32 blockNumber, - uint32 index - ) external view returns (uint32){ - OperatorIndexUpdate memory operatorIndexToCheck = _totalOperatorsHistory[quorumNumber][index]; - - // blocknumber must be at or after the "index'th" entry's fromBlockNumber - require( - blockNumber >= operatorIndexToCheck.fromBlockNumber, - "IndexRegistry.getTotalOperatorsForQuorumAtBlockNumberByIndex: provided index is too far in the past for provided block number" - ); - - // if there is an index update after the "index'th" update, the blocknumber must be before the next entry's fromBlockNumber - if (index != _totalOperatorsHistory[quorumNumber].length - 1){ - OperatorIndexUpdate memory nextOperatorIndex = _totalOperatorsHistory[quorumNumber][index + 1]; - require( - blockNumber < nextOperatorIndex.fromBlockNumber, - "IndexRegistry.getTotalOperatorsForQuorumAtBlockNumberByIndex: provided index is too far in the future for provided block number" - ); - } - return operatorIndexToCheck.index; - } - - /// @notice Returns an ordered list of operators of the services for the given `quorumNumber` at the given `blockNumber` - function getOperatorListForQuorumAtBlockNumber(uint8 quorumNumber, uint32 blockNumber) external view returns (bytes32[] memory){ - bytes32[] memory quorumOperatorList = new bytes32[](_getTotalOperatorsForQuorumAtBlockNumber(quorumNumber, blockNumber)); - for (uint256 i = 0; i < globalOperatorList.length; i++) { - bytes32 operatorId = globalOperatorList[i]; - uint32 index = _getIndexOfOperatorForQuorumAtBlockNumber(operatorId, quorumNumber, blockNumber); - // if the operator was not in the quorum at the given block number, skip it - if (index == OPERATOR_DEREGISTERED_INDEX) - continue; - quorumOperatorList[index] = operatorId; - } - return quorumOperatorList; - } - - /// @notice Returns the total number of operators for a given `quorumNumber` - function totalOperatorsForQuorum(uint8 quorumNumber) external view returns (uint32){ - uint256 totalOperatorsHistoryLength = _totalOperatorsHistory[quorumNumber].length; - if (totalOperatorsHistoryLength == 0) { - return 0; - } - return _totalOperatorsHistory[quorumNumber][totalOperatorsHistoryLength - 1].index; - } + /******************************************************************************* + INTERNAL FUNCTIONS + *******************************************************************************/ /** * @notice updates the total numbers of operator in `quorumNumber` to `numOperators` @@ -336,4 +233,119 @@ contract IndexRegistry is IndexRegistryStorage { // this will be hit if `blockNumber` is before when the operator registered or the operator has never registered for the given quorum return OPERATOR_DEREGISTERED_INDEX; } + + /******************************************************************************* + VIEW FUNCTIONS + *******************************************************************************/ + + /// @notice Returns the length of the globalOperatorList + function getGlobalOperatorListLength() external view returns (uint256) { + return globalOperatorList.length; + } + + /// @notice Returns the _operatorIdToIndexHistory entry for the specified `operatorId` and `quorumNumber` at the specified `index` + function getOperatorIndexUpdateOfOperatorIdForQuorumAtIndex( + bytes32 operatorId, + uint8 quorumNumber, + uint32 index + ) external view returns (OperatorIndexUpdate memory) { + return _operatorIdToIndexHistory[operatorId][quorumNumber][index]; + } + + /// @notice Returns the _totalOperatorsHistory entry for the specified `quorumNumber` at the specified `index` + function getTotalOperatorsUpdateForQuorumAtIndex( + uint8 quorumNumber, + uint32 index + ) external view returns (OperatorIndexUpdate memory) { + return _totalOperatorsHistory[quorumNumber][index]; + } + + /** + * @notice Looks up the `operator`'s index in the set of operators for `quorumNumber` at the specified `blockNumber` using the `index`. + * @param operatorId is the id of the operator for which the index is desired + * @param quorumNumber is the quorum number for which the operator index is desired + * @param blockNumber is the block number at which the index of the operator is desired + * @param index Used to specify the entry within the dynamic array `_operatorIdToIndexHistory[operatorId]` to + * read data from + * @dev Function will revert in the event that the specified `index` input does not identify the appropriate entry in the + * array `_operatorIdToIndexHistory[operatorId][quorumNumber]` to pull the info from. + */ + function getOperatorIndexForQuorumAtBlockNumberByIndex( + bytes32 operatorId, + uint8 quorumNumber, + uint32 blockNumber, + uint32 index + ) external view returns (uint32) { + OperatorIndexUpdate memory operatorIndexToCheck = _operatorIdToIndexHistory[operatorId][quorumNumber][index]; + + // blocknumber must be at or after the "index'th" entry's fromBlockNumber + require( + blockNumber >= operatorIndexToCheck.fromBlockNumber, + "IndexRegistry.getOperatorIndexForQuorumAtBlockNumberByIndex: provided index is too far in the past for provided block number" + ); + + // if there is an index update after the "index'th" update, the blocknumber must be before the next entry's fromBlockNumber + if (index != _operatorIdToIndexHistory[operatorId][quorumNumber].length - 1) { + OperatorIndexUpdate memory nextOperatorIndex = _operatorIdToIndexHistory[operatorId][quorumNumber][index + 1]; + require( + blockNumber < nextOperatorIndex.fromBlockNumber, + "IndexRegistry.getOperatorIndexForQuorumAtBlockNumberByIndex: provided index is too far in the future for provided block number" + ); + } + return operatorIndexToCheck.index; + } + + /** + * @notice Looks up the number of total operators for `quorumNumber` at the specified `blockNumber`. + * @param quorumNumber is the quorum number for which the total number of operators is desired + * @param blockNumber is the block number at which the total number of operators is desired + * @param index is the index of the entry in the dynamic array `_totalOperatorsHistory[quorumNumber]` to read data from + * @dev Function will revert in the event that the specified `index` input is outisde the bounds of the provided `blockNumber` + */ + function getTotalOperatorsForQuorumAtBlockNumberByIndex( + uint8 quorumNumber, + uint32 blockNumber, + uint32 index + ) external view returns (uint32){ + OperatorIndexUpdate memory operatorIndexToCheck = _totalOperatorsHistory[quorumNumber][index]; + + // blocknumber must be at or after the "index'th" entry's fromBlockNumber + require( + blockNumber >= operatorIndexToCheck.fromBlockNumber, + "IndexRegistry.getTotalOperatorsForQuorumAtBlockNumberByIndex: provided index is too far in the past for provided block number" + ); + + // if there is an index update after the "index'th" update, the blocknumber must be before the next entry's fromBlockNumber + if (index != _totalOperatorsHistory[quorumNumber].length - 1){ + OperatorIndexUpdate memory nextOperatorIndex = _totalOperatorsHistory[quorumNumber][index + 1]; + require( + blockNumber < nextOperatorIndex.fromBlockNumber, + "IndexRegistry.getTotalOperatorsForQuorumAtBlockNumberByIndex: provided index is too far in the future for provided block number" + ); + } + return operatorIndexToCheck.index; + } + + /// @notice Returns an ordered list of operators of the services for the given `quorumNumber` at the given `blockNumber` + function getOperatorListForQuorumAtBlockNumber(uint8 quorumNumber, uint32 blockNumber) external view returns (bytes32[] memory){ + bytes32[] memory quorumOperatorList = new bytes32[](_getTotalOperatorsForQuorumAtBlockNumber(quorumNumber, blockNumber)); + for (uint256 i = 0; i < globalOperatorList.length; i++) { + bytes32 operatorId = globalOperatorList[i]; + uint32 index = _getIndexOfOperatorForQuorumAtBlockNumber(operatorId, quorumNumber, blockNumber); + // if the operator was not in the quorum at the given block number, skip it + if (index == OPERATOR_DEREGISTERED_INDEX) + continue; + quorumOperatorList[index] = operatorId; + } + return quorumOperatorList; + } + + /// @notice Returns the total number of operators for a given `quorumNumber` + function totalOperatorsForQuorum(uint8 quorumNumber) external view returns (uint32){ + uint256 totalOperatorsHistoryLength = _totalOperatorsHistory[quorumNumber].length; + if (totalOperatorsHistoryLength == 0) { + return 0; + } + return _totalOperatorsHistory[quorumNumber][totalOperatorsHistoryLength - 1].index; + } } diff --git a/src/StakeRegistry.sol b/src/StakeRegistry.sol index 97f66cd4..d7f9c08d 100644 --- a/src/StakeRegistry.sol +++ b/src/StakeRegistry.sol @@ -69,177 +69,9 @@ contract StakeRegistry is StakeRegistryStorage { } } - /** - * @notice Returns the entire `operatorIdToStakeHistory[operatorId][quorumNumber]` array. - * @param operatorId The id of the operator of interest. - * @param quorumNumber The quorum number to get the stake for. - */ - function getOperatorIdToStakeHistory(bytes32 operatorId, uint8 quorumNumber) external view returns (OperatorStakeUpdate[] memory) { - return operatorIdToStakeHistory[operatorId][quorumNumber]; - } - - /** - * @notice Returns the `index`-th entry in the `operatorIdToStakeHistory[operatorId][quorumNumber]` array. - * @param quorumNumber The quorum number to get the stake for. - * @param operatorId The id of the operator of interest. - * @param index Array index for lookup, within the dynamic array `operatorIdToStakeHistory[operatorId][quorumNumber]`. - * @dev Function will revert if `index` is out-of-bounds. - */ - function getStakeUpdateForQuorumFromOperatorIdAndIndex( - uint8 quorumNumber, - bytes32 operatorId, - uint256 index - ) external view returns (OperatorStakeUpdate memory) { - return operatorIdToStakeHistory[operatorId][quorumNumber][index]; - } - - /** - * @notice Returns the `index`-th entry in the dynamic array of total stake, `_totalStakeHistory` for quorum `quorumNumber`. - * @param quorumNumber The quorum number to get the stake for. - * @param index Array index for lookup, within the dynamic array `_totalStakeHistory[quorumNumber]`. - */ - function getTotalStakeUpdateForQuorumFromIndex( - uint8 quorumNumber, - uint256 index - ) external view returns (OperatorStakeUpdate memory) { - return _totalStakeHistory[quorumNumber][index]; - } - - /// @notice Returns the indices of the operator stakes for the provided `quorumNumber` at the given `blockNumber` - function getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber( - bytes32 operatorId, - uint8 quorumNumber, - uint32 blockNumber - ) external view returns (uint32) { - return _getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber(operatorId, quorumNumber, blockNumber); - } - - /** - * @notice Returns the indices of the total stakes for the provided `quorumNumbers` at the given `blockNumber` - * @param blockNumber Block number to retrieve the stake indices from. - * @param quorumNumbers The quorum numbers to get the stake indices for. - * @dev Function will revert if there are no indices for the given `blockNumber` - */ - function getTotalStakeIndicesByQuorumNumbersAtBlockNumber( - uint32 blockNumber, - bytes calldata quorumNumbers - ) external view returns (uint32[] memory) { - uint32[] memory indices = new uint32[](quorumNumbers.length); - for (uint256 i = 0; i < quorumNumbers.length; i++) { - uint8 quorumNumber = uint8(quorumNumbers[i]); - require( - _totalStakeHistory[quorumNumber][0].updateBlockNumber <= blockNumber, - "StakeRegistry.getTotalStakeIndicesByQuorumNumbersAtBlockNumber: quorum has no stake history at blockNumber" - ); - uint32 length = uint32(_totalStakeHistory[quorumNumber].length); - for (uint32 j = 0; j < length; j++) { - if (_totalStakeHistory[quorumNumber][length - j - 1].updateBlockNumber <= blockNumber) { - indices[i] = length - j - 1; - break; - } - } - } - return indices; - } - - /** - * @notice Returns the stake weight corresponding to `operatorId` for quorum `quorumNumber`, at the - * `index`-th entry in the `operatorIdToStakeHistory[operatorId][quorumNumber]` array if it was the operator's - * stake at `blockNumber`. Reverts otherwise. - * @param quorumNumber The quorum number to get the stake for. - * @param operatorId The id of the operator of interest. - * @param index Array index for lookup, within the dynamic array `operatorIdToStakeHistory[operatorId][quorumNumber]`. - * @param blockNumber Block number to make sure the stake is from. - * @dev Function will revert if `index` is out-of-bounds. - */ - function getStakeForQuorumAtBlockNumberFromOperatorIdAndIndex( - uint8 quorumNumber, - uint32 blockNumber, - bytes32 operatorId, - uint256 index - ) external view returns (uint96) { - OperatorStakeUpdate memory operatorStakeUpdate = operatorIdToStakeHistory[operatorId][quorumNumber][index]; - _validateOperatorStakeUpdateAtBlockNumber(operatorStakeUpdate, blockNumber); - return operatorStakeUpdate.stake; - } - - /** - * @notice Returns the total stake weight for quorum `quorumNumber`, at the `index`-th entry in the - * `_totalStakeHistory[quorumNumber]` array if it was the stake at `blockNumber`. Reverts otherwise. - * @param quorumNumber The quorum number to get the stake for. - * @param index Array index for lookup, within the dynamic array `_totalStakeHistory[quorumNumber]`. - * @param blockNumber Block number to make sure the stake is from. - * @dev Function will revert if `index` is out-of-bounds. - */ - function getTotalStakeAtBlockNumberFromIndex( - uint8 quorumNumber, - uint32 blockNumber, - uint256 index - ) external view returns (uint96) { - OperatorStakeUpdate memory totalStakeUpdate = _totalStakeHistory[quorumNumber][index]; - _validateOperatorStakeUpdateAtBlockNumber(totalStakeUpdate, blockNumber); - return totalStakeUpdate.stake; - } - - /** - * @notice Returns the most recent stake weight for the `operatorId` for a certain quorum - * @dev Function returns an OperatorStakeUpdate struct with **every entry equal to 0** in the event that the operator has no stake history - */ - function getMostRecentStakeUpdateByOperatorId( - bytes32 operatorId, - uint8 quorumNumber - ) public view returns (OperatorStakeUpdate memory) { - uint256 historyLength = operatorIdToStakeHistory[operatorId][quorumNumber].length; - OperatorStakeUpdate memory operatorStakeUpdate; - if (historyLength == 0) { - return operatorStakeUpdate; - } else { - operatorStakeUpdate = operatorIdToStakeHistory[operatorId][quorumNumber][historyLength - 1]; - return operatorStakeUpdate; - } - } - - /** - * @notice Returns the most recent stake weight for the `operatorId` for quorum `quorumNumber` - * @dev Function returns weight of **0** in the event that the operator has no stake history - */ - function getCurrentOperatorStakeForQuorum(bytes32 operatorId, uint8 quorumNumber) external view returns (uint96) { - OperatorStakeUpdate memory operatorStakeUpdate = getMostRecentStakeUpdateByOperatorId(operatorId, quorumNumber); - return operatorStakeUpdate.stake; - } - - /// @notice Returns the stake of the operator for the provided `quorumNumber` at the given `blockNumber` - function getStakeForOperatorIdForQuorumAtBlockNumber( - bytes32 operatorId, - uint8 quorumNumber, - uint32 blockNumber - ) external view returns (uint96) { - return - operatorIdToStakeHistory[operatorId][quorumNumber][ - _getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber(operatorId, quorumNumber, blockNumber) - ].stake; - } - - /** - * @notice Returns the stake weight from the latest entry in `_totalStakeHistory` for quorum `quorumNumber`. - * @dev Will revert if `_totalStakeHistory[quorumNumber]` is empty. - */ - function getCurrentTotalStakeForQuorum(uint8 quorumNumber) external view returns (uint96) { - return _totalStakeHistory[quorumNumber][_totalStakeHistory[quorumNumber].length - 1].stake; - } - - function getLengthOfOperatorIdStakeHistoryForQuorum( - bytes32 operatorId, - uint8 quorumNumber - ) external view returns (uint256) { - return operatorIdToStakeHistory[operatorId][quorumNumber].length; - } - - function getLengthOfTotalStakeHistoryForQuorum(uint8 quorumNumber) external view returns (uint256) { - return _totalStakeHistory[quorumNumber].length; - } - - // MUTATING FUNCTIONS + /******************************************************************************* + EXTERNAL FUNCTIONS + *******************************************************************************/ /// @notice Adjusts the `minimumStakeFirstQuorum` -- i.e. the node stake (weight) requirement for inclusion in the 1st quorum. function setMinimumStakeForQuorum(uint8 quorumNumber, uint96 minimumStake) external onlyServiceManagerOwner { @@ -352,7 +184,9 @@ contract StakeRegistry is StakeRegistryStorage { // } } - // INTERNAL FUNCTIONS + /******************************************************************************* + INTERNAL FUNCTIONS + *******************************************************************************/ function _getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber( bytes32 operatorId, @@ -577,4 +411,178 @@ contract StakeRegistry is StakeRegistryStorage { "StakeRegistry._validateOperatorStakeAtBlockNumber: there is a newer operatorStakeUpdate available before blockNumber" ); } + + /******************************************************************************* + VIEW FUNCTIONS + *******************************************************************************/ + + /** + * @notice Returns the entire `operatorIdToStakeHistory[operatorId][quorumNumber]` array. + * @param operatorId The id of the operator of interest. + * @param quorumNumber The quorum number to get the stake for. + */ + function getOperatorIdToStakeHistory(bytes32 operatorId, uint8 quorumNumber) external view returns (OperatorStakeUpdate[] memory) { + return operatorIdToStakeHistory[operatorId][quorumNumber]; + } + + /** + * @notice Returns the `index`-th entry in the `operatorIdToStakeHistory[operatorId][quorumNumber]` array. + * @param quorumNumber The quorum number to get the stake for. + * @param operatorId The id of the operator of interest. + * @param index Array index for lookup, within the dynamic array `operatorIdToStakeHistory[operatorId][quorumNumber]`. + * @dev Function will revert if `index` is out-of-bounds. + */ + function getStakeUpdateForQuorumFromOperatorIdAndIndex( + uint8 quorumNumber, + bytes32 operatorId, + uint256 index + ) external view returns (OperatorStakeUpdate memory) { + return operatorIdToStakeHistory[operatorId][quorumNumber][index]; + } + + /** + * @notice Returns the `index`-th entry in the dynamic array of total stake, `_totalStakeHistory` for quorum `quorumNumber`. + * @param quorumNumber The quorum number to get the stake for. + * @param index Array index for lookup, within the dynamic array `_totalStakeHistory[quorumNumber]`. + */ + function getTotalStakeUpdateForQuorumFromIndex( + uint8 quorumNumber, + uint256 index + ) external view returns (OperatorStakeUpdate memory) { + return _totalStakeHistory[quorumNumber][index]; + } + + /// @notice Returns the indices of the operator stakes for the provided `quorumNumber` at the given `blockNumber` + function getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber( + bytes32 operatorId, + uint8 quorumNumber, + uint32 blockNumber + ) external view returns (uint32) { + return _getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber(operatorId, quorumNumber, blockNumber); + } + + /** + * @notice Returns the indices of the total stakes for the provided `quorumNumbers` at the given `blockNumber` + * @param blockNumber Block number to retrieve the stake indices from. + * @param quorumNumbers The quorum numbers to get the stake indices for. + * @dev Function will revert if there are no indices for the given `blockNumber` + */ + function getTotalStakeIndicesByQuorumNumbersAtBlockNumber( + uint32 blockNumber, + bytes calldata quorumNumbers + ) external view returns (uint32[] memory) { + uint32[] memory indices = new uint32[](quorumNumbers.length); + for (uint256 i = 0; i < quorumNumbers.length; i++) { + uint8 quorumNumber = uint8(quorumNumbers[i]); + require( + _totalStakeHistory[quorumNumber][0].updateBlockNumber <= blockNumber, + "StakeRegistry.getTotalStakeIndicesByQuorumNumbersAtBlockNumber: quorum has no stake history at blockNumber" + ); + uint32 length = uint32(_totalStakeHistory[quorumNumber].length); + for (uint32 j = 0; j < length; j++) { + if (_totalStakeHistory[quorumNumber][length - j - 1].updateBlockNumber <= blockNumber) { + indices[i] = length - j - 1; + break; + } + } + } + return indices; + } + + /** + * @notice Returns the stake weight corresponding to `operatorId` for quorum `quorumNumber`, at the + * `index`-th entry in the `operatorIdToStakeHistory[operatorId][quorumNumber]` array if it was the operator's + * stake at `blockNumber`. Reverts otherwise. + * @param quorumNumber The quorum number to get the stake for. + * @param operatorId The id of the operator of interest. + * @param index Array index for lookup, within the dynamic array `operatorIdToStakeHistory[operatorId][quorumNumber]`. + * @param blockNumber Block number to make sure the stake is from. + * @dev Function will revert if `index` is out-of-bounds. + */ + function getStakeForQuorumAtBlockNumberFromOperatorIdAndIndex( + uint8 quorumNumber, + uint32 blockNumber, + bytes32 operatorId, + uint256 index + ) external view returns (uint96) { + OperatorStakeUpdate memory operatorStakeUpdate = operatorIdToStakeHistory[operatorId][quorumNumber][index]; + _validateOperatorStakeUpdateAtBlockNumber(operatorStakeUpdate, blockNumber); + return operatorStakeUpdate.stake; + } + + /** + * @notice Returns the total stake weight for quorum `quorumNumber`, at the `index`-th entry in the + * `_totalStakeHistory[quorumNumber]` array if it was the stake at `blockNumber`. Reverts otherwise. + * @param quorumNumber The quorum number to get the stake for. + * @param index Array index for lookup, within the dynamic array `_totalStakeHistory[quorumNumber]`. + * @param blockNumber Block number to make sure the stake is from. + * @dev Function will revert if `index` is out-of-bounds. + */ + function getTotalStakeAtBlockNumberFromIndex( + uint8 quorumNumber, + uint32 blockNumber, + uint256 index + ) external view returns (uint96) { + OperatorStakeUpdate memory totalStakeUpdate = _totalStakeHistory[quorumNumber][index]; + _validateOperatorStakeUpdateAtBlockNumber(totalStakeUpdate, blockNumber); + return totalStakeUpdate.stake; + } + + /** + * @notice Returns the most recent stake weight for the `operatorId` for a certain quorum + * @dev Function returns an OperatorStakeUpdate struct with **every entry equal to 0** in the event that the operator has no stake history + */ + function getMostRecentStakeUpdateByOperatorId( + bytes32 operatorId, + uint8 quorumNumber + ) public view returns (OperatorStakeUpdate memory) { + uint256 historyLength = operatorIdToStakeHistory[operatorId][quorumNumber].length; + OperatorStakeUpdate memory operatorStakeUpdate; + if (historyLength == 0) { + return operatorStakeUpdate; + } else { + operatorStakeUpdate = operatorIdToStakeHistory[operatorId][quorumNumber][historyLength - 1]; + return operatorStakeUpdate; + } + } + + /** + * @notice Returns the most recent stake weight for the `operatorId` for quorum `quorumNumber` + * @dev Function returns weight of **0** in the event that the operator has no stake history + */ + function getCurrentOperatorStakeForQuorum(bytes32 operatorId, uint8 quorumNumber) external view returns (uint96) { + OperatorStakeUpdate memory operatorStakeUpdate = getMostRecentStakeUpdateByOperatorId(operatorId, quorumNumber); + return operatorStakeUpdate.stake; + } + + /// @notice Returns the stake of the operator for the provided `quorumNumber` at the given `blockNumber` + function getStakeForOperatorIdForQuorumAtBlockNumber( + bytes32 operatorId, + uint8 quorumNumber, + uint32 blockNumber + ) external view returns (uint96) { + return + operatorIdToStakeHistory[operatorId][quorumNumber][ + _getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber(operatorId, quorumNumber, blockNumber) + ].stake; + } + + /** + * @notice Returns the stake weight from the latest entry in `_totalStakeHistory` for quorum `quorumNumber`. + * @dev Will revert if `_totalStakeHistory[quorumNumber]` is empty. + */ + function getCurrentTotalStakeForQuorum(uint8 quorumNumber) external view returns (uint96) { + return _totalStakeHistory[quorumNumber][_totalStakeHistory[quorumNumber].length - 1].stake; + } + + function getLengthOfOperatorIdStakeHistoryForQuorum( + bytes32 operatorId, + uint8 quorumNumber + ) external view returns (uint256) { + return operatorIdToStakeHistory[operatorId][quorumNumber].length; + } + + function getLengthOfTotalStakeHistoryForQuorum(uint8 quorumNumber) external view returns (uint256) { + return _totalStakeHistory[quorumNumber].length; + } } diff --git a/src/VoteWeigherBase.sol b/src/VoteWeigherBase.sol index e5345535..9e306bbb 100644 --- a/src/VoteWeigherBase.sol +++ b/src/VoteWeigherBase.sol @@ -34,52 +34,9 @@ contract VoteWeigherBase is VoteWeigherBaseStorage { IServiceManager _serviceManager ) VoteWeigherBaseStorage(_strategyManager, _serviceManager) {} - /// @notice Returns the strategy and weight multiplier for the `index`'th strategy in the quorum `quorumNumber` - function strategyAndWeightingMultiplierForQuorumByIndex(uint8 quorumNumber, uint256 index) - public - view - returns (StrategyAndWeightingMultiplier memory) - { - return strategiesConsideredAndMultipliers[quorumNumber][index]; - } - - /** - * @notice This function computes the total weight of the @param operator in the quorum @param quorumNumber. - * @dev reverts in the case that `quorumNumber` is greater than or equal to `quorumCount` - */ - function weightOfOperatorForQuorumView(uint8 quorumNumber, address operator) public virtual view validQuorumNumber(quorumNumber) returns (uint96) { - uint96 weight; - uint256 stratsLength = strategiesConsideredAndMultipliersLength(quorumNumber); - StrategyAndWeightingMultiplier memory strategyAndMultiplier; - - for (uint256 i = 0; i < stratsLength;) { - // accessing i^th StrategyAndWeightingMultiplier struct for the quorumNumber - strategyAndMultiplier = strategiesConsideredAndMultipliers[quorumNumber][i]; - - // shares of the operator in the strategy - uint256 sharesAmount = delegation.operatorShares(operator, strategyAndMultiplier.strategy); - - // add the weight from the shares for this strategy to the total weight - if (sharesAmount > 0) { - weight += uint96(sharesAmount * strategyAndMultiplier.multiplier / WEIGHTING_DIVISOR); - } - - unchecked { - ++i; - } - } - - return weight; - } - - /** - * @notice This function computes the total weight of the @param operator in the quorum @param quorumNumber. - * @dev reverts in the case that `quorumNumber` is greater than or equal to `quorumCount` - * @dev a version of weightOfOperatorForQuorumView that can change state if needed - */ - function weightOfOperatorForQuorum(uint8 quorumNumber, address operator) public virtual validQuorumNumber(quorumNumber) returns (uint96) { - return weightOfOperatorForQuorumView(quorumNumber, operator); - } + /******************************************************************************* + EXTERNAL FUNCTIONS + *******************************************************************************/ /// @notice Create a new quorum and add the strategies and their associated weights to the quorum. function createQuorum( @@ -150,10 +107,9 @@ contract VoteWeigherBase is VoteWeigherBaseStorage { } } - /// @notice Returns the length of the dynamic array stored in `strategiesConsideredAndMultipliers[quorumNumber]`. - function strategiesConsideredAndMultipliersLength(uint8 quorumNumber) public view returns (uint256) { - return strategiesConsideredAndMultipliers[quorumNumber].length; - } + /******************************************************************************* + INTERNAL FUNCTIONS + *******************************************************************************/ /** * @notice Creates a quorum with the given_strategiesConsideredAndMultipliers. @@ -217,4 +173,60 @@ contract VoteWeigherBase is VoteWeigherBaseStorage { } } } + + /******************************************************************************* + VIEW FUNCTIONS + *******************************************************************************/ + + /// @notice Returns the length of the dynamic array stored in `strategiesConsideredAndMultipliers[quorumNumber]`. + function strategiesConsideredAndMultipliersLength(uint8 quorumNumber) public view returns (uint256) { + return strategiesConsideredAndMultipliers[quorumNumber].length; + } + + /// @notice Returns the strategy and weight multiplier for the `index`'th strategy in the quorum `quorumNumber` + function strategyAndWeightingMultiplierForQuorumByIndex(uint8 quorumNumber, uint256 index) + public + view + returns (StrategyAndWeightingMultiplier memory) + { + return strategiesConsideredAndMultipliers[quorumNumber][index]; + } + + /** + * @notice This function computes the total weight of the @param operator in the quorum @param quorumNumber. + * @dev reverts in the case that `quorumNumber` is greater than or equal to `quorumCount` + */ + function weightOfOperatorForQuorumView(uint8 quorumNumber, address operator) public virtual view validQuorumNumber(quorumNumber) returns (uint96) { + uint96 weight; + uint256 stratsLength = strategiesConsideredAndMultipliersLength(quorumNumber); + StrategyAndWeightingMultiplier memory strategyAndMultiplier; + + for (uint256 i = 0; i < stratsLength;) { + // accessing i^th StrategyAndWeightingMultiplier struct for the quorumNumber + strategyAndMultiplier = strategiesConsideredAndMultipliers[quorumNumber][i]; + + // shares of the operator in the strategy + uint256 sharesAmount = delegation.operatorShares(operator, strategyAndMultiplier.strategy); + + // add the weight from the shares for this strategy to the total weight + if (sharesAmount > 0) { + weight += uint96(sharesAmount * strategyAndMultiplier.multiplier / WEIGHTING_DIVISOR); + } + + unchecked { + ++i; + } + } + + return weight; + } + + /** + * @notice This function computes the total weight of the @param operator in the quorum @param quorumNumber. + * @dev reverts in the case that `quorumNumber` is greater than or equal to `quorumCount` + * @dev a version of weightOfOperatorForQuorumView that can change state if needed + */ + function weightOfOperatorForQuorum(uint8 quorumNumber, address operator) public virtual validQuorumNumber(quorumNumber) returns (uint96) { + return weightOfOperatorForQuorumView(quorumNumber, operator); + } } From cd94db0b5bee6cca40d67ff4b1fc8a13e19915af Mon Sep 17 00:00:00 2001 From: wadealexc Date: Wed, 18 Oct 2023 15:26:53 +0000 Subject: [PATCH 2/8] Additional ordering of functions by caller --- src/BLSPubkeyRegistry.sol | 2 +- src/BLSRegistryCoordinatorWithIndices.sol | 74 +++++++------- src/IndexRegistry.sol | 2 +- src/StakeRegistry.sol | 112 ++++++++++++---------- src/VoteWeigherBase.sol | 2 +- 5 files changed, 104 insertions(+), 88 deletions(-) diff --git a/src/BLSPubkeyRegistry.sol b/src/BLSPubkeyRegistry.sol index bb3eea6b..9ea9d7bb 100644 --- a/src/BLSPubkeyRegistry.sol +++ b/src/BLSPubkeyRegistry.sol @@ -23,7 +23,7 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage { ) BLSPubkeyRegistryStorage(_registryCoordinator, _pubkeyCompendium) {} /******************************************************************************* - EXTERNAL FUNCTIONS + EXTERNAL FUNCTIONS - REGISTRY COORDINATOR *******************************************************************************/ /** diff --git a/src/BLSRegistryCoordinatorWithIndices.sol b/src/BLSRegistryCoordinatorWithIndices.sol index b44f28f3..e8dedf72 100644 --- a/src/BLSRegistryCoordinatorWithIndices.sol +++ b/src/BLSRegistryCoordinatorWithIndices.sol @@ -125,34 +125,6 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr EXTERNAL FUNCTIONS *******************************************************************************/ - /** - * @notice Sets parameters of the operator set for the given `quorumNumber` - * @param quorumNumber is the quorum number to set the maximum number of operators for - * @param operatorSetParam is the parameters of the operator set for the `quorumNumber` - * @dev only callable by the service manager owner - */ - function setOperatorSetParams(uint8 quorumNumber, OperatorSetParam memory operatorSetParam) external onlyServiceManagerOwner { - _setOperatorSetParams(quorumNumber, operatorSetParam); - } - - /** - * @notice Sets the churnApprover - * @param _churnApprover is the address of the churnApprover - * @dev only callable by the service manager owner - */ - function setChurnApprover(address _churnApprover) external onlyServiceManagerOwner { - _setChurnApprover(_churnApprover); - } - - /** - * @notice Sets the ejector - * @param _ejector is the address of the ejector - * @dev only callable by the service manager owner - */ - function setEjector(address _ejector) external onlyServiceManagerOwner { - _setEjector(_ejector); - } - /** * @notice Registers msg.sender as an operator with the middleware * @param quorumNumbers are the bytes representing the quorum numbers that the operator is registering for @@ -294,6 +266,19 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr _deregisterOperatorWithCoordinator(msg.sender, quorumNumbers, pubkey, operatorIdsToSwap); } + /** + * @notice Updates the socket of the msg.sender given they are a registered operator + * @param socket is the new socket of the operator + */ + function updateSocket(string memory socket) external { + require(_operators[msg.sender].status == OperatorStatus.REGISTERED, "BLSRegistryCoordinatorWithIndicies.updateSocket: operator is not registered"); + emit OperatorSocketUpdate(_operators[msg.sender].operatorId, socket); + } + + /******************************************************************************* + EXTERNAL FUNCTIONS - EJECTOR + *******************************************************************************/ + /** * @notice Ejects the provided operator from the provided quorums from the AVS * @param operator is the operator to eject @@ -313,13 +298,36 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr _deregisterOperatorWithCoordinator(operator, quorumNumbers, pubkey, operatorIdsToSwap); } + /******************************************************************************* + EXTERNAL FUNCTIONS - SERVICE MANAGER OWNER + *******************************************************************************/ + /** - * @notice Updates the socket of the msg.sender given they are a registered operator - * @param socket is the new socket of the operator + * @notice Sets parameters of the operator set for the given `quorumNumber` + * @param quorumNumber is the quorum number to set the maximum number of operators for + * @param operatorSetParam is the parameters of the operator set for the `quorumNumber` + * @dev only callable by the service manager owner */ - function updateSocket(string memory socket) external { - require(_operators[msg.sender].status == OperatorStatus.REGISTERED, "BLSRegistryCoordinatorWithIndicies.updateSocket: operator is not registered"); - emit OperatorSocketUpdate(_operators[msg.sender].operatorId, socket); + function setOperatorSetParams(uint8 quorumNumber, OperatorSetParam memory operatorSetParam) external onlyServiceManagerOwner { + _setOperatorSetParams(quorumNumber, operatorSetParam); + } + + /** + * @notice Sets the churnApprover + * @param _churnApprover is the address of the churnApprover + * @dev only callable by the service manager owner + */ + function setChurnApprover(address _churnApprover) external onlyServiceManagerOwner { + _setChurnApprover(_churnApprover); + } + + /** + * @notice Sets the ejector + * @param _ejector is the address of the ejector + * @dev only callable by the service manager owner + */ + function setEjector(address _ejector) external onlyServiceManagerOwner { + _setEjector(_ejector); } /******************************************************************************* diff --git a/src/IndexRegistry.sol b/src/IndexRegistry.sol index 6a4df5a7..0fc95d0a 100644 --- a/src/IndexRegistry.sol +++ b/src/IndexRegistry.sol @@ -22,7 +22,7 @@ contract IndexRegistry is IndexRegistryStorage { ) IndexRegistryStorage(_registryCoordinator) {} /******************************************************************************* - EXTERNAL FUNCTIONS + EXTERNAL FUNCTIONS - REGISTRY COORDINATOR *******************************************************************************/ /** diff --git a/src/StakeRegistry.sol b/src/StakeRegistry.sol index d7f9c08d..f7bacc75 100644 --- a/src/StakeRegistry.sol +++ b/src/StakeRegistry.sol @@ -73,58 +73,6 @@ contract StakeRegistry is StakeRegistryStorage { EXTERNAL FUNCTIONS *******************************************************************************/ - /// @notice Adjusts the `minimumStakeFirstQuorum` -- i.e. the node stake (weight) requirement for inclusion in the 1st quorum. - function setMinimumStakeForQuorum(uint8 quorumNumber, uint96 minimumStake) external onlyServiceManagerOwner { - _setMinimumStakeForQuorum(quorumNumber, minimumStake); - } - - /** - * @notice Registers the `operator` with `operatorId` for the specified `quorumNumbers`. - * @param operator The address of the operator to register. - * @param operatorId The id 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 - */ - function registerOperator( - address operator, - bytes32 operatorId, - bytes calldata quorumNumbers - ) external virtual onlyRegistryCoordinator { - _beforeRegisterOperator(operator, operatorId, quorumNumbers); - - _registerOperator(operator, operatorId, quorumNumbers); - - _afterRegisterOperator(operator, operatorId, quorumNumbers); - } - - /** - * @notice Deregisters the operator with `operatorId` for the specified `quorumNumbers`. - * @param operatorId The id 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 - */ - function deregisterOperator( - bytes32 operatorId, - bytes calldata quorumNumbers - ) external virtual onlyRegistryCoordinator { - _beforeDeregisterOperator(operatorId, quorumNumbers); - - _deregisterOperator(operatorId, quorumNumbers); - - _afterDeregisterOperator(operatorId, quorumNumbers); - } - /** * @notice Used for updating information on deposits of nodes. * @param operators are the addresses of the operators whose stake information is getting updated @@ -184,6 +132,66 @@ contract StakeRegistry is StakeRegistryStorage { // } } + /******************************************************************************* + EXTERNAL FUNCTIONS - REGISTRY COORDINATOR + *******************************************************************************/ + + /** + * @notice Registers the `operator` with `operatorId` for the specified `quorumNumbers`. + * @param operator The address of the operator to register. + * @param operatorId The id 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 + */ + function registerOperator( + address operator, + bytes32 operatorId, + bytes calldata quorumNumbers + ) external virtual onlyRegistryCoordinator { + _beforeRegisterOperator(operator, operatorId, quorumNumbers); + + _registerOperator(operator, operatorId, quorumNumbers); + + _afterRegisterOperator(operator, operatorId, quorumNumbers); + } + + /** + * @notice Deregisters the operator with `operatorId` for the specified `quorumNumbers`. + * @param operatorId The id 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 + */ + function deregisterOperator( + bytes32 operatorId, + bytes calldata quorumNumbers + ) external virtual onlyRegistryCoordinator { + _beforeDeregisterOperator(operatorId, quorumNumbers); + + _deregisterOperator(operatorId, quorumNumbers); + + _afterDeregisterOperator(operatorId, quorumNumbers); + } + + /******************************************************************************* + EXTERNAL FUNCTIONS - SERVICE MANAGER OWNER + *******************************************************************************/ + + /// @notice Adjusts the `minimumStakeFirstQuorum` -- i.e. the node stake (weight) requirement for inclusion in the 1st quorum. + function setMinimumStakeForQuorum(uint8 quorumNumber, uint96 minimumStake) external onlyServiceManagerOwner { + _setMinimumStakeForQuorum(quorumNumber, minimumStake); + } + /******************************************************************************* INTERNAL FUNCTIONS *******************************************************************************/ diff --git a/src/VoteWeigherBase.sol b/src/VoteWeigherBase.sol index 9e306bbb..a6907f29 100644 --- a/src/VoteWeigherBase.sol +++ b/src/VoteWeigherBase.sol @@ -35,7 +35,7 @@ contract VoteWeigherBase is VoteWeigherBaseStorage { ) VoteWeigherBaseStorage(_strategyManager, _serviceManager) {} /******************************************************************************* - EXTERNAL FUNCTIONS + EXTERNAL FUNCTIONS - SERVICE MANAGER OWNER *******************************************************************************/ /// @notice Create a new quorum and add the strategies and their associated weights to the quorum. From dad3c20c7da4759d26c75fa7b16cf9f97342ad1e Mon Sep 17 00:00:00 2001 From: wadealexc Date: Wed, 18 Oct 2023 15:35:12 +0000 Subject: [PATCH 3/8] Made function definitions multi-line when they went off my screen --- src/BLSOperatorStateRetriever.sol | 12 +++- src/BLSPublicKeyCompendium.sol | 6 +- src/BLSRegistryCoordinatorWithIndices.sol | 78 ++++++++++++++++------- src/IndexRegistry.sol | 21 ++++-- src/StakeRegistry.sol | 5 +- src/VoteWeigherBase.sol | 18 ++++-- 6 files changed, 103 insertions(+), 37 deletions(-) diff --git a/src/BLSOperatorStateRetriever.sol b/src/BLSOperatorStateRetriever.sol index 6683c432..3ed09104 100644 --- a/src/BLSOperatorStateRetriever.sol +++ b/src/BLSOperatorStateRetriever.sol @@ -35,7 +35,11 @@ contract BLSOperatorStateRetriever { * 2) 2d array of Operator structs. For each quorum the provided operator * was a part of at `blockNumber`, an ordered list of operators. */ - function getOperatorState(IBLSRegistryCoordinatorWithIndices registryCoordinator, bytes32 operatorId, uint32 blockNumber) external view returns (uint256, Operator[][] memory) { + function getOperatorState( + IBLSRegistryCoordinatorWithIndices registryCoordinator, + bytes32 operatorId, + uint32 blockNumber + ) external view returns (uint256, Operator[][] memory) { bytes32[] memory operatorIds = new bytes32[](1); operatorIds[0] = operatorId; uint256 index = registryCoordinator.getQuorumBitmapIndicesByOperatorIdsAtBlockNumber(blockNumber, operatorIds)[0]; @@ -55,7 +59,11 @@ contract BLSOperatorStateRetriever { * @param blockNumber is the block number to get the operator state for * @return 2d array of operators. For each quorum, an ordered list of operators */ - function getOperatorState(IBLSRegistryCoordinatorWithIndices registryCoordinator, bytes memory quorumNumbers, uint32 blockNumber) public view returns(Operator[][] memory) { + function getOperatorState( + IBLSRegistryCoordinatorWithIndices registryCoordinator, + bytes memory quorumNumbers, + uint32 blockNumber + ) public view returns(Operator[][] memory) { IStakeRegistry stakeRegistry = registryCoordinator.stakeRegistry(); IIndexRegistry indexRegistry = registryCoordinator.indexRegistry(); diff --git a/src/BLSPublicKeyCompendium.sol b/src/BLSPublicKeyCompendium.sol index 56805b9a..30d43b45 100644 --- a/src/BLSPublicKeyCompendium.sol +++ b/src/BLSPublicKeyCompendium.sol @@ -27,7 +27,11 @@ contract BLSPublicKeyCompendium is IBLSPublicKeyCompendium { * @param pubkeyG1 is the corresponding G1 public key of the operator * @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 { + 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), diff --git a/src/BLSRegistryCoordinatorWithIndices.sol b/src/BLSRegistryCoordinatorWithIndices.sol index e8dedf72..7228e2a0 100644 --- a/src/BLSRegistryCoordinatorWithIndices.sol +++ b/src/BLSRegistryCoordinatorWithIndices.sol @@ -308,7 +308,10 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr * @param operatorSetParam is the parameters of the operator set for the `quorumNumber` * @dev only callable by the service manager owner */ - function setOperatorSetParams(uint8 quorumNumber, OperatorSetParam memory operatorSetParam) external onlyServiceManagerOwner { + function setOperatorSetParams( + uint8 quorumNumber, + OperatorSetParam memory operatorSetParam + ) external onlyServiceManagerOwner { _setOperatorSetParams(quorumNumber, operatorSetParam); } @@ -334,23 +337,13 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr INTERNAL FUNCTIONS *******************************************************************************/ - function _setOperatorSetParams(uint8 quorumNumber, OperatorSetParam memory operatorSetParam) internal { - _quorumOperatorSetParams[quorumNumber] = operatorSetParam; - emit OperatorSetParamsUpdated(quorumNumber, operatorSetParam); - } - - function _setChurnApprover(address newChurnApprover) internal { - emit ChurnApproverUpdated(churnApprover, newChurnApprover); - churnApprover = newChurnApprover; - } - - function _setEjector(address newEjector) internal { - emit EjectorUpdated(ejector, newEjector); - ejector = newEjector; - } - /// @return numOperatorsPerQuorum is the list of number of operators per quorum in quorumNumberss - function _registerOperatorWithCoordinator(address operator, bytes calldata quorumNumbers, BN254.G1Point memory pubkey, string memory socket) internal returns(uint32[] memory) { + function _registerOperatorWithCoordinator( + address operator, + bytes calldata quorumNumbers, + BN254.G1Point memory pubkey, + string memory socket + ) internal returns(uint32[] memory) { // require( // slasher.contractCanSlashOperatorUntilBlock(operator, address(serviceManager)) == type(uint32).max, // "StakeRegistry._registerOperator: operator must be opted into slashing by the serviceManager" @@ -414,7 +407,12 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr return numOperatorsPerQuorum; } - function _registerOperatorWithCoordinatorAndNoOverfilledQuorums(address operator, bytes calldata quorumNumbers, BN254.G1Point memory pubkey, string memory socket) internal { + function _registerOperatorWithCoordinatorAndNoOverfilledQuorums( + address operator, + bytes calldata quorumNumbers, + BN254.G1Point memory pubkey, + string memory socket + ) internal { uint32[] memory numOperatorsPerQuorum = _registerOperatorWithCoordinator(operator, quorumNumbers, pubkey, socket); for (uint i = 0; i < numOperatorsPerQuorum.length; i++) { require( @@ -424,7 +422,12 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr } } - function _deregisterOperatorWithCoordinator(address operator, bytes calldata quorumNumbers, BN254.G1Point memory pubkey, bytes32[] memory operatorIdsToSwap) internal { + function _deregisterOperatorWithCoordinator( + address operator, + bytes calldata quorumNumbers, + BN254.G1Point memory pubkey, + bytes32[] memory operatorIdsToSwap + ) internal { require(_operators[operator].status == OperatorStatus.REGISTERED, "BLSRegistryCoordinatorWithIndices._deregisterOperatorWithCoordinator: operator is not registered"); // get the operatorId of the operator @@ -513,7 +516,11 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr function _afterDeregisterOperator(address operator, bytes memory quorumNumbers) internal virtual {} /// @notice verifies churnApprover's signature on operator churn approval and increments the churnApprover nonce - function _verifyChurnApproverSignatureOnOperatorChurnApproval(bytes32 registeringOperatorId, OperatorKickParam[] memory operatorKickParams, SignatureWithSaltAndExpiry memory signatureWithSaltAndExpiry) internal { + function _verifyChurnApproverSignatureOnOperatorChurnApproval( + bytes32 registeringOperatorId, + OperatorKickParam[] memory operatorKickParams, + SignatureWithSaltAndExpiry memory signatureWithSaltAndExpiry + ) internal { // make sure the salt hasn't been used already require(!isChurnApproverSaltUsed[signatureWithSaltAndExpiry.salt], "BLSRegistryCoordinatorWithIndices._verifyChurnApproverSignatureOnOperatorChurnApproval: churnApprover salt already used"); require(signatureWithSaltAndExpiry.expiry >= block.timestamp, "BLSRegistryCoordinatorWithIndices._verifyChurnApproverSignatureOnOperatorChurnApproval: churnApprover signature expired"); @@ -525,6 +532,21 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr EIP1271SignatureUtils.checkSignature_EIP1271(churnApprover, calculateOperatorChurnApprovalDigestHash(registeringOperatorId, operatorKickParams, signatureWithSaltAndExpiry.salt, signatureWithSaltAndExpiry.expiry), signatureWithSaltAndExpiry.signature); } + function _setOperatorSetParams(uint8 quorumNumber, OperatorSetParam memory operatorSetParam) internal { + _quorumOperatorSetParams[quorumNumber] = operatorSetParam; + emit OperatorSetParamsUpdated(quorumNumber, operatorSetParam); + } + + function _setChurnApprover(address newChurnApprover) internal { + emit ChurnApproverUpdated(churnApprover, newChurnApprover); + churnApprover = newChurnApprover; + } + + function _setEjector(address newEjector) internal { + emit EjectorUpdated(ejector, newEjector); + ejector = newEjector; + } + /******************************************************************************* VIEW FUNCTIONS *******************************************************************************/ @@ -555,7 +577,10 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr } /// @notice Returns the indices of the quorumBitmaps for the provided `operatorIds` at the given `blockNumber` - function getQuorumBitmapIndicesByOperatorIdsAtBlockNumber(uint32 blockNumber, bytes32[] memory operatorIds) external view returns (uint32[] memory) { + function getQuorumBitmapIndicesByOperatorIdsAtBlockNumber( + uint32 blockNumber, + bytes32[] memory operatorIds + ) external view returns (uint32[] memory) { uint32[] memory indices = new uint32[](operatorIds.length); for (uint256 i = 0; i < operatorIds.length; i++) { uint32 length = uint32(_operatorIdToQuorumBitmapHistory[operatorIds[i]].length); @@ -578,7 +603,11 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr * @notice Returns the quorum bitmap for the given `operatorId` at the given `blockNumber` via the `index` * @dev reverts if `index` is incorrect */ - function getQuorumBitmapByOperatorIdAtBlockNumberByIndex(bytes32 operatorId, uint32 blockNumber, uint256 index) external view returns (uint192) { + function getQuorumBitmapByOperatorIdAtBlockNumberByIndex( + bytes32 operatorId, + uint32 blockNumber, + uint256 index + ) external view returns (uint192) { QuorumBitmapUpdate memory quorumBitmapUpdate = _operatorIdToQuorumBitmapHistory[operatorId][index]; require( quorumBitmapUpdate.updateBlockNumber <= blockNumber, @@ -594,7 +623,10 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr } /// @notice Returns the `index`th entry in the operator with `operatorId`'s bitmap history - function getQuorumBitmapUpdateByOperatorIdByIndex(bytes32 operatorId, uint256 index) external view returns (QuorumBitmapUpdate memory) { + function getQuorumBitmapUpdateByOperatorIdByIndex( + bytes32 operatorId, + uint256 index + ) external view returns (QuorumBitmapUpdate memory) { return _operatorIdToQuorumBitmapHistory[operatorId][index]; } diff --git a/src/IndexRegistry.sol b/src/IndexRegistry.sol index 0fc95d0a..d591036c 100644 --- a/src/IndexRegistry.sol +++ b/src/IndexRegistry.sol @@ -37,7 +37,10 @@ contract IndexRegistry is IndexRegistryStorage { * 3) `quorumNumbers` is ordered in ascending order * 4) the operator is not already registered */ - function registerOperator(bytes32 operatorId, bytes calldata quorumNumbers) external onlyRegistryCoordinator returns(uint32[] memory) { + function registerOperator( + bytes32 operatorId, + bytes calldata quorumNumbers + ) external onlyRegistryCoordinator returns(uint32[] memory) { _beforeRegisterOperator(operatorId, quorumNumbers); uint32[] memory numOperatorsPerQuorum = new uint32[](quorumNumbers.length); @@ -188,7 +191,10 @@ contract IndexRegistry is IndexRegistryStorage { * @dev Returns zero if the @param blockNumber is from before the @param quorumNumber existed, and returns the current number * of total operators if the @param blockNumber is in the future. */ - function _getTotalOperatorsForQuorumAtBlockNumber(uint8 quorumNumber, uint32 blockNumber) internal view returns (uint32){ + function _getTotalOperatorsForQuorumAtBlockNumber( + uint8 quorumNumber, + uint32 blockNumber + ) internal view returns (uint32){ // store list length in memory uint256 totalOperatorsHistoryLength = _totalOperatorsHistory[quorumNumber].length; // if there are no entries in the total operator history, return 0 @@ -217,7 +223,11 @@ contract IndexRegistry is IndexRegistryStorage { * @notice Returns the index of the `operatorId` at the given `blockNumber` for the given `quorumNumber`, or * `OPERATOR_DEREGISTERED_INDEX` if the operator was not registered for the `quorumNumber` at blockNumber */ - function _getIndexOfOperatorForQuorumAtBlockNumber(bytes32 operatorId, uint8 quorumNumber, uint32 blockNumber) internal view returns(uint32) { + function _getIndexOfOperatorForQuorumAtBlockNumber( + bytes32 operatorId, + uint8 quorumNumber, + uint32 blockNumber + ) internal view returns(uint32) { uint256 operatorIndexHistoryLength = _operatorIdToIndexHistory[operatorId][quorumNumber].length; // loop backward through index history to find the index of the operator at the given block number for (uint256 i = 0; i < operatorIndexHistoryLength; i++) { @@ -327,7 +337,10 @@ contract IndexRegistry is IndexRegistryStorage { } /// @notice Returns an ordered list of operators of the services for the given `quorumNumber` at the given `blockNumber` - function getOperatorListForQuorumAtBlockNumber(uint8 quorumNumber, uint32 blockNumber) external view returns (bytes32[] memory){ + function getOperatorListForQuorumAtBlockNumber( + uint8 quorumNumber, + uint32 blockNumber + ) external view returns (bytes32[] memory){ bytes32[] memory quorumOperatorList = new bytes32[](_getTotalOperatorsForQuorumAtBlockNumber(quorumNumber, blockNumber)); for (uint256 i = 0; i < globalOperatorList.length; i++) { bytes32 operatorId = globalOperatorList[i]; diff --git a/src/StakeRegistry.sol b/src/StakeRegistry.sol index f7bacc75..23dafeeb 100644 --- a/src/StakeRegistry.sol +++ b/src/StakeRegistry.sol @@ -429,7 +429,10 @@ contract StakeRegistry is StakeRegistryStorage { * @param operatorId The id of the operator of interest. * @param quorumNumber The quorum number to get the stake for. */ - function getOperatorIdToStakeHistory(bytes32 operatorId, uint8 quorumNumber) external view returns (OperatorStakeUpdate[] memory) { + function getOperatorIdToStakeHistory( + bytes32 operatorId, + uint8 quorumNumber + ) external view returns (OperatorStakeUpdate[] memory) { return operatorIdToStakeHistory[operatorId][quorumNumber]; } diff --git a/src/VoteWeigherBase.sol b/src/VoteWeigherBase.sol index a6907f29..fba20917 100644 --- a/src/VoteWeigherBase.sol +++ b/src/VoteWeigherBase.sol @@ -184,10 +184,10 @@ contract VoteWeigherBase is VoteWeigherBaseStorage { } /// @notice Returns the strategy and weight multiplier for the `index`'th strategy in the quorum `quorumNumber` - function strategyAndWeightingMultiplierForQuorumByIndex(uint8 quorumNumber, uint256 index) - public - view - returns (StrategyAndWeightingMultiplier memory) + function strategyAndWeightingMultiplierForQuorumByIndex( + uint8 quorumNumber, + uint256 index + ) public view returns (StrategyAndWeightingMultiplier memory) { return strategiesConsideredAndMultipliers[quorumNumber][index]; } @@ -196,7 +196,10 @@ contract VoteWeigherBase is VoteWeigherBaseStorage { * @notice This function computes the total weight of the @param operator in the quorum @param quorumNumber. * @dev reverts in the case that `quorumNumber` is greater than or equal to `quorumCount` */ - function weightOfOperatorForQuorumView(uint8 quorumNumber, address operator) public virtual view validQuorumNumber(quorumNumber) returns (uint96) { + function weightOfOperatorForQuorumView( + uint8 quorumNumber, + address operator + ) public virtual view validQuorumNumber(quorumNumber) returns (uint96) { uint96 weight; uint256 stratsLength = strategiesConsideredAndMultipliersLength(quorumNumber); StrategyAndWeightingMultiplier memory strategyAndMultiplier; @@ -226,7 +229,10 @@ contract VoteWeigherBase is VoteWeigherBaseStorage { * @dev reverts in the case that `quorumNumber` is greater than or equal to `quorumCount` * @dev a version of weightOfOperatorForQuorumView that can change state if needed */ - function weightOfOperatorForQuorum(uint8 quorumNumber, address operator) public virtual validQuorumNumber(quorumNumber) returns (uint96) { + function weightOfOperatorForQuorum( + uint8 quorumNumber, + address operator + ) public virtual validQuorumNumber(quorumNumber) returns (uint96) { return weightOfOperatorForQuorumView(quorumNumber, operator); } } From 534eef375bab9244c0eebd24a497cd9f8f906de3 Mon Sep 17 00:00:00 2001 From: wadealexc Date: Wed, 18 Oct 2023 15:52:31 +0000 Subject: [PATCH 4/8] Removed unused before/after hooks --- src/BLSPubkeyRegistry.sol | 33 ----- src/BLSRegistryCoordinatorWithIndices.sol | 35 ----- src/IndexRegistry.sol | 35 ----- src/StakeRegistry.sol | 171 +++++++--------------- 4 files changed, 54 insertions(+), 220 deletions(-) diff --git a/src/BLSPubkeyRegistry.sol b/src/BLSPubkeyRegistry.sol index 9ea9d7bb..cfa6e901 100644 --- a/src/BLSPubkeyRegistry.sol +++ b/src/BLSPubkeyRegistry.sol @@ -44,7 +44,6 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage { bytes memory quorumNumbers, BN254.G1Point memory pubkey ) external onlyRegistryCoordinator returns (bytes32) { - _beforeRegisterOperator(operator, quorumNumbers); //calculate hash of the operator's pubkey bytes32 pubkeyHash = BN254.hashG1Point(pubkey); @@ -57,7 +56,6 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage { // update each quorum's aggregate pubkey _processQuorumApkUpdate(quorumNumbers, pubkey); - _afterRegisterOperator(operator, quorumNumbers); // emit event so offchain actors can update their state emit OperatorAddedToQuorums(operator, quorumNumbers); return pubkeyHash; @@ -82,7 +80,6 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage { bytes memory quorumNumbers, BN254.G1Point memory pubkey ) external onlyRegistryCoordinator { - _beforeDeregisterOperator(operator, quorumNumbers); bytes32 pubkeyHash = BN254.hashG1Point(pubkey); require( @@ -93,8 +90,6 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage { // update each quorum's aggregate pubkey _processQuorumApkUpdate(quorumNumbers, pubkey.negate()); - _afterDeregisterOperator(operator, quorumNumbers); - emit OperatorRemovedFromQuorums(operator, quorumNumbers); } @@ -130,34 +125,6 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage { } } - /** - * @dev Hook that is called before any operator registration to insert additional logic. - * @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. - */ - function _beforeRegisterOperator(address operator, bytes memory quorumNumbers) internal virtual {} - - /** - * @dev Hook that is called after any operator registration to insert additional logic. - * @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. - */ - function _afterRegisterOperator(address operator, bytes memory quorumNumbers) internal virtual {} - - /** - * @dev Hook that is called before any operator deregistration to insert additional logic. - * @param operator The address of the operator to deregister. - * @param quorumNumbers The quorum numbers the operator is registering for, where each byte is an 8 bit integer quorumNumber. - */ - function _beforeDeregisterOperator(address operator, bytes memory quorumNumbers) internal virtual {} - - /** - * @dev Hook that is called after any operator deregistration to insert additional logic. - * @param operator The address of the operator to deregister. - * @param quorumNumbers The quorum numbers the operator is registering for, where each byte is an 8 bit integer quorumNumber. - */ - function _afterDeregisterOperator(address operator, bytes memory quorumNumbers) internal virtual {} - function _validateApkHashForQuorumAtBlockNumber(ApkUpdate memory apkUpdate, uint32 blockNumber) internal pure { require( blockNumber >= apkUpdate.updateBlockNumber, diff --git a/src/BLSRegistryCoordinatorWithIndices.sol b/src/BLSRegistryCoordinatorWithIndices.sol index 7228e2a0..313d65f3 100644 --- a/src/BLSRegistryCoordinatorWithIndices.sol +++ b/src/BLSRegistryCoordinatorWithIndices.sol @@ -349,7 +349,6 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr // "StakeRegistry._registerOperator: operator must be opted into slashing by the serviceManager" // ); - _beforeRegisterOperator(operator, quorumNumbers); // get the quorum bitmap from the quorum numbers uint256 quorumBitmap = BitmapUtils.orderedBytesArrayToBitmap(quorumNumbers); require(quorumBitmap <= MAX_QUORUM_BITMAP, "BLSRegistryCoordinatorWithIndices._registerOperatorWithCoordinator: quorumBitmap exceeds of max bitmap size"); @@ -397,8 +396,6 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr emit OperatorRegistered(operator, operatorId); } - _afterRegisterOperator(operator, quorumNumbers); - // record a stake update not bonding the operator at all (unbonded at 0), because they haven't served anything yet // serviceManager.recordFirstStakeUpdate(operator, 0); @@ -450,8 +447,6 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr // check if the operator is completely deregistering bool completeDeregistration = quorumBitmapBeforeUpdate == quorumsToRemoveBitmap; - - _beforeDeregisterOperator(operator, quorumNumbersToRemove); // deregister the operator from the BLSPubkeyRegistry blsPubkeyRegistry.deregisterOperator(operator, quorumNumbersToRemove, pubkey); @@ -462,8 +457,6 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr // deregister the operator from the IndexRegistry indexRegistry.deregisterOperator(operatorId, quorumNumbersToRemove, operatorIdsToSwap); - _afterDeregisterOperator(operator, quorumNumbersToRemove); - // set the toBlockNumber of the operator's quorum bitmap update _operatorIdToQuorumBitmapHistory[operatorId][operatorQuorumBitmapHistoryLengthMinusOne].nextUpdateBlockNumber = uint32(block.number); @@ -487,34 +480,6 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr } } - /** - * @dev Hook that is called before any operator registration to insert additional logic. - * @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. - */ - function _beforeRegisterOperator(address operator, bytes memory quorumNumbers) internal virtual{} - - /** - * @dev Hook that is called after any operator registration to insert additional logic. - * @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. - */ - function _afterRegisterOperator(address operator, bytes memory quorumNumbers) internal virtual {} - - /** - * @dev Hook that is called before any operator deregistration to insert additional logic. - * @param operator The address of the operator to deregister. - * @param quorumNumbers The quorum numbers the operator is registering for, where each byte is an 8 bit integer quorumNumber. - */ - function _beforeDeregisterOperator(address operator, bytes memory quorumNumbers) internal virtual {} - - /** - * @dev Hook that is called after any operator deregistration to insert additional logic. - * @param operator The address of the operator to deregister. - * @param quorumNumbers The quorum numbers the operator is registering for, where each byte is an 8 bit integer quorumNumber. - */ - function _afterDeregisterOperator(address operator, bytes memory quorumNumbers) internal virtual {} - /// @notice verifies churnApprover's signature on operator churn approval and increments the churnApprover nonce function _verifyChurnApproverSignatureOnOperatorChurnApproval( bytes32 registeringOperatorId, diff --git a/src/IndexRegistry.sol b/src/IndexRegistry.sol index d591036c..c32ea783 100644 --- a/src/IndexRegistry.sol +++ b/src/IndexRegistry.sol @@ -41,8 +41,6 @@ contract IndexRegistry is IndexRegistryStorage { bytes32 operatorId, bytes calldata quorumNumbers ) external onlyRegistryCoordinator returns(uint32[] memory) { - _beforeRegisterOperator(operatorId, quorumNumbers); - uint32[] memory numOperatorsPerQuorum = new uint32[](quorumNumbers.length); //add operator to operatorList globalOperatorList.push(operatorId); @@ -58,7 +56,6 @@ contract IndexRegistry is IndexRegistryStorage { numOperatorsPerQuorum[i] = numOperators + 1; } - _afterRegisterOperator(operatorId, quorumNumbers); return numOperatorsPerQuorum; } @@ -86,16 +83,12 @@ contract IndexRegistry is IndexRegistryStorage { "IndexRegistry.deregisterOperator: quorumNumbers and operatorIdsToSwap must be the same length" ); - _beforeDeregisterOperator(operatorId, quorumNumbers); - for (uint256 i = 0; i < quorumNumbers.length; i++) { uint8 quorumNumber = uint8(quorumNumbers[i]); uint32 indexOfOperatorToRemove = _operatorIdToIndexHistory[operatorId][quorumNumber][_operatorIdToIndexHistory[operatorId][quorumNumber].length - 1].index; _processOperatorRemoval(operatorId, quorumNumber, indexOfOperatorToRemove, operatorIdsToSwap[i]); _updateTotalOperatorHistory(quorumNumber, _totalOperatorsHistory[quorumNumber][_totalOperatorsHistory[quorumNumber].length - 1].index - 1); } - - _afterDeregisterOperator(operatorId, quorumNumbers); } /******************************************************************************* @@ -158,34 +151,6 @@ contract IndexRegistry is IndexRegistryStorage { _updateOperatorIdToIndexHistory(operatorId, quorumNumber, OPERATOR_DEREGISTERED_INDEX); } - /** - * @dev Hook that is called before any operator registration to insert additional logic. - * @param operatorId The id of the operator to register. - * @param quorumNumbers The quorum numbers the operator is registering for, where each byte is an 8 bit integer quorumNumber. - */ - function _beforeRegisterOperator(bytes32 operatorId, bytes memory quorumNumbers) internal virtual{} - - /** - * @dev Hook that is called after any operator registration to insert additional logic. - * @param operatorId The id of the operator to register. - * @param quorumNumbers The quorum numbers the operator is registering for, where each byte is an 8 bit integer quorumNumber. - */ - function _afterRegisterOperator(bytes32 operatorId, bytes memory quorumNumbers) internal virtual {} - - /** - * @dev Hook that is called before any operator deregistration to insert additional logic. - * @param operatorId The id of the operator to register. - * @param quorumNumbers The quorum numbers the operator is registering for, where each byte is an 8 bit integer quorumNumber. - */ - function _beforeDeregisterOperator(bytes32 operatorId, bytes memory quorumNumbers) internal virtual {} - - /** - * @dev Hook that is called after any operator deregistration to insert additional logic. - * @param operatorId The id of the operator to register. - * @param quorumNumbers The quorum numbers the operator is registering for, where each byte is an 8 bit integer quorumNumber. - */ - function _afterDeregisterOperator(bytes32 operatorId, bytes memory quorumNumbers) internal virtual {} - /** * @notice Returns the total number of operators of the service for the given `quorumNumber` at the given `blockNumber` * @dev Returns zero if the @param blockNumber is from before the @param quorumNumber existed, and returns the current number diff --git a/src/StakeRegistry.sol b/src/StakeRegistry.sol index 23dafeeb..80787d52 100644 --- a/src/StakeRegistry.sol +++ b/src/StakeRegistry.sol @@ -153,81 +153,6 @@ contract StakeRegistry is StakeRegistryStorage { bytes32 operatorId, bytes calldata quorumNumbers ) external virtual onlyRegistryCoordinator { - _beforeRegisterOperator(operator, operatorId, quorumNumbers); - - _registerOperator(operator, operatorId, quorumNumbers); - - _afterRegisterOperator(operator, operatorId, quorumNumbers); - } - - /** - * @notice Deregisters the operator with `operatorId` for the specified `quorumNumbers`. - * @param operatorId The id 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 - */ - function deregisterOperator( - bytes32 operatorId, - bytes calldata quorumNumbers - ) external virtual onlyRegistryCoordinator { - _beforeDeregisterOperator(operatorId, quorumNumbers); - - _deregisterOperator(operatorId, quorumNumbers); - - _afterDeregisterOperator(operatorId, quorumNumbers); - } - - /******************************************************************************* - EXTERNAL FUNCTIONS - SERVICE MANAGER OWNER - *******************************************************************************/ - - /// @notice Adjusts the `minimumStakeFirstQuorum` -- i.e. the node stake (weight) requirement for inclusion in the 1st quorum. - function setMinimumStakeForQuorum(uint8 quorumNumber, uint96 minimumStake) external onlyServiceManagerOwner { - _setMinimumStakeForQuorum(quorumNumber, minimumStake); - } - - /******************************************************************************* - INTERNAL FUNCTIONS - *******************************************************************************/ - - function _getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber( - bytes32 operatorId, - uint8 quorumNumber, - uint32 blockNumber - ) internal view returns (uint32) { - uint32 length = uint32(operatorIdToStakeHistory[operatorId][quorumNumber].length); - for (uint32 i = 0; i < length; i++) { - if (operatorIdToStakeHistory[operatorId][quorumNumber][length - i - 1].updateBlockNumber <= blockNumber) { - require( - operatorIdToStakeHistory[operatorId][quorumNumber][length - i - 1].nextUpdateBlockNumber == 0 || - operatorIdToStakeHistory[operatorId][quorumNumber][length - i - 1].nextUpdateBlockNumber > - blockNumber, - "StakeRegistry._getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber: operatorId has no stake update at blockNumber" - ); - return length - i - 1; - } - } - revert( - "StakeRegistry._getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber: no stake update found for operatorId and quorumNumber at block number" - ); - } - - function _setMinimumStakeForQuorum(uint8 quorumNumber, uint96 minimumStake) internal { - minimumStakeForQuorum[quorumNumber] = minimumStake; - emit MinimumStakeForQuorumUpdated(quorumNumber, minimumStake); - } - - /** - * @notice Updates the stake for the operator with `operatorId` for the specified `quorumNumbers`. The total stake - * for each quorum is updated accordingly in addition to the operator's individual stake history. - */ - function _registerOperator(address operator, bytes32 operatorId, bytes memory quorumNumbers) internal { // check the operator is registering for only valid quorums require( uint8(quorumNumbers[quorumNumbers.length - 1]) < quorumCount, @@ -267,11 +192,21 @@ contract StakeRegistry is StakeRegistryStorage { } /** - * @notice Removes the stakes of the operator with `operatorId` from the quorums specified in `quorumNumbers` - * the total stake of the quorums specified in `quorumNumbers` will be updated and so will the operator's individual - * stake updates. These operator's individual stake updates will have a 0 stake value for the latest update. + * @notice Deregisters the operator with `operatorId` for the specified `quorumNumbers`. + * @param operatorId The id 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 */ - function _deregisterOperator(bytes32 operatorId, bytes memory quorumNumbers) internal { + function deregisterOperator( + bytes32 operatorId, + bytes calldata quorumNumbers + ) external virtual onlyRegistryCoordinator { OperatorStakeUpdate memory _operatorStakeUpdate; // add the `updateBlockNumber` info _operatorStakeUpdate.updateBlockNumber = uint32(block.number); @@ -303,6 +238,46 @@ contract StakeRegistry is StakeRegistryStorage { } } + /******************************************************************************* + EXTERNAL FUNCTIONS - SERVICE MANAGER OWNER + *******************************************************************************/ + + /// @notice Adjusts the `minimumStakeFirstQuorum` -- i.e. the node stake (weight) requirement for inclusion in the 1st quorum. + function setMinimumStakeForQuorum(uint8 quorumNumber, uint96 minimumStake) external onlyServiceManagerOwner { + _setMinimumStakeForQuorum(quorumNumber, minimumStake); + } + + /******************************************************************************* + INTERNAL FUNCTIONS + *******************************************************************************/ + + function _getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber( + bytes32 operatorId, + uint8 quorumNumber, + uint32 blockNumber + ) internal view returns (uint32) { + uint32 length = uint32(operatorIdToStakeHistory[operatorId][quorumNumber].length); + for (uint32 i = 0; i < length; i++) { + if (operatorIdToStakeHistory[operatorId][quorumNumber][length - i - 1].updateBlockNumber <= blockNumber) { + require( + operatorIdToStakeHistory[operatorId][quorumNumber][length - i - 1].nextUpdateBlockNumber == 0 || + operatorIdToStakeHistory[operatorId][quorumNumber][length - i - 1].nextUpdateBlockNumber > + blockNumber, + "StakeRegistry._getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber: operatorId has no stake update at blockNumber" + ); + return length - i - 1; + } + } + revert( + "StakeRegistry._getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber: no stake update found for operatorId and quorumNumber at block number" + ); + } + + function _setMinimumStakeForQuorum(uint8 quorumNumber, uint96 minimumStake) internal { + minimumStakeForQuorum[quorumNumber] = minimumStake; + emit MinimumStakeForQuorumUpdated(quorumNumber, minimumStake); + } + /** * @notice Finds the updated stake for `operator` for `quorumNumber`, stores it, records the update, * and returns both the previous stake then updated stake. @@ -367,44 +342,6 @@ contract StakeRegistry is StakeRegistryStorage { _totalStakeHistory[quorumNumber].push(_totalStake); } - /** - * @dev Hook that is called before any operator registration to insert additional logic. - * @param operator The address of the operator to register. - * @param operatorId The id of the operator to register. - * @param quorumNumbers The quorum numbers the operator is registering for, where each byte is an 8 bit integer quorumNumber. - */ - function _beforeRegisterOperator( - address operator, - bytes32 operatorId, - bytes memory quorumNumbers - ) internal virtual {} - - /** - * @dev Hook that is called after any operator registration to insert additional logic. - * @param operator The address of the operator to register. - * @param operatorId The id of the operator to register. - * @param quorumNumbers The quorum numbers the operator is registering for, where each byte is an 8 bit integer quorumNumber. - */ - function _afterRegisterOperator( - address operator, - bytes32 operatorId, - bytes memory quorumNumbers - ) internal virtual {} - - /** - * @dev Hook that is called before any operator deregistration to insert additional logic. - * @param operatorId The id of the operator to register. - * @param quorumNumbers The quorum numbers the operator is registering for, where each byte is an 8 bit integer quorumNumber. - */ - function _beforeDeregisterOperator(bytes32 operatorId, bytes memory quorumNumbers) internal virtual {} - - /** - * @dev Hook that is called after any operator deregistration to insert additional logic. - * @param operatorId The id of the operator to register. - * @param quorumNumbers The quorum numbers the operator is registering for, where each byte is an 8 bit integer quorumNumber. - */ - function _afterDeregisterOperator(bytes32 operatorId, bytes memory quorumNumbers) internal virtual {} - /// @notice Validates that the `operatorStake` was accurate at the given `blockNumber` function _validateOperatorStakeUpdateAtBlockNumber( OperatorStakeUpdate memory operatorStakeUpdate, From 92d7f73b1c5991388a1e3ba03a6a46c73f36d8b5 Mon Sep 17 00:00:00 2001 From: wadealexc Date: Wed, 18 Oct 2023 15:58:16 +0000 Subject: [PATCH 5/8] Fixed broken test --- test/harnesses/StakeRegistryHarness.sol | 38 ++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/test/harnesses/StakeRegistryHarness.sol b/test/harnesses/StakeRegistryHarness.sol index f82aeae0..4cc8be9d 100644 --- a/test/harnesses/StakeRegistryHarness.sol +++ b/test/harnesses/StakeRegistryHarness.sol @@ -37,7 +37,43 @@ contract StakeRegistryHarness is StakeRegistry { } // mocked function to register an operator without having to mock other elements + // This is just a copy/paste from `registerOperator`, since that no longer uses an internal method function registerOperatorNonCoordinator(address operator, bytes32 operatorId, bytes calldata quorumNumbers) external { - _registerOperator(operator, operatorId, quorumNumbers); + // check the operator is registering for only valid quorums + require( + uint8(quorumNumbers[quorumNumbers.length - 1]) < quorumCount, + "StakeRegistry._registerOperator: greatest quorumNumber must be less than quorumCount" + ); + OperatorStakeUpdate memory _newTotalStakeUpdate; + // add the `updateBlockNumber` info + _newTotalStakeUpdate.updateBlockNumber = uint32(block.number); + // for each quorum, evaluate stake and add to total stake + for (uint8 quorumNumbersIndex = 0; quorumNumbersIndex < quorumNumbers.length; ) { + // get the next quorumNumber + uint8 quorumNumber = uint8(quorumNumbers[quorumNumbersIndex]); + // evaluate the stake for the operator + // since we don't use the first output, this will use 1 extra sload when deregistered operator's register again + (, uint96 stake) = _updateOperatorStake(operator, operatorId, quorumNumber); + // check if minimum requirement has been met, will be 0 if not + require( + stake != 0, + "StakeRegistry._registerOperator: Operator does not meet minimum stake requirement for quorum" + ); + // add operator stakes to total stake before update (in memory) + uint256 _totalStakeHistoryLength = _totalStakeHistory[quorumNumber].length; + // add calculate the total stake for the quorum + uint96 totalStakeAfterUpdate = stake; + if (_totalStakeHistoryLength != 0) { + // only add the stake if there is a previous total stake + // overwrite `stake` variable + totalStakeAfterUpdate += _totalStakeHistory[quorumNumber][_totalStakeHistoryLength - 1].stake; + } + _newTotalStakeUpdate.stake = totalStakeAfterUpdate; + // update storage of total stake + _recordTotalStakeUpdate(quorumNumber, _newTotalStakeUpdate); + unchecked { + ++quorumNumbersIndex; + } + } } } From c3ed18494bcec999b077a4a73745a55297b38566 Mon Sep 17 00:00:00 2001 From: wadealexc Date: Wed, 18 Oct 2023 16:21:09 +0000 Subject: [PATCH 6/8] Change a lot of internal function calls to use explicit param syntax to reduce line length and be consistent with our other repo --- src/BLSRegistryCoordinatorWithIndices.sol | 68 ++++++++++++++++++----- src/IndexRegistry.sol | 35 ++++++++++-- src/StakeRegistry.sol | 28 +++++++--- 3 files changed, 103 insertions(+), 28 deletions(-) diff --git a/src/BLSRegistryCoordinatorWithIndices.sol b/src/BLSRegistryCoordinatorWithIndices.sol index 313d65f3..69d9df5f 100644 --- a/src/BLSRegistryCoordinatorWithIndices.sol +++ b/src/BLSRegistryCoordinatorWithIndices.sol @@ -138,7 +138,12 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr // get the operator's BLS public key (BN254.G1Point memory pubkey, string memory socket) = abi.decode(registrationData, (BN254.G1Point, string)); // call internal function to register the operator - _registerOperatorWithCoordinatorAndNoOverfilledQuorums(msg.sender, quorumNumbers, pubkey, socket); + _registerOperatorWithCoordinatorAndNoOverfilledQuorums({ + operator: msg.sender, + quorumNumbers: quorumNumbers, + pubkey: pubkey, + socket: socket + }); } /** @@ -152,7 +157,12 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr BN254.G1Point memory pubkey, string calldata socket ) external onlyWhenNotPaused(PAUSED_REGISTER_OPERATOR) { - _registerOperatorWithCoordinatorAndNoOverfilledQuorums(msg.sender, quorumNumbers, pubkey, socket); + _registerOperatorWithCoordinatorAndNoOverfilledQuorums({ + operator: msg.sender, + quorumNumbers: quorumNumbers, + pubkey: pubkey, + socket: socket + }); } /** @@ -173,14 +183,23 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr SignatureWithSaltAndExpiry memory signatureWithSaltAndExpiry ) external onlyWhenNotPaused(PAUSED_REGISTER_OPERATOR) { // register the operator - uint32[] memory numOperatorsPerQuorum = _registerOperatorWithCoordinator(msg.sender, quorumNumbers, pubkey, socket); + uint32[] memory numOperatorsPerQuorum = _registerOperatorWithCoordinator({ + operator: msg.sender, + quorumNumbers: quorumNumbers, + pubkey: pubkey, + socket: socket + }); // get the registering operator's operatorId and set the operatorIdsToSwap to it because the registering operator is the one with the greatest index bytes32[] memory operatorIdsToSwap = new bytes32[](1); operatorIdsToSwap[0] = pubkey.hashG1Point(); // verify the churnApprover's signature - _verifyChurnApproverSignatureOnOperatorChurnApproval(operatorIdsToSwap[0], operatorKickParams, signatureWithSaltAndExpiry); + _verifyChurnApproverSignatureOnOperatorChurnApproval({ + registeringOperatorId: operatorIdsToSwap[0], + operatorKickParams: operatorKickParams, + signatureWithSaltAndExpiry: signatureWithSaltAndExpiry + }); uint256 operatorToKickParamsIndex = 0; // kick the operators @@ -223,12 +242,12 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr } // kick the operator - _deregisterOperatorWithCoordinator( - operatorKickParams[i].operator, - quorumNumbers[i:i+1], - operatorKickParams[i].pubkey, - operatorIdsToSwap - ); + _deregisterOperatorWithCoordinator({ + operator: operatorKickParams[0].operator, + quorumNumbers: quorumNumbers[i:i+1], + pubkey: operatorKickParams[i].pubkey, + operatorIdsToSwap: operatorIdsToSwap + }); } } @@ -246,7 +265,12 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr (BN254.G1Point memory pubkey, bytes32[] memory operatorIdsToSwap) = abi.decode(deregistrationData, (BN254.G1Point, bytes32[])); // call internal function to deregister the operator - _deregisterOperatorWithCoordinator(msg.sender, quorumNumbers, pubkey, operatorIdsToSwap); + _deregisterOperatorWithCoordinator({ + operator: msg.sender, + quorumNumbers: quorumNumbers, + pubkey: pubkey, + operatorIdsToSwap: operatorIdsToSwap + }); } /** @@ -263,7 +287,12 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr BN254.G1Point memory pubkey, bytes32[] memory operatorIdsToSwap ) external onlyWhenNotPaused(PAUSED_DEREGISTER_OPERATOR) { - _deregisterOperatorWithCoordinator(msg.sender, quorumNumbers, pubkey, operatorIdsToSwap); + _deregisterOperatorWithCoordinator({ + operator: msg.sender, + quorumNumbers: quorumNumbers, + pubkey: pubkey, + operatorIdsToSwap: operatorIdsToSwap + }); } /** @@ -295,7 +324,12 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr BN254.G1Point memory pubkey, bytes32[] memory operatorIdsToSwap ) external onlyEjector { - _deregisterOperatorWithCoordinator(operator, quorumNumbers, pubkey, operatorIdsToSwap); + _deregisterOperatorWithCoordinator({ + operator: operator, + quorumNumbers: quorumNumbers, + pubkey: pubkey, + operatorIdsToSwap: operatorIdsToSwap + }); } /******************************************************************************* @@ -410,7 +444,13 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr BN254.G1Point memory pubkey, string memory socket ) internal { - uint32[] memory numOperatorsPerQuorum = _registerOperatorWithCoordinator(operator, quorumNumbers, pubkey, socket); + uint32[] memory numOperatorsPerQuorum = _registerOperatorWithCoordinator({ + operator: operator, + quorumNumbers: quorumNumbers, + pubkey: pubkey, + socket: socket + }); + for (uint i = 0; i < numOperatorsPerQuorum.length; i++) { require( numOperatorsPerQuorum[i] <= _quorumOperatorSetParams[uint8(quorumNumbers[i])].maxOperatorCount, diff --git a/src/IndexRegistry.sol b/src/IndexRegistry.sol index c32ea783..31cccc9e 100644 --- a/src/IndexRegistry.sol +++ b/src/IndexRegistry.sol @@ -51,8 +51,15 @@ contract IndexRegistry is IndexRegistryStorage { //this is the would-be index of the operator being registered, the total number of operators for that quorum (which is last index + 1) uint256 quorumHistoryLength = _totalOperatorsHistory[quorumNumber].length; uint32 numOperators = quorumHistoryLength > 0 ? _totalOperatorsHistory[quorumNumber][quorumHistoryLength - 1].index : 0; - _updateOperatorIdToIndexHistory(operatorId, quorumNumber, numOperators); - _updateTotalOperatorHistory(quorumNumber, numOperators + 1); + _updateOperatorIdToIndexHistory({ + operatorId: operatorId, + quorumNumber: quorumNumber, + index: numOperators + }); + _updateTotalOperatorHistory({ + quorumNumber: quorumNumber, + numOperators: numOperators + 1 + }); numOperatorsPerQuorum[i] = numOperators + 1; } @@ -86,8 +93,16 @@ contract IndexRegistry is IndexRegistryStorage { for (uint256 i = 0; i < quorumNumbers.length; i++) { uint8 quorumNumber = uint8(quorumNumbers[i]); uint32 indexOfOperatorToRemove = _operatorIdToIndexHistory[operatorId][quorumNumber][_operatorIdToIndexHistory[operatorId][quorumNumber].length - 1].index; - _processOperatorRemoval(operatorId, quorumNumber, indexOfOperatorToRemove, operatorIdsToSwap[i]); - _updateTotalOperatorHistory(quorumNumber, _totalOperatorsHistory[quorumNumber][_totalOperatorsHistory[quorumNumber].length - 1].index - 1); + _processOperatorRemoval({ + operatorId: operatorId, + quorumNumber: quorumNumber, + indexOfOperatorToRemove: indexOfOperatorToRemove, + operatorIdToSwap: operatorIdsToSwap[i] + }); + _updateTotalOperatorHistory({ + quorumNumber: quorumNumber, + numOperators: _totalOperatorsHistory[quorumNumber][_totalOperatorsHistory[quorumNumber].length - 1].index - 1 + }); } } @@ -144,11 +159,19 @@ contract IndexRegistry is IndexRegistryStorage { // if the operator is not the last in the list, we must swap the last operator into their positon if (operatorId != operatorIdToSwap) { //update the swapped operator's operatorIdToIndexHistory list with a new entry, as their index has now changed - _updateOperatorIdToIndexHistory(operatorIdToSwap, quorumNumber, indexOfOperatorToRemove); + _updateOperatorIdToIndexHistory({ + operatorId: operatorIdToSwap, + quorumNumber: quorumNumber, + index: indexOfOperatorToRemove + }); } // marking the final entry in the deregistering operator's operatorIdToIndexHistory entry with the deregistration block number, // setting the index to OPERATOR_DEREGISTERED_INDEX. Note that this is a special meaning, and any other index value represents a real index - _updateOperatorIdToIndexHistory(operatorId, quorumNumber, OPERATOR_DEREGISTERED_INDEX); + _updateOperatorIdToIndexHistory({ + operatorId: operatorId, + quorumNumber: quorumNumber, + index: OPERATOR_DEREGISTERED_INDEX + }); } /** diff --git a/src/StakeRegistry.sol b/src/StakeRegistry.sol index 80787d52..a2cf32d0 100644 --- a/src/StakeRegistry.sol +++ b/src/StakeRegistry.sol @@ -101,11 +101,11 @@ contract StakeRegistry is StakeRegistryStorage { ]; } // update the operator's stake based on current state - (uint96 stakeBeforeUpdate, uint96 stakeAfterUpdate) = _updateOperatorStake( - operators[i], - operatorId, - quorumNumber - ); + (uint96 stakeBeforeUpdate, uint96 stakeAfterUpdate) = _updateOperatorStake({ + operator: operators[i], + operatorId: operatorId, + quorumNumber: quorumNumber + }); // calculate the new total stake for the quorum totalStakeUpdate.stake = totalStakeUpdate.stake - stakeBeforeUpdate + stakeAfterUpdate; } @@ -167,7 +167,11 @@ contract StakeRegistry is StakeRegistryStorage { uint8 quorumNumber = uint8(quorumNumbers[quorumNumbersIndex]); // evaluate the stake for the operator // since we don't use the first output, this will use 1 extra sload when deregistered operator's register again - (, uint96 stake) = _updateOperatorStake(operator, operatorId, quorumNumber); + (, uint96 stake) = _updateOperatorStake({ + operator: operator, + operatorId: operatorId, + quorumNumber: quorumNumber + }); // check if minimum requirement has been met, will be 0 if not require( stake != 0, @@ -217,7 +221,11 @@ contract StakeRegistry is StakeRegistryStorage { for (uint8 quorumNumbersIndex = 0; quorumNumbersIndex < quorumNumbers.length; ) { uint8 quorumNumber = uint8(quorumNumbers[quorumNumbersIndex]); // update the operator's stake - uint96 stakeBeforeUpdate = _recordOperatorStakeUpdate(operatorId, quorumNumber, _operatorStakeUpdate); + uint96 stakeBeforeUpdate = _recordOperatorStakeUpdate({ + operatorId: operatorId, + quorumNumber: quorumNumber, + operatorStakeUpdate: _operatorStakeUpdate + }); // subtract the amounts staked by the operator that is getting deregistered from the total stake before deregistration // copy latest totalStakes to memory _newTotalStakeUpdate.stake = @@ -299,7 +307,11 @@ contract StakeRegistry is StakeRegistryStorage { operatorStakeUpdate.stake = uint96(0); } // get stakeBeforeUpdate and update with new stake - uint96 stakeBeforeUpdate = _recordOperatorStakeUpdate(operatorId, quorumNumber, operatorStakeUpdate); + uint96 stakeBeforeUpdate = _recordOperatorStakeUpdate({ + operatorId: operatorId, + quorumNumber: quorumNumber, + operatorStakeUpdate: operatorStakeUpdate + }); emit StakeUpdate(operatorId, quorumNumber, operatorStakeUpdate.stake); From 3da5e124e629e54428e449cf29a34442202cb989 Mon Sep 17 00:00:00 2001 From: wadealexc Date: Wed, 18 Oct 2023 16:25:43 +0000 Subject: [PATCH 7/8] Removed unneeded View function --- src/VoteWeigherBase.sol | 14 +------------- src/interfaces/IVoteWeigher.sol | 9 +-------- test/EigenLayerTestHelper.t.sol | 8 ++++---- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/src/VoteWeigherBase.sol b/src/VoteWeigherBase.sol index fba20917..0be3d60e 100644 --- a/src/VoteWeigherBase.sol +++ b/src/VoteWeigherBase.sol @@ -196,7 +196,7 @@ contract VoteWeigherBase is VoteWeigherBaseStorage { * @notice This function computes the total weight of the @param operator in the quorum @param quorumNumber. * @dev reverts in the case that `quorumNumber` is greater than or equal to `quorumCount` */ - function weightOfOperatorForQuorumView( + function weightOfOperatorForQuorum( uint8 quorumNumber, address operator ) public virtual view validQuorumNumber(quorumNumber) returns (uint96) { @@ -223,16 +223,4 @@ contract VoteWeigherBase is VoteWeigherBaseStorage { return weight; } - - /** - * @notice This function computes the total weight of the @param operator in the quorum @param quorumNumber. - * @dev reverts in the case that `quorumNumber` is greater than or equal to `quorumCount` - * @dev a version of weightOfOperatorForQuorumView that can change state if needed - */ - function weightOfOperatorForQuorum( - uint8 quorumNumber, - address operator - ) public virtual validQuorumNumber(quorumNumber) returns (uint96) { - return weightOfOperatorForQuorumView(quorumNumber, operator); - } } diff --git a/src/interfaces/IVoteWeigher.sol b/src/interfaces/IVoteWeigher.sol index 886ccd6a..1059eccc 100644 --- a/src/interfaces/IVoteWeigher.sol +++ b/src/interfaces/IVoteWeigher.sol @@ -48,14 +48,7 @@ interface IVoteWeigher { * @notice This function computes the total weight of the @param operator in the quorum @param quorumNumber. * @dev reverts in the case that `quorumNumber` is greater than or equal to `quorumCount` */ - function weightOfOperatorForQuorumView(uint8 quorumNumber, address operator) external view returns (uint96); - - /** - * @notice This function computes the total weight of the @param operator in the quorum @param quorumNumber. - * @dev reverts in the case that `quorumNumber` is greater than or equal to `quorumCount` - * @dev a version of weightOfOperatorForQuorumView that can change state if needed - */ - function weightOfOperatorForQuorum(uint8 quorumNumber, address operator) external returns (uint96); + function weightOfOperatorForQuorum(uint8 quorumNumber, address operator) external view returns (uint96); /// @notice Number of quorums that are being used by the middleware. function quorumCount() external view returns (uint16); diff --git a/test/EigenLayerTestHelper.t.sol b/test/EigenLayerTestHelper.t.sol index 33e4b340..325986b6 100644 --- a/test/EigenLayerTestHelper.t.sol +++ b/test/EigenLayerTestHelper.t.sol @@ -363,8 +363,8 @@ contract EigenLayerTestHelper is EigenLayerDeployer { } uint256[3] memory amountsBefore; - amountsBefore[0] = stakeRegistry.weightOfOperatorForQuorumView(0, operator); - amountsBefore[1] = stakeRegistry.weightOfOperatorForQuorumView(1, operator); + amountsBefore[0] = stakeRegistry.weightOfOperatorForQuorum(0, operator); + amountsBefore[1] = stakeRegistry.weightOfOperatorForQuorum(1, operator); amountsBefore[2] = delegation.operatorShares(operator, wethStrat); //making additional deposits to the strategies @@ -381,8 +381,8 @@ contract EigenLayerTestHelper is EigenLayerDeployer { uint256 stakerEthWeight = strategyManager.stakerStrategyShares(staker, updatedStrategies[0]); uint256 stakerEigenWeight = strategyManager.stakerStrategyShares(staker, updatedStrategies[1]); - uint256 operatorEthWeightAfter = stakeRegistry.weightOfOperatorForQuorumView(0, operator); - uint256 operatorEigenWeightAfter = stakeRegistry.weightOfOperatorForQuorumView(1, operator); + uint256 operatorEthWeightAfter = stakeRegistry.weightOfOperatorForQuorum(0, operator); + uint256 operatorEigenWeightAfter = stakeRegistry.weightOfOperatorForQuorum(1, operator); assertTrue( operatorEthWeightAfter - amountsBefore[0] == stakerEthWeight, From c143a899ca466d92713b711e5e963dc0bd991a39 Mon Sep 17 00:00:00 2001 From: ChaoticWalrus <93558947+ChaoticWalrus@users.noreply.github.com> Date: Wed, 18 Oct 2023 12:40:42 -0700 Subject: [PATCH 8/8] copy license file from core repo modified the "licensed work" title to better reflect this repo. otherwise the license remains unchanged. --- LICENSE | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..15a4fb79 --- /dev/null +++ b/LICENSE @@ -0,0 +1,98 @@ +Business Source License 1.1 + +License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. +"Business Source License" is a trademark of MariaDB Corporation Ab. + +----------------------------------------------------------------------------- + +Parameters + +Licensor: Layr Labs, Inc. + +Licensed Work: EigenLayer Middleware Contracts + The Licensed Work is (c) 2023 Layr Labs, Inc. + +Additional Use Grant: None. + +Change Date: 2025-05-01 (May 1st, 2025) + +Change License: MIT + +----------------------------------------------------------------------------- + +Terms + +The Licensor hereby grants you the right to copy, modify, create derivative +works, redistribute, and make non-production use of the Licensed Work. The +Licensor may make an Additional Use Grant, above, permitting limited +production use. + +Effective on the Change Date, or the fourth anniversary of the first publicly +available distribution of a specific version of the Licensed Work under this +License, whichever comes first, the Licensor hereby grants you rights under +the terms of the Change License, and the rights granted in the paragraph +above terminate. + +If your use of the Licensed Work does not comply with the requirements +currently in effect as described in this License, you must purchase a +commercial license from the Licensor, its affiliated entities, or authorized +resellers, or you must refrain from using the Licensed Work. + +All copies of the original and modified Licensed Work, and derivative works +of the Licensed Work, are subject to this License. This License applies +separately for each version of the Licensed Work and the Change Date may vary +for each version of the Licensed Work released by Licensor. + +You must conspicuously display this License on each original or modified copy +of the Licensed Work. If you receive the Licensed Work in original or +modified form from a third party, the terms and conditions set forth in this +License apply to your use of that work. + +Any use of the Licensed Work in violation of this License will automatically +terminate your rights under this License for the current and all other +versions of the Licensed Work. + +This License does not grant you any right in any trademark or logo of +Licensor or its affiliates (provided that you may use a trademark or logo of +Licensor as expressly required by this License). + +TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +TITLE. + +MariaDB hereby grants you permission to use this License’s text to license +your works, and to refer to it using the trademark "Business Source License", +as long as you comply with the Covenants of Licensor below. + +----------------------------------------------------------------------------- + +Covenants of Licensor + +In consideration of the right to use this License’s text and the "Business +Source License" name and trademark, Licensor covenants to MariaDB, and to all +other recipients of the licensed work to be provided by Licensor: + +1. To specify as the Change License the GPL Version 2.0 or any later version, + or a license that is compatible with GPL Version 2.0 or a later version, + where "compatible" means that software provided under the Change License can + be included in a program with software provided under GPL Version 2.0 or a + later version. Licensor may specify additional Change Licenses without + limitation. + +2. To either: (a) specify an additional grant of rights to use that does not + impose any additional restriction on the right granted in this License, as + the Additional Use Grant; or (b) insert the text "None". + +3. To specify a Change Date. + +4. Not to modify this License in any other way. + +----------------------------------------------------------------------------- + +Notice + +The Business Source License (this document, or the "License") is not an Open +Source license. However, the Licensed Work will eventually be made available +under an Open Source License, as stated in this License.