pallet_revive/vm/evm/instructions/
stack.rs1use super::{utility::cast_slice_to_u256, Context};
19use crate::vm::Ext;
20use revm::{
21 interpreter::{
22 gas as revm_gas,
23 interpreter_types::{Immediates, Jumps, RuntimeFlag, StackTr},
24 InstructionResult,
25 },
26 primitives::U256,
27};
28
29pub fn pop<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
33 gas_legacy!(context.interpreter, revm_gas::BASE);
34 popn!([_i], context.interpreter);
36}
37
38pub fn push0<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
42 check!(context.interpreter, SHANGHAI);
43 gas_legacy!(context.interpreter, revm_gas::BASE);
44 push!(context.interpreter, U256::ZERO);
45}
46
47pub fn push<'ext, const N: usize, E: Ext>(context: Context<'_, 'ext, E>) {
51 gas_legacy!(context.interpreter, revm_gas::VERYLOW);
52 push!(context.interpreter, U256::ZERO);
53 popn_top!([], top, context.interpreter);
54
55 let imm = context.interpreter.bytecode.read_slice(N);
56 cast_slice_to_u256(imm, top);
57
58 context.interpreter.bytecode.relative_jump(N as isize);
60}
61
62pub fn dup<'ext, const N: usize, E: Ext>(context: Context<'_, 'ext, E>) {
66 gas_legacy!(context.interpreter, revm_gas::VERYLOW);
67 if !context.interpreter.stack.dup(N) {
68 context.interpreter.halt(InstructionResult::StackOverflow);
69 }
70}
71
72pub fn swap<'ext, const N: usize, E: Ext>(context: Context<'_, 'ext, E>) {
76 gas_legacy!(context.interpreter, revm_gas::VERYLOW);
77 assert!(N != 0);
78 if !context.interpreter.stack.exchange(0, N) {
79 context.interpreter.halt(InstructionResult::StackOverflow);
80 }
81}