revm_interpreter/instructions/
stack.rs1use crate::{
2 interpreter_types::{Immediates, InterpreterTypes, Jumps, RuntimeFlag, StackTr},
3 InstructionResult,
4};
5use primitives::U256;
6
7use crate::InstructionContext;
8
9pub fn pop<WIRE: InterpreterTypes, H: ?Sized>(context: InstructionContext<'_, H, WIRE>) {
13 popn!([_i], context.interpreter);
15}
16
17pub fn push0<WIRE: InterpreterTypes, H: ?Sized>(context: InstructionContext<'_, H, WIRE>) {
21 check!(context.interpreter, SHANGHAI);
22 push!(context.interpreter, U256::ZERO);
23}
24
25pub fn push<const N: usize, WIRE: InterpreterTypes, H: ?Sized>(
29 context: InstructionContext<'_, H, WIRE>,
30) {
31 let slice = context.interpreter.bytecode.read_slice(N);
32 if !context.interpreter.stack.push_slice(slice) {
33 context.interpreter.halt(InstructionResult::StackOverflow);
34 return;
35 }
36
37 context.interpreter.bytecode.relative_jump(N as isize);
39}
40
41pub fn dup<const N: usize, WIRE: InterpreterTypes, H: ?Sized>(
45 context: InstructionContext<'_, H, WIRE>,
46) {
47 if !context.interpreter.stack.dup(N) {
48 context.interpreter.halt(InstructionResult::StackOverflow);
49 }
50}
51
52pub fn swap<const N: usize, WIRE: InterpreterTypes, H: ?Sized>(
56 context: InstructionContext<'_, H, WIRE>,
57) {
58 assert!(N != 0);
59 if !context.interpreter.stack.exchange(0, N) {
60 context.interpreter.halt(InstructionResult::StackOverflow);
61 }
62}