|
1 | 1 | //! Execution step related module.
|
2 | 2 |
|
3 | 3 | use crate::{
|
4 |
| - circuit_input_builder::CallContext, error::ExecError, exec_trace::OperationRef, |
| 4 | + circuit_input_builder::CallContext, |
| 5 | + error::{ExecError, OogError}, |
| 6 | + exec_trace::OperationRef, |
5 | 7 | operation::RWCounter,
|
| 8 | + precompile::PrecompileCalls, |
6 | 9 | };
|
7 | 10 | use eth_types::{evm_types::OpcodeId, GethExecStep, Word, H256};
|
8 | 11 | use gadgets::impl_expr;
|
@@ -60,6 +63,7 @@ impl ExecStep {
|
60 | 63 | ExecStep {
|
61 | 64 | exec_state: ExecState::Op(step.op),
|
62 | 65 | pc: step.pc,
|
| 66 | + |
63 | 67 | stack_size: step.stack.0.len(),
|
64 | 68 | memory_size: call_ctx.memory.len(),
|
65 | 69 | gas_left: step.gas,
|
@@ -117,13 +121,25 @@ impl ExecStep {
|
117 | 121 | assert_eq!(memory_size % n_bytes_word, 0);
|
118 | 122 | memory_size / n_bytes_word
|
119 | 123 | }
|
| 124 | + |
| 125 | + /// Returns `true` if this is an execution step of Precompile. |
| 126 | + pub fn is_precompiled(&self) -> bool { |
| 127 | + matches!(self.exec_state, ExecState::Precompile(_)) |
| 128 | + } |
| 129 | + |
| 130 | + /// Returns `true` if `error` is oog in precompile calls |
| 131 | + pub fn is_precompile_oog_err(&self) -> bool { |
| 132 | + matches!(self.error, Some(ExecError::OutOfGas(OogError::Precompile))) |
| 133 | + } |
120 | 134 | }
|
121 | 135 |
|
122 | 136 | /// Execution state
|
123 | 137 | #[derive(Clone, Debug, Eq, PartialEq)]
|
124 | 138 | pub enum ExecState {
|
125 | 139 | /// EVM Opcode ID
|
126 | 140 | Op(OpcodeId),
|
| 141 | + /// Precompile call |
| 142 | + Precompile(PrecompileCalls), |
127 | 143 | /// Virtual step Begin Tx
|
128 | 144 | BeginTx,
|
129 | 145 | /// Virtual step End Tx
|
@@ -279,14 +295,14 @@ impl CopyEvent {
|
279 | 295 | // increase in rw counter from the start of the copy event to step index
|
280 | 296 | fn rw_counter_increase(&self, step_index: usize) -> u64 {
|
281 | 297 | let source_rw_increase = match self.src_type {
|
282 |
| - CopyDataType::Bytecode | CopyDataType::TxCalldata => 0, |
| 298 | + CopyDataType::Bytecode | CopyDataType::TxCalldata | CopyDataType::RlcAcc => 0, |
283 | 299 | CopyDataType::Memory => std::cmp::min(
|
284 | 300 | u64::try_from(step_index + 1).unwrap() / 2,
|
285 | 301 | self.src_addr_end
|
286 | 302 | .checked_sub(self.src_addr)
|
287 | 303 | .unwrap_or_default(),
|
288 | 304 | ),
|
289 |
| - CopyDataType::RlcAcc | CopyDataType::TxLog | CopyDataType::Padding => unreachable!(), |
| 305 | + CopyDataType::TxLog | CopyDataType::Padding => unreachable!(), |
290 | 306 | };
|
291 | 307 | let destination_rw_increase = match self.dst_type {
|
292 | 308 | CopyDataType::RlcAcc | CopyDataType::Bytecode => 0,
|
|
0 commit comments