Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Do some additional cleanup pre-release (0xPolygonZero#1532)
Browse files Browse the repository at this point in the history
* Add Debug impl for types

* Remove outdated clippy lint exceptions

* Hide internal custom gate methods and make some const
  • Loading branch information
Nashtare authored Feb 19, 2024
1 parent 4a620f4 commit 598ac87
Show file tree
Hide file tree
Showing 34 changed files with 87 additions and 61 deletions.
4 changes: 2 additions & 2 deletions field/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![allow(incomplete_features)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::type_complexity)]
#![allow(clippy::len_without_is_empty)]
#![allow(clippy::needless_range_loop)]
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(missing_debug_implementations)]
#![feature(specialization)]
#![cfg_attr(not(test), no_std)]
#![cfg(not(test))]
Expand Down
2 changes: 1 addition & 1 deletion field/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ pub trait PrimeField64: PrimeField + Field64 {
}

/// An iterator over the powers of a certain base element `b`: `b^0, b^1, b^2, ...`.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct Powers<F: Field> {
base: F,
current: F,
Expand Down
1 change: 1 addition & 0 deletions field/src/zero_poly_coset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::packed::PackedField;
use crate::types::Field;

/// Precomputations of the evaluation of `Z_H(X) = X^n - 1` on a coset `gK` with `H <= K`.
#[derive(Debug)]
pub struct ZeroPolyOnCoset<F: Field> {
/// `n = |H|`.
n: F,
Expand Down
10 changes: 9 additions & 1 deletion plonky2/src/fri/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::hash::hash_types::RichField;
use crate::iop::ext_target::ExtensionTarget;

/// Describes an instance of a FRI-based batch opening.
#[derive(Debug)]
pub struct FriInstanceInfo<F: RichField + Extendable<D>, const D: usize> {
/// The oracles involved, not counting oracles created during the commit phase.
pub oracles: Vec<FriOracleInfo>,
Expand All @@ -18,26 +19,29 @@ pub struct FriInstanceInfo<F: RichField + Extendable<D>, const D: usize> {
}

/// Describes an instance of a FRI-based batch opening.
#[derive(Debug)]
pub struct FriInstanceInfoTarget<const D: usize> {
/// The oracles involved, not counting oracles created during the commit phase.
pub oracles: Vec<FriOracleInfo>,
/// Batches of openings, where each batch is associated with a particular point.
pub batches: Vec<FriBatchInfoTarget<D>>,
}

#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub struct FriOracleInfo {
pub num_polys: usize,
pub blinding: bool,
}

/// A batch of openings at a particular point.
#[derive(Debug)]
pub struct FriBatchInfo<F: RichField + Extendable<D>, const D: usize> {
pub point: F::Extension,
pub polynomials: Vec<FriPolynomialInfo>,
}

/// A batch of openings at a particular point.
#[derive(Debug)]
pub struct FriBatchInfoTarget<const D: usize> {
pub point: ExtensionTarget<D>,
pub polynomials: Vec<FriPolynomialInfo>,
Expand Down Expand Up @@ -66,21 +70,25 @@ impl FriPolynomialInfo {
}

/// Opened values of each polynomial.
#[derive(Debug)]
pub struct FriOpenings<F: RichField + Extendable<D>, const D: usize> {
pub batches: Vec<FriOpeningBatch<F, D>>,
}

/// Opened values of each polynomial that's opened at a particular point.
#[derive(Debug)]
pub struct FriOpeningBatch<F: RichField + Extendable<D>, const D: usize> {
pub values: Vec<F::Extension>,
}

/// Opened values of each polynomial.
#[derive(Debug)]
pub struct FriOpeningsTarget<const D: usize> {
pub batches: Vec<FriOpeningBatchTarget<D>>,
}

/// Opened values of each polynomial that's opened at a particular point.
#[derive(Debug)]
pub struct FriOpeningBatchTarget<const D: usize> {
pub values: Vec<ExtensionTarget<D>>,
}
2 changes: 1 addition & 1 deletion plonky2/src/gadgets/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F, D> for Equ
}

/// Represents a base arithmetic operation in the circuit. Used to memoize results.
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub(crate) struct BaseArithmeticOperation<F: Field64> {
const_0: F,
const_1: F,
Expand Down
4 changes: 2 additions & 2 deletions plonky2/src/gadgets/arithmetic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F, D>
}

/// An iterator over the powers of a certain base element `b`: `b^0, b^1, b^2, ...`.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct PowersTarget<const D: usize> {
base: ExtensionTarget<D>,
current: ExtensionTarget<D>,
Expand Down Expand Up @@ -584,7 +584,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
}

