diff --git a/Cargo.toml b/Cargo.toml index 70ea7d9..4461682 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trevm" -version = "0.31.1" +version = "0.31.2" rust-version = "1.83.0" edition = "2021" authors = ["init4"] diff --git a/src/driver/alloy.rs b/src/driver/alloy.rs index 212c377..89a6bc7 100644 --- a/src/driver/alloy.rs +++ b/src/driver/alloy.rs @@ -1,6 +1,8 @@ use crate::{ helpers::Ctx, - system::{MAX_BLOB_GAS_PER_BLOCK_CANCUN, MAX_BLOB_GAS_PER_BLOCK_PRAGUE}, + system::{ + MAX_BLOB_GAS_PER_BLOCK_CANCUN, MAX_BLOB_GAS_PER_BLOCK_OSAKA, MAX_BLOB_GAS_PER_BLOCK_PRAGUE, + }, trevm_bail, trevm_ensure, trevm_try, Block, BundleDriver, DriveBundleResult, }; use alloy::{ @@ -592,6 +594,7 @@ where let mbg = match trevm.spec_id() { SpecId::CANCUN => MAX_BLOB_GAS_PER_BLOCK_CANCUN, SpecId::PRAGUE => MAX_BLOB_GAS_PER_BLOCK_PRAGUE, + SpecId::OSAKA => MAX_BLOB_GAS_PER_BLOCK_OSAKA, _ => 0, }; trevm_ensure!( @@ -690,6 +693,7 @@ where let mbg = match trevm.spec_id() { SpecId::CANCUN => MAX_BLOB_GAS_PER_BLOCK_CANCUN, SpecId::PRAGUE => MAX_BLOB_GAS_PER_BLOCK_PRAGUE, + SpecId::OSAKA => MAX_BLOB_GAS_PER_BLOCK_OSAKA, _ => 0, }; trevm_ensure!( diff --git a/src/evm/has_tx.rs b/src/evm/has_tx.rs index 7decc8c..70d17d4 100644 --- a/src/evm/has_tx.rs +++ b/src/evm/has_tx.rs @@ -1,8 +1,11 @@ use crate::{helpers::Ctx, EvmErrored, HasBlock, HasCfg, HasTx, Trevm, Tx}; -use alloy::primitives::{Address, Bytes, U256}; +use alloy::{ + eips::eip7825::MAX_TX_GAS_LIMIT_OSAKA, + primitives::{Address, Bytes, U256}, +}; use revm::{ context::{result::EVMError, ContextSetters, ContextTr, Transaction as _, TxEnv}, - primitives::TxKind, + primitives::{hardfork::SpecId, TxKind}, state::AccountInfo, Database, DatabaseRef, Inspector, }; @@ -212,8 +215,27 @@ where /// The gas limit after the operation. pub fn cap_tx_gas(&mut self) -> Result::Error>> { self.cap_tx_gas_to_block_limit(); + + // If the currently active SpecId is Osaka or greater, also attempt to cap the gas limit to the EIP-7825 limit. + if self.spec_id() >= SpecId::OSAKA { + self.cap_tx_gas_to_eip7825(); + } + self.cap_tx_gas_to_allowance() } + + /// Cap the gas limit of the transaction to the [`EIP-7825`] limit. + /// + /// # Returns + /// + /// The gas limit after the operation. + /// + /// [`EIP-7825`]: https://eips.ethereum.org/EIPS/eip-7825 + pub fn cap_tx_gas_to_eip7825(&mut self) -> u64 { + self.inner.modify_tx(|tx| tx.gas_limit = tx.gas_limit.min(MAX_TX_GAS_LIMIT_OSAKA)); + + self.tx().gas_limit + } } #[cfg(test)] @@ -264,7 +286,7 @@ mod tests { let log_address = Address::repeat_byte(0x32); // Set up trevm, and test balances. - let mut trevm = TrevmBuilder::new().with_db(db).with_spec_id(SpecId::PRAGUE).build_trevm(); + let mut trevm = TrevmBuilder::new().with_db(db).with_spec_id(SpecId::OSAKA).build_trevm(); let _ = trevm.test_set_balance(ALICE.address(), U256::from(ETH_TO_WEI)); let _ = trevm.set_bytecode_unchecked(log_address, Bytecode::new_raw(LOG_DEPLOYED_BYTECODE)); diff --git a/src/system/mod.rs b/src/system/mod.rs index 1c92006..38f93d6 100644 --- a/src/system/mod.rs +++ b/src/system/mod.rs @@ -59,6 +59,9 @@ pub const MAX_BLOB_GAS_PER_BLOCK_CANCUN: u64 = 786_432; /// The maximum blob gas limit for a block in Prague. pub const MAX_BLOB_GAS_PER_BLOCK_PRAGUE: u64 = 1_179_648; +/// The maximum blob gas limit for a block in Osaka, pre BPO-1. +pub const MAX_BLOB_GAS_PER_BLOCK_OSAKA: u64 = 1_749_648; + use crate::{ helpers::{Ctx, Evm}, EvmExtUnchecked, Tx,