Skip to content
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
2 changes: 1 addition & 1 deletion crates/interpreter/src/opcode/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum InstructionTables<'a, H: ?Sized> {
Boxed(BoxedInstructionTable<'a, H>),
}

impl<'a, H: Host + ?Sized> InstructionTables<'a, H> {
impl<H: Host + ?Sized> InstructionTables<'_, H> {
/// Creates a plain instruction table for the given spec. See [`make_instruction_table`].
#[inline]
pub const fn new_plain<SPEC: Spec>() -> Self {
Expand Down
24 changes: 23 additions & 1 deletion crates/precompile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use once_cell::race::OnceBox;
use std::{boxed::Box, vec::Vec};

pub fn calc_linear_cost_u32(len: usize, base: u64, word: u64) -> u64 {
(len as u64 + 32 - 1) / 32 * word + base
(len as u64).div_ceil(32) * word + base
}

#[derive(Clone, Default, Debug)]
Expand All @@ -64,6 +64,8 @@ impl Precompiles {
PrecompileSpecId::PRE_BERNOULLI => Self::pre_bernoulli(),
#[cfg(feature = "morph")]
PrecompileSpecId::BERNOULLI => Self::bernoulli(),
#[cfg(feature = "morph")]
PrecompileSpecId::MORPH203 => Self::morph203(),
PrecompileSpecId::CANCUN => Self::cancun(),
PrecompileSpecId::PRAGUE => Self::prague(),
PrecompileSpecId::LATEST => Self::latest(),
Expand Down Expand Up @@ -217,6 +219,22 @@ impl Precompiles {
})
}

/// Returns precompiles for Morph
#[cfg(feature = "morph")]
pub fn morph203() -> &'static Self {
static INSTANCE: OnceBox<Precompiles> = OnceBox::new();
INSTANCE.get_or_init(|| {
let mut precompiles = Self::bernoulli().clone();
precompiles.extend([
hash::RIPEMD160, // 0x03
modexp::BERLIN, // 0x05
bn128::pair::ISTANBUL, // 0x08
blake2::FUN, // 0x09
]);
Box::new(precompiles)
})
}

/// Returns the precompiles for the latest spec.
pub fn latest() -> &'static Self {
Self::prague()
Expand Down Expand Up @@ -318,6 +336,8 @@ pub enum PrecompileSpecId {
PRE_BERNOULLI,
#[cfg(feature = "morph")]
BERNOULLI,
#[cfg(feature = "morph")]
MORPH203,
CANCUN,
PRAGUE,
LATEST,
Expand Down Expand Up @@ -345,6 +365,8 @@ impl PrecompileSpecId {
PRE_BERNOULLI => Self::PRE_BERNOULLI,
#[cfg(feature = "morph")]
BERNOULLI | CURIE => Self::BERNOULLI,
#[cfg(feature = "morph")]
MORPH203 => Self::MORPH203,
}
}
}
Expand Down
19 changes: 16 additions & 3 deletions crates/primitives/src/specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ pub enum SpecId {
/// Although the Curie update include new opcodes in Cancun, the most important change
/// `EIP-4844` is not included. So we sort it before Cancun.
CURIE = 19,
CANCUN = 20,
PRAGUE = 21,
PRAGUE_EOF = 22,
MORPH203 = 20, // revert Precompiles: RIPEMD-160, point evaluation, modexp, ecPairing
CANCUN = 21,
PRAGUE = 22,
PRAGUE_EOF = 23,
#[default]
LATEST = u8::MAX,
}
Expand Down Expand Up @@ -174,6 +175,8 @@ impl From<&str> for SpecId {
"Bernoulli" => SpecId::BERNOULLI,
#[cfg(feature = "morph")]
"Curie" => SpecId::CURIE,
#[cfg(feature = "morph")]
"Morph203" => SpecId::MORPH203,
_ => Self::LATEST,
}
}
Expand Down Expand Up @@ -220,6 +223,8 @@ impl From<SpecId> for &'static str {
SpecId::BERNOULLI => "Bernoulli",
#[cfg(feature = "morph")]
SpecId::CURIE => "Curie",
#[cfg(feature = "morph")]
SpecId::MORPH203 => "Morph203",
SpecId::LATEST => "Latest",
}
}
Expand Down Expand Up @@ -290,6 +295,8 @@ spec!(PRE_BERNOULLI, PreBernoulliSpec);
#[cfg(feature = "morph")]
spec!(BERNOULLI, BernoulliSpec);
#[cfg(feature = "morph")]
spec!(MORPH203, Morph203Spec);
#[cfg(feature = "morph")]
spec!(CURIE, CurieSpec);

