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