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