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