From 49b2324f0a7a764971015f1f5592965486c49434 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 30 Nov 2022 00:12:17 +0000 Subject: [PATCH] Replace unnecessary dependencies on `FieldExt` trait --- halo2_gadgets/CHANGELOG.md | 4 ++ halo2_gadgets/src/ecc/chip/mul.rs | 15 +++---- halo2_gadgets/src/poseidon.rs | 20 ++++----- halo2_gadgets/src/poseidon/pow5.rs | 19 ++++---- halo2_gadgets/src/poseidon/primitives.rs | 21 ++++----- .../src/poseidon/primitives/grain.rs | 9 ++-- .../src/poseidon/primitives/p128pow5t3.rs | 6 +-- halo2_gadgets/src/sha256.rs | 8 ++-- .../table16/compression/compression_gates.rs | 11 +++-- halo2_gadgets/src/sha256/table16/gates.rs | 7 +-- .../message_schedule/schedule_gates.rs | 8 ++-- .../src/sha256/table16/spread_table.rs | 15 ++++--- .../src/sinsemilla/chip/hash_to_point.rs | 19 ++++---- halo2_gadgets/src/sinsemilla/message.rs | 20 ++++----- halo2_gadgets/src/utilities.rs | 16 +++---- halo2_gadgets/src/utilities/cond_swap.rs | 22 +++++----- .../src/utilities/decompose_running_sum.rs | 16 +++---- .../src/utilities/lookup_range_check.rs | 22 +++++----- halo2_proofs/CHANGELOG.md | 4 ++ halo2_proofs/benches/dev_lookup.rs | 6 +-- halo2_proofs/benches/plonk.rs | 13 +++--- halo2_proofs/examples/circuit-layout.rs | 13 +++--- halo2_proofs/examples/simple-example.rs | 18 ++++---- halo2_proofs/examples/two-chip.rs | 43 +++++++++---------- halo2_proofs/src/arithmetic.rs | 2 +- halo2_proofs/src/circuit.rs | 7 +-- halo2_proofs/src/dev.rs | 20 ++++----- halo2_proofs/src/dev/failure.rs | 7 ++- halo2_proofs/src/dev/util.rs | 9 ++-- halo2_proofs/src/plonk/lookup/verifier.rs | 4 +- halo2_proofs/src/poly.rs | 4 +- halo2_proofs/src/poly/commitment.rs | 14 +++--- halo2_proofs/src/poly/domain.rs | 2 +- halo2_proofs/src/poly/evaluator.rs | 10 ++--- halo2_proofs/src/poly/multiopen.rs | 7 +-- halo2_proofs/tests/plonk_api.rs | 13 +++--- 36 files changed, 227 insertions(+), 227 deletions(-) diff --git a/halo2_gadgets/CHANGELOG.md b/halo2_gadgets/CHANGELOG.md index 53ce5943..cdf730b5 100644 --- a/halo2_gadgets/CHANGELOG.md +++ b/halo2_gadgets/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to Rust's notion of ### Added - `halo2_gadgets::poseidon::primitives::generate_constants` +### Changed +- APIs with `F: pasta_curves::arithmetic::FieldExt` bounds have been changed to + use `ff` traits directly. + ## [0.2.0] - 2022-06-23 ### Added - `halo2_gadgets::utilities::RangeConstrained>::bitrange_of` diff --git a/halo2_gadgets/src/ecc/chip/mul.rs b/halo2_gadgets/src/ecc/chip/mul.rs index 9fda8091..8e857ae4 100644 --- a/halo2_gadgets/src/ecc/chip/mul.rs +++ b/halo2_gadgets/src/ecc/chip/mul.rs @@ -8,9 +8,8 @@ use std::{ ops::{Deref, Range}, }; -use ff::PrimeField; +use ff::{Field, PrimeField}; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{AssignedCell, Layouter, Region, Value}, plonk::{Advice, Assigned, Column, ConstraintSystem, Constraints, Error, Selector}, poly::Rotation, @@ -385,8 +384,8 @@ impl Config { #[derive(Clone, Debug)] // `x`-coordinate of the accumulator. -struct X(AssignedCell, F>); -impl Deref for X { +struct X(AssignedCell, F>); +impl Deref for X { type Target = AssignedCell, F>; fn deref(&self) -> &Self::Target { @@ -396,8 +395,8 @@ impl Deref for X { #[derive(Clone, Debug)] // `y`-coordinate of the accumulator. -struct Y(AssignedCell, F>); -impl Deref for Y { +struct Y(AssignedCell, F>); +impl Deref for Y { type Target = AssignedCell, F>; fn deref(&self) -> &Self::Target { @@ -407,8 +406,8 @@ impl Deref for Y { #[derive(Clone, Debug)] // Cumulative sum `z` used to decompose the scalar. -struct Z(AssignedCell); -impl Deref for Z { +struct Z(AssignedCell); +impl Deref for Z { type Target = AssignedCell; fn deref(&self) -> &Self::Target { diff --git a/halo2_gadgets/src/poseidon.rs b/halo2_gadgets/src/poseidon.rs index 13500751..4913ec6c 100644 --- a/halo2_gadgets/src/poseidon.rs +++ b/halo2_gadgets/src/poseidon.rs @@ -27,7 +27,7 @@ pub enum PaddedWord { } /// The set of circuit instructions required to use the Poseidon permutation. -pub trait PoseidonInstructions, const T: usize, const RATE: usize>: +pub trait PoseidonInstructions, const T: usize, const RATE: usize>: Chip { /// Variable representing the word over which the Poseidon permutation operates. @@ -45,7 +45,7 @@ pub trait PoseidonInstructions, const T: usize, /// /// [`Hash`]: self::Hash pub trait PoseidonSpongeInstructions< - F: FieldExt, + F: Field, S: Spec, D: Domain, const T: usize, @@ -71,7 +71,7 @@ pub trait PoseidonSpongeInstructions< /// A word over which the Poseidon permutation operates. #[derive(Debug)] pub struct Word< - F: FieldExt, + F: Field, PoseidonChip: PoseidonInstructions, S: Spec, const T: usize, @@ -81,7 +81,7 @@ pub struct Word< } impl< - F: FieldExt, + F: Field, PoseidonChip: PoseidonInstructions, S: Spec, const T: usize, @@ -100,7 +100,7 @@ impl< } fn poseidon_sponge< - F: FieldExt, + F: Field, PoseidonChip: PoseidonSpongeInstructions, S: Spec, D: Domain, @@ -122,7 +122,7 @@ fn poseidon_sponge< /// A Poseidon sponge. #[derive(Debug)] pub struct Sponge< - F: FieldExt, + F: Field, PoseidonChip: PoseidonSpongeInstructions, S: Spec, M: SpongeMode, @@ -137,7 +137,7 @@ pub struct Sponge< } impl< - F: FieldExt, + F: Field, PoseidonChip: PoseidonSpongeInstructions, S: Spec, D: Domain, @@ -210,7 +210,7 @@ impl< } impl< - F: FieldExt, + F: Field, PoseidonChip: PoseidonSpongeInstructions, S: Spec, D: Domain, @@ -241,7 +241,7 @@ impl< /// A Poseidon hash function, built around a sponge. #[derive(Debug)] pub struct Hash< - F: FieldExt, + F: Field, PoseidonChip: PoseidonSpongeInstructions, S: Spec, D: Domain, @@ -252,7 +252,7 @@ pub struct Hash< } impl< - F: FieldExt, + F: Field, PoseidonChip: PoseidonSpongeInstructions, S: Spec, D: Domain, diff --git a/halo2_gadgets/src/poseidon/pow5.rs b/halo2_gadgets/src/poseidon/pow5.rs index 62fe33fa..9c98eb75 100644 --- a/halo2_gadgets/src/poseidon/pow5.rs +++ b/halo2_gadgets/src/poseidon/pow5.rs @@ -1,6 +1,7 @@ use std::convert::TryInto; use std::iter; +use group::ff::Field; use halo2_proofs::{ arithmetic::FieldExt, circuit::{AssignedCell, Cell, Chip, Layouter, Region, Value}, @@ -18,7 +19,7 @@ use crate::utilities::Var; /// Configuration for a [`Pow5Chip`]. #[derive(Clone, Debug)] -pub struct Pow5Config { +pub struct Pow5Config { pub(crate) state: [Column; WIDTH], partial_sbox: Column, rc_a: [Column; WIDTH], @@ -40,11 +41,11 @@ pub struct Pow5Config { /// The chip is implemented using a single round per row for full rounds, and two rounds /// per row for partial rounds. #[derive(Debug)] -pub struct Pow5Chip { +pub struct Pow5Chip { config: Pow5Config, } -impl Pow5Chip { +impl Pow5Chip { /// Configures this chip for use in a circuit. /// /// # Side-effects @@ -209,7 +210,7 @@ impl Pow5Chip Chip for Pow5Chip { +impl Chip for Pow5Chip { type Config = Pow5Config; type Loaded = (); @@ -403,21 +404,21 @@ impl< /// A word in the Poseidon state. #[derive(Clone, Debug)] -pub struct StateWord(AssignedCell); +pub struct StateWord(AssignedCell); -impl From> for AssignedCell { +impl From> for AssignedCell { fn from(state_word: StateWord) -> AssignedCell { state_word.0 } } -impl From> for StateWord { +impl From> for StateWord { fn from(cell_value: AssignedCell) -> StateWord { StateWord(cell_value) } } -impl Var for StateWord { +impl Var for StateWord { fn cell(&self) -> Cell { self.0.cell() } @@ -428,7 +429,7 @@ impl Var for StateWord { } #[derive(Debug)] -struct Pow5State([StateWord; WIDTH]); +struct Pow5State([StateWord; WIDTH]); impl Pow5State { fn full_round( diff --git a/halo2_gadgets/src/poseidon/primitives.rs b/halo2_gadgets/src/poseidon/primitives.rs index 26015017..90631fbb 100644 --- a/halo2_gadgets/src/poseidon/primitives.rs +++ b/halo2_gadgets/src/poseidon/primitives.rs @@ -5,6 +5,7 @@ use std::fmt; use std::iter; use std::marker::PhantomData; +use group::ff::Field; use halo2_proofs::arithmetic::FieldExt; pub(crate) mod fp; @@ -30,7 +31,7 @@ pub(crate) type SpongeRate = [Option; RATE]; pub type Mds = [[F; T]; T]; /// A specification for a Poseidon permutation. -pub trait Spec: fmt::Debug { +pub trait Spec: fmt::Debug { /// The number of full rounds for this specification. /// /// This must be an even number. @@ -80,7 +81,7 @@ pub fn generate_constants, const T: usize, cons } /// Runs the Poseidon permutation on the given state. -pub(crate) fn permute, const T: usize, const RATE: usize>( +pub(crate) fn permute, const T: usize, const RATE: usize>( state: &mut State, mds: &Mds, round_constants: &[[F; T]], @@ -127,7 +128,7 @@ pub(crate) fn permute, const T: usize, const RA }); } -fn poseidon_sponge, const T: usize, const RATE: usize>( +fn poseidon_sponge, const T: usize, const RATE: usize>( state: &mut State, input: Option<&Absorbing>, mds_matrix: &Mds, @@ -184,7 +185,7 @@ impl Absorbing { /// A Poseidon sponge. pub(crate) struct Sponge< - F: FieldExt, + F: Field, S: Spec, M: SpongeMode, const T: usize, @@ -197,7 +198,7 @@ pub(crate) struct Sponge< _marker: PhantomData, } -impl, const T: usize, const RATE: usize> +impl, const T: usize, const RATE: usize> Sponge, T, RATE> { /// Constructs a new sponge for the given Poseidon specification. @@ -255,7 +256,7 @@ impl, const T: usize, const RATE: usize> } } -impl, const T: usize, const RATE: usize> +impl, const T: usize, const RATE: usize> Sponge, T, RATE> { /// Squeezes an element from the sponge. @@ -279,7 +280,7 @@ impl, const T: usize, const RATE: usize> } /// A domain in which a Poseidon hash function is being used. -pub trait Domain { +pub trait Domain { /// Iterator that outputs padding field elements. type Padding: IntoIterator; @@ -325,7 +326,7 @@ impl Domain for Constan /// A Poseidon hash function, built around a sponge. pub struct Hash< - F: FieldExt, + F: Field, S: Spec, D: Domain, const T: usize, @@ -335,7 +336,7 @@ pub struct Hash< _domain: PhantomData, } -impl, D: Domain, const T: usize, const RATE: usize> +impl, D: Domain, const T: usize, const RATE: usize> fmt::Debug for Hash { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -349,7 +350,7 @@ impl, D: Domain, const T: usize, const } } -impl, D: Domain, const T: usize, const RATE: usize> +impl, D: Domain, const T: usize, const RATE: usize> Hash { /// Initializes a new hasher. diff --git a/halo2_gadgets/src/poseidon/primitives/grain.rs b/halo2_gadgets/src/poseidon/primitives/grain.rs index 1d9ad45b..b4ceb672 100644 --- a/halo2_gadgets/src/poseidon/primitives/grain.rs +++ b/halo2_gadgets/src/poseidon/primitives/grain.rs @@ -3,6 +3,7 @@ use std::marker::PhantomData; use bitvec::prelude::*; +use group::ff::{Field, PrimeField}; use halo2_proofs::arithmetic::FieldExt; const STATE: usize = 80; @@ -43,13 +44,13 @@ impl SboxType { } } -pub(super) struct Grain { +pub(super) struct Grain { state: BitArr!(for 80, in u8, Msb0), next_bit: usize, _field: PhantomData, } -impl Grain { +impl Grain { pub(super) fn new(sbox: SboxType, t: u16, r_f: u16, r_p: u16) -> Self { // Initialize the LFSR state. let mut state = bitarr![u8, Msb0; 1; STATE]; @@ -135,7 +136,9 @@ impl Grain { } } } +} +impl Grain { /// Returns the next field element from this Grain instantiation, without using /// rejection sampling. pub(super) fn next_field_element_without_rejection(&mut self) -> F { @@ -165,7 +168,7 @@ impl Grain { } } -impl Iterator for Grain { +impl Iterator for Grain { type Item = bool; fn next(&mut self) -> Option { diff --git a/halo2_gadgets/src/poseidon/primitives/p128pow5t3.rs b/halo2_gadgets/src/poseidon/primitives/p128pow5t3.rs index d0313c87..dffa30bc 100644 --- a/halo2_gadgets/src/poseidon/primitives/p128pow5t3.rs +++ b/halo2_gadgets/src/poseidon/primitives/p128pow5t3.rs @@ -66,7 +66,7 @@ impl Spec for P128Pow5T3 { #[cfg(test)] mod tests { - use ff::PrimeField; + use ff::{Field, PrimeField}; use std::marker::PhantomData; use pasta_curves::arithmetic::FieldExt; @@ -82,9 +82,9 @@ mod tests { /// The same Poseidon specification as poseidon::P128Pow5T3, but constructed /// such that its constants will be generated at runtime. #[derive(Debug)] - pub struct P128Pow5T3Gen(PhantomData); + pub struct P128Pow5T3Gen(PhantomData); - impl P128Pow5T3Gen { + impl P128Pow5T3Gen { #![allow(dead_code)] pub fn new() -> Self { P128Pow5T3Gen(PhantomData::default()) diff --git a/halo2_gadgets/src/sha256.rs b/halo2_gadgets/src/sha256.rs index 19a658df..3e4cdafa 100644 --- a/halo2_gadgets/src/sha256.rs +++ b/halo2_gadgets/src/sha256.rs @@ -6,8 +6,8 @@ use std::cmp::min; use std::convert::TryInto; use std::fmt; +use group::ff::Field; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{Chip, Layouter}, plonk::Error, }; @@ -22,7 +22,7 @@ pub const BLOCK_SIZE: usize = 16; const DIGEST_SIZE: usize = 8; /// The set of circuit instructions required to use the [`Sha256`] gadget. -pub trait Sha256Instructions: Chip { +pub trait Sha256Instructions: Chip { /// Variable representing the SHA-256 internal state. type State: Clone + fmt::Debug; /// Variable representing a 32-bit word of the input block to the SHA-256 compression @@ -63,14 +63,14 @@ pub struct Sha256Digest([BlockWord; DIGEST_SIZE]); /// A gadget that constrains a SHA-256 invocation. It supports input at a granularity of /// 32 bits. #[derive(Debug)] -pub struct Sha256> { +pub struct Sha256> { chip: CS, state: CS::State, cur_block: Vec, length: usize, } -impl> Sha256 { +impl> Sha256 { /// Create a new hasher instance. pub fn new(chip: Sha256Chip, mut layouter: impl Layouter) -> Result { let state = chip.initialization_vector(&mut layouter)?; diff --git a/halo2_gadgets/src/sha256/table16/compression/compression_gates.rs b/halo2_gadgets/src/sha256/table16/compression/compression_gates.rs index e22a1021..7b4862a3 100644 --- a/halo2_gadgets/src/sha256/table16/compression/compression_gates.rs +++ b/halo2_gadgets/src/sha256/table16/compression/compression_gates.rs @@ -1,13 +1,12 @@ use super::super::{util::*, Gate}; -use halo2_proofs::{ - arithmetic::FieldExt, - plonk::{Constraint, Constraints, Expression}, -}; + +use group::ff::{Field, PrimeField}; +use halo2_proofs::plonk::{Constraint, Constraints, Expression}; use std::marker::PhantomData; -pub struct CompressionGate(PhantomData); +pub struct CompressionGate(PhantomData); -impl CompressionGate { +impl CompressionGate { fn ones() -> Expression { Expression::Constant(F::one()) } diff --git a/halo2_gadgets/src/sha256/table16/gates.rs b/halo2_gadgets/src/sha256/table16/gates.rs index 4f268092..f9b53dc0 100644 --- a/halo2_gadgets/src/sha256/table16/gates.rs +++ b/halo2_gadgets/src/sha256/table16/gates.rs @@ -1,8 +1,9 @@ -use halo2_proofs::{arithmetic::FieldExt, plonk::Expression}; +use group::ff::PrimeField; +use halo2_proofs::plonk::Expression; -pub struct Gate(pub Expression); +pub struct Gate(pub Expression); -impl Gate { +impl Gate { fn ones() -> Expression { Expression::Constant(F::one()) } diff --git a/halo2_gadgets/src/sha256/table16/message_schedule/schedule_gates.rs b/halo2_gadgets/src/sha256/table16/message_schedule/schedule_gates.rs index fab51bd3..b1021a0a 100644 --- a/halo2_gadgets/src/sha256/table16/message_schedule/schedule_gates.rs +++ b/halo2_gadgets/src/sha256/table16/message_schedule/schedule_gates.rs @@ -1,10 +1,12 @@ use super::super::Gate; -use halo2_proofs::{arithmetic::FieldExt, plonk::Expression}; + +use group::ff::{Field, PrimeField}; +use halo2_proofs::plonk::Expression; use std::marker::PhantomData; -pub struct ScheduleGate(PhantomData); +pub struct ScheduleGate(PhantomData); -impl ScheduleGate { +impl ScheduleGate { /// s_word for W_16 to W_63 #[allow(clippy::too_many_arguments)] pub fn s_word( diff --git a/halo2_gadgets/src/sha256/table16/spread_table.rs b/halo2_gadgets/src/sha256/table16/spread_table.rs index dc04f7ee..891799eb 100644 --- a/halo2_gadgets/src/sha256/table16/spread_table.rs +++ b/halo2_gadgets/src/sha256/table16/spread_table.rs @@ -1,6 +1,7 @@ use super::{util::*, AssignedBits}; + +use group::ff::{Field, PrimeField}; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{Chip, Layouter, Region, Value}, pasta::pallas, plonk::{Advice, Column, ConstraintSystem, Error, TableColumn}, @@ -153,12 +154,12 @@ pub(super) struct SpreadTableConfig { } #[derive(Clone, Debug)] -pub(super) struct SpreadTableChip { +pub(super) struct SpreadTableChip { config: SpreadTableConfig, _marker: PhantomData, } -impl Chip for SpreadTableChip { +impl Chip for SpreadTableChip { type Config = SpreadTableConfig; type Loaded = (); @@ -171,7 +172,7 @@ impl Chip for SpreadTableChip { } } -impl SpreadTableChip { +impl SpreadTableChip { pub fn configure( meta: &mut ConstraintSystem, input_tag: Column, @@ -250,7 +251,7 @@ impl SpreadTableChip { } impl SpreadTableConfig { - fn generate() -> impl Iterator { + fn generate() -> impl Iterator { (1..=(1 << 16)).scan( (F::zero(), F::zero(), F::zero()), |(tag, dense, spread), i| { @@ -287,8 +288,8 @@ mod tests { use super::{get_tag, SpreadTableChip, SpreadTableConfig}; use rand::Rng; + use group::ff::PrimeField; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{Layouter, SimpleFloorPlanner, Value}, dev::MockProver, pasta::Fp, @@ -303,7 +304,7 @@ mod tests { struct MyCircuit {} - impl Circuit for MyCircuit { + impl Circuit for MyCircuit { type Config = SpreadTableConfig; type FloorPlanner = SimpleFloorPlanner; diff --git a/halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs b/halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs index 25be0efb..001ca1d8 100644 --- a/halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs +++ b/halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs @@ -10,11 +10,8 @@ use halo2_proofs::{ plonk::{Assigned, Error}, }; -use group::ff::{PrimeField, PrimeFieldBits}; -use pasta_curves::{ - arithmetic::{CurveAffine, FieldExt}, - pallas, -}; +use group::ff::{Field, PrimeField, PrimeFieldBits}; +use pasta_curves::{arithmetic::CurveAffine, pallas}; use std::ops::Deref; @@ -379,15 +376,15 @@ where } /// The x-coordinate of the accumulator in a Sinsemilla hash instance. -struct X(AssignedCell, F>); +struct X(AssignedCell, F>); -impl From, F>> for X { +impl From, F>> for X { fn from(cell_value: AssignedCell, F>) -> Self { X(cell_value) } } -impl Deref for X { +impl Deref for X { type Target = AssignedCell, F>; fn deref(&self) -> &AssignedCell, F> { @@ -400,15 +397,15 @@ impl Deref for X { /// This is never actually witnessed until the last round, since it /// can be derived from other variables. Thus it only exists as a field /// element, not a `CellValue`. -struct Y(Value>); +struct Y(Value>); -impl From>> for Y { +impl From>> for Y { fn from(value: Value>) -> Self { Y(value) } } -impl Deref for Y { +impl Deref for Y { type Target = Value>; fn deref(&self) -> &Value> { diff --git a/halo2_gadgets/src/sinsemilla/message.rs b/halo2_gadgets/src/sinsemilla/message.rs index 6bb72e2f..a8bc303c 100644 --- a/halo2_gadgets/src/sinsemilla/message.rs +++ b/halo2_gadgets/src/sinsemilla/message.rs @@ -1,17 +1,15 @@ //! Gadget and chips for the Sinsemilla hash function. -use ff::PrimeFieldBits; -use halo2_proofs::{ - arithmetic::FieldExt, - circuit::{AssignedCell, Cell, Value}, -}; +use ff::{Field, PrimeFieldBits}; +use halo2_proofs::circuit::{AssignedCell, Cell, Value}; + use std::fmt::Debug; /// A [`Message`] composed of several [`MessagePiece`]s. #[derive(Clone, Debug)] -pub struct Message(Vec>); +pub struct Message(Vec>); -impl - From>> for Message +impl From>> + for Message { fn from(pieces: Vec>) -> Self { // A message cannot contain more than `MAX_WORDS` words. @@ -20,7 +18,7 @@ impl } } -impl std::ops::Deref +impl std::ops::Deref for Message { type Target = [MessagePiece]; @@ -35,13 +33,13 @@ impl std:: /// The piece must fit within a base field element, which means its length /// cannot exceed the base field's `NUM_BITS`. #[derive(Clone, Debug)] -pub struct MessagePiece { +pub struct MessagePiece { cell_value: AssignedCell, /// The number of K-bit words in this message piece. num_words: usize, } -impl MessagePiece { +impl MessagePiece { pub fn new(cell_value: AssignedCell, num_words: usize) -> Self { assert!(num_words * K < F::NUM_BITS as usize); Self { diff --git a/halo2_gadgets/src/utilities.rs b/halo2_gadgets/src/utilities.rs index 42b09f63..ae6a507d 100644 --- a/halo2_gadgets/src/utilities.rs +++ b/halo2_gadgets/src/utilities.rs @@ -1,11 +1,11 @@ //! Utility gadgets. -use ff::{Field, PrimeFieldBits}; +use ff::{Field, PrimeField, PrimeFieldBits}; use halo2_proofs::{ circuit::{AssignedCell, Cell, Layouter, Value}, plonk::{Advice, Column, Error, Expression}, }; -use pasta_curves::arithmetic::FieldExt; + use std::marker::PhantomData; use std::ops::Range; @@ -32,7 +32,7 @@ impl FieldValue for AssignedCell { } /// Trait for a variable in the circuit. -pub trait Var: Clone + std::fmt::Debug + From> { +pub trait Var: Clone + std::fmt::Debug + From> { /// The cell at which this variable was allocated. fn cell(&self) -> Cell; @@ -40,7 +40,7 @@ pub trait Var: Clone + std::fmt::Debug + From> { fn value(&self) -> Value; } -impl Var for AssignedCell { +impl Var for AssignedCell { fn cell(&self) -> Cell { self.cell() } @@ -51,7 +51,7 @@ impl Var for AssignedCell { } /// Trait for utilities used across circuits. -pub trait UtilitiesInstructions { +pub trait UtilitiesInstructions { /// Variable in the circuit. type Var: Var; @@ -130,14 +130,14 @@ impl RangeConstrained> { } /// Checks that an expression is either 1 or 0. -pub fn bool_check(value: Expression) -> Expression { +pub fn bool_check(value: Expression) -> Expression { range_check(value, 2) } /// If `a` then `b`, else `c`. Returns (a * b) + (1 - a) * c. /// /// `a` must be a boolean-constrained expression. -pub fn ternary(a: Expression, b: Expression, c: Expression) -> Expression { +pub fn ternary(a: Expression, b: Expression, c: Expression) -> Expression { let one_minus_a = Expression::Constant(F::one()) - a.clone(); a * b + one_minus_a * c } @@ -167,7 +167,7 @@ pub fn bitrange_subset(field_elem: &F, bitrange: Range /// Check that an expression is in the small range [0..range), /// i.e. 0 ≤ word < range. -pub fn range_check(word: Expression, range: usize) -> Expression { +pub fn range_check(word: Expression, range: usize) -> Expression { (1..range).fold(word.clone(), |acc, i| { acc * (Expression::Constant(F::from(i as u64)) - word.clone()) }) diff --git a/halo2_gadgets/src/utilities/cond_swap.rs b/halo2_gadgets/src/utilities/cond_swap.rs index 86194bf2..89245888 100644 --- a/halo2_gadgets/src/utilities/cond_swap.rs +++ b/halo2_gadgets/src/utilities/cond_swap.rs @@ -1,16 +1,18 @@ //! Gadget and chip for a conditional swap utility. use super::{bool_check, ternary, UtilitiesInstructions}; + +use group::ff::{Field, PrimeField}; use halo2_proofs::{ circuit::{AssignedCell, Chip, Layouter, Value}, plonk::{Advice, Column, ConstraintSystem, Constraints, Error, Selector}, poly::Rotation, }; -use pasta_curves::arithmetic::FieldExt; + use std::marker::PhantomData; /// Instructions for a conditional swap gadget. -pub trait CondSwapInstructions: UtilitiesInstructions { +pub trait CondSwapInstructions: UtilitiesInstructions { #[allow(clippy::type_complexity)] /// Given an input pair (a,b) and a `swap` boolean flag, returns /// (b,a) if `swap` is set, else (a,b) if `swap` is not set. @@ -32,7 +34,7 @@ pub struct CondSwapChip { _marker: PhantomData, } -impl Chip for CondSwapChip { +impl Chip for CondSwapChip { type Config = CondSwapConfig; type Loaded = (); @@ -63,11 +65,11 @@ impl CondSwapConfig { } } -impl UtilitiesInstructions for CondSwapChip { +impl UtilitiesInstructions for CondSwapChip { type Var = AssignedCell; } -impl CondSwapInstructions for CondSwapChip { +impl CondSwapInstructions for CondSwapChip { #[allow(clippy::type_complexity)] fn swap( &self, @@ -122,7 +124,7 @@ impl CondSwapInstructions for CondSwapChip { } } -impl CondSwapChip { +impl CondSwapChip { /// Configures this chip for use in a circuit. /// /// # Side-effects @@ -195,25 +197,25 @@ impl CondSwapChip { mod tests { use super::super::UtilitiesInstructions; use super::{CondSwapChip, CondSwapConfig, CondSwapInstructions}; - use group::ff::Field; + use group::ff::{Field, PrimeField}; use halo2_proofs::{ circuit::{Layouter, SimpleFloorPlanner, Value}, dev::MockProver, plonk::{Circuit, ConstraintSystem, Error}, }; - use pasta_curves::{arithmetic::FieldExt, pallas::Base}; + use pasta_curves::pallas::Base; use rand::rngs::OsRng; #[test] fn cond_swap() { #[derive(Default)] - struct MyCircuit { + struct MyCircuit { a: Value, b: Value, swap: Value, } - impl Circuit for MyCircuit { + impl Circuit for MyCircuit { type Config = CondSwapConfig; type FloorPlanner = SimpleFloorPlanner; diff --git a/halo2_gadgets/src/utilities/decompose_running_sum.rs b/halo2_gadgets/src/utilities/decompose_running_sum.rs index e6364f21..a0ee11c7 100644 --- a/halo2_gadgets/src/utilities/decompose_running_sum.rs +++ b/halo2_gadgets/src/utilities/decompose_running_sum.rs @@ -30,13 +30,13 @@ use halo2_proofs::{ }; use super::range_check; -use pasta_curves::arithmetic::FieldExt; + use std::marker::PhantomData; /// The running sum $[z_0, ..., z_W]$. If created in strict mode, $z_W = 0$. #[derive(Debug)] -pub struct RunningSum(Vec>); -impl std::ops::Deref for RunningSum { +pub struct RunningSum(Vec>); +impl std::ops::Deref for RunningSum { type Target = Vec>; fn deref(&self) -> &Vec> { @@ -46,15 +46,13 @@ impl std::ops::Deref for RunningSum { /// Configuration that provides methods for running sum decomposition. #[derive(Debug, Clone, Copy, Eq, PartialEq)] -pub struct RunningSumConfig { +pub struct RunningSumConfig { q_range_check: Selector, z: Column, _marker: PhantomData, } -impl - RunningSumConfig -{ +impl RunningSumConfig { /// Returns the q_range_check selector of this [`RunningSumConfig`]. pub(crate) fn q_range_check(&self) -> Selector { self.q_range_check @@ -228,7 +226,7 @@ mod tests { #[test] fn test_running_sum() { struct MyCircuit< - F: FieldExt + PrimeFieldBits, + F: PrimeFieldBits, const WORD_NUM_BITS: usize, const WINDOW_NUM_BITS: usize, const NUM_WINDOWS: usize, @@ -238,7 +236,7 @@ mod tests { } impl< - F: FieldExt + PrimeFieldBits, + F: PrimeFieldBits, const WORD_NUM_BITS: usize, const WINDOW_NUM_BITS: usize, const NUM_WINDOWS: usize, diff --git a/halo2_gadgets/src/utilities/lookup_range_check.rs b/halo2_gadgets/src/utilities/lookup_range_check.rs index b0f329bd..e57f9c5e 100644 --- a/halo2_gadgets/src/utilities/lookup_range_check.rs +++ b/halo2_gadgets/src/utilities/lookup_range_check.rs @@ -14,8 +14,8 @@ use super::*; /// The running sum $[z_0, ..., z_W]$. If created in strict mode, $z_W = 0$. #[derive(Debug)] -pub struct RunningSum(Vec>); -impl std::ops::Deref for RunningSum { +pub struct RunningSum(Vec>); +impl std::ops::Deref for RunningSum { type Target = Vec>; fn deref(&self) -> &Vec> { @@ -23,7 +23,7 @@ impl std::ops::Deref for RunningSum { } } -impl RangeConstrained> { +impl RangeConstrained> { /// Witnesses a subset of the bits in `value` and constrains them to be the correct /// number of bits. /// @@ -56,7 +56,7 @@ impl RangeConstrained> { /// Configuration that provides methods for a lookup range check. #[derive(Eq, PartialEq, Debug, Clone, Copy)] -pub struct LookupRangeCheckConfig { +pub struct LookupRangeCheckConfig { q_lookup: Selector, q_running: Selector, q_bitshift: Selector, @@ -65,7 +65,7 @@ pub struct LookupRangeCheckConfig _marker: PhantomData, } -impl LookupRangeCheckConfig { +impl LookupRangeCheckConfig { /// The `running_sum` advice column breaks the field element into `K`-bit /// words. It is used to construct the input expression to the lookup /// argument. @@ -395,19 +395,19 @@ mod tests { dev::{FailureLocation, MockProver, VerifyFailure}, plonk::{Circuit, ConstraintSystem, Error}, }; - use pasta_curves::{arithmetic::FieldExt, pallas}; + use pasta_curves::pallas; use std::{convert::TryInto, marker::PhantomData}; #[test] fn lookup_range_check() { #[derive(Clone, Copy)] - struct MyCircuit { + struct MyCircuit { num_words: usize, _marker: PhantomData, } - impl Circuit for MyCircuit { + impl Circuit for MyCircuit { type Config = LookupRangeCheckConfig; type FloorPlanner = SimpleFloorPlanner; @@ -438,7 +438,7 @@ mod tests { (F::from(1 << (self.num_words * K)), F::one(), false), // a word that is just over self.num_words * K bits long ]; - fn expected_zs( + fn expected_zs( element: F, num_words: usize, ) -> Vec { @@ -498,12 +498,12 @@ mod tests { #[test] fn short_range_check() { - struct MyCircuit { + struct MyCircuit { element: Value, num_bits: usize, } - impl Circuit for MyCircuit { + impl Circuit for MyCircuit { type Config = LookupRangeCheckConfig; type FloorPlanner = SimpleFloorPlanner; diff --git a/halo2_proofs/CHANGELOG.md b/halo2_proofs/CHANGELOG.md index a4aa09af..9af2af13 100644 --- a/halo2_proofs/CHANGELOG.md +++ b/halo2_proofs/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to Rust's notion of - `RegionLayouter::instance_value` method added to provide access to instance values within a region. +### Changed +- APIs with `F: pasta_curves::arithmetic::FieldExt` bounds have been changed to + use `ff` traits directly. + ## [0.2.0] - 2022-06-23 ### Added - `halo2_proofs::circuit::Value`, a more usable and type-safe replacement for diff --git a/halo2_proofs/benches/dev_lookup.rs b/halo2_proofs/benches/dev_lookup.rs index 7592b498..0a60a189 100644 --- a/halo2_proofs/benches/dev_lookup.rs +++ b/halo2_proofs/benches/dev_lookup.rs @@ -1,7 +1,7 @@ #[macro_use] extern crate criterion; -use halo2_proofs::arithmetic::FieldExt; +use group::ff::PrimeField; use halo2_proofs::circuit::{Layouter, SimpleFloorPlanner, Value}; use halo2_proofs::dev::MockProver; use halo2_proofs::plonk::*; @@ -14,7 +14,7 @@ use criterion::{BenchmarkId, Criterion}; fn criterion_benchmark(c: &mut Criterion) { #[derive(Clone, Default)] - struct MyCircuit { + struct MyCircuit { _marker: PhantomData, } @@ -25,7 +25,7 @@ fn criterion_benchmark(c: &mut Criterion) { advice: Column, } - impl Circuit for MyCircuit { + impl Circuit for MyCircuit { type Config = MyConfig; type FloorPlanner = SimpleFloorPlanner; diff --git a/halo2_proofs/benches/plonk.rs b/halo2_proofs/benches/plonk.rs index 9cc167ec..8e3dc55e 100644 --- a/halo2_proofs/benches/plonk.rs +++ b/halo2_proofs/benches/plonk.rs @@ -2,7 +2,6 @@ extern crate criterion; use group::ff::Field; -use halo2_proofs::arithmetic::FieldExt; use halo2_proofs::circuit::{Cell, Layouter, SimpleFloorPlanner, Value}; use halo2_proofs::pasta::{EqAffine, Fp}; use halo2_proofs::plonk::*; @@ -31,7 +30,7 @@ fn criterion_benchmark(c: &mut Criterion) { sm: Column, } - trait StandardCs { + trait StandardCs { fn raw_multiply( &self, layouter: &mut impl Layouter, @@ -50,17 +49,17 @@ fn criterion_benchmark(c: &mut Criterion) { } #[derive(Clone)] - struct MyCircuit { + struct MyCircuit { a: Value, k: u32, } - struct StandardPlonk { + struct StandardPlonk { config: PlonkConfig, _marker: PhantomData, } - impl StandardPlonk { + impl StandardPlonk { fn new(config: PlonkConfig) -> Self { StandardPlonk { config, @@ -69,7 +68,7 @@ fn criterion_benchmark(c: &mut Criterion) { } } - impl StandardCs for StandardPlonk { + impl StandardCs for StandardPlonk { fn raw_multiply( &self, layouter: &mut impl Layouter, @@ -174,7 +173,7 @@ fn criterion_benchmark(c: &mut Criterion) { } } - impl Circuit for MyCircuit { + impl Circuit for MyCircuit { type Config = PlonkConfig; type FloorPlanner = SimpleFloorPlanner; diff --git a/halo2_proofs/examples/circuit-layout.rs b/halo2_proofs/examples/circuit-layout.rs index 53971873..5cb05159 100644 --- a/halo2_proofs/examples/circuit-layout.rs +++ b/halo2_proofs/examples/circuit-layout.rs @@ -1,6 +1,5 @@ use ff::Field; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{Cell, Layouter, Region, SimpleFloorPlanner, Value}, pasta::Fp, plonk::{Advice, Assigned, Circuit, Column, ConstraintSystem, Error, Fixed, TableColumn}, @@ -28,7 +27,7 @@ struct PlonkConfig { sl: TableColumn, } -trait StandardCs { +trait StandardCs { fn raw_multiply(&self, region: &mut Region, f: F) -> Result<(Cell, Cell, Cell), Error> where F: FnMut() -> Value<(Assigned, Assigned, Assigned)>; @@ -39,17 +38,17 @@ trait StandardCs { fn lookup_table(&self, layouter: &mut impl Layouter, values: &[FF]) -> Result<(), Error>; } -struct MyCircuit { +struct MyCircuit { a: Value, lookup_table: Vec, } -struct StandardPlonk { +struct StandardPlonk { config: PlonkConfig, _marker: PhantomData, } -impl StandardPlonk { +impl StandardPlonk { fn new(config: PlonkConfig) -> Self { StandardPlonk { config, @@ -58,7 +57,7 @@ impl StandardPlonk { } } -impl StandardCs for StandardPlonk { +impl StandardCs for StandardPlonk { fn raw_multiply( &self, region: &mut Region, @@ -159,7 +158,7 @@ impl StandardCs for StandardPlonk { } } -impl Circuit for MyCircuit { +impl Circuit for MyCircuit { type Config = PlonkConfig; type FloorPlanner = SimpleFloorPlanner; diff --git a/halo2_proofs/examples/simple-example.rs b/halo2_proofs/examples/simple-example.rs index 5691ba60..85b87537 100644 --- a/halo2_proofs/examples/simple-example.rs +++ b/halo2_proofs/examples/simple-example.rs @@ -1,14 +1,14 @@ use std::marker::PhantomData; +use group::ff::Field; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{AssignedCell, Chip, Layouter, Region, SimpleFloorPlanner, Value}, plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Fixed, Instance, Selector}, poly::Rotation, }; // ANCHOR: instructions -trait NumericInstructions: Chip { +trait NumericInstructions: Chip { /// Variable representing a number. type Num; @@ -39,7 +39,7 @@ trait NumericInstructions: Chip { // ANCHOR: chip /// The chip that will implement our instructions! Chips store their own /// config, as well as type markers if necessary. -struct FieldChip { +struct FieldChip { config: FieldConfig, _marker: PhantomData, } @@ -65,7 +65,7 @@ struct FieldConfig { s_mul: Selector, } -impl FieldChip { +impl FieldChip { fn construct(config: >::Config) -> Self { Self { config, @@ -126,7 +126,7 @@ impl FieldChip { // ANCHOR_END: chip-config // ANCHOR: chip-impl -impl Chip for FieldChip { +impl Chip for FieldChip { type Config = FieldConfig; type Loaded = (); @@ -143,9 +143,9 @@ impl Chip for FieldChip { // ANCHOR: instructions-impl /// A variable representing a number. #[derive(Clone)] -struct Number(AssignedCell); +struct Number(AssignedCell); -impl NumericInstructions for FieldChip { +impl NumericInstructions for FieldChip { type Num = Number; fn load_private( @@ -238,13 +238,13 @@ impl NumericInstructions for FieldChip { /// they won't have any value during key generation. During proving, if any of these /// were `None` we would get an error. #[derive(Default)] -struct MyCircuit { +struct MyCircuit { constant: F, a: Value, b: Value, } -impl Circuit for MyCircuit { +impl Circuit for MyCircuit { // Since we are using a single chip for everything, we can just reuse its config. type Config = FieldConfig; type FloorPlanner = SimpleFloorPlanner; diff --git a/halo2_proofs/examples/two-chip.rs b/halo2_proofs/examples/two-chip.rs index f5871c2c..321ce8a5 100644 --- a/halo2_proofs/examples/two-chip.rs +++ b/halo2_proofs/examples/two-chip.rs @@ -1,7 +1,7 @@ use std::marker::PhantomData; +use group::ff::Field; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{AssignedCell, Chip, Layouter, Region, SimpleFloorPlanner, Value}, plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Instance, Selector}, poly::Rotation, @@ -10,9 +10,9 @@ use halo2_proofs::{ // ANCHOR: field-instructions /// A variable representing a number. #[derive(Clone)] -struct Number(AssignedCell); +struct Number(AssignedCell); -trait FieldInstructions: AddInstructions + MulInstructions { +trait FieldInstructions: AddInstructions + MulInstructions { /// Variable representing a number. type Num; @@ -43,7 +43,7 @@ trait FieldInstructions: AddInstructions + MulInstructions { // ANCHOR_END: field-instructions // ANCHOR: add-instructions -trait AddInstructions: Chip { +trait AddInstructions: Chip { /// Variable representing a number. type Num; @@ -58,7 +58,7 @@ trait AddInstructions: Chip { // ANCHOR_END: add-instructions // ANCHOR: mul-instructions -trait MulInstructions: Chip { +trait MulInstructions: Chip { /// Variable representing a number. type Num; @@ -108,28 +108,28 @@ struct MulConfig { // ANCHOR: field-chip /// The top-level chip that will implement the `FieldInstructions`. -struct FieldChip { +struct FieldChip { config: FieldConfig, _marker: PhantomData, } // ANCHOR_END: field-chip // ANCHOR: add-chip -struct AddChip { +struct AddChip { config: AddConfig, _marker: PhantomData, } // ANCHOR END: add-chip // ANCHOR: mul-chip -struct MulChip { +struct MulChip { config: MulConfig, _marker: PhantomData, } // ANCHOR_END: mul-chip // ANCHOR: add-chip-trait-impl -impl Chip for AddChip { +impl Chip for AddChip { type Config = AddConfig; type Loaded = (); @@ -144,7 +144,7 @@ impl Chip for AddChip { // ANCHOR END: add-chip-trait-impl // ANCHOR: add-chip-impl -impl AddChip { +impl AddChip { fn construct(config: >::Config, _loaded: >::Loaded) -> Self { Self { config, @@ -174,7 +174,7 @@ impl AddChip { // ANCHOR END: add-chip-impl // ANCHOR: add-instructions-impl -impl AddInstructions for FieldChip { +impl AddInstructions for FieldChip { type Num = Number; fn add( &self, @@ -189,7 +189,7 @@ impl AddInstructions for FieldChip { } } -impl AddInstructions for AddChip { +impl AddInstructions for AddChip { type Num = Number; fn add( @@ -231,7 +231,7 @@ impl AddInstructions for AddChip { // ANCHOR END: add-instructions-impl // ANCHOR: mul-chip-trait-impl -impl Chip for MulChip { +impl Chip for MulChip { type Config = MulConfig; type Loaded = (); @@ -246,7 +246,7 @@ impl Chip for MulChip { // ANCHOR END: mul-chip-trait-impl // ANCHOR: mul-chip-impl -impl MulChip { +impl MulChip { fn construct(config: >::Config, _loaded: >::Loaded) -> Self { Self { config, @@ -296,7 +296,7 @@ impl MulChip { // ANCHOR_END: mul-chip-impl // ANCHOR: mul-instructions-impl -impl MulInstructions for FieldChip { +impl MulInstructions for FieldChip { type Num = Number; fn mul( &self, @@ -310,7 +310,7 @@ impl MulInstructions for FieldChip { } } -impl MulInstructions for MulChip { +impl MulInstructions for MulChip { type Num = Number; fn mul( @@ -352,7 +352,7 @@ impl MulInstructions for MulChip { // ANCHOR END: mul-instructions-impl // ANCHOR: field-chip-trait-impl -impl Chip for FieldChip { +impl Chip for FieldChip { type Config = FieldConfig; type Loaded = (); @@ -367,7 +367,7 @@ impl Chip for FieldChip { // ANCHOR_END: field-chip-trait-impl // ANCHOR: field-chip-impl -impl FieldChip { +impl FieldChip { fn construct(config: >::Config, _loaded: >::Loaded) -> Self { Self { config, @@ -396,7 +396,7 @@ impl FieldChip { // ANCHOR_END: field-chip-impl // ANCHOR: field-instructions-impl -impl FieldInstructions for FieldChip { +impl FieldInstructions for FieldChip { type Num = Number; fn load_private( @@ -448,13 +448,13 @@ impl FieldInstructions for FieldChip { /// they won't have any value during key generation. During proving, if any of these /// were `Value::unknown()` we would get an error. #[derive(Default)] -struct MyCircuit { +struct MyCircuit { a: Value, b: Value, c: Value, } -impl Circuit for MyCircuit { +impl Circuit for MyCircuit { // Since we are using a single chip for everything, we can just reuse its config. type Config = FieldConfig; type FloorPlanner = SimpleFloorPlanner; @@ -496,7 +496,6 @@ impl Circuit for MyCircuit { #[allow(clippy::many_single_char_names)] fn main() { - use group::ff::Field; use halo2_proofs::{dev::MockProver, pasta::Fp}; use rand_core::OsRng; diff --git a/halo2_proofs/src/arithmetic.rs b/halo2_proofs/src/arithmetic.rs index bff0860f..680487e6 100644 --- a/halo2_proofs/src/arithmetic.rs +++ b/halo2_proofs/src/arithmetic.rs @@ -355,7 +355,7 @@ fn log2_floor(num: usize) -> u32 { /// Returns coefficients of an n - 1 degree polynomial given a set of n points /// and their evaluations. This function will panic if two values in `points` /// are the same. -pub fn lagrange_interpolate(points: &[F], evals: &[F]) -> Vec { +pub fn lagrange_interpolate(points: &[F], evals: &[F]) -> Vec { assert_eq!(points.len(), evals.len()); if points.len() == 1 { // Constant polynomial diff --git a/halo2_proofs/src/circuit.rs b/halo2_proofs/src/circuit.rs index 16a00817..7f166516 100644 --- a/halo2_proofs/src/circuit.rs +++ b/halo2_proofs/src/circuit.rs @@ -4,10 +4,7 @@ use std::{fmt, marker::PhantomData}; use ff::Field; -use crate::{ - arithmetic::FieldExt, - plonk::{Advice, Any, Assigned, Column, Error, Fixed, Instance, Selector, TableColumn}, -}; +use crate::plonk::{Advice, Any, Assigned, Column, Error, Fixed, Instance, Selector, TableColumn}; mod value; pub use value::Value; @@ -25,7 +22,7 @@ pub mod layouter; /// The chip also loads any fixed configuration needed at synthesis time /// using its own implementation of `load`, and stores it in [`Chip::Loaded`]. /// This can be accessed via [`Chip::loaded`]. -pub trait Chip: Sized { +pub trait Chip: Sized { /// A type that holds the configuration for this chip, and any other state it may need /// during circuit synthesis, that can be derived during [`Circuit::configure`]. /// diff --git a/halo2_proofs/src/dev.rs b/halo2_proofs/src/dev.rs index 7844fe0a..b9ddcb26 100644 --- a/halo2_proofs/src/dev.rs +++ b/halo2_proofs/src/dev.rs @@ -9,7 +9,7 @@ use ff::Field; use crate::plonk::Assigned; use crate::{ - arithmetic::{FieldExt, Group}, + arithmetic::FieldExt, circuit, plonk::{ permutation, Advice, Any, Assignment, Circuit, Column, ConstraintSystem, Error, Expression, @@ -72,7 +72,7 @@ impl Region { /// The value of a particular cell within the circuit. #[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum CellValue { +enum CellValue { // An unassigned cell. Unassigned, // A cell that has been assigned a value. @@ -83,12 +83,12 @@ enum CellValue { /// A value within an expression. #[derive(Clone, Copy, Debug, PartialEq, Eq, Ord, PartialOrd)] -enum Value { +enum Value { Real(F), Poison, } -impl From> for Value { +impl From> for Value { fn from(value: CellValue) -> Self { match value { // Cells that haven't been explicitly assigned to, default to zero. @@ -99,7 +99,7 @@ impl From> for Value { } } -impl Neg for Value { +impl Neg for Value { type Output = Self; fn neg(self) -> Self::Output { @@ -110,7 +110,7 @@ impl Neg for Value { } } -impl Add for Value { +impl Add for Value { type Output = Self; fn add(self, rhs: Self) -> Self::Output { @@ -121,7 +121,7 @@ impl Add for Value { } } -impl Mul for Value { +impl Mul for Value { type Output = Self; fn mul(self, rhs: Self) -> Self::Output { @@ -139,7 +139,7 @@ impl Mul for Value { } } -impl Mul for Value { +impl Mul for Value { type Output = Self; fn mul(self, rhs: F) -> Self::Output { @@ -267,7 +267,7 @@ impl Mul for Value { /// )); /// ``` #[derive(Debug)] -pub struct MockProver { +pub struct MockProver { k: u32, n: u32, cs: ConstraintSystem, @@ -308,7 +308,7 @@ impl InstanceValue { } } -impl Assignment for MockProver { +impl Assignment for MockProver { fn enter_region(&mut self, name: N) where NR: Into, diff --git a/halo2_proofs/src/dev/failure.rs b/halo2_proofs/src/dev/failure.rs index 5d94d33f..c08d1abe 100644 --- a/halo2_proofs/src/dev/failure.rs +++ b/halo2_proofs/src/dev/failure.rs @@ -2,7 +2,6 @@ use std::collections::{BTreeMap, HashSet}; use std::fmt; use group::ff::Field; -use pasta_curves::arithmetic::FieldExt; use super::{ metadata, @@ -396,7 +395,7 @@ fn render_constraint_not_satisfied( /// | x0 = 0x5 /// | x1 = 1 /// ``` -fn render_lookup( +fn render_lookup( prover: &MockProver, lookup_index: usize, location: &FailureLocation, @@ -430,7 +429,7 @@ fn render_lookup( ) }); - fn cell_value<'a, F: FieldExt, Q: Into + Copy>( + fn cell_value<'a, F: Field, Q: Into + Copy>( column_type: Any, load: impl Fn(Q) -> Value + 'a, ) -> impl Fn(Q) -> BTreeMap + 'a { @@ -535,7 +534,7 @@ fn render_lookup( impl VerifyFailure { /// Emits this failure in pretty-printed format to stderr. - pub(super) fn emit(&self, prover: &MockProver) { + pub(super) fn emit(&self, prover: &MockProver) { match self { Self::CellNotAssigned { gate, diff --git a/halo2_proofs/src/dev/util.rs b/halo2_proofs/src/dev/util.rs index faca0780..014e8994 100644 --- a/halo2_proofs/src/dev/util.rs +++ b/halo2_proofs/src/dev/util.rs @@ -1,7 +1,6 @@ use std::collections::BTreeMap; use group::ff::Field; -use pasta_curves::arithmetic::FieldExt; use super::{metadata, CellValue, InstanceValue, Value}; use crate::{ @@ -73,7 +72,7 @@ pub(super) fn format_value(v: F) -> String { } } -pub(super) fn load<'a, F: FieldExt, T: ColumnType, Q: Into + Copy>( +pub(super) fn load<'a, F: Field, T: ColumnType, Q: Into + Copy>( n: i32, row: i32, queries: &'a [(Column, Rotation)], @@ -86,7 +85,7 @@ pub(super) fn load<'a, F: FieldExt, T: ColumnType, Q: Into + Copy>( } } -pub(super) fn load_instance<'a, F: FieldExt, T: ColumnType, Q: Into + Copy>( +pub(super) fn load_instance<'a, F: Field, T: ColumnType, Q: Into + Copy>( n: i32, row: i32, queries: &'a [(Column, Rotation)], @@ -100,7 +99,7 @@ pub(super) fn load_instance<'a, F: FieldExt, T: ColumnType, Q: Into + } } -fn cell_value<'a, F: FieldExt, Q: Into + Copy>( +fn cell_value<'a, F: Field, Q: Into + Copy>( virtual_cells: &'a [VirtualCell], load: impl Fn(Q) -> Value + 'a, ) -> impl Fn(Q) -> BTreeMap + 'a { @@ -133,7 +132,7 @@ fn cell_value<'a, F: FieldExt, Q: Into + Copy>( } } -pub(super) fn cell_values<'a, F: FieldExt>( +pub(super) fn cell_values<'a, F: Field>( gate: &Gate, poly: &Expression, load_fixed: impl Fn(FixedQuery) -> Value + 'a, diff --git a/halo2_proofs/src/plonk/lookup/verifier.rs b/halo2_proofs/src/plonk/lookup/verifier.rs index db4394f2..df2c37f3 100644 --- a/halo2_proofs/src/plonk/lookup/verifier.rs +++ b/halo2_proofs/src/plonk/lookup/verifier.rs @@ -5,7 +5,7 @@ use super::super::{ }; use super::Argument; use crate::{ - arithmetic::{CurveAffine, FieldExt}, + arithmetic::CurveAffine, plonk::{Error, VerifyingKey}, poly::{multiopen::VerifierQuery, Rotation}, transcript::{EncodedChallenge, TranscriptRead}, @@ -31,7 +31,7 @@ pub struct Evaluated { permuted_table_eval: C::Scalar, } -impl Argument { +impl Argument { pub(in crate::plonk) fn read_permuted_commitments< C: CurveAffine, E: EncodedChallenge, diff --git a/halo2_proofs/src/poly.rs b/halo2_proofs/src/poly.rs index 80429db3..81c0525e 100644 --- a/halo2_proofs/src/poly.rs +++ b/halo2_proofs/src/poly.rs @@ -6,7 +6,7 @@ use crate::arithmetic::parallelize; use crate::plonk::Assigned; use group::ff::{BatchInvert, Field}; -use pasta_curves::arithmetic::FieldExt; + use std::fmt::Debug; use std::marker::PhantomData; use std::ops::{Add, Deref, DerefMut, Index, IndexMut, Mul, RangeFrom, RangeFull}; @@ -132,7 +132,7 @@ impl Polynomial { } } -pub(crate) fn batch_invert_assigned( +pub(crate) fn batch_invert_assigned( assigned: Vec, LagrangeCoeff>>, ) -> Vec> { let mut assigned_denominators: Vec<_> = assigned diff --git a/halo2_proofs/src/poly/commitment.rs b/halo2_proofs/src/poly/commitment.rs index 9f90b559..06283f9b 100644 --- a/halo2_proofs/src/poly/commitment.rs +++ b/halo2_proofs/src/poly/commitment.rs @@ -206,13 +206,13 @@ impl Params { #[derive(Copy, Clone, Eq, PartialEq, Debug)] pub struct Blind(pub F); -impl Default for Blind { +impl Default for Blind { fn default() -> Self { Blind(F::one()) } } -impl Add for Blind { +impl Add for Blind { type Output = Self; fn add(self, rhs: Blind) -> Self { @@ -220,7 +220,7 @@ impl Add for Blind { } } -impl Mul for Blind { +impl Mul for Blind { type Output = Self; fn mul(self, rhs: Blind) -> Self { @@ -228,25 +228,25 @@ impl Mul for Blind { } } -impl AddAssign for Blind { +impl AddAssign for Blind { fn add_assign(&mut self, rhs: Blind) { self.0 += rhs.0; } } -impl MulAssign for Blind { +impl MulAssign for Blind { fn mul_assign(&mut self, rhs: Blind) { self.0 *= rhs.0; } } -impl AddAssign for Blind { +impl AddAssign for Blind { fn add_assign(&mut self, rhs: F) { self.0 += rhs; } } -impl MulAssign for Blind { +impl MulAssign for Blind { fn mul_assign(&mut self, rhs: F) { self.0 *= rhs; } diff --git a/halo2_proofs/src/poly/domain.rs b/halo2_proofs/src/poly/domain.rs index a0987fe2..d83ce78e 100644 --- a/halo2_proofs/src/poly/domain.rs +++ b/halo2_proofs/src/poly/domain.rs @@ -16,7 +16,7 @@ use std::marker::PhantomData; /// performing operations on an evaluation domain of size $2^k$ and an extended /// domain of size $2^{k} * j$ with $j \neq 0$. #[derive(Clone, Debug)] -pub struct EvaluationDomain { +pub struct EvaluationDomain { n: u64, k: u32, extended_k: u32, diff --git a/halo2_proofs/src/poly/evaluator.rs b/halo2_proofs/src/poly/evaluator.rs index 6113f1ba..8f2b2014 100644 --- a/halo2_proofs/src/poly/evaluator.rs +++ b/halo2_proofs/src/poly/evaluator.rs @@ -140,7 +140,7 @@ impl Evaluator { let poly_len = self.polys.first().unwrap().len(); let (chunk_size, _num_chunks) = get_chunk_params(poly_len); - struct AstContext<'a, F: FieldExt, B: Basis> { + struct AstContext<'a, F: Field, B: Basis> { domain: &'a EvaluationDomain, poly_len: usize, chunk_size: usize, @@ -442,7 +442,7 @@ impl MulAssign for Ast { /// Operations which can be performed over a given basis. pub(crate) trait BasisOps: Basis { fn empty_poly(domain: &EvaluationDomain) -> Polynomial; - fn constant_term( + fn constant_term( poly_len: usize, chunk_size: usize, chunk_index: usize, @@ -469,7 +469,7 @@ impl BasisOps for Coeff { domain.empty_coeff() } - fn constant_term( + fn constant_term( poly_len: usize, chunk_size: usize, chunk_index: usize, @@ -520,7 +520,7 @@ impl BasisOps for LagrangeCoeff { domain.empty_lagrange() } - fn constant_term( + fn constant_term( poly_len: usize, chunk_size: usize, chunk_index: usize, @@ -564,7 +564,7 @@ impl BasisOps for ExtendedLagrangeCoeff { domain.empty_extended() } - fn constant_term( + fn constant_term( poly_len: usize, chunk_size: usize, chunk_index: usize, diff --git a/halo2_proofs/src/poly/multiopen.rs b/halo2_proofs/src/poly/multiopen.rs index 8b708704..11e10908 100644 --- a/halo2_proofs/src/poly/multiopen.rs +++ b/halo2_proofs/src/poly/multiopen.rs @@ -6,10 +6,7 @@ use std::collections::{BTreeMap, BTreeSet}; use super::*; -use crate::{ - arithmetic::{CurveAffine, FieldExt}, - transcript::ChallengeScalar, -}; +use crate::{arithmetic::CurveAffine, transcript::ChallengeScalar}; mod prover; mod verifier; @@ -136,7 +133,7 @@ type IntermediateSets = ( Vec>, ); -fn construct_intermediate_sets>(queries: I) -> IntermediateSets +fn construct_intermediate_sets>(queries: I) -> IntermediateSets where I: IntoIterator + Clone, { diff --git a/halo2_proofs/tests/plonk_api.rs b/halo2_proofs/tests/plonk_api.rs index f1cd0ac8..c70b9067 100644 --- a/halo2_proofs/tests/plonk_api.rs +++ b/halo2_proofs/tests/plonk_api.rs @@ -2,6 +2,7 @@ #![allow(clippy::op_ref)] use assert_matches::assert_matches; +use group::ff::Field; use halo2_proofs::arithmetic::{CurveAffine, FieldExt}; use halo2_proofs::circuit::{Cell, Layouter, SimpleFloorPlanner, Value}; use halo2_proofs::dev::MockProver; @@ -44,7 +45,7 @@ fn plonk_api() { } #[allow(clippy::type_complexity)] - trait StandardCs { + trait StandardCs { fn raw_multiply( &self, layouter: &mut impl Layouter, @@ -71,17 +72,17 @@ fn plonk_api() { } #[derive(Clone)] - struct MyCircuit { + struct MyCircuit { a: Value, lookup_table: Vec, } - struct StandardPlonk { + struct StandardPlonk { config: PlonkConfig, _marker: PhantomData, } - impl StandardPlonk { + impl StandardPlonk { fn new(config: PlonkConfig) -> Self { StandardPlonk { config, @@ -90,7 +91,7 @@ fn plonk_api() { } } - impl StandardCs for StandardPlonk { + impl StandardCs for StandardPlonk { fn raw_multiply( &self, layouter: &mut impl Layouter, @@ -265,7 +266,7 @@ fn plonk_api() { } } - impl Circuit for MyCircuit { + impl Circuit for MyCircuit { type Config = PlonkConfig; type FloorPlanner = SimpleFloorPlanner;