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

Commit

Permalink
Add failing write protection test for TStore
Browse files Browse the repository at this point in the history
  • Loading branch information
Mason Liang committed Apr 30, 2024
1 parent be4b13d commit 3d20797
Showing 1 changed file with 44 additions and 25 deletions.
69 changes: 44 additions & 25 deletions zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,25 @@ mod test {
Account::mock_code_balance(code)
}

enum FailureReason {
Sstore,
TStore,
CallWithValue,
}

#[test]
fn test_write_protection() {
// test sstore with write protection error
test_internal_write_protection(false);
// test call with write protection error
test_internal_write_protection(true);
for reason in [
FailureReason::Sstore,
FailureReason::CallWithValue,
FailureReason::TStore,
] {
test_internal_write_protection(reason)
}
}

// ErrorWriteProtection error happen in internal call
fn test_internal_write_protection(is_call: bool) {
fn test_internal_write_protection(reason: FailureReason) {
let mut caller_bytecode = bytecode! {
PUSH1(0)
PUSH1(0)
Expand All @@ -185,26 +194,36 @@ mod test {
PUSH1(0x02)
};

if is_call {
callee_bytecode.append(&bytecode! {
PUSH1(0)
PUSH1(0)
PUSH1(10)
PUSH1(200) // non zero value
PUSH20(Address::repeat_byte(0xff).to_word())
PUSH2(10000) // gas
//this call got error: ErrorWriteProtection
CALL
RETURN
STOP
});
} else {
callee_bytecode.append(&bytecode! {
// this SSTORE got error: ErrorWriteProtection
SSTORE
STOP
});
}
match reason {
CallWithValue => {
callee_bytecode.append(&bytecode! {
PUSH1(0)
PUSH1(0)
PUSH1(10)
PUSH1(200) // non zero value
PUSH20(Address::repeat_byte(0xff).to_word())
PUSH2(10000) // gas
//this call got error: ErrorWriteProtection
CALL
RETURN
STOP
});
}
Sstore => {

Check failure on line 212 in zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs

View workflow job for this annotation

GitHub Actions / Heavy unit tests

pattern binding `Sstore` is named the same as one of the variants of the type `evm_circuit::execution::error_write_protection::test::FailureReason`

Check failure on line 212 in zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs

View workflow job for this annotation

GitHub Actions / Light unit tests

pattern binding `Sstore` is named the same as one of the variants of the type `evm_circuit::execution::error_write_protection::test::FailureReason`
callee_bytecode.append(&bytecode! {
// this SSTORE got error: ErrorWriteProtection
SSTORE
STOP
});
}
TStore => {

Check failure on line 219 in zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs

View workflow job for this annotation

GitHub Actions / Heavy unit tests

pattern binding `TStore` is named the same as one of the variants of the type `evm_circuit::execution::error_write_protection::test::FailureReason`

Check failure on line 219 in zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs

View workflow job for this annotation

GitHub Actions / Light unit tests

pattern binding `TStore` is named the same as one of the variants of the type `evm_circuit::execution::error_write_protection::test::FailureReason`
callee_bytecode.append(&bytecode! {
// this TSTORE got error: ErrorWriteProtection
TSTORE
STOP
});
}
};

test_ok(
Account::mock_100_ether(caller_bytecode),
Expand Down

0 comments on commit 3d20797

Please sign in to comment.