Skip to content

Commit 05579a7

Browse files
authored
feat(general): osaka changes & fixes (#134)
* feat(general): osaka changes & fixes This fixes estimation issues with Osaka, as we now need to cap gas to the individual, per tx limit. * chore: add max blob gas per block for osaka pre bpo * chore: v0.31.2
1 parent 5251ce3 commit 05579a7

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "trevm"
3-
version = "0.31.1"
3+
version = "0.31.2"
44
rust-version = "1.83.0"
55
edition = "2021"
66
authors = ["init4"]

src/driver/alloy.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::{
22
helpers::Ctx,
3-
system::{MAX_BLOB_GAS_PER_BLOCK_CANCUN, MAX_BLOB_GAS_PER_BLOCK_PRAGUE},
3+
system::{
4+
MAX_BLOB_GAS_PER_BLOCK_CANCUN, MAX_BLOB_GAS_PER_BLOCK_OSAKA, MAX_BLOB_GAS_PER_BLOCK_PRAGUE,
5+
},
46
trevm_bail, trevm_ensure, trevm_try, Block, BundleDriver, DriveBundleResult,
57
};
68
use alloy::{
@@ -592,6 +594,7 @@ where
592594
let mbg = match trevm.spec_id() {
593595
SpecId::CANCUN => MAX_BLOB_GAS_PER_BLOCK_CANCUN,
594596
SpecId::PRAGUE => MAX_BLOB_GAS_PER_BLOCK_PRAGUE,
597+
SpecId::OSAKA => MAX_BLOB_GAS_PER_BLOCK_OSAKA,
595598
_ => 0,
596599
};
597600
trevm_ensure!(
@@ -690,6 +693,7 @@ where
690693
let mbg = match trevm.spec_id() {
691694
SpecId::CANCUN => MAX_BLOB_GAS_PER_BLOCK_CANCUN,
692695
SpecId::PRAGUE => MAX_BLOB_GAS_PER_BLOCK_PRAGUE,
696+
SpecId::OSAKA => MAX_BLOB_GAS_PER_BLOCK_OSAKA,
693697
_ => 0,
694698
};
695699
trevm_ensure!(

src/evm/has_tx.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use crate::{helpers::Ctx, EvmErrored, HasBlock, HasCfg, HasTx, Trevm, Tx};
2-
use alloy::primitives::{Address, Bytes, U256};
2+
use alloy::{
3+
eips::eip7825::MAX_TX_GAS_LIMIT_OSAKA,
4+
primitives::{Address, Bytes, U256},
5+
};
36
use revm::{
47
context::{result::EVMError, ContextSetters, ContextTr, Transaction as _, TxEnv},
5-
primitives::TxKind,
8+
primitives::{hardfork::SpecId, TxKind},
69
state::AccountInfo,
710
Database, DatabaseRef, Inspector,
811
};
@@ -212,8 +215,27 @@ where
212215
/// The gas limit after the operation.
213216
pub fn cap_tx_gas(&mut self) -> Result<u64, EVMError<<Db as Database>::Error>> {
214217
self.cap_tx_gas_to_block_limit();
218+
219+
// If the currently active SpecId is Osaka or greater, also attempt to cap the gas limit to the EIP-7825 limit.
220+
if self.spec_id() >= SpecId::OSAKA {
221+
self.cap_tx_gas_to_eip7825();
222+
}
223+
215224
self.cap_tx_gas_to_allowance()
216225
}
226+
227+
/// Cap the gas limit of the transaction to the [`EIP-7825`] limit.
228+
///
229+
/// # Returns
230+
///
231+
/// The gas limit after the operation.
232+
///
233+
/// [`EIP-7825`]: https://eips.ethereum.org/EIPS/eip-7825
234+
pub fn cap_tx_gas_to_eip7825(&mut self) -> u64 {
235+
self.inner.modify_tx(|tx| tx.gas_limit = tx.gas_limit.min(MAX_TX_GAS_LIMIT_OSAKA));
236+
237+
self.tx().gas_limit
238+
}
217239
}
218240

219241
#[cfg(test)]
@@ -264,7 +286,7 @@ mod tests {
264286
let log_address = Address::repeat_byte(0x32);
265287

266288
// Set up trevm, and test balances.
267-
let mut trevm = TrevmBuilder::new().with_db(db).with_spec_id(SpecId::PRAGUE).build_trevm();
289+
let mut trevm = TrevmBuilder::new().with_db(db).with_spec_id(SpecId::OSAKA).build_trevm();
268290
let _ = trevm.test_set_balance(ALICE.address(), U256::from(ETH_TO_WEI));
269291
let _ = trevm.set_bytecode_unchecked(log_address, Bytecode::new_raw(LOG_DEPLOYED_BYTECODE));
270292

src/system/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ pub const MAX_BLOB_GAS_PER_BLOCK_CANCUN: u64 = 786_432;
5959
/// The maximum blob gas limit for a block in Prague.
6060
pub const MAX_BLOB_GAS_PER_BLOCK_PRAGUE: u64 = 1_179_648;
6161

62+
/// The maximum blob gas limit for a block in Osaka, pre BPO-1.
63+
pub const MAX_BLOB_GAS_PER_BLOCK_OSAKA: u64 = 1_749_648;
64+
6265
use crate::{
6366
helpers::{Ctx, Evm},
6467
EvmExtUnchecked, Tx,

0 commit comments

Comments
 (0)