From 95cd3b80a7c505e224160fbd06b4d1e5b4bfa6fd Mon Sep 17 00:00:00 2001 From: benbencik Date: Wed, 29 Apr 2026 11:05:01 +0200 Subject: [PATCH 1/2] fix(l1): use crypto hash precompiles in hash_tree_root --- crates/guest-program/src/l1/program.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/guest-program/src/l1/program.rs b/crates/guest-program/src/l1/program.rs index 2a51fafbf9..8c61e30b0c 100644 --- a/crates/guest-program/src/l1/program.rs +++ b/crates/guest-program/src/l1/program.rs @@ -26,7 +26,7 @@ pub fn execution_program( blocks, execution_witness, } = input; - + let BatchExecutionResult { receipts: _, initial_state_hash, @@ -44,7 +44,7 @@ pub fn execution_program( }, crypto.clone(), )?; - + Ok(ProgramOutput { initial_state_hash, final_state_hash, @@ -54,6 +54,21 @@ pub fn execution_program( }) } +#[cfg(feature = "eip-8025")] +use libssz_merkle::Sha256Hasher; + +/// Wrapper to pass Crypto into libssz_merkle::hash_tree_root, +/// so hashing is computed by precompiles +#[cfg(feature = "eip-8025")] +struct CryptoWrapper(Arc); + +#[cfg(feature = "eip-8025")] +impl Sha256Hasher for CryptoWrapper { + fn hash(&self, data: &[u8]) -> [u8; 32] { + self.0.sha256(data) + } +} + /// Decode and execute the L1 stateless validation program from EIP-8025 wire /// bytes. /// @@ -64,13 +79,13 @@ pub fn execution_program( bytes: &[u8], crypto: Arc, ) -> Result { - use libssz_merkle::{HashTreeRoot, Sha2Hasher}; + use libssz_merkle::HashTreeRoot; let (new_payload_request, execution_witness) = super::decode_eip8025(bytes).map_err(|err| { ExecutionError::Internal(format!("failed to decode EIP-8025 input: {err}")) })?; - let request_root = new_payload_request.hash_tree_root(&Sha2Hasher); + let request_root = new_payload_request.hash_tree_root(&CryptoWrapper(crypto.clone())); let valid = validate_eip8025_execution(&new_payload_request, execution_witness, crypto).is_ok(); Ok(ProgramOutput { From 5ae7679059bfbb60dd5f6b2454c5f90073b87eb6 Mon Sep 17 00:00:00 2001 From: benbencik Date: Wed, 29 Apr 2026 15:44:01 +0200 Subject: [PATCH 2/2] style(l1): fmt --- crates/guest-program/src/l1/program.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/guest-program/src/l1/program.rs b/crates/guest-program/src/l1/program.rs index 8c61e30b0c..ad6a10a99d 100644 --- a/crates/guest-program/src/l1/program.rs +++ b/crates/guest-program/src/l1/program.rs @@ -10,6 +10,9 @@ use crate::l1::output::ProgramOutput; use ethrex_common::types::ELASTICITY_MULTIPLIER; use ethrex_vm::Evm; +#[cfg(feature = "eip-8025")] +use libssz_merkle::Sha256Hasher; + #[cfg(not(feature = "eip-8025"))] use crate::common::BatchExecutionResult; @@ -26,7 +29,7 @@ pub fn execution_program( blocks, execution_witness, } = input; - + let BatchExecutionResult { receipts: _, initial_state_hash, @@ -44,7 +47,7 @@ pub fn execution_program( }, crypto.clone(), )?; - + Ok(ProgramOutput { initial_state_hash, final_state_hash, @@ -54,10 +57,7 @@ pub fn execution_program( }) } -#[cfg(feature = "eip-8025")] -use libssz_merkle::Sha256Hasher; - -/// Wrapper to pass Crypto into libssz_merkle::hash_tree_root, +/// Wrapper to pass Crypto into libssz_merkle::hash_tree_root, /// so hashing is computed by precompiles #[cfg(feature = "eip-8025")] struct CryptoWrapper(Arc);