Skip to content

Commit

Permalink
fix: fmts
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Jan 13, 2025
1 parent eb3183f commit 8fd4e8f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion crates/optimism/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use inspector::{inspector_context::InspectorContext, InspectorEthFrame};
use maili_protocol::L1BlockInfoTx;
use revm::{
context::{block::BlockEnv, tx::TxEnv, CfgEnv, Context},
context_interface::Journal,
context_interface::result::{EVMError, InvalidTransaction},
context_interface::Journal,
database_interface::Database,
Evm, JournaledState,
};
Expand Down
10 changes: 5 additions & 5 deletions crates/optimism/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
pub mod precompiles;

use crate::{
calculate_tx_l1_cost,
transaction::{
abstraction::OpTxGetter,
deposit::{DepositTransaction, DEPOSIT_TRANSACTION_TYPE},
OpTransactionError, OpTxTrait,
},
calculate_tx_l1_cost,
L1BlockInfoGetter, OpSpec, OpSpecId, OptimismHaltReason, L1_FEE_RECIPIENT, BASE_FEE_RECIPIENT,
L1BlockInfoGetter, OpSpec, OpSpecId, OptimismHaltReason, BASE_FEE_RECIPIENT, L1_FEE_RECIPIENT,
};
use maili_protocol::L1BlockInfoTx;
use precompiles::OpPrecompileProvider;
Expand Down Expand Up @@ -114,8 +114,7 @@ where
// The L1-cost fee is only computed for Optimism non-deposit transactions.
let spec = context.cfg().spec();
if context.tx().tx_type() != DEPOSIT_TRANSACTION_TYPE {
let l1_block_info: L1BlockInfoTx =
crate::l1block::try_fetch(context.db(), spec)?;
let l1_block_info: L1BlockInfoTx = crate::l1block::try_fetch(context.db(), spec)?;

// Storage L1 block info for later use.
*context.l1_block_info_mut() = l1_block_info;
Expand Down Expand Up @@ -149,7 +148,8 @@ where
.expect("all not deposit tx have enveloped tx")
.clone();

tx_l1_cost = calculate_tx_l1_cost(context.l1_block_info(), &enveloped_tx, context.cfg().spec());
tx_l1_cost =
calculate_tx_l1_cost(context.l1_block_info(), &enveloped_tx, context.cfg().spec());
}

// We deduct caller max balance after minting and before deducing the
Expand Down
42 changes: 22 additions & 20 deletions crates/optimism/src/l1block.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::OpSpecId;
use maili_protocol::{
calculate_tx_l1_cost_bedrock, calculate_tx_l1_cost_bedrock_empty_scalars,
calculate_tx_l1_cost_ecotone, calculate_tx_l1_cost_fjord, calculate_tx_l1_cost_regolith,
L1BlockInfoBedrock, L1BlockInfoEcotone, L1BlockInfoTx,
};
use revm::{
database_interface::Database,
primitives::{address, Bytes, Address, U256},
primitives::{address, Address, Bytes, U256},
specification::hardfork::SpecId,
};
use maili_protocol::{
L1BlockInfoEcotone, L1BlockInfoBedrock, L1BlockInfoTx, calculate_tx_l1_cost_bedrock, calculate_tx_l1_cost_ecotone, calculate_tx_l1_cost_fjord,
calculate_tx_l1_cost_bedrock_empty_scalars,
calculate_tx_l1_cost_regolith,
};

use super::OpSpec;

Expand Down Expand Up @@ -96,9 +96,8 @@ pub fn try_fetch<DB: Database>(db: &mut DB, spec_id: OpSpec) -> Result<L1BlockIn
let _ = db.basic(L1_BLOCK_CONTRACT)?;
}

let l1_base_fee = TryInto::<u64>::try_into(
db.storage(L1_BLOCK_CONTRACT, L1_BASE_FEE_SLOT)?,
).unwrap();
let l1_base_fee =
TryInto::<u64>::try_into(db.storage(L1_BLOCK_CONTRACT, L1_BASE_FEE_SLOT)?).unwrap();

