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
|
### Added
|
||||||
- `halo2_gadgets::poseidon::primitives::generate_constants`
|
- `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
|
## [0.2.0] - 2022-06-23
|
||||||
### Added
|
### Added
|
||||||
- `halo2_gadgets::utilities::RangeConstrained<F, Value<F>>::bitrange_of`
|
- `halo2_gadgets::utilities::RangeConstrained<F, Value<F>>::bitrange_of`
|
||||||
|
|
|
@ -8,9 +8,8 @@ use std::{
|
||||||
ops::{Deref, Range},
|
ops::{Deref, Range},
|
||||||
};
|
};
|
||||||
|
|
||||||
use ff::PrimeField;
|
use ff::{Field, PrimeField};
|
||||||
use halo2_proofs::{
|
use halo2_proofs::{
|
||||||
arithmetic::FieldExt,
|
|
||||||
circuit::{AssignedCell, Layouter, Region, Value},
|
circuit::{AssignedCell, Layouter, Region, Value},
|
||||||
plonk::{Advice, Assigned, Column, ConstraintSystem, Constraints, Error, Selector},
|
plonk::{Advice, Assigned, Column, ConstraintSystem, Constraints, Error, Selector},
|
||||||
poly::Rotation,
|
poly::Rotation,
|
||||||
|
@ -385,8 +384,8 @@ impl Config {
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
// `x`-coordinate of the accumulator.
|
// `x`-coordinate of the accumulator.
|
||||||
struct X<F: FieldExt>(AssignedCell<Assigned<F>, F>);
|
struct X<F: Field>(AssignedCell<Assigned<F>, F>);
|
||||||
impl<F: FieldExt> Deref for X<F> {
|
impl<F: Field> Deref for X<F> {
|
||||||
type Target = AssignedCell<Assigned<F>, F>;
|
type Target = AssignedCell<Assigned<F>, F>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
|
@ -396,8 +395,8 @@ impl<F: FieldExt> Deref for X<F> {
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
// `y`-coordinate of the accumulator.
|
// `y`-coordinate of the accumulator.
|
||||||
struct Y<F: FieldExt>(AssignedCell<Assigned<F>, F>);
|
struct Y<F: Field>(AssignedCell<Assigned<F>, F>);
|
||||||
impl<F: FieldExt> Deref for Y<F> {
|
impl<F: Field> Deref for Y<F> {
|
||||||
type Target = AssignedCell<Assigned<F>, F>;
|
type Target = AssignedCell<Assigned<F>, F>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
|
@ -407,8 +406,8 @@ impl<F: FieldExt> Deref for Y<F> {
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
// Cumulative sum `z` used to decompose the scalar.
|
// Cumulative sum `z` used to decompose the scalar.
|
||||||
struct Z<F: FieldExt>(AssignedCell<F, F>);
|
struct Z<F: Field>(AssignedCell<F, F>);
|
||||||
impl<F: FieldExt> Deref for Z<F> {
|
impl<F: Field> Deref for Z<F> {
|
||||||
type Target = AssignedCell<F, F>;
|
type Target = AssignedCell<F, F>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
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.
|
/// 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>
|
Chip<F>
|
||||||
{
|
{
|
||||||
/// Variable representing the word over which the Poseidon permutation operates.
|
/// 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
|
/// [`Hash`]: self::Hash
|
||||||
pub trait PoseidonSpongeInstructions<
|
pub trait PoseidonSpongeInstructions<
|
||||||
F: FieldExt,
|
F: Field,
|
||||||
S: Spec<F, T, RATE>,
|
S: Spec<F, T, RATE>,
|
||||||
D: Domain<F, RATE>,
|
D: Domain<F, RATE>,
|
||||||
const T: usize,
|
const T: usize,
|
||||||
|
@ -71,7 +71,7 @@ pub trait PoseidonSpongeInstructions<
|
||||||
/// A word over which the Poseidon permutation operates.
|
/// A word over which the Poseidon permutation operates.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Word<
|
pub struct Word<
|
||||||
F: FieldExt,
|
F: Field,
|
||||||
PoseidonChip: PoseidonInstructions<F, S, T, RATE>,
|
PoseidonChip: PoseidonInstructions<F, S, T, RATE>,
|
||||||
S: Spec<F, T, RATE>,
|
S: Spec<F, T, RATE>,
|
||||||
const T: usize,
|
const T: usize,
|
||||||
|
@ -81,7 +81,7 @@ pub struct Word<
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
F: FieldExt,
|
F: Field,
|
||||||
PoseidonChip: PoseidonInstructions<F, S, T, RATE>,
|
PoseidonChip: PoseidonInstructions<F, S, T, RATE>,
|
||||||
S: Spec<F, T, RATE>,
|
S: Spec<F, T, RATE>,
|
||||||
const T: usize,
|
const T: usize,
|
||||||
|
@ -100,7 +100,7 @@ impl<
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poseidon_sponge<
|
fn poseidon_sponge<
|
||||||
F: FieldExt,
|
F: Field,
|
||||||
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
||||||
S: Spec<F, T, RATE>,
|
S: Spec<F, T, RATE>,
|
||||||
D: Domain<F, RATE>,
|
D: Domain<F, RATE>,
|
||||||
|
@ -122,7 +122,7 @@ fn poseidon_sponge<
|
||||||
/// A Poseidon sponge.
|
/// A Poseidon sponge.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Sponge<
|
pub struct Sponge<
|
||||||
F: FieldExt,
|
F: Field,
|
||||||
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
||||||
S: Spec<F, T, RATE>,
|
S: Spec<F, T, RATE>,
|
||||||
M: SpongeMode,
|
M: SpongeMode,
|
||||||
|
@ -137,7 +137,7 @@ pub struct Sponge<
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
F: FieldExt,
|
F: Field,
|
||||||
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
||||||
S: Spec<F, T, RATE>,
|
S: Spec<F, T, RATE>,
|
||||||
D: Domain<F, RATE>,
|
D: Domain<F, RATE>,
|
||||||
|
@ -210,7 +210,7 @@ impl<
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
F: FieldExt,
|
F: Field,
|
||||||
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
||||||
S: Spec<F, T, RATE>,
|
S: Spec<F, T, RATE>,
|
||||||
D: Domain<F, RATE>,
|
D: Domain<F, RATE>,
|
||||||
|
@ -241,7 +241,7 @@ impl<
|
||||||
/// A Poseidon hash function, built around a sponge.
|
/// A Poseidon hash function, built around a sponge.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Hash<
|
pub struct Hash<
|
||||||
F: FieldExt,
|
F: Field,
|
||||||
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
||||||
S: Spec<F, T, RATE>,
|
S: Spec<F, T, RATE>,
|
||||||
D: Domain<F, RATE>,
|
D: Domain<F, RATE>,
|
||||||
|
@ -252,7 +252,7 @@ pub struct Hash<
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
F: FieldExt,
|
F: Field,
|
||||||
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
PoseidonChip: PoseidonSpongeInstructions<F, S, D, T, RATE>,
|
||||||
S: Spec<F, T, RATE>,
|
S: Spec<F, T, RATE>,
|
||||||
D: Domain<F, RATE>,
|
D: Domain<F, RATE>,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
|
use group::ff::Field;
|
||||||
use halo2_proofs::{
|
use halo2_proofs::{
|
||||||
arithmetic::FieldExt,
|
arithmetic::FieldExt,
|
||||||
circuit::{AssignedCell, Cell, Chip, Layouter, Region, Value},
|
circuit::{AssignedCell, Cell, Chip, Layouter, Region, Value},
|
||||||
|
@ -18,7 +19,7 @@ use crate::utilities::Var;
|
||||||
|
|
||||||
/// Configuration for a [`Pow5Chip`].
|
/// Configuration for a [`Pow5Chip`].
|
||||||
#[derive(Clone, Debug)]
|
#[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],
|
pub(crate) state: [Column<Advice>; WIDTH],
|
||||||
partial_sbox: Column<Advice>,
|
partial_sbox: Column<Advice>,
|
||||||
rc_a: [Column<Fixed>; WIDTH],
|
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
|
/// The chip is implemented using a single round per row for full rounds, and two rounds
|
||||||
/// per row for partial rounds.
|
/// per row for partial rounds.
|
||||||
#[derive(Debug)]
|
#[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>,
|
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.
|
/// Configures this chip for use in a circuit.
|
||||||
///
|
///
|
||||||
/// # Side-effects
|
/// # 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 Config = Pow5Config<F, WIDTH, RATE>;
|
||||||
type Loaded = ();
|
type Loaded = ();
|
||||||
|
|
||||||
|
@ -403,21 +404,21 @@ impl<
|
||||||
|
|
||||||
/// A word in the Poseidon state.
|
/// A word in the Poseidon state.
|
||||||
#[derive(Clone, Debug)]
|
#[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> {
|
fn from(state_word: StateWord<F>) -> AssignedCell<F, F> {
|
||||||
state_word.0
|
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> {
|
fn from(cell_value: AssignedCell<F, F>) -> StateWord<F> {
|
||||||
StateWord(cell_value)
|
StateWord(cell_value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: FieldExt> Var<F> for StateWord<F> {
|
impl<F: Field> Var<F> for StateWord<F> {
|
||||||
fn cell(&self) -> Cell {
|
fn cell(&self) -> Cell {
|
||||||
self.0.cell()
|
self.0.cell()
|
||||||
}
|
}
|
||||||
|
@ -428,7 +429,7 @@ impl<F: FieldExt> Var<F> for StateWord<F> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[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> {
|
impl<F: FieldExt, const WIDTH: usize> Pow5State<F, WIDTH> {
|
||||||
fn full_round<const RATE: usize>(
|
fn full_round<const RATE: usize>(
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::fmt;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
|
use group::ff::Field;
|
||||||
use halo2_proofs::arithmetic::FieldExt;
|
use halo2_proofs::arithmetic::FieldExt;
|
||||||
|
|
||||||
pub(crate) mod fp;
|
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];
|
pub type Mds<F, const T: usize> = [[F; T]; T];
|
||||||
|
|
||||||
/// A specification for a Poseidon permutation.
|
/// 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.
|
/// The number of full rounds for this specification.
|
||||||
///
|
///
|
||||||
/// This must be an even number.
|
/// 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.
|
/// 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>,
|
state: &mut State<F, T>,
|
||||||
mds: &Mds<F, T>,
|
mds: &Mds<F, T>,
|
||||||
round_constants: &[[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>,
|
state: &mut State<F, T>,
|
||||||
input: Option<&Absorbing<F, RATE>>,
|
input: Option<&Absorbing<F, RATE>>,
|
||||||
mds_matrix: &Mds<F, T>,
|
mds_matrix: &Mds<F, T>,
|
||||||
|
@ -184,7 +185,7 @@ impl<F: fmt::Debug, const RATE: usize> Absorbing<F, RATE> {
|
||||||
|
|
||||||
/// A Poseidon sponge.
|
/// A Poseidon sponge.
|
||||||
pub(crate) struct Sponge<
|
pub(crate) struct Sponge<
|
||||||
F: FieldExt,
|
F: Field,
|
||||||
S: Spec<F, T, RATE>,
|
S: Spec<F, T, RATE>,
|
||||||
M: SpongeMode,
|
M: SpongeMode,
|
||||||
const T: usize,
|
const T: usize,
|
||||||
|
@ -197,7 +198,7 @@ pub(crate) struct Sponge<
|
||||||
_marker: PhantomData<S>,
|
_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>
|
Sponge<F, S, Absorbing<F, RATE>, T, RATE>
|
||||||
{
|
{
|
||||||
/// Constructs a new sponge for the given Poseidon specification.
|
/// 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>
|
Sponge<F, S, Squeezing<F, RATE>, T, RATE>
|
||||||
{
|
{
|
||||||
/// Squeezes an element from the sponge.
|
/// 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.
|
/// 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.
|
/// Iterator that outputs padding field elements.
|
||||||
type Padding: IntoIterator<Item = F>;
|
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.
|
/// A Poseidon hash function, built around a sponge.
|
||||||
pub struct Hash<
|
pub struct Hash<
|
||||||
F: FieldExt,
|
F: Field,
|
||||||
S: Spec<F, T, RATE>,
|
S: Spec<F, T, RATE>,
|
||||||
D: Domain<F, RATE>,
|
D: Domain<F, RATE>,
|
||||||
const T: usize,
|
const T: usize,
|
||||||
|
@ -335,7 +336,7 @@ pub struct Hash<
|
||||||
_domain: PhantomData<D>,
|
_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>
|
fmt::Debug for Hash<F, S, D, T, RATE>
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
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>
|
Hash<F, S, D, T, RATE>
|
||||||
{
|
{
|
||||||
/// Initializes a new hasher.
|
/// Initializes a new hasher.
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use bitvec::prelude::*;
|
use bitvec::prelude::*;
|
||||||
|
use group::ff::{Field, PrimeField};
|
||||||
use halo2_proofs::arithmetic::FieldExt;
|
use halo2_proofs::arithmetic::FieldExt;
|
||||||
|
|
||||||
const STATE: usize = 80;
|
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),
|
state: BitArr!(for 80, in u8, Msb0),
|
||||||
next_bit: usize,
|
next_bit: usize,
|
||||||
_field: PhantomData<F>,
|
_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 {
|
pub(super) fn new(sbox: SboxType, t: u16, r_f: u16, r_p: u16) -> Self {
|
||||||
// Initialize the LFSR state.
|
// Initialize the LFSR state.
|
||||||
let mut state = bitarr![u8, Msb0; 1; 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
|
/// Returns the next field element from this Grain instantiation, without using
|
||||||
/// rejection sampling.
|
/// rejection sampling.
|
||||||
pub(super) fn next_field_element_without_rejection(&mut self) -> F {
|
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;
|
type Item = bool;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
|
|
@ -66,7 +66,7 @@ impl Spec<Fq, 3, 2> for P128Pow5T3 {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ff::PrimeField;
|
use ff::{Field, PrimeField};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use pasta_curves::arithmetic::FieldExt;
|
use pasta_curves::arithmetic::FieldExt;
|
||||||
|
@ -82,9 +82,9 @@ mod tests {
|
||||||
/// The same Poseidon specification as poseidon::P128Pow5T3, but constructed
|
/// The same Poseidon specification as poseidon::P128Pow5T3, but constructed
|
||||||
/// such that its constants will be generated at runtime.
|
/// such that its constants will be generated at runtime.
|
||||||
#[derive(Debug)]
|
#[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)]
|
#![allow(dead_code)]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
P128Pow5T3Gen(PhantomData::default())
|
P128Pow5T3Gen(PhantomData::default())
|
||||||
|
|
|
@ -6,8 +6,8 @@ use std::cmp::min;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
use group::ff::Field;
|
||||||
use halo2_proofs::{
|
use halo2_proofs::{
|
||||||
arithmetic::FieldExt,
|
|
||||||
circuit::{Chip, Layouter},
|
circuit::{Chip, Layouter},
|
||||||
plonk::Error,
|
plonk::Error,
|
||||||
};
|
};
|
||||||
|
@ -22,7 +22,7 @@ pub const BLOCK_SIZE: usize = 16;
|
||||||
const DIGEST_SIZE: usize = 8;
|
const DIGEST_SIZE: usize = 8;
|
||||||
|
|
||||||
/// The set of circuit instructions required to use the [`Sha256`] gadget.
|
/// 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.
|
/// Variable representing the SHA-256 internal state.
|
||||||
type State: Clone + fmt::Debug;
|
type State: Clone + fmt::Debug;
|
||||||
/// Variable representing a 32-bit word of the input block to the SHA-256 compression
|
/// 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
|
/// A gadget that constrains a SHA-256 invocation. It supports input at a granularity of
|
||||||
/// 32 bits.
|
/// 32 bits.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Sha256<F: FieldExt, CS: Sha256Instructions<F>> {
|
pub struct Sha256<F: Field, CS: Sha256Instructions<F>> {
|
||||||
chip: CS,
|
chip: CS,
|
||||||
state: CS::State,
|
state: CS::State,
|
||||||
cur_block: Vec<CS::BlockWord>,
|
cur_block: Vec<CS::BlockWord>,
|
||||||
length: usize,
|
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.
|
/// Create a new hasher instance.
|
||||||
pub fn new(chip: Sha256Chip, mut layouter: impl Layouter<F>) -> Result<Self, Error> {
|
pub fn new(chip: Sha256Chip, mut layouter: impl Layouter<F>) -> Result<Self, Error> {
|
||||||
let state = chip.initialization_vector(&mut layouter)?;
|
let state = chip.initialization_vector(&mut layouter)?;
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
use super::super::{util::*, Gate};
|
use super::super::{util::*, Gate};
|
||||||
use halo2_proofs::{
|
|
||||||
arithmetic::FieldExt,
|
use group::ff::{Field, PrimeField};
|
||||||
plonk::{Constraint, Constraints, Expression},
|
use halo2_proofs::plonk::{Constraint, Constraints, Expression};
|
||||||
};
|
|
||||||
use std::marker::PhantomData;
|
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> {
|
fn ones() -> Expression<F> {
|
||||||
Expression::Constant(F::one())
|
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> {
|
fn ones() -> Expression<F> {
|
||||||
Expression::Constant(F::one())
|
Expression::Constant(F::one())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
use super::super::Gate;
|
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;
|
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
|
/// s_word for W_16 to W_63
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn s_word(
|
pub fn s_word(
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use super::{util::*, AssignedBits};
|
use super::{util::*, AssignedBits};
|
||||||
|
|
||||||
|
use group::ff::{Field, PrimeField};
|
||||||
use halo2_proofs::{
|
use halo2_proofs::{
|
||||||
arithmetic::FieldExt,
|
|
||||||
circuit::{Chip, Layouter, Region, Value},
|
circuit::{Chip, Layouter, Region, Value},
|
||||||
pasta::pallas,
|
pasta::pallas,
|
||||||
plonk::{Advice, Column, ConstraintSystem, Error, TableColumn},
|
plonk::{Advice, Column, ConstraintSystem, Error, TableColumn},
|
||||||
|
@ -153,12 +154,12 @@ pub(super) struct SpreadTableConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(super) struct SpreadTableChip<F: FieldExt> {
|
pub(super) struct SpreadTableChip<F: Field> {
|
||||||
config: SpreadTableConfig,
|
config: SpreadTableConfig,
|
||||||
_marker: PhantomData<F>,
|
_marker: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: FieldExt> Chip<F> for SpreadTableChip<F> {
|
impl<F: Field> Chip<F> for SpreadTableChip<F> {
|
||||||
type Config = SpreadTableConfig;
|
type Config = SpreadTableConfig;
|
||||||
type Loaded = ();
|
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(
|
pub fn configure(
|
||||||
meta: &mut ConstraintSystem<F>,
|
meta: &mut ConstraintSystem<F>,
|
||||||
input_tag: Column<Advice>,
|
input_tag: Column<Advice>,
|
||||||
|
@ -250,7 +251,7 @@ impl<F: FieldExt> SpreadTableChip<F> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SpreadTableConfig {
|
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(
|
(1..=(1 << 16)).scan(
|
||||||
(F::zero(), F::zero(), F::zero()),
|
(F::zero(), F::zero(), F::zero()),
|
||||||
|(tag, dense, spread), i| {
|
|(tag, dense, spread), i| {
|
||||||
|
@ -287,8 +288,8 @@ mod tests {
|
||||||
use super::{get_tag, SpreadTableChip, SpreadTableConfig};
|
use super::{get_tag, SpreadTableChip, SpreadTableConfig};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
|
use group::ff::PrimeField;
|
||||||
use halo2_proofs::{
|
use halo2_proofs::{
|
||||||
arithmetic::FieldExt,
|
|
||||||
circuit::{Layouter, SimpleFloorPlanner, Value},
|
circuit::{Layouter, SimpleFloorPlanner, Value},
|
||||||
dev::MockProver,
|
dev::MockProver,
|
||||||
pasta::Fp,
|
pasta::Fp,
|
||||||
|
@ -303,7 +304,7 @@ mod tests {
|
||||||
|
|
||||||
struct MyCircuit {}
|
struct MyCircuit {}
|
||||||
|
|
||||||
impl<F: FieldExt> Circuit<F> for MyCircuit {
|
impl<F: PrimeField> Circuit<F> for MyCircuit {
|
||||||
type Config = SpreadTableConfig;
|
type Config = SpreadTableConfig;
|
||||||
type FloorPlanner = SimpleFloorPlanner;
|
type FloorPlanner = SimpleFloorPlanner;
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,8 @@ use halo2_proofs::{
|
||||||
plonk::{Assigned, Error},
|
plonk::{Assigned, Error},
|
||||||
};
|
};
|
||||||
|
|
||||||
use group::ff::{PrimeField, PrimeFieldBits};
|
use group::ff::{Field, PrimeField, PrimeFieldBits};
|
||||||
use pasta_curves::{
|
use pasta_curves::{arithmetic::CurveAffine, pallas};
|
||||||
arithmetic::{CurveAffine, FieldExt},
|
|
||||||
pallas,
|
|
||||||
};
|
|
||||||
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
@ -379,15 +376,15 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The x-coordinate of the accumulator in a Sinsemilla hash instance.
|
/// 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 {
|
fn from(cell_value: AssignedCell<Assigned<F>, F>) -> Self {
|
||||||
X(cell_value)
|
X(cell_value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: FieldExt> Deref for X<F> {
|
impl<F: Field> Deref for X<F> {
|
||||||
type Target = AssignedCell<Assigned<F>, F>;
|
type Target = AssignedCell<Assigned<F>, F>;
|
||||||
|
|
||||||
fn deref(&self) -> &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
|
/// This is never actually witnessed until the last round, since it
|
||||||
/// can be derived from other variables. Thus it only exists as a field
|
/// can be derived from other variables. Thus it only exists as a field
|
||||||
/// element, not a `CellValue`.
|
/// 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 {
|
fn from(value: Value<Assigned<F>>) -> Self {
|
||||||
Y(value)
|
Y(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: FieldExt> Deref for Y<F> {
|
impl<F: Field> Deref for Y<F> {
|
||||||
type Target = Value<Assigned<F>>;
|
type Target = Value<Assigned<F>>;
|
||||||
|
|
||||||
fn deref(&self) -> &Value<Assigned<F>> {
|
fn deref(&self) -> &Value<Assigned<F>> {
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
//! Gadget and chips for the Sinsemilla hash function.
|
//! Gadget and chips for the Sinsemilla hash function.
|
||||||
use ff::PrimeFieldBits;
|
use ff::{Field, PrimeFieldBits};
|
||||||
use halo2_proofs::{
|
use halo2_proofs::circuit::{AssignedCell, Cell, Value};
|
||||||
arithmetic::FieldExt,
|
|
||||||
circuit::{AssignedCell, Cell, Value},
|
|
||||||
};
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
/// A [`Message`] composed of several [`MessagePiece`]s.
|
/// A [`Message`] composed of several [`MessagePiece`]s.
|
||||||
#[derive(Clone, Debug)]
|
#[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>
|
impl<F: PrimeFieldBits, const K: usize, const MAX_WORDS: usize> From<Vec<MessagePiece<F, K>>>
|
||||||
From<Vec<MessagePiece<F, K>>> for Message<F, K, MAX_WORDS>
|
for Message<F, K, MAX_WORDS>
|
||||||
{
|
{
|
||||||
fn from(pieces: Vec<MessagePiece<F, K>>) -> Self {
|
fn from(pieces: Vec<MessagePiece<F, K>>) -> Self {
|
||||||
// A message cannot contain more than `MAX_WORDS` words.
|
// 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>
|
for Message<F, K, MAX_WORDS>
|
||||||
{
|
{
|
||||||
type Target = [MessagePiece<F, K>];
|
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
|
/// The piece must fit within a base field element, which means its length
|
||||||
/// cannot exceed the base field's `NUM_BITS`.
|
/// cannot exceed the base field's `NUM_BITS`.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct MessagePiece<F: FieldExt, const K: usize> {
|
pub struct MessagePiece<F: Field, const K: usize> {
|
||||||
cell_value: AssignedCell<F, F>,
|
cell_value: AssignedCell<F, F>,
|
||||||
/// The number of K-bit words in this message piece.
|
/// The number of K-bit words in this message piece.
|
||||||
num_words: usize,
|
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 {
|
pub fn new(cell_value: AssignedCell<F, F>, num_words: usize) -> Self {
|
||||||
assert!(num_words * K < F::NUM_BITS as usize);
|
assert!(num_words * K < F::NUM_BITS as usize);
|
||||||
Self {
|
Self {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
//! Utility gadgets.
|
//! Utility gadgets.
|
||||||
|
|
||||||
use ff::{Field, PrimeFieldBits};
|
use ff::{Field, PrimeField, PrimeFieldBits};
|
||||||
use halo2_proofs::{
|
use halo2_proofs::{
|
||||||
circuit::{AssignedCell, Cell, Layouter, Value},
|
circuit::{AssignedCell, Cell, Layouter, Value},
|
||||||
plonk::{Advice, Column, Error, Expression},
|
plonk::{Advice, Column, Error, Expression},
|
||||||
};
|
};
|
||||||
use pasta_curves::arithmetic::FieldExt;
|
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ impl<F: Field> FieldValue<F> for AssignedCell<F, F> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait for a variable in the circuit.
|
/// 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.
|
/// The cell at which this variable was allocated.
|
||||||
fn cell(&self) -> Cell;
|
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>;
|
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 {
|
fn cell(&self) -> Cell {
|
||||||
self.cell()
|
self.cell()
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ impl<F: FieldExt> Var<F> for AssignedCell<F, F> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait for utilities used across circuits.
|
/// Trait for utilities used across circuits.
|
||||||
pub trait UtilitiesInstructions<F: FieldExt> {
|
pub trait UtilitiesInstructions<F: Field> {
|
||||||
/// Variable in the circuit.
|
/// Variable in the circuit.
|
||||||
type Var: Var<F>;
|
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.
|
/// 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)
|
range_check(value, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If `a` then `b`, else `c`. Returns (a * b) + (1 - a) * c.
|
/// If `a` then `b`, else `c`. Returns (a * b) + (1 - a) * c.
|
||||||
///
|
///
|
||||||
/// `a` must be a boolean-constrained expression.
|
/// `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();
|
let one_minus_a = Expression::Constant(F::one()) - a.clone();
|
||||||
a * b + one_minus_a * c
|
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),
|
/// Check that an expression is in the small range [0..range),
|
||||||
/// i.e. 0 ≤ word < 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| {
|
(1..range).fold(word.clone(), |acc, i| {
|
||||||
acc * (Expression::Constant(F::from(i as u64)) - word.clone())
|
acc * (Expression::Constant(F::from(i as u64)) - word.clone())
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
//! Gadget and chip for a conditional swap utility.
|
//! Gadget and chip for a conditional swap utility.
|
||||||
|
|
||||||
use super::{bool_check, ternary, UtilitiesInstructions};
|
use super::{bool_check, ternary, UtilitiesInstructions};
|
||||||
|
|
||||||
|
use group::ff::{Field, PrimeField};
|
||||||
use halo2_proofs::{
|
use halo2_proofs::{
|
||||||
circuit::{AssignedCell, Chip, Layouter, Value},
|
circuit::{AssignedCell, Chip, Layouter, Value},
|
||||||
plonk::{Advice, Column, ConstraintSystem, Constraints, Error, Selector},
|
plonk::{Advice, Column, ConstraintSystem, Constraints, Error, Selector},
|
||||||
poly::Rotation,
|
poly::Rotation,
|
||||||
};
|
};
|
||||||
use pasta_curves::arithmetic::FieldExt;
|
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
/// Instructions for a conditional swap gadget.
|
/// Instructions for a conditional swap gadget.
|
||||||
pub trait CondSwapInstructions<F: FieldExt>: UtilitiesInstructions<F> {
|
pub trait CondSwapInstructions<F: Field>: UtilitiesInstructions<F> {
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
/// Given an input pair (a,b) and a `swap` boolean flag, returns
|
/// 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.
|
/// (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>,
|
_marker: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: FieldExt> Chip<F> for CondSwapChip<F> {
|
impl<F: Field> Chip<F> for CondSwapChip<F> {
|
||||||
type Config = CondSwapConfig;
|
type Config = CondSwapConfig;
|
||||||
type Loaded = ();
|
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>;
|
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)]
|
#[allow(clippy::type_complexity)]
|
||||||
fn swap(
|
fn swap(
|
||||||
&self,
|
&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.
|
/// Configures this chip for use in a circuit.
|
||||||
///
|
///
|
||||||
/// # Side-effects
|
/// # Side-effects
|
||||||
|
@ -195,25 +197,25 @@ impl<F: FieldExt> CondSwapChip<F> {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::super::UtilitiesInstructions;
|
use super::super::UtilitiesInstructions;
|
||||||
use super::{CondSwapChip, CondSwapConfig, CondSwapInstructions};
|
use super::{CondSwapChip, CondSwapConfig, CondSwapInstructions};
|
||||||
use group::ff::Field;
|
use group::ff::{Field, PrimeField};
|
||||||
use halo2_proofs::{
|
use halo2_proofs::{
|
||||||
circuit::{Layouter, SimpleFloorPlanner, Value},
|
circuit::{Layouter, SimpleFloorPlanner, Value},
|
||||||
dev::MockProver,
|
dev::MockProver,
|
||||||
plonk::{Circuit, ConstraintSystem, Error},
|
plonk::{Circuit, ConstraintSystem, Error},
|
||||||
};
|
};
|
||||||
use pasta_curves::{arithmetic::FieldExt, pallas::Base};
|
use pasta_curves::pallas::Base;
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cond_swap() {
|
fn cond_swap() {
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct MyCircuit<F: FieldExt> {
|
struct MyCircuit<F: Field> {
|
||||||
a: Value<F>,
|
a: Value<F>,
|
||||||
b: Value<F>,
|
b: Value<F>,
|
||||||
swap: Value<bool>,
|
swap: Value<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
|
impl<F: PrimeField> Circuit<F> for MyCircuit<F> {
|
||||||
type Config = CondSwapConfig;
|
type Config = CondSwapConfig;
|
||||||
type FloorPlanner = SimpleFloorPlanner;
|
type FloorPlanner = SimpleFloorPlanner;
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,13 @@ use halo2_proofs::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::range_check;
|
use super::range_check;
|
||||||
use pasta_curves::arithmetic::FieldExt;
|
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
/// The running sum $[z_0, ..., z_W]$. If created in strict mode, $z_W = 0$.
|
/// The running sum $[z_0, ..., z_W]$. If created in strict mode, $z_W = 0$.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RunningSum<F: FieldExt + PrimeFieldBits>(Vec<AssignedCell<F, F>>);
|
pub struct RunningSum<F: PrimeFieldBits>(Vec<AssignedCell<F, F>>);
|
||||||
impl<F: FieldExt + PrimeFieldBits> std::ops::Deref for RunningSum<F> {
|
impl<F: PrimeFieldBits> std::ops::Deref for RunningSum<F> {
|
||||||
type Target = Vec<AssignedCell<F, F>>;
|
type Target = Vec<AssignedCell<F, F>>;
|
||||||
|
|
||||||
fn deref(&self) -> &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.
|
/// Configuration that provides methods for running sum decomposition.
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
#[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,
|
q_range_check: Selector,
|
||||||
z: Column<Advice>,
|
z: Column<Advice>,
|
||||||
_marker: PhantomData<F>,
|
_marker: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: FieldExt + PrimeFieldBits, const WINDOW_NUM_BITS: usize>
|
impl<F: PrimeFieldBits, const WINDOW_NUM_BITS: usize> RunningSumConfig<F, WINDOW_NUM_BITS> {
|
||||||
RunningSumConfig<F, WINDOW_NUM_BITS>
|
|
||||||
{
|
|
||||||
/// Returns the q_range_check selector of this [`RunningSumConfig`].
|
/// Returns the q_range_check selector of this [`RunningSumConfig`].
|
||||||
pub(crate) fn q_range_check(&self) -> Selector {
|
pub(crate) fn q_range_check(&self) -> Selector {
|
||||||
self.q_range_check
|
self.q_range_check
|
||||||
|
@ -228,7 +226,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_running_sum() {
|
fn test_running_sum() {
|
||||||
struct MyCircuit<
|
struct MyCircuit<
|
||||||
F: FieldExt + PrimeFieldBits,
|
F: PrimeFieldBits,
|
||||||
const WORD_NUM_BITS: usize,
|
const WORD_NUM_BITS: usize,
|
||||||
const WINDOW_NUM_BITS: usize,
|
const WINDOW_NUM_BITS: usize,
|
||||||
const NUM_WINDOWS: usize,
|
const NUM_WINDOWS: usize,
|
||||||
|
@ -238,7 +236,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
F: FieldExt + PrimeFieldBits,
|
F: PrimeFieldBits,
|
||||||
const WORD_NUM_BITS: usize,
|
const WORD_NUM_BITS: usize,
|
||||||
const WINDOW_NUM_BITS: usize,
|
const WINDOW_NUM_BITS: usize,
|
||||||
const NUM_WINDOWS: 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$.
|
/// The running sum $[z_0, ..., z_W]$. If created in strict mode, $z_W = 0$.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RunningSum<F: FieldExt + PrimeFieldBits>(Vec<AssignedCell<F, F>>);
|
pub struct RunningSum<F: PrimeFieldBits>(Vec<AssignedCell<F, F>>);
|
||||||
impl<F: FieldExt + PrimeFieldBits> std::ops::Deref for RunningSum<F> {
|
impl<F: PrimeFieldBits> std::ops::Deref for RunningSum<F> {
|
||||||
type Target = Vec<AssignedCell<F, F>>;
|
type Target = Vec<AssignedCell<F, F>>;
|
||||||
|
|
||||||
fn deref(&self) -> &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
|
/// Witnesses a subset of the bits in `value` and constrains them to be the correct
|
||||||
/// number of bits.
|
/// 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.
|
/// Configuration that provides methods for a lookup range check.
|
||||||
#[derive(Eq, PartialEq, Debug, Clone, Copy)]
|
#[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_lookup: Selector,
|
||||||
q_running: Selector,
|
q_running: Selector,
|
||||||
q_bitshift: Selector,
|
q_bitshift: Selector,
|
||||||
|
@ -65,7 +65,7 @@ pub struct LookupRangeCheckConfig<F: FieldExt + PrimeFieldBits, const K: usize>
|
||||||
_marker: PhantomData<F>,
|
_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
|
/// The `running_sum` advice column breaks the field element into `K`-bit
|
||||||
/// words. It is used to construct the input expression to the lookup
|
/// words. It is used to construct the input expression to the lookup
|
||||||
/// argument.
|
/// argument.
|
||||||
|
@ -395,19 +395,19 @@ mod tests {
|
||||||
dev::{FailureLocation, MockProver, VerifyFailure},
|
dev::{FailureLocation, MockProver, VerifyFailure},
|
||||||
plonk::{Circuit, ConstraintSystem, Error},
|
plonk::{Circuit, ConstraintSystem, Error},
|
||||||
};
|
};
|
||||||
use pasta_curves::{arithmetic::FieldExt, pallas};
|
use pasta_curves::pallas;
|
||||||
|
|
||||||
use std::{convert::TryInto, marker::PhantomData};
|
use std::{convert::TryInto, marker::PhantomData};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lookup_range_check() {
|
fn lookup_range_check() {
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
struct MyCircuit<F: FieldExt + PrimeFieldBits> {
|
struct MyCircuit<F: PrimeFieldBits> {
|
||||||
num_words: usize,
|
num_words: usize,
|
||||||
_marker: PhantomData<F>,
|
_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 Config = LookupRangeCheckConfig<F, K>;
|
||||||
type FloorPlanner = SimpleFloorPlanner;
|
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
|
(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,
|
element: F,
|
||||||
num_words: usize,
|
num_words: usize,
|
||||||
) -> Vec<F> {
|
) -> Vec<F> {
|
||||||
|
@ -498,12 +498,12 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn short_range_check() {
|
fn short_range_check() {
|
||||||
struct MyCircuit<F: FieldExt + PrimeFieldBits> {
|
struct MyCircuit<F: PrimeFieldBits> {
|
||||||
element: Value<F>,
|
element: Value<F>,
|
||||||
num_bits: usize,
|
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 Config = LookupRangeCheckConfig<F, K>;
|
||||||
type FloorPlanner = SimpleFloorPlanner;
|
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
|
- `RegionLayouter::instance_value` method added to provide access to
|
||||||
instance values within a region.
|
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
|
## [0.2.0] - 2022-06-23
|
||||||
### Added
|
### Added
|
||||||
- `halo2_proofs::circuit::Value`, a more usable and type-safe replacement for
|
- `halo2_proofs::circuit::Value`, a more usable and type-safe replacement for
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate criterion;
|
extern crate criterion;
|
||||||
|
|
||||||
use halo2_proofs::arithmetic::FieldExt;
|
use group::ff::PrimeField;
|
||||||
use halo2_proofs::circuit::{Layouter, SimpleFloorPlanner, Value};
|
use halo2_proofs::circuit::{Layouter, SimpleFloorPlanner, Value};
|
||||||
use halo2_proofs::dev::MockProver;
|
use halo2_proofs::dev::MockProver;
|
||||||
use halo2_proofs::plonk::*;
|
use halo2_proofs::plonk::*;
|
||||||
|
@ -14,7 +14,7 @@ use criterion::{BenchmarkId, Criterion};
|
||||||
|
|
||||||
fn criterion_benchmark(c: &mut Criterion) {
|
fn criterion_benchmark(c: &mut Criterion) {
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
struct MyCircuit<F: FieldExt> {
|
struct MyCircuit<F: PrimeField> {
|
||||||
_marker: PhantomData<F>,
|
_marker: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|
||||||
advice: Column<Advice>,
|
advice: Column<Advice>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
|
impl<F: PrimeField> Circuit<F> for MyCircuit<F> {
|
||||||
type Config = MyConfig;
|
type Config = MyConfig;
|
||||||
type FloorPlanner = SimpleFloorPlanner;
|
type FloorPlanner = SimpleFloorPlanner;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
extern crate criterion;
|
extern crate criterion;
|
||||||
|
|
||||||
use group::ff::Field;
|
use group::ff::Field;
|
||||||
use halo2_proofs::arithmetic::FieldExt;
|
|
||||||
use halo2_proofs::circuit::{Cell, Layouter, SimpleFloorPlanner, Value};
|
use halo2_proofs::circuit::{Cell, Layouter, SimpleFloorPlanner, Value};
|
||||||
use halo2_proofs::pasta::{EqAffine, Fp};
|
use halo2_proofs::pasta::{EqAffine, Fp};
|
||||||
use halo2_proofs::plonk::*;
|
use halo2_proofs::plonk::*;
|
||||||
|
@ -31,7 +30,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|
||||||
sm: Column<Fixed>,
|
sm: Column<Fixed>,
|
||||||
}
|
}
|
||||||
|
|
||||||
trait StandardCs<FF: FieldExt> {
|
trait StandardCs<FF: Field> {
|
||||||
fn raw_multiply<F>(
|
fn raw_multiply<F>(
|
||||||
&self,
|
&self,
|
||||||
layouter: &mut impl Layouter<FF>,
|
layouter: &mut impl Layouter<FF>,
|
||||||
|
@ -50,17 +49,17 @@ fn criterion_benchmark(c: &mut Criterion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct MyCircuit<F: FieldExt> {
|
struct MyCircuit<F: Field> {
|
||||||
a: Value<F>,
|
a: Value<F>,
|
||||||
k: u32,
|
k: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StandardPlonk<F: FieldExt> {
|
struct StandardPlonk<F: Field> {
|
||||||
config: PlonkConfig,
|
config: PlonkConfig,
|
||||||
_marker: PhantomData<F>,
|
_marker: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<FF: FieldExt> StandardPlonk<FF> {
|
impl<FF: Field> StandardPlonk<FF> {
|
||||||
fn new(config: PlonkConfig) -> Self {
|
fn new(config: PlonkConfig) -> Self {
|
||||||
StandardPlonk {
|
StandardPlonk {
|
||||||
config,
|
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>(
|
fn raw_multiply<F>(
|
||||||
&self,
|
&self,
|
||||||
layouter: &mut impl Layouter<FF>,
|
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 Config = PlonkConfig;
|
||||||
type FloorPlanner = SimpleFloorPlanner;
|
type FloorPlanner = SimpleFloorPlanner;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use ff::Field;
|
use ff::Field;
|
||||||
use halo2_proofs::{
|
use halo2_proofs::{
|
||||||
arithmetic::FieldExt,
|
|
||||||
circuit::{Cell, Layouter, Region, SimpleFloorPlanner, Value},
|
circuit::{Cell, Layouter, Region, SimpleFloorPlanner, Value},
|
||||||
pasta::Fp,
|
pasta::Fp,
|
||||||
plonk::{Advice, Assigned, Circuit, Column, ConstraintSystem, Error, Fixed, TableColumn},
|
plonk::{Advice, Assigned, Circuit, Column, ConstraintSystem, Error, Fixed, TableColumn},
|
||||||
|
@ -28,7 +27,7 @@ struct PlonkConfig {
|
||||||
sl: TableColumn,
|
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>
|
fn raw_multiply<F>(&self, region: &mut Region<FF>, f: F) -> Result<(Cell, Cell, Cell), Error>
|
||||||
where
|
where
|
||||||
F: FnMut() -> Value<(Assigned<FF>, Assigned<FF>, Assigned<FF>)>;
|
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>;
|
fn lookup_table(&self, layouter: &mut impl Layouter<FF>, values: &[FF]) -> Result<(), Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MyCircuit<F: FieldExt> {
|
struct MyCircuit<F: Field> {
|
||||||
a: Value<F>,
|
a: Value<F>,
|
||||||
lookup_table: Vec<F>,
|
lookup_table: Vec<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StandardPlonk<F: FieldExt> {
|
struct StandardPlonk<F: Field> {
|
||||||
config: PlonkConfig,
|
config: PlonkConfig,
|
||||||
_marker: PhantomData<F>,
|
_marker: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<FF: FieldExt> StandardPlonk<FF> {
|
impl<FF: Field> StandardPlonk<FF> {
|
||||||
fn new(config: PlonkConfig) -> Self {
|
fn new(config: PlonkConfig) -> Self {
|
||||||
StandardPlonk {
|
StandardPlonk {
|
||||||
config,
|
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>(
|
fn raw_multiply<F>(
|
||||||
&self,
|
&self,
|
||||||
region: &mut Region<FF>,
|
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 Config = PlonkConfig;
|
||||||
type FloorPlanner = SimpleFloorPlanner;
|
type FloorPlanner = SimpleFloorPlanner;
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
|
use group::ff::Field;
|
||||||
use halo2_proofs::{
|
use halo2_proofs::{
|
||||||
arithmetic::FieldExt,
|
|
||||||
circuit::{AssignedCell, Chip, Layouter, Region, SimpleFloorPlanner, Value},
|
circuit::{AssignedCell, Chip, Layouter, Region, SimpleFloorPlanner, Value},
|
||||||
plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Fixed, Instance, Selector},
|
plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Fixed, Instance, Selector},
|
||||||
poly::Rotation,
|
poly::Rotation,
|
||||||
};
|
};
|
||||||
|
|
||||||
// ANCHOR: instructions
|
// ANCHOR: instructions
|
||||||
trait NumericInstructions<F: FieldExt>: Chip<F> {
|
trait NumericInstructions<F: Field>: Chip<F> {
|
||||||
/// Variable representing a number.
|
/// Variable representing a number.
|
||||||
type Num;
|
type Num;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ trait NumericInstructions<F: FieldExt>: Chip<F> {
|
||||||
// ANCHOR: chip
|
// ANCHOR: chip
|
||||||
/// The chip that will implement our instructions! Chips store their own
|
/// The chip that will implement our instructions! Chips store their own
|
||||||
/// config, as well as type markers if necessary.
|
/// config, as well as type markers if necessary.
|
||||||
struct FieldChip<F: FieldExt> {
|
struct FieldChip<F: Field> {
|
||||||
config: FieldConfig,
|
config: FieldConfig,
|
||||||
_marker: PhantomData<F>,
|
_marker: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ struct FieldConfig {
|
||||||
s_mul: Selector,
|
s_mul: Selector,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: FieldExt> FieldChip<F> {
|
impl<F: Field> FieldChip<F> {
|
||||||
fn construct(config: <Self as Chip<F>>::Config) -> Self {
|
fn construct(config: <Self as Chip<F>>::Config) -> Self {
|
||||||
Self {
|
Self {
|
||||||
config,
|
config,
|
||||||
|
@ -126,7 +126,7 @@ impl<F: FieldExt> FieldChip<F> {
|
||||||
// ANCHOR_END: chip-config
|
// ANCHOR_END: chip-config
|
||||||
|
|
||||||
// ANCHOR: chip-impl
|
// ANCHOR: chip-impl
|
||||||
impl<F: FieldExt> Chip<F> for FieldChip<F> {
|
impl<F: Field> Chip<F> for FieldChip<F> {
|
||||||
type Config = FieldConfig;
|
type Config = FieldConfig;
|
||||||
type Loaded = ();
|
type Loaded = ();
|
||||||
|
|
||||||
|
@ -143,9 +143,9 @@ impl<F: FieldExt> Chip<F> for FieldChip<F> {
|
||||||
// ANCHOR: instructions-impl
|
// ANCHOR: instructions-impl
|
||||||
/// A variable representing a number.
|
/// A variable representing a number.
|
||||||
#[derive(Clone)]
|
#[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>;
|
type Num = Number<F>;
|
||||||
|
|
||||||
fn load_private(
|
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
|
/// they won't have any value during key generation. During proving, if any of these
|
||||||
/// were `None` we would get an error.
|
/// were `None` we would get an error.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct MyCircuit<F: FieldExt> {
|
struct MyCircuit<F: Field> {
|
||||||
constant: F,
|
constant: F,
|
||||||
a: Value<F>,
|
a: Value<F>,
|
||||||
b: 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.
|
// Since we are using a single chip for everything, we can just reuse its config.
|
||||||
type Config = FieldConfig;
|
type Config = FieldConfig;
|
||||||
type FloorPlanner = SimpleFloorPlanner;
|
type FloorPlanner = SimpleFloorPlanner;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
|
use group::ff::Field;
|
||||||
use halo2_proofs::{
|
use halo2_proofs::{
|
||||||
arithmetic::FieldExt,
|
|
||||||
circuit::{AssignedCell, Chip, Layouter, Region, SimpleFloorPlanner, Value},
|
circuit::{AssignedCell, Chip, Layouter, Region, SimpleFloorPlanner, Value},
|
||||||
plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Instance, Selector},
|
plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Instance, Selector},
|
||||||
poly::Rotation,
|
poly::Rotation,
|
||||||
|
@ -10,9 +10,9 @@ use halo2_proofs::{
|
||||||
// ANCHOR: field-instructions
|
// ANCHOR: field-instructions
|
||||||
/// A variable representing a number.
|
/// A variable representing a number.
|
||||||
#[derive(Clone)]
|
#[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.
|
/// Variable representing a number.
|
||||||
type Num;
|
type Num;
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ trait FieldInstructions<F: FieldExt>: AddInstructions<F> + MulInstructions<F> {
|
||||||
// ANCHOR_END: field-instructions
|
// ANCHOR_END: field-instructions
|
||||||
|
|
||||||
// ANCHOR: add-instructions
|
// ANCHOR: add-instructions
|
||||||
trait AddInstructions<F: FieldExt>: Chip<F> {
|
trait AddInstructions<F: Field>: Chip<F> {
|
||||||
/// Variable representing a number.
|
/// Variable representing a number.
|
||||||
type Num;
|
type Num;
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ trait AddInstructions<F: FieldExt>: Chip<F> {
|
||||||
// ANCHOR_END: add-instructions
|
// ANCHOR_END: add-instructions
|
||||||
|
|
||||||
// ANCHOR: mul-instructions
|
// ANCHOR: mul-instructions
|
||||||
trait MulInstructions<F: FieldExt>: Chip<F> {
|
trait MulInstructions<F: Field>: Chip<F> {
|
||||||
/// Variable representing a number.
|
/// Variable representing a number.
|
||||||
type Num;
|
type Num;
|
||||||
|
|
||||||
|
@ -108,28 +108,28 @@ struct MulConfig {
|
||||||
|
|
||||||
// ANCHOR: field-chip
|
// ANCHOR: field-chip
|
||||||
/// The top-level chip that will implement the `FieldInstructions`.
|
/// The top-level chip that will implement the `FieldInstructions`.
|
||||||
struct FieldChip<F: FieldExt> {
|
struct FieldChip<F: Field> {
|
||||||
config: FieldConfig,
|
config: FieldConfig,
|
||||||
_marker: PhantomData<F>,
|
_marker: PhantomData<F>,
|
||||||
}
|
}
|
||||||
// ANCHOR_END: field-chip
|
// ANCHOR_END: field-chip
|
||||||
|
|
||||||
// ANCHOR: add-chip
|
// ANCHOR: add-chip
|
||||||
struct AddChip<F: FieldExt> {
|
struct AddChip<F: Field> {
|
||||||
config: AddConfig,
|
config: AddConfig,
|
||||||
_marker: PhantomData<F>,
|
_marker: PhantomData<F>,
|
||||||
}
|
}
|
||||||
// ANCHOR END: add-chip
|
// ANCHOR END: add-chip
|
||||||
|
|
||||||
// ANCHOR: mul-chip
|
// ANCHOR: mul-chip
|
||||||
struct MulChip<F: FieldExt> {
|
struct MulChip<F: Field> {
|
||||||
config: MulConfig,
|
config: MulConfig,
|
||||||
_marker: PhantomData<F>,
|
_marker: PhantomData<F>,
|
||||||
}
|
}
|
||||||
// ANCHOR_END: mul-chip
|
// ANCHOR_END: mul-chip
|
||||||
|
|
||||||
// ANCHOR: add-chip-trait-impl
|
// 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 Config = AddConfig;
|
||||||
type Loaded = ();
|
type Loaded = ();
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ impl<F: FieldExt> Chip<F> for AddChip<F> {
|
||||||
// ANCHOR END: add-chip-trait-impl
|
// ANCHOR END: add-chip-trait-impl
|
||||||
|
|
||||||
// ANCHOR: add-chip-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 {
|
fn construct(config: <Self as Chip<F>>::Config, _loaded: <Self as Chip<F>>::Loaded) -> Self {
|
||||||
Self {
|
Self {
|
||||||
config,
|
config,
|
||||||
|
@ -174,7 +174,7 @@ impl<F: FieldExt> AddChip<F> {
|
||||||
// ANCHOR END: add-chip-impl
|
// ANCHOR END: add-chip-impl
|
||||||
|
|
||||||
// ANCHOR: add-instructions-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>;
|
type Num = Number<F>;
|
||||||
fn add(
|
fn add(
|
||||||
&self,
|
&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>;
|
type Num = Number<F>;
|
||||||
|
|
||||||
fn add(
|
fn add(
|
||||||
|
@ -231,7 +231,7 @@ impl<F: FieldExt> AddInstructions<F> for AddChip<F> {
|
||||||
// ANCHOR END: add-instructions-impl
|
// ANCHOR END: add-instructions-impl
|
||||||
|
|
||||||
// ANCHOR: mul-chip-trait-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 Config = MulConfig;
|
||||||
type Loaded = ();
|
type Loaded = ();
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ impl<F: FieldExt> Chip<F> for MulChip<F> {
|
||||||
// ANCHOR END: mul-chip-trait-impl
|
// ANCHOR END: mul-chip-trait-impl
|
||||||
|
|
||||||
// ANCHOR: mul-chip-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 {
|
fn construct(config: <Self as Chip<F>>::Config, _loaded: <Self as Chip<F>>::Loaded) -> Self {
|
||||||
Self {
|
Self {
|
||||||
config,
|
config,
|
||||||
|
@ -296,7 +296,7 @@ impl<F: FieldExt> MulChip<F> {
|
||||||
// ANCHOR_END: mul-chip-impl
|
// ANCHOR_END: mul-chip-impl
|
||||||
|
|
||||||
// ANCHOR: mul-instructions-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>;
|
type Num = Number<F>;
|
||||||
fn mul(
|
fn mul(
|
||||||
&self,
|
&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>;
|
type Num = Number<F>;
|
||||||
|
|
||||||
fn mul(
|
fn mul(
|
||||||
|
@ -352,7 +352,7 @@ impl<F: FieldExt> MulInstructions<F> for MulChip<F> {
|
||||||
// ANCHOR END: mul-instructions-impl
|
// ANCHOR END: mul-instructions-impl
|
||||||
|
|
||||||
// ANCHOR: field-chip-trait-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 Config = FieldConfig;
|
||||||
type Loaded = ();
|
type Loaded = ();
|
||||||
|
|
||||||
|
@ -367,7 +367,7 @@ impl<F: FieldExt> Chip<F> for FieldChip<F> {
|
||||||
// ANCHOR_END: field-chip-trait-impl
|
// ANCHOR_END: field-chip-trait-impl
|
||||||
|
|
||||||
// ANCHOR: field-chip-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 {
|
fn construct(config: <Self as Chip<F>>::Config, _loaded: <Self as Chip<F>>::Loaded) -> Self {
|
||||||
Self {
|
Self {
|
||||||
config,
|
config,
|
||||||
|
@ -396,7 +396,7 @@ impl<F: FieldExt> FieldChip<F> {
|
||||||
// ANCHOR_END: field-chip-impl
|
// ANCHOR_END: field-chip-impl
|
||||||
|
|
||||||
// ANCHOR: field-instructions-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>;
|
type Num = Number<F>;
|
||||||
|
|
||||||
fn load_private(
|
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
|
/// they won't have any value during key generation. During proving, if any of these
|
||||||
/// were `Value::unknown()` we would get an error.
|
/// were `Value::unknown()` we would get an error.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct MyCircuit<F: FieldExt> {
|
struct MyCircuit<F: Field> {
|
||||||
a: Value<F>,
|
a: Value<F>,
|
||||||
b: Value<F>,
|
b: Value<F>,
|
||||||
c: 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.
|
// Since we are using a single chip for everything, we can just reuse its config.
|
||||||
type Config = FieldConfig;
|
type Config = FieldConfig;
|
||||||
type FloorPlanner = SimpleFloorPlanner;
|
type FloorPlanner = SimpleFloorPlanner;
|
||||||
|
@ -496,7 +496,6 @@ impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
|
||||||
|
|
||||||
#[allow(clippy::many_single_char_names)]
|
#[allow(clippy::many_single_char_names)]
|
||||||
fn main() {
|
fn main() {
|
||||||
use group::ff::Field;
|
|
||||||
use halo2_proofs::{dev::MockProver, pasta::Fp};
|
use halo2_proofs::{dev::MockProver, pasta::Fp};
|
||||||
use rand_core::OsRng;
|
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
|
/// 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`
|
/// and their evaluations. This function will panic if two values in `points`
|
||||||
/// are the same.
|
/// 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());
|
assert_eq!(points.len(), evals.len());
|
||||||
if points.len() == 1 {
|
if points.len() == 1 {
|
||||||
// Constant polynomial
|
// Constant polynomial
|
||||||
|
|
|
@ -4,10 +4,7 @@ use std::{fmt, marker::PhantomData};
|
||||||
|
|
||||||
use ff::Field;
|
use ff::Field;
|
||||||
|
|
||||||
use crate::{
|
use crate::plonk::{Advice, Any, Assigned, Column, Error, Fixed, Instance, Selector, TableColumn};
|
||||||
arithmetic::FieldExt,
|
|
||||||
plonk::{Advice, Any, Assigned, Column, Error, Fixed, Instance, Selector, TableColumn},
|
|
||||||
};
|
|
||||||
|
|
||||||
mod value;
|
mod value;
|
||||||
pub use value::Value;
|
pub use value::Value;
|
||||||
|
@ -25,7 +22,7 @@ pub mod layouter;
|
||||||
/// The chip also loads any fixed configuration needed at synthesis time
|
/// The chip also loads any fixed configuration needed at synthesis time
|
||||||
/// using its own implementation of `load`, and stores it in [`Chip::Loaded`].
|
/// using its own implementation of `load`, and stores it in [`Chip::Loaded`].
|
||||||
/// This can be accessed via [`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
|
/// 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`].
|
/// during circuit synthesis, that can be derived during [`Circuit::configure`].
|
||||||
///
|
///
|
||||||
|
|
|
@ -9,7 +9,7 @@ use ff::Field;
|
||||||
|
|
||||||
use crate::plonk::Assigned;
|
use crate::plonk::Assigned;
|
||||||
use crate::{
|
use crate::{
|
||||||
arithmetic::{FieldExt, Group},
|
arithmetic::FieldExt,
|
||||||
circuit,
|
circuit,
|
||||||
plonk::{
|
plonk::{
|
||||||
permutation, Advice, Any, Assignment, Circuit, Column, ConstraintSystem, Error, Expression,
|
permutation, Advice, Any, Assignment, Circuit, Column, ConstraintSystem, Error, Expression,
|
||||||
|
@ -72,7 +72,7 @@ impl Region {
|
||||||
|
|
||||||
/// The value of a particular cell within the circuit.
|
/// The value of a particular cell within the circuit.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
enum CellValue<F: Group + Field> {
|
enum CellValue<F: Field> {
|
||||||
// An unassigned cell.
|
// An unassigned cell.
|
||||||
Unassigned,
|
Unassigned,
|
||||||
// A cell that has been assigned a value.
|
// A cell that has been assigned a value.
|
||||||
|
@ -83,12 +83,12 @@ enum CellValue<F: Group + Field> {
|
||||||
|
|
||||||
/// A value within an expression.
|
/// A value within an expression.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Ord, PartialOrd)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Ord, PartialOrd)]
|
||||||
enum Value<F: Group + Field> {
|
enum Value<F: Field> {
|
||||||
Real(F),
|
Real(F),
|
||||||
Poison,
|
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 {
|
fn from(value: CellValue<F>) -> Self {
|
||||||
match value {
|
match value {
|
||||||
// Cells that haven't been explicitly assigned to, default to zero.
|
// 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;
|
type Output = Self;
|
||||||
|
|
||||||
fn neg(self) -> Self::Output {
|
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;
|
type Output = Self;
|
||||||
|
|
||||||
fn add(self, rhs: Self) -> Self::Output {
|
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;
|
type Output = Self;
|
||||||
|
|
||||||
fn mul(self, rhs: Self) -> Self::Output {
|
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;
|
type Output = Self;
|
||||||
|
|
||||||
fn mul(self, rhs: F) -> Self::Output {
|
fn mul(self, rhs: F) -> Self::Output {
|
||||||
|
@ -267,7 +267,7 @@ impl<F: Group + Field> Mul<F> for Value<F> {
|
||||||
/// ));
|
/// ));
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MockProver<F: Group + Field> {
|
pub struct MockProver<F: Field> {
|
||||||
k: u32,
|
k: u32,
|
||||||
n: u32,
|
n: u32,
|
||||||
cs: ConstraintSystem<F>,
|
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)
|
fn enter_region<NR, N>(&mut self, name: N)
|
||||||
where
|
where
|
||||||
NR: Into<String>,
|
NR: Into<String>,
|
||||||
|
|
|
@ -2,7 +2,6 @@ use std::collections::{BTreeMap, HashSet};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use group::ff::Field;
|
use group::ff::Field;
|
||||||
use pasta_curves::arithmetic::FieldExt;
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
metadata,
|
metadata,
|
||||||
|
@ -396,7 +395,7 @@ fn render_constraint_not_satisfied<F: Field>(
|
||||||
/// | x0 = 0x5
|
/// | x0 = 0x5
|
||||||
/// | x1 = 1
|
/// | x1 = 1
|
||||||
/// ```
|
/// ```
|
||||||
fn render_lookup<F: FieldExt>(
|
fn render_lookup<F: Field>(
|
||||||
prover: &MockProver<F>,
|
prover: &MockProver<F>,
|
||||||
lookup_index: usize,
|
lookup_index: usize,
|
||||||
location: &FailureLocation,
|
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,
|
column_type: Any,
|
||||||
load: impl Fn(Q) -> Value<F> + 'a,
|
load: impl Fn(Q) -> Value<F> + 'a,
|
||||||
) -> impl Fn(Q) -> BTreeMap<metadata::VirtualCell, String> + 'a {
|
) -> impl Fn(Q) -> BTreeMap<metadata::VirtualCell, String> + 'a {
|
||||||
|
@ -535,7 +534,7 @@ fn render_lookup<F: FieldExt>(
|
||||||
|
|
||||||
impl VerifyFailure {
|
impl VerifyFailure {
|
||||||
/// Emits this failure in pretty-printed format to stderr.
|
/// 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 {
|
match self {
|
||||||
Self::CellNotAssigned {
|
Self::CellNotAssigned {
|
||||||
gate,
|
gate,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use group::ff::Field;
|
use group::ff::Field;
|
||||||
use pasta_curves::arithmetic::FieldExt;
|
|
||||||
|
|
||||||
use super::{metadata, CellValue, InstanceValue, Value};
|
use super::{metadata, CellValue, InstanceValue, Value};
|
||||||
use crate::{
|
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,
|
n: i32,
|
||||||
row: i32,
|
row: i32,
|
||||||
queries: &'a [(Column<T>, Rotation)],
|
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,
|
n: i32,
|
||||||
row: i32,
|
row: i32,
|
||||||
queries: &'a [(Column<T>, Rotation)],
|
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],
|
virtual_cells: &'a [VirtualCell],
|
||||||
load: impl Fn(Q) -> Value<F> + 'a,
|
load: impl Fn(Q) -> Value<F> + 'a,
|
||||||
) -> impl Fn(Q) -> BTreeMap<metadata::VirtualCell, String> + '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>,
|
gate: &Gate<F>,
|
||||||
poly: &Expression<F>,
|
poly: &Expression<F>,
|
||||||
load_fixed: impl Fn(FixedQuery) -> Value<F> + 'a,
|
load_fixed: impl Fn(FixedQuery) -> Value<F> + 'a,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use super::super::{
|
||||||
};
|
};
|
||||||
use super::Argument;
|
use super::Argument;
|
||||||
use crate::{
|
use crate::{
|
||||||
arithmetic::{CurveAffine, FieldExt},
|
arithmetic::CurveAffine,
|
||||||
plonk::{Error, VerifyingKey},
|
plonk::{Error, VerifyingKey},
|
||||||
poly::{multiopen::VerifierQuery, Rotation},
|
poly::{multiopen::VerifierQuery, Rotation},
|
||||||
transcript::{EncodedChallenge, TranscriptRead},
|
transcript::{EncodedChallenge, TranscriptRead},
|
||||||
|
@ -31,7 +31,7 @@ pub struct Evaluated<C: CurveAffine> {
|
||||||
permuted_table_eval: C::Scalar,
|
permuted_table_eval: C::Scalar,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: FieldExt> Argument<F> {
|
impl<F: Field> Argument<F> {
|
||||||
pub(in crate::plonk) fn read_permuted_commitments<
|
pub(in crate::plonk) fn read_permuted_commitments<
|
||||||
C: CurveAffine,
|
C: CurveAffine,
|
||||||
E: EncodedChallenge<C>,
|
E: EncodedChallenge<C>,
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::arithmetic::parallelize;
|
||||||
use crate::plonk::Assigned;
|
use crate::plonk::Assigned;
|
||||||
|
|
||||||
use group::ff::{BatchInvert, Field};
|
use group::ff::{BatchInvert, Field};
|
||||||
use pasta_curves::arithmetic::FieldExt;
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::{Add, Deref, DerefMut, Index, IndexMut, Mul, RangeFrom, RangeFull};
|
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>>,
|
assigned: Vec<Polynomial<Assigned<F>, LagrangeCoeff>>,
|
||||||
) -> Vec<Polynomial<F, LagrangeCoeff>> {
|
) -> Vec<Polynomial<F, LagrangeCoeff>> {
|
||||||
let mut assigned_denominators: Vec<_> = assigned
|
let mut assigned_denominators: Vec<_> = assigned
|
||||||
|
|
|
@ -206,13 +206,13 @@ impl<C: CurveAffine> Params<C> {
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||||
pub struct Blind<F>(pub F);
|
pub struct Blind<F>(pub F);
|
||||||
|
|
||||||
impl<F: FieldExt> Default for Blind<F> {
|
impl<F: Field> Default for Blind<F> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Blind(F::one())
|
Blind(F::one())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: FieldExt> Add for Blind<F> {
|
impl<F: Field> Add for Blind<F> {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
fn add(self, rhs: Blind<F>) -> 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;
|
type Output = Self;
|
||||||
|
|
||||||
fn mul(self, rhs: Blind<F>) -> 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>) {
|
fn add_assign(&mut self, rhs: Blind<F>) {
|
||||||
self.0 += rhs.0;
|
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>) {
|
fn mul_assign(&mut self, rhs: Blind<F>) {
|
||||||
self.0 *= rhs.0;
|
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) {
|
fn add_assign(&mut self, rhs: F) {
|
||||||
self.0 += rhs;
|
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) {
|
fn mul_assign(&mut self, rhs: F) {
|
||||||
self.0 *= rhs;
|
self.0 *= rhs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ use std::marker::PhantomData;
|
||||||
/// performing operations on an evaluation domain of size $2^k$ and an extended
|
/// performing operations on an evaluation domain of size $2^k$ and an extended
|
||||||
/// domain of size $2^{k} * j$ with $j \neq 0$.
|
/// domain of size $2^{k} * j$ with $j \neq 0$.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct EvaluationDomain<F: FieldExt> {
|
pub struct EvaluationDomain<F: Field> {
|
||||||
n: u64,
|
n: u64,
|
||||||
k: u32,
|
k: u32,
|
||||||
extended_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 poly_len = self.polys.first().unwrap().len();
|
||||||
let (chunk_size, _num_chunks) = get_chunk_params(poly_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>,
|
domain: &'a EvaluationDomain<F>,
|
||||||
poly_len: usize,
|
poly_len: usize,
|
||||||
chunk_size: 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.
|
/// Operations which can be performed over a given basis.
|
||||||
pub(crate) trait BasisOps: Basis {
|
pub(crate) trait BasisOps: Basis {
|
||||||
fn empty_poly<F: FieldExt>(domain: &EvaluationDomain<F>) -> Polynomial<F, Self>;
|
fn empty_poly<F: FieldExt>(domain: &EvaluationDomain<F>) -> Polynomial<F, Self>;
|
||||||
fn constant_term<F: FieldExt>(
|
fn constant_term<F: Field>(
|
||||||
poly_len: usize,
|
poly_len: usize,
|
||||||
chunk_size: usize,
|
chunk_size: usize,
|
||||||
chunk_index: usize,
|
chunk_index: usize,
|
||||||
|
@ -469,7 +469,7 @@ impl BasisOps for Coeff {
|
||||||
domain.empty_coeff()
|
domain.empty_coeff()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn constant_term<F: FieldExt>(
|
fn constant_term<F: Field>(
|
||||||
poly_len: usize,
|
poly_len: usize,
|
||||||
chunk_size: usize,
|
chunk_size: usize,
|
||||||
chunk_index: usize,
|
chunk_index: usize,
|
||||||
|
@ -520,7 +520,7 @@ impl BasisOps for LagrangeCoeff {
|
||||||
domain.empty_lagrange()
|
domain.empty_lagrange()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn constant_term<F: FieldExt>(
|
fn constant_term<F: Field>(
|
||||||
poly_len: usize,
|
poly_len: usize,
|
||||||
chunk_size: usize,
|
chunk_size: usize,
|
||||||
chunk_index: usize,
|
chunk_index: usize,
|
||||||
|
@ -564,7 +564,7 @@ impl BasisOps for ExtendedLagrangeCoeff {
|
||||||
domain.empty_extended()
|
domain.empty_extended()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn constant_term<F: FieldExt>(
|
fn constant_term<F: Field>(
|
||||||
poly_len: usize,
|
poly_len: usize,
|
||||||
chunk_size: usize,
|
chunk_size: usize,
|
||||||
chunk_index: usize,
|
chunk_index: usize,
|
||||||
|
|
|
@ -6,10 +6,7 @@
|
||||||
use std::collections::{BTreeMap, BTreeSet};
|
use std::collections::{BTreeMap, BTreeSet};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{arithmetic::CurveAffine, transcript::ChallengeScalar};
|
||||||
arithmetic::{CurveAffine, FieldExt},
|
|
||||||
transcript::ChallengeScalar,
|
|
||||||
};
|
|
||||||
|
|
||||||
mod prover;
|
mod prover;
|
||||||
mod verifier;
|
mod verifier;
|
||||||
|
@ -136,7 +133,7 @@ type IntermediateSets<F, Q> = (
|
||||||
Vec<Vec<F>>,
|
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
|
where
|
||||||
I: IntoIterator<Item = Q> + Clone,
|
I: IntoIterator<Item = Q> + Clone,
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#![allow(clippy::op_ref)]
|
#![allow(clippy::op_ref)]
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
|
use group::ff::Field;
|
||||||
use halo2_proofs::arithmetic::{CurveAffine, FieldExt};
|
use halo2_proofs::arithmetic::{CurveAffine, FieldExt};
|
||||||
use halo2_proofs::circuit::{Cell, Layouter, SimpleFloorPlanner, Value};
|
use halo2_proofs::circuit::{Cell, Layouter, SimpleFloorPlanner, Value};
|
||||||
use halo2_proofs::dev::MockProver;
|
use halo2_proofs::dev::MockProver;
|
||||||
|
@ -44,7 +45,7 @@ fn plonk_api() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
trait StandardCs<FF: FieldExt> {
|
trait StandardCs<FF: Field> {
|
||||||
fn raw_multiply<F>(
|
fn raw_multiply<F>(
|
||||||
&self,
|
&self,
|
||||||
layouter: &mut impl Layouter<FF>,
|
layouter: &mut impl Layouter<FF>,
|
||||||
|
@ -71,17 +72,17 @@ fn plonk_api() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct MyCircuit<F: FieldExt> {
|
struct MyCircuit<F: Field> {
|
||||||
a: Value<F>,
|
a: Value<F>,
|
||||||
lookup_table: Vec<F>,
|
lookup_table: Vec<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StandardPlonk<F: FieldExt> {
|
struct StandardPlonk<F: Field> {
|
||||||
config: PlonkConfig,
|
config: PlonkConfig,
|
||||||
_marker: PhantomData<F>,
|
_marker: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<FF: FieldExt> StandardPlonk<FF> {
|
impl<FF: Field> StandardPlonk<FF> {
|
||||||
fn new(config: PlonkConfig) -> Self {
|
fn new(config: PlonkConfig) -> Self {
|
||||||
StandardPlonk {
|
StandardPlonk {
|
||||||
config,
|
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>(
|
fn raw_multiply<F>(
|
||||||
&self,
|
&self,
|
||||||
layouter: &mut impl Layouter<FF>,
|
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 Config = PlonkConfig;
|
||||||
type FloorPlanner = SimpleFloorPlanner;
|
type FloorPlanner = SimpleFloorPlanner;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue