Fix the pedantic lints (3)
MODIFY
circuit-construction/src/prover.rs
circuit-construction/src/prover.rs
@@ -160,6 +160,10 @@ where
}
/// Creates the prover index on input an `srs`, used `constants`, parameters for Poseidon, number of public inputs, and a specific circuit
+///
+/// # Panics
+///
+/// Will panic if `constraint_system` is not built with `public` input.
pub fn generate_prover_index<C, H>(
srs: std::sync::Arc<SRS<C::Outer>>,
public: usize,
@@ -190,7 +194,7 @@ where
main(&mut system, public_input);
let gates = system.gates();
- println!("gates: {}", gates.len());
+
// Other base field = self scalar field
let (endo_q, _endo_r) = endos::<C::Inner>();

MODIFY
kimchi/src/circuits/wires.rs
kimchi/src/circuits/wires.rs
@@ -28,17 +28,20 @@ pub struct Wire {
impl Wire {
/// Creates a new set of wires for a given row.
+ #[must_use]
pub fn new(row: usize) -> [Self; PERMUTS] {
array::from_fn(|col| Self { row, col })
}
}
-/// GateWires document the wiring of a gate. More specifically, each value either
+/// `GateWires` document the wiring of a gate. More specifically, each value either
/// represents the same cell (row and column) or a different cell in another row.
/// (This is to help the permutation argument.)
+#[allow(clippy::module_name_repetitions)]
pub type GateWires = [Wire; PERMUTS];
impl ToBytes for Wire {
+ #[allow(clippy::cast_possible_truncation)]
#[inline]
fn write<W: Write>(&self, mut w: W) -> IoResult<()> {
(self.row as u32).write(&mut w)?;

MODIFY
kimchi/src/curve.rs
kimchi/src/curve.rs
@@ -8,6 +8,7 @@ use once_cell::sync::Lazy;
use oracle::poseidon::ArithmeticSpongeParams;
///Represents additional information that a curve needs in order to be used with Kimchi
+#[allow(clippy::module_name_repetitions)]
pub trait KimchiCurve: CommitmentCurve {
/// The other curve that forms the cycle used for recursion
type OtherCurve: KimchiCurve<
@@ -17,7 +18,7 @@ pub trait KimchiCurve: CommitmentCurve {
>;
/// Provides the sponge params to be used with this curve
- /// If the params for the base field are needed, they can be obtained from [KimchiCurve::OtherCurve]
+ /// If the params for the base field are needed, they can be obtained from [`KimchiCurve::OtherCurve`]
fn sponge_params() -> &'static ArithmeticSpongeParams<Self::ScalarField>;
/// Provides the coefficients for the curve endomorphism

MODIFY
kimchi/src/error.rs
kimchi/src/error.rs
-//! This module implements the [ProverError] type.
+//! This module implements the [`ProverError`] type.
use commitment_dlog::error::CommitmentError;
use thiserror::Error;
/// Errors that can arise when creating a proof
// TODO(mimoo): move this out of oracle
+#[allow(clippy::module_name_repetitions)]
#[derive(Error, Debug, Clone, Copy)]
pub enum ProverError {
#[error("the circuit is too large")]
@@ -33,6 +34,7 @@ pub enum ProverError {
}
/// Errors that can arise when verifying a proof
+#[allow(clippy::module_name_repetitions)]
#[derive(Error, Debug, Clone, Copy)]
pub enum VerifyError {
#[error("the commitment to {0} is of an unexpected size")]
@@ -67,6 +69,7 @@ pub enum VerifyError {
}
/// Errors that can arise when preparing the setup
+#[allow(clippy::module_name_repetitions)]
#[derive(Error, Debug, Clone)]
pub enum SetupError {
#[error("the domain could not be constructed: {0}")]
@@ -77,6 +80,7 @@ pub enum SetupError {
}
/// Errors that can arise when creating a verifier index
+#[allow(clippy::module_name_repetitions)]
#[derive(Error, Debug, Clone)]
pub enum VerifierIndexError {
#[error("srs has already been set")]

MODIFY
kimchi/src/linearization.rs
kimchi/src/linearization.rs
@@ -15,10 +15,16 @@ use crate::circuits::polynomials::varbasemul::VarbaseMul;
use crate::circuits::{
expr::{Column, ConstantExpr, Expr, Linearization, PolishToken},
gate::GateType,
- wires::*,
+ wires::COLUMNS,
};
use ark_ff::{FftField, SquareRootField};
+/// Get the expresion of constraints.
+///
+/// # Panics
+///
+/// Will panic if `generic_gate` is not associate with `alpha^0`.
+#[must_use]
pub fn constraints_expr<F: FftField + SquareRootField>(
chacha: bool,
range_check: bool,
@@ -85,11 +91,13 @@ pub fn constraints_expr<F: FftField + SquareRootField>(
/// Adds the polynomials that are evaluated as part of the proof
/// for the linearization to work.
+#[must_use]
+#[allow(clippy::module_name_repetitions)]
pub fn linearization_columns<F: FftField + SquareRootField>(
lookup_constraint_system: Option<&LookupConfiguration<F>>,
) -> std::collections::HashSet<Column> {
let mut h = std::collections::HashSet::new();
- use Column::*;
+ use Column::{Index, LookupAggreg, LookupRuntimeTable, LookupSorted, LookupTable, Witness, Z};
// the witness polynomials
for i in 0..COLUMNS {
@@ -98,7 +106,7 @@ pub fn linearization_columns<F: FftField + SquareRootField>(
// the lookup polynomials
if let Some(lcs) = &lookup_constraint_system {
- for i in 0..(lcs.lookup_info.max_per_row + 1) {
+ for i in 0..=lcs.lookup_info.max_per_row {
h.insert(LookupSorted(i));
}
h.insert(LookupAggreg);
@@ -122,6 +130,12 @@ pub fn linearization_columns<F: FftField + SquareRootField>(
h
}
+/// Linearize the `expr`.
+///
+/// # Panics
+///
+/// Will panic if the `linearization` process fails.
+#[must_use]
pub fn expr_linearization<F: FftField + SquareRootField>(
chacha: bool,
range_check: bool,
@@ -134,7 +148,7 @@ pub fn expr_linearization<F: FftField + SquareRootField>(
let linearization = expr
.linearize(evaluated_cols)
.unwrap()
- .map(|e| e.to_polish());
+ .map(crate::circuits::expr::Expr::to_polish);
(linearization, powers_of_alpha)
}

MODIFY
kimchi/src/plonk_sponge.rs
kimchi/src/plonk_sponge.rs
@@ -17,7 +17,7 @@ pub trait FrSponge<Fr: Field> {
/// Absorbs a slice of field elements into the sponge.
fn absorb_multiple(&mut self, x: &[Fr]);
- /// Creates a [ScalarChallenge] by squeezing the sponge.
+ /// Creates a [`ScalarChallenge`] by squeezing the sponge.
fn challenge(&mut self) -> ScalarChallenge<Fr>;
/// Consumes the sponge and returns the current digest, by squeezing.

MODIFY
kimchi/src/proof.rs
kimchi/src/proof.rs
@@ -143,6 +143,11 @@ where
//~ spec:endcode
impl<F> ProofEvaluations<F> {
+ /// Transpose the `ProofEvaluations`.
+ ///
+ /// # Panics
+ ///
+ /// Will panic if `ProofEvaluation` is None.
pub fn transpose<const N: usize>(
evals: [&ProofEvaluations<F>; N],
) -> ProofEvaluations<[&F; N]> {

MODIFY
kimchi/src/prover.rs
kimchi/src/prover.rs
@@ -135,7 +135,15 @@ where
}
/// This function constructs prover's recursive zk-proof from the witness & the `ProverIndex` against SRS instance
- #[allow(clippy::needless_pass_by_value, clippy::too_many_lines)]
+ ///
+ /// # Errors
+ ///
+ /// Will give error if inputs(like `lookup_context.joint_lookup_table_d8`) are None.
+ #[allow(
+ clippy::needless_pass_by_value,
+ clippy::too_many_lines,
+ clippy::cast_possible_truncation
+ )]
pub fn create_recursive<
EFqSponge: Clone + FqSponge<G::BaseField, G, G::ScalarField>,
EFrSponge: FrSponge<G::ScalarField>,

MODIFY
kimchi/src/prover_index.rs
kimchi/src/prover_index.rs
@@ -57,6 +57,10 @@ pub struct ProverIndex<G: KimchiCurve> {
impl<G: KimchiCurve> ProverIndex<G> {
/// this function compiles the index from constraints
+ ///
+ /// # Panics
+ ///
+ /// Will panic if `polynomial segment size` is bigger than `circuit`.
pub fn create(
mut cs: ConstraintSystem<G::ScalarField>,
endo_q: G::ScalarField,
@@ -145,6 +149,11 @@ pub mod testing {
use commitment_dlog::srs::endos;
use mina_curves::pasta::{pallas::Pallas, vesta::Vesta, Fp};
+ /// Create new index for lookups.
+ ///
+ /// # Panics
+ ///
+ /// Will panic if `constraint system` is not built with `gates` input.
#[must_use]
pub fn new_index_for_test_with_lookups(
gates: Vec<CircuitGate<Fp>>,

MODIFY
kimchi/src/snarky/constraint_system.rs
kimchi/src/snarky/constraint_system.rs
@@ -52,7 +52,7 @@ impl Position<usize> {
}
/** A gate/row/constraint consists of a type (kind), a row, the other cells its columns/cells are
-connected to (wired_to), and the selector polynomial associated with the gate. */
+connected to (`wired_to`), and the selector polynomial associated with the gate. */
struct GateSpec<Row, Field> {
kind: GateType,
wired_to: Vec<Position<Row>>,
@@ -60,7 +60,7 @@ struct GateSpec<Row, Field> {
}
impl<Row, Field> GateSpec<Row, Field> {
- /** Applies a function [f] to the [row] of [t] and all the rows of its [wired_to]. */
+ /** Applies a function [f] to the [row] of [t] and all the rows of its [`wired_to`]. */
fn map_rows<Row2, F: Fn(Row) -> Row2>(self, f: F) -> GateSpec<Row2, Field> {
let GateSpec {
kind,
@@ -285,9 +285,9 @@ impl<Field: PrimeField, Gates: GateVector<Field>> SnarkyConstraintSystem<Field,
res
}
- /** Compute the witness, given the constraint system `sys`
- and a function that converts the indexed secret inputs to their concrete values.
- */
+ /// Compute the witness, given the constraint system `sys`
+ /// and a function that converts the indexed secret inputs to their concrete values.
+ ///
/// # Panics
///
/// Will panic if some inputs like `public_input_size` are unknown(None value).
@@ -368,7 +368,8 @@ impl<Field: PrimeField, Gates: GateVector<Field>> SnarkyConstraintSystem<Field,
self.auxiliary_input_size
}
- /** Returns the number of public inputs. */
+ /// Returns the number of public inputs.
+ ///
/// # Panics
///
/// Will panic if `public_input_size` is None.
@@ -772,6 +773,12 @@ impl<Field: PrimeField, Gates: GateVector<Field>> SnarkyConstraintSystem<Field,
}
}
+ /// Applies the basic `SnarkyConstraint`.
+ /// Simply, place the values of `selector`(`sl`, `sr`, `so` ...) and `input`(`l`, `r`, `o`, `m`).
+ ///
+ /// # Panics
+ ///
+ /// Will panic if `constant selector` constraints are not matching.
#[allow(clippy::too_many_lines)]
pub fn add_basic_snarky_constraint<Cvar>(&mut self, constraint: BasicSnarkyConstraint<Cvar>)
where
@@ -1011,7 +1018,7 @@ impl<Field: PrimeField, Gates: GateVector<Field>> SnarkyConstraintSystem<Field,
}
}
- ///
+ /// Applies the `KimchiConstraint(s)` to the `circuit`.
///
/// # Panics
///

MODIFY
kimchi/src/verifier.rs
kimchi/src/verifier.rs
@@ -35,6 +35,14 @@ where
G::BaseField: PrimeField,
{
/// This function runs the random oracle argument
+ ///
+ /// # Errors
+ ///
+ /// Will give error if `commitment(s)` are invalid(missing or wrong length), or `proof` is verified as invalid.
+ ///
+ /// # Panics
+ ///
+ /// Will panic if `PolishToken` evaluation is invalid.
#[allow(clippy::too_many_lines)]
pub fn oracles<
EFqSponge: Clone + FqSponge<G::BaseField, G, G::ScalarField>,
@@ -240,8 +248,6 @@ where
]
};
- println!("verifier public eval: {:?}", public_evals);
-
//~ 1. Absorb the unique evaluation of ft: $ft(\zeta\omega)$.
fr_sponge.absorb(&self.ft_eval1);
@@ -869,6 +875,10 @@ where
}
/// Verify a proof [`ProverProof`] using a [`VerifierIndex`] and a `group_map`.
+///
+/// # Errors
+///
+/// Will give error if `proof(s)` are not verified as valid.
pub fn verify<G, EFqSponge, EFrSponge>(
group_map: &G::Map,
verifier_index: &VerifierIndex<G>,
@@ -888,6 +898,10 @@ where
/// proofs: vector of Plonk proofs
/// index: `VerifierIndex`
/// RETURN: verification status
+///
+/// # Errors
+///
+/// Will give error if `srs` of `proof` is invalid or `verify` process fails.
pub fn batch_verify<G, EFqSponge, EFrSponge>(
group_map: &G::Map,
proofs: &[(&VerifierIndex<G>, &ProverProof<G>)],

Fix the pedantic lints (3)