Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ contract MultipleVersionRollupVerifier is IRollupVerifier, Ownable {
/// @dev Thrown when the given start batch index is smaller than `latestVerifier.startBatchIndex`.
error ErrorStartBatchIndexTooSmall();

/// @dev Verifier not found
error ErrorVerifierNotFound();

/*************
* Constants *
*************/
Expand Down Expand Up @@ -97,15 +100,23 @@ contract MultipleVersionRollupVerifier is IRollupVerifier, Ownable {
Verifier memory _verifier = latestVerifier[_version];

if (_verifier.startBatchIndex > _batchIndex) {
bool found;
uint256 _length = legacyVerifiers[_version].length;
// In most case, only last few verifier will be used by `Rollup`.
// So, we use linear search instead of binary search.
unchecked {
for (uint256 i = _length; i > 0; --i) {
_verifier = legacyVerifiers[_version][i - 1];
if (_verifier.startBatchIndex <= _batchIndex) break;
if (_verifier.startBatchIndex <= _batchIndex) {
found = true;
break;
}
}
}

if (!found) {
revert ErrorVerifierNotFound();
}
}

return _verifier.verifier;
Expand Down
6 changes: 3 additions & 3 deletions contracts/contracts/l1/rollup/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
***************/

/// @notice constructor
/// @param _chainID The chain ID
/// @param _chainID The chain ID
constructor(uint64 _chainID) {
LAYER_2_CHAIN_ID = _chainID;
_disableInitializers();
Expand Down Expand Up @@ -279,7 +279,7 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
BatchHeaderCodecV0.storeBlobVersionedHash(_batchPtr, _blobVersionedHash);
committedBatches[_batchIndex] = BatchHeaderCodecV0.computeBatchHash(_batchPtr, _headerLength);
uint256 proveRemainingTime = 0;
if (inChallenge){
if (inChallenge) {
// Make the batch finalize time longer than the time required for the current challenge
proveRemainingTime = proofWindow + challenges[batchChallenged].startTime - block.timestamp;
}
Expand Down Expand Up @@ -737,7 +737,7 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
return l2BlockNumber;
}

/// @dev Internal function to commit a batch with version 1.
/// @dev Internal function to commit a batch with version 0.
/// @param _blockContexts The encoded block contexts to commit.
/// @param _totalL1MessagesPoppedInBatch The total number of L1 messages popped in current batch.
/// @param _totalL1MessagesPoppedOverall The total number of L1 messages popped in all batches including current batch.
Expand Down
29 changes: 29 additions & 0 deletions contracts/contracts/test/MultipleVersionRollupVerifier.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,35 @@ contract MultipleVersionRollupVerifierTest is DSTestPlus {
assertEq(verifier.getVerifier(version, 10000), address(v2));
}

function test_getVerifier_failures(uint256 version) external {
verifier.initialize(address(rollup));
hevm.assume(version != 0);

verifier.updateVerifier(version, 10, address(v0));
verifier.updateVerifier(version, 100, address(v1));
verifier.updateVerifier(version, 300, address(v2));

hevm.startPrank(address(1));
hevm.expectRevert(MultipleVersionRollupVerifier.ErrorVerifierNotFound.selector);
verifier.getVerifier(version, 1);
hevm.stopPrank();

hevm.startPrank(address(1));
hevm.expectRevert(MultipleVersionRollupVerifier.ErrorVerifierNotFound.selector);
verifier.getVerifier(version, 9);
hevm.stopPrank();

assertEq(verifier.getVerifier(version, 10), address(v0));
assertEq(verifier.getVerifier(version, 11), address(v0));
assertEq(verifier.getVerifier(version, 99), address(v0));
assertEq(verifier.getVerifier(version, 100), address(v1));
assertEq(verifier.getVerifier(version, 101), address(v1));
assertEq(verifier.getVerifier(version, 299), address(v1));
assertEq(verifier.getVerifier(version, 300), address(v2));
assertEq(verifier.getVerifier(version, 301), address(v2));
assertEq(verifier.getVerifier(version, 10000), address(v2));
}

function test_verifyAggregateProof_succeeds(uint256 version) external {
verifier.initialize(address(rollup));
hevm.assume(version != 0);
Expand Down