Skip to content

Commit 9da4e06

Browse files
committed
feat: correctly read the public inputs of the user proof aggregator program in zisk chunk aggregator
1 parent 30c310c commit 9da4e06

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

aggregation_mode/proof_aggregator/aggregation_programs/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/proof_aggregator/aggregation_programs/zisk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ lambdaworks-crypto = { git = "https://github.com/lambdaclass/lambdaworks.git", r
1313
ziskos = { git = "https://github.com/0xPolygonHermez/zisk.git", tag = "v0.15.0" }
1414
proofman-verifier = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", tag = "v0.15.0" }
1515
bincode = "1.3.3"
16+
bytemuck = "1.23.2"
1617

1718
[patch.crates-io]
1819
sha2 = { git = "https://github.com/0xPolygonHermez/zisk-patch-hashes.git", tag = "patch-sha2-0.10.9-zisk-0.15.0" }

aggregation_mode/proof_aggregator/aggregation_programs/zisk/src/chunk_aggregator_main.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use lambdaworks_crypto::merkle_tree::merkle::MerkleTree;
55
use zisk_aggregation_program::{ChunkAggregatorInput, Hash32};
66

77
// Generated with `make proof_aggregator_write_program_ids` and copied from program_ids.json
8-
pub const USER_PROOFS_AGGREGATOR_PROGRAM_VK_HASH: [u8; 32] = [0u8; 32];
8+
pub const USER_PROOFS_AGGREGATOR_PROGRAM_VK_HASH: [u8; 32] = [
9+
86, 146, 102, 198, 206, 75, 142, 66, 123, 251, 236, 150, 2, 205, 75, 142, 237, 255, 93, 54, 2,
10+
16, 190, 188, 246, 3, 188, 241, 235, 64, 220, 228,
11+
];
912

1013
pub fn main() {
1114
let input = ziskos::read_input_slice();
@@ -21,12 +24,30 @@ pub fn main() {
2124
// same public inputs could bypass verification.
2225
assert!(proof.vk.clone() == USER_PROOFS_AGGREGATOR_PROGRAM_VK_HASH);
2326

24-
let merkle_root: [u8; 32] = proof
25-
.proof
26-
.clone()
27+
let proof_words = bytemuck::cast_slice::<u8, u64>(&proof.proof);
28+
29+
// Reading public inputs as done in the verify of the lib at https://github.com/0xPolygonHermez/zisk/blob/maint/checkouts/pil2-proofman-3d49384e4e2f0af7/78497c5/verifier/src/verifier.rs#L66-L73
30+
let mut p = 0;
31+
let n_public_inputs = proof_words[p];
32+
p += 1;
33+
34+
// we should end up with a vector of length 4 as the public input is a 256 bits digest
35+
let mut publics = Vec::new();
36+
for _ in 0..n_public_inputs {
37+
publics.push(proof_words[p]);
38+
p += 1;
39+
}
40+
41+
let merkle_root_words: [u64; 4] = publics
2742
.try_into()
2843
.expect("Public input to be the hash of the chunk tree");
2944

45+
let mut merkle_root = [0u8; 32];
46+
for (idx, word) in merkle_root_words.iter().enumerate() {
47+
let start = idx * 8;
48+
merkle_root[start..start + 8].copy_from_slice(&word.to_le_bytes());
49+
}
50+
3051
// Reconstruct the merkle tree and verify that the roots match
3152
let leaves_commitment: Vec<Hash32> = leaves_commitment.into_iter().map(Hash32).collect();
3253
let merkle_tree: MerkleTree<Hash32> = MerkleTree::build(&leaves_commitment).unwrap();

0 commit comments

Comments
 (0)