Skip to content

Commit 0b5f8a8

Browse files
committed
Merge branch 'feat/aggregation-mode-risc0' into feat/aggregation-mode-risc0-contracts
2 parents ef4419f + 5e43630 commit 0b5f8a8

File tree

14 files changed

+930
-136
lines changed

14 files changed

+930
-136
lines changed

.github/workflows/build-and-test-rust.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ jobs:
3131
source /home/runner/.bashrc
3232
~/.sp1/bin/sp1up
3333
34+
- name: Install risc0 toolchain
35+
run: |
36+
curl -L https://risczero.com/install | bash
37+
source /home/runner/.bashrc
38+
/home/runner/.risc0/bin/rzup install
39+
3440
- name: Cache Rust dependencies
3541
uses: actions/cache@v3
3642
with:
@@ -70,7 +76,8 @@ jobs:
7076
- name: Run Clippy on AggregationMode
7177
run: |
7278
cd aggregation_mode
73-
cargo clippy --all -- -D warnings
79+
# We need to skip the build as clippy does not support the riscv32im-risc0-zkvm-elf target
80+
RISC0_SKIP_BUILD=1 cargo clippy --all -- -D warnings
7481
7582
test:
7683
runs-on: aligned-runner
@@ -89,6 +96,12 @@ jobs:
8996
source /home/runner/.bashrc
9097
~/.sp1/bin/sp1up
9198
99+
- name: Install risc0 toolchain
100+
run: |
101+
curl -L https://risczero.com/install | bash
102+
source /home/runner/.bashrc
103+
/home/runner/.risc0/bin/rzup install
104+
92105
- name: Cache Rust dependencies
93106
uses: actions/cache@v3
94107
with:

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ is_aggregator_set:
162162
exit 1; \
163163
fi
164164

165-
start_proof_aggregator_local: is_aggregator_set ## Start the proof aggregator locally using Mock Verifier Contract
165+
start_proof_aggregator_dev: is_aggregator_set ## Starts proof aggregator with mock proofs (DEV mode)
166166
RISC0_DEV_MODE=1 cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features $(AGGREGATOR) -- config-files/config-proof-aggregator-mock.yaml
167167

168-
start_proof_aggregator_local_with_proving: is_aggregator_set ## Start the proof aggregator locally using SP1 Verifier Contract
168+
start_proof_aggregator: is_aggregator_set ## Starts proof aggregator with proving activated
169169
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove,$(AGGREGATOR) -- config-files/config-proof-aggregator.yaml
170170

171-
start_proof_aggregator_local_with_proving_gpu: is_aggregator_set ## Start the proof aggregator locally using SP1 Verifier Contract
171+
start_proof_aggregator_gpu: is_aggregator_set ## Starts proof aggregator with proving + GPU acceleration (CUDA)
172172
SP1_PROVER=cuda cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove,gpu,$(AGGREGATOR) -- config-files/config-proof-aggregator.yaml
173173

174174
_AGGREGATOR_:
@@ -713,11 +713,11 @@ deploy_proof_aggregator:
713713
@. contracts/scripts/.env.$(NETWORK) && . contracts/scripts/deploy_proof_aggregator.sh
714714

715715
build_aligned_contracts:
716-
@cd contracts/src/core && forge build
716+
@cd contracts/src/core && forge build --via-ir
717717

718718
show_aligned_error_codes:
719719
@echo "\nAlignedLayerServiceManager errors:"
720-
@cd contracts && forge inspect src/core/IAlignedLayerServiceManager.sol:IAlignedLayerServiceManager errors
720+
@cd contracts && forge inspect src/core/IAligedLayerServiceManager.sol:IAlignedLayerServiceManager errors
721721
@echo "\nBatcherPaymentService errors:"
722722
@cd contracts && forge inspect src/core/BatcherPaymentService.sol:BatcherPaymentService errors
723723

aggregation_mode/README.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
21
# Aligned aggregation mode
32

43
## How to run it locally
54

65
1. Deploy aligned contracts on anvil:
76

87
```shell
9-
make deploy_aligned_contracts
8+
make anvil_deploy_risc0_contracts
9+
make anvil_deploy_sp1_contracts
10+
make anvil_deploy_aligned_contracts
1011
```
1112

1213
2. Start anvil:
1314

1415
```shell
15-
make anvil_start_with_block_time
16+
make anvil_start
1617
```
1718

