Skip to content

Commit 1ebcd5e

Browse files
committed
Merge branch 'staging' into feat/verify-agg-proof-on-chain
2 parents 1b69227 + 0eab47e commit 1ebcd5e

File tree

44 files changed

+577
-66
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+577
-66
lines changed

Makefile

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,18 @@ is_aggregator_set:
166166
exit 1; \
167167
fi
168168

169-
start_proof_aggregator_dev: is_aggregator_set ## Starts proof aggregator with mock proofs (DEV mode)
170-
AGGREGATOR=$(AGGREGATOR) RISC0_DEV_MODE=1 cargo run --manifest-path ./aggregation_mode/Cargo.toml --release -- config-files/config-proof-aggregator-mock.yaml
169+
reset_last_aggregated_block:
170+
@echo "Resetting last aggregated block..."
171+
@echo '{"last_aggregated_block":0}' > config-files/proof-aggregator.last_aggregated_block.json
171172

172-
start_proof_aggregator: is_aggregator_set ## Starts proof aggregator with proving activated
173-
AGGREGATOR=$(AGGREGATOR) cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove -- config-files/config-proof-aggregator.yaml
173+
start_proof_aggregator_dev: is_aggregator_set reset_last_aggregated_block ## Starts proof aggregator with mock proofs (DEV mode)
174+
AGGREGATOR=$(AGGREGATOR) RISC0_DEV_MODE=1 cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin proof_aggregator -- config-files/config-proof-aggregator-mock.yaml
174175

175-
start_proof_aggregator_gpu: is_aggregator_set ## Starts proof aggregator with proving + GPU acceleration (CUDA)
176-
AGGREGATOR=$(AGGREGATOR) SP1_PROVER=cuda cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove,gpu -- config-files/config-proof-aggregator.yaml
176+
start_proof_aggregator: is_aggregator_set reset_last_aggregated_block ## Starts proof aggregator with proving activated
177+
AGGREGATOR=$(AGGREGATOR) cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove --bin proof_aggregator -- config-files/config-proof-aggregator.yaml
178+
179+
start_proof_aggregator_gpu: is_aggregator_set reset_last_aggregated_block ## Starts proof aggregator with proving + GPU acceleration (CUDA)
180+
AGGREGATOR=$(AGGREGATOR) SP1_PROVER=cuda cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove,gpu --bin proof_aggregator -- config-files/config-proof-aggregator.yaml
177181

178182
verify_aggregated_proof_sp1_holesky_stage:
179183
@echo "Verifying SP1 in aggregated proofs on holesky..."
@@ -200,7 +204,11 @@ verify_aggregated_proof_risc0_holesky_stage:
200204
--rpc_url https://ethereum-holesky-rpc.publicnode.com
201205

202206
install_aggregation_mode: ## Install the aggregation mode with proving enabled
203-
cargo install --path aggregation_mode --features prove
207+
cargo install --path aggregation_mode --features prove,gpu --bin proof_aggregator
208+
209+
agg_mode_write_program_ids: ## Write proof aggregator zkvm programs ids
210+
@cd aggregation_mode && \
211+
cargo run --release --bin write_program_image_id_vk_hash
204212

205213
_AGGREGATOR_:
206214

@@ -568,6 +576,11 @@ batcher_send_burst_groth16: batcher/target/release/aligned
568576
@mkdir -p scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs
569577
@./batcher/aligned/send_burst_tasks.sh $(BURST_SIZE) $(START_COUNTER)
570578

579+
batcher_send_proof_with_random_address:
580+
@cd batcher/aligned/ && ./send_proof_with_random_address.sh
581+
582+
batcher_send_burst_with_random_address:
583+
@cd batcher/aligned/ && ./send_burst_with_random_address.sh
571584

572585
__TASK_SENDER__:
573586
BURST_TIME_SECS ?= 3

aggregation_mode/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name = "proof_aggregator"
33
version = "0.1.0"
44
edition = "2021"
55

