-
Notifications
You must be signed in to change notification settings - Fork 199
fix(l1): use hash precompiles in eip8025 hash tree root #6549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<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. | ||
| /// | ||
|
|
@@ -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
|
||
|
|
||
| Ok(ProgramOutput { | ||
|
|
||
There was a problem hiding this comment.
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::sha256uses a software SHA-256 implementation. Consider rewording to clarify that this enables precompile-backed hashing when the providedCryptoimplementation supports it (e.g., zkVM targets).