Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(interpreter): rename some macros #1304

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions crates/interpreter/src/instructions/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn resize_memory(

/// EOF Create instruction
pub fn eofcreate<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, EOF_CREATE_GAS);
let initcontainer_index = unsafe { *interpreter.instruction_pointer };
pop!(interpreter, value, salt, data_offset, data_size);
Expand Down Expand Up @@ -92,7 +92,7 @@ pub fn eofcreate<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H)
}

pub fn txcreate<H: Host + ?Sized>(interpreter: &mut Interpreter, host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, EOF_CREATE_GAS);
pop!(
interpreter,
Expand Down Expand Up @@ -171,7 +171,7 @@ pub fn txcreate<H: Host + ?Sized>(interpreter: &mut Interpreter, host: &mut H) {
}

pub fn return_contract<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_not_init_eof!(interpreter);
require_init_eof!(interpreter);
let deploy_container_index = unsafe { read_u16(interpreter.instruction_pointer) };
pop!(interpreter, aux_data_offset, aux_data_size);
let aux_data_size = as_usize_or_fail!(interpreter, aux_data_size);
Expand Down Expand Up @@ -280,7 +280,7 @@ pub fn extcall_gas_calc<H: Host + ?Sized>(
}

pub fn extcall<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
pop_address!(interpreter, target_address);

// input call
Expand Down Expand Up @@ -315,7 +315,7 @@ pub fn extcall<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host
}

pub fn extdcall<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
pop_address!(interpreter, target_address);

// input call
Expand Down Expand Up @@ -348,7 +348,7 @@ pub fn extdcall<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, hos
}

pub fn extscall<H: Host + ?Sized>(interpreter: &mut Interpreter, host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
pop_address!(interpreter, target_address);

// input call
Expand Down Expand Up @@ -382,7 +382,7 @@ pub fn create<const IS_CREATE2: bool, H: Host + ?Sized, SPEC: Spec>(
interpreter: &mut Interpreter,
host: &mut H,
) {
error_on_static_call!(interpreter);
require_non_staticcall!(interpreter);

// EIP-1014: Skinny CREATE2
if IS_CREATE2 {
Expand Down
12 changes: 6 additions & 6 deletions crates/interpreter/src/instructions/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};

pub fn rjump<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, gas::BASE);
let offset = unsafe { read_i16(interpreter.instruction_pointer) } as isize;
// In spec it is +3 but pointer is already incremented in
Expand All @@ -15,7 +15,7 @@ pub fn rjump<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
}

pub fn rjumpi<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, gas::CONDITION_JUMP_GAS);
pop!(interpreter, condition);
// In spec it is +3 but pointer is already incremented in
Expand All @@ -29,7 +29,7 @@ pub fn rjumpi<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
}

pub fn rjumpv<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, gas::CONDITION_JUMP_GAS);
pop!(interpreter, case);
let case = as_isize_saturated!(case);
Expand Down Expand Up @@ -83,7 +83,7 @@ pub fn jumpdest_or_nop<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &
}

pub fn callf<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, gas::LOW);

let idx = unsafe { read_u16(interpreter.instruction_pointer) } as usize;
Expand All @@ -104,7 +104,7 @@ pub fn callf<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
}

pub fn retf<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, gas::RETF_GAS);

let Some(fframe) = interpreter.function_stack.pop() else {
Expand All @@ -115,7 +115,7 @@ pub fn retf<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
}

pub fn jumpf<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, gas::LOW);

let idx = unsafe { read_u16(interpreter.instruction_pointer) } as usize;
Expand Down
8 changes: 4 additions & 4 deletions crates/interpreter/src/instructions/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
};

pub fn data_load<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, DATA_LOAD_GAS);
pop_top!(interpreter, offset);

Expand All @@ -27,7 +27,7 @@ pub fn data_load<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H)
}

pub fn data_loadn<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, VERYLOW);
let offset = unsafe { read_u16(interpreter.instruction_pointer) } as usize;

Expand All @@ -48,15 +48,15 @@ pub fn data_loadn<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H
}

pub fn data_size<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, BASE);
let data_size = interpreter.eof().expect("eof").header.data_size;

