Skip to content

Commit

Permalink
[nits] remove PrimeField bound when there is FromUnifromBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenfeizhang committed Mar 14, 2023
1 parent eacc57a commit 6a4f13e
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 68 deletions.
6 changes: 3 additions & 3 deletions src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl AccountGadget {
/// + circuit selector * 1
/// + exported col * 8 (MUST by following sequence: layout_flag, s_enable, old_val, new_val, key_val and 3 ext field for old/new/key_val)
/// + free col * 4
pub fn configure<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn configure<Fp: FromUniformBytes<64> + Ord>(
meta: &mut ConstraintSystem<Fp>,
sel: Selector,
exported: &[Column<Advice>],
Expand Down Expand Up @@ -386,7 +386,7 @@ struct AccountChip<'d, F> {
data: &'d Account<F>,
}

impl<Fp: PrimeField + FromUniformBytes<64> + Ord> Chip<Fp> for AccountChip<'_, Fp> {
impl<Fp: FromUniformBytes<64> + Ord> Chip<Fp> for AccountChip<'_, Fp> {
type Config = AccountChipConfig;
type Loaded = Account<Fp>;

Expand All @@ -399,7 +399,7 @@ impl<Fp: PrimeField + FromUniformBytes<64> + Ord> Chip<Fp> for AccountChip<'_, F
}
}

