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

fix(op): move l1block loading to verification #1970

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
Loading