Skip to content

Commit a0aa4af

Browse files
committed
feat: prove feature to not run prover locally
1 parent 4aa0e46 commit a0aa4af

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

aggregation-mode/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "proof_aggregator"
33
version = "0.1.0"
44
edition = "2021"
55

6+
67
[dependencies]
78
sp1-sdk = "4.1.3"
89
sp1_aggregator = { path = "./zkvm/sp1/" }
@@ -12,8 +13,12 @@ tracing = { version = "0.1", features = ["log"] }
1213
tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }
1314

1415
[build-dependencies]
15-
sp1-build = "4.1.3"
16+
sp1-build = { version = "4.1.3" }
1617

1718
[profile.release]
1819
opt-level = 3
1920
lto = true
21+
22+
[features]
23+
prove = []
24+

aggregation-mode/src/aggregator/sp1.rs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
use sp1_aggregator::SP1CompressedProof;
2-
use sp1_sdk::{ProverClient, SP1ProofWithPublicValues, SP1Stdin, SP1VerifyingKey};
2+
use sp1_sdk::{ProverClient, SP1ProofMode, SP1ProofWithPublicValues, SP1Stdin, SP1VerifyingKey};
33

44
use super::interface::{AggregatedProof, AggregatedVerificationError, ProgramOutput};
55

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

88
pub struct SP1AggregatedProof {
9-
proof: SP1ProofWithPublicValues,
10-
vk: SP1VerifyingKey,
9+
pub proof: SP1ProofWithPublicValues,
10+
pub vk: SP1VerifyingKey,
1111
}
1212

1313
pub(crate) fn aggregate_proofs(
1414
proofs: Vec<SP1CompressedProof>,
1515
) -> Result<ProgramOutput, AggregatedVerificationError> {
16+
#[cfg(feature = "prove")]
17+
{
18+
prove(proofs)
19+
}
20+
// If not in prove mode, execute the program and create a mock proof
21+
#[cfg(not(feature = "prove"))]
22+
{
23+
mock_prove(proofs)
24+
}
25+
}
26+
27+
#[cfg(feature = "prove")]
28+
fn prove(proofs: Vec<SP1CompressedProof>) -> Result<ProgramOutput, AggregatedVerificationError> {
1629
let mut stdin = SP1Stdin::new();
1730
stdin.write(&proofs);
1831

@@ -33,3 +46,29 @@ pub(crate) fn aggregate_proofs(
3346

3447
Ok(output)
3548
}
49+
50+
fn mock_prove(
51+
proofs: Vec<SP1CompressedProof>,
52+
) -> Result<ProgramOutput, AggregatedVerificationError> {
53+
let mut stdin = SP1Stdin::new();
54+
stdin.write(&proofs);
55+
56+
let client = ProverClient::from_env();
57+
let (pk, vk) = client.setup(PROGRAM_ELF);
58+
let (public_vales, _) = client
59+
.execute(PROGRAM_ELF, &stdin)
60+
.run()
61+
.map_err(|_| AggregatedVerificationError::SP1Proving)?;
62+
63+
let output = ProgramOutput::new(AggregatedProof::SP1(SP1AggregatedProof {
64+
proof: SP1ProofWithPublicValues::create_mock_proof(
65+
&pk,
66+
public_vales,
67+
SP1ProofMode::Groth16,
68+
"",
69+
),
70+
vk,
71+
}));
72+
73+
Ok(output)
74+
}

0 commit comments

Comments
 (0)