Skip to content

Commit 4487597

Browse files
committed
Merge and fix sp1
2 parents 5afbf67 + 5607821 commit 4487597

File tree

60 files changed

+1297
-202
lines changed

Some content is hidden

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

60 files changed

+1297
-202
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.lock

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

aggregation_mode/Cargo.toml

Lines changed: 9 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"
@@ -17,6 +16,7 @@ tokio = { version = "1", features = ["time"]}
1716
sha3 = "0.10.8"
1817
reqwest = { version = "0.12" }
1918
ciborium = "=0.2.2"
19+
lambdaworks-crypto = { git = "https://github.com/lambdaclass/lambdaworks.git", rev = "5f8f2cfcc8a1a22f77e8dff2d581f1166eefb80b", features = ["serde"]}
2020
# Necessary for the VerificationData type
2121
aligned-sdk = { path = "../batcher/aligned-sdk/" }
2222
# zkvms
@@ -41,3 +41,11 @@ opt-level = 3
4141
default = []
4242
prove = []
4343
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/Cargo.lock

Lines changed: 112 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aggregation_mode/aggregation_programs/risc0/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ serde_json = "1.0.117"
1010
# Unstable feature is necessary for tiny-keccak patch, see: https://dev.risczero.com/api/zkvm/precompiles#stability
1111
risc0-zkvm = { git = "https://github.com/risc0/risc0", tag="v2.0.0", default-features = false, features = ["unstable", "std"] }
1212
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
13+
lambdaworks-crypto = { git = "https://github.com/lambdaclass/lambdaworks.git", rev = "5f8f2cfcc8a1a22f77e8dff2d581f1166eefb80b", features = ["serde"]}
1314

1415
[lib]
1516
path = "./src/lib.rs"

aggregation_mode/aggregation_programs/risc0/src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use lambdaworks_crypto::merkle_tree::traits::IsMerkleTreeBackend;
12
use serde::{Deserialize, Serialize};
23
use tiny_keccak::{Hasher, Keccak};
34

@@ -21,6 +22,35 @@ impl Risc0ImageIdAndPubInputs {
2122
}
2223
}
2324

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
35+
impl IsMerkleTreeBackend for Risc0ImageIdAndPubInputs {
36+
type Data = Risc0ImageIdAndPubInputs;
37+
type Node = [u8; 32];
38+
39+
fn hash_data(leaf: &Self::Data) -> Self::Node {
40+
leaf.commitment()
41+
}
42+
43+
fn hash_new_parent(child_1: &Self::Node, child_2: &Self::Node) -> Self::Node {
44+
let mut hasher = Keccak::v256();
45+
hasher.update(child_1);
46+
hasher.update(child_2);
47+
48+
let mut hash = [0u8; 32];
49+
hasher.finalize(&mut hash);
50+
hash
51+
}
52+
}
53+
2454
#[derive(Serialize, Deserialize)]
2555
pub struct Input {
2656
pub proofs_image_id_and_pub_inputs: Vec<Risc0ImageIdAndPubInputs>,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![no_main]
2+
3+
use lambdaworks_crypto::merkle_tree::merkle::MerkleTree;
4+
use risc0_aggregation_program::{Input, Risc0ImageIdAndPubInputs};
5+
use risc0_zkvm::guest::env;
6+
7+
risc0_zkvm::guest::entry!(main);
8+
9+
fn main() {
10+
let input = env::read::<Input>();
11+
12+
for Risc0ImageIdAndPubInputs {
13+
image_id,
14+
public_inputs,
15+
} in &input.proofs_image_id_and_pub_inputs
16+
{
17+
env::verify(image_id.clone(), &public_inputs).expect("proof to be verified correctly");
18+
}
19+
20+
let merkle_tree: MerkleTree<Risc0ImageIdAndPubInputs> =
21+
MerkleTree::build(&input.proofs_image_id_and_pub_inputs).unwrap();
22+
23+
env::commit_slice(&merkle_tree.root);
24+
}

aggregation_mode/aggregation_programs/sp1/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ sha2 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", tag = "sha2-v
1010
sha3 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", tag = "sha3-v0.10.8-patch-v1" }
1111
serde = { version = "1.0.203", features = ["derive"] }
1212
serde_json = "1.0.117"
13+
lambdaworks-crypto = { git = "https://github.com/lambdaclass/lambdaworks.git", rev = "5f8f2cfcc8a1a22f77e8dff2d581f1166eefb80b", features = ["serde"]}
1314

1415
[lib]
1516
path = "./src/lib.rs"
1617

1718
[[bin]]
1819
name = "sp1_chunk_aggregator_program"
19-
path = "./bin/chunk_aggregator.rs"
20+
path = "./src/chunk_aggregator_main.rs"
2021

2122
[[bin]]
2223
name = "sp1_root_aggregator_program"
23-
path = "./bin/root_aggregator.rs"
24+
path = "./src/root_aggregator_main.rs"

aggregation_mode/aggregation_programs/sp1/bin/chunk_aggregator.rs renamed to aggregation_mode/aggregation_programs/sp1/src/chunk_aggregator_main.rs

File renamed without changes.

0 commit comments

Comments
 (0)