Skip to content

Commit bc22e73

Browse files
committed
add StackPopOnlyOpcode
1 parent 3b3954e commit bc22e73

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

bus-mapping/src/evm/opcodes.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ use returndatasize::Returndatasize;
118118
use selfbalance::Selfbalance;
119119
use sload::Sload;
120120
use sstore::Sstore;
121-
use stackonlyop::StackOnlyOpcode;
121+
use stackonlyop::{StackOnlyOpcode, StackPopOnlyOpcode};
122122
use stop::Stop;
123123
use swap::Swap;
124124

@@ -222,14 +222,14 @@ fn fn_gen_associated_ops(opcode_id: &OpcodeId) -> FnGenAssociatedOps {
222222
OpcodeId::CHAINID => StackOnlyOpcode::<0, 1>::gen_associated_ops,
223223
OpcodeId::SELFBALANCE => Selfbalance::gen_associated_ops,
224224
OpcodeId::BASEFEE => StackOnlyOpcode::<0, 1>::gen_associated_ops,
225-
OpcodeId::POP => StackOnlyOpcode::<1, 0>::gen_associated_ops,
225+
OpcodeId::POP => StackPopOnlyOpcode::<1>::gen_associated_ops,
226226
OpcodeId::MLOAD => Mload::gen_associated_ops,
227227
OpcodeId::MSTORE => Mstore::<false>::gen_associated_ops,
228228
OpcodeId::MSTORE8 => Mstore::<true>::gen_associated_ops,
229229
OpcodeId::SLOAD => Sload::gen_associated_ops,
230230
OpcodeId::SSTORE => Sstore::gen_associated_ops,
231-
OpcodeId::JUMP => StackOnlyOpcode::<1, 0>::gen_associated_ops,
232-
OpcodeId::JUMPI => StackOnlyOpcode::<2, 0>::gen_associated_ops,
231+
OpcodeId::JUMP => StackPopOnlyOpcode::<1>::gen_associated_ops,
232+
OpcodeId::JUMPI => StackPopOnlyOpcode::<2>::gen_associated_ops,
233233
OpcodeId::PC => StackOnlyOpcode::<0, 1>::gen_associated_ops,
234234
OpcodeId::MSIZE => StackOnlyOpcode::<0, 1>::gen_associated_ops,
235235
OpcodeId::GAS => StackOnlyOpcode::<0, 1>::gen_associated_ops,

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

+22
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,28 @@ impl<const N_POP: usize, const N_PUSH: usize, const IS_ERR: bool> Opcode
5454
}
5555
}
5656

57+
#[derive(Debug, Copy, Clone)]
58+
pub(crate) struct StackPopOnlyOpcode<const N_POP: usize>;
59+
60+
impl<const N_POP: usize> Opcode for StackPopOnlyOpcode<N_POP> {
61+
fn gen_associated_ops(
62+
state: &mut CircuitInputStateRef,
63+
geth_steps: &[GethExecStep],
64+
) -> Result<Vec<ExecStep>, Error> {
65+
let geth_step = &geth_steps[0];
66+
let mut exec_step = state.new_step(geth_step)?;
67+
// N_POP stack reads
68+
for i in 0..N_POP {
69+
assert_eq!(
70+
geth_step.stack.nth_last(i)?,
71+
state.stack_pop(&mut exec_step)?
72+
);
73+
}
74+
75+
Ok(vec![exec_step])
76+
}
77+
}
78+
5779
#[cfg(test)]
5880
mod stackonlyop_tests {
5981
use crate::{

0 commit comments

Comments
 (0)