Skip to content

Commit 7a8493b

Browse files
committed
feat(general): osaka changes & fixes
This fixes estimation issues with Osaka, as we now need to cap gas to the individual, per tx limit.
1 parent 5251ce3 commit 7a8493b

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

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

0 commit comments

Comments
 (0)