diff --git a/src/constraint_builder.rs b/src/constraint_builder.rs index b653a5f7..484557e0 100644 --- a/src/constraint_builder.rs +++ b/src/constraint_builder.rs @@ -1,6 +1,6 @@ use crate::gadgets::poseidon::PoseidonLookup; use halo2_proofs::{ - arithmetic::FieldExt, + halo2curves::ff::FromUniformBytes, plonk::{ConstraintSystem, SecondPhase}, }; use itertools::Itertools; @@ -15,7 +15,7 @@ pub use binary_query::BinaryQuery; pub use column::{AdviceColumn, FixedColumn, SecondPhaseAdviceColumn, SelectorColumn}; pub use query::Query; -pub struct ConstraintBuilder { +pub struct ConstraintBuilder + Ord> { constraints: Vec<(&'static str, Query)>, #[allow(clippy::type_complexity)] lookups: Vec<(&'static str, Vec<(Query, Query)>)>, @@ -23,7 +23,7 @@ pub struct ConstraintBuilder { conditions: Vec>, } -impl ConstraintBuilder { +impl + Ord> ConstraintBuilder { pub fn new(every_row: SelectorColumn) -> Self { Self { constraints: vec![], diff --git a/src/constraint_builder/binary_column.rs b/src/constraint_builder/binary_column.rs index c414850f..c51062d9 100644 --- a/src/constraint_builder/binary_column.rs +++ b/src/constraint_builder/binary_column.rs @@ -1,7 +1,7 @@ use super::{BinaryQuery, ConstraintBuilder, Query}; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{Region, Value}, + halo2curves::ff::FromUniformBytes, plonk::ConstraintSystem, plonk::{Advice, Column}, }; @@ -10,23 +10,23 @@ use halo2_proofs::{ pub struct BinaryColumn(pub Column); impl BinaryColumn { - pub fn rotation(&self, i: i32) -> BinaryQuery { + pub fn rotation + Ord>(&self, i: i32) -> BinaryQuery { BinaryQuery(Query::Advice(self.0, i)) } - pub fn current(&self) -> BinaryQuery { + pub fn current + Ord>(&self) -> BinaryQuery { self.rotation(0) } - pub fn previous(&self) -> BinaryQuery { + pub fn previous + Ord>(&self) -> BinaryQuery { self.rotation(-1) } - pub fn next(&self) -> BinaryQuery { + pub fn next + Ord>(&self) -> BinaryQuery { self.rotation(1) } - pub fn configure( + pub fn configure + Ord>( cs: &mut ConstraintSystem, cb: &mut ConstraintBuilder, ) -> Self { @@ -38,9 +38,19 @@ impl BinaryColumn { binary_column } - pub fn assign(&self, region: &mut Region<'_, F>, offset: usize, value: bool) { + pub fn assign + Ord>( + &self, + region: &mut Region<'_, F>, + offset: usize, + value: bool, + ) { region - .assign_advice(|| "binary", self.0, offset, || Value::known(F::from(value))) + .assign_advice( + || "binary", + self.0, + offset, + || Value::known(F::from(value as u64)), + ) .expect("failed assign_advice"); } } diff --git a/src/constraint_builder/binary_query.rs b/src/constraint_builder/binary_query.rs index 9c80f967..67d6c7b3 100644 --- a/src/constraint_builder/binary_query.rs +++ b/src/constraint_builder/binary_query.rs @@ -1,6 +1,7 @@ use super::Query; use halo2_proofs::{ - arithmetic::{Field, FieldExt}, + arithmetic::Field, + halo2curves::ff::FromUniformBytes, plonk::{Expression, VirtualCells}, }; // use std::iter::Sum; @@ -9,7 +10,7 @@ use halo2_proofs::{ #[derive(Clone)] pub struct BinaryQuery(pub Query); -impl BinaryQuery { +impl + Ord> BinaryQuery { pub fn zero() -> Self { Self(Query::from(0)) } @@ -35,13 +36,13 @@ impl BinaryQuery { } } -impl BinaryQuery { +impl + Ord> BinaryQuery { pub fn run(self, meta: &mut VirtualCells<'_, F>) -> Expression { self.0.run(meta) } } -impl std::ops::Not for BinaryQuery { +impl + Ord> std::ops::Not for BinaryQuery { type Output = Self; // In general this can cause a ConstraintPoisoned. You need to add a selector column that's all ones to be safe. diff --git a/src/constraint_builder/column.rs b/src/constraint_builder/column.rs index b3dbfa03..bd810283 100644 --- a/src/constraint_builder/column.rs +++ b/src/constraint_builder/column.rs @@ -1,7 +1,7 @@ use super::{BinaryQuery, Query}; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{Region, Value}, + halo2curves::ff::FromUniformBytes, plonk::{Advice, Column, Fixed}, }; use std::fmt::Debug; @@ -10,17 +10,17 @@ use std::fmt::Debug; pub struct SelectorColumn(pub Column); impl SelectorColumn { - pub fn current(self) -> BinaryQuery { + pub fn current + Ord>(self) -> BinaryQuery { self.rotation(0) } - pub fn rotation(self, i: i32) -> BinaryQuery { + pub fn rotation + Ord>(self, i: i32) -> BinaryQuery { BinaryQuery(Query::Fixed(self.0, i)) } - pub fn enable(&self, region: &mut Region<'_, F>, offset: usize) { + pub fn enable + Ord>(&self, region: &mut Region<'_, F>, offset: usize) { region - .assign_fixed(|| "selector", self.0, offset, || Value::known(F::one())) + .assign_fixed(|| "selector", self.0, offset, || Value::known(F::ONE)) .expect("failed enable selector"); } } @@ -29,19 +29,19 @@ impl SelectorColumn { pub struct FixedColumn(pub Column); impl FixedColumn { - pub fn rotation(self, i: i32) -> Query { + pub fn rotation + Ord>(self, i: i32) -> Query { Query::Fixed(self.0, i) } - pub fn current(self) -> Query { + pub fn current + Ord>(self) -> Query { self.rotation(0) } - pub fn previous(self) -> Query { + pub fn previous + Ord>(self) -> Query { self.rotation(-1) } - pub fn assign>( + pub fn assign + Ord, T: Copy + TryInto>( &self, region: &mut Region<'_, F>, offset: usize, @@ -64,27 +64,27 @@ impl FixedColumn { pub struct AdviceColumn(pub Column); impl AdviceColumn { - pub fn rotation(self, i: i32) -> Query { + pub fn rotation + Ord>(self, i: i32) -> Query { Query::Advice(self.0, i) } - pub fn current(self) -> Query { + pub fn current + Ord>(self) -> Query { self.rotation(0) } - pub fn previous(self) -> Query { + pub fn previous + Ord>(self) -> Query { self.rotation(-1) } - pub fn next(self) -> Query { + pub fn next + Ord>(self) -> Query { self.rotation(1) } - pub fn delta(self) -> Query { + pub fn delta + Ord>(self) -> Query { self.current() - self.previous() } - pub fn assign>( + pub fn assign + Ord, T: Copy + TryInto>( &self, region: &mut Region<'_, F>, offset: usize, @@ -107,19 +107,24 @@ impl AdviceColumn { pub struct SecondPhaseAdviceColumn(pub Column); impl SecondPhaseAdviceColumn { - fn rotation(self, i: i32) -> Query { + fn rotation + Ord>(self, i: i32) -> Query { Query::Advice(self.0, i) } - pub fn current(self) -> Query { + pub fn current + Ord>(self) -> Query { self.rotation(0) } - pub fn previous(self) -> Query { + pub fn previous + Ord>(self) -> Query { self.rotation(-1) } - pub fn assign(&self, region: &mut Region<'_, F>, offset: usize, value: Value) { + pub fn assign + Ord>( + &self, + region: &mut Region<'_, F>, + offset: usize, + value: Value, + ) { region .assign_advice(|| "second phase advice", self.0, offset, || value) .expect("failed assign_advice"); diff --git a/src/constraint_builder/query.rs b/src/constraint_builder/query.rs index c7b24c4c..41719477 100644 --- a/src/constraint_builder/query.rs +++ b/src/constraint_builder/query.rs @@ -1,7 +1,7 @@ use super::BinaryQuery; use halo2_proofs::{ - arithmetic::{Field, FieldExt}, - halo2curves::{bn256::Fr, group::ff::PrimeField}, + arithmetic::Field, + halo2curves::{bn256::Fr, ff::FromUniformBytes, group::ff::PrimeField}, plonk::{Advice, Challenge, Column, Expression, Fixed, VirtualCells}, poly::Rotation, }; @@ -24,7 +24,7 @@ pub enum Query { Mul(Box, Box), } -impl Query { +impl + Ord> Query { pub fn zero() -> Self { Self::from(0) } @@ -43,7 +43,7 @@ impl Query { Query::Advice(c, r) => meta.query_advice(*c, Rotation(*r)), Query::Fixed(c, r) => meta.query_fixed(*c, Rotation(*r)), Query::Challenge(c) => meta.query_challenge(*c), - Query::Neg(q) => Expression::Constant(F::zero()) - q.run(meta), + Query::Neg(q) => Expression::Constant(F::ZERO) - q.run(meta), Query::Add(q, u) => q.run(meta) + u.run(meta), Query::Mul(q, u) => q.run(meta) * u.run(meta), } @@ -54,13 +54,13 @@ impl Query { } } -impl From for Query { +impl + Ord> From for Query { fn from(x: u64) -> Self { Self::Constant(F::from(x)) } } -impl From for Query { +impl + Ord> From for Query { fn from(x: Fr) -> Self { let little_endian_bytes = x.to_repr(); let little_endian_limbs = little_endian_bytes @@ -73,7 +73,7 @@ impl From for Query { } } -impl From> for Query { +impl + Ord> From> for Query { fn from(b: BinaryQuery) -> Self { b.0 } diff --git a/src/gadgets/byte_bit.rs b/src/gadgets/byte_bit.rs index 60474732..90c58240 100644 --- a/src/gadgets/byte_bit.rs +++ b/src/gadgets/byte_bit.rs @@ -1,5 +1,5 @@ use super::super::constraint_builder::{ConstraintBuilder, FixedColumn, Query}; -use halo2_proofs::{arithmetic::FieldExt, circuit::Region, plonk::ConstraintSystem}; +use halo2_proofs::{circuit::Region, halo2curves::ff::FromUniformBytes, plonk::ConstraintSystem}; // TODO: fix name to configggggggg #[derive(Clone)] @@ -10,19 +10,19 @@ pub struct ByteBitGadget { } pub trait RangeCheck8Lookup { - fn lookup(&self) -> [Query; 1]; + fn lookup + Ord>(&self) -> [Query; 1]; } pub trait RangeCheck256Lookup { - fn lookup(&self) -> [Query; 1]; + fn lookup + Ord>(&self) -> [Query; 1]; } pub trait ByteBitLookup { - fn lookup(&self) -> [Query; 3]; + fn lookup + Ord>(&self) -> [Query; 3]; } impl ByteBitGadget { - pub fn configure( + pub fn configure + Ord>( cs: &mut ConstraintSystem, cb: &mut ConstraintBuilder, ) -> Self { @@ -30,13 +30,14 @@ impl ByteBitGadget { Self { byte, index, bit } } - pub fn assign(&self, region: &mut Region<'_, F>) { + pub fn assign + Ord>(&self, region: &mut Region<'_, F>) { let mut offset = 0; for byte in 0..256 { for index in 0..8 { self.byte.assign(region, offset, byte); self.index.assign(region, offset, index); - self.bit.assign(region, offset, byte & (1 << index) != 0); + self.bit + .assign(region, offset, (byte & (1 << index) != 0) as u64); offset += 1; } } @@ -44,19 +45,19 @@ impl ByteBitGadget { } impl RangeCheck8Lookup for ByteBitGadget { - fn lookup(&self) -> [Query; 1] { + fn lookup + Ord>(&self) -> [Query; 1] { [self.index.current()] } } impl RangeCheck256Lookup for ByteBitGadget { - fn lookup(&self) -> [Query; 1] { + fn lookup + Ord>(&self) -> [Query; 1] { [self.byte.current()] } } impl ByteBitLookup for ByteBitGadget { - fn lookup(&self) -> [Query; 3] { + fn lookup + Ord>(&self) -> [Query; 3] { [ self.byte.current(), self.index.current(), diff --git a/src/gadgets/byte_representation.rs b/src/gadgets/byte_representation.rs index 4ce4a331..41df3f53 100644 --- a/src/gadgets/byte_representation.rs +++ b/src/gadgets/byte_representation.rs @@ -4,18 +4,17 @@ use crate::constraint_builder::{ }; use ethers_core::types::{Address, H256}; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{Region, Value}, - halo2curves::bn256::Fr, + halo2curves::{bn256::Fr, ff::FromUniformBytes}, plonk::ConstraintSystem, }; pub trait RlcLookup { - fn lookup(&self) -> [Query; 3]; + fn lookup + Ord>(&self) -> [Query; 3]; } pub trait BytesLookup { - fn lookup(&self) -> [Query; 2]; + fn lookup + Ord>(&self) -> [Query; 2]; } // Right the byte order is big endian, which means that e.g. proving that 0x01 fits into 3 @@ -37,7 +36,7 @@ pub struct ByteRepresentationConfig { // WARNING: it is a soundness issue if the index lookup is >= 31 (i.e. the value can // overflow in the field if it has 32 or more bytes). impl RlcLookup for ByteRepresentationConfig { - fn lookup(&self) -> [Query; 3] { + fn lookup + Ord>(&self) -> [Query; 3] { [ self.value.current(), self.index.current(), @@ -47,13 +46,13 @@ impl RlcLookup for ByteRepresentationConfig { } impl BytesLookup for ByteRepresentationConfig { - fn lookup(&self) -> [Query; 2] { + fn lookup + Ord>(&self) -> [Query; 2] { [self.value.current(), self.index.current()] } } impl ByteRepresentationConfig { - pub fn configure( + pub fn configure + Ord>( cs: &mut ConstraintSystem, cb: &mut ConstraintBuilder, range_check: &impl RangeCheck256Lookup, @@ -94,7 +93,7 @@ impl ByteRepresentationConfig { } // can this we done with an Iterator instead? - pub fn assign( + pub fn assign + Ord>( &self, region: &mut Region<'_, F>, u32s: &[u32], @@ -113,8 +112,8 @@ impl ByteRepresentationConfig { let mut offset = 0; for byte_representation in byte_representations { - let mut value = F::zero(); - let mut rlc = Value::known(F::zero()); + let mut value = F::ZERO; + let mut rlc = Value::known(F::ZERO); for (index, byte) in byte_representation.iter().enumerate() { let byte = F::from(u64::from(*byte)); self.byte.assign(region, offset, byte); diff --git a/src/gadgets/canonical_representation.rs b/src/gadgets/canonical_representation.rs index 7e2ae9b5..40ec23d9 100644 --- a/src/gadgets/canonical_representation.rs +++ b/src/gadgets/canonical_representation.rs @@ -3,9 +3,11 @@ use super::super::constraint_builder::{ SelectorColumn, }; use super::{byte_bit::RangeCheck256Lookup, is_zero::IsZeroGadget, rlc_randomness::RlcRandomness}; +use ethers_core::k256::elliptic_curve::PrimeField; use ethers_core::types::U256; +use halo2_proofs::halo2curves::ff::FromUniformBytes; use halo2_proofs::{ - arithmetic::{Field, FieldExt}, + arithmetic::Field, circuit::{Region, Value}, halo2curves::bn256::Fr, plonk::ConstraintSystem, @@ -14,12 +16,12 @@ use itertools::Itertools; use num_traits::Zero; pub trait CanonicalRepresentationLookup { - fn lookup(&self) -> [Query; 3]; + fn lookup + Ord>(&self) -> [Query; 3]; } // Lookup to prove that Rlc(x: Fr) = y pub trait FrRlcLookup { - fn lookup(&self) -> [Query; 2]; + fn lookup + Ord>(&self) -> [Query; 2]; } #[derive(Clone)] @@ -183,7 +185,7 @@ impl CanonicalRepresentationConfig { } impl CanonicalRepresentationLookup for CanonicalRepresentationConfig { - fn lookup(&self) -> [Query; 3] { + fn lookup + Ord>(&self) -> [Query; 3] { [ self.value.current(), self.index.current(), @@ -193,7 +195,7 @@ impl CanonicalRepresentationLookup for CanonicalRepresentationConfig { } impl FrRlcLookup for CanonicalRepresentationConfig { - fn lookup(&self) -> [Query; 2] { + fn lookup + Ord>(&self) -> [Query; 2] { [ self.value.current() * self.index_is_31.current(), self.rlc.current() * self.index_is_31.current(), diff --git a/src/gadgets/is_zero.rs b/src/gadgets/is_zero.rs index 9fe7163d..a853dd55 100644 --- a/src/gadgets/is_zero.rs +++ b/src/gadgets/is_zero.rs @@ -1,5 +1,5 @@ use crate::constraint_builder::{AdviceColumn, BinaryQuery, ConstraintBuilder, Query}; -use halo2_proofs::{arithmetic::FieldExt, circuit::Region, plonk::ConstraintSystem}; +use halo2_proofs::{circuit::Region, halo2curves::ff::FromUniformBytes, plonk::ConstraintSystem}; use std::fmt::Debug; #[derive(Clone, Copy)] @@ -9,15 +9,15 @@ pub struct IsZeroGadget { } impl IsZeroGadget { - pub fn current(self) -> BinaryQuery { + pub fn current + Ord>(self) -> BinaryQuery { BinaryQuery(Query::one() - self.value.current() * self.inverse_or_zero.current()) } - pub fn previous(self) -> BinaryQuery { + pub fn previous + Ord>(self) -> BinaryQuery { BinaryQuery(Query::one() - self.value.previous() * self.inverse_or_zero.previous()) } - pub fn assign>( + pub fn assign + Ord, T: Copy + TryInto>( &self, region: &mut Region<'_, F>, offset: usize, @@ -28,12 +28,12 @@ impl IsZeroGadget { self.inverse_or_zero.assign( region, offset, - value.try_into().unwrap().invert().unwrap_or(F::zero()), + value.try_into().unwrap().invert().unwrap_or(F::ZERO), ); } // TODO: get rid of assign method in favor of it. - pub fn assign_value_and_inverse>( + pub fn assign_value_and_inverse + Ord, T: Copy + TryInto>( &self, region: &mut Region<'_, F>, offset: usize, @@ -45,7 +45,7 @@ impl IsZeroGadget { self.assign(region, offset, value); } - pub fn configure( + pub fn configure + Ord>( cs: &mut ConstraintSystem, cb: &mut ConstraintBuilder, value: AdviceColumn, // TODO: make this a query once Query is clonable/copyable..... diff --git a/src/gadgets/key_bit.rs b/src/gadgets/key_bit.rs index 8891665d..cdb20f39 100644 --- a/src/gadgets/key_bit.rs +++ b/src/gadgets/key_bit.rs @@ -4,11 +4,13 @@ use super::{ }; use crate::constraint_builder::{AdviceColumn, ConstraintBuilder, Query, SelectorColumn}; use halo2_proofs::{ - arithmetic::FieldExt, circuit::Region, halo2curves::bn256::Fr, plonk::ConstraintSystem, + circuit::Region, + halo2curves::{bn256::Fr, ff::FromUniformBytes}, + plonk::ConstraintSystem, }; pub trait KeyBitLookup { - fn lookup(&self) -> [Query; 3]; + fn lookup + Ord>(&self) -> [Query; 3]; } #[derive(Clone)] @@ -27,7 +29,7 @@ pub struct KeyBitConfig { } impl KeyBitConfig { - pub fn configure( + pub fn configure + Ord>( cs: &mut ConstraintSystem, cb: &mut ConstraintBuilder, representation: &impl CanonicalRepresentationLookup, @@ -111,7 +113,7 @@ impl KeyBitConfig { } impl KeyBitLookup for KeyBitConfig { - fn lookup(&self) -> [Query; 3] { + fn lookup + Ord>(&self) -> [Query; 3] { [ self.value.current(), self.index.current(), diff --git a/src/gadgets/mpt_update.rs b/src/gadgets/mpt_update.rs index 500537e7..f3c25211 100644 --- a/src/gadgets/mpt_update.rs +++ b/src/gadgets/mpt_update.rs @@ -29,9 +29,9 @@ use crate::{ }; use ethers_core::types::Address; use halo2_proofs::{ - arithmetic::{Field, FieldExt}, + arithmetic::Field, circuit::{Region, Value}, - halo2curves::{bn256::Fr, group::ff::PrimeField}, + halo2curves::{bn256::Fr, ff::FromUniformBytes, group::ff::PrimeField}, plonk::ConstraintSystem, }; use itertools::izip; @@ -44,7 +44,7 @@ lazy_static! { domain_hash(Fr::zero(), *ZERO_PAIR_HASH, HashDomain::AccountFields); } -pub trait MptUpdateLookup { +pub trait MptUpdateLookup + Ord> { fn lookup(&self) -> [Query; 8]; } @@ -76,7 +76,7 @@ pub struct MptUpdateConfig { is_zero_gadgets: [IsZeroGadget; 4], // can be 3 } -impl MptUpdateLookup for MptUpdateConfig { +impl + Ord> MptUpdateLookup for MptUpdateConfig { fn lookup(&self) -> [Query; 8] { let is_start = || self.segment_type.current_matches(&[SegmentType::Start]); let old_root_rlc = self.second_phase_intermediate_values[0].current() * is_start(); @@ -103,7 +103,7 @@ impl MptUpdateLookup for MptUpdateConfig { } impl MptUpdateConfig { - pub fn configure( + pub fn configure + Ord>( cs: &mut ConstraintSystem, cb: &mut ConstraintBuilder, poseidon: &impl PoseidonLookup, @@ -870,22 +870,22 @@ impl MptUpdateConfig { } } -fn old_left(config: &MptUpdateConfig) -> Query { +fn old_left + Ord>(config: &MptUpdateConfig) -> Query { config.direction.current() * config.sibling.current() + (Query::one() - config.direction.current()) * config.old_hash.current() } -fn old_right(config: &MptUpdateConfig) -> Query { +fn old_right + Ord>(config: &MptUpdateConfig) -> Query { config.direction.current() * config.old_hash.current() + (Query::one() - config.direction.current()) * config.sibling.current() } -fn new_left(config: &MptUpdateConfig) -> Query { +fn new_left + Ord>(config: &MptUpdateConfig) -> Query { config.direction.current() * config.sibling.current() + (Query::one() - config.direction.current()) * config.new_hash.current() } -fn new_right(config: &MptUpdateConfig) -> Query { +fn new_right + Ord>(config: &MptUpdateConfig) -> Query { config.direction.current() * config.new_hash.current() + (Query::one() - config.direction.current()) * config.sibling.current() } @@ -897,7 +897,7 @@ fn address_to_fr(a: Address) -> Fr { Fr::from_repr(bytes).unwrap() } -fn configure_segment_transitions( +fn configure_segment_transitions + Ord>( cb: &mut ConstraintBuilder, segment: &OneHot, proof: MPTProofType, @@ -917,7 +917,7 @@ fn configure_segment_transitions( } } -fn configure_common_path( +fn configure_common_path + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, @@ -1116,7 +1116,7 @@ fn configure_common_path( ); } -fn configure_extension_old( +fn configure_extension_old + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, @@ -1198,7 +1198,7 @@ fn configure_extension_old( ); } -fn configure_extension_new( +fn configure_extension_new + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, @@ -1285,7 +1285,7 @@ fn configure_extension_new( ); } -fn configure_nonce( +fn configure_nonce + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, bytes: &impl BytesLookup, @@ -1415,7 +1415,7 @@ fn configure_nonce( } } -fn configure_code_size( +fn configure_code_size + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, bytes: &impl BytesLookup, @@ -1505,7 +1505,7 @@ fn configure_code_size( } } -fn configure_balance( +fn configure_balance + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, @@ -1632,7 +1632,7 @@ fn configure_balance( } } -fn configure_poseidon_code_hash( +fn configure_poseidon_code_hash + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, ) { @@ -1683,7 +1683,7 @@ fn configure_poseidon_code_hash( } } -fn configure_keccak_code_hash( +fn configure_keccak_code_hash + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, @@ -1772,7 +1772,7 @@ fn configure_keccak_code_hash( } } -fn configure_storage( +fn configure_storage + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, @@ -1879,7 +1879,7 @@ fn configure_storage( } } -fn configure_empty_storage( +fn configure_empty_storage + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, @@ -1960,7 +1960,7 @@ fn configure_empty_storage( } } -fn configure_empty_account( +fn configure_empty_account + Ord>( cb: &mut ConstraintBuilder, config: &MptUpdateConfig, poseidon: &impl PoseidonLookup, diff --git a/src/gadgets/mpt_update/nonexistence_proof.rs b/src/gadgets/mpt_update/nonexistence_proof.rs index ad657814..d6677393 100644 --- a/src/gadgets/mpt_update/nonexistence_proof.rs +++ b/src/gadgets/mpt_update/nonexistence_proof.rs @@ -1,11 +1,12 @@ +use halo2_proofs::halo2curves::ff::FromUniformBytes; + use crate::{ constraint_builder::{AdviceColumn, ConstraintBuilder, Query, SecondPhaseAdviceColumn}, gadgets::{is_zero::IsZeroGadget, poseidon::PoseidonLookup}, types::HashDomain, }; -use halo2_proofs::arithmetic::FieldExt; -pub fn configure( +pub fn configure + Ord>( cb: &mut ConstraintBuilder, value: SecondPhaseAdviceColumn, key: AdviceColumn, diff --git a/src/gadgets/mpt_update/word_rlc.rs b/src/gadgets/mpt_update/word_rlc.rs index ec7f1153..bb2de094 100644 --- a/src/gadgets/mpt_update/word_rlc.rs +++ b/src/gadgets/mpt_update/word_rlc.rs @@ -7,14 +7,13 @@ use crate::{ types::HashDomain, util::{rlc, u256_hi_lo}, }; -use ethers_core::types::U256; +use ethers_core::{k256::elliptic_curve::PrimeField, types::U256}; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{Region, Value}, - halo2curves::bn256::Fr, + halo2curves::{bn256::Fr, ff::FromUniformBytes}, }; -pub fn configure( +pub fn configure + Ord>( cb: &mut ConstraintBuilder, [word_hash, high, low]: [AdviceColumn; 3], [rlc_word, rlc_high, rlc_low]: [SecondPhaseAdviceColumn; 3], diff --git a/src/gadgets/one_hot.rs b/src/gadgets/one_hot.rs index d33dd0ad..1d5c9927 100644 --- a/src/gadgets/one_hot.rs +++ b/src/gadgets/one_hot.rs @@ -1,5 +1,5 @@ use crate::constraint_builder::{BinaryColumn, BinaryQuery, ConstraintBuilder, Query}; -use halo2_proofs::{arithmetic::FieldExt, circuit::Region, plonk::ConstraintSystem}; +use halo2_proofs::{circuit::Region, halo2curves::ff::FromUniformBytes, plonk::ConstraintSystem}; use std::{cmp::Eq, collections::BTreeMap, hash::Hash}; use strum::IntoEnumIterator; @@ -12,7 +12,7 @@ pub struct OneHot { } impl OneHot { - pub fn configure( + pub fn configure + Ord>( cs: &mut ConstraintSystem, cb: &mut ConstraintBuilder, ) -> Self { @@ -28,25 +28,30 @@ impl OneHot { config } - pub fn assign(&self, region: &mut Region<'_, F>, offset: usize, value: T) { + pub fn assign + Ord>( + &self, + region: &mut Region<'_, F>, + offset: usize, + value: T, + ) { if let Some(c) = self.columns.get(&value) { c.assign(region, offset, true) } } - pub fn previous_matches(&self, values: &[T]) -> BinaryQuery { + pub fn previous_matches + Ord>(&self, values: &[T]) -> BinaryQuery { self.matches(values, -1) } - pub fn current_matches(&self, values: &[T]) -> BinaryQuery { + pub fn current_matches + Ord>(&self, values: &[T]) -> BinaryQuery { self.matches(values, 0) } - pub fn next_matches(&self, values: &[T]) -> BinaryQuery { + pub fn next_matches + Ord>(&self, values: &[T]) -> BinaryQuery { self.matches(values, 1) } - fn matches(&self, values: &[T], r: i32) -> BinaryQuery { + fn matches + Ord>(&self, values: &[T], r: i32) -> BinaryQuery { let query = values .iter() .map(|v| { @@ -59,7 +64,7 @@ impl OneHot { BinaryQuery(query) } - pub fn current(&self) -> Query { + pub fn current + Ord>(&self) -> Query { T::iter().enumerate().fold(Query::zero(), |acc, (i, t)| { acc + Query::from(u64::try_from(i).unwrap()) * self @@ -69,7 +74,7 @@ impl OneHot { }) } - pub fn previous(&self) -> Query { + pub fn previous + Ord>(&self) -> Query { T::iter().enumerate().fold(Query::zero(), |acc, (i, t)| { acc + Query::from(u64::try_from(i).unwrap()) * self @@ -79,7 +84,7 @@ impl OneHot { }) } - fn sum(&self, r: i32) -> BinaryQuery { + fn sum + Ord>(&self, r: i32) -> BinaryQuery { BinaryQuery( self.columns .values() diff --git a/src/gadgets/rlc_randomness.rs b/src/gadgets/rlc_randomness.rs index 84710221..d367448d 100644 --- a/src/gadgets/rlc_randomness.rs +++ b/src/gadgets/rlc_randomness.rs @@ -1,7 +1,7 @@ use crate::constraint_builder::Query; use halo2_proofs::{ - arithmetic::FieldExt, circuit::{Layouter, Value}, + halo2curves::ff::FromUniformBytes, plonk::{Challenge, ConstraintSystem, FirstPhase}, }; @@ -9,7 +9,7 @@ use halo2_proofs::{ pub struct RlcRandomness(pub Challenge); impl RlcRandomness { - pub fn configure(cs: &mut ConstraintSystem) -> Self { + pub fn configure + Ord>(cs: &mut ConstraintSystem) -> Self { // TODO: this is a hack so that we don't get a "'No Column is // used in phase Phase(0) while allocating a new "Challenge usable after // phase Phase(0)" error. @@ -19,11 +19,11 @@ impl RlcRandomness { Self(cs.challenge_usable_after(FirstPhase)) } - pub fn query(&self) -> Query { + pub fn query + Ord>(&self) -> Query { Query::Challenge(self.0) } - pub fn value(&self, layouter: &impl Layouter) -> Value { + pub fn value + Ord>(&self, layouter: &impl Layouter) -> Value { layouter.get_challenge(self.0) } } diff --git a/src/mpt.rs b/src/mpt.rs index 08c8c50c..a800aa8a 100644 --- a/src/mpt.rs +++ b/src/mpt.rs @@ -16,9 +16,8 @@ use crate::{ types::Proof, }; use halo2_proofs::{ - arithmetic::FieldExt, circuit::Layouter, - halo2curves::bn256::Fr, + halo2curves::{bn256::Fr, ff::FromUniformBytes}, plonk::{Challenge, ConstraintSystem, Error, Expression, VirtualCells}, }; use itertools::Itertools; @@ -177,7 +176,10 @@ impl MptCircuitConfig { ) } - pub fn lookup_exprs(&self, meta: &mut VirtualCells<'_, F>) -> [Expression; 8] { + pub fn lookup_exprs + Ord>( + &self, + meta: &mut VirtualCells<'_, F>, + ) -> [Expression; 8] { self.mpt_update.lookup().map(|q| q.run(meta)) } } diff --git a/src/types.rs b/src/types.rs index 47dbf8c6..b39b27a1 100644 --- a/src/types.rs +++ b/src/types.rs @@ -7,8 +7,11 @@ use crate::{ }, MPTProofType, }; -use ethers_core::types::{Address, U256}; -use halo2_proofs::{arithmetic::FieldExt, halo2curves::bn256::Fr}; +use ethers_core::{ + k256::elliptic_curve::PrimeField, + types::{Address, U256}, +}; +use halo2_proofs::halo2curves::bn256::Fr; use itertools::{EitherOrBoth, Itertools}; use num_bigint::BigUint; use num_traits::identities::Zero; diff --git a/src/types/storage.rs b/src/types/storage.rs index fa5b43e6..be841be3 100644 --- a/src/types/storage.rs +++ b/src/types/storage.rs @@ -5,8 +5,8 @@ use crate::{ types::{trie::TrieRows, HashDomain}, util::{domain_hash, fr, storage_key_hash, u256_from_hex, u256_hi_lo}, }; -use ethers_core::types::U256; -use halo2_proofs::{arithmetic::FieldExt, halo2curves::bn256::Fr}; +use ethers_core::{k256::elliptic_curve::PrimeField, types::U256}; +use halo2_proofs::halo2curves::bn256::Fr; #[derive(Clone, Debug)] pub enum StorageProof { diff --git a/src/util.rs b/src/util.rs index 33fb3360..49e82f51 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,8 +1,8 @@ use crate::{constraint_builder::Query, serde::HexBytes, types::HashDomain}; use ethers_core::types::{Address, U256}; use halo2_proofs::{ - arithmetic::{Field, FieldExt}, - halo2curves::{bn256::Fr, group::ff::PrimeField}, + arithmetic::Field, + halo2curves::{bn256::Fr, ff::FromUniformBytes, group::ff::PrimeField}, }; use hash_circuit::hash::Hashable; use num_bigint::BigUint; @@ -127,7 +127,10 @@ pub fn check_domain_consistency(before: HashDomain, after: HashDomain, direction } } -pub fn lagrange_polynomial(argument: Query, points: &[(Fr, Query)]) -> Query { +pub fn lagrange_polynomial + Ord>( + argument: Query, + points: &[(Fr, Query)], +) -> Query { let x_coordinates = points.iter().map(|p| p.0); let mut basis_polynomials = vec![]; for (i, xi) in x_coordinates.clone().enumerate() {