/// Represents an extension arithmetic operation in the circuit. Used to memoize results.
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub(crate) struct ExtensionArithmeticOperation<F: Field64 + Extendable<D>, const D: usize> {
const_0: F,
const_1: F,
Expand Down
1 change: 1 addition & 0 deletions plonky2/src/gadgets/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl<const D: usize> PolynomialCoeffsExtTarget<D> {
}
}

#[derive(Debug)]
pub struct PolynomialCoeffsExtAlgebraTarget<const D: usize>(pub Vec<ExtensionAlgebraTarget<D>>);

impl<const D: usize> PolynomialCoeffsExtAlgebraTarget<D> {
Expand Down
8 changes: 4 additions & 4 deletions plonky2/src/gates/arithmetic_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ impl ArithmeticGate {
config.num_routed_wires / wires_per_op
}

pub const fn wire_ith_multiplicand_0(i: usize) -> usize {
pub(crate) const fn wire_ith_multiplicand_0(i: usize) -> usize {
4 * i
}
pub const fn wire_ith_multiplicand_1(i: usize) -> usize {
pub(crate) const fn wire_ith_multiplicand_1(i: usize) -> usize {
4 * i + 1
}
pub const fn wire_ith_addend(i: usize) -> usize {
pub(crate) const fn wire_ith_addend(i: usize) -> usize {
4 * i + 2
}
pub const fn wire_ith_output(i: usize) -> usize {
pub(crate) const fn wire_ith_output(i: usize) -> usize {
4 * i + 3
}
}
Expand Down
8 changes: 4 additions & 4 deletions plonky2/src/gates/arithmetic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ impl<const D: usize> ArithmeticExtensionGate<D> {
config.num_routed_wires / wires_per_op
}

pub const fn wires_ith_multiplicand_0(i: usize) -> Range<usize> {
pub(crate) const fn wires_ith_multiplicand_0(i: usize) -> Range<usize> {
4 * D * i..4 * D * i + D
}
pub const fn wires_ith_multiplicand_1(i: usize) -> Range<usize> {
pub(crate) const fn wires_ith_multiplicand_1(i: usize) -> Range<usize> {
4 * D * i + D..4 * D * i + 2 * D
}
pub const fn wires_ith_addend(i: usize) -> Range<usize> {
pub(crate) const fn wires_ith_addend(i: usize) -> Range<usize> {
4 * D * i + 2 * D..4 * D * i + 3 * D
}
pub const fn wires_ith_output(i: usize) -> Range<usize> {
pub(crate) const fn wires_ith_output(i: usize) -> Range<usize> {
4 * D * i + 3 * D..4 * D * i + 4 * D
}
}
Expand Down
6 changes: 3 additions & 3 deletions plonky2/src/gates/base_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ impl<const B: usize> BaseSumGate<B> {
Self::new(num_limbs)
}

pub const WIRE_SUM: usize = 0;
pub const START_LIMBS: usize = 1;
pub(crate) const WIRE_SUM: usize = 0;
pub(crate) const START_LIMBS: usize = 1;

/// Returns the index of the `i`th limb wire.
pub const fn limbs(&self) -> Range<usize> {
pub(crate) const fn limbs(&self) -> Range<usize> {
Self::START_LIMBS..Self::START_LIMBS + self.num_limbs
}
}
Expand Down
4 changes: 2 additions & 2 deletions plonky2/src/gates/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ impl ConstantGate {
Self { num_consts }
}

pub fn const_input(&self, i: usize) -> usize {
const fn const_input(&self, i: usize) -> usize {
debug_assert!(i < self.num_consts);
i
}

pub fn wire_output(&self, i: usize) -> usize {
const fn wire_output(&self, i: usize) -> usize {
debug_assert!(i < self.num_consts);
i
}
Expand Down
12 changes: 6 additions & 6 deletions plonky2/src/gates/coset_interpolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,31 +141,31 @@ impl<F: RichField + Extendable<D>, const D: usize> CosetInterpolationGate<F, D>
self.start_intermediates()
}

fn num_intermediates(&self) -> usize {
(self.num_points() - 2) / (self.degree() - 1)
const fn num_intermediates(&self) -> usize {
(self.num_points() - 2) / (self.degree - 1)
}

/// The wires corresponding to the i'th intermediate evaluation.
fn wires_intermediate_eval(&self, i: usize) -> Range<usize> {
const fn wires_intermediate_eval(&self, i: usize) -> Range<usize> {
debug_assert!(i < self.num_intermediates());
let start = self.start_intermediates() + D * i;
start..start + D
}

/// The wires corresponding to the i'th intermediate product.
fn wires_intermediate_prod(&self, i: usize) -> Range<usize> {
const fn wires_intermediate_prod(&self, i: usize) -> Range<usize> {
debug_assert!(i < self.num_intermediates());
let start = self.start_intermediates() + D * (self.num_intermediates() + i);
start..start + D
}

/// End of wire indices, exclusive.
fn end(&self) -> usize {
const fn end(&self) -> usize {
self.start_intermediates() + D * (2 * self.num_intermediates() + 1)
}

/// Wire indices of the shifted point to evaluate the interpolant at.
fn wires_shifted_evaluation_point(&self) -> Range<usize> {
const fn wires_shifted_evaluation_point(&self) -> Range<usize> {
let start = self.start_intermediates() + D * 2 * self.num_intermediates();
start..start + D
}
Expand Down
6 changes: 3 additions & 3 deletions plonky2/src/gates/exponentiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ impl<F: RichField + Extendable<D>, const D: usize> ExponentiationGate<F, D> {
max_for_routed_wires.min(max_for_wires)
}

pub const fn wire_base(&self) -> usize {
pub(crate) const fn wire_base(&self) -> usize {
0
}

/// The `i`th bit of the exponent, in little-endian order.
pub fn wire_power_bit(&self, i: usize) -> usize {
pub(crate) const fn wire_power_bit(&self, i: usize) -> usize {
debug_assert!(i < self.num_power_bits);
1 + i
}
Expand All @@ -69,7 +69,7 @@ impl<F: RichField + Extendable<D>, const D: usize> ExponentiationGate<F, D> {
1 + self.num_power_bits
}

pub fn wire_intermediate_value(&self, i: usize) -> usize {
pub(crate) const fn wire_intermediate_value(&self, i: usize) -> usize {
debug_assert!(i < self.num_power_bits);
2 + self.num_power_bits + i
}
Expand Down
2 changes: 1 addition & 1 deletion plonky2/src/gates/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ pub struct CurrentSlot<F: RichField + Extendable<D>, const D: usize> {
}

/// A gate along with any constants used to configure it.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct GateInstance<F: RichField + Extendable<D>, const D: usize> {
pub gate_ref: GateRef<F, D>,
pub constants: Vec<F>,
Expand Down
6 changes: 3 additions & 3 deletions plonky2/src/gates/multiplication_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ impl<const D: usize> MulExtensionGate<D> {
config.num_routed_wires / wires_per_op
}

pub const fn wires_ith_multiplicand_0(i: usize) -> Range<usize> {
pub(crate) const fn wires_ith_multiplicand_0(i: usize) -> Range<usize> {
3 * D * i..3 * D * i + D
}
pub const fn wires_ith_multiplicand_1(i: usize) -> Range<usize> {
pub(crate) const fn wires_ith_multiplicand_1(i: usize) -> Range<usize> {
3 * D * i + D..3 * D * i + 2 * D
}
pub const fn wires_ith_output(i: usize) -> Range<usize> {
pub(crate) const fn wires_ith_output(i: usize) -> Range<usize> {
3 * D * i + 2 * D..3 * D * i + 3 * D
}
}
Expand Down
1 change: 1 addition & 0 deletions plonky2/src/gates/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBaseBa
use crate::util::serialization::{Buffer, IoResult};

/// A gate which does nothing.
#[derive(Debug)]
pub struct NoopGate;

impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for NoopGate {
Expand Down
14 changes: 7 additions & 7 deletions plonky2/src/gates/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ impl<F: RichField + Extendable<D>, const D: usize> PoseidonGate<F, D> {
}

/// The wire index for the `i`th input to the permutation.
pub const fn wire_input(i: usize) -> usize {
pub(crate) const fn wire_input(i: usize) -> usize {
i
}

/// The wire index for the `i`th output to the permutation.
pub const fn wire_output(i: usize) -> usize {
pub(crate) const fn wire_output(i: usize) -> usize {
SPONGE_WIDTH + i
}

/// If this is set to 1, the first four inputs will be swapped with the next four inputs. This
/// is useful for ordering hashes in Merkle proofs. Otherwise, this should be set to 0.
pub const WIRE_SWAP: usize = 2 * SPONGE_WIDTH;
pub(crate) const WIRE_SWAP: usize = 2 * SPONGE_WIDTH;

const START_DELTA: usize = 2 * SPONGE_WIDTH + 1;

/// A wire which stores `swap * (input[i + 4] - input[i])`; used to compute the swapped inputs.
fn wire_delta(i: usize) -> usize {
const fn wire_delta(i: usize) -> usize {
assert!(i < 4);
Self::START_DELTA + i
}
Expand All @@ -64,7 +64,7 @@ impl<F: RichField + Extendable<D>, const D: usize> PoseidonGate<F, D> {

/// A wire which stores the input of the `i`-th S-box of the `round`-th round of the first set
/// of full rounds.
fn wire_full_sbox_0(round: usize, i: usize) -> usize {
const fn wire_full_sbox_0(round: usize, i: usize) -> usize {
debug_assert!(
round != 0,
"First round S-box inputs are not stored as wires"
Expand All @@ -78,7 +78,7 @@ impl<F: RichField + Extendable<D>, const D: usize> PoseidonGate<F, D> {
Self::START_FULL_0 + SPONGE_WIDTH * (poseidon::HALF_N_FULL_ROUNDS - 1);

/// A wire which stores the input of the S-box of the `round`-th round of the partial rounds.
fn wire_partial_sbox(round: usize) -> usize {
const fn wire_partial_sbox(round: usize) -> usize {
debug_assert!(round < poseidon::N_PARTIAL_ROUNDS);
Self::START_PARTIAL + round
}
Expand All @@ -87,7 +87,7 @@ impl<F: RichField + Extendable<D>, const D: usize> PoseidonGate<F, D> {

/// A wire which stores the input of the `i`-th S-box of the `round`-th round of the second set
/// of full rounds.
fn wire_full_sbox_1(round: usize, i: usize) -> usize {
const fn wire_full_sbox_1(round: usize, i: usize) -> usize {
debug_assert!(round < poseidon::HALF_N_FULL_ROUNDS);
debug_assert!(i < SPONGE_WIDTH);
Self::START_FULL_1 + SPONGE_WIDTH * round + i
Expand Down
4 changes: 2 additions & 2 deletions plonky2/src/gates/poseidon_mds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ impl<F: RichField + Extendable<D> + Poseidon, const D: usize> PoseidonMdsGate<F,
Self(PhantomData)
}

pub fn wires_input(i: usize) -> Range<usize> {
pub(crate) const fn wires_input(i: usize) -> Range<usize> {
assert!(i < SPONGE_WIDTH);
i * D..(i + 1) * D
}

pub fn wires_output(i: usize) -> Range<usize> {
pub(crate) const fn wires_output(i: usize) -> Range<usize> {
assert!(i < SPONGE_WIDTH);
(SPONGE_WIDTH + i) * D..(SPONGE_WIDTH + i + 1) * D
}
Expand Down
3 changes: 2 additions & 1 deletion plonky2/src/gates/public_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ use crate::plonk::vars::{
use crate::util::serialization::{Buffer, IoResult};

/// A gate whose first four wires will be equal to a hash of public inputs.
#[derive(Debug)]
pub struct PublicInputGate;

impl PublicInputGate {
pub const fn wires_public_inputs_hash() -> Range<usize> {
pub(crate) const fn wires_public_inputs_hash() -> Range<usize> {
0..4
}
}
Expand Down
Loading

0 comments on commit 598ac87

Please sign in to comment.