From 34ba0d7bc24a2726e8f17bfdb49b63fb3efb0727 Mon Sep 17 00:00:00 2001 From: kaitaowu Date: Mon, 10 Jun 2024 23:25:52 -0700 Subject: [PATCH] Rebase --- README.md | 9 - script/ServiceManagerRouterDeploy.s.sol | 8 - src/RegistryCoordinator.sol | 24 +- src/ServiceManagerBase.sol | 169 +----- src/interfaces/IServiceManager.sol | 24 +- test/ffi/UpdateOperators.t.sol | 8 - test/integration/CoreRegistration.t.sol | 51 -- test/integration/IntegrationDeployer.t.sol | 28 - test/mocks/AVSDirectoryMock.sol | 4 - test/mocks/ServiceManagerMock.sol | 13 - test/tree/BLSSignatureCheckerUnit.tree | 8 - test/unit/BLSApkRegistryUnit.t.sol | 651 +-------------------- test/unit/BLSSignatureCheckerUnit.t.sol | 47 -- test/unit/OperatorStateRetrieverUnit.t.sol | 8 - test/utils/MockAVSDeployer.sol | 48 -- 15 files changed, 36 insertions(+), 1064 deletions(-) diff --git a/README.md b/README.md index 08513afb..5a752928 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,6 @@ EigenLayer is a set of smart contracts deployed on Ethereum that enable restaking of assets to secure new services called AVSs (actively validated services). The core contracts that enable these features can be found in the [`eigenlayer-contracts` repo][core-repo]. -<<<<<<< HEAD -======= -This repo contains smart contracts used to create an AVS that interacts with the EigenLayer core contracts. Because these contracts are meant to be used by any AVS, there is no single deployment. However, you can see EigenDA's deployment info on our [docs site](https://docs.eigenlayer.xyz/eigenda/deployed-contracts). - ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) ## Getting Started * [Branching](#branching) @@ -49,7 +44,6 @@ foundryup forge build forge test -<<<<<<< HEAD ``` ## Deployments @@ -86,6 +80,3 @@ The current testnet deployment is on holesky, is from our M2 beta release. You c [`ProxyAdmin`](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.7.1/contracts/proxy/transparent/ProxyAdmin.sol) | - | [`0xB043...5c15`](https://holesky.etherscan.io/address/0xB043055dd967A382577c2f5261fA6428f2905c15) | | [`eigenda/EigenDAServiceManager`](https://github.com/Layr-Labs/eigenda/blob/a33b41561cc3fb4cd6d50a8738e4c5dca43ec0a5/contracts/src/core/EigenDAServiceManager.sol) | [`0xD4A7E1Bd8015057293f0D0A557088c286942e84b`](https://holesky.etherscan.io/address/0xD4A7E1Bd8015057293f0D0A557088c286942e84b) | [`0xa722...67f3`](https://holesky.etherscan.io/address/0xa7227485e6C693AC4566fe168C5E3647c5c267f3) | Proxy: [`TUP@4.7.1`](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.7.1/contracts/proxy/transparent/TransparentUpgradeableProxy.sol) | -======= -``` ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) diff --git a/script/ServiceManagerRouterDeploy.s.sol b/script/ServiceManagerRouterDeploy.s.sol index c76b40e2..6a61a796 100644 --- a/script/ServiceManagerRouterDeploy.s.sol +++ b/script/ServiceManagerRouterDeploy.s.sol @@ -1,9 +1,5 @@ // SPDX-License-Identifier: BUSL-1.1 -<<<<<<< HEAD pragma solidity ^0.8.12; -======= -pragma solidity =0.8.12; ->>>>>>> Feat: service manager router (#193) import {ServiceManagerRouter} from "../src/ServiceManagerRouter.sol"; import "forge-std/Script.sol"; @@ -16,8 +12,4 @@ contract ServiceManagerRouterDeploy is Script { vm.stopBroadcast(); } -<<<<<<< HEAD } -======= -} ->>>>>>> Feat: service manager router (#193) diff --git a/src/RegistryCoordinator.sol b/src/RegistryCoordinator.sol index 7cd5c475..e13bcbab 100644 --- a/src/RegistryCoordinator.sol +++ b/src/RegistryCoordinator.sol @@ -154,11 +154,8 @@ contract RegistryCoordinator is quorumNumbers: quorumNumbers, socket: socket, operatorSignature: operatorSignature, -<<<<<<< HEAD operatorSignAddr: operatorSignatureAddr -======= params: params ->>>>>>> Check and update BLS and ECDSA key whenever starting operator }).numOperatorsPerQuorum; // For each quorum, validate that the new operator count does not exceed the maximum @@ -220,11 +217,8 @@ contract RegistryCoordinator is quorumNumbers: quorumNumbers, socket: socket, operatorSignature: operatorSignature, -<<<<<<< HEAD operatorSignAddr: msg.sender -======= params: params ->>>>>>> Check and update BLS and ECDSA key whenever starting operator }); // Check that each quorum's operator count is below the configured maximum. If the max @@ -481,11 +475,8 @@ contract RegistryCoordinator is bytes calldata quorumNumbers, string memory socket, SignatureWithSaltAndExpiry memory operatorSignature, -<<<<<<< HEAD address operatorSignAddr -======= IBLSApkRegistry.PubkeyRegistrationParams calldata params ->>>>>>> Check and update BLS and ECDSA key whenever starting operator ) internal virtual returns (RegisterResults memory results) { /** * Get bitmap of quorums to register for and operator's current bitmap. Validate that: @@ -965,7 +956,7 @@ contract RegistryCoordinator is return OwnableUpgradeable.owner(); } - function updateBLSPublicKey(IBLSApkRegistry.PubkeyRegistrationParams calldata params) external override { + function updateBLSPublicKey(IBLSApkRegistry.PubkeyRegistrationParams calldata params) external override onlyWhenNotPaused(PAUSED_REGISTER_OPERATOR){ address operator = msg.sender; bytes32 operatorId = blsApkRegistry.getOperatorId(operator); require(operatorId != bytes32(0), "RegistryCoordinator.updateBLSPublicKey: operator is not registered"); @@ -973,4 +964,17 @@ contract RegistryCoordinator is bytes memory quorumsToUpdate = BitmapUtils.bitmapToBytesArray(currentBitmap); blsApkRegistry.updateBLSPublicKey(operator, quorumsToUpdate, params, pubkeyRegistrationMessageHash(operator)); } + + function updateOperatorSignAddr(address signAddr) external override onlyWhenNotPaused(PAUSED_REGISTER_OPERATOR){ + address operator = msg.sender; + bytes32 operatorId = blsApkRegistry.getOperatorId(operator); + require(_operatorInfo[operator].status == OperatorStatus.REGISTERED, "RegistryCoordinator.updateOperatorSignAddr: operator is not registered"); + stakeRegistry.updateOperatorSignAddr(operator, signAddr); + } + + function getOperatorBlsKeyAndSignAddr(address operator) external override view returns (OperatorBlsKeyAndSigner memory) { + (BN254.G1Point memory pubKey, bytes32 pubKeyHash) = blsApkRegistry.getRegisteredPubkey(operator); + address signAddr = stakeRegistry.getOperatorSignAddress(operator); + return OperatorBlsKeyAndSigner(pubKey, pubKeyHash, signAddr); + } } diff --git a/src/ServiceManagerBase.sol b/src/ServiceManagerBase.sol index fa51601b..4b7aaf74 100644 --- a/src/ServiceManagerBase.sol +++ b/src/ServiceManagerBase.sol @@ -5,10 +5,7 @@ import {OwnableUpgradeable} from "@openzeppelin-upgrades/contracts/access/Ownabl import {Initializable} from "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol"; import {ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/ISignatureUtils.sol"; import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol"; -<<<<<<< HEAD import {IRewardsCoordinator} from "eigenlayer-contracts/src/contracts/interfaces/IRewardsCoordinator.sol"; -======= ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) import {ServiceManagerBaseStorage} from "./ServiceManagerBaseStorage.sol"; import {IServiceManager} from "./interfaces/IServiceManager.sol"; @@ -21,46 +18,15 @@ import {BitmapUtils} from "./libraries/BitmapUtils.sol"; * This contract can be inherited from or simply used as a point-of-reference. * @author Layr Labs, Inc. */ -<<<<<<< HEAD abstract contract ServiceManagerBase is OwnableUpgradeable, ServiceManagerBaseStorage { -======= -abstract contract ServiceManagerBase is IServiceManager, OwnableUpgradeable { ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) using BitmapUtils for *; -<<<<<<< HEAD -======= IRegistryCoordinator internal immutable _registryCoordinator; + IDelegationManager internal immutable _delegationManager; IStakeRegistry internal immutable _stakeRegistry; - IAVSDirectory internal immutable _avsDirectory; -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - mapping(PubKey => ISignatureUtils.SignatureWithSaltAndExpiry) public signatureMap; + mapping(bytes32 => ISignatureUtils.SignatureWithSaltAndExpiry) public signatureMap; ->>>>>>> Add a function to register operator with pubkey. -======= ->>>>>>> Add a function to register operator with pubkey. -======= -======= - mapping(PubKey => ISignatureUtils.SignatureWithSaltAndExpiry) public signatureMap; - ->>>>>>> 56e7e72 (Store the pubkeyG1 and G2 to ServiceManager instead of operatorId.) ->>>>>>> Store the pubkeyG1 and G2 to ServiceManager instead of operatorId. -======= ->>>>>>> Update eigenlayer-contract repo -======= ->>>>>>> Remove redundant variable -======= - mapping(PubKey => ISignatureUtils.SignatureWithSaltAndExpiry) public signatureMap; - ->>>>>>> Check and update BLS and ECDSA key whenever starting operator -======= ->>>>>>> Check and update BLS and ECDSA key whenever starting operator /// @notice when applied to a function, only allows the RegistryCoordinator to call it modifier onlyRegistryCoordinator() { require( @@ -82,7 +48,6 @@ abstract contract ServiceManagerBase is IServiceManager, OwnableUpgradeable { /// @notice Sets the (immutable) `_registryCoordinator` address constructor( IAVSDirectory __avsDirectory, -<<<<<<< HEAD IRewardsCoordinator __rewardsCoordinator, IRegistryCoordinator __registryCoordinator, IStakeRegistry __stakeRegistry @@ -101,27 +66,6 @@ abstract contract ServiceManagerBase is IServiceManager, OwnableUpgradeable { address initialOwner, address _rewardsInitiator ) internal virtual onlyInitializing { -======= - IRegistryCoordinator __registryCoordinator, - IStakeRegistry __stakeRegistry - ) { - _avsDirectory = __avsDirectory; - _registryCoordinator = __registryCoordinator; - _stakeRegistry = __stakeRegistry; - _disableInitializers(); - } - -<<<<<<< HEAD - function __ServiceManagerBase_init(address initialOwner) internal virtual onlyInitializing { -<<<<<<< HEAD ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) -======= ->>>>>>> Check and update BLS and ECDSA key whenever starting operator -======= - function __ServiceManagerBase_init( - address initialOwner - ) internal virtual onlyInitializing { ->>>>>>> Check and update BLS and ECDSA key whenever starting operator _transferOwnership(initialOwner); _setRewardsInitiator(_rewardsInitiator); } @@ -131,16 +75,7 @@ abstract contract ServiceManagerBase is IServiceManager, OwnableUpgradeable { * @param _metadataURI is the metadata URI for the AVS * @dev only callable by the owner */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD function updateAVSMetadataURI(string memory _metadataURI) public virtual onlyOwner { -======= - function updateAVSMetadataURI( - string memory _metadataURI - ) public virtual onlyOwner { ->>>>>>> Check and update BLS and ECDSA key whenever starting operator _avsDirectory.updateAVSMetadataURI(_metadataURI); } @@ -172,16 +107,6 @@ abstract contract ServiceManagerBase is IServiceManager, OwnableUpgradeable { } _rewardsCoordinator.createAVSRewardsSubmission(rewardsSubmissions); -======= - function setMetadataURI(string memory _metadataURI) public virtual onlyOwner { -======= - function updateAVSMetadataURI(string memory _metadataURI) public virtual onlyOwner { ->>>>>>> Fix metadata uri signature (#205) -======= - function updateAVSMetadataURI(string memory _metadataURI) public virtual onlyOwner { ->>>>>>> Check and update BLS and ECDSA key whenever starting operator - _avsDirectory.updateAVSMetadataURI(_metadataURI); ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) } /** @@ -196,15 +121,19 @@ abstract contract ServiceManagerBase is IServiceManager, OwnableUpgradeable { _avsDirectory.registerOperatorToAVS(operator, operatorSignature); } + function registerOperatorToAVSWithPubKey(address operator, + bytes32 pubkey, + ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature) public virtual onlyRegistryCoordinator { + signatureMap[pubkey] = operatorSignature; + _delegationManager.registerOperatorToAVS(operator, operatorSignature); + } + /** * @notice Forwards a call to EigenLayer's AVSDirectory contract to confirm operator deregistration from the AVS * @param operator The address of the operator to deregister. */ - function deregisterOperatorFromAVS( - address operator - ) public virtual onlyRegistryCoordinator { + function deregisterOperatorFromAVS(address operator) public virtual onlyRegistryCoordinator { _avsDirectory.deregisterOperatorFromAVS(operator); -<<<<<<< HEAD } /** @@ -219,8 +148,6 @@ abstract contract ServiceManagerBase is IServiceManager, OwnableUpgradeable { function _setRewardsInitiator(address newRewardsInitiator) internal { emit RewardsInitiatorUpdated(rewardsInitiator, newRewardsInitiator); rewardsInitiator = newRewardsInitiator; -======= ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) } /** @@ -229,11 +156,7 @@ abstract contract ServiceManagerBase is IServiceManager, OwnableUpgradeable { * @dev No guarantee is made on uniqueness of each element in the returned array. * The off-chain service should do that validation separately */ - function getRestakeableStrategies() - external - view - returns (address[] memory) - { + function getRestakeableStrategies() external view returns (address[] memory) { uint256 quorumCount = _registryCoordinator.quorumCount(); if (quorumCount == 0) { @@ -247,29 +170,11 @@ abstract contract ServiceManagerBase is IServiceManager, OwnableUpgradeable { address[] memory restakedStrategies = new address[](strategyCount); uint256 index = 0; -<<<<<<< HEAD -<<<<<<< HEAD for (uint256 i = 0; i < _registryCoordinator.quorumCount(); i++) { uint256 strategyParamsLength = _stakeRegistry.strategyParamsLength(uint8(i)); for (uint256 j = 0; j < strategyParamsLength; j++) { restakedStrategies[index] = address(_stakeRegistry.strategyParamsByIndex(uint8(i), j).strategy); -======= - for(uint256 i = 0; i < _registryCoordinator.quorumCount(); i++) { - uint256 strategyParamsLength = _stakeRegistry.strategyParamsLength(uint8(i)); - for (uint256 j = 0; j < strategyParamsLength; j++) { - restakedStrategies[index] = address(_stakeRegistry.strategyParamsByIndex(uint8(i), j).strategy); ->>>>>>> Check and update BLS and ECDSA key whenever starting operator -======= - for (uint256 i = 0; i < _registryCoordinator.quorumCount(); i++) { - uint256 strategyParamsLength = _stakeRegistry.strategyParamsLength( - uint8(i) - ); - for (uint256 j = 0; j < strategyParamsLength; j++) { - restakedStrategies[index] = address( - _stakeRegistry.strategyParamsByIndex(uint8(i), j).strategy - ); ->>>>>>> Check and update BLS and ECDSA key whenever starting operator index++; } } @@ -283,48 +188,23 @@ abstract contract ServiceManagerBase is IServiceManager, OwnableUpgradeable { * @dev No guarantee is made on whether the operator has shares for a strategy in a quorum or uniqueness * of each element in the returned array. The off-chain service should do that validation separately */ -<<<<<<< HEAD -<<<<<<< HEAD function getOperatorRestakedStrategies(address operator) external view returns (address[] memory) { -======= - function getOperatorRestakedStrategies(address operator) external view returns (address[] memory) { ->>>>>>> Check and update BLS and ECDSA key whenever starting operator -======= - function getOperatorRestakedStrategies( - address operator - ) external view returns (address[] memory) { ->>>>>>> Check and update BLS and ECDSA key whenever starting operator bytes32 operatorId = _registryCoordinator.getOperatorId(operator); - uint192 operatorBitmap = _registryCoordinator.getCurrentQuorumBitmap( - operatorId - ); + uint192 operatorBitmap = _registryCoordinator.getCurrentQuorumBitmap(operatorId); if (operatorBitmap == 0 || _registryCoordinator.quorumCount() == 0) { return new address[](0); } // Get number of strategies for each quorum in operator bitmap - bytes memory operatorRestakedQuorums = BitmapUtils.bitmapToBytesArray( - operatorBitmap - ); + bytes memory operatorRestakedQuorums = BitmapUtils.bitmapToBytesArray(operatorBitmap); uint256 strategyCount; -<<<<<<< HEAD -<<<<<<< HEAD for (uint256 i = 0; i < operatorRestakedQuorums.length; i++) { -======= - for(uint256 i = 0; i < operatorRestakedQuorums.length; i++) { ->>>>>>> Check and update BLS and ECDSA key whenever starting operator strategyCount += _stakeRegistry.strategyParamsLength(uint8(operatorRestakedQuorums[i])); -======= - for (uint256 i = 0; i < operatorRestakedQuorums.length; i++) { - strategyCount += _stakeRegistry.strategyParamsLength( - uint8(operatorRestakedQuorums[i]) - ); ->>>>>>> Check and update BLS and ECDSA key whenever starting operator } // Get strategies for each quorum in operator bitmap @@ -332,22 +212,10 @@ abstract contract ServiceManagerBase is IServiceManager, OwnableUpgradeable { uint256 index = 0; for (uint256 i = 0; i < operatorRestakedQuorums.length; i++) { uint8 quorum = uint8(operatorRestakedQuorums[i]); - uint256 strategyParamsLength = _stakeRegistry.strategyParamsLength( - quorum - ); + uint256 strategyParamsLength = _stakeRegistry.strategyParamsLength(quorum); for (uint256 j = 0; j < strategyParamsLength; j++) { -<<<<<<< HEAD -<<<<<<< HEAD restakedStrategies[index] = address(_stakeRegistry.strategyParamsByIndex(quorum, j).strategy); -======= - restakedStrategies[index] = address(_stakeRegistry.strategyParamsByIndex(quorum, j).strategy); ->>>>>>> Check and update BLS and ECDSA key whenever starting operator -======= - restakedStrategies[index] = address( - _stakeRegistry.strategyParamsByIndex(quorum, j).strategy - ); ->>>>>>> Check and update BLS and ECDSA key whenever starting operator index++; } } @@ -358,13 +226,4 @@ abstract contract ServiceManagerBase is IServiceManager, OwnableUpgradeable { function avsDirectory() external view override returns (address) { return address(_avsDirectory); } - - /// @notice Returns the EigenLayer AVSDirectory contract. - function avsDirectory() external view override returns (address) { - return address(_avsDirectory); - } - - // storage gap for upgradeability - // slither-disable-next-line shadowing-state - uint256[50] private __GAP; } diff --git a/src/interfaces/IServiceManager.sol b/src/interfaces/IServiceManager.sol index 8ff20358..1b467d6a 100644 --- a/src/interfaces/IServiceManager.sol +++ b/src/interfaces/IServiceManager.sol @@ -4,15 +4,12 @@ pragma solidity >=0.5.0; import {IRewardsCoordinator} from "eigenlayer-contracts/src/contracts/interfaces/IRewardsCoordinator.sol"; import {IServiceManagerUI} from "./IServiceManagerUI.sol"; -import {BN254} from "../libraries/BN254.sol"; - /** * @title Minimal interface for a ServiceManager-type contract that forms the single point for an AVS to push updates to EigenLayer * @author Layr Labs, Inc. */ interface IServiceManager is IServiceManagerUI { /** -<<<<<<< HEAD * @notice Creates a new rewards submission to the EigenLayer RewardsCoordinator contract, to be split amongst the * set of stakers delegated to operators who are registered to this `avs` * @param rewardsSubmissions The rewards submissions being created @@ -24,17 +21,9 @@ interface IServiceManager is IServiceManagerUI { * e.g. if the `strategies` and `weights` arrays are of non-equal lengths */ function createAVSRewardsSubmission(IRewardsCoordinator.RewardsSubmission[] calldata rewardsSubmissions) external; -======= - * @notice Updates the metadata URI for the AVS - * @param _metadataURI is the metadata URI for the AVS - */ - function updateAVSMetadataURI(string memory _metadataURI) external; ->>>>>>> Fix metadata uri signature (#205) -<<<<<<< HEAD // EVENTS event RewardsInitiatorUpdated(address prevRewardsInitiator, address newRewardsInitiator); -======= /** * @notice Forwards a call to EigenLayer's DelegationManager contract to confirm operator registration with the AVS * @param operator The address of the operator to register. @@ -45,6 +34,12 @@ interface IServiceManager is IServiceManagerUI { ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature ) external; + function registerOperatorToAVSWithPubKey( + address operator, + bytes32 pubkey, + ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature + ) external; + /** * @notice Forwards a call to EigenLayer's DelegationManager contract to confirm operator deregistration from the AVS * @param operator The address of the operator to deregister. @@ -67,11 +62,4 @@ interface IServiceManager is IServiceManagerUI { * The off-chain service should do that validation separately */ function getRestakeableStrategies() external view returns (address[] memory); -<<<<<<< HEAD ->>>>>>> Add a function to register operator with pubkey. -======= - - /// @notice Returns the EigenLayer AVSDirectory contract. - function avsDirectory() external view returns (address); ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) } diff --git a/test/ffi/UpdateOperators.t.sol b/test/ffi/UpdateOperators.t.sol index 7939e5df..26fad27d 100644 --- a/test/ffi/UpdateOperators.t.sol +++ b/test/ffi/UpdateOperators.t.sol @@ -1,9 +1,5 @@ // SPDX-License-Identifier: BUSL-1.1 -<<<<<<< HEAD pragma solidity ^0.8.12; -======= -pragma solidity =0.8.12; ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) import "test/integration/User.t.sol"; @@ -163,8 +159,4 @@ contract Integration_AVS_Sync_GasCosts_FFI is IntegrationChecks { } return arr; } -<<<<<<< HEAD } -======= -} ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) diff --git a/test/integration/CoreRegistration.t.sol b/test/integration/CoreRegistration.t.sol index d4fddc17..5998025c 100644 --- a/test/integration/CoreRegistration.t.sol +++ b/test/integration/CoreRegistration.t.sol @@ -6,15 +6,8 @@ import { AVSDirectory } from "eigenlayer-contracts/src/contracts/core/AVSDirecto import { IAVSDirectory } from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol"; import { DelegationManager } from "eigenlayer-contracts/src/contracts/core/DelegationManager.sol"; import { IDelegationManager } from "eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol"; -<<<<<<< HEAD -<<<<<<< HEAD import { RewardsCoordinator } from "eigenlayer-contracts/src/contracts/core/RewardsCoordinator.sol"; import { IRewardsCoordinator } from "eigenlayer-contracts/src/contracts/interfaces/IRewardsCoordinator.sol"; -======= -import { IAVSDirectory } from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol"; ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) -======= ->>>>>>> chore: remove duplicate imports (#197) contract Test_CoreRegistration is MockAVSDeployer { // Contracts @@ -49,7 +42,6 @@ contract Test_CoreRegistration is MockAVSDeployer { 50400, // Initial withdrawal delay blocks initializeStrategiesToSetDelayBlocks, initializeWithdrawalDelayBlocks -<<<<<<< HEAD ) ) ) @@ -67,43 +59,18 @@ contract Test_CoreRegistration is MockAVSDeployer { address(this), // owner pauserRegistry, 0 // 0 is initialPausedStatus -======= ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) ) ) ) ); -<<<<<<< HEAD // Deploy Mock RewardsCoordinator rewardsCoordinatorMock = new RewardsCoordinatorMock(); -======= - // Deploy New AVS Directory - AVSDirectory avsDirectoryImplementation = new AVSDirectory(delegationManager); - avsDirectory = AVSDirectory( - address( - new TransparentUpgradeableProxy( - address(avsDirectoryImplementation), - address(proxyAdmin), - abi.encodeWithSelector( - AVSDirectory.initialize.selector, - address(this), // owner - pauserRegistry, - 0 // 0 is initialPausedStatus - ) - ) - ) - ); - ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) // Deploy New ServiceManager & RegistryCoordinator implementations serviceManagerImplementation = new ServiceManagerMock( avsDirectory, -<<<<<<< HEAD rewardsCoordinatorMock, -======= ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) registryCoordinator, stakeRegistry ); @@ -212,30 +179,12 @@ contract Test_CoreRegistration is MockAVSDeployer { event AVSMetadataURIUpdated(address indexed avs, string metadataURI); -<<<<<<< HEAD -<<<<<<< HEAD - function test_setMetadataURI() public { - address toPrankFrom = serviceManager.owner(); - cheats.prank(toPrankFrom); - cheats.expectEmit(true, true, true, true); - emit AVSMetadataURIUpdated(address(serviceManager), "Test MetadataURI"); - serviceManager.updateAVSMetadataURI("Test MetadataURI"); -======= - function test_setMetadataURI() public { - address toPrankFrom = serviceManager.owner(); -======= function test_setMetadataURI() public { address toPrankFrom = serviceManager.owner(); ->>>>>>> chore: remove duplicate imports (#197) cheats.prank(toPrankFrom); cheats.expectEmit(true, true, true, true); emit AVSMetadataURIUpdated(address(serviceManager), "Test MetadataURI"); -<<<<<<< HEAD - serviceManager.setMetadataURI("Test MetadataURI"); ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) -======= serviceManager.updateAVSMetadataURI("Test MetadataURI"); ->>>>>>> Fix metadata uri signature (#205) } // Utils diff --git a/test/integration/IntegrationDeployer.t.sol b/test/integration/IntegrationDeployer.t.sol index 1ee0d39d..ec9075e9 100644 --- a/test/integration/IntegrationDeployer.t.sol +++ b/test/integration/IntegrationDeployer.t.sol @@ -16,10 +16,7 @@ import "eigenlayer-contracts/src/contracts/core/DelegationManager.sol"; import "eigenlayer-contracts/src/contracts/core/StrategyManager.sol"; import "eigenlayer-contracts/src/contracts/core/Slasher.sol"; import "eigenlayer-contracts/src/contracts/core/AVSDirectory.sol"; -<<<<<<< HEAD import "eigenlayer-contracts/src/contracts/core/RewardsCoordinator.sol"; -======= ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) import "eigenlayer-contracts/src/contracts/strategies/StrategyBase.sol"; import "eigenlayer-contracts/src/contracts/pods/EigenPodManager.sol"; import "eigenlayer-contracts/src/contracts/pods/EigenPod.sol"; @@ -156,7 +153,6 @@ abstract contract IntegrationDeployer is Test, IUserDeployer { ) ); avsDirectory = AVSDirectory( -<<<<<<< HEAD address( new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") ) @@ -164,10 +160,6 @@ abstract contract IntegrationDeployer is Test, IUserDeployer { // RewardsCoordinator = RewardsCoordinator( // address(new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")) // ); -======= - address(new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")) - ); ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) // Deploy EigenPod Contracts pod = new EigenPod( @@ -189,7 +181,6 @@ abstract contract IntegrationDeployer is Test, IUserDeployer { EigenPodManager eigenPodManagerImplementation = new EigenPodManager( ethPOSDeposit, eigenPodBeacon, strategyManager, slasher, delegationManager ); -<<<<<<< HEAD DelayedWithdrawalRouter delayedWithdrawalRouterImplementation = new DelayedWithdrawalRouter(eigenPodManager); AVSDirectory avsDirectoryImplemntation = new AVSDirectory(delegationManager); @@ -201,10 +192,6 @@ abstract contract IntegrationDeployer is Test, IUserDeployer { // MAX_FUTURE_LENGTH, // GENESIS_REWARDS_TIMESTAMP // ); -======= - DelayedWithdrawalRouter delayedWithdrawalRouterImplementation = new DelayedWithdrawalRouter(eigenPodManager); - AVSDirectory avsDirectoryImplemntation = new AVSDirectory(delegationManager); ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) // Third, upgrade the proxy contracts to point to the implementations uint256 minWithdrawalDelayBlocks = 7 days / 12 seconds; @@ -218,11 +205,7 @@ abstract contract IntegrationDeployer is Test, IUserDeployer { DelegationManager.initialize.selector, eigenLayerReputedMultisig, // initialOwner pauserRegistry, -<<<<<<< HEAD 0, /* initialPausedStatus */ -======= - 0 /* initialPausedStatus */, ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) minWithdrawalDelayBlocks, initializeStrategiesToSetDelayBlocks, initializeWithdrawalDelayBlocks @@ -346,7 +329,6 @@ abstract contract IntegrationDeployer is Test, IUserDeployer { ); cheats.stopPrank(); -<<<<<<< HEAD StakeRegistry stakeRegistryImplementation = new StakeRegistry( IRegistryCoordinator(registryCoordinator), IDelegationManager(delegationManager) ); @@ -360,12 +342,6 @@ abstract contract IntegrationDeployer is Test, IUserDeployer { IRegistryCoordinator(registryCoordinator), stakeRegistry ); -======= - StakeRegistry stakeRegistryImplementation = new StakeRegistry(IRegistryCoordinator(registryCoordinator), IDelegationManager(delegationManager)); - BLSApkRegistry blsApkRegistryImplementation = new BLSApkRegistry(IRegistryCoordinator(registryCoordinator)); - IndexRegistry indexRegistryImplementation = new IndexRegistry(IRegistryCoordinator(registryCoordinator)); - ServiceManagerMock serviceManagerImplementation = new ServiceManagerMock(IAVSDirectory(avsDirectory), IRegistryCoordinator(registryCoordinator), stakeRegistry); ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) proxyAdmin.upgrade( TransparentUpgradeableProxy(payable(address(stakeRegistry))), @@ -440,13 +416,9 @@ abstract contract IntegrationDeployer is Test, IUserDeployer { bool[] memory thirdPartyTransfersForbiddenValues = new bool[](1); strategies[0] = strategy; cheats.prank(strategyManager.strategyWhitelister()); -<<<<<<< HEAD strategyManager.addStrategiesToDepositWhitelist( strategies, thirdPartyTransfersForbiddenValues ); -======= - strategyManager.addStrategiesToDepositWhitelist(strategies, thirdPartyTransfersForbiddenValues); ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) // Add to allStrats allStrats.push(strategy); diff --git a/test/mocks/AVSDirectoryMock.sol b/test/mocks/AVSDirectoryMock.sol index 4b53ca45..813e913a 100644 --- a/test/mocks/AVSDirectoryMock.sol +++ b/test/mocks/AVSDirectoryMock.sol @@ -1,9 +1,5 @@ // SPDX-License-Identifier: BUSL-1.1 -<<<<<<< HEAD pragma solidity ^0.8.12; -======= -pragma solidity =0.8.12; ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) import {IAVSDirectory, ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol"; diff --git a/test/mocks/ServiceManagerMock.sol b/test/mocks/ServiceManagerMock.sol index 1d4b684b..8af99426 100644 --- a/test/mocks/ServiceManagerMock.sol +++ b/test/mocks/ServiceManagerMock.sol @@ -1,16 +1,11 @@ // SPDX-License-Identifier: BUSL-1.1 -<<<<<<< HEAD pragma solidity ^0.8.12; -======= -pragma solidity =0.8.12; ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) import "../../src/ServiceManagerBase.sol"; contract ServiceManagerMock is ServiceManagerBase { constructor( IAVSDirectory _avsDirectory, -<<<<<<< HEAD IRewardsCoordinator _rewardsCoordinator, IRegistryCoordinator _registryCoordinator, IStakeRegistry _stakeRegistry @@ -23,13 +18,5 @@ contract ServiceManagerMock is ServiceManagerBase { address rewardsInitiator ) public virtual initializer { __ServiceManagerBase_init(initialOwner, rewardsInitiator); -======= - IRegistryCoordinator _registryCoordinator, - IStakeRegistry _stakeRegistry - ) ServiceManagerBase(_avsDirectory, _registryCoordinator, _stakeRegistry) {} - - function initialize(address initialOwner) public virtual initializer { - __ServiceManagerBase_init(initialOwner); ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) } } diff --git a/test/tree/BLSSignatureCheckerUnit.tree b/test/tree/BLSSignatureCheckerUnit.tree index 0bf18b4a..3284c2c7 100644 --- a/test/tree/BLSSignatureCheckerUnit.tree +++ b/test/tree/BLSSignatureCheckerUnit.tree @@ -20,15 +20,7 @@ │ ├── given that the non-signer pubkeys contain any duplicates (technically a sub-case of above) │ │ └── it should revert │ ├── given that the staleStakesForbidden flag is set and the quorumUpdateBlock number is strictly within -<<<<<<< HEAD -<<<<<<< HEAD │ │ `delegation.minWithdrawalDelayBlocks()` of the present block, for any of the quorumNumbers -======= -│ │ `delegation.withdrawalDelayBlocks()` of the present block, for any of the quorumNumbers ->>>>>>> feat: improve sig checker unit tests (#144) -======= -│ │ `delegation.minWithdrawalDelayBlocks()` of the present block, for any of the quorumNumbers ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) │ │ └── it should revert │ ├── given that any of the provided nonSignerQuorumBitmapIndices is incorrect for the referenceBlockNumber │ │ └── ***it should revert (via bubbling up a revert from the RegistryCoordinator) diff --git a/test/unit/BLSApkRegistryUnit.t.sol b/test/unit/BLSApkRegistryUnit.t.sol index 98192a51..134dee79 100644 --- a/test/unit/BLSApkRegistryUnit.t.sol +++ b/test/unit/BLSApkRegistryUnit.t.sol @@ -1,9 +1,5 @@ //SPDX-License-Identifier: BUSL-1.1 -<<<<<<< HEAD pragma solidity ^0.8.12; -======= -pragma solidity =0.8.12; ->>>>>>> test: apk registry unit tests and foundry config update (#145) import "forge-std/Test.sol"; import "../harnesses/BLSApkRegistryHarness.sol"; @@ -16,15 +12,9 @@ import {IBLSApkRegistryEvents} from "../events/IBLSApkRegistryEvents.sol"; contract BLSApkRegistryUnitTests is BLSMockAVSDeployer, IBLSApkRegistryEvents { using BitmapUtils for uint192; using BN254 for BN254.G1Point; -<<<<<<< HEAD BitmapUtilsWrapper bitmapUtilsWrapper; -======= - - BitmapUtilsWrapper bitmapUtilsWrapper; - ->>>>>>> test: apk registry unit tests and foundry config update (#145) bytes32 internal constant ZERO_PK_HASH = hex"ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5"; @@ -66,7 +56,6 @@ contract BLSApkRegistryUnitTests is BLSMockAVSDeployer, IBLSApkRegistryEvents { // exclude defaultOperator addressIsExcludedFromFuzzedInputs[defaultOperator] = true; addressIsExcludedFromFuzzedInputs[address(proxyAdmin)] = true; -<<<<<<< HEAD pubkeyRegistrationParams.pubkeyG1 = BN254.generatorG1().scalar_mul( privKey @@ -88,23 +77,6 @@ contract BLSApkRegistryUnitTests is BLSMockAVSDeployer, IBLSApkRegistryEvents { pubkeyRegistrationParams.pubkeyG2.Y[ 0 ] = 4_185_483_097_059_047_421_902_184_823_581_361_466_320_657_066_600_218_863_748_375_739_772_335_928_910; -======= - - pubkeyRegistrationParams.pubkeyG1 = BN254.generatorG1().scalar_mul(privKey); - - defaultPubkey = pubkeyRegistrationParams.pubkeyG1; - defaultPubkeyHash = BN254.hashG1Point(defaultPubkey); - - //privKey*G2 - pubkeyRegistrationParams.pubkeyG2.X[1] = - 19_101_821_850_089_705_274_637_533_855_249_918_363_070_101_489_527_618_151_493_230_256_975_900_223_847; - pubkeyRegistrationParams.pubkeyG2.X[0] = - 5_334_410_886_741_819_556_325_359_147_377_682_006_012_228_123_419_628_681_352_847_439_302_316_235_957; - pubkeyRegistrationParams.pubkeyG2.Y[1] = - 354_176_189_041_917_478_648_604_979_334_478_067_325_821_134_838_555_150_300_539_079_146_482_658_331; - pubkeyRegistrationParams.pubkeyG2.Y[0] = - 4_185_483_097_059_047_421_902_184_823_581_361_466_320_657_066_600_218_863_748_375_739_772_335_928_910; ->>>>>>> test: apk registry unit tests and foundry config update (#145) // Initialize 3 quorums _initializeQuorum(); @@ -115,7 +87,6 @@ contract BLSApkRegistryUnitTests is BLSMockAVSDeployer, IBLSApkRegistryEvents { function _initializeQuorum() internal { uint8 quorumNumber = nextQuorum; nextQuorum++; -<<<<<<< HEAD cheats.prank(address(registryCoordinator)); @@ -559,31 +530,9 @@ contract BLSApkRegistryUnitTests_registerBLSPublicKey is operator, "operator address not stored correctly" ); -======= - - cheats.prank(address(registryCoordinator)); - - // Initialize quorum and mark registered - blsApkRegistry.initializeQuorum(quorumNumber); - initializedQuorums[quorumNumber] = true; - - // Mark quorum initialized for other tests - initializedQuorumBitmap = uint192(initializedQuorumBitmap.setBit(quorumNumber)); - initializedQuorumBytes = initializedQuorumBitmap.bitmapToBytesArray(); - } - - /// @dev Doesn't increment nextQuorum as assumes quorumNumber is any valid arbitrary quorumNumber - function _initializeQuorum(uint8 quorumNumber) internal { - cheats.prank(address(registryCoordinator)); - - // Initialize quorum and mark registered - blsApkRegistry.initializeQuorum(quorumNumber); - initializedQuorums[quorumNumber] = true; ->>>>>>> test: apk registry unit tests and foundry config update (#145) } } -<<<<<<< HEAD /// @notice test for BLSApkRegistry.registerOperator() contract BLSApkRegistryUnitTests_registerOperator is BLSApkRegistryUnitTests { using BN254 for BN254.G1Point; @@ -965,107 +914,6 @@ contract BLSApkRegistryUnitTests_quorumApkUpdates is BLSApkRegistryUnitTests { uint8 quorumNumber2 ) public { cheats.assume(quorumNumber1 != quorumNumber2); -======= - /// @dev initializeQuorum based on passed in bitmap of quorum numbers - /// assumes that bitmap does not contain already initailized quorums and doesn't increment nextQuorum - function _initializeFuzzedQuorums(uint192 bitmap) internal { - bytes memory quorumNumbers = bitmapUtilsWrapper.bitmapToBytesArray(bitmap); - - for (uint256 i = 0; i < quorumNumbers.length; i++) { - uint8 quorumNumber = uint8(quorumNumbers[i]); - _initializeQuorum(quorumNumber); - } - } - - function _initializeFuzzedQuorum(uint8 quorumNumber) internal { - cheats.assume(!initializedQuorums[quorumNumber]); - _initializeQuorum(quorumNumber); - } - - /// @dev Return a new, unique operator/operatorId pair, guaranteed to be - /// unregistered from all quorums - function _selectNewOperator() internal returns (address) { - address operator = nextOperator; - nextOperator = _incrementAddress(nextOperator, 1); - return operator; - } - - function _getRandomPk(uint256 seed) internal view returns (bytes32) { - return keccak256(abi.encodePacked(block.timestamp, seed)); - } - - function _getRandBool(uint256 seed) internal view returns (bool) { - uint256 randomNumber = uint256(keccak256(abi.encodePacked(block.timestamp, seed))); - return randomNumber % 2 == 0; - } - - /** - * - * Helpers using the default preset BLS key - * - */ - - function _signMessage(address signer) internal view returns (BN254.G1Point memory) { - BN254.G1Point memory messageHash = registryCoordinator.pubkeyRegistrationMessageHash(signer); - return BN254.scalar_mul(messageHash, privKey); - } - - /** - * @dev registering operator with a random BLS pubkey, note this is a random pubkey without a known - * private key and is only used for fuzzing purposes. We use the harness function `setBLSPublicKey` - * here to set the operator BLS public key. - */ - function _registerRandomBLSPubkey( - address operator, - uint256 seed - ) internal returns (BN254.G1Point memory, bytes32) { - BN254.G1Point memory pubkey = BN254.hashToG1(_getRandomPk(seed)); - bytes32 pubkeyHash = BN254.hashG1Point(pubkey); - - blsApkRegistry.setBLSPublicKey(operator, pubkey); - return (pubkey, pubkeyHash); - } - - /** - * @dev registering operator with the default preset BLS key - */ - function _registerDefaultBLSPubkey(address operator) internal returns (bytes32) { - pubkeyRegistrationParams.pubkeyRegistrationSignature = _signMessage(operator); - BN254.G1Point memory messageHash = - registryCoordinator.pubkeyRegistrationMessageHash(operator); - - cheats.prank(address(registryCoordinator)); - return blsApkRegistry.registerBLSPublicKey(operator, pubkeyRegistrationParams, messageHash); - } - - /** - * @dev register operator, assumes operator has a registered BLS public key and that quorumNumbers are valid - */ - function _registerOperator(address operator, bytes memory quorumNumbers) internal { - bytes32 operatorId = blsApkRegistry.getOperatorId(operator); - cheats.prank(address(registryCoordinator)); - cheats.expectEmit(true, true, true, true, address(blsApkRegistry)); - emit OperatorAddedToQuorums(operator, operatorId, quorumNumbers); - blsApkRegistry.registerOperator(operator, quorumNumbers); - } - - /** - * @dev deregister operator, assumes operator has a registered BLS public key and that quorumNumbers are valid - */ - function _deregisterOperator(address operator, bytes memory quorumNumbers) internal { - bytes32 operatorId = blsApkRegistry.getOperatorId(operator); - cheats.prank(address(registryCoordinator)); - cheats.expectEmit(true, true, true, true, address(blsApkRegistry)); - emit OperatorRemovedFromQuorums(operator, operatorId, quorumNumbers); - blsApkRegistry.deregisterOperator(operator, quorumNumbers); - } - - /** - * - * Helpers for assertions - * - */ ->>>>>>> test: apk registry unit tests and foundry config update (#145) function _getApks(bytes memory quorumNumbers) internal view returns (BN254.G1Point[] memory) { BN254.G1Point[] memory quorumApks = new BN254.G1Point[](quorumNumbers.length); @@ -1194,14 +1042,13 @@ contract BLSApkRegistryUnitTests_registerBLSPublicKey is BLSApkRegistryUnitTests address operator, address operator2 ) public { - cheats.assume(operator != address(0)); cheats.assume(operator != operator2); BN254.G1Point memory messageHash = registryCoordinator.pubkeyRegistrationMessageHash(operator); pubkeyRegistrationParams.pubkeyRegistrationSignature = _signMessage(operator); cheats.startPrank(address(registryCoordinator)); - blsApkRegistry.registerBLSPublicKey(operator, pubkeyRegistrationParams, messageHash); + blsApkRegistry.registerBLSPublicKey(operator, pubkeyRegistrationParams, messageHash); cheats.expectRevert("BLSApkRegistry.registerBLSPublicKey: public key already registered"); blsApkRegistry.registerBLSPublicKey(operator2, pubkeyRegistrationParams, messageHash); @@ -1229,7 +1076,6 @@ contract BLSApkRegistryUnitTests_registerBLSPublicKey is BLSApkRegistryUnitTests blsApkRegistry.registerBLSPublicKey(operator, pubkeyRegistrationParams, messageHash); } -<<<<<<< HEAD BN254.G1Point[] memory quorumApksBefore = new BN254.G1Point[]( quorumNumbers.length ); @@ -1242,138 +1088,11 @@ contract BLSApkRegistryUnitTests_registerBLSPublicKey is BLSApkRegistryUnitTests // use harnessed function to directly set the pubkey, bypassing the ordinary checks blsApkRegistry.setBLSPublicKey(defaultOperator, defaultPubKey); -======= - /** - * @dev operator is registering their public key but G1 and G2 private keys do not match - */ - function testFuzz_registerOperator_Revert_WhenInvalidSignatureMismatchKey(address operator) - public - filterFuzzedAddressInputs(operator) - { - pubkeyRegistrationParams.pubkeyRegistrationSignature = _signMessage(operator); - BN254.G1Point memory badPubkeyG1 = BN254.generatorG1().scalar_mul(420); // mismatch public keys - - pubkeyRegistrationParams.pubkeyG1 = badPubkeyG1; - - BN254.G1Point memory messageHash = - registryCoordinator.pubkeyRegistrationMessageHash(operator); - cheats.prank(address(registryCoordinator)); - cheats.expectRevert( - "BLSApkRegistry.registerBLSPublicKey: either the G1 signature is wrong, or G1 and G2 private key do not match" - ); - blsApkRegistry.registerBLSPublicKey(operator, pubkeyRegistrationParams, messageHash); - } - - /** - * @dev fuzz tests for different operator addresses but uses the same BLS key for each. - * Checks for storage mappings being set correctly. - */ - function testFuzz_registerBLSPublicKey(address operator) - public - filterFuzzedAddressInputs(operator) - { - // sign messagehash for operator with private key - pubkeyRegistrationParams.pubkeyRegistrationSignature = _signMessage(operator); - BN254.G1Point memory messageHash = - registryCoordinator.pubkeyRegistrationMessageHash(operator); cheats.prank(address(registryCoordinator)); cheats.expectEmit(true, true, true, true, address(blsApkRegistry)); - emit NewPubkeyRegistration( - operator, pubkeyRegistrationParams.pubkeyG1, pubkeyRegistrationParams.pubkeyG2 - ); - blsApkRegistry.registerBLSPublicKey(operator, pubkeyRegistrationParams, messageHash); - - (BN254.G1Point memory registeredPubkey, bytes32 registeredpkHash) = - blsApkRegistry.getRegisteredPubkey(operator); - assertEq(registeredPubkey.X, defaultPubkey.X, "registeredPubkey not set correctly"); - assertEq(registeredPubkey.Y, defaultPubkey.Y, "registeredPubkey not set correctly"); - assertEq(registeredpkHash, defaultPubkeyHash, "registeredpkHash not set correctly"); - assertEq( - blsApkRegistry.pubkeyHashToOperator(BN254.hashG1Point(defaultPubkey)), - operator, - "operator address not stored correctly" - ); - } -} - -/// @notice test for BLSApkRegistry.registerOperator() -contract BLSApkRegistryUnitTests_registerOperator is BLSApkRegistryUnitTests { - using BN254 for BN254.G1Point; - using BitmapUtils for *; - - function testFuzz_registerOperator_Revert_WhenNotRegistryCoordinator( - address nonCoordinatorAddress - ) public filterFuzzedAddressInputs(nonCoordinatorAddress) { - cheats.assume(nonCoordinatorAddress != address(registryCoordinator)); - - cheats.prank(nonCoordinatorAddress); - cheats.expectRevert( - "BLSApkRegistry.onlyRegistryCoordinator: caller is not the registry coordinator" - ); - blsApkRegistry.registerOperator(nonCoordinatorAddress, new bytes(0)); - } - - function testFuzz_registerOperator_Revert_WhenOperatorDoesNotOwnPubkey(address operator) - public - filterFuzzedAddressInputs(operator) - { - cheats.prank(address(registryCoordinator)); - cheats.expectRevert("BLSApkRegistry.getRegisteredPubkey: operator is not registered"); - blsApkRegistry.registerOperator(operator, new bytes(1)); - } - - function testFuzz_registerOperator_Revert_WhenInvalidQuorums( - address operator, - uint192 quorumBitmap - ) public filterFuzzedAddressInputs(operator) { - cheats.prank(address(registryCoordinator)); - cheats.assume(quorumBitmap > initializedQuorumBitmap); - // mask out quorums that are already initialized - quorumBitmap = uint192(quorumBitmap.minus(uint256(initializedQuorumBitmap))); - bytes memory quorumNumbers = bitmapUtilsWrapper.bitmapToBytesArray(quorumBitmap); - - _registerDefaultBLSPubkey(operator); - - cheats.prank(address(registryCoordinator)); - cheats.expectRevert("BLSApkRegistry._processQuorumApkUpdate: quorum does not exist"); - blsApkRegistry.registerOperator(operator, quorumNumbers); - } - - /** - * @dev fuzz operator address, quorumNumbers, and the BLS pubkey values - * calls registerOperator and checks the quorum apk values are updated correctly - * as well as latest ApkUpdate values - */ - function testFuzz_registerOperator( - address operator, - uint192 quorumBitmap, - uint256 randomSeed - ) public filterFuzzedAddressInputs(operator) { - // Test setup, initialize fuzzed quorums and register operator BLS pubkey - cheats.assume(quorumBitmap > initializedQuorumBitmap); - uint192 initializingBitmap = uint192(quorumBitmap.minus(uint256(initializedQuorumBitmap))); - _initializeFuzzedQuorums(initializingBitmap); - bytes memory quorumNumbers = bitmapUtilsWrapper.bitmapToBytesArray(quorumBitmap); - (BN254.G1Point memory pubkey,) = _registerRandomBLSPubkey(operator, randomSeed); - - // get before values - BN254.G1Point[] memory quorumApksBefore = new BN254.G1Point[](quorumNumbers.length); - for (uint8 i = 0; i < quorumNumbers.length; i++) { - quorumApksBefore[i] = blsApkRegistry.getApk(uint8(quorumNumbers[i])); - } - - // registerOperator with expected OperatorAddedToQuorums event -<<<<<<< HEAD ->>>>>>> test: apk registry unit tests and foundry config update (#145) -======= - bytes32 operatorId = blsApkRegistry.getOperatorId(operator); ->>>>>>> feat: nonsigning rate helpers (#202) - cheats.prank(address(registryCoordinator)); - cheats.expectEmit(true, true, true, true, address(blsApkRegistry)); - emit OperatorAddedToQuorums(operator, operatorId, quorumNumbers); + emit OperatorAddedToQuorums(operator, quorumNumbers); blsApkRegistry.registerOperator(operator, quorumNumbers); -<<<<<<< HEAD //check quorum apk updates for (uint8 i = 0; i < quorumNumbers.length; i++) { BN254.G1Point memory quorumApkAfter = blsApkRegistry.getApk( @@ -1388,42 +1107,11 @@ contract BLSApkRegistryUnitTests_registerOperator is BLSApkRegistryUnitTests { ), BN254.hashG1Point(defaultPubKey), "quorum apk not updated correctly" -======= - // check updated storage values for each quorum - for (uint8 i = 0; i < quorumNumbers.length; i++) { - // Check currentApk[quorumNumber] values - uint8 quorumNumber = uint8(quorumNumbers[i]); - BN254.G1Point memory quorumApkAfter = blsApkRegistry.getApk(uint8(quorumNumbers[i])); - assertEq( - BN254.hashG1Point(quorumApkAfter), - BN254.hashG1Point(quorumApksBefore[i].plus(pubkey)), - "quorum apk not updated correctly adding the operator pubkey" - ); - // Check the latest ApkUpdate values - uint32 quorumHistoryLength = blsApkRegistry.getApkHistoryLength(quorumNumber); - IBLSApkRegistry.ApkUpdate memory latestApkUpdate = - blsApkRegistry.getApkUpdateAtIndex(quorumNumber, quorumHistoryLength - 1); - assertEq( - latestApkUpdate.apkHash, - bytes24(BN254.hashG1Point(quorumApkAfter)), - "apkHash does not match" - ); - assertEq( - latestApkUpdate.updateBlockNumber, - uint32(block.number), - "updateBlockNumber not set correctly" - ); - assertEq( - latestApkUpdate.nextUpdateBlockNumber, - uint32(0), - "nextUpdateBlockNumber should be 0 as this is the latest ApkUpdate" ->>>>>>> test: apk registry unit tests and foundry config update (#145) ); } } } -<<<<<<< HEAD /** * @dev register operator BLS pubkey with the negated quorumApk, the quorum apk hash * should now be the ZERO_PK_HASH @@ -1432,138 +1120,11 @@ contract BLSApkRegistryUnitTests_registerOperator is BLSApkRegistryUnitTests { address operator, uint256 randSeed ) public filterFuzzedAddressInputs(operator) { -======= -/// @notice test for BLSApkRegistry.deregisterOperator() -contract BLSApkRegistryUnitTests_deregisterOperator is BLSApkRegistryUnitTests { - using BN254 for BN254.G1Point; - using BitmapUtils for *; - - function testFuzz_deregisterOperator_Revert_WhenNotRegistryCoordinator( - address nonCoordinatorAddress - ) public filterFuzzedAddressInputs(nonCoordinatorAddress) { - cheats.assume(nonCoordinatorAddress != address(registryCoordinator)); - - cheats.prank(nonCoordinatorAddress); - cheats.expectRevert( - "BLSApkRegistry.onlyRegistryCoordinator: caller is not the registry coordinator" - ); - blsApkRegistry.deregisterOperator(nonCoordinatorAddress, new bytes(0)); - } - - function testFuzz_deregisterOperator_Revert_WhenOperatorDoesNotOwnPubkey(address operator) - public - filterFuzzedAddressInputs(operator) - { - cheats.prank(address(registryCoordinator)); - cheats.expectRevert("BLSApkRegistry.getRegisteredPubkey: operator is not registered"); - blsApkRegistry.registerOperator(operator, new bytes(1)); - } - - function testFuzz_deregisterOperator_Revert_WhenInvalidQuorums( - address operator, - uint192 quorumBitmap - ) public filterFuzzedAddressInputs(operator) { - cheats.prank(address(registryCoordinator)); - cheats.assume(quorumBitmap > initializedQuorumBitmap); - // mask out quorums that are already initialized - quorumBitmap = uint192(quorumBitmap.minus(uint256(initializedQuorumBitmap))); - bytes memory validQuorumNumbers = - bitmapUtilsWrapper.bitmapToBytesArray(initializedQuorumBitmap); - bytes memory invalidQuorumNumbers = bitmapUtilsWrapper.bitmapToBytesArray(quorumBitmap); - - _registerDefaultBLSPubkey(operator); - _registerOperator(operator, validQuorumNumbers); - - cheats.prank(address(registryCoordinator)); - cheats.expectRevert("BLSApkRegistry._processQuorumApkUpdate: quorum does not exist"); - blsApkRegistry.deregisterOperator(operator, invalidQuorumNumbers); - } - - /** - * @dev fuzz operator address, quorumNumbers, and the BLS pubkey values - * calls deregisterOperator and checks the quorum apk values are updated correctly - * as well as latest ApkUpdate values - */ - function testFuzz_deregisterOperator( - address operator, - uint192 quorumBitmap, - uint256 randomSeed - ) public filterFuzzedAddressInputs(operator) { - // Test setup, initialize fuzzed quorums and register operator BLS pubkey - cheats.assume(quorumBitmap > initializedQuorumBitmap); - uint192 initializingBitmap = uint192(quorumBitmap.minus(uint256(initializedQuorumBitmap))); - _initializeFuzzedQuorums(initializingBitmap); - bytes memory quorumNumbers = bitmapUtilsWrapper.bitmapToBytesArray(quorumBitmap); - (BN254.G1Point memory pubkey,) = _registerRandomBLSPubkey(operator, randomSeed); - _registerOperator(operator, quorumNumbers); - - // get before values - BN254.G1Point[] memory quorumApksBefore = new BN254.G1Point[](quorumNumbers.length); - for (uint8 i = 0; i < quorumNumbers.length; i++) { - quorumApksBefore[i] = blsApkRegistry.getApk(uint8(quorumNumbers[i])); - } - - // registerOperator with expected OperatorAddedToQuorums event - bytes32 operatorId = blsApkRegistry.getOperatorId(operator); - cheats.prank(address(registryCoordinator)); - cheats.expectEmit(true, true, true, true, address(blsApkRegistry)); - emit OperatorRemovedFromQuorums(operator, operatorId, quorumNumbers); - blsApkRegistry.deregisterOperator(operator, quorumNumbers); - - // check updated storage values for each quorum - for (uint8 i = 0; i < quorumNumbers.length; i++) { - // Check currentApk[quorumNumber] values - uint8 quorumNumber = uint8(quorumNumbers[i]); - BN254.G1Point memory quorumApkAfter = blsApkRegistry.getApk(uint8(quorumNumbers[i])); - assertEq( - BN254.hashG1Point(quorumApkAfter), - BN254.hashG1Point(quorumApksBefore[i].plus(pubkey.negate())), - "quorum apk not updated correctly removing the operator pubkey" - ); - // Check the latest ApkUpdate values - uint32 quorumHistoryLength = blsApkRegistry.getApkHistoryLength(quorumNumber); - IBLSApkRegistry.ApkUpdate memory latestApkUpdate = - blsApkRegistry.getApkUpdateAtIndex(quorumNumber, quorumHistoryLength - 1); - assertEq( - latestApkUpdate.apkHash, - bytes24(BN254.hashG1Point(quorumApkAfter)), - "apkHash does not match" - ); - assertEq( - latestApkUpdate.updateBlockNumber, - uint32(block.number), - "updateBlockNumber not set correctly" - ); - assertEq( - latestApkUpdate.nextUpdateBlockNumber, - uint32(0), - "nextUpdateBlockNumber should be 0 as this is the latest ApkUpdate" - ); - } - } -} - -/** - * @notice test for _processQuorumApkUpdate() internal function - * Called by both registerOperator and deregisterOperator functions - */ -contract BLSApkRegistryUnitTests_quorumApkUpdates is BLSApkRegistryUnitTests { - using BN254 for BN254.G1Point; - using BitmapUtils for *; - - /** - * @dev register/deregister up to 200 operators and check quorum apk updates - * Test uses only the defaultQuorumNumber - */ - function testFuzz_quorumApkUpdates(uint256 numOperators, uint256[200] memory randSeed) public { - cheats.assume(0 < numOperators && numOperators <= 200); ->>>>>>> test: apk registry unit tests and foundry config update (#145) bytes memory quorumNumbers = new bytes(1); quorumNumbers[0] = bytes1(defaultQuorumNumber); _registerRandomBLSPubkey(defaultOperator, randSeed); _registerOperator(defaultOperator, quorumNumbers); -<<<<<<< HEAD BN254.G1Point memory quorumApk = blsApkRegistry.getApk( defaultQuorumNumber ); @@ -1594,186 +1155,24 @@ contract BLSApkRegistryUnitTests_quorumApkUpdates is BLSApkRegistryUnitTests { numRegistrants = bound(numRegistrants, 1, 100); blockGap = bound(blockGap, 0, 100); -======= - /** - * For each operator, randomly proceed with either registering/deregistering an operator - * If registering, we add to quorum apk the operator pubkey and check the quorum apk updates - * Else if deregistering, we add to quorum apk the negated operator pubkey and check the quorum apk updates - */ - for (uint256 i = 0; i < numOperators; i++) { - // register and check quorum apk updates - BN254.G1Point[] memory quorumApksBefore = _getApks(quorumNumbers); - address operator = _selectNewOperator(); - (BN254.G1Point memory operatorPubkey,) = _registerRandomBLSPubkey(operator, randSeed[i]); - _registerOperator(operator, quorumNumbers); - BN254.G1Point[] memory quorumApksAfter = _getApks(quorumNumbers); - _assertQuorumApkUpdates( - quorumNumbers, quorumApksBefore, quorumApksAfter, operatorPubkey - ); - - // deregister and check quorum apk updates - bool isDeregistering = _getRandBool(randSeed[i]); - if (isDeregistering) { - quorumApksBefore = _getApks(quorumNumbers); - _deregisterOperator(operator, quorumNumbers); - quorumApksAfter = _getApks(quorumNumbers); - _assertQuorumApkUpdates( - quorumNumbers, quorumApksBefore, quorumApksAfter, operatorPubkey.negate() - ); - } - } - } - - /** - * @dev register/deregister up to 50 operators fuzzing the quorumNumbers - * and checking quorum apk updates - */ - function testFuzz_quorumApkUpdates_MultiQuorums( - uint32 quorumBitmap, - uint256 numOperators, - uint256[50] memory randSeed - ) public { - cheats.assume(0 < numOperators && numOperators <= 50); - cheats.assume(quorumBitmap > initializedQuorumBitmap); - // mask out quorums that are already initialized - uint192 initializingBitmap = uint192(quorumBitmap.minus(uint256(initializedQuorumBitmap))); - _initializeFuzzedQuorums(initializingBitmap); - bytes memory quorumNumbers = bitmapUtilsWrapper.bitmapToBytesArray(quorumBitmap); - - /** - * For each operator, randomly proceed with either registering/deregistering an operator - * If registering, we add to quorum apk the operator pubkey and check the quorum apk updates - * Else if deregistering, we add to quorum apk the negated operator pubkey and check the quorum apk updates - */ - for (uint256 i = 0; i < numOperators; i++) { - // register and check quorum apk updates - BN254.G1Point[] memory quorumApksBefore = _getApks(quorumNumbers); - address operator = _selectNewOperator(); - (BN254.G1Point memory operatorPubkey,) = _registerRandomBLSPubkey(operator, randSeed[i]); - _registerOperator(operator, quorumNumbers); - BN254.G1Point[] memory quorumApksAfter = _getApks(quorumNumbers); - _assertQuorumApkUpdates( - quorumNumbers, quorumApksBefore, quorumApksAfter, operatorPubkey - ); - - // deregister and check quorum apk updates - bool isDeregistering = _getRandBool(randSeed[i]); - if (isDeregistering) { - quorumApksBefore = _getApks(quorumNumbers); - _deregisterOperator(operator, quorumNumbers); - quorumApksAfter = _getApks(quorumNumbers); - _assertQuorumApkUpdates( - quorumNumbers, quorumApksBefore, quorumApksAfter, operatorPubkey.negate() - ); - } - } - } - - function testFuzz_quorumApkUpdates_DualQuorum( - uint8 quorumNumber1, - uint8 quorumNumber2 - ) public { - cheats.assume(quorumNumber1 != quorumNumber2); - - bytes memory quorumNumbers = new bytes(2); - quorumNumbers[0] = bytes1(quorumNumber1); - quorumNumbers[1] = bytes1(quorumNumber2); - if (!initializedQuorums[quorumNumber1]) { - _initializeFuzzedQuorum(quorumNumber1); - } - if (!initializedQuorums[quorumNumber2]) { - _initializeFuzzedQuorum(quorumNumber2); - } - - BN254.G1Point[] memory quorumApksBefore = new BN254.G1Point[](quorumNumbers.length); - for (uint8 i = 0; i < quorumNumbers.length; i++) { - quorumApksBefore[i] = blsApkRegistry.getApk(uint8(quorumNumbers[i])); - } - - // use harnessed function to directly set the pubkey, bypassing the ordinary checks - blsApkRegistry.setBLSPublicKey(defaultOperator, defaultPubKey); - - cheats.prank(address(registryCoordinator)); - blsApkRegistry.registerOperator(defaultOperator, quorumNumbers); - - //check quorum apk updates - for (uint8 i = 0; i < quorumNumbers.length; i++) { - BN254.G1Point memory quorumApkAfter = blsApkRegistry.getApk(uint8(quorumNumbers[i])); - assertEq( - BN254.hashG1Point(BN254.plus(quorumApkAfter, BN254.negate(quorumApksBefore[i]))), - BN254.hashG1Point(defaultPubKey), - "quorum apk not updated correctly" - ); - } - } - - /** - * @dev register operator BLS pubkey with the negated quorumApk, the quorum apk hash - * should now be the ZERO_PK_HASH - */ - function testFuzz_quorumApkUpdates_RegisterWithNegativeQuorumApk( - address operator, - uint256 randSeed - ) public filterFuzzedAddressInputs(operator) { ->>>>>>> test: apk registry unit tests and foundry config update (#145) bytes memory quorumNumbers = new bytes(1); quorumNumbers[0] = bytes1(defaultQuorumNumber); _registerRandomBLSPubkey(defaultOperator, randSeed); _registerOperator(defaultOperator, quorumNumbers); -<<<<<<< HEAD -======= - BN254.G1Point memory quorumApk = blsApkRegistry.getApk(defaultQuorumNumber); - BN254.G1Point memory negatedQuorumApk = BN254.negate(quorumApk); - - //register for one quorum with negative quorum apk - // use harnessed function to directly set the pubkey, bypassing the ordinary checks - blsApkRegistry.setBLSPublicKey(operator, negatedQuorumApk); - cheats.prank(address(registryCoordinator)); - blsApkRegistry.registerOperator(operator, quorumNumbers); - - assertEq( - BN254.hashG1Point(blsApkRegistry.getApk(defaultQuorumNumber)), - ZERO_PK_HASH, - "quorumApk not set correctly" - ); - } - - /** - * @dev fuzz test for quorum apk updates at a specific block number while randomly - * register/deregistering operators for the defaultQuorumNumber - */ - function testFuzz_quorumApkUpdates_AtBlockNumber( - uint256 numRegistrants, - uint256 blockGap, - uint256 randSeed - ) external { - cheats.assume(numRegistrants > 0 && numRegistrants < 100); - cheats.assume(blockGap < 100); - - bytes memory quorumNumbers = new bytes(1); - quorumNumbers[0] = bytes1(defaultQuorumNumber); - ->>>>>>> test: apk registry unit tests and foundry config update (#145) BN254.G1Point memory quorumApk = BN254.G1Point(0, 0); bytes24 quorumApkHash; for (uint256 i = 0; i < numRegistrants; i++) { // generate operator and register them with BLS pubkey address operator = _selectNewOperator(); -<<<<<<< HEAD (BN254.G1Point memory operatorPubkey, ) = _registerRandomBLSPubkey( operator, uint256(keccak256(abi.encodePacked(operator, randSeed))) -======= - (BN254.G1Point memory operatorPubkey,) = _registerRandomBLSPubkey( - operator, uint256(keccak256(abi.encodePacked(operator, randSeed))) ->>>>>>> test: apk registry unit tests and foundry config update (#145) ); _registerOperator(operator, quorumNumbers); quorumApk = quorumApk.plus(operatorPubkey); quorumApkHash = bytes24(BN254.hashG1Point(quorumApk)); -<<<<<<< HEAD uint256 historyLength = blsApkRegistry.getApkHistoryLength( defaultQuorumNumber ); @@ -1783,13 +1182,6 @@ contract BLSApkRegistryUnitTests_quorumApkUpdates is BLSApkRegistryUnitTests { defaultQuorumNumber, uint32(block.number + blockGap), historyLength - 1 -======= - uint256 historyLength = blsApkRegistry.getApkHistoryLength(defaultQuorumNumber); - assertEq( - quorumApkHash, - blsApkRegistry.getApkHashAtBlockNumberAndIndex( - defaultQuorumNumber, uint32(block.number + blockGap), historyLength - 1 ->>>>>>> test: apk registry unit tests and foundry config update (#145) ), "incorrect quorum apk update" ); @@ -1798,7 +1190,6 @@ contract BLSApkRegistryUnitTests_quorumApkUpdates is BLSApkRegistryUnitTests { _deregisterOperator(operator, quorumNumbers); quorumApk = quorumApk.plus(operatorPubkey.negate()); quorumApkHash = bytes24(BN254.hashG1Point(quorumApk)); -<<<<<<< HEAD historyLength = blsApkRegistry.getApkHistoryLength( defaultQuorumNumber ); @@ -1808,13 +1199,6 @@ contract BLSApkRegistryUnitTests_quorumApkUpdates is BLSApkRegistryUnitTests { defaultQuorumNumber, uint32(block.number + blockGap), historyLength - 1 -======= - historyLength = blsApkRegistry.getApkHistoryLength(defaultQuorumNumber); - assertEq( - quorumApkHash, - blsApkRegistry.getApkHashAtBlockNumberAndIndex( - defaultQuorumNumber, uint32(block.number + blockGap), historyLength - 1 ->>>>>>> test: apk registry unit tests and foundry config update (#145) ), "incorrect quorum apk update" ); @@ -1834,11 +1218,7 @@ contract BLSApkRegistryUnitTests_quorumApkUpdates is BLSApkRegistryUnitTests { uint32 wrongBlockNumber, uint256 randSeed ) external { -<<<<<<< HEAD numRegistrants = bound(numRegistrants, 1, 100); -======= - cheats.assume(numRegistrants > 0 && numRegistrants < 100); ->>>>>>> test: apk registry unit tests and foundry config update (#145) cheats.assume(indexToCheck < numRegistrants - 1); bytes memory quorumNumbers = new bytes(1); quorumNumbers[0] = bytes1(defaultQuorumNumber); @@ -1848,19 +1228,14 @@ contract BLSApkRegistryUnitTests_quorumApkUpdates is BLSApkRegistryUnitTests { for (uint256 i = 0; i < numRegistrants; i++) { address operator = _selectNewOperator(); _registerRandomBLSPubkey( -<<<<<<< HEAD operator, uint256(keccak256(abi.encodePacked(operator, randSeed))) -======= - operator, uint256(keccak256(abi.encodePacked(operator, randSeed))) ->>>>>>> test: apk registry unit tests and foundry config update (#145) ); _registerOperator(operator, quorumNumbers); cheats.roll(block.number + 100); } if (wrongBlockNumber < startingBlockNumber + indexToCheck * 100) { emit log_named_uint("index too recent: ", indexToCheck); -<<<<<<< HEAD cheats.expectRevert( "BLSApkRegistry._validateApkHashAtBlockNumber: index too recent" ); @@ -1873,26 +1248,14 @@ contract BLSApkRegistryUnitTests_quorumApkUpdates is BLSApkRegistryUnitTests { if ( wrongBlockNumber >= startingBlockNumber + (indexToCheck + 1) * 100 ) { -======= - cheats.expectRevert("BLSApkRegistry._validateApkHashAtBlockNumber: index too recent"); - blsApkRegistry.getApkHashAtBlockNumberAndIndex( - defaultQuorumNumber, wrongBlockNumber, indexToCheck - ); - } - if (wrongBlockNumber >= startingBlockNumber + (indexToCheck + 1) * 100) { ->>>>>>> test: apk registry unit tests and foundry config update (#145) emit log_named_uint("index not latest: ", indexToCheck); cheats.expectRevert( "BLSApkRegistry._validateApkHashAtBlockNumber: not latest apk update" ); blsApkRegistry.getApkHashAtBlockNumberAndIndex( -<<<<<<< HEAD defaultQuorumNumber, wrongBlockNumber, indexToCheck -======= - defaultQuorumNumber, wrongBlockNumber, indexToCheck ->>>>>>> test: apk registry unit tests and foundry config update (#145) ); } } @@ -1918,13 +1281,9 @@ contract BLSApkRegistryUnitTests_quorumApkUpdates is BLSApkRegistryUnitTests { BN254.G1Point[] memory quorumApksBefore = new BN254.G1Point[](2); for (uint8 i = 0; i < quorumNumbers.length; i++) { -<<<<<<< HEAD quorumApksBefore[i] = blsApkRegistry.getApk( uint8(quorumNumbers[i]) ); -======= - quorumApksBefore[i] = blsApkRegistry.getApk(uint8(quorumNumbers[i])); ->>>>>>> test: apk registry unit tests and foundry config update (#145) } cheats.startPrank(address(registryCoordinator)); @@ -1934,7 +1293,6 @@ contract BLSApkRegistryUnitTests_quorumApkUpdates is BLSApkRegistryUnitTests { BN254.G1Point memory quorumApkAfter; for (uint8 i = 0; i < quorumNumbers.length; i++) { quorumApkAfter = blsApkRegistry.getApk(uint8(quorumNumbers[i])); -<<<<<<< HEAD BN254.G1Point memory quorumApk = blsApkRegistry.getApk( defaultQuorumNumber ); @@ -1942,11 +1300,6 @@ contract BLSApkRegistryUnitTests_quorumApkUpdates is BLSApkRegistryUnitTests { BN254.hashG1Point( quorumApksBefore[i].plus(defaultPubKey.negate()) ), -======= - BN254.G1Point memory quorumApk = blsApkRegistry.getApk(defaultQuorumNumber); - assertEq( - BN254.hashG1Point(quorumApksBefore[i].plus(defaultPubKey.negate())), ->>>>>>> test: apk registry unit tests and foundry config update (#145) BN254.hashG1Point(quorumApkAfter), "quorum apk not updated correctly" ); diff --git a/test/unit/BLSSignatureCheckerUnit.t.sol b/test/unit/BLSSignatureCheckerUnit.t.sol index 0f43bf84..29369b3f 100644 --- a/test/unit/BLSSignatureCheckerUnit.t.sol +++ b/test/unit/BLSSignatureCheckerUnit.t.sol @@ -38,15 +38,7 @@ contract BLSSignatureCheckerUnitTests is BLSMockAVSDeployer { // this test checks that a valid signature from maxOperatorsToRegister with a random number of nonsigners is checked // correctly on the BLSSignatureChecker contract when all operators are only regsitered for a single quorum and // the signature is only checked for stakes on that quorum -<<<<<<< HEAD -<<<<<<< HEAD function testFuzz_checkSignatures_SingleQuorum(uint256 pseudoRandomNumber) public { -======= - function test_checkSignatures_SingleQuorum(uint256 pseudoRandomNumber) public { ->>>>>>> feat: improve sig checker unit tests (#144) -======= - function testFuzz_checkSignatures_SingleQuorum(uint256 pseudoRandomNumber) public { ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) uint256 numNonSigners = pseudoRandomNumber % (maxOperatorsToRegister - 1); uint256 quorumBitmap = 1; bytes memory quorumNumbers = BitmapUtils.bitmapToBytesArray(quorumBitmap); @@ -249,29 +241,13 @@ contract BLSSignatureCheckerUnitTests is BLSMockAVSDeployer { (/*uint32 referenceBlockNumber*/, BLSSignatureChecker.NonSignerStakesAndSignature memory nonSignerStakesAndSignature) = _registerSignatoriesAndGetNonSignerStakeAndSignatureRandom(pseudoRandomNumber, numNonSigners, quorumBitmap); -<<<<<<< HEAD -<<<<<<< HEAD - // Create an invalid reference block: any block number >= the current block - uint32 invalidReferenceBlock = uint32(block.number + (pseudoRandomNumber % 20)); -======= ->>>>>>> feat: improve sig checker unit tests (#144) -======= // Create an invalid reference block: any block number >= the current block uint32 invalidReferenceBlock = uint32(block.number + (pseudoRandomNumber % 20)); ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) cheats.expectRevert("BLSSignatureChecker.checkSignatures: invalid reference block"); blsSignatureChecker.checkSignatures( msgHash, quorumNumbers, -<<<<<<< HEAD -<<<<<<< HEAD invalidReferenceBlock, -======= - uint32(block.number + 1), ->>>>>>> feat: improve sig checker unit tests (#144) -======= - invalidReferenceBlock, ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) nonSignerStakesAndSignature ); } @@ -338,24 +314,11 @@ contract BLSSignatureCheckerUnitTests is BLSMockAVSDeployer { } // move referenceBlockNumber forward to a block number the last block number where the stakes will be considered "not stale" -<<<<<<< HEAD -<<<<<<< HEAD referenceBlockNumber = uint32(stalestUpdateBlock + delegationMock.minWithdrawalDelayBlocks()) - 1; // roll forward to make the reference block number valid // we roll to referenceBlockNumber + 1 because the current block number is not a valid reference block cheats.roll(referenceBlockNumber + 1); -======= - referenceBlockNumber = uint32(stalestUpdateBlock + delegationMock.withdrawalDelayBlocks()); - // roll forward to make the reference block number valid - cheats.roll(referenceBlockNumber); ->>>>>>> feat: improve sig checker unit tests (#144) -======= - referenceBlockNumber = uint32(stalestUpdateBlock + delegationMock.minWithdrawalDelayBlocks()); - // roll forward to make the reference block number valid - // we roll to referenceBlockNumber + 1 because the current block number is not a valid reference block - cheats.roll(referenceBlockNumber + 1); ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) blsSignatureChecker.checkSignatures( msgHash, quorumNumbers, @@ -365,18 +328,8 @@ contract BLSSignatureCheckerUnitTests is BLSMockAVSDeployer { // move referenceBlockNumber forward one more block, making the stakes "stale" referenceBlockNumber += 1; -<<<<<<< HEAD -<<<<<<< HEAD - // roll forward to reference + 1 to ensure the referenceBlockNumber is still valid - cheats.roll(referenceBlockNumber + 1); -======= - // roll forward to make the reference block number valid - cheats.roll(referenceBlockNumber); ->>>>>>> feat: improve sig checker unit tests (#144) -======= // roll forward to reference + 1 to ensure the referenceBlockNumber is still valid cheats.roll(referenceBlockNumber + 1); ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) cheats.expectRevert("BLSSignatureChecker.checkSignatures: StakeRegistry updates must be within withdrawalDelayBlocks window"); blsSignatureChecker.checkSignatures( msgHash, diff --git a/test/unit/OperatorStateRetrieverUnit.t.sol b/test/unit/OperatorStateRetrieverUnit.t.sol index 0649c55b..89a9d94a 100644 --- a/test/unit/OperatorStateRetrieverUnit.t.sol +++ b/test/unit/OperatorStateRetrieverUnit.t.sol @@ -55,15 +55,7 @@ contract OperatorStateRetrieverUnitTests is MockAVSDeployer { } function test_getOperatorState_revert_quorumNotCreatedAtCallTime() public { -<<<<<<< HEAD -<<<<<<< HEAD cheats.expectRevert("IndexRegistry._operatorCountAtBlockNumber: quorum did not exist at given block number"); -======= - cheats.expectRevert("IndexRegistry._operatorCountAtBlockNumber: quorum does not exist"); ->>>>>>> feat: add tree and start on tests for op state ret (#140) -======= - cheats.expectRevert("IndexRegistry._operatorCountAtBlockNumber: quorum did not exist at given block number"); ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) operatorStateRetriever.getOperatorState(registryCoordinator, BitmapUtils.bitmapToBytesArray(1 << numQuorums), uint32(block.number)); } diff --git a/test/utils/MockAVSDeployer.sol b/test/utils/MockAVSDeployer.sol index 381d61c9..71da5500 100644 --- a/test/utils/MockAVSDeployer.sol +++ b/test/utils/MockAVSDeployer.sol @@ -32,19 +32,11 @@ import {DelegationMock} from "../mocks/DelegationMock.sol"; import {AVSDirectory} from "eigenlayer-contracts/src/contracts/core/AVSDirectory.sol"; import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol"; -<<<<<<< HEAD import {RewardsCoordinatorMock} from "../mocks/RewardsCoordinatorMock.sol"; import { RewardsCoordinator } from "eigenlayer-contracts/src/contracts/core/RewardsCoordinator.sol"; import { IRewardsCoordinator } from "eigenlayer-contracts/src/contracts/interfaces/IRewardsCoordinator.sol"; -======= - -<<<<<<< HEAD -import {AVSDirectoryMock} from "../mocks/AVSDirectoryMock.sol"; ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) -======= ->>>>>>> chore: remove duplicate imports (#197) import {BLSApkRegistryHarness} from "../harnesses/BLSApkRegistryHarness.sol"; import {EmptyContract} from "eigenlayer-contracts/src/test/mocks/EmptyContract.sol"; @@ -84,12 +76,9 @@ contract MockAVSDeployer is Test { AVSDirectory public avsDirectory; AVSDirectory public avsDirectoryImplementation; AVSDirectoryMock public avsDirectoryMock; -<<<<<<< HEAD RewardsCoordinator public rewardsCoordinator; RewardsCoordinator public rewardsCoordinatorImplementation; RewardsCoordinatorMock public rewardsCoordinatorMock; -======= ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) /// @notice StakeRegistry, Constant used as a divisor in calculating weights. uint256 public constant WEIGHTING_DIVISOR = 1e18; @@ -183,7 +172,6 @@ contract MockAVSDeployer is Test { new TransparentUpgradeableProxy( address(avsDirectoryImplementation), address(proxyAdmin), -<<<<<<< HEAD abi.encodeWithSelector( AVSDirectory.initialize.selector, msg.sender, @@ -192,17 +180,6 @@ contract MockAVSDeployer is Test { ) ) ) -======= - abi.encodeWithSelector(AVSDirectory.initialize.selector, msg.sender, pauserRegistry, 0/*initialPausedStatus*/) - ) - ) - ); - - strategyManagerMock.setAddresses( - delegationMock, - eigenPodManagerMock, - slasher ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) ); rewardsCoordinatorMock = new RewardsCoordinatorMock(); @@ -268,10 +245,7 @@ contract MockAVSDeployer is Test { serviceManagerImplementation = new ServiceManagerMock( avsDirectoryMock, -<<<<<<< HEAD IRewardsCoordinator(address(rewardsCoordinatorMock)), -======= ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) registryCoordinator, stakeRegistry ); @@ -375,13 +349,9 @@ contract MockAVSDeployer is Test { ISignatureUtils.SignatureWithSaltAndExpiry memory emptySignatureAndExpiry; cheats.prank(operator); -<<<<<<< HEAD registryCoordinator.registerOperator( quorumNumbers, defaultSocket, pubkeyRegistrationParams, emptySignatureAndExpiry ); -======= - registryCoordinator.registerOperator(quorumNumbers, defaultSocket, pubkeyRegistrationParams, emptySignatureAndExpiry, operator); ->>>>>>> Add support for ecdsa separation. } /** @@ -405,13 +375,9 @@ contract MockAVSDeployer is Test { ISignatureUtils.SignatureWithSaltAndExpiry memory emptySignatureAndExpiry; cheats.prank(operator); -<<<<<<< HEAD registryCoordinator.registerOperator( quorumNumbers, defaultSocket, pubkeyRegistrationParams, emptySignatureAndExpiry ); -======= - registryCoordinator.registerOperator(quorumNumbers, defaultSocket, pubkeyRegistrationParams, emptySignatureAndExpiry, operator); ->>>>>>> Add support for ecdsa separation. } function _registerRandomOperators(uint256 pseudoRandomNumber) @@ -460,16 +426,12 @@ contract MockAVSDeployer is Test { for (uint256 i = 0; i < operatorMetadatas.length; i++) { cheats.roll(registrationBlockNumber + blocksBetweenRegistrations * i); -<<<<<<< HEAD _registerOperatorWithCoordinator( operatorMetadatas[i].operator, operatorMetadatas[i].quorumBitmap, operatorMetadatas[i].pubkey, operatorMetadatas[i].stakes ); -======= - _registerOperatorWithCoordinator(operatorMetadatas[i].operator, operatorMetadatas[i].quorumBitmap, operatorMetadatas[i].pubkey, operatorMetadatas[i].stakes); ->>>>>>> chore: remove duplicate imports (#197) } return (operatorMetadatas, expectedOperatorOverallIndices); @@ -501,7 +463,6 @@ contract MockAVSDeployer is Test { return bytes32(uint256(start) + inc); } -<<<<<<< HEAD function _signOperatorChurnApproval( address registeringOperator, bytes32 registeringOperatorId, @@ -511,15 +472,6 @@ contract MockAVSDeployer is Test { ) internal view returns (ISignatureUtils.SignatureWithSaltAndExpiry memory) { bytes32 digestHash = registryCoordinator.calculateOperatorChurnApprovalDigestHash( registeringOperator, registeringOperatorId, operatorKickParams, salt, expiry -======= - function _signOperatorChurnApproval(address registeringOperator, bytes32 registeringOperatorId, IRegistryCoordinator.OperatorKickParam[] memory operatorKickParams, bytes32 salt, uint256 expiry) internal view returns(ISignatureUtils.SignatureWithSaltAndExpiry memory) { - bytes32 digestHash = registryCoordinator.calculateOperatorChurnApprovalDigestHash( - registeringOperator, - registeringOperatorId, - operatorKickParams, - salt, - expiry ->>>>>>> fixes(m2-mainnet): combined pr for all m2-mainnet fixs (#162) ); (uint8 v, bytes32 r, bytes32 s) = vm.sign(churnApproverPrivateKey, digestHash); return ISignatureUtils.SignatureWithSaltAndExpiry({