Skip to content

Commit 154f7f6

Browse files
authored
feat: verifier crate checks vk root (#1085)
* works * groth cleanup * also do plonk * refac * reuse verifier_vks * cleanup; * fmt and clipy
1 parent c8354d8 commit 154f7f6

File tree

20 files changed

+187
-141
lines changed

20 files changed

+187
-141
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/prover/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ license = { workspace = true }
88
repository = { workspace = true }
99
keywords = { workspace = true }
1010
categories = { workspace = true }
11-
exclude = ["src/vk_map.bin"]
1211

1312
[dependencies]
1413
sp1-recursion-compiler = { workspace = true }

crates/prover/build.rs

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

crates/prover/release.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ fi
8080
# fi
8181

8282
# # Copy Groth16 and Plonk vks to verifier crate
83-
cp ./build/groth16/groth16_vk.bin ../verifier/bn254-vk/groth16_vk.bin
84-
cp ./build/plonk/plonk_vk.bin ../verifier/bn254-vk/plonk_vk.bin
83+
cp ./build/groth16/groth16_vk.bin ../verifier/vk-artifacts/groth16_vk.bin
84+
cp ./build/plonk/plonk_vk.bin ../verifier/vk-artifacts/plonk_vk.bin
8585

8686
echo "Successfully uploaded build artifacts to S3:"
8787
echo "- s3://$S3_BUCKET/$GROTH16_ARCHIVE"

crates/prover/src/build.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use itertools::Itertools;
44
use sha2::{Digest, Sha256};
5-
use slop_algebra::{AbstractField, PrimeField, PrimeField32};
5+
use slop_algebra::{AbstractField, PrimeField32};
66
use slop_bn254::Bn254Fr;
77
use sp1_hypercube::{koalabears_to_bn254, MachineVerifyingKey, SP1PcsProofOuter, ShardProof};
88
use sp1_primitives::{io::sha256_hash, SP1Field, SP1OuterGlobalContext};
@@ -21,6 +21,7 @@ use sp1_recursion_gnark_ffi::{
2121
ffi::{build_groth16_bn254, build_plonk_bn254},
2222
GnarkWitness,
2323
};
24+
use sp1_verifier::VK_ROOT_BYTES;
2425
use std::{
2526
borrow::Borrow,
2627
fs::File,
@@ -41,9 +42,7 @@ use {
4142

4243
use crate::{
4344
components::{CpuSP1ProverComponents, SP1ProverComponents},
44-
recursion::RecursionVks,
4545
utils::words_to_bytes,
46-
worker::DEFAULT_MAX_COMPOSE_ARITY,
4746
SP1_CIRCUIT_VERSION,
4847
};
4948

@@ -213,11 +212,9 @@ pub fn get_groth16_vkey_hash(build_dir: &Path) -> [u8; 32] {
213212
Sha256::digest(vk_bin_bytes).into()
214213
}
215214

216-
/// Get the vk root.
215+
/// Get the vk root as a hex string.
217216
pub fn get_vk_root() -> String {
218-
let root_field = RecursionVks::new(None, DEFAULT_MAX_COMPOSE_ARITY, true).root();
219-
let bigint = koalabears_to_bn254(&root_field).as_canonical_biguint();
220-
bigint.to_str_radix(16)
217+
hex::encode(*VK_ROOT_BYTES)
221218
}
222219

223220
/// Build the Plonk contracts.

crates/prover/src/verify.rs

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@ use crate::{
55
};
66
use anyhow::{anyhow, Result};
77
use num_bigint::BigUint;
8-
use serde::{Deserialize, Serialize};
98
use slop_algebra::{AbstractField, PrimeField};
10-
use slop_challenger::IopCtx;
119
use sp1_core_executor::SP1RecursionProof;
1210
use sp1_core_machine::riscv::MAX_LOG_NUMBER_OF_SHARDS;
1311
use sp1_hypercube::{
1412
air::{PublicValues, POSEIDON_NUM_WORDS, PV_DIGEST_NUM_WORDS},
15-
koalabears_to_bn254, verify_merkle_proof, HashableKey, MachineVerifier,
16-
MachineVerifierConfigError, MachineVerifierError, MachineVerifyingKey, MerkleProof,
17-
SP1InnerPcs, SP1OuterPcs, SP1PcsProofInner, SP1PcsProofOuter, SP1VerifyingKey, SP1WrapProof,
18-
PROOF_MAX_NUM_PVS,
13+
koalabears_to_bn254, HashableKey, MachineVerifier, MachineVerifierConfigError,
14+
MachineVerifierError, MachineVerifyingKey, SP1InnerPcs, SP1OuterPcs, SP1PcsProofInner,
15+
SP1PcsProofOuter, SP1VerifyingKey, SP1WrapProof, PROOF_MAX_NUM_PVS,
1916
};
2017
use sp1_primitives::{
2118
io::{blake3_hash, SP1PublicValues},
@@ -26,6 +23,7 @@ use sp1_recursion_executor::RecursionPublicValues;
2623
use sp1_recursion_gnark_ffi::{
2724
Groth16Bn254Proof, Groth16Bn254Prover, PlonkBn254Proof, PlonkBn254Prover,
2825
};
26+
pub use sp1_verifier::VerifierRecursionVks;
2927
use sp1_verifier::{Groth16Verifier, PlonkVerifier, GROTH16_VK_BYTES, PLONK_VK_BYTES};
3028
use std::{borrow::Borrow, str::FromStr};
3129
use thiserror::Error;
@@ -62,46 +60,6 @@ bn254 proof"
6260
/// The verifying key for the program wrapping an SP1 proof into a SNARK friendly format.
6361
pub const WRAP_VK_BYTES: &[u8] = include_bytes!("../wrap_vk.bin");
6462

65-
/// The recursion verifying keys used by the SP1 verifier.
66-
pub const VERIFIER_VK_DATA_BYTES: &[u8] = include_bytes!("../verifier_vks.bin");
67-
68-
#[derive(Clone, Serialize, Debug, PartialEq, Eq, Deserialize)]
69-
pub struct VerifierRecursionVks {
70-
pub root: <SP1GlobalContext as IopCtx>::Digest,
71-
pub vk_verification: bool,
72-
pub num_keys: usize,
73-
}
74-
75-
impl Default for VerifierRecursionVks {
76-
fn default() -> Self {
77-
bincode::deserialize(VERIFIER_VK_DATA_BYTES).unwrap()
78-
}
79-
}
80-
81-
impl VerifierRecursionVks {
82-
pub fn vk_verification(&self) -> bool {
83-
self.vk_verification
84-
}
85-
pub fn root(&self) -> <SP1GlobalContext as IopCtx>::Digest {
86-
self.root
87-
}
88-
89-
pub fn num_keys(&self) -> usize {
90-
self.num_keys
91-
}
92-
93-
pub fn verify(
94-
&self,
95-
proof: &MerkleProof<SP1GlobalContext>,
96-
vk: &MachineVerifyingKey<SP1GlobalContext>,
97-
) -> bool {
98-
if !self.vk_verification {
99-
return true;
100-
}
101-
verify_merkle_proof(proof, vk.hash_koalabear(), self.root).is_ok()
102-
}
103-
}
104-
10563
#[derive(Clone)]
10664
pub struct SP1Verifier {
10765
pub core: MachineVerifier<SP1GlobalContext, CoreSC>,

crates/verifier/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ sp1-primitives = { workspace = true }
3030
sp1-recursion-machine = { workspace = true, default-features = false }
3131
sp1-recursion-executor = { workspace = true, default-features = false }
3232
slop-algebra = { workspace = true }
33+
slop-challenger = { workspace = true }
3334
slop-primitives = { workspace = true }
3435
slop-symmetric = { workspace = true }
3536

crates/verifier/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ SP1 zkVM context is patched, in order to make use of the
1616

1717
### Pre-generated verification keys
1818

19-
Verification keys for Groth16 and Plonk are stored in the [`bn254-vk`](./bn254-vk/) directory. These
19+
Verification keys for Groth16 and Plonk are stored in the [`vk-artifacts`](./vk-artifacts/) directory. These
2020
vkeys are used to verify all SP1 proofs.
2121

2222
These vkeys are the same as those found locally in

crates/verifier/guest-verify-programs/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/verifier/src/compressed/internal.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ use sp1_primitives::{fri_params::recursion_fri_config, poseidon2_hasher, SP1Fiel
1313
use sp1_recursion_executor::{RecursionPublicValues, NUM_PV_ELMS_TO_HASH};
1414

1515
use super::CompressedError;
16-
use crate::{blake3_hash, hash_public_inputs, hash_public_inputs_with_fn};
16+
use crate::{
17+
blake3_hash,
18+
compressed::{RECURSION_LOG_STACKING_HEIGHT, RECURSION_MAX_LOG_ROW_COUNT},
19+
hash_public_inputs, hash_public_inputs_with_fn,
20+
};
1721

1822
/// The finite field used for compress proofs.
1923
type GC = sp1_primitives::SP1GlobalContext;
@@ -25,9 +29,6 @@ pub const COMPRESS_DEGREE: usize = 3;
2529

2630
pub type CompressAir<SP1Field> = sp1_recursion_machine::RecursionAir<SP1Field, COMPRESS_DEGREE, 2>;
2731

28-
pub const RECURSION_LOG_STACKING_HEIGHT: u32 = 20;
29-
pub const RECURSION_MAX_LOG_ROW_COUNT: usize = 21;
30-
3132
// // The rest of the functions in this file have been copied from elsewhere with slight
3233
// modifications.
3334

0 commit comments

Comments
 (0)