arnaucube
arnaucube/sonobePublic Self-hosted repository
sonobe/src/lib.rs
src/lib.rsRaw
  1#![allow(non_snake_case)]
  2#![allow(non_upper_case_globals)]
  3
  4use ark_ec::CurveGroup;
  5use ark_ff::PrimeField;
  6use ark_std::{fmt::Debug, rand::RngCore};
  7use thiserror::Error;
  8
  9pub mod transcript;
 10use transcript::Transcript;
 11pub mod ccs;
 12pub mod constants;
 13pub mod folding;
 14pub mod frontend;
 15pub mod pedersen;
 16pub mod utils;
 17
 18#[derive(Debug, Error)]
 19pub enum Error {
 20    #[error("ark_relations::r1cs::SynthesisError")]
 21    SynthesisError(#[from] ark_relations::r1cs::SynthesisError),
 22    #[error("ark_serialize::SerializationError")]
 23    SerializationError(#[from] ark_serialize::SerializationError),
 24    #[error("{0}")]
 25    Other(String),
 26
 27    #[error("Relation not satisfied")]
 28    NotSatisfied,
 29    #[error("Not equal")]
 30    NotEqual,
 31    #[error("Vectors should have the same length ({0}: {1}, {2}: {3})")]
 32    NotSameLength(String, usize, String, usize),
 33    #[error("Vector's length ({0}) is not the expected ({1})")]
 34    NotExpectedLength(usize, usize),
 35    #[error("Can not be empty")]
 36    Empty,
 37    #[error("Pedersen parameters length is not suficient (generators.len={0} < vector.len={1} unsatisfied)")]
 38    PedersenParamsLen(usize, usize),
 39    #[error("Pedersen verification failed")]
 40    PedersenVerificationFail,
 41    #[error("IVC verification failed")]
 42    IVCVerificationFail,
 43    #[error("R1CS instance is expected to not be relaxed")]
 44    R1CSUnrelaxedFail,
 45    #[error("Could not find the inner ConstraintSystem")]
 46    NoInnerConstraintSystem,
 47    #[error("Sum-check prove failed: {0}")]
 48    SumCheckProveError(String),
 49    #[error("Sum-check verify failed: {0}")]
 50    SumCheckVerifyError(String),
 51    #[error("Value out of bounds")]
 52    OutOfBounds,
 53    #[error("Could not construct the Evaluation Domain")]
 54    NewDomainFail,
 55
 56    #[error(transparent)]
 57    ProtoGalaxy(folding::protogalaxy::ProtoGalaxyError),
 58}
 59
 60/// FoldingScheme defines trait that is implemented by the diverse folding schemes. It is defined
 61/// over a cycle of curves (C1, C2), where:
 62/// - C1 is the main curve, which ScalarField we use as our F for al the field operations
 63/// - C2 is the auxiliary curve, which we use for the commitments, whose BaseField (for point
 64/// coordinates) are in the C1::ScalarField.
 65/// In other words, C1.Fq == C2.Fr, and C1.Fr == C2.Fq.
 66pub trait FoldingScheme<C1: CurveGroup, C2: CurveGroup>: Clone + Debug
 67where
 68    C1: CurveGroup<BaseField = C2::ScalarField, ScalarField = C2::BaseField>,
 69    C2::BaseField: PrimeField,
 70{
 71    type PreprocessorParam: Debug;
 72    type ProverParam: Debug;
 73    type VerifierParam: Debug;
 74    type Witness: Debug;
 75    type CommittedInstanceWithWitness: Debug;
 76    type CommittedInstance: Clone + Debug;
 77
 78    fn preprocess(
 79        prep_param: &Self::PreprocessorParam,
 80    ) -> Result<(Self::ProverParam, Self::VerifierParam), Error>;
 81
 82    fn init_accumulator(
 83        pp: &Self::ProverParam,
 84    ) -> Result<Self::CommittedInstanceWithWitness, Error>;
 85
 86    fn prove(
 87        pp: &Self::ProverParam,
 88        running_instance: &mut Self::CommittedInstanceWithWitness,
 89        incomming_instances: &[Self::Witness],
 90        transcript: &mut impl Transcript<C1>,
 91    ) -> Result<(), Error>;
 92
 93    fn verify(
 94        vp: &Self::VerifierParam,
 95        running_instance: &mut Self::CommittedInstance,
 96        incomming_instances: &[Self::CommittedInstance],
 97        transcript: &mut impl Transcript<C1>,
 98    ) -> Result<(), Error>;
 99}
100
101pub trait Decider<C: CurveGroup>: Clone + Debug {
102    type PreprocessorParam: Debug;
103    type ProverParam: Debug;
104    type VerifierParam: Debug;
105    type FreshInstance: Debug;
106    type PublicInput: Debug;
107    type CommittedInstanceWithWitness: Debug;
108    type CommittedInstance: Clone + Debug;
109
110    fn prove(
111        pp: &Self::ProverParam,
112        running_instance: &Self::CommittedInstanceWithWitness,
113        transcript: &mut impl Transcript<C>,
114        rng: impl RngCore,
115    ) -> Result<(), Error>;
116
117    fn verify(
118        vp: &Self::VerifierParam,
119        running_instance: &Self::CommittedInstance,
120        transcript: &mut impl Transcript<C>,
121        rng: impl RngCore,
122    ) -> Result<(), Error>;
123}