forked from scroll-tech/scroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultipleVersionRollupVerifier.t.sol
199 lines (168 loc) · 8.91 KB
/
MultipleVersionRollupVerifier.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// SPDX-License-Identifier: MIT
pragma solidity =0.8.24;
import {DSTestPlus} from "solmate/test/utils/DSTestPlus.sol";
import {L1MessageQueue} from "../L1/rollup/L1MessageQueue.sol";
import {MultipleVersionRollupVerifier} from "../L1/rollup/MultipleVersionRollupVerifier.sol";
import {MockScrollChain} from "./mocks/MockScrollChain.sol";
import {MockZkEvmVerifier} from "./mocks/MockZkEvmVerifier.sol";
contract MultipleVersionRollupVerifierTest is DSTestPlus {
// from MultipleVersionRollupVerifier
event UpdateVerifier(uint256 startBatchIndex, address verifier);
MultipleVersionRollupVerifier private verifier;
MockZkEvmVerifier private v0;
MockZkEvmVerifier private v1;
MockZkEvmVerifier private v2;
function setUp() external {
v0 = new MockZkEvmVerifier();
v1 = new MockZkEvmVerifier();
v2 = new MockZkEvmVerifier();
uint256[] memory _versions = new uint256[](1);
address[] memory _verifiers = new address[](1);
_versions[0] = 0;
_verifiers[0] = address(v0);
verifier = new MultipleVersionRollupVerifier(_versions, _verifiers);
}
function testUpdateVerifierVersion0(address _newVerifier) external {
hevm.assume(_newVerifier != address(0));
// set by non-owner, should revert
hevm.startPrank(address(1));
hevm.expectRevert("Ownable: caller is not the owner");
verifier.updateVerifier(0, 0, address(0));
hevm.stopPrank();
// zero verifier address, revert
hevm.expectRevert(MultipleVersionRollupVerifier.ErrorZeroAddress.selector);
verifier.updateVerifier(0, 1, address(0));
// change to random operator
assertEq(verifier.legacyVerifiersLength(0), 0);
verifier.updateVerifier(0, uint64(100), _newVerifier);
assertEq(verifier.legacyVerifiersLength(0), 1);
(uint64 _startBatchIndex, address _verifier) = verifier.latestVerifier(0);
assertEq(_startBatchIndex, uint64(100));
assertEq(_verifier, _newVerifier);
(_startBatchIndex, _verifier) = verifier.legacyVerifiers(0, 0);
assertEq(_startBatchIndex, uint64(0));
assertEq(_verifier, address(v0));
// change to same batch index
verifier.updateVerifier(0, uint64(100), address(v1));
(_startBatchIndex, _verifier) = verifier.latestVerifier(0);
assertEq(_startBatchIndex, uint64(100));
assertEq(_verifier, address(v1));
(_startBatchIndex, _verifier) = verifier.legacyVerifiers(0, 0);
assertEq(_startBatchIndex, uint64(0));
assertEq(_verifier, address(v0));
// start batch index too small, revert
hevm.expectRevert(MultipleVersionRollupVerifier.ErrorStartBatchIndexTooSmall.selector);
verifier.updateVerifier(0, 99, _newVerifier);
}
function testUpdateVerifierVersion(uint256 version, address _newVerifier) external {
hevm.assume(version != 0);
hevm.assume(_newVerifier != address(0));
// set v0
assertEq(verifier.legacyVerifiersLength(version), 0);
verifier.updateVerifier(version, 1, address(v0));
assertEq(verifier.legacyVerifiersLength(version), 0);
(uint64 _startBatchIndex, address _verifier) = verifier.latestVerifier(version);
assertEq(_startBatchIndex, 1);
assertEq(_verifier, address(v0));
// set by non-owner, should revert
hevm.startPrank(address(1));
hevm.expectRevert("Ownable: caller is not the owner");
verifier.updateVerifier(version, 0, address(0));
hevm.stopPrank();
// zero verifier address, revert
hevm.expectRevert(MultipleVersionRollupVerifier.ErrorZeroAddress.selector);
verifier.updateVerifier(version, 1, address(0));
// change to random operator
assertEq(verifier.legacyVerifiersLength(version), 0);
verifier.updateVerifier(version, uint64(100), _newVerifier);
assertEq(verifier.legacyVerifiersLength(version), 1);
(_startBatchIndex, _verifier) = verifier.latestVerifier(version);
assertEq(_startBatchIndex, uint64(100));
assertEq(_verifier, _newVerifier);
(_startBatchIndex, _verifier) = verifier.legacyVerifiers(version, 0);
assertEq(_startBatchIndex, uint64(1));
assertEq(_verifier, address(v0));
// change to same batch index
verifier.updateVerifier(version, uint64(100), address(v1));
(_startBatchIndex, _verifier) = verifier.latestVerifier(version);
assertEq(_startBatchIndex, uint64(100));
assertEq(_verifier, address(v1));
(_startBatchIndex, _verifier) = verifier.legacyVerifiers(version, 0);
assertEq(_startBatchIndex, uint64(1));
assertEq(_verifier, address(v0));
// start batch index too small, revert
hevm.expectRevert(MultipleVersionRollupVerifier.ErrorStartBatchIndexTooSmall.selector);
verifier.updateVerifier(version, 99, _newVerifier);
}
function testGetVerifierV0() external {
verifier.updateVerifier(0, 100, address(v1));
verifier.updateVerifier(0, 300, address(v2));
assertEq(verifier.getVerifier(0, 0), address(v0));
assertEq(verifier.getVerifier(0, 1), address(v0));
assertEq(verifier.getVerifier(0, 99), address(v0));
assertEq(verifier.getVerifier(0, 100), address(v1));
assertEq(verifier.getVerifier(0, 101), address(v1));
assertEq(verifier.getVerifier(0, 299), address(v1));
assertEq(verifier.getVerifier(0, 300), address(v2));
assertEq(verifier.getVerifier(0, 301), address(v2));
assertEq(verifier.getVerifier(0, 10000), address(v2));
}
function testGetVerifier(uint256 version) external {
hevm.assume(version != 0);
verifier.updateVerifier(version, 1, address(v0));
verifier.updateVerifier(version, 100, address(v1));
verifier.updateVerifier(version, 300, address(v2));
assertEq(verifier.getVerifier(version, 1), 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 testVerifyAggregateProofV0() external {
verifier.updateVerifier(0, 100, address(v1));
verifier.updateVerifier(0, 300, address(v2));
hevm.expectRevert(abi.encode(address(v0)));
verifier.verifyAggregateProof(0, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v0)));
verifier.verifyAggregateProof(1, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v0)));
verifier.verifyAggregateProof(99, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v1)));
verifier.verifyAggregateProof(100, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v1)));
verifier.verifyAggregateProof(101, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v1)));
verifier.verifyAggregateProof(299, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v2)));
verifier.verifyAggregateProof(300, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v2)));
verifier.verifyAggregateProof(301, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v2)));
verifier.verifyAggregateProof(10000, new bytes(0), bytes32(0));
}
function testVerifyAggregateProof(uint256 version) external {
hevm.assume(version != 0);
verifier.updateVerifier(version, 1, address(v0));
verifier.updateVerifier(version, 100, address(v1));
verifier.updateVerifier(version, 300, address(v2));
hevm.expectRevert(abi.encode(address(v0)));
verifier.verifyAggregateProof(version, 1, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v0)));
verifier.verifyAggregateProof(version, 99, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v1)));
verifier.verifyAggregateProof(version, 100, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v1)));
verifier.verifyAggregateProof(version, 101, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v1)));
verifier.verifyAggregateProof(version, 299, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v2)));
verifier.verifyAggregateProof(version, 300, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v2)));
verifier.verifyAggregateProof(version, 301, new bytes(0), bytes32(0));
hevm.expectRevert(abi.encode(address(v2)));
verifier.verifyAggregateProof(version, 10000, new bytes(0), bytes32(0));
}
}