#[cfg(not(any(feature = "optimism", feature = "morph")))]
Expand Down Expand Up @@ -534,6 +541,10 @@ macro_rules! spec_to_generic {
use $crate::BernoulliSpec as SPEC;
$e
}
$crate::SpecId::MORPH203 => {
use $crate::Morph203Spec as SPEC;
$e
}
$crate::SpecId::CURIE => {
use $crate::CurieSpec as SPEC;
$e
Expand Down Expand Up @@ -578,6 +589,8 @@ mod tests {
#[cfg(feature = "morph")]
spec_to_generic!(BERNOULLI, assert_eq!(SPEC::SPEC_ID, BERNOULLI));
#[cfg(feature = "morph")]
spec_to_generic!(MORPH203, assert_eq!(SPEC::SPEC_ID, MORPH203));
#[cfg(feature = "morph")]
spec_to_generic!(CURIE, assert_eq!(SPEC::SPEC_ID, CURIE));
spec_to_generic!(CANCUN, assert_eq!(SPEC::SPEC_ID, CANCUN));
#[cfg(feature = "optimism")]
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/context/context_precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<DB: Database> ContextPrecompiles<DB> {

/// Returns precompiles addresses.
#[inline]
pub fn addresses<'a>(&'a self) -> Box<dyn ExactSizeIterator<Item = &Address> + 'a> {
pub fn addresses<'a>(&'a self) -> Box<dyn ExactSizeIterator<Item = &'a Address> + 'a> {
match self.inner {
PrecompilesCow::StaticRef(inner) => Box::new(inner.addresses()),
PrecompilesCow::Owned(ref inner) => Box::new(inner.keys()),
Expand Down
3 changes: 0 additions & 3 deletions crates/revm/src/context/inner_evm_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ impl<DB: Database> InnerEvmContext<DB> {
.map(|acc| (acc.info.code_size, acc.is_cold))
}

/// Get code hash of address.
///

/// Get code hash of address.
///
/// In case of EOF account it will return `EOF_MAGIC_HASH`
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/handler/handle_types/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<'a, EXT: 'a, DB: Database + 'a> ExecutionHandler<'a, EXT, DB> {
}
}

impl<'a, EXT, DB: Database> ExecutionHandler<'a, EXT, DB> {
impl<EXT, DB: Database> ExecutionHandler<'_, EXT, DB> {
/// Executes single frame.
#[inline]
pub fn execute_frame(
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/handler/handle_types/post_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl<'a, EXT: 'a, DB: Database + 'a> PostExecutionHandler<'a, EXT, DB> {
}
}

impl<'a, EXT, DB: Database> PostExecutionHandler<'a, EXT, DB> {
impl<EXT, DB: Database> PostExecutionHandler<'_, EXT, DB> {
/// Calculate final refund
pub fn refund(&self, context: &mut Context<EXT, DB>, gas: &mut Gas, eip7702_refund: i64) {
(self.refund)(context, gas, eip7702_refund)
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/handler/handle_types/pre_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'a, EXT: 'a, DB: Database + 'a> PreExecutionHandler<'a, EXT, DB> {
}
}

impl<'a, EXT, DB: Database> PreExecutionHandler<'a, EXT, DB> {
impl<EXT, DB: Database> PreExecutionHandler<'_, EXT, DB> {
/// Deduct caller to its limit.
pub fn deduct_caller(&self, context: &mut Context<EXT, DB>) -> Result<(), EVMError<DB::Error>> {
(self.deduct_caller)(context)
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/handler/handle_types/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<'a, EXT: 'a, DB: Database + 'a> ValidationHandler<'a, EXT, DB> {
}
}

impl<'a, EXT, DB: Database> ValidationHandler<'a, EXT, DB> {
impl<EXT, DB: Database> ValidationHandler<'_, EXT, DB> {
/// Validate env.
pub fn env(&self, env: &Env) -> Result<(), EVMError<DB::Error>> {
(self.env)(env)
Expand Down
32 changes: 19 additions & 13 deletions crates/revm/src/handler/mainnet/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,34 @@ pub fn validate_initial_tx_gas<SPEC: Spec, DB: Database>(
.map(|l| l.len() as u64)
.unwrap_or_default();

let mut initial_gas_spend = gas::validate_initial_tx_gas(
#[cfg(not(feature = "morph"))]
let initial_gas_spend = gas::validate_initial_tx_gas(
SPEC::SPEC_ID,
input,
is_create,
access_list,
authorization_list_num,
);

#[cfg(feature = "morph")]
let initial_gas_spend = {
let gas = gas::validate_initial_tx_gas(
SPEC::SPEC_ID,
input,
is_create,
access_list,
authorization_list_num,
);
if gas > env.tx.gas_limit && env.tx.morph.is_l1_msg {
env.tx.gas_limit
} else {
gas
}
};

// Additional check to see if limit is big enough to cover initial gas.
if initial_gas_spend > env.tx.gas_limit {
cfg_if::cfg_if! {
if #[cfg(not(feature = "morph"))] {
return Err(InvalidTransaction::CallGasCostMoreThanGasLimit.into());
} else {
// reset initial gas spend for l1 message to ensure execution doesn't fail
if env.tx.morph.is_l1_msg {
initial_gas_spend = env.tx.gas_limit
} else {
return Err(InvalidTransaction::CallGasCostMoreThanGasLimit.into());
}
}
}
return Err(InvalidTransaction::CallGasCostMoreThanGasLimit.into());
}
Ok(initial_gas_spend)
}
Loading