Skip to content

Commit

Permalink
Merge pull request #105 from Layr-Labs/fix-address-contract-code-size…
Browse files Browse the repository at this point in the history
…-issues

fix: address contract code size issues
  • Loading branch information
ChaoticWalrus authored Dec 13, 2023
2 parents 891a219 + d03039f commit 05402be
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 32 deletions.
3 changes: 3 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions src/BLSApkRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

/**
Expand Down
31 changes: 12 additions & 19 deletions src/RegistryCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IBLSApkRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions test/unit/BLSApkRegistryUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/StakeRegistryUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion test/utils/MockAVSDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 05402be

Please sign in to comment.