Skip to content

Commit

Permalink
Adapt to new version
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbosio committed Mar 14, 2024
1 parent 41058fa commit 727bc58
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 2 deletions.
82 changes: 81 additions & 1 deletion kimchi/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,11 +1518,13 @@ internal_tracing::decl_traces!(internal_traces;
#[cfg(feature = "ocaml_types")]
pub mod caml {
use super::*;
use crate::poly_commitment::commitment::caml::CamlPairingProof;
use crate::proof::caml::{CamlProofEvaluations, CamlRecursionChallenge};
use ark_ec::AffineCurve;
use ark_ec::{AffineCurve, PairingEngine};
use poly_commitment::{
commitment::caml::{CamlOpeningProof, CamlPolyComm},
evaluation_proof::OpeningProof,
pairing_proof::PairingProof,
};

#[cfg(feature = "internal_tracing")]
Expand All @@ -1534,6 +1536,12 @@ pub mod caml {
pub proof: CamlProverProof<CamlG, CamlF>,
}

#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
pub struct CamlKzgProofWithPublic<CamlG, CamlF> {
pub public_evals: Option<PointEvaluations<Vec<CamlF>>>,
pub proof: CamlKzgProverProof<CamlG, CamlF>,
}

//
// CamlProverProof<CamlG, CamlF>
//
Expand All @@ -1549,6 +1557,21 @@ pub mod caml {
pub prev_challenges: Vec<CamlRecursionChallenge<CamlG, CamlF>>, //Vec<(Vec<CamlF>, CamlPolyComm<CamlG>)>,
}

//
// CamlKzgProverProof<CamlG, CamlF>
//

#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
pub struct CamlKzgProverProof<CamlG, CamlF> {
pub commitments: CamlProverCommitments<CamlG>,
pub proof: CamlPairingProof<CamlG, CamlF>,
// OCaml doesn't have sized arrays, so we have to convert to a tuple..
pub evals: CamlProofEvaluations<CamlF>,
pub ft_eval1: CamlF,
pub public: Vec<CamlF>,
pub prev_challenges: Vec<CamlRecursionChallenge<CamlG, CamlF>>, //Vec<(Vec<CamlF>, CamlPolyComm<CamlG>)>,
}

//
// CamlProverCommitments<CamlG>
//
Expand Down Expand Up @@ -1783,6 +1806,63 @@ pub mod caml {
.collect(),
};

(proof, caml_pp.public.into_iter().map(Into::into).collect())
}
}
impl<G, CamlG, CamlF, Pair> From<(ProverProof<G, PairingProof<Pair>>, Vec<G::ScalarField>)>
for CamlKzgProofWithPublic<CamlG, CamlF>
where
Pair: PairingEngine,
G: AffineCurve,
CamlG: From<G> + From<<Pair as PairingEngine>::G1Affine>,
CamlF: From<G::ScalarField>
+ From<<<Pair as PairingEngine>::G1Affine as AffineCurve>::ScalarField>,
{
fn from(pp: (ProverProof<G, PairingProof<Pair>>, Vec<G::ScalarField>)) -> Self {
let (public_evals, evals) = pp.0.evals.into();
CamlKzgProofWithPublic {
public_evals,
proof: CamlKzgProverProof {
commitments: pp.0.commitments.into(),
proof: pp.0.proof.into(),
evals,
ft_eval1: pp.0.ft_eval1.into(),
public: pp.1.into_iter().map(Into::into).collect(),
prev_challenges: pp.0.prev_challenges.into_iter().map(Into::into).collect(),
},
}
}
}

impl<G, CamlG, CamlF, Pair> From<CamlKzgProofWithPublic<CamlG, CamlF>>
for (ProverProof<G, PairingProof<Pair>>, Vec<G::ScalarField>)
where
Pair: PairingEngine,
CamlF: Clone,
G: AffineCurve + From<CamlG>,
G::ScalarField: From<CamlF>,
<Pair as PairingEngine>::G1Affine: From<CamlG>,
<<Pair as PairingEngine>::G1Affine as AffineCurve>::ScalarField: From<CamlF>,
{
fn from(
caml_pp: CamlKzgProofWithPublic<CamlG, CamlF>,
) -> (ProverProof<G, PairingProof<Pair>>, Vec<G::ScalarField>) {
let CamlKzgProofWithPublic {
public_evals,
proof: caml_pp,
} = caml_pp;
let proof = ProverProof {
commitments: caml_pp.commitments.into(),
proof: caml_pp.proof.into(),
evals: (public_evals, caml_pp.evals).into(),
ft_eval1: caml_pp.ft_eval1.into(),
prev_challenges: caml_pp
.prev_challenges
.into_iter()
.map(Into::into)
.collect(),
};

(proof, caml_pp.public.into_iter().map(Into::into).collect())
}
}
Expand Down
2 changes: 1 addition & 1 deletion kimchi/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ where
Ok(())
}

fn to_batch<'a, G, EFqSponge, EFrSponge, OpeningProof: OpenProof<G>>(
pub fn to_batch<'a, G, EFqSponge, EFrSponge, OpeningProof: OpenProof<G>>(
verifier_index: &VerifierIndex<G, OpeningProof>,
proof: &'a ProverProof<G, OpeningProof>,
public_input: &'a [<G as AffineCurve>::ScalarField],
Expand Down
43 changes: 43 additions & 0 deletions poly-commitment/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,11 @@ mod tests {

#[cfg(feature = "ocaml_types")]
pub mod caml {
use ark_ec::PairingEngine;

use crate::pairing_proof;
use crate::pairing_proof::PairingProof;

use super::*;

// polynomial commitment
Expand Down Expand Up @@ -1282,4 +1287,42 @@ pub mod caml {
}
}
}

// pairing proof

#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
pub struct CamlPairingProof<G, F> {
pub quotient: G,
pub blinding: F,
}

impl<Pair, CamlF, CamlG> From<PairingProof<Pair>> for CamlPairingProof<CamlG, CamlF>
where
Pair: PairingEngine,
Pair::G1Affine: AffineCurve,
CamlG: From<Pair::G1Affine>,
CamlF: From<<Pair::G1Affine as AffineCurve>::ScalarField>,
{
fn from(pairing_proof: PairingProof<Pair>) -> Self {
Self {
quotient: pairing_proof.quotient.into(),
blinding: pairing_proof.blinding.into(),
}
}
}

impl<Pair, CamlF, CamlG> From<CamlPairingProof<CamlG, CamlF>> for PairingProof<Pair>
where
Pair: PairingEngine,
Pair::G1Affine: AffineCurve,
CamlG: Into<Pair::G1Affine>,
CamlF: Into<<Pair::G1Affine as AffineCurve>::ScalarField>,
{
fn from(caml: CamlPairingProof<CamlG, CamlF>) -> Self {
Self {
quotient: caml.quotient.into(),
blinding: caml.blinding.into(),
}
}
}
}

0 comments on commit 727bc58

Please sign in to comment.