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: expose functionality for custom EVMs #1201

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 13 additions & 6 deletions crates/interpreter/src/instructions/macros.rs
Expand Up @@ -17,6 +17,7 @@ macro_rules! check {
};
}

#[macro_export]
macro_rules! gas {
($interp:expr, $gas:expr) => {
gas!($interp, $gas, ())
Expand Down Expand Up @@ -47,6 +48,7 @@ macro_rules! gas_or_fail {
};
}

#[macro_export]
macro_rules! shared_memory_resize {
($interp:expr, $offset:expr, $len:expr) => {
shared_memory_resize!($interp, $offset, $len, ())
Expand All @@ -55,7 +57,7 @@ macro_rules! shared_memory_resize {
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) {
Expand All @@ -65,7 +67,10 @@ macro_rules! shared_memory_resize {

// Gas is calculated in evm words (256bits).
let words_num = rounded_size / 32;
if !$interp.gas.record_memory(crate::gas::memory_gas(words_num)) {
if !$interp
.gas
.record_memory($crate::gas::memory_gas(words_num))
{
$interp.instruction_result = InstructionResult::MemoryLimitOOG;
return $ret;
}
Expand Down Expand Up @@ -94,21 +99,23 @@ 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, ())
};
}

#[macro_export]
macro_rules! pop_ret {
($interp:expr, $x1:ident, $ret:expr) => {
if $interp.stack.len() < 1 {
Expand Down
2 changes: 1 addition & 1 deletion crates/interpreter/src/lib.rs
Expand Up @@ -19,7 +19,7 @@ mod host;
mod inner_models;
mod instruction_result;
pub mod instructions;
mod interpreter;
pub mod interpreter;

// Reexport primary types.
pub use call_outcome::CallOutcome;
Expand Down
4 changes: 2 additions & 2 deletions crates/precompile/src/lib.rs
Expand Up @@ -17,7 +17,7 @@ mod identity;
#[cfg(feature = "c-kzg")]
pub mod kzg_point_evaluation;
mod modexp;
mod secp256k1;
pub mod secp256k1;
pub mod utilities;

use core::hash::Hash;
Expand Down Expand Up @@ -260,7 +260,7 @@ impl PrecompileSpecId {
/// Note that 32 + 128 = 160 = 20 bytes (the length of an address). This function is used
/// as a convenience for specifying the addresses of the various precompiles.
#[inline]
const fn u64_to_address(x: u64) -> Address {
pub const fn u64_to_address(x: u64) -> Address {
let x = x.to_be_bytes();
Address::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7],
Expand Down
2 changes: 2 additions & 0 deletions crates/precompile/src/secp256k1.rs
Expand Up @@ -6,6 +6,8 @@ pub const ECRECOVER: PrecompileWithAddress = PrecompileWithAddress(
Precompile::Standard(ec_recover_run),
);

pub use self::secp256k1::ecrecover;

#[cfg(not(feature = "secp256k1"))]
#[allow(clippy::module_inception)]
mod secp256k1 {
Expand Down