Skip to content

Commit 051c882

Browse files
committed
refactor: move files around more
1 parent 943b83d commit 051c882

File tree

6 files changed

+42
-37
lines changed

6 files changed

+42
-37
lines changed

aggregation-mode/src/zk/interface/aggregator.rs renamed to aggregation-mode/src/zk/aggregator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ impl ProgramOutput {
2626
}
2727

2828
#[derive(Debug)]
29-
pub enum AggregatedVerificationError {
29+
pub enum ProofAggregationError {
3030
SP1Verification(sp1_sdk::SP1VerificationError),
3131
SP1Proving,
3232
}
3333

34-
pub fn aggregate_proofs(input: ProgramInput) -> Result<ProgramOutput, AggregatedVerificationError> {
34+
pub fn aggregate_proofs(input: ProgramInput) -> Result<ProgramOutput, ProofAggregationError> {
3535
match input {
3636
ProgramInput::SP1(input) => sp1::aggregate_proofs(input),
3737
}
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
use sp1_sdk::{Prover, ProverClient, SP1ProofWithPublicValues, SP1Stdin, SP1VerifyingKey};
22

3-
use crate::zk::interface::aggregator::{
4-
AggregatedProof, AggregatedVerificationError, ProgramOutput,
5-
};
3+
use crate::zk::aggregator::{AggregatedProof, ProgramOutput, ProofAggregationError};
64

75
const PROGRAM_ELF: &[u8] = include_bytes!("../../../zkvm/sp1/elf/sp1_aggregator_program");
86

97
// TODO lock prover
108

119
pub struct SP1Proof {
1210
pub elf: Vec<u8>,
13-
pub proof: Vec<u8>,
11+
pub proof: SP1ProofWithPublicValues,
12+
}
13+
14+
impl SP1Proof {
15+
pub fn verifying_key(&self) -> SP1VerifyingKey {
16+
let client = ProverClient::from_env();
17+
let (_pk, vk) = client.setup(&self.elf);
18+
vk
19+
}
1420
}
1521

1622
pub struct SP1AggregatedProof {
@@ -20,7 +26,7 @@ pub struct SP1AggregatedProof {
2026

2127
pub(crate) fn aggregate_proofs(
2228
input: sp1_aggregator::Input,
23-
) -> Result<ProgramOutput, AggregatedVerificationError> {
29+
) -> Result<ProgramOutput, ProofAggregationError> {
2430
let mut stdin = SP1Stdin::new();
2531
stdin.write(&input);
2632

@@ -35,12 +41,12 @@ pub(crate) fn aggregate_proofs(
3541
.prove(&pk, &stdin)
3642
.groth16()
3743
.run()
38-
.map_err(|_| AggregatedVerificationError::SP1Proving)?;
44+
.map_err(|_| ProofAggregationError::SP1Proving)?;
3945

4046
// a sanity check, vm already performs it
4147
client
4248
.verify(&proof, &vk)
43-
.map_err(AggregatedVerificationError::SP1Verification)?;
49+
.map_err(ProofAggregationError::SP1Verification)?;
4450

4551
let proof = SP1AggregatedProof { proof, vk };
4652

@@ -51,19 +57,13 @@ pub(crate) fn aggregate_proofs(
5157

5258
pub enum SP1VerificationError {
5359
Verification(sp1_sdk::SP1VerificationError),
54-
DecodeProofBinary,
5560
}
5661

5762
pub(crate) fn verify(proof: &SP1Proof) -> Result<(), SP1VerificationError> {
5863
let client = ProverClient::from_env();
5964

6065
let (_pk, vk) = client.setup(&proof.elf);
61-
62-
if let Ok(proof) = bincode::deserialize(&proof.proof) {
63-
client
64-
.verify(&proof, &vk)
65-
.map_err(SP1VerificationError::Verification)
66-
} else {
67-
Err(SP1VerificationError::DecodeProofBinary)
68-
}
66+
client
67+
.verify(&proof.proof, &vk)
68+
.map_err(SP1VerificationError::Verification)
6969
}

aggregation-mode/src/zk/interface/mod.rs

Lines changed: 0 additions & 2 deletions
This file was deleted.

aggregation-mode/src/zk/interface/verifier.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

aggregation-mode/src/zk/mod.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
1+
pub mod aggregator;
12
mod backends;
2-
pub mod interface;
3+
4+
use backends::sp1::{self, SP1Proof, SP1VerificationError};
5+
6+
pub enum ZKVMEngine {
7+
SP1,
8+
}
9+
10+
pub enum Proof {
11+
SP1(SP1Proof),
12+
}
13+
14+
pub enum VerificationError {
15+
SP1(SP1VerificationError),
16+
}
17+
18+
impl Proof {
19+
pub fn verify(&self) -> Result<(), VerificationError> {
20+
match self {
21+
Proof::SP1(proof) => sp1::verify(proof).map_err(VerificationError::SP1),
22+
}
23+
}
24+
}

aggregation-mode/zkvm/sp1/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use sha2::{Digest, Sha256};
33

44
#[derive(Serialize, Deserialize)]
55
pub struct SP1CompressedProof {
6-
vk: Vec<u8>,
6+
pub vk: Vec<u8>,
77
pub public_inputs: Vec<u8>,
88
}
99

0 commit comments

Comments
 (0)