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);
16}
17
18pub fn push0<WIRE: InterpreterTypes, H: ?Sized>(context: InstructionContext<'_, H, WIRE>) {
22 check!(context.interpreter, SHANGHAI);
23 push!(context.interpreter, U256::ZERO);
25}
26
27pub fn push<const N: usize, WIRE: InterpreterTypes, H: ?Sized>(
31 context: InstructionContext<'_, H, WIRE>,
32) {
33 let slice = context.interpreter.bytecode.read_slice(N);
36 if !context.interpreter.stack.push_slice(slice) {
37 context.interpreter.halt(InstructionResult::StackOverflow);
38 return;
39 }
40
41 context.interpreter.bytecode.relative_jump(N as isize);
43}
44
45pub fn dup<const N: usize, WIRE: InterpreterTypes, H: ?Sized>(
49 context: InstructionContext<'_, H, WIRE>,
50) {
51 if !context.interpreter.stack.dup(N) {
53 context.interpreter.halt(InstructionResult::StackOverflow);
54 }
55}
56
57pub fn swap<const N: usize, WIRE: InterpreterTypes, H: ?Sized>(
61 context: InstructionContext<'_, H, WIRE>,
62) {
63 assert!(N != 0);
65 if !context.interpreter.stack.exchange(0, N) {
66 context.interpreter.halt(InstructionResult::StackOverflow);
67 }
68}