Skip to content

Commit

Permalink
feat: timestamp requirement is able to be toggled
Browse files Browse the repository at this point in the history
  • Loading branch information
8sunyuan committed Nov 30, 2023
1 parent ecf8fca commit 6993116
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/BLSSignatureChecker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 6993116

Please sign in to comment.