Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions crates/guest-program/src/l1/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -54,6 +57,18 @@ pub fn execution_program(
})
}

/// Wrapper to pass Crypto into libssz_merkle::hash_tree_root,
/// so hashing is computed by precompiles
Comment on lines +60 to +61
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on this wrapper implies hashing will be computed by precompiles, but in native builds Crypto::sha256 uses a software SHA-256 implementation. Consider rewording to clarify that this enables precompile-backed hashing when the provided Crypto implementation supports it (e.g., zkVM targets).

Suggested change
/// Wrapper to pass Crypto into libssz_merkle::hash_tree_root,
/// so hashing is computed by precompiles
/// Wrapper to pass `Crypto` into `libssz_merkle::hash_tree_root`,
/// enabling precompile-backed hashing when the provided `Crypto`
/// implementation supports it (for example, on zkVM targets).

Copilot uses AI. Check for mistakes.
#[cfg(feature = "eip-8025")]
struct CryptoWrapper(Arc<dyn Crypto>);

#[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.
///
Expand All @@ -64,13 +79,13 @@ pub fn execution_program(
bytes: &[u8],
crypto: Arc<dyn Crypto>,
) -> Result<ProgramOutput, ExecutionError> {
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();
Comment on lines +88 to 89
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes NewPayloadRequest root computation depend on the provided Crypto implementation. There’s currently no test that would fail if hash_tree_root accidentally reverted to using Sha2Hasher/a native hasher. Consider adding a unit test (under cfg(all(test, feature = "eip-8025"))) with a small custom Crypto impl overriding sha256 (e.g., counting calls or returning a distinctive value) to assert the hasher passed into hash_tree_root is actually used.

Copilot uses AI. Check for mistakes.

Ok(ProgramOutput {
Expand Down
Loading