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}
 47
 48/// FoldingScheme defines trait that is implemented by the diverse folding schemes. It is defined
 49/// over a cycle of curves (C1, C2), where:
 50/// - C1 is the main curve, which ScalarField we use as our F for al the field operations
 51/// - C2 is the auxiliary curve, which we use for the commitments, whose BaseField (for point
 52/// coordinates) are in the C1::ScalarField.
 53/// In other words, C1.Fq == C2.Fr, and C1.Fr == C2.Fq.
 54pub trait FoldingScheme<C1: CurveGroup, C2: CurveGroup>: Clone + Debug
 55where
 56    C1: CurveGroup<BaseField = C2::ScalarField, ScalarField = C2::BaseField>,
 57    C2::BaseField: PrimeField,
 58{
 59    type PreprocessorParam: Debug;
 60    type ProverParam: Debug;
 61    type VerifierParam: Debug;
 62    type Witness: Debug;
 63    type CommittedInstanceWithWitness: Debug;
 64    type CommittedInstance: Clone + Debug;
 65
 66    fn preprocess(
 67        prep_param: &Self::PreprocessorParam,
 68    ) -> Result<(Self::ProverParam, Self::VerifierParam), Error>;
 69
 70    fn init_accumulator(
 71        pp: &Self::ProverParam,
 72    ) -> Result<Self::CommittedInstanceWithWitness, Error>;
 73
 74    fn prove(
 75        pp: &Self::ProverParam,
 76        running_instance: &mut Self::CommittedInstanceWithWitness,
 77        incomming_instances: &[Self::Witness],
 78        transcript: &mut impl Transcript<C1>,
 79    ) -> Result<(), Error>;
 80
 81    fn verify(
 82        vp: &Self::VerifierParam,
 83        running_instance: &mut Self::CommittedInstance,
 84        incomming_instances: &[Self::CommittedInstance],
 85        transcript: &mut impl Transcript<C1>,
 86    ) -> Result<(), Error>;
 87}
 88
 89pub trait Decider<C: CurveGroup>: Clone + Debug {
 90    type PreprocessorParam: Debug;
 91    type ProverParam: Debug;
 92    type VerifierParam: Debug;
 93    type FreshInstance: Debug;
 94    type PublicInput: Debug;
 95    type CommittedInstanceWithWitness: Debug;
 96    type CommittedInstance: Clone + Debug;
 97
 98    fn prove(
 99        pp: &Self::ProverParam,
100        running_instance: &Self::CommittedInstanceWithWitness,
101        transcript: &mut impl Transcript<C>,
102        rng: impl RngCore,
103    ) -> Result<(), Error>;
104
105    fn verify(
106        vp: &Self::VerifierParam,
107        running_instance: &Self::CommittedInstance,
108        transcript: &mut impl Transcript<C>,
109        rng: impl RngCore,
110    ) -> Result<(), Error>;
111}