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
 24    #[error("Relation not satisfied")]
 25    NotSatisfied,
 26    #[error("Not equal")]
 27    NotEqual,
 28    #[error("Vectors should have the same length")]
 29    NotSameLength,
 30    #[error("Vector's length is not the expected")]
 31    NotExpectedLength,
 32    #[error("Can not be empty")]
 33    Empty,
 34    #[error("Commitment verification failed")]
 35    CommitmentVerificationFail,
 36}
 37
 38/// FoldingScheme defines trait that is implemented by the diverse folding schemes. It is defined
 39/// over a cycle of curves (C1, C2), where:
 40/// - C1 is the main curve, which ScalarField we use as our F for al the field operations
 41/// - C2 is the auxiliary curve, which we use for the commitments, whose BaseField (for point
 42/// coordinates) are in the C1::ScalarField.
 43/// In other words, C1.Fq == C2.Fr, and C1.Fr == C2.Fq.
 44pub trait FoldingScheme<C1: CurveGroup, C2: CurveGroup>: Clone + Debug
 45where
 46    C1: CurveGroup<BaseField = C2::ScalarField, ScalarField = C2::BaseField>,
 47    C2::BaseField: PrimeField,
 48{
 49    type PreprocessorParam: Debug;
 50    type ProverParam: Debug;
 51    type VerifierParam: Debug;
 52    type Witness: Debug;
 53    type CommittedInstanceWithWitness: Debug;
 54    type CommittedInstance: Clone + Debug;
 55
 56    fn preprocess(
 57        prep_param: &Self::PreprocessorParam,
 58    ) -> Result<(Self::ProverParam, Self::VerifierParam), Error>;
 59
 60    fn init_accumulator(
 61        pp: &Self::ProverParam,
 62    ) -> Result<Self::CommittedInstanceWithWitness, Error>;
 63
 64    fn prove(
 65        pp: &Self::ProverParam,
 66        running_instance: &mut Self::CommittedInstanceWithWitness,
 67        incomming_instances: &[Self::Witness],
 68        transcript: &mut impl Transcript<C1>,
 69    ) -> Result<(), Error>;
 70
 71    fn verify(
 72        vp: &Self::VerifierParam,
 73        running_instance: &mut Self::CommittedInstance,
 74        incomming_instances: &[Self::CommittedInstance],
 75        transcript: &mut impl Transcript<C1>,
 76    ) -> Result<(), Error>;
 77}
 78
 79pub trait Decider<C: CurveGroup>: Clone + Debug {
 80    type PreprocessorParam: Debug;
 81    type ProverParam: Debug;
 82    type VerifierParam: Debug;
 83    type FreshInstance: Debug;
 84    type PublicInput: Debug;
 85    type CommittedInstanceWithWitness: Debug;
 86    type CommittedInstance: Clone + Debug;
 87
 88    fn prove(
 89        pp: &Self::ProverParam,
 90        running_instance: &Self::CommittedInstanceWithWitness,
 91        transcript: &mut impl Transcript<C>,
 92        rng: impl RngCore,
 93    ) -> Result<(), Error>;
 94
 95    fn verify(
 96        vp: &Self::VerifierParam,
 97        running_instance: &Self::CommittedInstance,
 98        transcript: &mut impl Transcript<C>,
 99        rng: impl RngCore,
100    ) -> Result<(), Error>;
101}