Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add missing Debug implementations #282

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ xclippy = [
"-Wclippy::unnecessary_mut_passed",
"-Wclippy::unnecessary_wraps",
"-Wclippy::use_self",
"-Wmissing_debug_implementations",
"-Wnonstandard_style",
"-Wrust_2018_idioms",
"-Wtrivial_numeric_casts",
Expand Down
4 changes: 2 additions & 2 deletions src/gadgets/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use bellpepper_core::{
use ff::{Field, PrimeField};

/// `AllocatedPoint` provides an elliptic curve abstraction inside a circuit.
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct AllocatedPoint<E: Engine> {
pub(crate) x: AllocatedNum<E::Base>,
pub(crate) y: AllocatedNum<E::Base>,
Expand Down Expand Up @@ -590,7 +590,7 @@ where
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
/// `AllocatedPoint` but one that is guaranteed to be not infinity
pub struct AllocatedPointNonInfinity<E: Engine> {
x: AllocatedNum<E::Base>,
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use traits::{
};

/// A type that holds parameters for the primary and secondary circuits of Nova and SuperNova
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Abomonation)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(where <E::Scalar as PrimeField>::Repr: Abomonation)]
pub struct R1CSWithArity<E: Engine> {
Expand All @@ -87,7 +87,7 @@ impl<E: Engine> R1CSWithArity<E> {
}

/// A type that holds public parameters of Nova
#[derive(Clone, PartialEq, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(
where
Expand Down Expand Up @@ -706,7 +706,7 @@ where
}

/// A type that holds the verifier key for `CompressedSNARK`
#[derive(Clone, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(
where
Expand Down Expand Up @@ -739,7 +739,7 @@ where
}

/// A SNARK that proves the knowledge of a valid `RecursiveSNARK`
#[derive(Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(bound = "")]
pub struct CompressedSNARK<E1, E2, C1, C2, S1, S2>
where
Expand Down
6 changes: 3 additions & 3 deletions src/provider/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use neptune::{
use serde::{Deserialize, Serialize};

/// All Poseidon Constants that are used in Nova
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Abomonation)]
#[abomonation_bounds(where Scalar::Repr: Abomonation)]
pub struct PoseidonConstantsCircuit<Scalar: PrimeField>(PoseidonConstants<Scalar, U24>);

Expand All @@ -35,7 +35,7 @@ impl<Scalar: PrimeField> Default for PoseidonConstantsCircuit<Scalar> {
}

/// A Poseidon-based RO to use outside circuits
#[derive(Serialize, Deserialize, Abomonation)]
#[derive(Debug, Serialize, Deserialize, Abomonation)]
#[abomonation_bounds(
where
Base: PrimeField,
Expand Down Expand Up @@ -115,7 +115,7 @@ where
}

