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