Skip to content

Commit

Permalink
fix(op): move l1block loading to verification
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Jan 6, 2025
1 parent ae26414 commit 40818a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
5 changes: 2 additions & 3 deletions crates/revm/src/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ mod l1block;
mod precompile;

pub use handler_register::{
clear, deduct_caller, end, last_frame_return, load_accounts, load_precompiles,
optimism_handle_register, output, refund, reimburse_caller, reward_beneficiary, validate_env,
validate_tx_against_state,
clear, deduct_caller, end, last_frame_return, load_precompiles, optimism_handle_register,
output, refund, reimburse_caller, reward_beneficiary, validate_env, validate_tx_against_state,
};
pub use l1block::{
L1BlockInfo, BASE_FEE_RECIPIENT, L1_BLOCK_CONTRACT, L1_FEE_RECIPIENT, OPERATOR_FEE_RECIPIENT,
Expand Down
35 changes: 11 additions & 24 deletions crates/revm/src/optimism/handler_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ pub fn optimism_handle_register<DB: Database, EXT>(handler: &mut EvmHandler<'_,
handler.validation.tx_against_state = Arc::new(validate_tx_against_state::<SPEC, EXT, DB>);
// Load additional precompiles for the given chain spec.
handler.pre_execution.load_precompiles = Arc::new(load_precompiles::<SPEC, EXT, DB>);
// load l1 data
handler.pre_execution.load_accounts = Arc::new(load_accounts::<SPEC, EXT, DB>);
// An estimated batch cost is charged from the caller and added to L1 Fee Vault.
handler.pre_execution.deduct_caller = Arc::new(deduct_caller::<SPEC, EXT, DB>);
// Refund is calculated differently then mainnet.
Expand Down Expand Up @@ -70,13 +68,21 @@ pub fn validate_env<SPEC: Spec, DB: Database>(env: &Env) -> Result<(), EVMError<
pub fn validate_tx_against_state<SPEC: Spec, EXT, DB: Database>(
context: &mut Context<EXT, DB>,
) -> Result<(), EVMError<DB::Error>> {
let env @ Env { cfg, tx, .. } = context.evm.inner.env.as_ref();

// No validation is needed for deposit transactions, as they are pre-verified on L1.
if tx.optimism.source_hash.is_some() {
if context.evm.inner.env.tx.optimism.source_hash.is_some() {
return Ok(());
}

// the L1-cost fee is only computed for Optimism non-deposit transactions.
let l1_block_info =
crate::optimism::L1BlockInfo::try_fetch(&mut context.evm.inner.db, SPEC::SPEC_ID)
.map_err(EVMError::Database)?;

// storage l1 block info for later use.
context.evm.inner.l1_block_info = Some(l1_block_info);

let env @ Env { cfg, tx, .. } = context.evm.inner.env.as_ref();

// load acc
let tx_caller = tx.caller;
let account = context
Expand Down Expand Up @@ -312,25 +318,6 @@ pub fn load_precompiles<SPEC: Spec, EXT, DB: Database>() -> ContextPrecompiles<D
}
}

/// Load account (make them warm) and l1 data from database.
#[inline]
pub fn load_accounts<SPEC: Spec, EXT, DB: Database>(
context: &mut Context<EXT, DB>,
) -> Result<(), EVMError<DB::Error>> {
// the L1-cost fee is only computed for Optimism non-deposit transactions.

if context.evm.inner.env.tx.optimism.source_hash.is_none() {
let l1_block_info =
crate::optimism::L1BlockInfo::try_fetch(&mut context.evm.inner.db, SPEC::SPEC_ID)
.map_err(EVMError::Database)?;

// storage l1 block info for later use.
context.evm.inner.l1_block_info = Some(l1_block_info);
}

mainnet::load_accounts::<SPEC, EXT, DB>(context)
}

/// Deduct max balance from caller
#[inline]
pub fn deduct_caller<SPEC: Spec, EXT, DB: Database>(
Expand Down

0 comments on commit 40818a8

Please sign in to comment.