Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion src/driver/alloy.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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!(
Expand Down
28 changes: 25 additions & 3 deletions src/evm/has_tx.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down Expand Up @@ -212,8 +215,27 @@ where
/// The gas limit after the operation.
pub fn cap_tx_gas(&mut self) -> Result<u64, EVMError<<Db as Database>::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)]
Expand Down Expand Up @@ -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));

Expand Down
3 changes: 3 additions & 0 deletions src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down