6-
76
[dependencies]
87
serde = { version = "1.0.203", features = ["derive"] }
98
serde_json = "1.0.117"
@@ -42,3 +41,11 @@ opt-level = 3
4241
default = []
4342
prove = []
4443
gpu = ["risc0-zkvm/cuda"]
44+
45+
[[bin]]
46+
name = "proof_aggregator"
47+
path = "./src/main.rs"
48+
49+
[[bin]]
50+
name = "write_program_image_id_vk_hash"
51+
path = "./bin/write_program_image_id_vk_hash.rs"

aggregation_mode/abi/AlignedProofAggregationService.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

aggregation_mode/aggregation_programs/risc0/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ impl Risc0ImageIdAndPubInputs {
2222
}
2323
}
2424

25+
// Note: this MerkleTreeBackend is defined in three locations
26+
// - aggregation_mode/src/aggregators/mod.rs
27+
// - aggregation_mode/src/aggregators/risc0_aggregator.rs
28+
// - aggregation_mode/src/aggregators/sp1_aggregator.rs
29+
// All 3 implementations should match
30+
// The definition on aggregator/mod.rs supports taking proofs from both Risc0 and SP1,
31+
// Additionally, a version that takes the leaves as already hashed data is defined on:
32+
// - batcher/aligned-sdk/src/sdk/aggregation.rs
33+
// This one is used in the SDK since,
34+
// the user may not have access to the proofs that he didn't submit
2535
impl IsMerkleTreeBackend for Risc0ImageIdAndPubInputs {
2636
type Data = Risc0ImageIdAndPubInputs;
2737
type Node = [u8; 32];

aggregation_mode/aggregation_programs/sp1/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ impl SP1VkAndPubInputs {
1919
}
2020
}
2121

22+
// Note: this MerkleTreeBackend is defined in three locations
23+
// - aggregation_mode/src/aggregators/mod.rs
24+
// - aggregation_mode/src/aggregators/risc0_aggregator.rs and
25+
// - aggregation_mode/src/aggregators/sp1_aggregator.rs
26+
// All 3 implementations should match
27+
// The definition on aggregator/mod.rs supports taking proofs from both Risc0 and SP1,
28+
// Additionally, a version that takes the leaves as already hashed data is defined on:
29+
// - batcher/aligned-sdk/src/sdk/aggregation.rs
30+
// This one is used in the SDK since
31+
// the user may not have access to the proofs that they didn't submit
2232
impl IsMerkleTreeBackend for SP1VkAndPubInputs {
2333
type Data = SP1VkAndPubInputs;
2434
type Node = [u8; 32];
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use alloy::hex::hex;
2+
use proof_aggregator::aggregators::{
3+
risc0_aggregator::RISC0_AGGREGATOR_PROGRAM_ID_BYTES, sp1_aggregator,
4+
};
5+
use serde_json::json;
6+
use sp1_sdk::HashableKey;
7+
use std::{env, fs, path::Path};
8+
use tracing::info;
9+
use tracing_subscriber::FmtSubscriber;
10+
11+
const SP1_PROGRAM_ELF: &[u8] =
12+
include_bytes!("../aggregation_programs/sp1/elf/sp1_aggregator_program");
13+
14+
include!(concat!(env!("OUT_DIR"), "/methods.rs"));
15+
16+
fn main() {
17+
let subscriber = FmtSubscriber::builder().finish();
18+
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
19+
20+
info!("About to write sp1 programs vk hash bytes + risc0 programs image id bytes");
21+
let sp1_vk_hash = sp1_aggregator::vk_from_elf(SP1_PROGRAM_ELF).bytes32_raw();
22+
let risc0_image_id_bytes = RISC0_AGGREGATOR_PROGRAM_ID_BYTES;
23+
24+
let sp1_vk_hash_hex = hex::encode(sp1_vk_hash);
25+
let risc0_image_id_hex = hex::encode(risc0_image_id_bytes);
26+
27+
let dest_path = Path::new("programs_ids.json");
28+
29+
let json_data = json!({
30+
"sp1_vk_hash": format!("0x{}", sp1_vk_hash_hex),
31+
"risc0_image_id": format!("0x{}", risc0_image_id_hex),
32+
});
33+
34+
// Write to the file
35+
fs::write(dest_path, serde_json::to_string_pretty(&json_data).unwrap()).unwrap();
36+
37+
info!("Program ids written to {:?}", dest_path);
38+
}

aggregation_mode/build.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1+
use risc0_build::{DockerOptionsBuilder, GuestOptionsBuilder};
2+
use std::collections::HashMap;
3+
4+
// Reference: https://docs.succinct.xyz/docs/sp1/writing-programs/compiling#advanced-build-options-1
15
fn main() {
26
sp1_build::build_program_with_args("./aggregation_programs/sp1", {
37
sp1_build::BuildArgs {
48
output_directory: Some("./aggregation_programs/sp1/elf".to_string()),
9+
// We use Docker to generate a reproducible ELF that will be identical across all platforms
10+
// (https://docs.succinct.xyz/docs/sp1/writing-programs/compiling#production-builds)
11+
docker: true,
512
..Default::default()
613
}
714
});
815

9-
risc0_build::embed_methods();
16+
// With this containerized build process, we ensure that all builds of the guest code,
17+
// regardless of the machine or local environment, will produce the same ImageID
18+
let docker_options = DockerOptionsBuilder::default().build().unwrap();
19+
// Reference: https://github.com/risc0/risc0/blob/main/risc0/build/src/config.rs#L73-L90
20+
let guest_options = GuestOptionsBuilder::default()
21+
.use_docker(docker_options)
22+
.build()
23+
.unwrap();
24+
risc0_build::embed_methods_with_options(HashMap::from([(
25+
"risc0_aggregation_program",
26+
guest_options,
27+
)]));
1028
}

aggregation_mode/programs_ids.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"risc0_image_id": "0xa2966b3e63b5e73848dd3fb8ff1e03ac68ca10fa961ca0c0d8dbbb0a85b60acd",
3+
"sp1_vk_hash": "0x00eb8139c8360fc371b9a6decdec55ba01aaae0f4739f68139e0b3d40397d1d6"
4+
}

