From 69931165946c2c858c762e0066172d65ed68077f Mon Sep 17 00:00:00 2001 From: 8sunyuan Date: Thu, 30 Nov 2023 11:18:51 -0500 Subject: [PATCH] feat: timestamp requirement is able to be toggled --- src/BLSSignatureChecker.sol | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/BLSSignatureChecker.sol b/src/BLSSignatureChecker.sol index 44e29e51..36c05245 100644 --- a/src/BLSSignatureChecker.sol +++ b/src/BLSSignatureChecker.sol @@ -28,12 +28,22 @@ contract BLSSignatureChecker is IBLSSignatureChecker { IStakeRegistry public immutable stakeRegistry; IBLSPubkeyRegistry public immutable blsPubkeyRegistry; IDelegationManager public immutable delegation; + IServiceManager public immutable serviceManager; + /// @notice If true, check that the signature timestamp is within the delegation withdrawalDelayBlocks window. + bool public isTimestampChecked; + + modifier onlyServiceManagerOwner { + require(msg.sender == serviceManager.owner(), "BLSSignatureChecker.onlyServiceManagerOwner: caller is not the service manager owner"); + _; + } constructor(IBLSRegistryCoordinatorWithIndices _registryCoordinator) { registryCoordinator = IRegistryCoordinator(_registryCoordinator); stakeRegistry = _registryCoordinator.stakeRegistry(); blsPubkeyRegistry = _registryCoordinator.blsPubkeyRegistry(); delegation = stakeRegistry.delegation(); + serviceManager = _registryCoordinator.serviceManager(); + isTimestampChecked = true; } /** @@ -75,10 +85,12 @@ contract BLSSignatureChecker is IBLSSignatureChecker { // loop through every quorumNumber and keep track of the apk BN254.G1Point memory apk = BN254.G1Point(0, 0); for (uint i = 0; i < quorumNumbers.length; i++) { - require( - registryCoordinator.quorumUpdateBlocknumber(uint8(quorumNumbers[i])) + delegation.withdrawalDelayBlocks() <= block.number, - "BLSSignatureChecker.checkSignatures: StakeRegistry updates must be within withdrawalDelayBlocks window" - ); + if (isTimestampChecked) { + require( + registryCoordinator.quorumUpdateBlocknumber(uint8(quorumNumbers[i])) + delegation.withdrawalDelayBlocks() <= block.number, + "BLSSignatureChecker.checkSignatures: StakeRegistry updates must be within withdrawalDelayBlocks window" + ); + } require( bytes24(nonSignerStakesAndSignature.quorumApks[i].hashG1Point()) == IBLSPubkeyRegistry(blsPubkeyRegistry).getApkHashAtBlockNumberAndIndex( @@ -207,4 +219,13 @@ contract BLSSignatureChecker is IBLSSignatureChecker { PAIRING_EQUALITY_CHECK_GAS ); } + + /** + * ServiceManager owner can either enforce or not require that the signature timestamp is checked + * within the delegation.withdrawalDelayBlocks() window. + * @param value to toggle checkSignatureTimestamp on or off + */ + function setSignatureTimestampCheck(bool value) external onlyServiceManagerOwner { + isTimestampChecked = value; + } }