diff --git a/crates/guest-program/src/l1/program.rs b/crates/guest-program/src/l1/program.rs index 2a51fafbf9..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; @@ -54,6 +57,18 @@ pub fn execution_program( }) } +/// 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 {