Skip to content

Commit bcab0d1

Browse files
committed
feat: load local proofs and add to proof aggregator
1 parent 8885b02 commit bcab0d1

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

aggregation-mode/src/backend/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub struct ProofAggregator {
4646
pub struct Config {
4747
pub rpc_url: String,
4848
pub private_key: String,
49+
pub submit_proofs_every_secs: u64,
50+
pub max_proofs_in_queue: u16,
4951
}
5052

5153
impl ProofAggregator {
@@ -59,8 +61,8 @@ impl ProofAggregator {
5961

6062
Self {
6163
engine: ZKVMEngine::SP1,
62-
submit_proof_every_secs: 10,
63-
max_proofs_in_queue: 2,
64+
submit_proof_every_secs: config.submit_proofs_every_secs,
65+
max_proofs_in_queue: config.max_proofs_in_queue,
6466
proofs_queue: vec![],
6567
proof_aggregation_service,
6668
}

aggregation-mode/src/main.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,46 @@
1-
use proof_aggregator::backend::{Config, ProofAggregator};
1+
use std::fs;
2+
3+
use proof_aggregator::{
4+
backend::{Config, ProofAggregator},
5+
zk::{
6+
backends::sp1::{vk_from_elf, SP1Proof},
7+
Proof,
8+
},
9+
};
10+
use sp1_sdk::SP1ProofWithPublicValues;
211
use tracing_subscriber::FmtSubscriber;
312

413
#[tokio::main]
514
async fn main() {
615
let subscriber = FmtSubscriber::builder().finish();
716
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
817

18+
let proofs_to_push = 2;
19+
920
// TODO read proof aggregator yaml config file
1021
let config = Config {
1122
private_key: "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6".into(),
1223
rpc_url: "http://localhost:8545".into(),
24+
max_proofs_in_queue: proofs_to_push,
25+
submit_proofs_every_secs: 2,
1326
};
1427
let mut proof_aggregator = ProofAggregator::new(config);
1528

16-
// TODO read proofs from fs
17-
// proof_aggregator.add_proof(proof)
29+
for _ in 0..proofs_to_push {
30+
let sp1_proof =
31+
SP1ProofWithPublicValues::load("../scripts/test_files/sp1/sp1_fibonacci_4_1_3.proof")
32+
.expect("loading proof failed");
33+
let proof_elf =
34+
fs::read("../scripts/test_files/sp1/sp1_fibonacci_4_1_3.elf").expect("elf bytes");
35+
let proof = Proof::SP1(SP1Proof {
36+
proof: sp1_proof,
37+
vk: vk_from_elf(&proof_elf),
38+
});
39+
40+
proof_aggregator
41+
.add_proof(proof, &proof_elf)
42+
.expect("Proof to be valid");
43+
}
1844

1945
proof_aggregator.start().await;
2046
}

aggregation-mode/src/zk/backends/sp1.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,9 @@ pub(crate) fn verify(sp1_proof: &SP1Proof, elf: &[u8]) -> Result<(), SP1Verifica
105105
_ => Err(SP1VerificationError::UnsupportedProof),
106106
}
107107
}
108+
109+
pub fn vk_from_elf(elf: &[u8]) -> SP1VerifyingKey {
110+
let prover = ProverClient::builder().cpu().build();
111+
let (_, vk) = prover.setup(elf);
112+
vk
113+
}

0 commit comments

Comments
 (0)