mirror of https://github.com/zcash/halo2.git
Replace unnecessary dependencies on `FieldExt` trait
This commit is contained in:
parent
63e6bd882c
commit
49b2324f0a
|
@ -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<F, Value<F>>::bitrange_of`
|
||||
|
|
|
@ -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<F: FieldExt>(AssignedCell<Assigned<F>, F>);
|
||||
impl<F: FieldExt> Deref for X<F> {
|
||||
struct X<F: Field>(AssignedCell<Assigned<F>, F>);
|
||||
impl<F: Field> Deref for X<F> {
|
||||
type Target = AssignedCell<Assigned<F>, F>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
@ -396,8 +395,8 @@ impl<F: FieldExt> Deref for X<F> {
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
// `y`-coordinate of the accumulator.
|
||||
struct Y<F: FieldExt>(AssignedCell<Assigned<F>, F>);
|
||||
impl<F: FieldExt> Deref for Y<F> {
|
||||
struct Y<F: Field>(AssignedCell<Assigned<F>, F>);
|
||||
impl<F: Field> Deref for Y<F> {
|
||||
type Target = AssignedCell<Assigned<F>, F>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
@ -407,8 +406,8 @@ impl<F: FieldExt> Deref for Y<F> {
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
// Cumulative sum `z` used to decompose the scalar.
|
||||
struct Z<F: FieldExt>(AssignedCell<F, F>);
|
||||
impl<F: FieldExt> Deref for Z<F> {
|
||||
struct Z<F: Field>(AssignedCell<F, F>);
|
||||
impl<F: Field> Deref for Z<F> {
|
||||
type Target = AssignedCell<F, F>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
|
|
@ -27,7 +27,7 @@ pub enum PaddedWord<F: Field> {
|
|||
}
|
||||
|
||||
/// The set of circuit instructions required to use the Poseidon permutation.
|
||||
pub trait PoseidonInstructions<F: FieldExt, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>:
|
||||
pub trait PoseidonInstructions<F: Field, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>:
|
||||
Chip<F>
|
||||
{
|
||||
/// Variable representing the word over which the Poseidon permutation operates.
|
||||
|
@ -45,7 +45,7 @@ pub trait PoseidonInstructions<F: FieldExt, S: Spec<F, T, RATE>, const T: usize,
|
|||
///
|
||||
/// [`Hash`]: self::Hash
|
||||
pub trait PoseidonSpongeInstructions<
|
||||
F: FieldExt,
|
||||
F: Field,
|
||||
S: Spec<F, T, RATE>,
|
||||
D: Domain<F, RATE>,
|
||||
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<F, S, T, RATE>,
|
||||
S: Spec<F, T, RATE>,
|
||||
const T: usize,
|
||||
|
@ -81,7 +81,7 @@ pub struct Word<
|
|||
}
|
||||
|
||||
impl<
|
||||
F: FieldExt,
|
||||
F: Field,
|
||||
PoseidonChip: PoseidonInstructions<F, S, T, RATE>,
|
||||
S: Spec<F, T, RATE>,
|
||||
const T: usize,
|
||||
|
@ -100,7 +100,7 @@ impl<
|
|||
}
|
||||
|
||||
fn poseidon_sponge<
|
||||
F: FieldExt,
|
||||
F: Field,
|
||||
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
||||
S: Spec<F, T, RATE>,
|
||||
D: Domain<F, RATE>,
|
||||
|
@ -122,7 +122,7 @@ fn poseidon_sponge<
|
|||
/// A Poseidon sponge.
|
||||
#[derive(Debug)]
|
||||
pub struct Sponge<
|
||||
F: FieldExt,
|
||||
F: Field,
|
||||
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
||||
S: Spec<F, T, RATE>,
|
||||
M: SpongeMode,
|
||||
|
@ -137,7 +137,7 @@ pub struct Sponge<
|
|||
}
|
||||
|
||||
impl<
|
||||
F: FieldExt,
|
||||
F: Field,
|
||||
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
||||
S: Spec<F, T, RATE>,
|
||||
D: Domain<F, RATE>,
|
||||
|
@ -210,7 +210,7 @@ impl<
|
|||
}
|
||||
|
||||
impl<
|
||||
F: FieldExt,
|
||||
F: Field,
|
||||
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
||||
S: Spec<F, T, RATE>,
|
||||
D: Domain<F, RATE>,
|
||||
|
@ -241,7 +241,7 @@ impl<
|
|||
/// A Poseidon hash function, built around a sponge.
|
||||
#[derive(Debug)]
|
||||
pub struct Hash<
|
||||
F: FieldExt,
|
||||
F: Field,
|
||||
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
||||
S: Spec<F, T, RATE>,
|
||||
D: Domain<F, RATE>,
|
||||
|
@ -252,7 +252,7 @@ pub struct Hash<
|
|||
}
|
||||
|
||||
impl<
|
||||
F: FieldExt,
|
||||
F: Field,
|
||||
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
||||
S: Spec<F, T, RATE>,
|
||||
D: Domain<F, RATE>,
|
||||
|
|
|
@ -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<F: FieldExt, const WIDTH: usize, const RATE: usize> {
|
||||
pub struct Pow5Config<F: Field, const WIDTH: usize, const RATE: usize> {
|
||||
pub(crate) state: [Column<Advice>; WIDTH],
|
||||
partial_sbox: Column<Advice>,
|
||||
rc_a: [Column<Fixed>; WIDTH],
|
||||
|
@ -40,11 +41,11 @@ pub struct Pow5Config<F: FieldExt, const WIDTH: usize, const RATE: usize> {
|
|||
/// 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<F: FieldExt, const WIDTH: usize, const RATE: usize> {
|
||||
pub struct Pow5Chip<F: Field, const WIDTH: usize, const RATE: usize> {
|
||||
config: Pow5Config<F, WIDTH, RATE>,
|
||||
}
|
||||
|
||||
impl<F: FieldExt, const WIDTH: usize, const RATE: usize> Pow5Chip<F, WIDTH, RATE> {
|
||||
impl<F: Field, const WIDTH: usize, const RATE: usize> Pow5Chip<F, WIDTH, RATE> {
|
||||
/// Configures this chip for use in a circuit.
|
||||
///
|
||||
/// # Side-effects
|
||||
|
@ -209,7 +210,7 @@ impl<F: FieldExt, const WIDTH: usize, const RATE: usize> Pow5Chip<F, WIDTH, RATE
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt, const WIDTH: usize, const RATE: usize> Chip<F> for Pow5Chip<F, WIDTH, RATE> {
|
||||
impl<F: Field, const WIDTH: usize, const RATE: usize> Chip<F> for Pow5Chip<F, WIDTH, RATE> {
|
||||
type Config = Pow5Config<F, WIDTH, RATE>;
|
||||
type Loaded = ();
|
||||
|
||||
|
@ -403,21 +404,21 @@ impl<
|
|||
|
||||
/// A word in the Poseidon state.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct StateWord<F: FieldExt>(AssignedCell<F, F>);
|
||||
pub struct StateWord<F: Field>(AssignedCell<F, F>);
|
||||
|
||||
impl<F: FieldExt> From<StateWord<F>> for AssignedCell<F, F> {
|
||||
impl<F: Field> From<StateWord<F>> for AssignedCell<F, F> {
|
||||
fn from(state_word: StateWord<F>) -> AssignedCell<F, F> {
|
||||
state_word.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> From<AssignedCell<F, F>> for StateWord<F> {
|
||||
impl<F: Field> From<AssignedCell<F, F>> for StateWord<F> {
|
||||
fn from(cell_value: AssignedCell<F, F>) -> StateWord<F> {
|
||||
StateWord(cell_value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Var<F> for StateWord<F> {
|
||||
impl<F: Field> Var<F> for StateWord<F> {
|
||||
fn cell(&self) -> Cell {
|
||||
self.0.cell()
|
||||
}
|
||||
|
@ -428,7 +429,7 @@ impl<F: FieldExt> Var<F> for StateWord<F> {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Pow5State<F: FieldExt, const WIDTH: usize>([StateWord<F>; WIDTH]);
|
||||
struct Pow5State<F: Field, const WIDTH: usize>([StateWord<F>; WIDTH]);
|
||||
|
||||
impl<F: FieldExt, const WIDTH: usize> Pow5State<F, WIDTH> {
|
||||
fn full_round<const RATE: usize>(
|
||||
|
|
|
@ -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<F, const RATE: usize> = [Option<F>; RATE];
|
|||
pub type Mds<F, const T: usize> = [[F; T]; T];
|
||||
|
||||
/// A specification for a Poseidon permutation.
|
||||
pub trait Spec<F: FieldExt, const T: usize, const RATE: usize>: fmt::Debug {
|
||||
pub trait Spec<F: Field, const T: usize, const RATE: usize>: fmt::Debug {
|
||||
/// The number of full rounds for this specification.
|
||||
///
|
||||
/// This must be an even number.
|
||||
|
@ -80,7 +81,7 @@ pub fn generate_constants<F: FieldExt, S: Spec<F, T, RATE>, const T: usize, cons
|
|||
}
|
||||
|
||||
/// Runs the Poseidon permutation on the given state.
|
||||
pub(crate) fn permute<F: FieldExt, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>(
|
||||
pub(crate) fn permute<F: Field, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>(
|
||||
state: &mut State<F, T>,
|
||||
mds: &Mds<F, T>,
|
||||
round_constants: &[[F; T]],
|
||||
|
@ -127,7 +128,7 @@ pub(crate) fn permute<F: FieldExt, S: Spec<F, T, RATE>, const T: usize, const RA
|
|||
});
|
||||
}
|
||||
|
||||
fn poseidon_sponge<F: FieldExt, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>(
|
||||
fn poseidon_sponge<F: Field, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>(
|
||||
state: &mut State<F, T>,
|
||||
input: Option<&Absorbing<F, RATE>>,
|
||||
mds_matrix: &Mds<F, T>,
|
||||
|
@ -184,7 +185,7 @@ impl<F: fmt::Debug, const RATE: usize> Absorbing<F, RATE> {
|
|||
|
||||
/// A Poseidon sponge.
|
||||
pub(crate) struct Sponge<
|
||||
F: FieldExt,
|
||||
F: Field,
|
||||
S: Spec<F, T, RATE>,
|
||||
M: SpongeMode,
|
||||
const T: usize,
|
||||
|
@ -197,7 +198,7 @@ pub(crate) struct Sponge<
|
|||
_marker: PhantomData<S>,
|
||||
}
|
||||
|
||||
impl<F: FieldExt, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>
|
||||
impl<F: Field, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>
|
||||
Sponge<F, S, Absorbing<F, RATE>, T, RATE>
|
||||
{
|
||||
/// Constructs a new sponge for the given Poseidon specification.
|
||||
|
@ -255,7 +256,7 @@ impl<F: FieldExt, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>
|
||||
impl<F: Field, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>
|
||||
Sponge<F, S, Squeezing<F, RATE>, T, RATE>
|
||||
{
|
||||
/// Squeezes an element from the sponge.
|
||||
|
@ -279,7 +280,7 @@ impl<F: FieldExt, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>
|
|||
}
|
||||
|
||||
/// A domain in which a Poseidon hash function is being used.
|
||||
pub trait Domain<F: FieldExt, const RATE: usize> {
|
||||
pub trait Domain<F: Field, const RATE: usize> {
|
||||
/// Iterator that outputs padding field elements.
|
||||
type Padding: IntoIterator<Item = F>;
|
||||
|
||||
|
@ -325,7 +326,7 @@ impl<F: FieldExt, const RATE: usize, const L: usize> Domain<F, RATE> for Constan
|
|||
|
||||
/// A Poseidon hash function, built around a sponge.
|
||||
pub struct Hash<
|
||||
F: FieldExt,
|
||||
F: Field,
|
||||
S: Spec<F, T, RATE>,
|
||||
D: Domain<F, RATE>,
|
||||
const T: usize,
|
||||
|
@ -335,7 +336,7 @@ pub struct Hash<
|
|||
_domain: PhantomData<D>,
|
||||
}
|
||||
|
||||
impl<F: FieldExt, S: Spec<F, T, RATE>, D: Domain<F, RATE>, const T: usize, const RATE: usize>
|
||||
impl<F: Field, S: Spec<F, T, RATE>, D: Domain<F, RATE>, const T: usize, const RATE: usize>
|
||||
fmt::Debug for Hash<F, S, D, T, RATE>
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
|
@ -349,7 +350,7 @@ impl<F: FieldExt, S: Spec<F, T, RATE>, D: Domain<F, RATE>, const T: usize, const
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt, S: Spec<F, T, RATE>, D: Domain<F, RATE>, const T: usize, const RATE: usize>
|
||||
impl<F: Field, S: Spec<F, T, RATE>, D: Domain<F, RATE>, const T: usize, const RATE: usize>
|
||||
Hash<F, S, D, T, RATE>
|
||||
{
|
||||
/// Initializes a new hasher.
|
||||
|
|
|
@ -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<F: FieldExt> {
|
||||
pub(super) struct Grain<F: Field> {
|
||||
state: BitArr!(for 80, in u8, Msb0),
|
||||
next_bit: usize,
|
||||
_field: PhantomData<F>,
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Grain<F> {
|
||||
impl<F: PrimeField> Grain<F> {
|
||||
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<F: FieldExt> Grain<F> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Grain<F> {
|
||||
/// 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<F: FieldExt> Grain<F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Iterator for Grain<F> {
|
||||
impl<F: PrimeField> Iterator for Grain<F> {
|
||||
type Item = bool;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
|
|
@ -66,7 +66,7 @@ impl Spec<Fq, 3, 2> 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<F: FieldExt, const SECURE_MDS: usize>(PhantomData<F>);
|
||||
pub struct P128Pow5T3Gen<F: Field, const SECURE_MDS: usize>(PhantomData<F>);
|
||||
|
||||
impl<F: FieldExt, const SECURE_MDS: usize> P128Pow5T3Gen<F, SECURE_MDS> {
|
||||
impl<F: Field, const SECURE_MDS: usize> P128Pow5T3Gen<F, SECURE_MDS> {
|
||||
#![allow(dead_code)]
|
||||
pub fn new() -> Self {
|
||||
P128Pow5T3Gen(PhantomData::default())
|
||||
|
|
|
@ -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<F: FieldExt>: Chip<F> {
|
||||
pub trait Sha256Instructions<F: Field>: Chip<F> {
|
||||
/// 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>([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<F: FieldExt, CS: Sha256Instructions<F>> {
|
||||
pub struct Sha256<F: Field, CS: Sha256Instructions<F>> {
|
||||
chip: CS,
|
||||
state: CS::State,
|
||||
cur_block: Vec<CS::BlockWord>,
|
||||
length: usize,
|
||||
}
|
||||
|
||||
impl<F: FieldExt, Sha256Chip: Sha256Instructions<F>> Sha256<F, Sha256Chip> {
|
||||
impl<F: Field, Sha256Chip: Sha256Instructions<F>> Sha256<F, Sha256Chip> {
|
||||
/// Create a new hasher instance.
|
||||
pub fn new(chip: Sha256Chip, mut layouter: impl Layouter<F>) -> Result<Self, Error> {
|
||||
let state = chip.initialization_vector(&mut layouter)?;
|
||||
|
|
|
@ -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<F: FieldExt>(PhantomData<F>);
|
||||
pub struct CompressionGate<F: Field>(PhantomData<F>);
|
||||
|
||||
impl<F: FieldExt> CompressionGate<F> {
|
||||
impl<F: PrimeField> CompressionGate<F> {
|
||||
fn ones() -> Expression<F> {
|
||||
Expression::Constant(F::one())
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use halo2_proofs::{arithmetic::FieldExt, plonk::Expression};
|
||||
use group::ff::PrimeField;
|
||||
use halo2_proofs::plonk::Expression;
|
||||
|
||||
pub struct Gate<F: FieldExt>(pub Expression<F>);
|
||||
pub struct Gate<F: PrimeField>(pub Expression<F>);
|
||||
|
||||
impl<F: FieldExt> Gate<F> {
|
||||
impl<F: PrimeField> Gate<F> {
|
||||
fn ones() -> Expression<F> {
|
||||
Expression::Constant(F::one())
|
||||
}
|
||||
|
|
|
@ -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<F: FieldExt>(PhantomData<F>);
|
||||
pub struct ScheduleGate<F: Field>(PhantomData<F>);
|
||||
|
||||
impl<F: FieldExt> ScheduleGate<F> {
|
||||
impl<F: PrimeField> ScheduleGate<F> {
|
||||
/// s_word for W_16 to W_63
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn s_word(
|
||||
|
|
|
@ -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<F: FieldExt> {
|
||||
pub(super) struct SpreadTableChip<F: Field> {
|
||||
config: SpreadTableConfig,
|
||||
_marker: PhantomData<F>,
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Chip<F> for SpreadTableChip<F> {
|
||||
impl<F: Field> Chip<F> for SpreadTableChip<F> {
|
||||
type Config = SpreadTableConfig;
|
||||
type Loaded = ();
|
||||
|
||||
|
@ -171,7 +172,7 @@ impl<F: FieldExt> Chip<F> for SpreadTableChip<F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> SpreadTableChip<F> {
|
||||
impl<F: PrimeField> SpreadTableChip<F> {
|
||||
pub fn configure(
|
||||
meta: &mut ConstraintSystem<F>,
|
||||
input_tag: Column<Advice>,
|
||||
|
@ -250,7 +251,7 @@ impl<F: FieldExt> SpreadTableChip<F> {
|
|||
}
|
||||
|
||||
impl SpreadTableConfig {
|
||||
fn generate<F: FieldExt>() -> impl Iterator<Item = (F, F, F)> {
|
||||
fn generate<F: PrimeField>() -> impl Iterator<Item = (F, F, F)> {
|
||||
(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<F: FieldExt> Circuit<F> for MyCircuit {
|
||||
impl<F: PrimeField> Circuit<F> for MyCircuit {
|
||||
type Config = SpreadTableConfig;
|
||||
type FloorPlanner = SimpleFloorPlanner;
|
||||
|
||||
|
|
|
@ -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<F: FieldExt>(AssignedCell<Assigned<F>, F>);
|
||||
struct X<F: Field>(AssignedCell<Assigned<F>, F>);
|
||||
|
||||
impl<F: FieldExt> From<AssignedCell<Assigned<F>, F>> for X<F> {
|
||||
impl<F: Field> From<AssignedCell<Assigned<F>, F>> for X<F> {
|
||||
fn from(cell_value: AssignedCell<Assigned<F>, F>) -> Self {
|
||||
X(cell_value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Deref for X<F> {
|
||||
impl<F: Field> Deref for X<F> {
|
||||
type Target = AssignedCell<Assigned<F>, F>;
|
||||
|
||||
fn deref(&self) -> &AssignedCell<Assigned<F>, F> {
|
||||
|
@ -400,15 +397,15 @@ impl<F: FieldExt> Deref for X<F> {
|
|||
/// 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<F: FieldExt>(Value<Assigned<F>>);
|
||||
struct Y<F: Field>(Value<Assigned<F>>);
|
||||
|
||||
impl<F: FieldExt> From<Value<Assigned<F>>> for Y<F> {
|
||||
impl<F: Field> From<Value<Assigned<F>>> for Y<F> {
|
||||
fn from(value: Value<Assigned<F>>) -> Self {
|
||||
Y(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Deref for Y<F> {
|
||||
impl<F: Field> Deref for Y<F> {
|
||||
type Target = Value<Assigned<F>>;
|
||||
|
||||
fn deref(&self) -> &Value<Assigned<F>> {
|
||||
|
|
|
@ -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<F: FieldExt, const K: usize, const MAX_WORDS: usize>(Vec<MessagePiece<F, K>>);
|
||||
pub struct Message<F: Field, const K: usize, const MAX_WORDS: usize>(Vec<MessagePiece<F, K>>);
|
||||
|
||||
impl<F: FieldExt + PrimeFieldBits, const K: usize, const MAX_WORDS: usize>
|
||||
From<Vec<MessagePiece<F, K>>> for Message<F, K, MAX_WORDS>
|
||||
impl<F: PrimeFieldBits, const K: usize, const MAX_WORDS: usize> From<Vec<MessagePiece<F, K>>>
|
||||
for Message<F, K, MAX_WORDS>
|
||||
{
|
||||
fn from(pieces: Vec<MessagePiece<F, K>>) -> Self {
|
||||
// A message cannot contain more than `MAX_WORDS` words.
|
||||
|
@ -20,7 +18,7 @@ impl<F: FieldExt + PrimeFieldBits, const K: usize, const MAX_WORDS: usize>
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt + PrimeFieldBits, const K: usize, const MAX_WORDS: usize> std::ops::Deref
|
||||
impl<F: PrimeFieldBits, const K: usize, const MAX_WORDS: usize> std::ops::Deref
|
||||
for Message<F, K, MAX_WORDS>
|
||||
{
|
||||
type Target = [MessagePiece<F, K>];
|
||||
|
@ -35,13 +33,13 @@ impl<F: FieldExt + PrimeFieldBits, const K: usize, const MAX_WORDS: usize> 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<F: FieldExt, const K: usize> {
|
||||
pub struct MessagePiece<F: Field, const K: usize> {
|
||||
cell_value: AssignedCell<F, F>,
|
||||
/// The number of K-bit words in this message piece.
|
||||
num_words: usize,
|
||||
}
|
||||
|
||||
impl<F: FieldExt + PrimeFieldBits, const K: usize> MessagePiece<F, K> {
|
||||
impl<F: PrimeFieldBits, const K: usize> MessagePiece<F, K> {
|
||||
pub fn new(cell_value: AssignedCell<F, F>, num_words: usize) -> Self {
|
||||
assert!(num_words * K < F::NUM_BITS as usize);
|
||||
Self {
|
||||
|
|
|
@ -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<F: Field> FieldValue<F> for AssignedCell<F, F> {
|
|||
}
|
||||
|
||||
/// Trait for a variable in the circuit.
|
||||
pub trait Var<F: FieldExt>: Clone + std::fmt::Debug + From<AssignedCell<F, F>> {
|
||||
pub trait Var<F: Field>: Clone + std::fmt::Debug + From<AssignedCell<F, F>> {
|
||||
/// The cell at which this variable was allocated.
|
||||
fn cell(&self) -> Cell;
|
||||
|
||||
|
@ -40,7 +40,7 @@ pub trait Var<F: FieldExt>: Clone + std::fmt::Debug + From<AssignedCell<F, F>> {
|
|||
fn value(&self) -> Value<F>;
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Var<F> for AssignedCell<F, F> {
|
||||
impl<F: Field> Var<F> for AssignedCell<F, F> {
|
||||
fn cell(&self) -> Cell {
|
||||
self.cell()
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ impl<F: FieldExt> Var<F> for AssignedCell<F, F> {
|
|||
}
|
||||
|
||||
/// Trait for utilities used across circuits.
|
||||
pub trait UtilitiesInstructions<F: FieldExt> {
|
||||
pub trait UtilitiesInstructions<F: Field> {
|
||||
/// Variable in the circuit.
|
||||
type Var: Var<F>;
|
||||
|
||||
|
@ -130,14 +130,14 @@ impl<F: Field> RangeConstrained<F, AssignedCell<F, F>> {
|
|||
}
|
||||
|
||||
/// Checks that an expression is either 1 or 0.
|
||||
pub fn bool_check<F: FieldExt>(value: Expression<F>) -> Expression<F> {
|
||||
pub fn bool_check<F: PrimeField>(value: Expression<F>) -> Expression<F> {
|
||||
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<F: FieldExt>(a: Expression<F>, b: Expression<F>, c: Expression<F>) -> Expression<F> {
|
||||
pub fn ternary<F: Field>(a: Expression<F>, b: Expression<F>, c: Expression<F>) -> Expression<F> {
|
||||
let one_minus_a = Expression::Constant(F::one()) - a.clone();
|
||||
a * b + one_minus_a * c
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ pub fn bitrange_subset<F: PrimeFieldBits>(field_elem: &F, bitrange: Range<usize>
|
|||
|
||||
/// Check that an expression is in the small range [0..range),
|
||||
/// i.e. 0 ≤ word < range.
|
||||
pub fn range_check<F: FieldExt>(word: Expression<F>, range: usize) -> Expression<F> {
|
||||
pub fn range_check<F: PrimeField>(word: Expression<F>, range: usize) -> Expression<F> {
|
||||
(1..range).fold(word.clone(), |acc, i| {
|
||||
acc * (Expression::Constant(F::from(i as u64)) - word.clone())
|
||||
})
|
||||
|
|
|
@ -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<F: FieldExt>: UtilitiesInstructions<F> {
|
||||
pub trait CondSwapInstructions<F: Field>: UtilitiesInstructions<F> {
|
||||
#[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<F> {
|
|||
_marker: PhantomData<F>,
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Chip<F> for CondSwapChip<F> {
|
||||
impl<F: Field> Chip<F> for CondSwapChip<F> {
|
||||
type Config = CondSwapConfig;
|
||||
type Loaded = ();
|
||||
|
||||
|
@ -63,11 +65,11 @@ impl CondSwapConfig {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> UtilitiesInstructions<F> for CondSwapChip<F> {
|
||||
impl<F: Field> UtilitiesInstructions<F> for CondSwapChip<F> {
|
||||
type Var = AssignedCell<F, F>;
|
||||
}
|
||||
|
||||
impl<F: FieldExt> CondSwapInstructions<F> for CondSwapChip<F> {
|
||||
impl<F: PrimeField> CondSwapInstructions<F> for CondSwapChip<F> {
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn swap(
|
||||
&self,
|
||||
|
@ -122,7 +124,7 @@ impl<F: FieldExt> CondSwapInstructions<F> for CondSwapChip<F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> CondSwapChip<F> {
|
||||
impl<F: PrimeField> CondSwapChip<F> {
|
||||
/// Configures this chip for use in a circuit.
|
||||
///
|
||||
/// # Side-effects
|
||||
|
@ -195,25 +197,25 @@ impl<F: FieldExt> CondSwapChip<F> {
|
|||
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<F: FieldExt> {
|
||||
struct MyCircuit<F: Field> {
|
||||
a: Value<F>,
|
||||
b: Value<F>,
|
||||
swap: Value<bool>,
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
|
||||
impl<F: PrimeField> Circuit<F> for MyCircuit<F> {
|
||||
type Config = CondSwapConfig;
|
||||
type FloorPlanner = SimpleFloorPlanner;
|
||||
|
||||
|
|
|
@ -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<F: FieldExt + PrimeFieldBits>(Vec<AssignedCell<F, F>>);
|
||||
impl<F: FieldExt + PrimeFieldBits> std::ops::Deref for RunningSum<F> {
|
||||
pub struct RunningSum<F: PrimeFieldBits>(Vec<AssignedCell<F, F>>);
|
||||
impl<F: PrimeFieldBits> std::ops::Deref for RunningSum<F> {
|
||||
type Target = Vec<AssignedCell<F, F>>;
|
||||
|
||||
fn deref(&self) -> &Vec<AssignedCell<F, F>> {
|
||||
|
@ -46,15 +46,13 @@ impl<F: FieldExt + PrimeFieldBits> std::ops::Deref for RunningSum<F> {
|
|||
|
||||
/// Configuration that provides methods for running sum decomposition.
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub struct RunningSumConfig<F: FieldExt + PrimeFieldBits, const WINDOW_NUM_BITS: usize> {
|
||||
pub struct RunningSumConfig<F: PrimeFieldBits, const WINDOW_NUM_BITS: usize> {
|
||||
q_range_check: Selector,
|
||||
z: Column<Advice>,
|
||||
_marker: PhantomData<F>,
|
||||
}
|
||||
|
||||
impl<F: FieldExt + PrimeFieldBits, const WINDOW_NUM_BITS: usize>
|
||||
RunningSumConfig<F, WINDOW_NUM_BITS>
|
||||
{
|
||||
impl<F: PrimeFieldBits, const WINDOW_NUM_BITS: usize> RunningSumConfig<F, WINDOW_NUM_BITS> {
|
||||
/// 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,
|
||||
|
|
|
@ -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<F: FieldExt + PrimeFieldBits>(Vec<AssignedCell<F, F>>);
|
||||
impl<F: FieldExt + PrimeFieldBits> std::ops::Deref for RunningSum<F> {
|
||||
pub struct RunningSum<F: PrimeFieldBits>(Vec<AssignedCell<F, F>>);
|
||||
impl<F: PrimeFieldBits> std::ops::Deref for RunningSum<F> {
|
||||
type Target = Vec<AssignedCell<F, F>>;
|
||||
|
||||
fn deref(&self) -> &Vec<AssignedCell<F, F>> {
|
||||
|
@ -23,7 +23,7 @@ impl<F: FieldExt + PrimeFieldBits> std::ops::Deref for RunningSum<F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt + PrimeFieldBits> RangeConstrained<F, AssignedCell<F, F>> {
|
||||
impl<F: PrimeFieldBits> RangeConstrained<F, AssignedCell<F, F>> {
|
||||
/// Witnesses a subset of the bits in `value` and constrains them to be the correct
|
||||
/// number of bits.
|
||||
///
|
||||
|
@ -56,7 +56,7 @@ impl<F: FieldExt + PrimeFieldBits> RangeConstrained<F, AssignedCell<F, F>> {
|
|||
|
||||
/// Configuration that provides methods for a lookup range check.
|
||||
#[derive(Eq, PartialEq, Debug, Clone, Copy)]
|
||||
pub struct LookupRangeCheckConfig<F: FieldExt + PrimeFieldBits, const K: usize> {
|
||||
pub struct LookupRangeCheckConfig<F: PrimeFieldBits, const K: usize> {
|
||||
q_lookup: Selector,
|
||||
q_running: Selector,
|
||||
q_bitshift: Selector,
|
||||
|
@ -65,7 +65,7 @@ pub struct LookupRangeCheckConfig<F: FieldExt + PrimeFieldBits, const K: usize>
|
|||
_marker: PhantomData<F>,
|
||||
}
|
||||
|
||||
impl<F: FieldExt + PrimeFieldBits, const K: usize> LookupRangeCheckConfig<F, K> {
|
||||
impl<F: PrimeFieldBits, const K: usize> LookupRangeCheckConfig<F, K> {
|
||||
/// 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<F: FieldExt + PrimeFieldBits> {
|
||||
struct MyCircuit<F: PrimeFieldBits> {
|
||||
num_words: usize,
|
||||
_marker: PhantomData<F>,
|
||||
}
|
||||
|
||||
impl<F: FieldExt + PrimeFieldBits> Circuit<F> for MyCircuit<F> {
|
||||
impl<F: PrimeFieldBits> Circuit<F> for MyCircuit<F> {
|
||||
type Config = LookupRangeCheckConfig<F, K>;
|
||||
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<F: FieldExt + PrimeFieldBits, const K: usize>(
|
||||
fn expected_zs<F: PrimeFieldBits, const K: usize>(
|
||||
element: F,
|
||||
num_words: usize,
|
||||
) -> Vec<F> {
|
||||
|
@ -498,12 +498,12 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn short_range_check() {
|
||||
struct MyCircuit<F: FieldExt + PrimeFieldBits> {
|
||||
struct MyCircuit<F: PrimeFieldBits> {
|
||||
element: Value<F>,
|
||||
num_bits: usize,
|
||||
}
|
||||
|
||||
impl<F: FieldExt + PrimeFieldBits> Circuit<F> for MyCircuit<F> {
|
||||
impl<F: PrimeFieldBits> Circuit<F> for MyCircuit<F> {
|
||||
type Config = LookupRangeCheckConfig<F, K>;
|
||||
type FloorPlanner = SimpleFloorPlanner;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<F: FieldExt> {
|
||||
struct MyCircuit<F: PrimeField> {
|
||||
_marker: PhantomData<F>,
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|
|||
advice: Column<Advice>,
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
|
||||
impl<F: PrimeField> Circuit<F> for MyCircuit<F> {
|
||||
type Config = MyConfig;
|
||||
type FloorPlanner = SimpleFloorPlanner;
|
||||
|
||||
|
|
|
@ -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<Fixed>,
|
||||
}
|
||||
|
||||
trait StandardCs<FF: FieldExt> {
|
||||
trait StandardCs<FF: Field> {
|
||||
fn raw_multiply<F>(
|
||||
&self,
|
||||
layouter: &mut impl Layouter<FF>,
|
||||
|
@ -50,17 +49,17 @@ fn criterion_benchmark(c: &mut Criterion) {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct MyCircuit<F: FieldExt> {
|
||||
struct MyCircuit<F: Field> {
|
||||
a: Value<F>,
|
||||
k: u32,
|
||||
}
|
||||
|
||||
struct StandardPlonk<F: FieldExt> {
|
||||
struct StandardPlonk<F: Field> {
|
||||
config: PlonkConfig,
|
||||
_marker: PhantomData<F>,
|
||||
}
|
||||
|
||||
impl<FF: FieldExt> StandardPlonk<FF> {
|
||||
impl<FF: Field> StandardPlonk<FF> {
|
||||
fn new(config: PlonkConfig) -> Self {
|
||||
StandardPlonk {
|
||||
config,
|
||||
|
@ -69,7 +68,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|
|||
}
|
||||
}
|
||||
|
||||
impl<FF: FieldExt> StandardCs<FF> for StandardPlonk<FF> {
|
||||
impl<FF: Field> StandardCs<FF> for StandardPlonk<FF> {
|
||||
fn raw_multiply<F>(
|
||||
&self,
|
||||
layouter: &mut impl Layouter<FF>,
|
||||
|
@ -174,7 +173,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
|
||||
impl<F: Field> Circuit<F> for MyCircuit<F> {
|
||||
type Config = PlonkConfig;
|
||||
type FloorPlanner = SimpleFloorPlanner;
|
||||
|
||||
|
|
|
@ -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<FF: FieldExt> {
|
||||
trait StandardCs<FF: Field> {
|
||||
fn raw_multiply<F>(&self, region: &mut Region<FF>, f: F) -> Result<(Cell, Cell, Cell), Error>
|
||||
where
|
||||
F: FnMut() -> Value<(Assigned<FF>, Assigned<FF>, Assigned<FF>)>;
|
||||
|
@ -39,17 +38,17 @@ trait StandardCs<FF: FieldExt> {
|
|||
fn lookup_table(&self, layouter: &mut impl Layouter<FF>, values: &[FF]) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
struct MyCircuit<F: FieldExt> {
|
||||
struct MyCircuit<F: Field> {
|
||||
a: Value<F>,
|
||||
lookup_table: Vec<F>,
|
||||
}
|
||||
|
||||
struct StandardPlonk<F: FieldExt> {
|
||||
struct StandardPlonk<F: Field> {
|
||||
config: PlonkConfig,
|
||||
_marker: PhantomData<F>,
|
||||
}
|
||||
|
||||
impl<FF: FieldExt> StandardPlonk<FF> {
|
||||
impl<FF: Field> StandardPlonk<FF> {
|
||||
fn new(config: PlonkConfig) -> Self {
|
||||
StandardPlonk {
|
||||
config,
|
||||
|
@ -58,7 +57,7 @@ impl<FF: FieldExt> StandardPlonk<FF> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<FF: FieldExt> StandardCs<FF> for StandardPlonk<FF> {
|
||||
impl<FF: Field> StandardCs<FF> for StandardPlonk<FF> {
|
||||
fn raw_multiply<F>(
|
||||
&self,
|
||||
region: &mut Region<FF>,
|
||||
|
@ -159,7 +158,7 @@ impl<FF: FieldExt> StandardCs<FF> for StandardPlonk<FF> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
|
||||
impl<F: Field> Circuit<F> for MyCircuit<F> {
|
||||
type Config = PlonkConfig;
|
||||
type FloorPlanner = SimpleFloorPlanner;
|
||||
|
||||
|
|
|
@ -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<F: FieldExt>: Chip<F> {
|
||||
trait NumericInstructions<F: Field>: Chip<F> {
|
||||
/// Variable representing a number.
|
||||
type Num;
|
||||
|
||||
|
@ -39,7 +39,7 @@ trait NumericInstructions<F: FieldExt>: Chip<F> {
|
|||
// ANCHOR: chip
|
||||
/// The chip that will implement our instructions! Chips store their own
|
||||
/// config, as well as type markers if necessary.
|
||||
struct FieldChip<F: FieldExt> {
|
||||
struct FieldChip<F: Field> {
|
||||
config: FieldConfig,
|
||||
_marker: PhantomData<F>,
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ struct FieldConfig {
|
|||
s_mul: Selector,
|
||||
}
|
||||
|
||||
impl<F: FieldExt> FieldChip<F> {
|
||||
impl<F: Field> FieldChip<F> {
|
||||
fn construct(config: <Self as Chip<F>>::Config) -> Self {
|
||||
Self {
|
||||
config,
|
||||
|
@ -126,7 +126,7 @@ impl<F: FieldExt> FieldChip<F> {
|
|||
// ANCHOR_END: chip-config
|
||||
|
||||
// ANCHOR: chip-impl
|
||||
impl<F: FieldExt> Chip<F> for FieldChip<F> {
|
||||
impl<F: Field> Chip<F> for FieldChip<F> {
|
||||
type Config = FieldConfig;
|
||||
type Loaded = ();
|
||||
|
||||
|
@ -143,9 +143,9 @@ impl<F: FieldExt> Chip<F> for FieldChip<F> {
|
|||
// ANCHOR: instructions-impl
|
||||
/// A variable representing a number.
|
||||
#[derive(Clone)]
|
||||
struct Number<F: FieldExt>(AssignedCell<F, F>);
|
||||
struct Number<F: Field>(AssignedCell<F, F>);
|
||||
|
||||
impl<F: FieldExt> NumericInstructions<F> for FieldChip<F> {
|
||||
impl<F: Field> NumericInstructions<F> for FieldChip<F> {
|
||||
type Num = Number<F>;
|
||||
|
||||
fn load_private(
|
||||
|
@ -238,13 +238,13 @@ impl<F: FieldExt> NumericInstructions<F> for FieldChip<F> {
|
|||
/// 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<F: FieldExt> {
|
||||
struct MyCircuit<F: Field> {
|
||||
constant: F,
|
||||
a: Value<F>,
|
||||
b: Value<F>,
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
|
||||
impl<F: Field> Circuit<F> for MyCircuit<F> {
|
||||
// Since we are using a single chip for everything, we can just reuse its config.
|
||||
type Config = FieldConfig;
|
||||
type FloorPlanner = SimpleFloorPlanner;
|
||||
|
|
|
@ -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<F: FieldExt>(AssignedCell<F, F>);
|
||||
struct Number<F: Field>(AssignedCell<F, F>);
|
||||
|
||||
trait FieldInstructions<F: FieldExt>: AddInstructions<F> + MulInstructions<F> {
|
||||
trait FieldInstructions<F: Field>: AddInstructions<F> + MulInstructions<F> {
|
||||
/// Variable representing a number.
|
||||
type Num;
|
||||
|
||||
|
@ -43,7 +43,7 @@ trait FieldInstructions<F: FieldExt>: AddInstructions<F> + MulInstructions<F> {
|
|||
// ANCHOR_END: field-instructions
|
||||
|
||||
// ANCHOR: add-instructions
|
||||
trait AddInstructions<F: FieldExt>: Chip<F> {
|
||||
trait AddInstructions<F: Field>: Chip<F> {
|
||||
/// Variable representing a number.
|
||||
type Num;
|
||||
|
||||
|
@ -58,7 +58,7 @@ trait AddInstructions<F: FieldExt>: Chip<F> {
|
|||
// ANCHOR_END: add-instructions
|
||||
|
||||
// ANCHOR: mul-instructions
|
||||
trait MulInstructions<F: FieldExt>: Chip<F> {
|
||||
trait MulInstructions<F: Field>: Chip<F> {
|
||||
/// 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<F: FieldExt> {
|
||||
struct FieldChip<F: Field> {
|
||||
config: FieldConfig,
|
||||
_marker: PhantomData<F>,
|
||||
}
|
||||
// ANCHOR_END: field-chip
|
||||
|
||||
// ANCHOR: add-chip
|
||||
struct AddChip<F: FieldExt> {
|
||||
struct AddChip<F: Field> {
|
||||
config: AddConfig,
|
||||
_marker: PhantomData<F>,
|
||||
}
|
||||
// ANCHOR END: add-chip
|
||||
|
||||
// ANCHOR: mul-chip
|
||||
struct MulChip<F: FieldExt> {
|
||||
struct MulChip<F: Field> {
|
||||
config: MulConfig,
|
||||
_marker: PhantomData<F>,
|
||||
}
|
||||
// ANCHOR_END: mul-chip
|
||||
|
||||
// ANCHOR: add-chip-trait-impl
|
||||
impl<F: FieldExt> Chip<F> for AddChip<F> {
|
||||
impl<F: Field> Chip<F> for AddChip<F> {
|
||||
type Config = AddConfig;
|
||||
type Loaded = ();
|
||||
|
||||
|
@ -144,7 +144,7 @@ impl<F: FieldExt> Chip<F> for AddChip<F> {
|
|||
// ANCHOR END: add-chip-trait-impl
|
||||
|
||||
// ANCHOR: add-chip-impl
|
||||
impl<F: FieldExt> AddChip<F> {
|
||||
impl<F: Field> AddChip<F> {
|
||||
fn construct(config: <Self as Chip<F>>::Config, _loaded: <Self as Chip<F>>::Loaded) -> Self {
|
||||
Self {
|
||||
config,
|
||||
|
@ -174,7 +174,7 @@ impl<F: FieldExt> AddChip<F> {
|
|||
// ANCHOR END: add-chip-impl
|
||||
|
||||
// ANCHOR: add-instructions-impl
|
||||
impl<F: FieldExt> AddInstructions<F> for FieldChip<F> {
|
||||
impl<F: Field> AddInstructions<F> for FieldChip<F> {
|
||||
type Num = Number<F>;
|
||||
fn add(
|
||||
&self,
|
||||
|
@ -189,7 +189,7 @@ impl<F: FieldExt> AddInstructions<F> for FieldChip<F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> AddInstructions<F> for AddChip<F> {
|
||||
impl<F: Field> AddInstructions<F> for AddChip<F> {
|
||||
type Num = Number<F>;
|
||||
|
||||
fn add(
|
||||
|
@ -231,7 +231,7 @@ impl<F: FieldExt> AddInstructions<F> for AddChip<F> {
|
|||
// ANCHOR END: add-instructions-impl
|
||||
|
||||
// ANCHOR: mul-chip-trait-impl
|
||||
impl<F: FieldExt> Chip<F> for MulChip<F> {
|
||||
impl<F: Field> Chip<F> for MulChip<F> {
|
||||
type Config = MulConfig;
|
||||
type Loaded = ();
|
||||
|
||||
|
@ -246,7 +246,7 @@ impl<F: FieldExt> Chip<F> for MulChip<F> {
|
|||
// ANCHOR END: mul-chip-trait-impl
|
||||
|
||||
// ANCHOR: mul-chip-impl
|
||||
impl<F: FieldExt> MulChip<F> {
|
||||
impl<F: Field> MulChip<F> {
|
||||
fn construct(config: <Self as Chip<F>>::Config, _loaded: <Self as Chip<F>>::Loaded) -> Self {
|
||||
Self {
|
||||
config,
|
||||
|
@ -296,7 +296,7 @@ impl<F: FieldExt> MulChip<F> {
|
|||
// ANCHOR_END: mul-chip-impl
|
||||
|
||||
// ANCHOR: mul-instructions-impl
|
||||
impl<F: FieldExt> MulInstructions<F> for FieldChip<F> {
|
||||
impl<F: Field> MulInstructions<F> for FieldChip<F> {
|
||||
type Num = Number<F>;
|
||||
fn mul(
|
||||
&self,
|
||||
|
@ -310,7 +310,7 @@ impl<F: FieldExt> MulInstructions<F> for FieldChip<F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> MulInstructions<F> for MulChip<F> {
|
||||
impl<F: Field> MulInstructions<F> for MulChip<F> {
|
||||
type Num = Number<F>;
|
||||
|
||||
fn mul(
|
||||
|
@ -352,7 +352,7 @@ impl<F: FieldExt> MulInstructions<F> for MulChip<F> {
|
|||
// ANCHOR END: mul-instructions-impl
|
||||
|
||||
// ANCHOR: field-chip-trait-impl
|
||||
impl<F: FieldExt> Chip<F> for FieldChip<F> {
|
||||
impl<F: Field> Chip<F> for FieldChip<F> {
|
||||
type Config = FieldConfig;
|
||||
type Loaded = ();
|
||||
|
||||
|
@ -367,7 +367,7 @@ impl<F: FieldExt> Chip<F> for FieldChip<F> {
|
|||
// ANCHOR_END: field-chip-trait-impl
|
||||
|
||||
// ANCHOR: field-chip-impl
|
||||
impl<F: FieldExt> FieldChip<F> {
|
||||
impl<F: Field> FieldChip<F> {
|
||||
fn construct(config: <Self as Chip<F>>::Config, _loaded: <Self as Chip<F>>::Loaded) -> Self {
|
||||
Self {
|
||||
config,
|
||||
|
@ -396,7 +396,7 @@ impl<F: FieldExt> FieldChip<F> {
|
|||
// ANCHOR_END: field-chip-impl
|
||||
|
||||
// ANCHOR: field-instructions-impl
|
||||
impl<F: FieldExt> FieldInstructions<F> for FieldChip<F> {
|
||||
impl<F: Field> FieldInstructions<F> for FieldChip<F> {
|
||||
type Num = Number<F>;
|
||||
|
||||
fn load_private(
|
||||
|
@ -448,13 +448,13 @@ impl<F: FieldExt> FieldInstructions<F> for FieldChip<F> {
|
|||
/// 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<F: FieldExt> {
|
||||
struct MyCircuit<F: Field> {
|
||||
a: Value<F>,
|
||||
b: Value<F>,
|
||||
c: Value<F>,
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
|
||||
impl<F: Field> Circuit<F> for MyCircuit<F> {
|
||||
// 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<F: FieldExt> Circuit<F> for MyCircuit<F> {
|
|||
|
||||
#[allow(clippy::many_single_char_names)]
|
||||
fn main() {
|
||||
use group::ff::Field;
|
||||
use halo2_proofs::{dev::MockProver, pasta::Fp};
|
||||
use rand_core::OsRng;
|
||||
|
||||
|
|
|
@ -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<F: FieldExt>(points: &[F], evals: &[F]) -> Vec<F> {
|
||||
pub fn lagrange_interpolate<F: Field>(points: &[F], evals: &[F]) -> Vec<F> {
|
||||
assert_eq!(points.len(), evals.len());
|
||||
if points.len() == 1 {
|
||||
// Constant polynomial
|
||||
|
|
|
@ -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<F: FieldExt>: Sized {
|
||||
pub trait Chip<F: Field>: 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`].
|
||||
///
|
||||
|
|
|
@ -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<F: Group + Field> {
|
||||
enum CellValue<F: Field> {
|
||||
// An unassigned cell.
|
||||
Unassigned,
|
||||
// A cell that has been assigned a value.
|
||||
|
@ -83,12 +83,12 @@ enum CellValue<F: Group + Field> {
|
|||
|
||||
/// A value within an expression.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Ord, PartialOrd)]
|
||||
enum Value<F: Group + Field> {
|
||||
enum Value<F: Field> {
|
||||
Real(F),
|
||||
Poison,
|
||||
}
|
||||
|
||||
impl<F: Group + Field> From<CellValue<F>> for Value<F> {
|
||||
impl<F: Field> From<CellValue<F>> for Value<F> {
|
||||
fn from(value: CellValue<F>) -> Self {
|
||||
match value {
|
||||
// Cells that haven't been explicitly assigned to, default to zero.
|
||||
|
@ -99,7 +99,7 @@ impl<F: Group + Field> From<CellValue<F>> for Value<F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: Group + Field> Neg for Value<F> {
|
||||
impl<F: Field> Neg for Value<F> {
|
||||
type Output = Self;
|
||||
|
||||
fn neg(self) -> Self::Output {
|
||||
|
@ -110,7 +110,7 @@ impl<F: Group + Field> Neg for Value<F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: Group + Field> Add for Value<F> {
|
||||
impl<F: Field> Add for Value<F> {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
|
@ -121,7 +121,7 @@ impl<F: Group + Field> Add for Value<F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: Group + Field> Mul for Value<F> {
|
||||
impl<F: Field> Mul for Value<F> {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, rhs: Self) -> Self::Output {
|
||||
|
@ -139,7 +139,7 @@ impl<F: Group + Field> Mul for Value<F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: Group + Field> Mul<F> for Value<F> {
|
||||
impl<F: Field> Mul<F> for Value<F> {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, rhs: F) -> Self::Output {
|
||||
|
@ -267,7 +267,7 @@ impl<F: Group + Field> Mul<F> for Value<F> {
|
|||
/// ));
|
||||
/// ```
|
||||
#[derive(Debug)]
|
||||
pub struct MockProver<F: Group + Field> {
|
||||
pub struct MockProver<F: Field> {
|
||||
k: u32,
|
||||
n: u32,
|
||||
cs: ConstraintSystem<F>,
|
||||
|
@ -308,7 +308,7 @@ impl<F: Field> InstanceValue<F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: Field + Group> Assignment<F> for MockProver<F> {
|
||||
impl<F: Field> Assignment<F> for MockProver<F> {
|
||||
fn enter_region<NR, N>(&mut self, name: N)
|
||||
where
|
||||
NR: Into<String>,
|
||||
|
|
|
@ -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<F: Field>(
|
|||
/// | x0 = 0x5
|
||||
/// | x1 = 1
|
||||
/// ```
|
||||
fn render_lookup<F: FieldExt>(
|
||||
fn render_lookup<F: Field>(
|
||||
prover: &MockProver<F>,
|
||||
lookup_index: usize,
|
||||
location: &FailureLocation,
|
||||
|
@ -430,7 +429,7 @@ fn render_lookup<F: FieldExt>(
|
|||
)
|
||||
});
|
||||
|
||||
fn cell_value<'a, F: FieldExt, Q: Into<AnyQuery> + Copy>(
|
||||
fn cell_value<'a, F: Field, Q: Into<AnyQuery> + Copy>(
|
||||
column_type: Any,
|
||||
load: impl Fn(Q) -> Value<F> + 'a,
|
||||
) -> impl Fn(Q) -> BTreeMap<metadata::VirtualCell, String> + 'a {
|
||||
|
@ -535,7 +534,7 @@ fn render_lookup<F: FieldExt>(
|
|||
|
||||
impl VerifyFailure {
|
||||
/// Emits this failure in pretty-printed format to stderr.
|
||||
pub(super) fn emit<F: FieldExt>(&self, prover: &MockProver<F>) {
|
||||
pub(super) fn emit<F: Field>(&self, prover: &MockProver<F>) {
|
||||
match self {
|
||||
Self::CellNotAssigned {
|
||||
gate,
|
||||
|
|
|
@ -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<F: Field>(v: F) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn load<'a, F: FieldExt, T: ColumnType, Q: Into<AnyQuery> + Copy>(
|
||||
pub(super) fn load<'a, F: Field, T: ColumnType, Q: Into<AnyQuery> + Copy>(
|
||||
n: i32,
|
||||
row: i32,
|
||||
queries: &'a [(Column<T>, Rotation)],
|
||||
|
@ -86,7 +85,7 @@ pub(super) fn load<'a, F: FieldExt, T: ColumnType, Q: Into<AnyQuery> + Copy>(
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn load_instance<'a, F: FieldExt, T: ColumnType, Q: Into<AnyQuery> + Copy>(
|
||||
pub(super) fn load_instance<'a, F: Field, T: ColumnType, Q: Into<AnyQuery> + Copy>(
|
||||
n: i32,
|
||||
row: i32,
|
||||
queries: &'a [(Column<T>, Rotation)],
|
||||
|
@ -100,7 +99,7 @@ pub(super) fn load_instance<'a, F: FieldExt, T: ColumnType, Q: Into<AnyQuery> +
|
|||
}
|
||||
}
|
||||
|
||||
fn cell_value<'a, F: FieldExt, Q: Into<AnyQuery> + Copy>(
|
||||
fn cell_value<'a, F: Field, Q: Into<AnyQuery> + Copy>(
|
||||
virtual_cells: &'a [VirtualCell],
|
||||
load: impl Fn(Q) -> Value<F> + 'a,
|
||||
) -> impl Fn(Q) -> BTreeMap<metadata::VirtualCell, String> + 'a {
|
||||
|
@ -133,7 +132,7 @@ fn cell_value<'a, F: FieldExt, Q: Into<AnyQuery> + Copy>(
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn cell_values<'a, F: FieldExt>(
|
||||
pub(super) fn cell_values<'a, F: Field>(
|
||||
gate: &Gate<F>,
|
||||
poly: &Expression<F>,
|
||||
load_fixed: impl Fn(FixedQuery) -> Value<F> + 'a,
|
||||
|
|
|
@ -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<C: CurveAffine> {
|
|||
permuted_table_eval: C::Scalar,
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Argument<F> {
|
||||
impl<F: Field> Argument<F> {
|
||||
pub(in crate::plonk) fn read_permuted_commitments<
|
||||
C: CurveAffine,
|
||||
E: EncodedChallenge<C>,
|
||||
|
|
|
@ -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<F, B> Polynomial<F, B> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn batch_invert_assigned<F: FieldExt>(
|
||||
pub(crate) fn batch_invert_assigned<F: Field>(
|
||||
assigned: Vec<Polynomial<Assigned<F>, LagrangeCoeff>>,
|
||||
) -> Vec<Polynomial<F, LagrangeCoeff>> {
|
||||
let mut assigned_denominators: Vec<_> = assigned
|
||||
|
|
|
@ -206,13 +206,13 @@ impl<C: CurveAffine> Params<C> {
|
|||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||
pub struct Blind<F>(pub F);
|
||||
|
||||
impl<F: FieldExt> Default for Blind<F> {
|
||||
impl<F: Field> Default for Blind<F> {
|
||||
fn default() -> Self {
|
||||
Blind(F::one())
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Add for Blind<F> {
|
||||
impl<F: Field> Add for Blind<F> {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Blind<F>) -> Self {
|
||||
|
@ -220,7 +220,7 @@ impl<F: FieldExt> Add for Blind<F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Mul for Blind<F> {
|
||||
impl<F: Field> Mul for Blind<F> {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, rhs: Blind<F>) -> Self {
|
||||
|
@ -228,25 +228,25 @@ impl<F: FieldExt> Mul for Blind<F> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> AddAssign for Blind<F> {
|
||||
impl<F: Field> AddAssign for Blind<F> {
|
||||
fn add_assign(&mut self, rhs: Blind<F>) {
|
||||
self.0 += rhs.0;
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> MulAssign for Blind<F> {
|
||||
impl<F: Field> MulAssign for Blind<F> {
|
||||
fn mul_assign(&mut self, rhs: Blind<F>) {
|
||||
self.0 *= rhs.0;
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> AddAssign<F> for Blind<F> {
|
||||
impl<F: Field> AddAssign<F> for Blind<F> {
|
||||
fn add_assign(&mut self, rhs: F) {
|
||||
self.0 += rhs;
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> MulAssign<F> for Blind<F> {
|
||||
impl<F: Field> MulAssign<F> for Blind<F> {
|
||||
fn mul_assign(&mut self, rhs: F) {
|
||||
self.0 *= rhs;
|
||||
}
|
||||
|
|
|
@ -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<F: FieldExt> {
|
||||
pub struct EvaluationDomain<F: Field> {
|
||||
n: u64,
|
||||
k: u32,
|
||||
extended_k: u32,
|
||||
|
|
|
@ -140,7 +140,7 @@ impl<E, F: Field, B: Basis> Evaluator<E, F, B> {
|
|||
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<F>,
|
||||
poly_len: usize,
|
||||
chunk_size: usize,
|
||||
|
@ -442,7 +442,7 @@ impl<E: Clone, F: Field> MulAssign for Ast<E, F, ExtendedLagrangeCoeff> {
|
|||
/// Operations which can be performed over a given basis.
|
||||
pub(crate) trait BasisOps: Basis {
|
||||
fn empty_poly<F: FieldExt>(domain: &EvaluationDomain<F>) -> Polynomial<F, Self>;
|
||||
fn constant_term<F: FieldExt>(
|
||||
fn constant_term<F: Field>(
|
||||
poly_len: usize,
|
||||
chunk_size: usize,
|
||||
chunk_index: usize,
|
||||
|
@ -469,7 +469,7 @@ impl BasisOps for Coeff {
|
|||
domain.empty_coeff()
|
||||
}
|
||||
|
||||
fn constant_term<F: FieldExt>(
|
||||
fn constant_term<F: Field>(
|
||||
poly_len: usize,
|
||||
chunk_size: usize,
|
||||
chunk_index: usize,
|
||||
|
@ -520,7 +520,7 @@ impl BasisOps for LagrangeCoeff {
|
|||
domain.empty_lagrange()
|
||||
}
|
||||
|
||||
fn constant_term<F: FieldExt>(
|
||||
fn constant_term<F: Field>(
|
||||
poly_len: usize,
|
||||
chunk_size: usize,
|
||||
chunk_index: usize,
|
||||
|
@ -564,7 +564,7 @@ impl BasisOps for ExtendedLagrangeCoeff {
|
|||
domain.empty_extended()
|
||||
}
|
||||
|
||||
fn constant_term<F: FieldExt>(
|
||||
fn constant_term<F: Field>(
|
||||
poly_len: usize,
|
||||
chunk_size: usize,
|
||||
chunk_index: usize,
|
||||
|
|
|
@ -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<F, Q> = (
|
|||
Vec<Vec<F>>,
|
||||
);
|
||||
|
||||
fn construct_intermediate_sets<F: FieldExt, I, Q: Query<F>>(queries: I) -> IntermediateSets<F, Q>
|
||||
fn construct_intermediate_sets<F: Field + Ord, I, Q: Query<F>>(queries: I) -> IntermediateSets<F, Q>
|
||||
where
|
||||
I: IntoIterator<Item = Q> + Clone,
|
||||
{
|
||||
|
|
|
@ -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<FF: FieldExt> {
|
||||
trait StandardCs<FF: Field> {
|
||||
fn raw_multiply<F>(
|
||||
&self,
|
||||
layouter: &mut impl Layouter<FF>,
|
||||
|
@ -71,17 +72,17 @@ fn plonk_api() {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct MyCircuit<F: FieldExt> {
|
||||
struct MyCircuit<F: Field> {
|
||||
a: Value<F>,
|
||||
lookup_table: Vec<F>,
|
||||
}
|
||||
|
||||
struct StandardPlonk<F: FieldExt> {
|
||||
struct StandardPlonk<F: Field> {
|
||||
config: PlonkConfig,
|
||||
_marker: PhantomData<F>,
|
||||
}
|
||||
|
||||
impl<FF: FieldExt> StandardPlonk<FF> {
|
||||
impl<FF: Field> StandardPlonk<FF> {
|
||||
fn new(config: PlonkConfig) -> Self {
|
||||
StandardPlonk {
|
||||
config,
|
||||
|
@ -90,7 +91,7 @@ fn plonk_api() {
|
|||
}
|
||||
}
|
||||
|
||||
impl<FF: FieldExt> StandardCs<FF> for StandardPlonk<FF> {
|
||||
impl<FF: Field> StandardCs<FF> for StandardPlonk<FF> {
|
||||
fn raw_multiply<F>(
|
||||
&self,
|
||||
layouter: &mut impl Layouter<FF>,
|
||||
|
@ -265,7 +266,7 @@ fn plonk_api() {
|
|||
}
|
||||
}
|
||||
|
||||
impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
|
||||
impl<F: Field> Circuit<F> for MyCircuit<F> {
|
||||
type Config = PlonkConfig;
|
||||
type FloorPlanner = SimpleFloorPlanner;
|
||||
|
||||
|
|
Loading…
Reference in New Issue