mirror of
https://github.com/arnaucube/sonobe.git
synced 2026-01-23 12:33:50 +01:00
Unify the computation of digests and challenges in different folding schemes (#94)
* Remove the trait bound `C::BaseField: PrimeField` for better DX
* Methods in `TranscriptVar` now exactly matches the ones in `Transcript`
* Add `ProtoGalaxyTranscriptVar` and `CommittedInstanceVar` for protogalaxy
* betas are unnecessary in "plain" (incoming) instances
* Absorb the result of `get_challenge_nbits` as well
* `ProtoGalaxyTranscript` now allows absorbing mulitple instances
* Always return `Result<(), SynthesisError>` in `ProtoGalaxyTranscriptVar`
* Impl `Transcript{Var}` for `PoseidonSponge{Var}` directly and remove `PoseidonTranscript{Var}`
* `Transcript::absorb_point` doesn't need to return `Error`
* Add `AbsorbNonNative` trait for hashing non-native values
Note that now `absorb_point` only supports hashing points whose BaseField is equal to the sponge's field
* More efficient `TranscriptVar::absorb_point` by securely removing `is_inf`
* Use `sponge` and `transcript` consistently
* Clarify the usage of `AbsorbNonNative{Gadget}`
* Generic `sponge` and `transcript` params
* Avoid unstable `associated_type_bounds`
* Reuse `sponge` in hypernova
* Clean up redundant imports
* Remove unstable code
* Clarify the usage of `absorb_point` and `absorb_nonnative`
This commit is contained in:
@@ -81,13 +81,13 @@ impl<C: CurveGroup, const H: bool> CommitmentScheme<C, H> for Pedersen<C, H> {
|
||||
|
||||
fn prove(
|
||||
params: &Self::ProverParams,
|
||||
transcript: &mut impl Transcript<C>,
|
||||
transcript: &mut impl Transcript<C::ScalarField>,
|
||||
cm: &C,
|
||||
v: &[C::ScalarField],
|
||||
r: &C::ScalarField, // blinding factor
|
||||
_rng: Option<&mut dyn RngCore>,
|
||||
) -> Result<Self::Proof, Error> {
|
||||
transcript.absorb_point(cm)?;
|
||||
transcript.absorb_nonnative(cm);
|
||||
let r1 = transcript.get_challenge();
|
||||
let d = transcript.get_challenges(v.len());
|
||||
|
||||
@@ -98,7 +98,7 @@ impl<C: CurveGroup, const H: bool> CommitmentScheme<C, H> for Pedersen<C, H> {
|
||||
R += params.h.mul(r1);
|
||||
}
|
||||
|
||||
transcript.absorb_point(&R)?;
|
||||
transcript.absorb_nonnative(&R);
|
||||
let e = transcript.get_challenge();
|
||||
|
||||
let challenge = (r1, d, R, e);
|
||||
@@ -133,14 +133,14 @@ impl<C: CurveGroup, const H: bool> CommitmentScheme<C, H> for Pedersen<C, H> {
|
||||
|
||||
fn verify(
|
||||
params: &Self::VerifierParams,
|
||||
transcript: &mut impl Transcript<C>,
|
||||
transcript: &mut impl Transcript<C::ScalarField>,
|
||||
cm: &C,
|
||||
proof: &Proof<C>,
|
||||
) -> Result<(), Error> {
|
||||
transcript.absorb_point(cm)?;
|
||||
transcript.absorb_nonnative(cm);
|
||||
transcript.get_challenge(); // r_1
|
||||
transcript.get_challenges(proof.u.len()); // d
|
||||
transcript.absorb_point(&proof.R)?;
|
||||
transcript.absorb_nonnative(&proof.R);
|
||||
let e = transcript.get_challenge();
|
||||
Self::verify_with_challenge(params, e, cm, proof)
|
||||
}
|
||||
@@ -217,14 +217,14 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ark_crypto_primitives::sponge::{poseidon::PoseidonSponge, CryptographicSponge};
|
||||
use ark_ff::{BigInteger, PrimeField};
|
||||
use ark_pallas::{constraints::GVar, Fq, Fr, Projective};
|
||||
use ark_r1cs_std::{alloc::AllocVar, eq::EqGadget};
|
||||
use ark_relations::r1cs::ConstraintSystem;
|
||||
use ark_std::UniformRand;
|
||||
|
||||
use super::*;
|
||||
use crate::transcript::poseidon::{poseidon_canonical_config, PoseidonTranscript};
|
||||
use crate::transcript::poseidon::poseidon_canonical_config;
|
||||
|
||||
#[test]
|
||||
fn test_pedersen() {
|
||||
@@ -240,9 +240,9 @@ mod tests {
|
||||
let poseidon_config = poseidon_canonical_config::<Fr>();
|
||||
|
||||
// init Prover's transcript
|
||||
let mut transcript_p = PoseidonTranscript::<Projective>::new(&poseidon_config);
|
||||
let mut transcript_p = PoseidonSponge::<Fr>::new(&poseidon_config);
|
||||
// init Verifier's transcript
|
||||
let mut transcript_v = PoseidonTranscript::<Projective>::new(&poseidon_config);
|
||||
let mut transcript_v = PoseidonSponge::<Fr>::new(&poseidon_config);
|
||||
|
||||
let v: Vec<Fr> = std::iter::repeat_with(|| Fr::rand(&mut rng))
|
||||
.take(n)
|
||||
|
||||
Reference in New Issue
Block a user