1819
3. Start batcher
@@ -21,26 +22,39 @@ make anvil_start_with_block_time
2122
make start_batcher_local
2223
```
2324

24-
4. Send SP1 proofs:
25+
4. Send SP1/Risc0 proofs:
2526

2627
```shell
2728
make batcher_send_sp1_burst
29+
make batcher_send_risc0_burst
2830
```
2931

32+
Notes:
33+
34+
- For SP1 only `compressed` proofs are supported
35+
- For Risc0 both `succinct` and `composite` proofs are supported.
36+
3037
5. Start proof aggregator:
3138

3239
```shell
3340
# This will not run a real prover but a mocked one see below to run a real prover
34-
make start_proof_aggregator_local
41+
make start_proof_aggregator_dev AGGREGATOR="sp1|risc0"
3542
```
3643

3744
or
3845

3946
```shell
40-
make start_proof_aggregator_local_with_proving
47+
make start_proof_aggregator AGGREGATOR="sp1|risc0"
4148
```
4249

43-
Note: Proving can be quite slow without GPUs
50+
Notes:
51+
52+
- Stark2Snark is only supported for x86 architecture in Risc0, so you won't be able to run the risc0 aggregator on Apple Silicon.
53+
- Proving can be quite slow without GPUs, to activate gpu run:
54+
55+
```shell
56+
make start_proof_aggregator_gpu AGGREGATOR="sp1|risc0"
57+
```
4458

4559
### Check the logs
4660

aggregation_mode/src/aggregators/lib.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{
2-
risc0_aggregator::{self, Risc0AggregationInput, Risc0ProofReceiptAndImageId},
3-
sp1_aggregator::{self, SP1AggregationInput, SP1ProofWithPubValuesAndElf},
2+
risc0_aggregator::{Risc0AggregationInput, Risc0ProofReceiptAndImageId},
3+
sp1_aggregator::{SP1AggregationInput, SP1ProofWithPubValuesAndElf},
44
};
55

66
pub enum ProgramInput {
@@ -9,8 +9,8 @@ pub enum ProgramInput {
99
}
1010

1111
pub enum AggregatedProof {
12-
SP1(SP1ProofWithPubValuesAndElf),
13-
Risc0(Risc0ProofReceiptAndImageId),
12+
SP1(Box<SP1ProofWithPubValuesAndElf>),
13+
Risc0(Box<Risc0ProofReceiptAndImageId>),
1414
}
1515

1616
pub struct ProgramOutput {
@@ -30,10 +30,3 @@ pub enum ProofAggregationError {
3030
Risc0Proving(String),
3131
UnsupportedProof,
3232
}
33-
34-
pub fn aggregate_proofs(input: ProgramInput) -> Result<ProgramOutput, ProofAggregationError> {
35-
match input {
36-
ProgramInput::SP1(input) => sp1_aggregator::aggregate_proofs(input),
37-
ProgramInput::Risc0(input) => risc0_aggregator::aggregate_proofs(input),
38-
}
39-
}

aggregation_mode/src/aggregators/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ impl ZKVMEngine {
3939
}
4040

4141
pub enum AlignedProof {
42-
SP1(SP1ProofWithPubValuesAndElf),
43-
Risc0(Risc0ProofReceiptAndImageId),
42+
SP1(Box<SP1ProofWithPubValuesAndElf>),
43+
Risc0(Box<Risc0ProofReceiptAndImageId>),
4444
}
4545

4646
impl AlignedProof {

aggregation_mode/src/aggregators/risc0_aggregator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl Risc0ProofReceiptAndImageId {
3333
impl Risc0ProofReceiptAndImageId {
3434
pub fn hash_image_id_and_public_inputs(&self) -> [u8; 32] {
3535
let mut hasher = Keccak256::new();
36-
hasher.update(&self.image_id);
36+
hasher.update(self.image_id);
3737
hasher.update(self.public_inputs());
3838
hasher.finalize().into()
3939
}
@@ -88,7 +88,7 @@ pub(crate) fn aggregate_proofs(
8888
receipt,
8989
};
9090

91-
Ok(ProgramOutput::new(AggregatedProof::Risc0(output)))
91+
Ok(ProgramOutput::new(AggregatedProof::Risc0(output.into())))
9292
}
9393

9494
#[derive(Debug)]

aggregation_mode/src/aggregators/sp1_aggregator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub(crate) fn aggregate_proofs(
9292
elf: PROGRAM_ELF.to_vec(),
9393
};
9494

95-
let output = ProgramOutput::new(AggregatedProof::SP1(proof_and_elf));
95+
let output = ProgramOutput::new(AggregatedProof::SP1(proof_and_elf.into()));
9696

9797
Ok(output)
9898
}

aggregation_mode/src/backend/fetcher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl ProofsFetcher {
119119
elf,
120120
};
121121

122-
Some(AlignedProof::SP1(sp1_proof))
122+
Some(AlignedProof::SP1(sp1_proof.into()))
123123
}
124124

125125
_ => None,
@@ -138,7 +138,7 @@ impl ProofsFetcher {
138138
let receipt = Receipt::new(inner_receipt, public_inputs);
139139
let risc0_proof = Risc0ProofReceiptAndImageId { image_id, receipt };
140140

141-
Some(AlignedProof::Risc0(risc0_proof))
141+
Some(AlignedProof::Risc0(risc0_proof.into()))
142142
}
143143
_ => None,
144144
})

aggregation_mode/src/backend/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl ProofAggregator {
118118
let proofs = proofs
119119
.into_iter()
120120
.filter_map(|proof| match proof {
121-
AlignedProof::SP1(proof) => Some(proof),
121+
AlignedProof::SP1(proof) => Some(*proof),
122122
_ => None,
123123
})
124124
.collect();
@@ -135,7 +135,7 @@ impl ProofAggregator {
135135
let proofs = proofs
136136
.into_iter()
137137
.filter_map(|proof| match proof {
138-
AlignedProof::Risc0(proof) => Some(proof),
138+
AlignedProof::Risc0(proof) => Some(*proof),
139139
_ => None,
140140
})
141141
.collect();

0 commit comments

Comments
 (0)