aggregation_mode/src/aggregators/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ impl AlignedProof {
125125
}
126126
}
127127

128+
/// Merkle tree commitment for aligned proofs.
129+
///
130+
/// Each leaf node (representing a proof) is committed by hashing:
131+
/// — The program id: the verification key hash in SP1 or the image ID in RISC Zero
132+
/// — Public inputs.
133+
///
134+
/// Intermediate nodes in the tree are formed by computing the keccak pairs of child nodes.
135+
// Note: this MerkleTreeBackend is defined in three locations
136+
// - aggregation_mode/src/aggregators/mod.rs
137+
// - aggregation_mode/src/aggregators/risc0_aggregator.rs
138+
// - aggregation_mode/src/aggregators/sp1_aggregator.rs
139+
// All 3 implementations should match
140+
// The definition on aggregator/mod.rs supports taking proofs from both Risc0 and SP1,
141+
// Additionally, a version that takes the leaves as already hashed data is defined on:
142+
// - batcher/aligned-sdk/src/sdk/aggregation.rs
143+
// This one is used in the SDK since,
144+
// the user may not have access to the proofs that he didn't submit
128145
impl IsMerkleTreeBackend for AlignedProof {
129146
type Data = AlignedProof;
130147
type Node = [u8; 32];

aggregation_mode/src/aggregators/risc0_aggregator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use risc0_zkvm::{default_prover, ExecutorEnv, ProverOpts, Receipt};
44
use sha3::{Digest, Keccak256};
55

66
/// Byte representation of the aggregator image_id, converted from `[u32; 8]` to `[u8; 32]`.
7-
const RISC0_AGGREGATOR_PROGRAM_ID_BYTES: [u8; 32] = {
7+
pub const RISC0_AGGREGATOR_PROGRAM_ID_BYTES: [u8; 32] = {
88
let mut res = [0u8; 32];
99
let mut i = 0;
1010
while i < 8 {

0 commit comments

Comments
 (0)