From bc85623cf56fb8a00f97429951a5686a2f3b3693 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 20 Jan 2025 15:11:11 -0300 Subject: [PATCH 01/10] WIP Use levm when applying transactions --- crates/blockchain/payload.rs | 44 +++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/crates/blockchain/payload.rs b/crates/blockchain/payload.rs index 4eef04e677..b58b44af44 100644 --- a/crates/blockchain/payload.rs +++ b/crates/blockchain/payload.rs @@ -422,24 +422,32 @@ fn apply_plain_transaction( head: &HeadTransaction, context: &mut PayloadBuildContext, ) -> Result { - let result = execute_tx( - &head.tx, - &context.payload.header, - context.evm_state, - spec_id( - &context.chain_config().map_err(ChainError::from)?, - context.payload.header.timestamp, - ), - )?; - context.remaining_gas = context.remaining_gas.saturating_sub(result.gas_used()); - context.block_value += U256::from(result.gas_used()) * head.tip; - let receipt = Receipt::new( - head.tx.tx_type(), - result.is_success(), - context.payload.header.gas_limit - context.remaining_gas, - result.logs(), - ); - Ok(receipt) + #[cfg(feature = "levm")] + { + println!("USING LEVM",); + } + #[cfg(not(feature = "levm"))] + { + println!("NOT USING LEVM",); + let result = execute_tx( + &head.tx, + &context.payload.header, + context.evm_state, + spec_id( + &context.chain_config().map_err(ChainError::from)?, + context.payload.header.timestamp, + ), + )?; + context.remaining_gas = context.remaining_gas.saturating_sub(result.gas_used()); + context.block_value += U256::from(result.gas_used()) * head.tip; + let receipt = Receipt::new( + head.tx.tx_type(), + result.is_success(), + context.payload.header.gas_limit - context.remaining_gas, + result.logs(), + ); + Ok(receipt) + } } fn finalize_payload(context: &mut PayloadBuildContext) -> Result<(), StoreError> { From 8205e6ae92235a3893bd5b1137303d43d3aedef2 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 20 Jan 2025 16:05:05 -0300 Subject: [PATCH 02/10] WIP add levm vm --- crates/blockchain/payload.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/blockchain/payload.rs b/crates/blockchain/payload.rs index b58b44af44..3d0da22475 100644 --- a/crates/blockchain/payload.rs +++ b/crates/blockchain/payload.rs @@ -15,13 +15,15 @@ use ethrex_core::{ use ethrex_rlp::encode::RLPEncode; use ethrex_storage::{error::StoreError, Store}; use ethrex_vm::{ - beacon_root_contract_call, evm_state, execute_tx, get_state_transitions, process_withdrawals, - spec_id, EvmError, EvmState, SpecId, + beacon_root_contract_call, db::StoreWrapper, evm_state, execute_tx, execute_tx_levm, + get_state_transitions, process_withdrawals, spec_id, EvmError, EvmState, SpecId, }; use sha3::{Digest, Keccak256}; use ethrex_metrics::metrics; +use std::sync::Arc; + #[cfg(feature = "metrics")] use ethrex_metrics::metrics_transactions::{MetricsTxStatus, MetricsTxType, METRICS_TX}; @@ -425,6 +427,25 @@ fn apply_plain_transaction( #[cfg(feature = "levm")] { println!("USING LEVM",); + + let mut block_cache: CacheDB = HashMap::new(); + // let mut db = dB::default(); + + let store_wrapper = Arc::new(StoreWrapper { + store: context.evm_state.database().unwrap().clone(), + block_hash: context.payload.header.parent_hash, + }); + + let result = execute_tx_levm( + &head.tx, + &context.payload.header, + store_wrapper.clone(), + block_cache, + spec_id( + &context.chain_config().map_err(ChainError::from)?, + context.payload.header.timestamp, + ), + ); } #[cfg(not(feature = "levm"))] { From 7f2550de8d1e45944a5d84e88184962999407425 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 20 Jan 2025 16:26:34 -0300 Subject: [PATCH 03/10] WIP --- crates/blockchain/payload.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/blockchain/payload.rs b/crates/blockchain/payload.rs index 3d0da22475..83d4bd98f9 100644 --- a/crates/blockchain/payload.rs +++ b/crates/blockchain/payload.rs @@ -428,8 +428,7 @@ fn apply_plain_transaction( { println!("USING LEVM",); - let mut block_cache: CacheDB = HashMap::new(); - // let mut db = dB::default(); + let mut block_cache = HashMap::new(); let store_wrapper = Arc::new(StoreWrapper { store: context.evm_state.database().unwrap().clone(), @@ -445,7 +444,16 @@ fn apply_plain_transaction( &context.chain_config().map_err(ChainError::from)?, context.payload.header.timestamp, ), + ) + .map_err(EvmError::from)?; + + let receipt = Receipt::new( + head.tx.tx_type(), + result.is_success(), + context.payload.header.gas_limit - context.remaining_gas, + result.logs, ); + Ok(receipt) } #[cfg(not(feature = "levm"))] { From ff463fe3f13330a1e491105eaaab578d5e6253bf Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 20 Jan 2025 16:28:06 -0300 Subject: [PATCH 04/10] WIP: Remove mut from cache --- crates/blockchain/payload.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/blockchain/payload.rs b/crates/blockchain/payload.rs index 83d4bd98f9..0b7ceb27f6 100644 --- a/crates/blockchain/payload.rs +++ b/crates/blockchain/payload.rs @@ -428,7 +428,7 @@ fn apply_plain_transaction( { println!("USING LEVM",); - let mut block_cache = HashMap::new(); + let block_cache = HashMap::new(); let store_wrapper = Arc::new(StoreWrapper { store: context.evm_state.database().unwrap().clone(), From 9513f78d39636546962051217f620cf3b177b23f Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 20 Jan 2025 16:34:01 -0300 Subject: [PATCH 05/10] Add feature flag to cargo test --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index aef4dabb12..0364c9f9e6 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ SPECTEST_VECTORS_DIR := cmd/ef_tests/ethrex/vectors CRATE ?= * test: $(SPECTEST_VECTORS_DIR) ## 🧪 Run each crate's tests - cargo test -p '$(CRATE)' --workspace --exclude ethrex-prover --exclude ethrex-levm --exclude ef_tests-levm --exclude ethrex-l2 -- --skip test_contract_compilation + cargo test -p '$(CRATE)' --features levm --workspace --exclude ethrex-prover --exclude ethrex-levm --exclude ef_tests-levm --exclude ethrex-l2 -- --skip test_contract_compilation clean: clean-vectors ## 🧹 Remove build artifacts cargo clean From 17397749277c26e890f39a886e60e619fabeb006 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 20 Jan 2025 17:01:47 -0300 Subject: [PATCH 06/10] Add conditional uses --- crates/blockchain/payload.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/blockchain/payload.rs b/crates/blockchain/payload.rs index 0b7ceb27f6..73f70a03bd 100644 --- a/crates/blockchain/payload.rs +++ b/crates/blockchain/payload.rs @@ -14,16 +14,21 @@ use ethrex_core::{ }; use ethrex_rlp::encode::RLPEncode; use ethrex_storage::{error::StoreError, Store}; +#[cfg(feature = "levm")] +use ethrex_vm::{db::StoreWrapper, execute_tx_levm}; + +#[cfg(feature = "levm")] +use std::sync::Arc; + use ethrex_vm::{ - beacon_root_contract_call, db::StoreWrapper, evm_state, execute_tx, execute_tx_levm, - get_state_transitions, process_withdrawals, spec_id, EvmError, EvmState, SpecId, + beacon_root_contract_call, evm_state, execute_tx, get_state_transitions, process_withdrawals, + spec_id, EvmError, EvmState, SpecId, }; + use sha3::{Digest, Keccak256}; use ethrex_metrics::metrics; -use std::sync::Arc; - #[cfg(feature = "metrics")] use ethrex_metrics::metrics_transactions::{MetricsTxStatus, MetricsTxType, METRICS_TX}; From b437fd6baf0727cc5b7bc5dad805b58f2e44d7c1 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 20 Jan 2025 17:05:02 -0300 Subject: [PATCH 07/10] Remove debug prints --- crates/blockchain/payload.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/blockchain/payload.rs b/crates/blockchain/payload.rs index 73f70a03bd..0bc78c632f 100644 --- a/crates/blockchain/payload.rs +++ b/crates/blockchain/payload.rs @@ -431,8 +431,6 @@ fn apply_plain_transaction( ) -> Result { #[cfg(feature = "levm")] { - println!("USING LEVM",); - let block_cache = HashMap::new(); let store_wrapper = Arc::new(StoreWrapper { @@ -462,7 +460,6 @@ fn apply_plain_transaction( } #[cfg(not(feature = "levm"))] { - println!("NOT USING LEVM",); let result = execute_tx( &head.tx, &context.payload.header, From 368eea52ae4dd768168c301f78f15436fbce1a33 Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 20 Jan 2025 17:42:24 -0300 Subject: [PATCH 08/10] Restore order --- crates/blockchain/payload.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/blockchain/payload.rs b/crates/blockchain/payload.rs index 0bc78c632f..403f004a91 100644 --- a/crates/blockchain/payload.rs +++ b/crates/blockchain/payload.rs @@ -20,9 +20,12 @@ use ethrex_vm::{db::StoreWrapper, execute_tx_levm}; #[cfg(feature = "levm")] use std::sync::Arc; +#[cfg(not(feature = "levm"))] +use ethrex_vm::execute_tx; + use ethrex_vm::{ - beacon_root_contract_call, evm_state, execute_tx, get_state_transitions, process_withdrawals, - spec_id, EvmError, EvmState, SpecId, + beacon_root_contract_call, evm_state, get_state_transitions, process_withdrawals, spec_id, + EvmError, EvmState, SpecId, }; use sha3::{Digest, Keccak256}; @@ -458,6 +461,7 @@ fn apply_plain_transaction( ); Ok(receipt) } + #[cfg(not(feature = "levm"))] { let result = execute_tx( From a87cff8c8ffcc34a90fcf359df39c90310fc89ca Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Mon, 20 Jan 2025 17:47:29 -0300 Subject: [PATCH 09/10] Add comment saying explicitely that its REVM --- crates/blockchain/payload.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/blockchain/payload.rs b/crates/blockchain/payload.rs index 403f004a91..6b171fd7a9 100644 --- a/crates/blockchain/payload.rs +++ b/crates/blockchain/payload.rs @@ -462,6 +462,7 @@ fn apply_plain_transaction( Ok(receipt) } + // REVM Implementation #[cfg(not(feature = "levm"))] { let result = execute_tx( From c801c4ec639250499364ee168f24048c7b0861fe Mon Sep 17 00:00:00 2001 From: Tomas Fabrizio Orsi Date: Tue, 21 Jan 2025 09:24:43 -0300 Subject: [PATCH 10/10] Remove features flag --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0364c9f9e6..aef4dabb12 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ SPECTEST_VECTORS_DIR := cmd/ef_tests/ethrex/vectors CRATE ?= * test: $(SPECTEST_VECTORS_DIR) ## 🧪 Run each crate's tests - cargo test -p '$(CRATE)' --features levm --workspace --exclude ethrex-prover --exclude ethrex-levm --exclude ef_tests-levm --exclude ethrex-l2 -- --skip test_contract_compilation + cargo test -p '$(CRATE)' --workspace --exclude ethrex-prover --exclude ethrex-levm --exclude ef_tests-levm --exclude ethrex-l2 -- --skip test_contract_compilation clean: clean-vectors ## 🧹 Remove build artifacts cargo clean