Skip to content

Commit

Permalink
refactor: move unvet payload validation to dedicated function
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurayan committed Nov 18, 2024
1 parent 0f565e0 commit 508cd74
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions contracts/0.8.9/DepositSecurityModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -584,20 +584,7 @@ contract DepositSecurityModule {
bytes calldata vettedSigningKeysCounts,
Signature calldata sig
) external {
/// @dev The most likely reason for the signature to go stale
uint256 onchainNonce = STAKING_ROUTER.getStakingModuleNonce(stakingModuleId);
if (nonce != onchainNonce) revert ModuleNonceChanged();

uint256 nodeOperatorsCount = nodeOperatorIds.length / 8;

if (
nodeOperatorIds.length % 8 != 0 ||
vettedSigningKeysCounts.length % 16 != 0 ||
vettedSigningKeysCounts.length / 16 != nodeOperatorsCount ||
nodeOperatorsCount > maxOperatorsPerUnvetting
) {
revert UnvetPayloadInvalid();
}
_checkIfUnvetPayloadValid(nodeOperatorIds, vettedSigningKeysCounts);

address guardianAddr = msg.sender;
int256 guardianIndex = _getGuardianIndex(msg.sender);
Expand Down Expand Up @@ -630,4 +617,23 @@ contract DepositSecurityModule {
vettedSigningKeysCounts
);
}

function _checkIfUnvetPayloadValid(
uint256 stakingModuleId,
uint256 nonce,
bytes calldata nodeOperatorIds,
bytes calldata vettedSigningKeysCounts
) internal view {
/// @dev The most likely reason for the signature to go stale
uint256 onchainNonce = STAKING_ROUTER.getStakingModuleNonce(stakingModuleId);
if (nonce != onchainNonce) revert ModuleNonceChanged();

uint256 nodeOperatorsCount = nodeOperatorIds.length / 8;

if (
nodeOperatorIds.length % 8 != 0 ||
vettedSigningKeysCounts.length != nodeOperatorsCount * 16 ||
nodeOperatorsCount > maxOperatorsPerUnvetting
) revert UnvetPayloadInvalid();
}
}

0 comments on commit 508cd74

Please sign in to comment.