Skip to content

Commit

Permalink
feat: import change from scroll-tech/scroll#1372 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimpha authored Jun 24, 2024
1 parent 9e4e333 commit ca7f076
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 33 deletions.
2 changes: 1 addition & 1 deletion scripts/foundry/DeployL1BridgeContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ contract DeployL1BridgeContracts is Script {
address[] memory _verifiers = new address[](1);
_versions[0] = 0;
_verifiers[0] = address(zkEvmVerifierV1);
rollupVerifier = new MultipleVersionRollupVerifier(L1_SCROLL_CHAIN_PROXY_ADDR, _versions, _verifiers);
rollupVerifier = new MultipleVersionRollupVerifier(_versions, _verifiers);

logAddress("L1_MULTIPLE_VERSION_ROLLUP_VERIFIER_ADDR", address(rollupVerifier));
}
Expand Down
27 changes: 6 additions & 21 deletions src/L1/rollup/MultipleVersionRollupVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity =0.8.24;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

import {IScrollChain} from "./IScrollChain.sol";
import {IRollupVerifier} from "../../libraries/verifier/IRollupVerifier.sol";
import {IZkEvmVerifier} from "../../libraries/verifier/IZkEvmVerifier.sol";

Expand All @@ -28,19 +27,9 @@ contract MultipleVersionRollupVerifier is IRollupVerifier, Ownable {
/// @dev Thrown when the given address is `address(0)`.
error ErrorZeroAddress();

/// @dev Thrown when the given start batch index is finalized.
error ErrorStartBatchIndexFinalized();

/// @dev Thrown when the given start batch index is smaller than `latestVerifier.startBatchIndex`.
error ErrorStartBatchIndexTooSmall();

/*************
* Constants *
*************/

/// @notice The address of ScrollChain contract.
address public immutable scrollChain;

/***********
* Structs *
***********/
Expand All @@ -67,14 +56,7 @@ contract MultipleVersionRollupVerifier is IRollupVerifier, Ownable {
* Constructor *
***************/

constructor(
address _scrollChain,
uint256[] memory _versions,
address[] memory _verifiers
) {
if (_scrollChain == address(0)) revert ErrorZeroAddress();
scrollChain = _scrollChain;

constructor(uint256[] memory _versions, address[] memory _verifiers) {
for (uint256 i = 0; i < _versions.length; i++) {
if (_verifiers[i] == address(0)) revert ErrorZeroAddress();
latestVerifier[_versions[i]].verifier = _verifiers[i];
Expand Down Expand Up @@ -157,8 +139,11 @@ contract MultipleVersionRollupVerifier is IRollupVerifier, Ownable {
uint64 _startBatchIndex,
address _verifier
) external onlyOwner {
if (_startBatchIndex <= IScrollChain(scrollChain).lastFinalizedBatchIndex())
revert ErrorStartBatchIndexFinalized();
// We are using version to decide the verifier to use and also this function is
// controlled by 7 days TimeLock. It is hard to predict `lastFinalizedBatchIndex` after 7 days.
// So we decide to remove this check to make verifier updating more easier.
// if (_startBatchIndex <= IScrollChain(scrollChain).lastFinalizedBatchIndex())
// revert ErrorStartBatchIndexFinalized();

Verifier memory _latestVerifier = latestVerifier[_version];
if (_startBatchIndex < _latestVerifier.startBatchIndex) revert ErrorStartBatchIndexTooSmall();
Expand Down
12 changes: 1 addition & 11 deletions src/test/MultipleVersionRollupVerifier.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@ contract MultipleVersionRollupVerifierTest is DSTestPlus {
MockZkEvmVerifier private v0;
MockZkEvmVerifier private v1;
MockZkEvmVerifier private v2;
MockScrollChain private chain;

function setUp() external {
v0 = new MockZkEvmVerifier();
v1 = new MockZkEvmVerifier();
v2 = new MockZkEvmVerifier();

chain = new MockScrollChain(address(1), address(1));
uint256[] memory _versions = new uint256[](1);
address[] memory _verifiers = new address[](1);
_versions[0] = 0;
_verifiers[0] = address(v0);
verifier = new MultipleVersionRollupVerifier(address(chain), _versions, _verifiers);
verifier = new MultipleVersionRollupVerifier(_versions, _verifiers);
}

function testUpdateVerifierVersion0(address _newVerifier) external {
Expand All @@ -42,10 +40,6 @@ contract MultipleVersionRollupVerifierTest is DSTestPlus {
verifier.updateVerifier(0, 0, address(0));
hevm.stopPrank();

// start batch index finalized, revert
hevm.expectRevert(MultipleVersionRollupVerifier.ErrorStartBatchIndexFinalized.selector);
verifier.updateVerifier(0, 0, address(1));

// zero verifier address, revert
hevm.expectRevert(MultipleVersionRollupVerifier.ErrorZeroAddress.selector);
verifier.updateVerifier(0, 1, address(0));
Expand Down Expand Up @@ -93,10 +87,6 @@ contract MultipleVersionRollupVerifierTest is DSTestPlus {
verifier.updateVerifier(version, 0, address(0));
hevm.stopPrank();

// start batch index finalized, revert
hevm.expectRevert(MultipleVersionRollupVerifier.ErrorStartBatchIndexFinalized.selector);
verifier.updateVerifier(version, 0, address(1));

// zero verifier address, revert
hevm.expectRevert(MultipleVersionRollupVerifier.ErrorZeroAddress.selector);
verifier.updateVerifier(version, 1, address(0));
Expand Down

0 comments on commit ca7f076

Please sign in to comment.