diff --git a/kimchi/src/prover.rs b/kimchi/src/prover.rs index 45fb2e6304..bedab008ff 100644 --- a/kimchi/src/prover.rs +++ b/kimchi/src/prover.rs @@ -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")] @@ -1534,6 +1536,12 @@ pub mod caml { pub proof: CamlProverProof, } + #[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] + pub struct CamlKzgProofWithPublic { + pub public_evals: Option>>, + pub proof: CamlKzgProverProof, + } + // // CamlProverProof // @@ -1549,6 +1557,21 @@ pub mod caml { pub prev_challenges: Vec>, //Vec<(Vec, CamlPolyComm)>, } + // + // CamlKzgProverProof + // + + #[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] + pub struct CamlKzgProverProof { + pub commitments: CamlProverCommitments, + pub proof: CamlPairingProof, + // OCaml doesn't have sized arrays, so we have to convert to a tuple.. + pub evals: CamlProofEvaluations, + pub ft_eval1: CamlF, + pub public: Vec, + pub prev_challenges: Vec>, //Vec<(Vec, CamlPolyComm)>, + } + // // CamlProverCommitments // @@ -1783,6 +1806,63 @@ pub mod caml { .collect(), }; + (proof, caml_pp.public.into_iter().map(Into::into).collect()) + } + } + impl From<(ProverProof>, Vec)> + for CamlKzgProofWithPublic + where + Pair: PairingEngine, + G: AffineCurve, + CamlG: From + From<::G1Affine>, + CamlF: From + + From<<::G1Affine as AffineCurve>::ScalarField>, + { + fn from(pp: (ProverProof>, Vec)) -> 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 From> + for (ProverProof>, Vec) + where + Pair: PairingEngine, + CamlF: Clone, + G: AffineCurve + From, + G::ScalarField: From, + ::G1Affine: From, + <::G1Affine as AffineCurve>::ScalarField: From, + { + fn from( + caml_pp: CamlKzgProofWithPublic, + ) -> (ProverProof>, Vec) { + 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()) } } diff --git a/kimchi/src/verifier.rs b/kimchi/src/verifier.rs index 0c9cd4aef3..be00b5e4b7 100644 --- a/kimchi/src/verifier.rs +++ b/kimchi/src/verifier.rs @@ -738,7 +738,7 @@ where Ok(()) } -fn to_batch<'a, G, EFqSponge, EFrSponge, OpeningProof: OpenProof>( +pub fn to_batch<'a, G, EFqSponge, EFrSponge, OpeningProof: OpenProof>( verifier_index: &VerifierIndex, proof: &'a ProverProof, public_input: &'a [::ScalarField], diff --git a/poly-commitment/src/commitment.rs b/poly-commitment/src/commitment.rs index 3d6cdf2411..d7ce48fa79 100644 --- a/poly-commitment/src/commitment.rs +++ b/poly-commitment/src/commitment.rs @@ -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 @@ -1282,4 +1287,42 @@ pub mod caml { } } } + + // pairing proof + + #[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] + pub struct CamlPairingProof { + pub quotient: G, + pub blinding: F, + } + + impl From> for CamlPairingProof + where + Pair: PairingEngine, + Pair::G1Affine: AffineCurve, + CamlG: From, + CamlF: From<::ScalarField>, + { + fn from(pairing_proof: PairingProof) -> Self { + Self { + quotient: pairing_proof.quotient.into(), + blinding: pairing_proof.blinding.into(), + } + } + } + + impl From> for PairingProof + where + Pair: PairingEngine, + Pair::G1Affine: AffineCurve, + CamlG: Into, + CamlF: Into<::ScalarField>, + { + fn from(caml: CamlPairingProof) -> Self { + Self { + quotient: caml.quotient.into(), + blinding: caml.blinding.into(), + } + } + } }