|
1 | 1 | 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 | +}; |
3 | 6 | use revm::{ |
4 | 7 | context::{result::EVMError, ContextSetters, ContextTr, Transaction as _, TxEnv}, |
5 | | - primitives::TxKind, |
| 8 | + primitives::{hardfork::SpecId, TxKind}, |
6 | 9 | state::AccountInfo, |
7 | 10 | Database, DatabaseRef, Inspector, |
8 | 11 | }; |
@@ -212,8 +215,27 @@ where |
212 | 215 | /// The gas limit after the operation. |
213 | 216 | pub fn cap_tx_gas(&mut self) -> Result<u64, EVMError<<Db as Database>::Error>> { |
214 | 217 | 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 | + |
215 | 224 | self.cap_tx_gas_to_allowance() |
216 | 225 | } |
| 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 | + } |
217 | 239 | } |
218 | 240 |
|
219 | 241 | #[cfg(test)] |
@@ -264,7 +286,7 @@ mod tests { |
264 | 286 | let log_address = Address::repeat_byte(0x32); |
265 | 287 |
|
266 | 288 | // 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(); |
268 | 290 | let _ = trevm.test_set_balance(ALICE.address(), U256::from(ETH_TO_WEI)); |
269 | 291 | let _ = trevm.set_bytecode_unchecked(log_address, Bytecode::new_raw(LOG_DEPLOYED_BYTECODE)); |
270 | 292 |
|
|
0 commit comments