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

Commit

Permalink
Handle reverts and write protection failure for TSTORE in bus mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Mason Liang committed Apr 30, 2024
1 parent 18845eb commit 0105019
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
9 changes: 9 additions & 0 deletions bus-mapping/src/circuit_input_builder/input_state_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,14 @@ impl<'a> CircuitInputStateRef<'a> {
None
}
}
OperationRef(Target::TransientStorage, idx) => {
let operation = &self.block.container.transient_storage[*idx];
if operation.rw().is_write() && operation.reversible() {
Some(OpEnum::TransientStorage(operation.op().reverse()))
} else {
None
}
}
OperationRef(Target::TxAccessListAccount, idx) => {
let operation = &self.block.container.tx_access_list_account[*idx];
if operation.rw().is_write() && operation.reversible() {
Expand Down Expand Up @@ -1436,6 +1444,7 @@ impl<'a> CircuitInputStateRef<'a> {
OpcodeId::RETURNDATACOPY => Some(ExecError::ReturnDataOutOfBounds),
// Break write protection (CALL with value will be handled below)
OpcodeId::SSTORE
| OpcodeId::TSTORE
| OpcodeId::CREATE
| OpcodeId::CREATE2
| OpcodeId::SELFDESTRUCT
Expand Down
1 change: 1 addition & 0 deletions bus-mapping/src/evm/opcodes/error_write_protection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl Opcode for ErrorWriteProtection {
// assert op code can only be following codes
assert!([
OpcodeId::SSTORE,
OpcodeId::TSTORE,
OpcodeId::CREATE,
OpcodeId::CREATE2,
OpcodeId::CALL,
Expand Down
7 changes: 5 additions & 2 deletions bus-mapping/src/operation/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ impl OperationContainer {
OperationRef::from((Target::Storage, self.storage.len() - 1))
}
OpEnum::TransientStorage(op) => {
self.transient_storage
.push(Operation::new(rwc, rwc_inner_chunk, rw, op));
self.transient_storage.push(if reversible {
Operation::new_reversible(rwc, rwc_inner_chunk, rw, op)
} else {
Operation::new(rwc, rwc_inner_chunk, rw, op)
});
OperationRef::from((Target::TransientStorage, self.transient_storage.len() - 1))
}
OpEnum::TxAccessListAccount(op) => {
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/tstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ mod test {
accs[0]
.address(MOCK_ACCOUNTS[0])
.balance(Word::from(10u64.pow(19)))
.code(bytecode)
.code(bytecode);
accs[1]
.address(MOCK_ACCOUNTS[1])
.balance(Word::from(10u64.pow(19)));
Expand Down

0 comments on commit 0105019

Please sign in to comment.