Skip to content

Commit

Permalink
feat: add limit on keys per operator
Browse files Browse the repository at this point in the history
  • Loading branch information
blockgroot committed Dec 9, 2024
1 parent 3618d8a commit acacb35
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions contracts/PermissionlessNodeRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ contract PermissionlessNodeRegistry is
//mapping of operator address with nodeELReward vault address
mapping(uint256 => address) public override nodeELRewardVaultByOperatorId;
mapping(uint256 => address) public proposedRewardAddressByOperatorId;
uint256 public maxKeyPerOperator;

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
Expand Down Expand Up @@ -150,6 +151,10 @@ contract PermissionlessNodeRegistry is
) public payable override nonReentrant whenNotPaused {
uint256 operatorId = onlyActiveOperator(msg.sender);
uint256 keyCount = _pubkey.length;
uint256 totalKeys = getOperatorTotalKeys(operatorId);
if (totalKeys + keyCount > maxKeyPerOperator) {
revert MaxKeyLimitExceed();

Check warning on line 156 in contracts/PermissionlessNodeRegistry.sol

View check run for this annotation

Codecov / codecov/patch

contracts/PermissionlessNodeRegistry.sol#L156

Added line #L156 was not covered by tests
}
if (keyCount != _preDepositSignature.length || keyCount != _depositSignature.length) {
revert MisMatchingInputKeysSize();
}
Expand Down Expand Up @@ -444,6 +449,16 @@ contract PermissionlessNodeRegistry is
emit TransferredCollateralToPool(_amount);
}

/**
* @notice update the max validator per operator value
* @dev only `MANAGER` role can update
*/
function updateMaxKeyPerOperator(uint256 _maxKeyPerOperator) external {
UtilLib.onlyManagerRole(msg.sender, staderConfig);
maxKeyPerOperator = _maxKeyPerOperator;
emit UpdateMaxKeyPerOperator(_maxKeyPerOperator);
}

/**
* @param _nodeOperator @notice operator total non terminal keys within a specified validator list
* @param _startIndex start index in validator queue to start with
Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/IPermissionlessNodeRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface IPermissionlessNodeRegistry {
error InSufficientBalance();
error CooldownNotComplete();
error NoChangeInState();
error MaxKeyLimitExceed();

// Events
event OnboardedOperator(
Expand All @@ -21,6 +22,7 @@ interface IPermissionlessNodeRegistry {
event UpdatedSocializingPoolState(uint256 operatorId, bool optedForSocializingPool, uint256 block);
event TransferredCollateralToPool(uint256 amount);
event ValidatorAddedViaReferral(uint256 amount, string referralId);
event UpdateMaxKeyPerOperator(uint256 maxKeyPerOperator);

//Getters

Expand Down
2 changes: 2 additions & 0 deletions test/foundry_tests/PermissionlessNodeRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ contract PermissionlessNodeRegistryTest is Test {
staderConfig.grantRole(staderConfig.OPERATOR(), operator);
vaultFactory.grantRole(vaultFactory.NODE_REGISTRY_CONTRACT(), address(nodeRegistry));
vm.stopPrank();
vm.prank(staderManager);
nodeRegistry.updateMaxKeyPerOperator(500);
}

function test_JustToIncreaseCoverage() public {
Expand Down

0 comments on commit acacb35

Please sign in to comment.