Skip to content

Commit

Permalink
Write serialization regression tests for poly-commitment and parts of…
Browse files Browse the repository at this point in the history
… kimchi
  • Loading branch information
volhovm committed Sep 24, 2024
1 parent 4b11acf commit a1f5545
Show file tree
Hide file tree
Showing 13 changed files with 756 additions and 62 deletions.
3 changes: 2 additions & 1 deletion kimchi/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ impl BenchmarkCtx {

// add the proof to the batch
(
ProverProof::create::<BaseSponge, ScalarSponge>(
ProverProof::create::<BaseSponge, ScalarSponge, _>(
&self.group_map,
witness,
&[],
&self.index,
&mut rand::rngs::OsRng,
)
.unwrap(),
public_input,
Expand Down
12 changes: 6 additions & 6 deletions kimchi/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::array;
//~ spec:startcode
/// Evaluations of a polynomial at 2 points
#[serde_as]
#[derive(Copy, Clone, Serialize, Deserialize, Default, Debug)]
#[derive(Copy, Clone, Serialize, Deserialize, Default, Debug, PartialEq)]
#[cfg_attr(
feature = "ocaml_types",
derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)
Expand All @@ -41,7 +41,7 @@ pub struct PointEvaluations<Evals> {
/// - **Chunked evaluations** `Field` is instantiated with vectors with a length that equals the length of the chunk
/// - **Non chunked evaluations** `Field` is instantiated with a field, so they are single-sized#[serde_as]
#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ProofEvaluations<Evals> {
/// public input polynomials
pub public: Option<Evals>,
Expand Down Expand Up @@ -106,7 +106,7 @@ pub struct ProofEvaluations<Evals> {

/// Commitments linked to the lookup feature
#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(bound = "G: ark_serialize::CanonicalDeserialize + ark_serialize::CanonicalSerialize")]
pub struct LookupCommitments<G: AffineRepr> {
/// Commitments to the sorted lookup table polynomial (may have chunks)
Expand All @@ -119,7 +119,7 @@ pub struct LookupCommitments<G: AffineRepr> {

/// All the commitments that the prover creates as part of the proof.
#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(bound = "G: ark_serialize::CanonicalDeserialize + ark_serialize::CanonicalSerialize")]
pub struct ProverCommitments<G: AffineRepr> {
/// The commitments to the witness (execution trace)
Expand All @@ -134,7 +134,7 @@ pub struct ProverCommitments<G: AffineRepr> {

/// The proof that the prover creates from a [ProverIndex](super::prover_index::ProverIndex) and a `witness`.
#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(bound = "G: ark_serialize::CanonicalDeserialize + ark_serialize::CanonicalSerialize")]
pub struct ProverProof<G: AffineRepr, OpeningProof> {
/// All the polynomial commitments required in the proof
Expand All @@ -160,7 +160,7 @@ pub struct ProverProof<G: AffineRepr, OpeningProof> {

/// A struct to store the challenges inside a `ProverProof`
#[serde_as]
#[derive(Debug, Clone, Deserialize, Serialize)]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(bound = "G: ark_serialize::CanonicalDeserialize + ark_serialize::CanonicalSerialize")]
pub struct RecursionChallenge<G>
where
Expand Down
11 changes: 7 additions & 4 deletions kimchi/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use poly_commitment::{
evaluation_proof::DensePolynomialOrEvaluations,
OpenProof, SRS as _,
};
use rand_core::{CryptoRng, RngCore};
use rayon::prelude::*;
use std::array;
use std::collections::HashMap;
Expand Down Expand Up @@ -134,22 +135,25 @@ where
pub fn create<
EFqSponge: Clone + FqSponge<G::BaseField, G, G::ScalarField>,
EFrSponge: FrSponge<G::ScalarField>,
RNG: RngCore + CryptoRng,
>(
groupmap: &G::Map,
witness: [Vec<G::ScalarField>; COLUMNS],
runtime_tables: &[RuntimeTable<G::ScalarField>],
index: &ProverIndex<G, OpeningProof>,
rng: &mut RNG,
) -> Result<Self>
where
VerifierIndex<G, OpeningProof>: Clone,
{
Self::create_recursive::<EFqSponge, EFrSponge>(
Self::create_recursive::<EFqSponge, EFrSponge, RNG>(
groupmap,
witness,
runtime_tables,
index,
Vec::new(),
None,
rng,
)
}

Expand All @@ -165,13 +169,15 @@ where
pub fn create_recursive<
EFqSponge: Clone + FqSponge<G::BaseField, G, G::ScalarField>,
EFrSponge: FrSponge<G::ScalarField>,
RNG: RngCore + CryptoRng,
>(
group_map: &G::Map,
mut witness: [Vec<G::ScalarField>; COLUMNS],
runtime_tables: &[RuntimeTable<G::ScalarField>],
index: &ProverIndex<G, OpeningProof>,
prev_challenges: Vec<RecursionChallenge<G>>,
blinders: Option<[Option<PolyComm<G::ScalarField>>; COLUMNS]>,
rng: &mut RNG,
) -> Result<Self>
where
VerifierIndex<G, OpeningProof>: Clone,
Expand All @@ -187,9 +193,6 @@ where
d1_size / index.max_poly_size
};

// TODO: rng should be passed as arg
let rng = &mut rand::rngs::OsRng;

// Verify the circuit satisfiability by the computed witness (baring plookup constraints)
// Catch mistakes before proof generation.
if cfg!(debug_assertions) && !index.cs.disable_gates_checks {
Expand Down
Loading

0 comments on commit a1f5545

Please sign in to comment.