Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.

Commit 18845eb

Browse files
author
Mason Liang
committed
Add failing write protection test for TStore
1 parent be4b13d commit 18845eb

File tree

1 file changed

+45
-25
lines changed

1 file changed

+45
-25
lines changed

zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs

+45-25
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,26 @@ mod test {
155155
Account::mock_code_balance(code)
156156
}
157157

158+
#[derive(Copy, Clone, Debug)]
159+
enum FailureReason {
160+
Sstore,
161+
TStore,
162+
CallWithValue,
163+
}
164+
158165
#[test]
159166
fn test_write_protection() {
160-
// test sstore with write protection error
161-
test_internal_write_protection(false);
162-
// test call with write protection error
163-
test_internal_write_protection(true);
167+
for reason in [
168+
FailureReason::Sstore,
169+
FailureReason::CallWithValue,
170+
FailureReason::TStore,
171+
] {
172+
test_internal_write_protection(reason)
173+
}
164174
}
165175

166176
// ErrorWriteProtection error happen in internal call
167-
fn test_internal_write_protection(is_call: bool) {
177+
fn test_internal_write_protection(reason: FailureReason) {
168178
let mut caller_bytecode = bytecode! {
169179
PUSH1(0)
170180
PUSH1(0)
@@ -185,26 +195,36 @@ mod test {
185195
PUSH1(0x02)
186196
};
187197

188-
if is_call {
189-
callee_bytecode.append(&bytecode! {
190-
PUSH1(0)
191-
PUSH1(0)
192-
PUSH1(10)
193-
PUSH1(200) // non zero value
194-
PUSH20(Address::repeat_byte(0xff).to_word())
195-
PUSH2(10000) // gas
196-
//this call got error: ErrorWriteProtection
197-
CALL
198-
RETURN
199-
STOP
200-
});
201-
} else {
202-
callee_bytecode.append(&bytecode! {
203-
// this SSTORE got error: ErrorWriteProtection
204-
SSTORE
205-
STOP
206-
});
207-
}
198+
match reason {
199+
FailureReason::CallWithValue => {
200+
callee_bytecode.append(&bytecode! {
201+
PUSH1(0)
202+
PUSH1(0)
203+
PUSH1(10)
204+
PUSH1(200) // non zero value
205+
PUSH20(Address::repeat_byte(0xff).to_word())
206+
PUSH2(10000) // gas
207+
//this call got error: ErrorWriteProtection
208+
CALL
209+
RETURN
210+
STOP
211+
});
212+
}
213+
FailureReason::Sstore => {
214+
callee_bytecode.append(&bytecode! {
215+
// this SSTORE got error: ErrorWriteProtection
216+
SSTORE
217+
STOP
218+
});
219+
}
220+
FailureReason::TStore => {
221+
callee_bytecode.append(&bytecode! {
222+
// this TSTORE got error: ErrorWriteProtection
223+
TSTORE
224+
STOP
225+
});
226+
}
227+
};
208228

209229
test_ok(
210230
Account::mock_100_ether(caller_bytecode),

0 commit comments

Comments
 (0)