From 58278e7ee7c31cb8a97c1c22ddfe395475de721d Mon Sep 17 00:00:00 2001 From: evalir Date: Tue, 16 Sep 2025 16:45:46 -0400 Subject: [PATCH 01/11] chore(evm): add 7702 estimation test --- src/evm.rs | 99 ++++++++++++++++++++++++++++++++++++++++++++++- src/test_utils.rs | 3 ++ 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/src/evm.rs b/src/evm.rs index bccf3c8..0b10775 100644 --- a/src/evm.rs +++ b/src/evm.rs @@ -2033,7 +2033,7 @@ where // NB: 64 / 63 is due to Ethereum's gas-forwarding rules. Each call // frame can forward only 63/64 of the gas it has when it makes a new // frame. - let mut needle = gas_used + gas_refunded + revm::interpreter::gas::CALL_STIPEND * 64 / 63; + let mut needle = (gas_used + gas_refunded + revm::interpreter::gas::CALL_STIPEND) * 64 / 63; // If the first search is outside the range, we don't need to try it. if search_range.contains(needle) { @@ -2346,6 +2346,103 @@ where } } +#[cfg(test)] +mod tests { + use std::sync::LazyLock; + + use alloy::network::{TransactionBuilder, TransactionBuilder7702}; + use alloy::rpc::types::Authorization; + use alloy::signers::k256::ecdsa::SigningKey; + use alloy::signers::local::PrivateKeySigner; + use alloy::signers::SignerSync; + use alloy::{consensus::constants::ETH_TO_WEI, rpc::types::TransactionRequest}; + + use revm::database::InMemoryDB; + use revm::inspector::NoOpInspector; + use revm::primitives::bytes; + + use crate::test_utils::{test_trevm_with_funds, LOG_BYTECODE}; + use crate::{EvmNeedsCfg, TrevmBuilder}; + use crate::{NoopBlock, NoopCfg}; + + use super::*; + + static ALICE: LazyLock = + LazyLock::new(|| PrivateKeySigner::from(SigningKey::from_slice(&[0x11; 32]).unwrap())); + static BOB: LazyLock = + LazyLock::new(|| PrivateKeySigner::from(SigningKey::from_slice(&[0x22; 32]).unwrap())); + + fn trevm_with_funds() -> EvmNeedsCfg { + test_trevm_with_funds(&[ + (ALICE.address(), U256::from(ETH_TO_WEI)), + (BOB.address(), U256::from(ETH_TO_WEI)), + ]) + } + + #[test] + fn test_estimate_gas_simple_transfer() { + let trevm = trevm_with_funds(); + + let tx = TransactionRequest::default() + .from(ALICE.address()) + .to(BOB.address()) + .value(U256::from(ETH_TO_WEI / 2)); + + let (estimation, _trevm) = + trevm.fill_cfg(&NoopCfg).fill_block(&NoopBlock).fill_tx(&tx).estimate_gas().unwrap(); + + assert!(estimation.is_success()); + // The gas used should correspond to a simple transfer. + assert!(estimation.gas_used() == 21000); + } + + #[test] + fn test_7702_authorization_estimation() { + // Insert the LogContract code + let db = InMemoryDB::default(); + 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().unwrap(); + let _ = trevm.test_set_balance(ALICE.address(), U256::from(ETH_TO_WEI)); + let _ = trevm.set_bytecode_unchecked(log_address, Bytecode::new_raw(LOG_BYTECODE.into())); + + // Bob will sign the authorization. + let authorization = Authorization { + chain_id: U256::ZERO, + address: log_address, + // We know Bob's nonce is 0. + nonce: 0, + }; + let signature = BOB.sign_hash_sync(&authorization.signature_hash()).unwrap(); + let signed_authorization = authorization.into_signed(signature); + + let tx = TransactionRequest::default() + .from(ALICE.address()) + .to(BOB.address()) + .with_authorization_list(vec![signed_authorization]) + .with_input(bytes!("0x7b3ab2d0")); // emitHello() + + let (estimation, trevm) = + trevm.fill_cfg(&NoopCfg).fill_block(&NoopBlock).fill_tx(&tx).estimate_gas().unwrap(); + + dbg!(&estimation); + assert!(estimation.is_success()); + + let tx = tx.with_gas_limit(estimation.limit()); + + let mut output = trevm.clear_tx().fill_tx(&tx).run().unwrap(); + + let bob_code = output.read_code(BOB.address()); + dbg!(&bob_code); + + dbg!(&output.result()); + assert!(output.result().is_success()); + assert!(output.result().logs().len() == 1); + } +} + // Some code above and documentation is adapted from the revm crate, and is // reproduced here under the terms of the MIT license. // diff --git a/src/test_utils.rs b/src/test_utils.rs index c706e45..a2c3d7e 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -12,6 +12,9 @@ use revm::{ Context, Inspector, MainBuilder, }; +/// LogContract bytecode +pub const LOG_BYTECODE: &str = "0x60806040526004361015610013575b6100ca565b61001d5f3561003c565b80637b3ab2d01461003757639ee1a4400361000e57610097565b610064565b60e01c90565b60405190565b5f80fd5b5f80fd5b5f91031261005a57565b61004c565b5f0190565b3461009257610074366004610050565b61007c6100ce565b610084610042565b8061008e8161005f565b0390f35b610048565b346100c5576100a7366004610050565b6100af610106565b6100b7610042565b806100c18161005f565b0390f35b610048565b5f80fd5b7fbcdfe0d5b27dd186282e187525415c57ea3077c34efb39148111e4d342e7ab0e6100f7610042565b806101018161005f565b0390a1565b7f2d67bb91f17bca05af6764ab411e86f4ddf757adb89fcec59a7d21c525d4171261012f610042565b806101398161005f565b0390a156fea2646970667358221220e22cd46ba129dcbd6f62f632cc862b0924d3f36c991fd0b45947581aa3010d6464736f6c634300081a0033"; + impl Trevm where Insp: Inspector>, From 1d18030f17d11eeaa6e8e2ce661770cf47f53999 Mon Sep 17 00:00:00 2001 From: evalir Date: Tue, 16 Sep 2025 17:01:42 -0400 Subject: [PATCH 02/11] fix: .accept() --- src/est.rs | 29 ++++++++++++++++++++++++++++- src/evm.rs | 10 +++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/est.rs b/src/est.rs index c2a5b4d..4c2f6a7 100644 --- a/src/est.rs +++ b/src/est.rs @@ -34,7 +34,7 @@ impl SearchRange { /// Calculate the midpoint of the search range. pub(crate) const fn midpoint(&self) -> u64 { - (self.max() + self.min()) / 2 + ((self.max() as u128 + self.min() as u128) / 2) as u64 } /// Get the start of the search range. @@ -272,6 +272,33 @@ impl EstimationResult { } } +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_search_range() { + let mut range = SearchRange::new(100, 200); + assert_eq!(range.min(), 100); + assert_eq!(range.max(), 200); + assert_eq!(range.size(), 100); + assert_eq!(range.ratio(), 0.5); + assert_eq!(range.midpoint(), 150); + assert!(range.contains(150)); + + range.maybe_raise_min(100); + assert_eq!(range.min(), 100); + + range.maybe_raise_min(125); + assert_eq!(range.min(), 125); + assert_eq!(range.midpoint(), 162); + + range.maybe_lower_max(180); + assert_eq!(range.max(), 180); + assert_eq!(range.midpoint(), 152); + } +} + // Some code above is reproduced from `reth`. It is reused here under the MIT // license. // diff --git a/src/evm.rs b/src/evm.rs index 0b10775..98c4ff4 100644 --- a/src/evm.rs +++ b/src/evm.rs @@ -2432,14 +2432,14 @@ mod tests { let tx = tx.with_gas_limit(estimation.limit()); - let mut output = trevm.clear_tx().fill_tx(&tx).run().unwrap(); + let mut output = trevm.clear_tx().fill_tx(&tx).run().unwrap().accept(); - let bob_code = output.read_code(BOB.address()); + let bob_code = output.1.read_code(BOB.address()); dbg!(&bob_code); - dbg!(&output.result()); - assert!(output.result().is_success()); - assert!(output.result().logs().len() == 1); + dbg!(&output.0); + assert!(output.0.is_success()); + assert!(output.0.logs().len() == 1); } } From 527c2441510c1f6c604d5f4ce93113adb598dfe2 Mon Sep 17 00:00:00 2001 From: evalir Date: Tue, 16 Sep 2025 17:35:34 -0400 Subject: [PATCH 03/11] fix: properly set tx type on TransactionRequest filler --- src/evm.rs | 2 ++ src/fill/alloy.rs | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/evm.rs b/src/evm.rs index 98c4ff4..adb5a37 100644 --- a/src/evm.rs +++ b/src/evm.rs @@ -2357,6 +2357,7 @@ mod tests { use alloy::signers::SignerSync; use alloy::{consensus::constants::ETH_TO_WEI, rpc::types::TransactionRequest}; + use revm::context::transaction::AuthorizationTr; use revm::database::InMemoryDB; use revm::inspector::NoOpInspector; use revm::primitives::bytes; @@ -2417,6 +2418,7 @@ mod tests { }; let signature = BOB.sign_hash_sync(&authorization.signature_hash()).unwrap(); let signed_authorization = authorization.into_signed(signature); + assert!(signed_authorization.authority().unwrap() == BOB.address()); let tx = TransactionRequest::default() .from(ALICE.address()) diff --git a/src/fill/alloy.rs b/src/fill/alloy.rs index d0ff065..9b24d64 100644 --- a/src/fill/alloy.rs +++ b/src/fill/alloy.rs @@ -359,9 +359,22 @@ impl Tx for alloy::rpc::types::TransactionRequest { *caller = self.from.unwrap_or_default(); - // NB: this is set to max if not provided, as users will typically - // intend that to mean "as much as possible" - *tx_type = self.transaction_type.unwrap_or(TxType::Eip1559 as u8); + // Determine the minimal tx type usable. + *tx_type = { + if self.transaction_type.is_some() { + self.transaction_type.unwrap() + } else if self.authorization_list.is_some() { + TxType::Eip7702 as u8 + } else if self.has_eip4844_fields() { + TxType::Eip4844 as u8 + } else if self.has_eip1559_fields() { + TxType::Eip1559 as u8 + } else if self.access_list.is_some() { + TxType::Eip2930 as u8 + } else { + TxType::Legacy as u8 + } + }; *gas_limit = self.gas.unwrap_or(u64::MAX); *gas_price = self.gas_price.unwrap_or_default().max(self.max_fee_per_gas.unwrap_or_default()); From fe187153b2e4796878aac596b48e3c3568a1a9df Mon Sep 17 00:00:00 2001 From: evalir Date: Tue, 16 Sep 2025 17:42:00 -0400 Subject: [PATCH 04/11] chore: push proper bytecode --- src/test_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test_utils.rs b/src/test_utils.rs index a2c3d7e..498f73a 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -13,7 +13,7 @@ use revm::{ }; /// LogContract bytecode -pub const LOG_BYTECODE: &str = "0x60806040526004361015610013575b6100ca565b61001d5f3561003c565b80637b3ab2d01461003757639ee1a4400361000e57610097565b610064565b60e01c90565b60405190565b5f80fd5b5f80fd5b5f91031261005a57565b61004c565b5f0190565b3461009257610074366004610050565b61007c6100ce565b610084610042565b8061008e8161005f565b0390f35b610048565b346100c5576100a7366004610050565b6100af610106565b6100b7610042565b806100c18161005f565b0390f35b610048565b5f80fd5b7fbcdfe0d5b27dd186282e187525415c57ea3077c34efb39148111e4d342e7ab0e6100f7610042565b806101018161005f565b0390a1565b7f2d67bb91f17bca05af6764ab411e86f4ddf757adb89fcec59a7d21c525d4171261012f610042565b806101398161005f565b0390a156fea2646970667358221220e22cd46ba129dcbd6f62f632cc862b0924d3f36c991fd0b45947581aa3010d6464736f6c634300081a0033"; +pub const LOG_BYTECODE: &str = "0x6004361015600b575f80fd5b5f3560e01c80637b3ab2d014605f57639ee1a440146027575f80fd5b34605b575f366003190112605b577f2d67bb91f17bca05af6764ab411e86f4ddf757adb89fcec59a7d21c525d417125f80a1005b5f80fd5b34605b575f366003190112605b577fbcdfe0d5b27dd186282e187525415c57ea3077c34efb39148111e4d342e7ab0e5f80a100fea2646970667358221220f6b42b522bc9fb2b4c7d7e611c"; impl Trevm where From 72bc2e53ab56470202bddaff1f70d4e9c1eebda4 Mon Sep 17 00:00:00 2001 From: evalir Date: Tue, 16 Sep 2025 17:45:01 -0400 Subject: [PATCH 05/11] readd bytecode --- src/test_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test_utils.rs b/src/test_utils.rs index 498f73a..a2c3d7e 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -13,7 +13,7 @@ use revm::{ }; /// LogContract bytecode -pub const LOG_BYTECODE: &str = "0x6004361015600b575f80fd5b5f3560e01c80637b3ab2d014605f57639ee1a440146027575f80fd5b34605b575f366003190112605b577f2d67bb91f17bca05af6764ab411e86f4ddf757adb89fcec59a7d21c525d417125f80a1005b5f80fd5b34605b575f366003190112605b577fbcdfe0d5b27dd186282e187525415c57ea3077c34efb39148111e4d342e7ab0e5f80a100fea2646970667358221220f6b42b522bc9fb2b4c7d7e611c"; +pub const LOG_BYTECODE: &str = "0x60806040526004361015610013575b6100ca565b61001d5f3561003c565b80637b3ab2d01461003757639ee1a4400361000e57610097565b610064565b60e01c90565b60405190565b5f80fd5b5f80fd5b5f91031261005a57565b61004c565b5f0190565b3461009257610074366004610050565b61007c6100ce565b610084610042565b8061008e8161005f565b0390f35b610048565b346100c5576100a7366004610050565b6100af610106565b6100b7610042565b806100c18161005f565b0390f35b610048565b5f80fd5b7fbcdfe0d5b27dd186282e187525415c57ea3077c34efb39148111e4d342e7ab0e6100f7610042565b806101018161005f565b0390a1565b7f2d67bb91f17bca05af6764ab411e86f4ddf757adb89fcec59a7d21c525d4171261012f610042565b806101398161005f565b0390a156fea2646970667358221220e22cd46ba129dcbd6f62f632cc862b0924d3f36c991fd0b45947581aa3010d6464736f6c634300081a0033"; impl Trevm where From 3ee90ffa0ba922c06df813af35e1fc67b9f17a43 Mon Sep 17 00:00:00 2001 From: evalir Date: Wed, 17 Sep 2025 09:00:36 -0400 Subject: [PATCH 06/11] chore: address review comments --- src/est.rs | 8 +++++- src/evm.rs | 63 +++++++++++++++++------------------------------ src/test_utils.rs | 26 ++++++++++++++++++- 3 files changed, 55 insertions(+), 42 deletions(-) diff --git a/src/est.rs b/src/est.rs index 4c2f6a7..ac0ec59 100644 --- a/src/est.rs +++ b/src/est.rs @@ -34,7 +34,7 @@ impl SearchRange { /// Calculate the midpoint of the search range. pub(crate) const fn midpoint(&self) -> u64 { - ((self.max() as u128 + self.min() as u128) / 2) as u64 + (self.max() + self.min()) / 2 } /// Get the start of the search range. @@ -296,6 +296,12 @@ mod tests { range.maybe_lower_max(180); assert_eq!(range.max(), 180); assert_eq!(range.midpoint(), 152); + + range.maybe_raise_min(100); + assert_eq!(range.min(), 125); + + range.maybe_lower_max(200); + assert_eq!(range.max(), 180); } } diff --git a/src/evm.rs b/src/evm.rs index adb5a37..c7f906a 100644 --- a/src/evm.rs +++ b/src/evm.rs @@ -2348,41 +2348,29 @@ where #[cfg(test)] mod tests { - use std::sync::LazyLock; - - use alloy::network::{TransactionBuilder, TransactionBuilder7702}; - use alloy::rpc::types::Authorization; - use alloy::signers::k256::ecdsa::SigningKey; - use alloy::signers::local::PrivateKeySigner; - use alloy::signers::SignerSync; - use alloy::{consensus::constants::ETH_TO_WEI, rpc::types::TransactionRequest}; - - use revm::context::transaction::AuthorizationTr; - use revm::database::InMemoryDB; - use revm::inspector::NoOpInspector; - use revm::primitives::bytes; - - use crate::test_utils::{test_trevm_with_funds, LOG_BYTECODE}; - use crate::{EvmNeedsCfg, TrevmBuilder}; - use crate::{NoopBlock, NoopCfg}; - + use alloy::{ + network::{TransactionBuilder, TransactionBuilder7702}, + rpc::types::{Authorization, TransactionRequest}, + signers::SignerSync, + consensus::constants::ETH_TO_WEI, + }; + use revm::{ + context::transaction::AuthorizationTr, + database::InMemoryDB, + primitives::bytes, + }; + use crate::{ + test_utils::{test_trevm_with_funds, ALICE, BOB, LOG_BYTECODE}, + TrevmBuilder, NoopBlock, NoopCfg, + }; use super::*; - static ALICE: LazyLock = - LazyLock::new(|| PrivateKeySigner::from(SigningKey::from_slice(&[0x11; 32]).unwrap())); - static BOB: LazyLock = - LazyLock::new(|| PrivateKeySigner::from(SigningKey::from_slice(&[0x22; 32]).unwrap())); - - fn trevm_with_funds() -> EvmNeedsCfg { - test_trevm_with_funds(&[ - (ALICE.address(), U256::from(ETH_TO_WEI)), - (BOB.address(), U256::from(ETH_TO_WEI)), - ]) - } - #[test] fn test_estimate_gas_simple_transfer() { - let trevm = trevm_with_funds(); + let trevm = test_trevm_with_funds(&[ + (ALICE.address(), U256::from(ETH_TO_WEI)), + (BOB.address(), U256::from(ETH_TO_WEI)), + ]); let tx = TransactionRequest::default() .from(ALICE.address()) @@ -2394,7 +2382,7 @@ mod tests { assert!(estimation.is_success()); // The gas used should correspond to a simple transfer. - assert!(estimation.gas_used() == 21000); + assert_eq!(estimation.gas_used(), 21000); } #[test] @@ -2418,7 +2406,7 @@ mod tests { }; let signature = BOB.sign_hash_sync(&authorization.signature_hash()).unwrap(); let signed_authorization = authorization.into_signed(signature); - assert!(signed_authorization.authority().unwrap() == BOB.address()); + assert_eq!(signed_authorization.authority().unwrap(), BOB.address()); let tx = TransactionRequest::default() .from(ALICE.address()) @@ -2429,19 +2417,14 @@ mod tests { let (estimation, trevm) = trevm.fill_cfg(&NoopCfg).fill_block(&NoopBlock).fill_tx(&tx).estimate_gas().unwrap(); - dbg!(&estimation); assert!(estimation.is_success()); let tx = tx.with_gas_limit(estimation.limit()); - let mut output = trevm.clear_tx().fill_tx(&tx).run().unwrap().accept(); - - let bob_code = output.1.read_code(BOB.address()); - dbg!(&bob_code); + let output = trevm.clear_tx().fill_tx(&tx).run().unwrap().accept(); - dbg!(&output.0); assert!(output.0.is_success()); - assert!(output.0.logs().len() == 1); + assert_eq!(output.0.logs().len(), 1); } } diff --git a/src/test_utils.rs b/src/test_utils.rs index a2c3d7e..500219a 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -1,5 +1,7 @@ +use std::sync::LazyLock; + use crate::{helpers::Ctx, EvmNeedsCfg, Trevm}; -use alloy::primitives::{Address, U256}; +use alloy::{primitives::{Address, U256}, signers::{k256::ecdsa::SigningKey, local::PrivateKeySigner}}; use revm::{ bytecode::Bytecode, database::{CacheDB, EmptyDB, InMemoryDB, State}, @@ -13,8 +15,30 @@ use revm::{ }; /// LogContract bytecode +/// ``` +/// contract LogContract { +/// event Hello(); +/// event World(); +/// +/// function emitHello() public { +/// emit Hello(); +/// } +/// +/// function emitWorld() public { +/// emit World(); +/// } +/// } +/// ``` pub const LOG_BYTECODE: &str = "0x60806040526004361015610013575b6100ca565b61001d5f3561003c565b80637b3ab2d01461003757639ee1a4400361000e57610097565b610064565b60e01c90565b60405190565b5f80fd5b5f80fd5b5f91031261005a57565b61004c565b5f0190565b3461009257610074366004610050565b61007c6100ce565b610084610042565b8061008e8161005f565b0390f35b610048565b346100c5576100a7366004610050565b6100af610106565b6100b7610042565b806100c18161005f565b0390f35b610048565b5f80fd5b7fbcdfe0d5b27dd186282e187525415c57ea3077c34efb39148111e4d342e7ab0e6100f7610042565b806101018161005f565b0390a1565b7f2d67bb91f17bca05af6764ab411e86f4ddf757adb89fcec59a7d21c525d4171261012f610042565b806101398161005f565b0390a156fea2646970667358221220e22cd46ba129dcbd6f62f632cc862b0924d3f36c991fd0b45947581aa3010d6464736f6c634300081a0033"; + +/// Alice testing signer +pub static ALICE: LazyLock = + LazyLock::new(|| PrivateKeySigner::from(SigningKey::from_slice(&[0x11; 32]).unwrap())); +/// Bob testing signer +pub static BOB: LazyLock = + LazyLock::new(|| PrivateKeySigner::from(SigningKey::from_slice(&[0x22; 32]).unwrap())); + impl Trevm where Insp: Inspector>, From 579cd78125a4bdf3080ccff29f54ec8b8893a853 Mon Sep 17 00:00:00 2001 From: evalir Date: Wed, 17 Sep 2025 09:00:43 -0400 Subject: [PATCH 07/11] chore: patch bump --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 78436e4..97b9a2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trevm" -version = "0.27.8" +version = "0.27.9" rust-version = "1.83.0" edition = "2021" authors = ["init4"] From 78228e7f80f600c50c3e47190c9311205c304cf9 Mon Sep 17 00:00:00 2001 From: evalir Date: Wed, 17 Sep 2025 09:05:18 -0400 Subject: [PATCH 08/11] chore: correct runtime bytecode --- src/test_utils.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test_utils.rs b/src/test_utils.rs index 500219a..e1722b6 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -1,7 +1,10 @@ use std::sync::LazyLock; use crate::{helpers::Ctx, EvmNeedsCfg, Trevm}; -use alloy::{primitives::{Address, U256}, signers::{k256::ecdsa::SigningKey, local::PrivateKeySigner}}; +use alloy::{ + primitives::{Address, U256}, + signers::{k256::ecdsa::SigningKey, local::PrivateKeySigner}, +}; use revm::{ bytecode::Bytecode, database::{CacheDB, EmptyDB, InMemoryDB, State}, @@ -15,6 +18,7 @@ use revm::{ }; /// LogContract bytecode +/// This is the runtime bytecode. This should be set directly with ``set_bytecode_unchecked`` /// ``` /// contract LogContract { /// event Hello(); @@ -29,8 +33,7 @@ use revm::{ /// } /// } /// ``` -pub const LOG_BYTECODE: &str = "0x60806040526004361015610013575b6100ca565b61001d5f3561003c565b80637b3ab2d01461003757639ee1a4400361000e57610097565b610064565b60e01c90565b60405190565b5f80fd5b5f80fd5b5f91031261005a57565b61004c565b5f0190565b3461009257610074366004610050565b61007c6100ce565b610084610042565b8061008e8161005f565b0390f35b610048565b346100c5576100a7366004610050565b6100af610106565b6100b7610042565b806100c18161005f565b0390f35b610048565b5f80fd5b7fbcdfe0d5b27dd186282e187525415c57ea3077c34efb39148111e4d342e7ab0e6100f7610042565b806101018161005f565b0390a1565b7f2d67bb91f17bca05af6764ab411e86f4ddf757adb89fcec59a7d21c525d4171261012f610042565b806101398161005f565b0390a156fea2646970667358221220e22cd46ba129dcbd6f62f632cc862b0924d3f36c991fd0b45947581aa3010d6464736f6c634300081a0033"; - +pub const LOG_BYTECODE: &str = "0x6004361015600b575f80fd5b5f3560e01c80637b3ab2d014605f57639ee1a440146027575f80fd5b34605b575f366003190112605b577f2d67bb91f17bca05af6764ab411e86f4ddf757adb89fcec59a7d21c525d417125f80a1005b5f80fd5b34605b575f366003190112605b577fbcdfe0d5b27dd186282e187525415c57ea3077c34efb39148111e4d342e7ab0e5f80a100fea2646970667358221220f6b42b522bc9fb2b4c7d7e611c7c3e995d057ecab7fd7be4179712804c886b4f64736f6c63430008190033"; /// Alice testing signer pub static ALICE: LazyLock = From 37872bab37c758655a902903be4d3d114e42316c Mon Sep 17 00:00:00 2001 From: evalir Date: Wed, 17 Sep 2025 09:13:21 -0400 Subject: [PATCH 09/11] chore: doctests --- src/test_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test_utils.rs b/src/test_utils.rs index e1722b6..7c5fac0 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -19,7 +19,7 @@ use revm::{ /// LogContract bytecode /// This is the runtime bytecode. This should be set directly with ``set_bytecode_unchecked`` -/// ``` +/// ```no_run /// contract LogContract { /// event Hello(); /// event World(); From 5bcebdf6668d5b4ef88d06bed5bb19a3d1732a5a Mon Sep 17 00:00:00 2001 From: James Date: Wed, 17 Sep 2025 09:28:22 -0400 Subject: [PATCH 10/11] fix: bytes --- src/builder.rs | 9 +++++++++ src/evm.rs | 20 ++++++++++---------- src/test_utils.rs | 6 +++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 4138898..501e6a9 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -45,10 +45,19 @@ impl TrevmBuilder { } /// Set the inspector for the EVM. + /// + /// Equivalent to [`Self::with_inspector`]. pub fn with_insp(self, insp: OInsp) -> TrevmBuilder { TrevmBuilder { db: self.db, insp, spec: self.spec, precompiles: self.precompiles } } + /// Set the inspector for the EVM. + /// + /// Equivalent to [`Self::with_insp`]. + pub fn with_inspector(self, insp: OInsp) -> TrevmBuilder { + self.with_insp(insp) + } + /// Set the spec id for the EVM. pub const fn with_spec_id(mut self, spec: SpecId) -> Self { self.spec = spec; diff --git a/src/evm.rs b/src/evm.rs index c7f906a..574ca85 100644 --- a/src/evm.rs +++ b/src/evm.rs @@ -2348,22 +2348,21 @@ where #[cfg(test)] mod tests { + use super::*; + use crate::{ + test_utils::{test_trevm_with_funds, ALICE, BOB, LOG_DEPLOYED_BYTECODE}, + NoopBlock, NoopCfg, TrevmBuilder, + }; use alloy::{ + consensus::constants::ETH_TO_WEI, network::{TransactionBuilder, TransactionBuilder7702}, rpc::types::{Authorization, TransactionRequest}, signers::SignerSync, - consensus::constants::ETH_TO_WEI, }; use revm::{ - context::transaction::AuthorizationTr, - database::InMemoryDB, - primitives::bytes, - }; - use crate::{ - test_utils::{test_trevm_with_funds, ALICE, BOB, LOG_BYTECODE}, - TrevmBuilder, NoopBlock, NoopCfg, + context::transaction::AuthorizationTr, database::InMemoryDB, + inspector::inspectors::TracerEip3155, primitives::bytes, }; - use super::*; #[test] fn test_estimate_gas_simple_transfer() { @@ -2395,7 +2394,7 @@ mod tests { let mut trevm = TrevmBuilder::new().with_db(db).with_spec_id(SpecId::PRAGUE).build_trevm().unwrap(); let _ = trevm.test_set_balance(ALICE.address(), U256::from(ETH_TO_WEI)); - let _ = trevm.set_bytecode_unchecked(log_address, Bytecode::new_raw(LOG_BYTECODE.into())); + let _ = trevm.set_bytecode_unchecked(log_address, Bytecode::new_raw(LOG_DEPLOYED_BYTECODE)); // Bob will sign the authorization. let authorization = Authorization { @@ -2417,6 +2416,7 @@ mod tests { let (estimation, trevm) = trevm.fill_cfg(&NoopCfg).fill_block(&NoopBlock).fill_tx(&tx).estimate_gas().unwrap(); + dbg!(&estimation); assert!(estimation.is_success()); let tx = tx.with_gas_limit(estimation.limit()); diff --git a/src/test_utils.rs b/src/test_utils.rs index 7c5fac0..39b53a7 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -12,14 +12,14 @@ use revm::{ interpreter::{ CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, InterpreterTypes, }, - primitives::{hardfork::SpecId, Log}, + primitives::{bytes, hardfork::SpecId, Log}, state::AccountInfo, Context, Inspector, MainBuilder, }; /// LogContract bytecode /// This is the runtime bytecode. This should be set directly with ``set_bytecode_unchecked`` -/// ```no_run +/// ```ignore /// contract LogContract { /// event Hello(); /// event World(); @@ -33,7 +33,7 @@ use revm::{ /// } /// } /// ``` -pub const LOG_BYTECODE: &str = "0x6004361015600b575f80fd5b5f3560e01c80637b3ab2d014605f57639ee1a440146027575f80fd5b34605b575f366003190112605b577f2d67bb91f17bca05af6764ab411e86f4ddf757adb89fcec59a7d21c525d417125f80a1005b5f80fd5b34605b575f366003190112605b577fbcdfe0d5b27dd186282e187525415c57ea3077c34efb39148111e4d342e7ab0e5f80a100fea2646970667358221220f6b42b522bc9fb2b4c7d7e611c7c3e995d057ecab7fd7be4179712804c886b4f64736f6c63430008190033"; +pub const LOG_DEPLOYED_BYTECODE: alloy::primitives::Bytes = bytes!("6080604052348015600e575f80fd5b50600436106030575f3560e01c80637b3ab2d01460345780639ee1a44014603c575b5f80fd5b603a6044565b005b60426072565b005b7fbcdfe0d5b27dd186282e187525415c57ea3077c34efb39148111e4d342e7ab0e60405160405180910390a1565b7f2d67bb91f17bca05af6764ab411e86f4ddf757adb89fcec59a7d21c525d4171260405160405180910390a156fea2646970667358221220144b313f421e29c7119666392827595d05f3dc33d0ccb0e75314cc9180e4fb1f64736f6c634300081a0033"); /// Alice testing signer pub static ALICE: LazyLock = From aa8ee381f3c4c951159ccf57eb81f92c4f4953f7 Mon Sep 17 00:00:00 2001 From: evalir Date: Wed, 17 Sep 2025 09:32:22 -0400 Subject: [PATCH 11/11] chore: clippy / fmt --- src/evm.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/evm.rs b/src/evm.rs index 574ca85..cfeaf70 100644 --- a/src/evm.rs +++ b/src/evm.rs @@ -2359,10 +2359,7 @@ mod tests { rpc::types::{Authorization, TransactionRequest}, signers::SignerSync, }; - use revm::{ - context::transaction::AuthorizationTr, database::InMemoryDB, - inspector::inspectors::TracerEip3155, primitives::bytes, - }; + use revm::{context::transaction::AuthorizationTr, database::InMemoryDB, primitives::bytes}; #[test] fn test_estimate_gas_simple_transfer() { @@ -2416,7 +2413,6 @@ mod tests { let (estimation, trevm) = trevm.fill_cfg(&NoopCfg).fill_block(&NoopBlock).fill_tx(&tx).estimate_gas().unwrap(); - dbg!(&estimation); assert!(estimation.is_success()); let tx = tx.with_gas_limit(estimation.limit());