impl<'d, Fp: PrimeField + FromUniformBytes<64> + Ord> AccountChip<'d, Fp> {
impl<'d, Fp: FromUniformBytes<64> + Ord> AccountChip<'d, Fp> {
fn lagrange_polynomial_for_row<const T: usize>(ref_n: Expression<Fp>) -> Expression<Fp> {
super::lagrange_polynomial::<Fp, T, LAST_ROW>(ref_n)
}
Expand Down
18 changes: 9 additions & 9 deletions src/layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use halo2_proofs::{
circuit::{Layouter, Region, Value},
ff::{FromUniformBytes, PrimeField},
ff::FromUniformBytes,
plonk::{Advice, Column, ConstraintSystem, Error, Expression, Selector, TableColumn},
poly::Rotation,
};
Expand Down Expand Up @@ -104,7 +104,7 @@ impl LayerGadget {
self.sel
}

pub fn configure<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn configure<Fp: FromUniformBytes<64> + Ord>(
meta: &mut ConstraintSystem<Fp>,
steps: usize,
required_cols: usize,
Expand Down Expand Up @@ -319,7 +319,7 @@ impl LayerGadget {
}

// LayerGadget must be first assigned, with other gadgets start from the offset it has returned
pub fn assign<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn assign<Fp: FromUniformBytes<64> + Ord>(
&self,
region: &mut Region<'_, Fp>,
max_rows: usize,
Expand Down Expand Up @@ -394,7 +394,7 @@ impl LayerGadget {
// pace has to be called before a working gadget is assigned on the specified offset, the rows
// that working gadget would occpuy, and the result of the new root which gadget has output,
// must be known before
pub fn pace_op<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn pace_op<Fp: FromUniformBytes<64> + Ord>(
&self,
region: &mut Region<'_, Fp>,
offset: usize,
Expand Down Expand Up @@ -472,7 +472,7 @@ impl LayerGadget {

// complete block is called AFTER all working gadget has been assigned on the specified offset,
// this entry fill whole block with series and index value
pub fn complete_block<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn complete_block<Fp: FromUniformBytes<64> + Ord>(
&self,
region: &mut Region<'_, Fp>,
offset: usize,
Expand Down Expand Up @@ -512,7 +512,7 @@ impl LayerGadget {

// set all transition rules
// + end_op: is the last op code in your assignation, often just (<padding gadget's op type, usually 0>, 0)
pub fn set_op_border<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn set_op_border<Fp: FromUniformBytes<64> + Ord>(
&self,
layouter: &mut impl Layouter<Fp>,
inter_op: &[OpBorder],
Expand All @@ -524,7 +524,7 @@ impl LayerGadget {

// set all transition rules
// + start_op: all possible starting op code and ctrl code
pub fn set_op_border_ex<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn set_op_border_ex<Fp: FromUniformBytes<64> + Ord>(
&self,
layouter: &mut impl Layouter<Fp>,
inter_op: &[OpBorder],
Expand Down Expand Up @@ -720,7 +720,7 @@ pub(crate) struct PaddingGadget {
}

impl PaddingGadget {
pub fn configure<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn configure<Fp: FromUniformBytes<64> + Ord>(
_meta: &mut ConstraintSystem<Fp>,
_sel: Selector,
exported: &[Column<Advice>],
Expand All @@ -733,7 +733,7 @@ impl PaddingGadget {
}
}

pub fn padding<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn padding<Fp: FromUniformBytes<64> + Ord>(
&self,
region: &mut Region<'_, Fp>,
offset: usize,
Expand Down
18 changes: 7 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ use mpt::MPTOpGadget;
use operation::{AccountOp, HashTracesSrc, SingleOp};

// building lagrange polynmials L for T so that L(n) = 1 when n = T else 0, n in [0, TO]
fn lagrange_polynomial<
Fp: PrimeField + FromUniformBytes<64> + Ord,
const T: usize,
const TO: usize,
>(
fn lagrange_polynomial<Fp: FromUniformBytes<64> + Ord, const T: usize, const TO: usize>(
ref_n: Expression<Fp>,
) -> Expression<Fp> {
let mut denominators: Vec<Fp> = (0..=TO)
Expand Down Expand Up @@ -116,7 +112,7 @@ pub struct SimpleTrieConfig {

/// The chip for op on a simple trie
#[derive(Clone, Default)]
pub struct SimpleTrie<F: PrimeField + FromUniformBytes<64> + Ord> {
pub struct SimpleTrie<F: FromUniformBytes<64> + Ord> {
c_size: usize, //how many rows
start_root: F,
final_root: F,
Expand All @@ -126,7 +122,7 @@ pub struct SimpleTrie<F: PrimeField + FromUniformBytes<64> + Ord> {
const OP_MPT: u32 = 1;
const OP_PADDING: u32 = 0;

impl<Fp: PrimeField + FromUniformBytes<64> + Ord> SimpleTrie<Fp> {
impl<Fp: FromUniformBytes<64> + Ord> SimpleTrie<Fp> {
/// create a new, empty circuit with specified size
pub fn new(c_size: usize) -> Self {
Self {
Expand All @@ -152,7 +148,7 @@ impl<Fp: PrimeField + FromUniformBytes<64> + Ord> SimpleTrie<Fp> {
}
}

impl<Fp: PrimeField + FromUniformBytes<64> + Ord> Circuit<Fp> for SimpleTrie<Fp> {
impl<Fp: FromUniformBytes<64> + Ord> Circuit<Fp> for SimpleTrie<Fp> {
type Config = SimpleTrieConfig;
type FloorPlanner = SimpleFloorPlanner;

Expand Down Expand Up @@ -611,7 +607,7 @@ impl EthTrieConfig {
}
/// The chip for op on an storage trie
#[derive(Clone, Default)]
pub struct EthTrie<F: PrimeField + FromUniformBytes<64> + Ord> {
pub struct EthTrie<F: FromUniformBytes<64> + Ord> {
start_root: F,
final_root: F,
ops: Vec<AccountOp<F>>,
Expand All @@ -622,7 +618,7 @@ const OP_TRIE_STATE: u32 = 2;
const OP_ACCOUNT: u32 = 3;
const OP_STORAGE: u32 = 4;

impl<Fp: PrimeField + FromUniformBytes<64> + Ord> EthTrie<Fp> {
impl<Fp: FromUniformBytes<64> + Ord> EthTrie<Fp> {
/// Obtain the wrapped operation sequence
pub fn get_ops(&self) -> &[AccountOp<Fp>] {
&self.ops
Expand Down Expand Up @@ -654,7 +650,7 @@ impl<Fp: PrimeField + FromUniformBytes<64> + Ord> EthTrie<Fp> {

/// the mpt circuit type
#[derive(Clone, Default, Debug)]
pub struct EthTrieCircuit<F: PrimeField + FromUniformBytes<64> + Ord, const LITE: bool> {
pub struct EthTrieCircuit<F: FromUniformBytes<64> + Ord, const LITE: bool> {
/// the maxium records in circuits (would affect vk)
pub calcs: usize,
/// the operations in circuits
Expand Down
36 changes: 18 additions & 18 deletions src/mpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use crate::operation::{MPTPath, SingleOp};
use halo2_proofs::{
arithmetic::Field,
circuit::{Chip, Layouter, Region, Value},
ff::{FromUniformBytes, PrimeField},
ff::FromUniformBytes,
plonk::{
Advice, Column, ConstraintSystem, Error, Expression, Selector, TableColumn, VirtualCells,
},
Expand Down Expand Up @@ -123,7 +123,7 @@ impl MPTOpTables {
)
}

pub fn build_lookup_any<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn build_lookup_any<Fp: FromUniformBytes<64> + Ord>(
&self,
enable: Expression<Fp>,
rules: impl IntoIterator<Item = Expression<Fp>>,
Expand All @@ -138,7 +138,7 @@ impl MPTOpTables {
ret
}

pub fn build_lookup<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn build_lookup<Fp: FromUniformBytes<64> + Ord>(
&self,
enable: Expression<Fp>,
old: Expression<Fp>,
Expand All @@ -148,7 +148,7 @@ impl MPTOpTables {
self.build_lookup_any(enable, [old, new], mark)
}

pub fn fill_constant<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn fill_constant<Fp: FromUniformBytes<64> + Ord>(
&self,
layouter: &mut impl Layouter<Fp>,
rules: impl Iterator<Item = ([u32; 3], u32)> + Clone,
Expand Down Expand Up @@ -207,7 +207,7 @@ impl HashTable {
self.0.map(|col| col.index())
}

pub fn build_lookup<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn build_lookup<Fp: FromUniformBytes<64> + Ord>(
&self,
meta: &mut VirtualCells<'_, Fp>,
enable: Expression<Fp>,
Expand Down Expand Up @@ -239,7 +239,7 @@ impl HashTable {

/// a helper entry to fill hash table with specified rows, use padding record
/// when hashing_records is not enough
pub fn dev_fill_with_paddings<'d, Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn dev_fill_with_paddings<'d, Fp: FromUniformBytes<64> + Ord>(
&self,
layouter: &mut impl Layouter<Fp>,
hashing_records: impl Iterator<Item = &'d (Fp, Fp, Fp)> + Clone,
Expand All @@ -256,7 +256,7 @@ impl HashTable {
}

/// a helper entry to fill hash table, only for dev (in using cases)
pub fn dev_fill<'d, Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn dev_fill<'d, Fp: FromUniformBytes<64> + Ord>(
&self,
layouter: &mut impl Layouter<Fp>,
hashing_records: impl Iterator<Item = &'d (Fp, Fp, Fp)> + Clone,
Expand Down Expand Up @@ -349,7 +349,7 @@ impl MPTOpGadget {
}

/// if the gadget would be used only once, this entry is more easy
pub fn configure_simple<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn configure_simple<Fp: FromUniformBytes<64> + Ord>(
meta: &mut ConstraintSystem<Fp>,
sel: Selector,
exported: &[Column<Advice>],
Expand Down Expand Up @@ -378,7 +378,7 @@ impl MPTOpGadget {
/// + s_op_flags * 6 (corresponding 6 ctrl_types)
/// + free col * 8
/// notice the gadget has bi-direction exporting (on top it exporting mpt root and bottom exporting leaf)
pub fn configure<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn configure<Fp: FromUniformBytes<64> + Ord>(
meta: &mut ConstraintSystem<Fp>,
sel: Selector,
exported: &[Column<Advice>],
Expand Down Expand Up @@ -469,13 +469,13 @@ impl MPTOpGadget {
i1.chain(i2)
}

/* pub fn init<Fp: PrimeField + FromUniformBytes<64> + Ord>(&self, layouter: &mut impl Layouter<Fp>) -> Result<(), Error> {
/* pub fn init<Fp: FromUniformBytes<64> + Ord>(&self, layouter: &mut impl Layouter<Fp>) -> Result<(), Error> {
self.tables
.fill_constant(layouter, Self::transition_rules())
}*/

/// assign data and enable flag for MPT circuit
pub fn assign<Fp: PrimeField + FromUniformBytes<64> + Ord>(
pub fn assign<Fp: FromUniformBytes<64> + Ord>(
&self,
region: &mut Region<'_, Fp>,
offset: usize,
Expand Down Expand Up @@ -510,7 +510,7 @@ impl MPTOpGadget {
}

/*
fn lagrange_polynomial_for_hashtype<Fp: PrimeField + FromUniformBytes<64> + Ord, const T: usize>(
fn lagrange_polynomial_for_hashtype<Fp: FromUniformBytes<64> + Ord, const T: usize>(
ref_n: Expression<Fp>,
) -> Expression<Fp> {
super::lagrange_polynomial::<Fp, T, 5 /* last Type: Leaf */>(ref_n)
Expand All @@ -531,14 +531,14 @@ struct PathChipConfig {

/// chip for verify mutiple merkle path in MPT
/// it do not need any auxiliary cols
struct PathChip<'d, F: PrimeField + FromUniformBytes<64> + Ord> {
struct PathChip<'d, F: FromUniformBytes<64> + Ord> {
offset: usize,
config: PathChipConfig,
data: &'d MPTPath<F>,
ref_ctrl_type: Option<&'d [HashType]>,
}

impl<Fp: PrimeField + FromUniformBytes<64> + Ord> Chip<Fp> for PathChip<'_, Fp> {
impl<Fp: FromUniformBytes<64> + Ord> Chip<Fp> for PathChip<'_, Fp> {
type Config = PathChipConfig;
type Loaded = MPTPath<Fp>;

Expand All @@ -551,7 +551,7 @@ impl<Fp: PrimeField + FromUniformBytes<64> + Ord> Chip<Fp> for PathChip<'_, Fp>
}
}

impl<'d, Fp: PrimeField + FromUniformBytes<64> + Ord> PathChip<'d, Fp> {
impl<'d, Fp: FromUniformBytes<64> + Ord> PathChip<'d, Fp> {
fn configure(
meta: &mut ConstraintSystem<Fp>,
g_config: &MPTOpConfig,
Expand Down Expand Up @@ -854,13 +854,13 @@ struct OpChipConfig {

/// chip for verify mutiple merkle path in MPT
/// it do not need any auxiliary cols
struct OpChip<'d, F: PrimeField + FromUniformBytes<64> + Ord> {
struct OpChip<'d, F: FromUniformBytes<64> + Ord> {
offset: usize,
config: OpChipConfig,
data: &'d SingleOp<F>,
}

impl<Fp: PrimeField + FromUniformBytes<64> + Ord> Chip<Fp> for OpChip<'_, Fp> {
impl<Fp: FromUniformBytes<64> + Ord> Chip<Fp> for OpChip<'_, Fp> {
type Config = OpChipConfig;
type Loaded = SingleOp<Fp>;

Expand All @@ -873,7 +873,7 @@ impl<Fp: PrimeField + FromUniformBytes<64> + Ord> Chip<Fp> for OpChip<'_, Fp> {
}
}

impl<'d, Fp: PrimeField + FromUniformBytes<64> + Ord> OpChip<'d, Fp> {
impl<'d, Fp: FromUniformBytes<64> + Ord> OpChip<'d, Fp> {
fn configure(
meta: &mut ConstraintSystem<Fp>,
g_config: &MPTOpConfig,
Expand Down
2 changes: 1 addition & 1 deletion src/mpt_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Config {
self.address.index()
}

pub fn bind_mpt_circuit<F: PrimeField + FromUniformBytes<64> + Ord>(
pub fn bind_mpt_circuit<F: FromUniformBytes<64> + Ord>(
&self,
meta: &mut ConstraintSystem<F>,
gadget_id: Column<Advice>,
Expand Down
9 changes: 5 additions & 4 deletions src/mpt_table/byte32.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use halo2_proofs::{
circuit::{Region, Value},
ff::{FromUniformBytes, PrimeField},
ff::FromUniformBytes,
plonk::{Advice, Column, ConstraintSystem, Error, Expression, Selector},
poly::Rotation,
};
Expand All @@ -12,7 +12,7 @@ pub(crate) struct Config {
}

impl Config {
pub fn configure<F: PrimeField + FromUniformBytes<64> + Ord, const N: usize>(
pub fn configure<F: FromUniformBytes<64> + Ord, const N: usize>(
meta: &mut ConstraintSystem<F>,
sel: Selector,
rep: &[Column<Advice>; N],
Expand Down Expand Up @@ -49,7 +49,7 @@ impl Config {
Self { rep_hi, rep_lo }
}

pub fn assign<F: PrimeField + FromUniformBytes<64> + Ord>(
pub fn assign<F: FromUniformBytes<64> + Ord>(
&self,
region: &mut Region<'_, F>,
offset: usize,
Expand All @@ -67,7 +67,7 @@ impl Config {
Ok(true)
}

pub fn flush<F: PrimeField + FromUniformBytes<64> + Ord>(
pub fn flush<F: FromUniformBytes<64> + Ord>(
&self,
region: &mut Region<'_, F>,
offset: usize,
Expand All @@ -84,6 +84,7 @@ mod test {
use super::super::value_rep::Config as RepConfig;
use super::*;
use crate::test_utils::*;
use halo2_proofs::ff::PrimeField;
use halo2_proofs::{
circuit::{Layouter, Region, SimpleFloorPlanner},
dev::{MockProver, VerifyFailure},
Expand Down
Loading

0 comments on commit 6a4f13e

Please sign in to comment.