push!(interpreter, U256::from(data_size));
}

pub fn data_copy<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, VERYLOW);
pop!(interpreter, mem_offset, offset, size);

Expand Down
8 changes: 4 additions & 4 deletions crates/interpreter/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn sload<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host:
}

pub fn sstore<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
error_on_static_call!(interpreter);
require_non_staticcall!(interpreter);

pop!(interpreter, index, value);
let Some(SStoreResult {
Expand All @@ -160,7 +160,7 @@ pub fn sstore<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host:
/// Store value to transient storage
pub fn tstore<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
check!(interpreter, CANCUN);
error_on_static_call!(interpreter);
require_non_staticcall!(interpreter);
gas!(interpreter, gas::WARM_STORAGE_READ_COST);

pop!(interpreter, index, value);
Expand All @@ -180,7 +180,7 @@ pub fn tload<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host:
}

pub fn log<const N: usize, H: Host + ?Sized>(interpreter: &mut Interpreter, host: &mut H) {
error_on_static_call!(interpreter);
require_non_staticcall!(interpreter);

pop!(interpreter, offset, len);
let len = as_usize_or_fail!(interpreter, len);
Expand Down Expand Up @@ -213,7 +213,7 @@ pub fn log<const N: usize, H: Host + ?Sized>(interpreter: &mut Interpreter, host
}

pub fn selfdestruct<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
error_on_static_call!(interpreter);
require_non_staticcall!(interpreter);
pop_address!(interpreter, target);

let Some(res) = host.selfdestruct(interpreter.contract.target_address, target) else {
Expand Down
6 changes: 3 additions & 3 deletions crates/interpreter/src/instructions/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/// Fails the instruction if the current call is static.
#[macro_export]
macro_rules! error_on_static_call {
macro_rules! require_non_staticcall {
($interp:expr) => {
if $interp.is_static {
$interp.instruction_result = $crate::InstructionResult::StateChangeDuringStaticCall;
Expand All @@ -13,7 +13,7 @@ macro_rules! error_on_static_call {

/// Error if the current call is executing EOF.
#[macro_export]
macro_rules! error_on_disabled_eof {
macro_rules! require_eof {
($interp:expr) => {
if !$interp.is_eof {
$interp.instruction_result = $crate::InstructionResult::EOFOpcodeDisabledInLegacy;
Expand All @@ -24,7 +24,7 @@ macro_rules! error_on_disabled_eof {

/// Error if not init eof call.
#[macro_export]
macro_rules! error_on_not_init_eof {
macro_rules! require_init_eof {
($interp:expr) => {
if !$interp.is_eof_init {
$interp.instruction_result = $crate::InstructionResult::ReturnContractInNotInitEOF;
Expand Down
6 changes: 3 additions & 3 deletions crates/interpreter/src/instructions/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn swap<const N: usize, H: Host + ?Sized>(interpreter: &mut Interpreter, _ho
}

pub fn dupn<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, gas::VERYLOW);
let imm = unsafe { *interpreter.instruction_pointer };
if let Err(result) = interpreter.stack.dup(imm as usize + 1) {
Expand All @@ -62,7 +62,7 @@ pub fn dupn<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
}

pub fn swapn<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, gas::VERYLOW);
let imm = unsafe { *interpreter.instruction_pointer };
if let Err(result) = interpreter.stack.swap(imm as usize + 1) {
Expand All @@ -72,7 +72,7 @@ pub fn swapn<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
}

pub fn exchange<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, gas::VERYLOW);
let imm = unsafe { *interpreter.instruction_pointer };
let n = (imm >> 4) + 1;
Expand Down
2 changes: 1 addition & 1 deletion crates/interpreter/src/instructions/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub fn returndatacopy<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interprete

/// Part of EOF `<https://eips.ethereum.org/EIPS/eip-7069>`.
pub fn returndataload<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
error_on_disabled_eof!(interpreter);
require_eof!(interpreter);
gas!(interpreter, gas::VERYLOW);
pop_top!(interpreter, offset);
let offset_usize = as_usize_or_fail!(interpreter, offset);
Expand Down
Loading