/// A Poseidon-based RO gadget to use inside the verifier circuit.
#[derive(Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
pub struct PoseidonROCircuit<Scalar: PrimeField> {
// Internal state
state: Vec<AllocatedNum<Scalar>>,
Expand Down
1 change: 1 addition & 0 deletions src/r1cs/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ impl<F: PrimeField> SparseMatrix<F> {
}

/// Iterator for sparse matrix
#[derive(Debug)]
pub struct Iter<'a, F: PrimeField> {
matrix: &'a SparseMatrix<F>,
row: usize,
Expand Down
4 changes: 2 additions & 2 deletions src/spartan/batched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub struct BatchedRelaxedR1CSSNARK<E: Engine, EE: EvaluationEngineTrait<E>> {
}

/// A type that represents the prover's key
#[derive(Clone, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(where <E::Scalar as ff::PrimeField>::Repr: Abomonation)]
pub struct ProverKey<E: Engine, EE: EvaluationEngineTrait<E>> {
Expand All @@ -69,7 +69,7 @@ pub struct ProverKey<E: Engine, EE: EvaluationEngineTrait<E>> {
}

/// A type that represents the verifier's key
#[derive(Clone, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(where <E::Scalar as ff::PrimeField>::Repr: Abomonation)]
pub struct VerifierKey<E: Engine, EE: EvaluationEngineTrait<E>> {
Expand Down
4 changes: 2 additions & 2 deletions src/spartan/batched_ppsnark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use rayon::prelude::*;
use serde::{Deserialize, Serialize};

/// A type that represents the prover's key
#[derive(Clone, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(where < E::Scalar as PrimeField >::Repr: Abomonation)]
pub struct ProverKey<E: Engine, EE: EvaluationEngineTrait<E>> {
Expand All @@ -55,7 +55,7 @@ pub struct ProverKey<E: Engine, EE: EvaluationEngineTrait<E>> {
}

/// A type that represents the verifier's key
#[derive(Clone, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(where < E::Scalar as PrimeField >::Repr: Abomonation)]
pub struct VerifierKey<E: Engine, EE: EvaluationEngineTrait<E>> {
Expand Down
2 changes: 2 additions & 0 deletions src/spartan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fn powers<E: Engine>(s: &E::Scalar, n: usize) -> Vec<E::Scalar> {
}

/// A type that holds a witness to a polynomial evaluation instance
#[derive(Debug)]
struct PolyEvalWitness<E: Engine> {
p: Vec<E::Scalar>, // polynomial
}
Expand Down Expand Up @@ -114,6 +115,7 @@ impl<E: Engine> PolyEvalWitness<E> {
}

/// A type that holds a polynomial evaluation instance
#[derive(Debug)]
struct PolyEvalInstance<E: Engine> {
c: Commitment<E>, // commitment to the polynomial
x: Vec<E::Scalar>, // evaluation point
Expand Down
8 changes: 4 additions & 4 deletions src/spartan/ppsnark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn padded<E: Engine>(v: &[E::Scalar], n: usize, e: &E::Scalar) -> Vec<E::Scalar>
}

/// A type that holds `R1CSShape` in a form amenable to memory checking
#[derive(Clone, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(where <E::Scalar as PrimeField>::Repr: Abomonation)]
pub struct R1CSShapeSparkRepr<E: Engine> {
Expand All @@ -78,7 +78,7 @@ pub struct R1CSShapeSparkRepr<E: Engine> {
}

/// A type that holds a commitment to a sparse polynomial
#[derive(Clone, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(where <E::Scalar as PrimeField>::Repr: Abomonation)]
pub struct R1CSShapeSparkCommitment<E: Engine> {
Expand Down Expand Up @@ -255,7 +255,7 @@ impl<E: Engine> R1CSShapeSparkRepr<E> {
}

/// A type that represents the prover's key
#[derive(Clone, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(where <E::Scalar as PrimeField>::Repr: Abomonation)]
pub struct ProverKey<E: Engine, EE: EvaluationEngineTrait<E>> {
Expand All @@ -267,7 +267,7 @@ pub struct ProverKey<E: Engine, EE: EvaluationEngineTrait<E>> {
}

/// A type that represents the verifier's key
#[derive(Clone, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(where <E::Scalar as PrimeField>::Repr: Abomonation)]
pub struct VerifierKey<E: Engine, EE: EvaluationEngineTrait<E>> {
Expand Down
16 changes: 8 additions & 8 deletions src/spartan/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use rayon::prelude::*;
use serde::{Deserialize, Serialize};

/// A type that represents the prover's key
#[derive(Clone, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(where <E::Scalar as ff::PrimeField>::Repr: Abomonation)]
pub struct ProverKey<E: Engine, EE: EvaluationEngineTrait<E>> {
Expand All @@ -43,7 +43,7 @@ pub struct ProverKey<E: Engine, EE: EvaluationEngineTrait<E>> {
}

/// A type that represents the verifier's key
#[derive(Clone, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(where <E::Scalar as ff::PrimeField>::Repr: Abomonation)]
pub struct VerifierKey<E: Engine, EE: EvaluationEngineTrait<E>> {
Expand Down Expand Up @@ -189,7 +189,7 @@ where
// claims from the end of sum-check
let (claim_Az, claim_Bz): (E::Scalar, E::Scalar) = (claims_outer[1], claims_outer[2]);
let claim_Cz = poly_Cz.evaluate(&r_x);
let eval_E = MultilinearPolynomial::new(W.E.clone()).evaluate(&r_x);
let eval_E = MultilinearPolynomial::evaluate_with(&W.E, &r_x);
transcript.absorb(
b"claims_outer",
&[claim_Az, claim_Bz, claim_Cz, eval_E].as_slice(),
Expand Down Expand Up @@ -536,11 +536,11 @@ pub(in crate::spartan) fn batch_eval_verify<E: Engine>(
EqPolynomial::new(r_hi.to_vec()).evaluate(&u.x)
});

evals_r
.zip_eq(evals_batch.iter())
.zip_eq(powers_of_rho.iter())
.map(|((e_i, p_i), rho_i)| e_i * *p_i * rho_i)
.sum()
zip_with!(
(evals_r, evals_batch.iter(), powers_of_rho.iter()),
|e_i, p_i, rho_i| e_i * *p_i * rho_i
)
.sum()
};

if claim_batch_final != claim_batch_final_expected {
Expand Down
6 changes: 3 additions & 3 deletions src/supernova/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use circuit::{
use error::SuperNovaError;

/// A struct that manages all the digests of the primary circuits of a SuperNova instance
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CircuitDigests<E: Engine> {
digests: Vec<E::Scalar>,
}
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<E: Engine> CircuitDigests<E> {
}

/// A vector of [R1CSWithArity] adjoined to a set of [PublicParams]
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(bound = "")]
pub struct PublicParams<E1, E2, C1, C2>
where
Expand Down Expand Up @@ -107,7 +107,7 @@ where
/// Auxiliary [PublicParams] information about the commitment keys and
/// secondary circuit. This is used as a helper struct when reconstructing
/// [PublicParams] downstream in lurk.
#[derive(Clone, PartialEq, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(
where
Expand Down
4 changes: 2 additions & 2 deletions src/supernova/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use serde::{Deserialize, Serialize};
use std::marker::PhantomData;

/// A type that holds the prover key for `CompressedSNARK`
#[derive(Clone, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(
where
Expand All @@ -46,7 +46,7 @@ where
}

/// A type that holds the verifier key for `CompressedSNARK`
#[derive(Clone, Serialize, Deserialize, Abomonation)]
#[derive(Debug, Clone, Serialize, Deserialize, Abomonation)]
#[serde(bound = "")]
#[abomonation_bounds(
where
Expand Down
6 changes: 4 additions & 2 deletions src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ pub trait ROTrait<Base: PrimeField, Scalar> {
type CircuitRO: ROCircuitTrait<Base, Constants = Self::Constants>;

/// A type representing constants/parameters associated with the hash function
type Constants: Default
type Constants: Debug
+ Default
+ Clone
+ PartialEq
+ Send
Expand All @@ -92,7 +93,8 @@ pub trait ROCircuitTrait<Base: PrimeField> {
type NativeRO<T: PrimeField>: ROTrait<Base, T, Constants = Self::Constants>;

/// A type representing constants/parameters associated with the hash function on this Base field
type Constants: Default
type Constants: Debug
+ Default
+ Clone
+ PartialEq
+ Send
Expand Down