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
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,16 @@ alloy-op-hardforks = { version = "0.2" }
op-alloy-consensus = { version = "0.18", default-features = false }

# revm
revm = { version = "24.0.0", default-features = false }
op-revm = { version = "5.0.0", default-features = false }
revm = { version = "26.0.0", default-features = false }
op-revm = { version = "7.0.0", default-features = false }

# misc
auto_impl = "1"
derive_more = { version = "2", default-features = false, features = ["full"] }
serde = { version = "1", default-features = false, features = ["derive"] }
thiserror = { version = "2.0.0", default-features = false }
serde_json = "1"

#[patch.crates-io]
#revm = { git = "https://github.com/bluealloy/revm", rev = "11b16259" }
#op-revm = { git = "https://github.com/bluealloy/revm", rev = "11b16259" }
14 changes: 10 additions & 4 deletions crates/evm/src/block/state_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ where
let mut balance_increments = HashMap::default();

// Add block rewards if they are enabled.
if let Some(base_block_reward) = calc::base_block_reward(&spec, block_env.number) {
if let Some(base_block_reward) =
calc::base_block_reward(&spec, block_env.number.saturating_to())
{
// Ommer rewards
for ommer in ommers {
*balance_increments.entry(ommer.beneficiary()).or_default() +=
calc::ommer_reward(base_block_reward, block_env.number, ommer.number());
*balance_increments.entry(ommer.beneficiary()).or_default() += calc::ommer_reward(
base_block_reward,
block_env.number.saturating_to(),
ommer.number(),
);
}

// Full block reward
Expand All @@ -44,7 +49,7 @@ where
// process withdrawals
insert_post_block_withdrawals_balance_increments(
spec,
block_env.timestamp,
block_env.timestamp.saturating_to(),
withdrawals.map(|w| w.as_slice()),
&mut balance_increments,
);
Expand Down Expand Up @@ -122,6 +127,7 @@ where
info: account.info.clone(),
storage: Default::default(),
status: AccountStatus::Touched,
transaction_id: 0,
},
))
};
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/src/block/system_calls/eip2935.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ pub(crate) fn transact_blockhashes_contract_call<Halt>(
parent_block_hash: B256,
evm: &mut impl Evm<HaltReason = Halt>,
) -> Result<Option<ResultAndState<Halt>>, BlockExecutionError> {
if !spec.is_prague_active_at_timestamp(evm.block().timestamp) {
if !spec.is_prague_active_at_timestamp(evm.block().timestamp.saturating_to()) {
return Ok(None);
}

// if the block number is zero (genesis block) then no system transaction may occur as per
// EIP-2935
if evm.block().number == 0 {
if evm.block().number.is_zero() {
return Ok(None);
}

Expand Down
4 changes: 2 additions & 2 deletions crates/evm/src/block/system_calls/eip4788.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(crate) fn transact_beacon_root_contract_call<Halt>(
parent_beacon_block_root: Option<B256>,
evm: &mut impl Evm<HaltReason = Halt>,
) -> Result<Option<ResultAndState<Halt>>, BlockExecutionError> {
if !spec.is_cancun_active_at_timestamp(evm.block().timestamp) {
if !spec.is_cancun_active_at_timestamp(evm.block().timestamp.saturating_to()) {
return Ok(None);
}

Expand All @@ -34,7 +34,7 @@ pub(crate) fn transact_beacon_root_contract_call<Halt>(

// if the block number is zero (genesis block) then the parent beacon block root must
// be 0x0 and no system transaction may occur as per EIP-4788
if evm.block().number == 0 {
if evm.block().number.is_zero() {
if !parent_beacon_block_root.is_zero() {
return Err(BlockValidationError::CancunGenesisParentBeaconBlockRootNotZero {
parent_beacon_block_root,
Expand Down
9 changes: 6 additions & 3 deletions crates/evm/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ where
fn apply_pre_execution_changes(&mut self) -> Result<(), BlockExecutionError> {
// Set state clear flag if the block is after the Spurious Dragon hardfork.
let state_clear_flag =
self.spec.is_spurious_dragon_active_at_block(self.evm.block().number);
self.spec.is_spurious_dragon_active_at_block(self.evm.block().number.saturating_to());
self.evm.db_mut().set_state_clear_flag(state_clear_flag);

self.system_caller.apply_blockhashes_contract_call(self.ctx.parent_hash, &mut self.evm)?;
Expand Down Expand Up @@ -157,7 +157,10 @@ where
fn finish(
mut self,
) -> Result<(Self::Evm, BlockExecutionResult<R::Receipt>), BlockExecutionError> {
let requests = if self.spec.is_prague_active_at_timestamp(self.evm.block().timestamp) {
let requests = if self
.spec
.is_prague_active_at_timestamp(self.evm.block().timestamp.saturating_to())
{
// Collect all EIP-6110 deposits
let deposit_requests =
eip6110::parse_deposits_from_receipts(&self.spec, &self.receipts)?;
Expand Down Expand Up @@ -185,7 +188,7 @@ where
if self
.spec
.ethereum_fork_activation(EthereumHardfork::Dao)
.transitions_at_block(self.evm.block().number)
.transitions_at_block(self.evm.block().number.saturating_to())
{
// drain balances from hardcoded addresses.
let drained_balance: u128 = self
Expand Down
23 changes: 16 additions & 7 deletions crates/evm/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core::{
use revm::{
context::{BlockEnv, CfgEnv, Evm as RevmEvm, TxEnv},
context_interface::result::{EVMError, HaltReason, ResultAndState},
handler::{instructions::EthInstructions, EthPrecompiles, PrecompileProvider},
handler::{instructions::EthInstructions, EthFrame, EthPrecompiles, PrecompileProvider},
inspector::NoOpInspector,
interpreter::{interpreter::EthInterpreter, InterpreterResult},
precompile::{PrecompileSpecId, Precompiles},
Expand Down Expand Up @@ -41,6 +41,7 @@ pub struct EthEvm<DB: Database, I, PRECOMPILE = EthPrecompiles> {
I,
EthInstructions<EthInterpreter, EthEvmContext<DB>>,
PRECOMPILE,
EthFrame,
>,
inspect: bool,
}
Expand All @@ -56,6 +57,7 @@ impl<DB: Database, I, PRECOMPILE> EthEvm<DB, I, PRECOMPILE> {
I,
EthInstructions<EthInterpreter, EthEvmContext<DB>>,
PRECOMPILE,
EthFrame,
>,
inspect: bool,
) -> Self {
Expand All @@ -65,8 +67,13 @@ impl<DB: Database, I, PRECOMPILE> EthEvm<DB, I, PRECOMPILE> {
/// Consumes self and return the inner EVM instance.
pub fn into_inner(
self,
) -> RevmEvm<EthEvmContext<DB>, I, EthInstructions<EthInterpreter, EthEvmContext<DB>>, PRECOMPILE>
{
) -> RevmEvm<
EthEvmContext<DB>,
I,
EthInstructions<EthInterpreter, EthEvmContext<DB>>,
PRECOMPILE,
EthFrame,
> {
self.inner
}

Expand Down Expand Up @@ -119,10 +126,12 @@ where
self.cfg.chain_id
}

fn transact_raw(&mut self, tx: Self::Tx) -> Result<ResultAndState, Self::Error> {
fn transact_raw(
&mut self,
tx: Self::Tx,
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
if self.inspect {
self.inner.set_tx(tx);
self.inner.inspect_replay()
self.inner.inspect_tx(tx)
} else {
self.inner.transact(tx)
}
Expand All @@ -133,7 +142,7 @@ where
caller: Address,
contract: Address,
data: Bytes,
) -> Result<ResultAndState, Self::Error> {
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
let tx = TxEnv {
caller,
kind: TxKind::Call(contract),
Expand Down
14 changes: 8 additions & 6 deletions crates/evm/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,14 @@ impl<CTX: ContextTr> PrecompileProvider<CTX> for PrecompilesMap {
let r;
let input_bytes = match &inputs.input {
CallInput::SharedBuffer(range) => {
match context.local().shared_memory_buffer_slice(range.clone()) {
Some(slice) => {
r = slice;
&*r
}
None => &[],
// `map_or` does not work here as we use `r` to extend lifetime of the slice
// and return it.
#[allow(clippy::option_if_let_else)]
if let Some(slice) = context.local().shared_memory_buffer_slice(range.clone()) {
r = slice;
r.as_ref()
} else {
&[]
Comment on lines +194 to +201
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Foundry we are getting the following error on the r.as_ref() line in https://github.com/foundry-rs/foundry/tree/zerosnacks/bump-revm-26.0.0:

the trait bound `[u8]: AsRef<[_; 0]>` is not satisfied
the following other types implement trait `AsRef<T>`:
  `[u8]` implements `AsRef<winnow::stream::bstr::BStr>`
  `[u8]` implements `AsRef<winnow::stream::bytes::Bytes>`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #114

}
}
CallInput::Bytes(bytes) => bytes.as_ref(),
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<E: Evm, Txs: Iterator, F> TracerIter<'_, E, Txs, F> {
}
}

impl<'a, E, T, Txs, F, O, Err> Iterator for TracerIter<'a, E, Txs, F>
impl<E, T, Txs, F, O, Err> Iterator for TracerIter<'_, E, Txs, F>
where
E: Evm<DB: DatabaseCommit, Inspector: Clone>,
T: IntoTxEnv<E::Tx> + Clone,
Expand Down
17 changes: 12 additions & 5 deletions crates/op-evm/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ where
/// Creates a new [`OpBlockExecutor`].
pub fn new(evm: E, ctx: OpBlockExecutionCtx, spec: Spec, receipt_builder: R) -> Self {
Self {
is_regolith: spec.is_regolith_active_at_timestamp(evm.block().timestamp),
is_regolith: spec
.is_regolith_active_at_timestamp(evm.block().timestamp.saturating_to()),
evm,
system_caller: SystemCaller::new(spec.clone()),
spec,
Expand Down Expand Up @@ -101,7 +102,7 @@ where
fn apply_pre_execution_changes(&mut self) -> Result<(), BlockExecutionError> {
// Set state clear flag if the block is after the Spurious Dragon hardfork.
let state_clear_flag =
self.spec.is_spurious_dragon_active_at_block(self.evm.block().number);
self.spec.is_spurious_dragon_active_at_block(self.evm.block().number.saturating_to());
self.evm.db_mut().set_state_clear_flag(state_clear_flag);

self.system_caller.apply_blockhashes_contract_call(self.ctx.parent_hash, &mut self.evm)?;
Expand All @@ -112,8 +113,12 @@ where
// blocks will always have at least a single transaction in them (the L1 info transaction),
// so we can safely assume that this will always be triggered upon the transition and that
// the above check for empty blocks will never be hit on OP chains.
ensure_create2_deployer(&self.spec, self.evm.block().timestamp, self.evm.db_mut())
.map_err(BlockExecutionError::other)?;
ensure_create2_deployer(
&self.spec,
self.evm.block().timestamp.saturating_to(),
self.evm.db_mut(),
)
.map_err(BlockExecutionError::other)?;

Ok(())
}
Expand Down Expand Up @@ -195,7 +200,9 @@ where
// this is only set for post-Canyon deposit
// transactions.
deposit_receipt_version: (is_deposit
&& self.spec.is_canyon_active_at_timestamp(self.evm.block().timestamp))
&& self.spec.is_canyon_active_at_timestamp(
self.evm.block().timestamp.saturating_to(),
))
.then_some(1),
})
}
Expand Down
3 changes: 1 addition & 2 deletions crates/op-evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ where
tx: Self::Tx,
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
if self.inspect {
self.inner.set_tx(tx);
self.inner.inspect_replay()
self.inner.inspect_tx(tx)
} else {
self.inner.transact(tx)
}
Expand Down