arnaucube
arnaucube/sonobePublic Self-hosted repository
sonobe/folding-schemes/src/transcript/mod.rs
folding-schemes/src/transcript/mod.rsRaw
 1use crate::Error;
 2use ark_ec::CurveGroup;
 3use ark_ff::PrimeField;
 4use ark_r1cs_std::{boolean::Boolean, fields::fp::FpVar};
 5use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
 6use ark_std::fmt::Debug;
 7
 8pub mod poseidon;
 9
10pub trait Transcript<C: CurveGroup> {
11    type TranscriptConfig: Debug;
12
13    fn new(config: &Self::TranscriptConfig) -> Self;
14    fn absorb(&mut self, v: &C::ScalarField);
15    fn absorb_vec(&mut self, v: &[C::ScalarField]);
16    fn absorb_point(&mut self, v: &C) -> Result<(), Error>;
17    fn get_challenge(&mut self) -> C::ScalarField;
18    /// get_challenge_nbits returns a field element of size nbits
19    fn get_challenge_nbits(&mut self, nbits: usize) -> Vec<bool>;
20    fn get_challenges(&mut self, n: usize) -> Vec<C::ScalarField>;
21}
22
23pub trait TranscriptVar<F: PrimeField> {
24    type TranscriptVarConfig: Debug;
25
26    fn new(cs: ConstraintSystemRef<F>, poseidon_config: &Self::TranscriptVarConfig) -> Self;
27    fn absorb(&mut self, v: FpVar<F>) -> Result<(), SynthesisError>;
28    fn absorb_vec(&mut self, v: &[FpVar<F>]) -> Result<(), SynthesisError>;
29    fn get_challenge(&mut self) -> Result<FpVar<F>, SynthesisError>;
30    /// returns the bit representation of the challenge, we use its output in-circuit for the
31    /// `GC.scalar_mul_le` method.
32    fn get_challenge_nbits(&mut self, nbits: usize) -> Result<Vec<Boolean<F>>, SynthesisError>;
33    fn get_challenges(&mut self, n: usize) -> Result<Vec<FpVar<F>>, SynthesisError>;
34}