diff --git a/foundry.toml b/foundry.toml index 6a48adda..f8f557c1 100644 --- a/foundry.toml +++ b/foundry.toml @@ -6,4 +6,7 @@ fs_permissions = [{ access = "read-write", path = "./" }] ffi = true +# The number of optimizer runs +optimizer_runs = 100 + # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/src/BLSApkRegistry.sol b/src/BLSApkRegistry.sol index 71e3a77b..a732a44a 100644 --- a/src/BLSApkRegistry.sol +++ b/src/BLSApkRegistry.sol @@ -32,7 +32,6 @@ contract BLSApkRegistry is BLSApkRegistryStorage { * @notice Registers the `operator`'s pubkey for the specified `quorumNumbers`. * @param operator The address of the operator to register. * @param quorumNumbers The quorum numbers the operator is registering for, where each byte is an 8 bit integer quorumNumber. - * @return pubkeyHash of the operator's pubkey * @dev access restricted to the RegistryCoordinator * @dev Preconditions (these are assumed, not validated in this contract): * 1) `quorumNumbers` has no duplicates @@ -43,16 +42,15 @@ contract BLSApkRegistry is BLSApkRegistryStorage { function registerOperator( address operator, bytes memory quorumNumbers - ) public virtual onlyRegistryCoordinator returns (bytes32) { + ) public virtual onlyRegistryCoordinator { // Get the operator's pubkey. Reverts if they have not registered a key - (BN254.G1Point memory pubkey, bytes32 pubkeyHash) = getRegisteredPubkey(operator); + (BN254.G1Point memory pubkey, ) = getRegisteredPubkey(operator); // Update each quorum's aggregate pubkey _processQuorumApkUpdate(quorumNumbers, pubkey); // Return pubkeyHash, which will become the operator's unique id emit OperatorAddedToQuorums(operator, quorumNumbers); - return pubkeyHash; } /** diff --git a/src/RegistryCoordinator.sol b/src/RegistryCoordinator.sol index 3a84a0f9..b86f9dc6 100644 --- a/src/RegistryCoordinator.sol +++ b/src/RegistryCoordinator.sol @@ -178,25 +178,23 @@ contract RegistryCoordinator is bytes32 operatorId = _getOrCreateOperatorId(msg.sender, params); // Register the operator in each of the registry contracts - RegisterResults memory results = _registerOperator({ + uint32[] memory numOperatorsPerQuorum = _registerOperator({ operator: msg.sender, operatorId: operatorId, quorumNumbers: quorumNumbers, socket: socket, operatorSignature: operatorSignature - }); + }).numOperatorsPerQuorum; for (uint256 i = 0; i < quorumNumbers.length; i++) { uint8 quorumNumber = uint8(quorumNumbers[i]); - - OperatorSetParam memory operatorSetParams = _quorumParams[quorumNumber]; - + /** * The new operator count for each quorum may not exceed the configured maximum * If it does, use `registerOperatorWithChurn` instead. */ require( - results.numOperatorsPerQuorum[i] <= operatorSetParams.maxOperatorCount, + numOperatorsPerQuorum[i] <= _quorumParams[quorumNumber].maxOperatorCount, "RegistryCoordinator.registerOperator: operator count exceeds maximum" ); } @@ -434,7 +432,7 @@ contract RegistryCoordinator is /** * @notice Sets the metadata URI for the AVS * @param _metadataURI is the metadata URI for the AVS - * @dev only callable by the service manager owner + * @dev only callable by the owner */ function setMetadataURI(string memory _metadataURI) external onlyOwner { delegationManager.updateAVSMetadataURI(_metadataURI); @@ -460,7 +458,7 @@ contract RegistryCoordinator is bytes calldata quorumNumbers, string memory socket, SignatureWithSaltAndExpiry memory operatorSignature - ) internal virtual returns (RegisterResults memory) { + ) internal virtual returns (RegisterResults memory results) { /** * Get bitmap of quorums to register for and operator's current bitmap. Validate that: * - we're trying to register for at least 1 quorum @@ -500,26 +498,21 @@ contract RegistryCoordinator is /** * Register the operator with the BLSApkRegistry, StakeRegistry, and IndexRegistry */ - bytes32 registeredId = blsApkRegistry.registerOperator(operator, quorumNumbers); - require(registeredId == operatorId, "RegistryCoordinator._registerOperator: operatorId mismatch"); - (uint96[] memory operatorStakes, uint96[] memory totalStakes) = + blsApkRegistry.registerOperator(operator, quorumNumbers); + (results.operatorStakes, results.totalStakes) = stakeRegistry.registerOperator(operator, operatorId, quorumNumbers); - uint32[] memory numOperatorsPerQuorum = indexRegistry.registerOperator(operatorId, quorumNumbers); + results.numOperatorsPerQuorum = indexRegistry.registerOperator(operatorId, quorumNumbers); - return RegisterResults({ - numOperatorsPerQuorum: numOperatorsPerQuorum, - operatorStakes: operatorStakes, - totalStakes: totalStakes - }); + return results; } function _getOrCreateOperatorId( address operator, IBLSApkRegistry.PubkeyRegistrationParams calldata params ) internal returns (bytes32 operatorId) { - operatorId = blsApkRegistry.getOperatorId(msg.sender); + operatorId = blsApkRegistry.getOperatorId(operator); if (operatorId == 0) { - operatorId = blsApkRegistry.registerBLSPublicKey(msg.sender, params, pubkeyRegistrationMessageHash(msg.sender)); + operatorId = blsApkRegistry.registerBLSPublicKey(operator, params, pubkeyRegistrationMessageHash(operator)); } return operatorId; } diff --git a/src/interfaces/IBLSApkRegistry.sol b/src/interfaces/IBLSApkRegistry.sol index 916320ec..62a3e6b1 100644 --- a/src/interfaces/IBLSApkRegistry.sol +++ b/src/interfaces/IBLSApkRegistry.sol @@ -60,7 +60,7 @@ interface IBLSApkRegistry is IRegistry { * 3) `quorumNumbers` is ordered in ascending order * 4) the operator is not already registered */ - function registerOperator(address operator, bytes calldata quorumNumbers) external returns(bytes32); + function registerOperator(address operator, bytes calldata quorumNumbers) external; /** * @notice Deregisters the `operator`'s pubkey for the specified `quorumNumbers`. diff --git a/test/harnesses/RegistryCoordinatorHarness.sol b/test/harnesses/RegistryCoordinatorHarness.t.sol similarity index 93% rename from test/harnesses/RegistryCoordinatorHarness.sol rename to test/harnesses/RegistryCoordinatorHarness.t.sol index 246ea705..f3ce41a7 100644 --- a/test/harnesses/RegistryCoordinatorHarness.sol +++ b/test/harnesses/RegistryCoordinatorHarness.t.sol @@ -3,8 +3,10 @@ pragma solidity =0.8.12; import "src/RegistryCoordinator.sol"; +import "forge-std/Test.sol"; + // wrapper around the RegistryCoordinator contract that exposes the internal functions for unit testing. -contract RegistryCoordinatorHarness is RegistryCoordinator { +contract RegistryCoordinatorHarness is RegistryCoordinator, Test { constructor( IDelegationManager _delegationManager, ISlasher _slasher, diff --git a/test/unit/BLSApkRegistryUnit.t.sol b/test/unit/BLSApkRegistryUnit.t.sol index 0d8ed07a..81c02654 100644 --- a/test/unit/BLSApkRegistryUnit.t.sol +++ b/test/unit/BLSApkRegistryUnit.t.sol @@ -92,13 +92,11 @@ contract BLSApkRegistryUnitTests is Test { bytes memory quorumNumbers = new bytes(1); quorumNumbers[0] = bytes1(defaultQuorumNumber); - cheats.startPrank(address(registryCoordinator)); - bytes32 registeredpkHash = blsApkRegistry.registerOperator(operator, quorumNumbers); - cheats.stopPrank(); - + cheats.prank(address(registryCoordinator)); + blsApkRegistry.registerOperator(operator, quorumNumbers); + (, bytes32 registeredpkHash) = blsApkRegistry.getRegisteredPubkey(operator); require(registeredpkHash == pkHash, "registeredpkHash not set correctly"); - emit log("ehey"); return pkHash; } diff --git a/test/unit/StakeRegistryUnit.t.sol b/test/unit/StakeRegistryUnit.t.sol index c0ae719b..766e5fe3 100644 --- a/test/unit/StakeRegistryUnit.t.sol +++ b/test/unit/StakeRegistryUnit.t.sol @@ -25,7 +25,7 @@ import {SlasherMock} from "eigenlayer-contracts/src/test/mocks/SlasherMock.sol"; import {StakeRegistryHarness} from "test/harnesses/StakeRegistryHarness.sol"; import {StakeRegistry} from "src/StakeRegistry.sol"; -import {RegistryCoordinatorHarness} from "test/harnesses/RegistryCoordinatorHarness.sol"; +import {RegistryCoordinatorHarness} from "test/harnesses/RegistryCoordinatorHarness.t.sol"; import "forge-std/Test.sol"; diff --git a/test/utils/MockAVSDeployer.sol b/test/utils/MockAVSDeployer.sol index c7f5a757..118cbd03 100644 --- a/test/utils/MockAVSDeployer.sol +++ b/test/utils/MockAVSDeployer.sol @@ -14,7 +14,7 @@ import {BN254} from "src/libraries/BN254.sol"; import {OperatorStateRetriever} from "src/OperatorStateRetriever.sol"; import {RegistryCoordinator} from "src/RegistryCoordinator.sol"; -import {RegistryCoordinatorHarness} from "test/harnesses/RegistryCoordinatorHarness.sol"; +import {RegistryCoordinatorHarness} from "test/harnesses/RegistryCoordinatorHarness.t.sol"; import {BLSApkRegistry} from "src/BLSApkRegistry.sol"; import {StakeRegistry} from "src/StakeRegistry.sol"; import {IndexRegistry} from "src/IndexRegistry.sol";