Skip to content

Commit c20f22a

Browse files
committed
chore: rename program names
ex proof_aggregator now is user_proots_aggregator and ex root_aggregator is now chunk_aggregator
1 parent 767122b commit c20f22a

17 files changed

+188
-187
lines changed

aggregation_mode/aggregation_programs/risc0/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ lambdaworks-crypto = { git = "https://github.com/lambdaclass/lambdaworks.git", r
1616
path = "./src/lib.rs"
1717

1818
[[bin]]
19-
name = "risc0_chunk_aggregator_program"
20-
path = "./src/chunk_aggregator_main.rs"
19+
name = "risc0_user_proofs_aggregator_program"
20+
path = "./src/user_proofs_aggregator_main.rs"
2121

2222
[[bin]]
23-
name = "risc0_root_aggregator_program"
24-
path = "./src/root_aggregator_main.rs"
23+
name = "risc0_chunk_aggregator_program"
24+
path = "./src/chunk_aggregator_main.rs"
Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,50 @@
11
#![no_main]
22

33
use lambdaworks_crypto::merkle_tree::merkle::MerkleTree;
4-
use risc0_aggregation_program::{ChunkAggregatorInput, Risc0ImageIdAndPubInputs};
4+
use risc0_aggregation_program::{ChunkAggregatorInput, Hash32};
55
use risc0_zkvm::guest::env;
66

77
risc0_zkvm::guest::entry!(main);
88

9+
// Generated with `make agg_mode_write_program_ids` and copied from program_ids.json
10+
pub const USER_PROOFS_AGGREGATOR_PROGRAM_IMAGE_ID: [u8; 32] = [
11+
83, 145, 39, 254, 127, 217, 146, 127, 63, 217, 69, 190, 11, 204, 170, 138, 215, 35, 175, 246,
12+
209, 154, 52, 243, 85, 37, 177, 147, 22, 153, 155, 156,
13+
];
14+
915
fn main() {
1016
let input = env::read::<ChunkAggregatorInput>();
1117

12-
for proof in &input.proofs_image_id_and_pub_inputs {
13-
env::verify(proof.image_id.clone(), &proof.public_inputs)
14-
.expect("proof to be verified correctly");
18+
let mut leaves: Vec<Hash32> = vec![];
19+
20+
for (proof, leaves_commitment) in input.proofs_and_leaves_commitment {
21+
let image_id = proof.image_id;
22+
23+
// Ensure the aggregated chunk originates from the L1 aggregation program.
24+
// This validation step guarantees that the proof was genuinely verified
25+
// by this program. Without this check, a different program using the
26+
// same public inputs could bypass verification.
27+
assert!(image_id == USER_PROOFS_AGGREGATOR_PROGRAM_IMAGE_ID);
28+
29+
// Ensure the committed root matches the root of the provided leaves
30+
let merkle_root: [u8; 32] = proof
31+
.public_inputs
32+
.clone()
33+
.try_into()
34+
.expect("Public input to be the chunk merkle root");
35+
36+
let leaves_commitment: Vec<Hash32> =
37+
leaves_commitment.into_iter().map(|el| Hash32(el)).collect();
38+
let merkle_tree = MerkleTree::<Hash32>::build(&leaves_commitment).unwrap();
39+
assert!(merkle_root == merkle_tree.root);
40+
41+
leaves.extend(leaves_commitment);
42+
43+
// finally verify the proof
44+
env::verify(image_id, &proof.public_inputs).expect("proof to be verified correctly");
1545
}
1646

17-
let merkle_tree =
18-
MerkleTree::<Risc0ImageIdAndPubInputs>::build(&input.proofs_image_id_and_pub_inputs)
19-
.unwrap();
47+
let merkle_tree = MerkleTree::<Hash32>::build(&leaves).unwrap();
2048

2149
env::commit_slice(&merkle_tree.root);
2250
}

aggregation_mode/aggregation_programs/risc0/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ impl IsMerkleTreeBackend for Hash32 {
114114
}
115115

116116
#[derive(Serialize, Deserialize)]
117-
pub struct ChunkAggregatorInput {
117+
pub struct UserProofsAggregatorInput {
118118
pub proofs_image_id_and_pub_inputs: Vec<Risc0ImageIdAndPubInputs>,
119119
}
120120

121121
#[derive(Serialize, Deserialize)]
122-
pub struct RootAggregatorInput {
122+
pub struct ChunkAggregatorInput {
123123
pub proofs_and_leaves_commitment: Vec<(Risc0ImageIdAndPubInputs, Vec<[u8; 32]>)>,
124124
}

aggregation_mode/aggregation_programs/risc0/src/root_aggregator_main.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![no_main]
2+
3+
use lambdaworks_crypto::merkle_tree::merkle::MerkleTree;
4+
use risc0_aggregation_program::{Risc0ImageIdAndPubInputs, UserProofsAggregatorInput};
5+
use risc0_zkvm::guest::env;
6+
7+
risc0_zkvm::guest::entry!(main);
8+
9+
fn main() {
10+
let input = env::read::<UserProofsAggregatorInput>();
11+
12+
for proof in &input.proofs_image_id_and_pub_inputs {
13+
env::verify(proof.image_id.clone(), &proof.public_inputs)
14+
.expect("proof to be verified correctly");
15+
}
16+
17+
let merkle_tree =
18+
MerkleTree::<Risc0ImageIdAndPubInputs>::build(&input.proofs_image_id_and_pub_inputs)
19+
.unwrap();
20+
21+
env::commit_slice(&merkle_tree.root);
22+
}

aggregation_mode/aggregation_programs/sp1/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ lambdaworks-crypto = { git = "https://github.com/lambdaclass/lambdaworks.git", r
1616
path = "./src/lib.rs"
1717

1818
[[bin]]
19-
name = "sp1_chunk_aggregator_program"
20-
path = "./src/chunk_aggregator_main.rs"
19+
name = "sp1_user_proofs_aggregator_program"
20+
path = "./src/user_proofs_aggregator_main.rs"
2121

2222
[[bin]]
23-
name = "sp1_root_aggregator_program"
24-
path = "./src/root_aggregator_main.rs"
23+
name = "sp1_chunk_aggregator_program"
24+
path = "./src/chunk_aggregator_main.rs"

aggregation_mode/aggregation_programs/sp1/src/chunk_aggregator_main.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,48 @@ sp1_zkvm::entrypoint!(main);
33

44
use lambdaworks_crypto::merkle_tree::merkle::MerkleTree;
55
use sha2::{Digest, Sha256};
6-
use sp1_aggregation_program::{ChunkAggregatorInput, SP1VkAndPubInputs};
6+
use sp1_aggregation_program::{ChunkAggregatorInput, Hash32};
7+
8+
// Generated with `make agg_mode_write_program_ids` and copied from program_ids.json
9+
pub const USER_PROOFS_AGGREGATOR_PROGRAM_VK_HASH: [u32; 8] = [
10+
1040333920, 1542570412, 411443120, 206151865, 190370181, 1775934843, 1568897572, 1219192306,
11+
];
712

813
pub fn main() {
914
let input = sp1_zkvm::io::read::<ChunkAggregatorInput>();
1015

16+
let mut leaves = vec![];
17+
1118
// Verify the proofs.
12-
for proof in input.proofs_vk_and_pub_inputs.iter() {
19+
for (proof, leaves_commitment) in input.proofs_and_leaves_commitment {
1320
let vkey = proof.vk;
14-
let public_values = &proof.public_inputs;
15-
let public_values_digest = Sha256::digest(public_values);
21+
let public_values_digest = Sha256::digest(&proof.public_inputs);
22+
23+
// Ensure the aggregated chunk originates from the L1 aggregation program.
24+
// This validation step guarantees that the proof was genuinely verified
25+
// by this program. Without this check, a different program using the
26+
// same public inputs could bypass verification.
27+
assert!(proof.vk == USER_PROOFS_AGGREGATOR_PROGRAM_VK_HASH);
28+
29+
let merkle_root: [u8; 32] = proof
30+
.public_inputs
31+
.clone()
32+
.try_into()
33+
.expect("Public input to be the hash of the chunk tree");
34+
35+
// Reconstruct the merkle tree and verify that the roots match
36+
let leaves_commitment: Vec<Hash32> =
37+
leaves_commitment.into_iter().map(|el| Hash32(el)).collect();
38+
let merkle_tree: MerkleTree<Hash32> = MerkleTree::build(&leaves_commitment).unwrap();
39+
assert!(merkle_tree.root == merkle_root);
40+
41+
leaves.extend(leaves_commitment);
1642

1743
sp1_zkvm::lib::verify::verify_sp1_proof(&vkey, &public_values_digest.into());
1844
}
1945

20-
let merkle_tree =
21-
MerkleTree::<SP1VkAndPubInputs>::build(&input.proofs_vk_and_pub_inputs).unwrap();
46+
// Finally, compute the final merkle root with all the leaves
47+
let merkle_tree: MerkleTree<Hash32> = MerkleTree::build(&leaves).unwrap();
2248

2349
sp1_zkvm::io::commit_slice(&merkle_tree.root);
2450
}

aggregation_mode/aggregation_programs/sp1/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ impl IsMerkleTreeBackend for Hash32 {
107107
}
108108

109109
#[derive(Serialize, Deserialize)]
110-
pub struct ChunkAggregatorInput {
110+
pub struct UserProofsAggregatorInput {
111111
pub proofs_vk_and_pub_inputs: Vec<SP1VkAndPubInputs>,
112112
}
113113

114114
#[derive(Serialize, Deserialize)]
115-
pub struct RootAggregatorInput {
115+
pub struct ChunkAggregatorInput {
116116
pub proofs_and_leaves_commitment: Vec<(SP1VkAndPubInputs, Vec<[u8; 32]>)>,
117117
}

aggregation_mode/aggregation_programs/sp1/src/root_aggregator_main.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![no_main]
2+
sp1_zkvm::entrypoint!(main);
3+
4+
use lambdaworks_crypto::merkle_tree::merkle::MerkleTree;
5+
use sha2::{Digest, Sha256};
6+
use sp1_aggregation_program::{SP1VkAndPubInputs, UserProofsAggregatorInput};
7+
8+
pub fn main() {
9+
let input = sp1_zkvm::io::read::<UserProofsAggregatorInput>();
10+
11+
// Verify the proofs.
12+
for proof in input.proofs_vk_and_pub_inputs.iter() {
13+
let vkey = proof.vk;
14+
let public_values = &proof.public_inputs;
15+
let public_values_digest = Sha256::digest(public_values);
16+
17+
sp1_zkvm::lib::verify::verify_sp1_proof(&vkey, &public_values_digest.into());
18+
}
19+
20+
let merkle_tree =
21+
MerkleTree::<SP1VkAndPubInputs>::build(&input.proofs_vk_and_pub_inputs).unwrap();
22+
23+
sp1_zkvm::io::commit_slice(&merkle_tree.root);
24+
}

0 commit comments

Comments
 (0)