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, 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 gas_legacy!(context.interpreter, revm_gas::BASE);
43 push!(context.interpreter, U256::ZERO);
44}
45
46pub fn push<'ext, const N: usize, E: Ext>(context: Context<'_, 'ext, E>) {
50 gas_legacy!(context.interpreter, revm_gas::VERYLOW);
51 push!(context.interpreter, U256::ZERO);
52 popn_top!([], top, context.interpreter);
53
54 let imm = context.interpreter.bytecode.read_slice(N);
55 cast_slice_to_u256(imm, top);
56
57 context.interpreter.bytecode.relative_jump(N as isize);
59}
60
61pub fn dup<'ext, const N: usize, E: Ext>(context: Context<'_, 'ext, E>) {
65 gas_legacy!(context.interpreter, revm_gas::VERYLOW);
66 if !context.interpreter.stack.dup(N) {
67 context.interpreter.halt(InstructionResult::StackOverflow);
68 }
69}
70
71pub fn swap<'ext, const N: usize, E: Ext>(context: Context<'_, 'ext, E>) {
75 gas_legacy!(context.interpreter, revm_gas::VERYLOW);
76 assert!(N != 0);
77 if !context.interpreter.stack.exchange(0, N) {
78 context.interpreter.halt(InstructionResult::StackOverflow);
79 }
80}