Skip to content

Commit c674b3b

Browse files
committed
feat: merkle tree hash with keccak
1 parent 6ffb456 commit c674b3b

File tree

6 files changed

+32
-3
lines changed

6 files changed

+32
-3
lines changed

aggregation-mode/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aggregation-mode/zkvm/Cargo.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aggregation-mode/zkvm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ members = ["sp1"]
99
serde = { version = "1.0.203", features = ["derive"] }
1010
serde_json = "1.0.117"
1111
sha2 = "0.10.8"
12+
sha3 = "0.10.8"

aggregation-mode/zkvm/sp1/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ sp1-zkvm = { version = "4.1.3", features = ["verify"] }
99
serde = { workspace = true }
1010
serde_json = { workspace = true }
1111
sha2 = { workspace = true }
12+
sha3 = { workspace = true }
1213

1314
[patch.crates-io]
1415
sha2 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", tag = "sha2-v0.10.8-patch-v1" }
16+
sha3 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", tag = "sha3-v0.10.8-patch-v1" }
1517

1618
[lib]
1719
path = "./src/lib.rs"

aggregation-mode/zkvm/sp1/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use serde::{Deserialize, Serialize};
2-
use sha2::{Digest, Sha256};
2+
use sha3::{Digest, Keccak256};
33

44
#[derive(Serialize, Deserialize)]
55
pub struct SP1CompressedProof {
@@ -21,7 +21,7 @@ impl SP1CompressedProof {
2121
}
2222

2323
pub fn hash(&self) -> [u8; 32] {
24-
let mut hasher = Sha256::new();
24+
let mut hasher = Keccak256::new();
2525
hasher.update(&self.vk);
2626
hasher.update(&self.public_inputs);
2727
hasher.finalize().into()
@@ -44,4 +44,5 @@ impl Proof {
4444
#[derive(Serialize, Deserialize)]
4545
pub struct Input {
4646
pub proofs: Vec<Proof>,
47+
pub merkle_root: [u8; 32],
4748
}

aggregation-mode/zkvm/sp1/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
sp1_zkvm::entrypoint!(main);
33

44
use sha2::{Digest, Sha256};
5+
use sha3::Keccak256;
56
use sp1_aggregator::{Input, Proof};
67

78
fn combine_hashes(hash_a: &[u8; 32], hash_b: &[u8; 32]) -> [u8; 32] {
8-
let mut hasher = Sha256::new();
9+
let mut hasher = Keccak256::new();
910
hasher.update(hash_a);
1011
hasher.update(hash_b);
1112
hasher.finalize().into()
@@ -53,5 +54,8 @@ pub fn main() {
5354
}
5455

5556
let merkle_root = compute_merkle_root(&input.proofs);
57+
58+
assert_eq!(merkle_root, input.merkle_root);
59+
5660
sp1_zkvm::io::commit_slice(&merkle_root);
5761
}

0 commit comments

Comments
 (0)