Skip to content

Commit 37be9e4

Browse files
JuArceMarcosNicolauMauroToscanoMechanix97
authored
feat: integrate sp1 verifier with aggregation mode (#1843)
Co-authored-by: Marcos Nicolau <[email protected]> Co-authored-by: MauroFab <[email protected]> Co-authored-by: Lucas Rack <[email protected]> Co-authored-by: Mauro Toscano <[email protected]> Co-authored-by: Marcos Nicolau <[email protected]>
1 parent 43a1084 commit 37be9e4

34 files changed

+2658
-2358
lines changed

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

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
branches: ["*"]
88
paths:
99
- "batcher/**"
10+
- "aggregation_mode/**"
1011
- ".github/workflows/build-rust.yml"
1112

1213
jobs:
@@ -22,6 +23,14 @@ jobs:
2223
toolchain: stable
2324
components: rustfmt, clippy
2425
override: true
26+
27+
# Reference: https://github.com/succinctlabs/sp1/actions/runs/8886659400/workflow#L61-L65
28+
- name: Install sp1 toolchain
29+
run: |
30+
curl -L https://sp1.succinct.xyz | bash
31+
source /home/runner/.bashrc
32+
~/.sp1/bin/sp1up
33+
2534
- name: Cache Rust dependencies
2635
uses: actions/cache@v3
2736
with:
@@ -32,27 +41,54 @@ jobs:
3241
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
3342
restore-keys: |
3443
${{ runner.os }}-rust-
35-
- name: Check formatting of Rust projects
44+
45+
- name: Check formatting of Batcher
3646
run: |
3747
cd batcher
3848
cargo fmt --all -- --check
39-
- name: Run Clippy
49+
50+
- name: Run Clippy on Batcher
4051
run: |
4152
cd batcher
4253
cargo clippy --all -- -D warnings
43-
- name: Build Rust projects
54+
55+
- name: Build Batcher
4456
run: |
4557
cd batcher
4658
cargo build --all
4759
60+
- name: Check formatting of AggregationMode
61+
run: |
62+
cd aggregation_mode
63+
cargo fmt --all -- --check
64+
65+
- name: Build AggregationMode # We build before clippy to generate the ELF
66+
run: |
67+
cd aggregation_mode
68+
cargo build --all
69+
70+
- name: Run Clippy on AggregationMode
71+
run: |
72+
cd aggregation_mode
73+
cargo clippy --all -- -D warnings
74+
4875
test:
4976
runs-on: aligned-runner
5077
needs: build
5178
steps:
5279
- name: Checkout code
5380
uses: actions/checkout@v4
81+
5482
- name: foundry-toolchain
5583
uses: foundry-rs/[email protected]
84+
85+
# Reference: https://github.com/succinctlabs/sp1/actions/runs/8886659400/workflow#L61-L65
86+
- name: Install sp1 toolchain
87+
run: |
88+
curl -L https://sp1.succinct.xyz | bash
89+
source /home/runner/.bashrc
90+
~/.sp1/bin/sp1up
91+
5692
- name: Cache Rust dependencies
5793
uses: actions/cache@v3
5894
with:
@@ -63,7 +99,13 @@ jobs:
6399
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
64100
restore-keys: |
65101
${{ runner.os }}-rust-
66-
- name: Run tests
102+
103+
- name: Run Batcher tests
67104
run: |
68105
cd batcher
69106
cargo test --all
107+
108+
- name: Run AggregationMode tests
109+
run: |
110+
cd aggregation_mode
111+
cargo test --all

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ anvil_deploy_eigen_contracts:
7575
@echo "Deploying Eigen Contracts..."
7676
. contracts/scripts/anvil/deploy_eigen_contracts.sh
7777

78+
anvil_deploy_sp1_contracts:
79+
@echo "Deploying SP1 Contracts..."
80+
. contracts/scripts/anvil/deploy_sp1_contracts.sh
81+
7882
anvil_deploy_aligned_contracts:
7983
@echo "Deploying Aligned Contracts..."
8084
. contracts/scripts/anvil/deploy_aligned_contracts.sh
@@ -152,7 +156,7 @@ anvil_start_with_block_time_with_more_prefunded_accounts:
152156

153157
__AGGREGATION_MODE__: ## ____
154158
start_proof_aggregator_local: ## Start the proof aggregator locally using Mock Verifier Contract
155-
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release -- config-files/config-proof-aggregator.yaml
159+
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release -- config-files/config-proof-aggregator-mock.yaml
156160

157161
start_proof_aggregator_local_with_proving: ## Start the proof aggregator locally using SP1 Verifier Contract
158162
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove -- config-files/config-proof-aggregator.yaml
@@ -694,6 +698,10 @@ upgrade_batcher_payment_service: ## Upgrade BatcherPayments contract. Parameters
694698
@echo "Upgrading BatcherPayments Contract on $(NETWORK) network..."
695699
@. contracts/scripts/.env.$(NETWORK) && . contracts/scripts/upgrade_batcher_payment_service.sh
696700

701+
deploy_proof_aggregator:
702+
@echo "Deploying ProofAggregator contract on $(NETWORK) network..."
703+
@. contracts/scripts/.env.$(NETWORK) && . contracts/scripts/deploy_proof_aggregator.sh
704+
697705
build_aligned_contracts:
698706
@cd contracts/src/core && forge build
699707

aggregation_mode/abi/AlignedProofAggregationService.json

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

aggregation_mode/src/aggregators/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
pub mod sp1_aggregator;
21
pub mod lib;
2+
pub mod sp1_aggregator;
33

44
use sp1_aggregator::{AlignedSP1VerificationError, SP1ProofWithPubValuesAndElf};
55
pub enum ZKVMEngine {
@@ -26,7 +26,11 @@ pub enum AlignedVerificationError {
2626
impl AlignedProof {
2727
pub fn verify(&self) -> Result<(), AlignedVerificationError> {
2828
match self {
29-
AlignedProof::SP1(proof) => sp1_aggregator::verify(proof).map_err(|arg0: sp1_aggregator::AlignedSP1VerificationError| AlignedVerificationError::Sp1(arg0)),
29+
AlignedProof::SP1(proof) => sp1_aggregator::verify(proof).map_err(
30+
|arg0: sp1_aggregator::AlignedSP1VerificationError| {
31+
AlignedVerificationError::Sp1(arg0)
32+
},
33+
),
3034
}
3135
}
3236
}

aggregation_mode/src/aggregators/sp1_aggregator.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ use sp1_sdk::{
66

77
use super::lib::{AggregatedProof, ProgramOutput, ProofAggregationError};
88

9-
const PROGRAM_ELF: &[u8] = include_bytes!("../../aggregation_programs/sp1/elf/sp1_aggregator_program");
9+
const PROGRAM_ELF: &[u8] =
10+
include_bytes!("../../aggregation_programs/sp1/elf/sp1_aggregator_program");
1011

1112
pub struct SP1ProofWithPubValuesAndElf {
1213
pub proof_with_pub_values: SP1ProofWithPublicValues,
13-
pub elf: Vec<u8>
14+
pub elf: Vec<u8>,
1415
}
1516

1617
impl SP1ProofWithPubValuesAndElf {
@@ -98,15 +99,23 @@ pub enum AlignedSP1VerificationError {
9899
UnsupportedProof,
99100
}
100101

101-
pub(crate) fn verify(sp1_proof_with_pub_values_and_elf: &SP1ProofWithPubValuesAndElf) -> Result<(), AlignedSP1VerificationError> {
102+
pub(crate) fn verify(
103+
sp1_proof_with_pub_values_and_elf: &SP1ProofWithPubValuesAndElf,
104+
) -> Result<(), AlignedSP1VerificationError> {
102105
let client = ProverClient::from_env();
103106

104107
let (_pk, vk) = client.setup(&sp1_proof_with_pub_values_and_elf.elf);
105108

106109
// only sp1 compressed proofs are supported for aggregation now
107-
match sp1_proof_with_pub_values_and_elf.proof_with_pub_values.proof {
110+
match sp1_proof_with_pub_values_and_elf
111+
.proof_with_pub_values
112+
.proof
113+
{
108114
sp1_sdk::SP1Proof::Compressed(_) => client
109-
.verify(&sp1_proof_with_pub_values_and_elf.proof_with_pub_values, &vk)
115+
.verify(
116+
&sp1_proof_with_pub_values_and_elf.proof_with_pub_values,
117+
&vk,
118+
)
110119
.map_err(AlignedSP1VerificationError::Verification),
111120
_ => Err(AlignedSP1VerificationError::UnsupportedProof),
112121
}

aggregation_mode/src/backend/fetcher.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use super::{
55
types::{AlignedLayerServiceManager, AlignedLayerServiceManagerContract, RPCProvider},
66
};
77
use crate::{
8-
aggregators::{sp1_aggregator::SP1ProofWithPubValuesAndElf, AlignedProof}, backend::s3::get_aligned_batch_from_s3
8+
aggregators::{sp1_aggregator::SP1ProofWithPubValuesAndElf, AlignedProof},
9+
backend::s3::get_aligned_batch_from_s3,
910
};
1011
use aligned_sdk::core::types::ProvingSystemId;
1112
use alloy::{
@@ -88,7 +89,10 @@ impl ProofsFetcher {
8889
ProvingSystemId::SP1 => {
8990
let elf = p.vm_program_code?;
9091
let proof_with_pub_values = bincode::deserialize(&p.proof).ok()?;
91-
let sp1_proof = SP1ProofWithPubValuesAndElf { proof_with_pub_values, elf };
92+
let sp1_proof = SP1ProofWithPubValuesAndElf {
93+
proof_with_pub_values,
94+
elf,
95+
};
9296

9397
Some(AlignedProof::SP1(sp1_proof))
9498
}

aggregation_mode/src/backend/merkle_tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pub fn compute_proofs_merkle_root(proofs: &[AlignedProof]) -> ([u8; 32], Vec<[u8
1818
root = root
1919
.chunks(2)
2020
.map(|chunk| match chunk {
21-
[a, b] => combine_hashes(&a, &b),
22-
[a] => combine_hashes(&a, &a),
21+
[a, b] => combine_hashes(a, b),
22+
[a] => combine_hashes(a, a),
2323
_ => panic!("Unexpected chunk size in leaves"),
2424
})
2525
.collect()

aggregation_mode/src/backend/mod.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use crate::aggregators::{
1111
};
1212

1313
use alloy::{
14-
consensus::{BlobTransactionSidecar},
14+
consensus::BlobTransactionSidecar,
1515
eips::eip4844::BYTES_PER_BLOB,
1616
hex,
1717
network::EthereumWallet,
18-
primitives::{Address},
18+
primitives::Address,
1919
providers::{PendingTransactionError, ProviderBuilder},
2020
rpc::types::TransactionReceipt,
2121
signers::local::LocalSigner,
@@ -81,11 +81,6 @@ impl ProofAggregator {
8181
}
8282
Err(err) => {
8383
error!("Error while aggregating and submitting proofs: {:?}", err);
84-
info!("About to set aggregated proof as missed");
85-
if let Err(err) = self.set_aggregated_proof_as_missed().await {
86-
error!("Error while marking proof as failed: {:?}", err);
87-
};
88-
info!("Proofs set as missed");
8984
}
9085
}
9186
}
@@ -99,7 +94,7 @@ impl ProofAggregator {
9994
.await
10095
.map_err(AggregatedProofSubmissionError::FetchingProofs)?;
10196

102-
if proofs.len() == 0 {
97+
if proofs.is_empty() {
10398
warn!("No proofs collected, skipping aggregation...");
10499
return Ok(());
105100
}
@@ -114,8 +109,8 @@ impl ProofAggregator {
114109
// only SP1 compressed proofs are supported
115110
let proofs = proofs
116111
.into_iter()
117-
.filter_map(|proof| match proof {
118-
AlignedProof::SP1(proof) => Some(proof),
112+
.map(|proof| match proof {
113+
AlignedProof::SP1(proof) => proof,
119114
})
120115
.collect();
121116

@@ -219,19 +214,4 @@ impl ProofAggregator {
219214

220215
Ok((blob, blob_versioned_hash))
221216
}
222-
223-
async fn set_aggregated_proof_as_missed(
224-
&self,
225-
) -> Result<TransactionReceipt, AggregatedProofSubmissionError> {
226-
let res = self
227-
.proof_aggregation_service
228-
.markCurrentAggregatedProofAsMissed()
229-
.send()
230-
.await
231-
.map_err(AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction)?;
232-
233-
res.get_receipt()
234-
.await
235-
.map_err(AggregatedProofSubmissionError::ReceiptError)
236-
}
237217
}

aggregation_mode/src/backend/s3.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub enum GetBatchProofsError {
66
Deserialization,
77
EmptyBody,
88
StatusFailed,
9-
ReqwestClientFailed
9+
ReqwestClientFailed,
1010
}
1111

1212
// needed to make S3 bucket work
@@ -16,11 +16,13 @@ pub async fn get_aligned_batch_from_s3(
1616
url: String,
1717
) -> Result<Vec<VerificationData>, GetBatchProofsError> {
1818
let client = reqwest::Client::builder()
19-
.user_agent(DEFAULT_USER_AGENT)
20-
.build()
21-
.map_err(|_| GetBatchProofsError::ReqwestClientFailed)?;
19+
.user_agent(DEFAULT_USER_AGENT)
20+
.build()
21+
.map_err(|_| GetBatchProofsError::ReqwestClientFailed)?;
2222

23-
let response = client.get(url).send()
23+
let response = client
24+
.get(url)
25+
.send()
2426
.await
2527
.map_err(|_| GetBatchProofsError::Fetching)?;
2628
if !response.status().is_success() {

aggregation_mode/src/backend/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::too_many_arguments)]
12
use alloy::{
23
network::EthereumWallet,
34
providers::{

0 commit comments

Comments
 (0)