From 6e4b76a280709094d901c0025a81f9ff672f81e5 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Fri, 15 Mar 2024 23:25:57 +0100 Subject: [PATCH 1/3] feat(interpreter): export utility macros --- crates/interpreter/src/instructions/macros.rs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/crates/interpreter/src/instructions/macros.rs b/crates/interpreter/src/instructions/macros.rs index ec6e6cb775..442bc34eb3 100644 --- a/crates/interpreter/src/instructions/macros.rs +++ b/crates/interpreter/src/instructions/macros.rs @@ -1,3 +1,7 @@ +//! Utility macros to help implementementing opcode instruction functions. + +/// Fails the instruction if the current call is static. +#[macro_export] macro_rules! check_staticcall { ($interp:expr) => { if $interp.is_static { @@ -7,6 +11,8 @@ macro_rules! check_staticcall { }; } +/// Fails the instruction if the `min` is not enabled in `SPEC`. +#[macro_export] macro_rules! check { ($interp:expr, $min:ident) => { // TODO: Force const-eval on the condition with a `const {}` block once they are stable @@ -17,6 +23,8 @@ macro_rules! check { }; } +/// Records a `gas` cost and fails the instruction if it would exceed the available gas. +#[macro_export] macro_rules! gas { ($interp:expr, $gas:expr) => { gas!($interp, $gas, ()) @@ -29,12 +37,16 @@ macro_rules! gas { }; } +/// Records a `gas` refund. +#[macro_export] macro_rules! refund { ($interp:expr, $gas:expr) => { $interp.gas.record_refund($gas) }; } +/// Same as [`gas!`], but with `gas` as an option. +#[macro_export] macro_rules! gas_or_fail { ($interp:expr, $gas:expr) => { match $gas { @@ -47,6 +59,9 @@ macro_rules! gas_or_fail { }; } +/// Resizes the interpreter memory if necessary. Fails the instruction if the memory or gas limit +/// is exceeded. +#[macro_export] macro_rules! shared_memory_resize { ($interp:expr, $offset:expr, $len:expr) => { shared_memory_resize!($interp, $offset, $len, ()) @@ -74,6 +89,8 @@ macro_rules! shared_memory_resize { }; } +/// Pops `Address` values from the stack. Fails the instruction if the stack is too small. +#[macro_export] macro_rules! pop_address { ($interp:expr, $x1:ident) => { if $interp.stack.len() < 1 { @@ -94,6 +111,8 @@ macro_rules! pop_address { }; } +/// Pops `U256` values from the stack. Fails the instruction if the stack is too small. +#[macro_export] macro_rules! pop { ($interp:expr, $x1:ident) => { pop_ret!($interp, $x1, ()) @@ -109,6 +128,9 @@ macro_rules! pop { }; } +/// Pops `U256` values from the stack, and returns `ret`. +/// Fails the instruction if the stack is too small. +#[macro_export] macro_rules! pop_ret { ($interp:expr, $x1:ident, $ret:expr) => { if $interp.stack.len() < 1 { @@ -144,6 +166,9 @@ macro_rules! pop_ret { }; } +/// Pops `U256` values from the stack, and returns a reference to the top of the stack. +/// Fails the instruction if the stack is too small. +#[macro_export] macro_rules! pop_top { ($interp:expr, $x1:ident) => { if $interp.stack.len() < 1 { @@ -171,6 +196,7 @@ macro_rules! pop_top { }; } +/// Pushes `B256` values onto the stack. Fails the instruction if the stack is full. #[macro_export] macro_rules! push_b256 { ($interp:expr, $($x:expr),* $(,)?) => ($( @@ -184,6 +210,7 @@ macro_rules! push_b256 { )*) } +/// Pushes a `B256` value onto the stack. Fails the instruction if the stack is full. #[macro_export] macro_rules! push { ($interp:expr, $($x:expr),* $(,)?) => ($( @@ -197,6 +224,8 @@ macro_rules! push { )*) } +/// Converts a `U256` value to a `u64`, saturating to `MAX` if the value is too large. +#[macro_export] macro_rules! as_u64_saturated { ($v:expr) => {{ let x: &[u64; 4] = $v.as_limbs(); @@ -208,12 +237,16 @@ macro_rules! as_u64_saturated { }}; } +/// Converts a `U256` value to a `usize`, saturating to `MAX` if the value is too large. +#[macro_export] macro_rules! as_usize_saturated { ($v:expr) => { usize::try_from(as_u64_saturated!($v)).unwrap_or(usize::MAX) }; } +/// Converts a `U256` value to a `usize`, failing the instruction if the value is too large. +#[macro_export] macro_rules! as_usize_or_fail { ($interp:expr, $v:expr) => { as_usize_or_fail_ret!($interp, $v, ()) @@ -223,6 +256,9 @@ macro_rules! as_usize_or_fail { }; } +/// Converts a `U256` value to a `usize` and returns `ret`, +/// failing the instruction if the value is too large. +#[macro_export] macro_rules! as_usize_or_fail_ret { ($interp:expr, $v:expr, $ret:expr) => { as_usize_or_fail_ret!($interp, $v, InstructionResult::InvalidOperandOOG, $ret) From f303101aebe47226ab34aa937f20659adc74b8eb Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Fri, 15 Mar 2024 23:27:21 +0100 Subject: [PATCH 2/3] chore: rename memory resize macro --- crates/interpreter/src/gas.rs | 4 +++- crates/interpreter/src/instructions/control.rs | 2 +- crates/interpreter/src/instructions/host.rs | 6 +++--- crates/interpreter/src/instructions/host/call_helpers.rs | 4 ++-- crates/interpreter/src/instructions/macros.rs | 4 ++-- crates/interpreter/src/instructions/memory.rs | 8 ++++---- crates/interpreter/src/instructions/system.rs | 8 ++++---- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/crates/interpreter/src/gas.rs b/crates/interpreter/src/gas.rs index e700c5501b..9a37bf67ee 100644 --- a/crates/interpreter/src/gas.rs +++ b/crates/interpreter/src/gas.rs @@ -111,7 +111,9 @@ impl Gas { true } - /// used in shared_memory_resize! macro to record gas used for memory expansion. + /// Records memory expansion gas. + /// + /// Used in [`resize_memory!`](crate::resize_memory). #[inline] pub fn record_memory(&mut self, gas_memory: u64) -> bool { if gas_memory > self.memory { diff --git a/crates/interpreter/src/instructions/control.rs b/crates/interpreter/src/instructions/control.rs index ac843da98c..61a132e940 100644 --- a/crates/interpreter/src/instructions/control.rs +++ b/crates/interpreter/src/instructions/control.rs @@ -49,7 +49,7 @@ fn return_inner(interpreter: &mut Interpreter, instruction_result: InstructionRe let mut output = Bytes::default(); if len != 0 { let offset = as_usize_or_fail!(interpreter, offset); - shared_memory_resize!(interpreter, offset, len); + resize_memory!(interpreter, offset, len); output = interpreter.shared_memory.slice(offset, len).to_vec().into() } diff --git a/crates/interpreter/src/instructions/host.rs b/crates/interpreter/src/instructions/host.rs index a80c3b54e2..64a579a8f9 100644 --- a/crates/interpreter/src/instructions/host.rs +++ b/crates/interpreter/src/instructions/host.rs @@ -112,7 +112,7 @@ pub fn extcodecopy(interpreter: &mut Interpreter, host: &mu } let memory_offset = as_usize_or_fail!(interpreter, memory_offset); let code_offset = min(as_usize_saturated!(code_offset), code.len()); - shared_memory_resize!(interpreter, memory_offset, len); + resize_memory!(interpreter, memory_offset, len); // Note: this can't panic because we resized memory to fit. interpreter @@ -204,7 +204,7 @@ pub fn log(interpreter: &mut Interpreter, host: &mut H) Bytes::new() } else { let offset = as_usize_or_fail!(interpreter, offset); - shared_memory_resize!(interpreter, offset, len); + resize_memory!(interpreter, offset, len); Bytes::copy_from_slice(interpreter.shared_memory.slice(offset, len)) }; @@ -278,7 +278,7 @@ pub fn create( } let code_offset = as_usize_or_fail!(interpreter, code_offset); - shared_memory_resize!(interpreter, code_offset, len); + resize_memory!(interpreter, code_offset, len); code = Bytes::copy_from_slice(interpreter.shared_memory.slice(code_offset, len)); } diff --git a/crates/interpreter/src/instructions/host/call_helpers.rs b/crates/interpreter/src/instructions/host/call_helpers.rs index fc9509c25d..3156c9a75b 100644 --- a/crates/interpreter/src/instructions/host/call_helpers.rs +++ b/crates/interpreter/src/instructions/host/call_helpers.rs @@ -15,7 +15,7 @@ pub fn get_memory_input_and_out_ranges( let in_len = as_usize_or_fail_ret!(interpreter, in_len, None); let input = if in_len != 0 { let in_offset = as_usize_or_fail_ret!(interpreter, in_offset, None); - shared_memory_resize!(interpreter, in_offset, in_len, None); + resize_memory!(interpreter, in_offset, in_len, None); Bytes::copy_from_slice(interpreter.shared_memory.slice(in_offset, in_len)) } else { Bytes::new() @@ -24,7 +24,7 @@ pub fn get_memory_input_and_out_ranges( let out_len = as_usize_or_fail_ret!(interpreter, out_len, None); let out_offset = if out_len != 0 { let out_offset = as_usize_or_fail_ret!(interpreter, out_offset, None); - shared_memory_resize!(interpreter, out_offset, out_len, None); + resize_memory!(interpreter, out_offset, out_len, None); out_offset } else { usize::MAX //unrealistic value so we are sure it is not used diff --git a/crates/interpreter/src/instructions/macros.rs b/crates/interpreter/src/instructions/macros.rs index 442bc34eb3..a015075044 100644 --- a/crates/interpreter/src/instructions/macros.rs +++ b/crates/interpreter/src/instructions/macros.rs @@ -62,9 +62,9 @@ macro_rules! gas_or_fail { /// Resizes the interpreter memory if necessary. Fails the instruction if the memory or gas limit /// is exceeded. #[macro_export] -macro_rules! shared_memory_resize { +macro_rules! resize_memory { ($interp:expr, $offset:expr, $len:expr) => { - shared_memory_resize!($interp, $offset, $len, ()) + resize_memory!($interp, $offset, $len, ()) }; ($interp:expr, $offset:expr, $len:expr, $ret:expr) => { let size = $offset.saturating_add($len); diff --git a/crates/interpreter/src/instructions/memory.rs b/crates/interpreter/src/instructions/memory.rs index 6a63eb6b03..1166f22c27 100644 --- a/crates/interpreter/src/instructions/memory.rs +++ b/crates/interpreter/src/instructions/memory.rs @@ -9,7 +9,7 @@ pub fn mload(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop!(interpreter, index); let index = as_usize_or_fail!(interpreter, index); - shared_memory_resize!(interpreter, index, 32); + resize_memory!(interpreter, index, 32); push!(interpreter, interpreter.shared_memory.get_u256(index)); } @@ -17,7 +17,7 @@ pub fn mstore(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop!(interpreter, index, value); let index = as_usize_or_fail!(interpreter, index); - shared_memory_resize!(interpreter, index, 32); + resize_memory!(interpreter, index, 32); interpreter.shared_memory.set_u256(index, value); } @@ -25,7 +25,7 @@ pub fn mstore8(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop!(interpreter, index, value); let index = as_usize_or_fail!(interpreter, index); - shared_memory_resize!(interpreter, index, 1); + resize_memory!(interpreter, index, 1); interpreter.shared_memory.set_byte(index, value.byte(0)) } @@ -50,7 +50,7 @@ pub fn mcopy(interpreter: &mut Interpreter, _host: &mut H) let dst = as_usize_or_fail!(interpreter, dst); let src = as_usize_or_fail!(interpreter, src); // resize memory - shared_memory_resize!(interpreter, max(dst, src), len); + resize_memory!(interpreter, max(dst, src), len); // copy memory in place interpreter.shared_memory.copy(dst, src, len); } diff --git a/crates/interpreter/src/instructions/system.rs b/crates/interpreter/src/instructions/system.rs index 07df7a6604..55109d8004 100644 --- a/crates/interpreter/src/instructions/system.rs +++ b/crates/interpreter/src/instructions/system.rs @@ -12,7 +12,7 @@ pub fn keccak256(interpreter: &mut Interpreter, _host: &mut H) { KECCAK_EMPTY } else { let from = as_usize_or_fail!(interpreter, from); - shared_memory_resize!(interpreter, from, len); + resize_memory!(interpreter, from, len); crate::primitives::keccak256(interpreter.shared_memory.slice(from, len)) }; @@ -43,7 +43,7 @@ pub fn codecopy(interpreter: &mut Interpreter, _host: &mut H) { } let memory_offset = as_usize_or_fail!(interpreter, memory_offset); let code_offset = as_usize_saturated!(code_offset); - shared_memory_resize!(interpreter, memory_offset, len); + resize_memory!(interpreter, memory_offset, len); // Note: this can't panic because we resized memory to fit. interpreter.shared_memory.set_data( @@ -89,7 +89,7 @@ pub fn calldatacopy(interpreter: &mut Interpreter, _host: &mut H) { } let memory_offset = as_usize_or_fail!(interpreter, memory_offset); let data_offset = as_usize_saturated!(data_offset); - shared_memory_resize!(interpreter, memory_offset, len); + resize_memory!(interpreter, memory_offset, len); // Note: this can't panic because we resized memory to fit. interpreter.shared_memory.set_data( @@ -124,7 +124,7 @@ pub fn returndatacopy(interpreter: &mut Interpreter, _host: } if len != 0 { let memory_offset = as_usize_or_fail!(interpreter, memory_offset); - shared_memory_resize!(interpreter, memory_offset, len); + resize_memory!(interpreter, memory_offset, len); interpreter.shared_memory.set( memory_offset, &interpreter.return_data_buffer[data_offset..data_end], From 1c6abb0ac9dd60c627bbb7d9c30f82458b74f796 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sat, 16 Mar 2024 18:37:10 +0100 Subject: [PATCH 3/3] chore: dollar crate --- .../src/instructions/arithmetic.rs | 2 +- .../interpreter/src/instructions/bitwise.rs | 2 +- crates/interpreter/src/instructions/host.rs | 2 +- .../interpreter/src/instructions/host_env.rs | 2 +- crates/interpreter/src/instructions/macros.rs | 76 +++++++++++-------- crates/interpreter/src/instructions/memory.rs | 2 +- crates/interpreter/src/instructions/stack.rs | 2 +- 7 files changed, 51 insertions(+), 37 deletions(-) diff --git a/crates/interpreter/src/instructions/arithmetic.rs b/crates/interpreter/src/instructions/arithmetic.rs index 724f5ff9c3..209baae55c 100644 --- a/crates/interpreter/src/instructions/arithmetic.rs +++ b/crates/interpreter/src/instructions/arithmetic.rs @@ -2,7 +2,7 @@ use super::i256::{i256_div, i256_mod}; use crate::{ gas, primitives::{Spec, U256}, - Host, InstructionResult, Interpreter, + Host, Interpreter, }; pub fn wrapping_add(interpreter: &mut Interpreter, _host: &mut H) { diff --git a/crates/interpreter/src/instructions/bitwise.rs b/crates/interpreter/src/instructions/bitwise.rs index 95ed56e2d1..3f49dc57eb 100644 --- a/crates/interpreter/src/instructions/bitwise.rs +++ b/crates/interpreter/src/instructions/bitwise.rs @@ -2,7 +2,7 @@ use super::i256::{i256_cmp, i256_sign_compl, two_compl, Sign}; use crate::{ gas, primitives::{Spec, U256}, - Host, InstructionResult, Interpreter, + Host, Interpreter, }; use core::cmp::Ordering; diff --git a/crates/interpreter/src/instructions/host.rs b/crates/interpreter/src/instructions/host.rs index 64a579a8f9..7357adf4f3 100644 --- a/crates/interpreter/src/instructions/host.rs +++ b/crates/interpreter/src/instructions/host.rs @@ -5,7 +5,7 @@ pub use call_helpers::{calc_call_gas, get_memory_input_and_out_ranges}; use crate::{ gas::{self, COLD_ACCOUNT_ACCESS_COST, WARM_STORAGE_READ_COST}, interpreter::{Interpreter, InterpreterAction}, - primitives::{Address, Bytes, Log, LogData, Spec, SpecId::*, B256, U256}, + primitives::{Bytes, Log, LogData, Spec, SpecId::*, B256, U256}, CallContext, CallInputs, CallScheme, CreateInputs, CreateScheme, Host, InstructionResult, SStoreResult, Transfer, MAX_INITCODE_SIZE, }; diff --git a/crates/interpreter/src/instructions/host_env.rs b/crates/interpreter/src/instructions/host_env.rs index cce993bac6..230bb39b37 100644 --- a/crates/interpreter/src/instructions/host_env.rs +++ b/crates/interpreter/src/instructions/host_env.rs @@ -1,7 +1,7 @@ use crate::{ gas, primitives::{Spec, SpecId::*, U256}, - Host, InstructionResult, Interpreter, + Host, Interpreter, }; /// EIP-1344: ChainID opcode diff --git a/crates/interpreter/src/instructions/macros.rs b/crates/interpreter/src/instructions/macros.rs index a015075044..861489d38f 100644 --- a/crates/interpreter/src/instructions/macros.rs +++ b/crates/interpreter/src/instructions/macros.rs @@ -5,7 +5,7 @@ macro_rules! check_staticcall { ($interp:expr) => { if $interp.is_static { - $interp.instruction_result = InstructionResult::StateChangeDuringStaticCall; + $interp.instruction_result = $crate::InstructionResult::StateChangeDuringStaticCall; return; } }; @@ -17,7 +17,7 @@ macro_rules! check { ($interp:expr, $min:ident) => { // TODO: Force const-eval on the condition with a `const {}` block once they are stable if !::enabled($crate::primitives::SpecId::$min) { - $interp.instruction_result = InstructionResult::NotActivated; + $interp.instruction_result = $crate::InstructionResult::NotActivated; return; } }; @@ -27,11 +27,11 @@ macro_rules! check { #[macro_export] macro_rules! gas { ($interp:expr, $gas:expr) => { - gas!($interp, $gas, ()) + $crate::gas!($interp, $gas, ()) }; ($interp:expr, $gas:expr, $ret:expr) => { if !$interp.gas.record_cost($gas) { - $interp.instruction_result = InstructionResult::OutOfGas; + $interp.instruction_result = $crate::InstructionResult::OutOfGas; return $ret; } }; @@ -50,9 +50,9 @@ macro_rules! refund { macro_rules! gas_or_fail { ($interp:expr, $gas:expr) => { match $gas { - Some(gas_used) => gas!($interp, gas_used), + Some(gas_used) => $crate::gas!($interp, gas_used), None => { - $interp.instruction_result = InstructionResult::OutOfGas; + $interp.instruction_result = $crate::InstructionResult::OutOfGas; return; } } @@ -64,24 +64,27 @@ macro_rules! gas_or_fail { #[macro_export] macro_rules! resize_memory { ($interp:expr, $offset:expr, $len:expr) => { - resize_memory!($interp, $offset, $len, ()) + $crate::resize_memory!($interp, $offset, $len, ()) }; ($interp:expr, $offset:expr, $len:expr, $ret:expr) => { let size = $offset.saturating_add($len); if size > $interp.shared_memory.len() { // We are fine with saturating to usize if size is close to MAX value. - let rounded_size = crate::interpreter::next_multiple_of_32(size); + let rounded_size = $crate::interpreter::next_multiple_of_32(size); #[cfg(feature = "memory_limit")] if $interp.shared_memory.limit_reached(size) { - $interp.instruction_result = InstructionResult::MemoryLimitOOG; + $interp.instruction_result = $crate::InstructionResult::MemoryLimitOOG; return $ret; } // Gas is calculated in evm words (256bits). let words_num = rounded_size / 32; - if !$interp.gas.record_memory(crate::gas::memory_gas(words_num)) { - $interp.instruction_result = InstructionResult::MemoryLimitOOG; + if !$interp + .gas + .record_memory($crate::gas::memory_gas(words_num)) + { + $interp.instruction_result = $crate::InstructionResult::MemoryLimitOOG; return $ret; } $interp.shared_memory.resize(rounded_size); @@ -94,20 +97,26 @@ macro_rules! resize_memory { macro_rules! pop_address { ($interp:expr, $x1:ident) => { if $interp.stack.len() < 1 { - $interp.instruction_result = InstructionResult::StackUnderflow; + $interp.instruction_result = $crate::InstructionResult::StackUnderflow; return; } // SAFETY: Length is checked above. - let $x1 = Address::from_word(B256::from(unsafe { $interp.stack.pop_unsafe() })); + let $x1 = $crate::primitives::Address::from_word($crate::primitives::B256::from(unsafe { + $interp.stack.pop_unsafe() + })); }; ($interp:expr, $x1:ident, $x2:ident) => { if $interp.stack.len() < 2 { - $interp.instruction_result = InstructionResult::StackUnderflow; + $interp.instruction_result = $crate::InstructionResult::StackUnderflow; return; } // SAFETY: Length is checked above. - let $x1 = Address::from_word(B256::from(unsafe { $interp.stack.pop_unsafe() })); - let $x2 = Address::from_word(B256::from(unsafe { $interp.stack.pop_unsafe() })); + let $x1 = $crate::primitives::Address::from_word($crate::primitives::B256::from(unsafe { + $interp.stack.pop_unsafe() + })); + let $x2 = $crate::primitives::Address::from_word($crate::primitives::B256::from(unsafe { + $interp.stack.pop_unsafe() + })); }; } @@ -115,16 +124,16 @@ macro_rules! pop_address { #[macro_export] macro_rules! pop { ($interp:expr, $x1:ident) => { - pop_ret!($interp, $x1, ()) + $crate::pop_ret!($interp, $x1, ()) }; ($interp:expr, $x1:ident, $x2:ident) => { - pop_ret!($interp, $x1, $x2, ()) + $crate::pop_ret!($interp, $x1, $x2, ()) }; ($interp:expr, $x1:ident, $x2:ident, $x3:ident) => { - pop_ret!($interp, $x1, $x2, $x3, ()) + $crate::pop_ret!($interp, $x1, $x2, $x3, ()) }; ($interp:expr, $x1:ident, $x2:ident, $x3:ident, $x4:ident) => { - pop_ret!($interp, $x1, $x2, $x3, $x4, ()) + $crate::pop_ret!($interp, $x1, $x2, $x3, $x4, ()) }; } @@ -134,7 +143,7 @@ macro_rules! pop { macro_rules! pop_ret { ($interp:expr, $x1:ident, $ret:expr) => { if $interp.stack.len() < 1 { - $interp.instruction_result = InstructionResult::StackUnderflow; + $interp.instruction_result = $crate::InstructionResult::StackUnderflow; return $ret; } // SAFETY: Length is checked above. @@ -142,7 +151,7 @@ macro_rules! pop_ret { }; ($interp:expr, $x1:ident, $x2:ident, $ret:expr) => { if $interp.stack.len() < 2 { - $interp.instruction_result = InstructionResult::StackUnderflow; + $interp.instruction_result = $crate::InstructionResult::StackUnderflow; return $ret; } // SAFETY: Length is checked above. @@ -150,7 +159,7 @@ macro_rules! pop_ret { }; ($interp:expr, $x1:ident, $x2:ident, $x3:ident, $ret:expr) => { if $interp.stack.len() < 3 { - $interp.instruction_result = InstructionResult::StackUnderflow; + $interp.instruction_result = $crate::InstructionResult::StackUnderflow; return $ret; } // SAFETY: Length is checked above. @@ -158,7 +167,7 @@ macro_rules! pop_ret { }; ($interp:expr, $x1:ident, $x2:ident, $x3:ident, $x4:ident, $ret:expr) => { if $interp.stack.len() < 4 { - $interp.instruction_result = InstructionResult::StackUnderflow; + $interp.instruction_result = $crate::InstructionResult::StackUnderflow; return $ret; } // SAFETY: Length is checked above. @@ -172,7 +181,7 @@ macro_rules! pop_ret { macro_rules! pop_top { ($interp:expr, $x1:ident) => { if $interp.stack.len() < 1 { - $interp.instruction_result = InstructionResult::StackUnderflow; + $interp.instruction_result = $crate::InstructionResult::StackUnderflow; return; } // SAFETY: Length is checked above. @@ -180,7 +189,7 @@ macro_rules! pop_top { }; ($interp:expr, $x1:ident, $x2:ident) => { if $interp.stack.len() < 2 { - $interp.instruction_result = InstructionResult::StackUnderflow; + $interp.instruction_result = $crate::InstructionResult::StackUnderflow; return; } // SAFETY: Length is checked above. @@ -188,7 +197,7 @@ macro_rules! pop_top { }; ($interp:expr, $x1:ident, $x2:ident, $x3:ident) => { if $interp.stack.len() < 3 { - $interp.instruction_result = InstructionResult::StackUnderflow; + $interp.instruction_result = $crate::InstructionResult::StackUnderflow; return; } // SAFETY: Length is checked above. @@ -241,7 +250,7 @@ macro_rules! as_u64_saturated { #[macro_export] macro_rules! as_usize_saturated { ($v:expr) => { - usize::try_from(as_u64_saturated!($v)).unwrap_or(usize::MAX) + usize::try_from($crate::as_u64_saturated!($v)).unwrap_or(usize::MAX) }; } @@ -249,10 +258,10 @@ macro_rules! as_usize_saturated { #[macro_export] macro_rules! as_usize_or_fail { ($interp:expr, $v:expr) => { - as_usize_or_fail_ret!($interp, $v, ()) + $crate::as_usize_or_fail_ret!($interp, $v, ()) }; ($interp:expr, $v:expr, $reason:expr) => { - as_usize_or_fail_ret!($interp, $v, $reason, ()) + $crate::as_usize_or_fail_ret!($interp, $v, $reason, ()) }; } @@ -261,7 +270,12 @@ macro_rules! as_usize_or_fail { #[macro_export] macro_rules! as_usize_or_fail_ret { ($interp:expr, $v:expr, $ret:expr) => { - as_usize_or_fail_ret!($interp, $v, InstructionResult::InvalidOperandOOG, $ret) + $crate::as_usize_or_fail_ret!( + $interp, + $v, + $crate::InstructionResult::InvalidOperandOOG, + $ret + ) }; ($interp:expr, $v:expr, $reason:expr, $ret:expr) => {{ diff --git a/crates/interpreter/src/instructions/memory.rs b/crates/interpreter/src/instructions/memory.rs index 1166f22c27..264c4c61c7 100644 --- a/crates/interpreter/src/instructions/memory.rs +++ b/crates/interpreter/src/instructions/memory.rs @@ -1,7 +1,7 @@ use crate::{ gas, primitives::{Spec, U256}, - Host, InstructionResult, Interpreter, + Host, Interpreter, }; use core::cmp::max; diff --git a/crates/interpreter/src/instructions/stack.rs b/crates/interpreter/src/instructions/stack.rs index 6913116330..14d9e35238 100644 --- a/crates/interpreter/src/instructions/stack.rs +++ b/crates/interpreter/src/instructions/stack.rs @@ -1,7 +1,7 @@ use crate::{ gas, primitives::{Spec, U256}, - Host, InstructionResult, Interpreter, + Host, Interpreter, }; pub fn pop(interpreter: &mut Interpreter, _host: &mut H) {