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