Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializaiton regression tests for proof-systems and parts of kimchi #2598

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, collections::HashMap};

Expand Down Expand Up @@ -133,22 +134,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 @@ -164,13 +168,15 @@ where
pub fn create_recursive<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems to introduce a change also in the whole Mina repository. We might want to be more careful regarding this. Can we avoid this in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't really, since then the prover is non-deterministic and it serializes to a different value every time.

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 @@ -186,9 +192,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