Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit 6c9df1a

Browse files
committed
fix precompile revert
1 parent cd35d7b commit 6c9df1a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bus-mapping/src/evm/opcodes/error_precompile_failed.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{
22
circuit_input_builder::{CircuitInputStateRef, ExecStep},
33
error::ExecError,
44
evm::Opcode,
5+
operation::CallContextField,
56
Error,
67
};
78
use eth_types::{evm_types::OpcodeId, GethExecStep};
@@ -33,7 +34,7 @@ impl Opcode for PrecompileFailed {
3334
state.call_expand_memory(args_offset, args_length, ret_offset, ret_length)?;
3435

3536
let call = state.parse_call(geth_step)?;
36-
state.push_call(call);
37+
state.push_call(call.clone());
3738
state.handle_return(&mut exec_step, geth_steps, false)?;
3839

3940
for i in 0..stack_input_num {
@@ -51,6 +52,14 @@ impl Opcode for PrecompileFailed {
5152
(0_u64).into(),
5253
)?;
5354

55+
for (field, value) in [
56+
(CallContextField::LastCalleeId, call.call_id.into()),
57+
(CallContextField::LastCalleeReturnDataOffset, 0.into()),
58+
(CallContextField::LastCalleeReturnDataLength, 0.into()),
59+
] {
60+
state.call_context_write(&mut exec_step, call.caller_id, field, value);
61+
}
62+
5463
Ok(vec![exec_step])
5564
}
5665
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{
99
CachedRegion, Cell, Word,
1010
},
1111
},
12+
table::CallContextFieldTag,
1213
util::Expr,
1314
witness::{Block, Call, ExecStep, Transaction},
1415
};
@@ -46,6 +47,9 @@ impl<F: Field> ExecutionGadget<F> for ErrorPrecompileFailedGadget<F> {
4647
let is_staticcall =
4748
IsZeroGadget::construct(cb, opcode.expr() - OpcodeId::STATICCALL.expr());
4849

50+
// Use rw_counter of the step which triggers next call as its call_id.
51+
let callee_call_id = cb.curr.state.rw_counter.clone();
52+
4953
let gas = cb.query_word_rlc();
5054
let callee_address = cb.query_word_rlc();
5155
let value = cb.query_word_rlc();
@@ -67,6 +71,14 @@ impl<F: Field> ExecutionGadget<F> for ErrorPrecompileFailedGadget<F> {
6771
cb.stack_pop(rd_length.expr());
6872
cb.stack_push(0.expr());
6973

74+
for (field_tag, value) in [
75+
(CallContextFieldTag::LastCalleeId, callee_call_id.expr()),
76+
(CallContextFieldTag::LastCalleeReturnDataOffset, 0.expr()),
77+
(CallContextFieldTag::LastCalleeReturnDataLength, 0.expr()),
78+
] {
79+
cb.call_context_lookup(true.expr(), None, field_tag, value);
80+
}
81+
7082
let cd_address = MemoryAddressGadget::construct(cb, cd_offset, cd_length);
7183
let rd_address = MemoryAddressGadget::construct(cb, rd_offset, rd_length);
7284

0 commit comments

Comments
 (0)