if !spec_id.is_enabled_in(OpSpecId::ECOTONE) {
let l1_fee_overhead = db.storage(L1_BLOCK_CONTRACT, L1_OVERHEAD_SLOT)?;
Expand All @@ -111,20 +110,22 @@ pub fn try_fetch<DB: Database>(db: &mut DB, spec_id: OpSpec) -> Result<L1BlockIn
..Default::default()
}))
} else {
let l1_blob_base_fee = TryInto::<u128>::try_into(db.storage(L1_BLOCK_CONTRACT, ECOTONE_L1_BLOB_BASE_FEE_SLOT)?).unwrap();
let l1_blob_base_fee = TryInto::<u128>::try_into(
db.storage(L1_BLOCK_CONTRACT, ECOTONE_L1_BLOB_BASE_FEE_SLOT)?,
)
.unwrap();
let l1_fee_scalars = db
.storage(L1_BLOCK_CONTRACT, ECOTONE_L1_FEE_SCALARS_SLOT)?
.to_be_bytes::<32>();


let l1_base_fee_scalar = TryInto::<u32>::try_into(U256::from_be_slice(
l1_fee_scalars[BASE_FEE_SCALAR_OFFSET..BASE_FEE_SCALAR_OFFSET + 4]
.as_ref(),
)).unwrap();
l1_fee_scalars[BASE_FEE_SCALAR_OFFSET..BASE_FEE_SCALAR_OFFSET + 4].as_ref(),
))
.unwrap();
let l1_blob_base_fee_scalar = TryInto::<u32>::try_into(U256::from_be_slice(
l1_fee_scalars[BLOB_BASE_FEE_SCALAR_OFFSET..BLOB_BASE_FEE_SCALAR_OFFSET + 4]
.as_ref(),
)).unwrap();
l1_fee_scalars[BLOB_BASE_FEE_SCALAR_OFFSET..BLOB_BASE_FEE_SCALAR_OFFSET + 4].as_ref(),
))
.unwrap();

// Check if the L1 fee scalars are empty. If so, we use the Bedrock cost function.
// The L1 fee overhead is only necessary if `empty_scalars` is true, as it was deprecated in Ecotone.
Expand All @@ -150,8 +151,8 @@ pub fn try_fetch<DB: Database>(db: &mut DB, spec_id: OpSpec) -> Result<L1BlockIn
#[cfg(test)]
mod tests {
use super::*;
use maili_protocol::{data_gas_bedrock, data_gas_fjord, data_gas_regolith};
use revm::primitives::{bytes, hex};
use maili_protocol::{data_gas_regolith, data_gas_bedrock, data_gas_fjord};

#[test]
fn test_data_gas_non_zero_bytes() {
Expand Down Expand Up @@ -302,7 +303,8 @@ mod tests {

assert_eq!(gas_used, expected_l1_gas_used);

let l1_fee = calculate_tx_l1_cost(&l1_block_info, &Bytes::from(TX), OpSpecId::ECOTONE.into());
let l1_fee =
calculate_tx_l1_cost(&l1_block_info, &Bytes::from(TX), OpSpecId::ECOTONE.into());

assert_eq!(l1_fee, expected_l1_fee)
}
Expand Down Expand Up @@ -353,7 +355,7 @@ mod tests {
assert_eq!(gas_cost, U256::ZERO);
}

#[test]
#[test]
fn calculate_tx_l1_cost_fjord() {
// rig

Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ extern crate alloc as std;

pub mod bn128;
pub mod evm;
pub mod l1block;
pub mod fast_lz;
pub mod handler;
pub mod l1block;
pub mod result;
pub mod spec;
pub mod transaction;

pub use l1block::{calculate_tx_l1_cost, L1_FEE_RECIPIENT, BASE_FEE_RECIPIENT};
pub use evm::L1BlockInfoGetter;
pub use l1block::{calculate_tx_l1_cost, BASE_FEE_RECIPIENT, L1_FEE_RECIPIENT};
pub use result::OptimismHaltReason;
pub use spec::*;
pub use transaction::{error::OpTransactionError, estimate_tx_compressed_size, OpTransaction};

0 comments on commit 8fd4e8f

Please sign in to comment.