From ef0656a79d97cf7b31d012a31d5075ae024fd2fe Mon Sep 17 00:00:00 2001 From: z2trillion Date: Tue, 14 Nov 2023 08:06:12 +0800 Subject: [PATCH] Remove disallow dead code and remove it (#103) * deny warnings for clippy * don't allow dead code * fix clippy --------- Co-authored-by: Mason Liang --- Makefile | 2 +- src/constraint_builder/query.rs | 7 ------- src/gadgets/byte_representation.rs | 9 --------- src/gadgets/key_bit.rs | 9 +++------ src/gadgets/mpt_update.rs | 9 +-------- src/lib.rs | 1 - src/types.rs | 31 ------------------------------ src/util.rs | 17 +--------------- 8 files changed, 6 insertions(+), 79 deletions(-) diff --git a/Makefile b/Makefile index beb636f4..cf38b795 100644 --- a/Makefile +++ b/Makefile @@ -5,4 +5,4 @@ fmt: @cargo fmt clippy: - @cargo clippy --all-features + @cargo clippy --all-features -- -D warnings diff --git a/src/constraint_builder/query.rs b/src/constraint_builder/query.rs index c7b24c4c..11437fe1 100644 --- a/src/constraint_builder/query.rs +++ b/src/constraint_builder/query.rs @@ -6,13 +6,6 @@ use halo2_proofs::{ poly::Rotation, }; -#[derive(Clone, Copy)] -pub enum ColumnType { - Advice, - Fixed, - Challenge, -} - #[derive(Clone)] pub enum Query { Constant(F), diff --git a/src/gadgets/byte_representation.rs b/src/gadgets/byte_representation.rs index aa8b2904..f7ff1047 100644 --- a/src/gadgets/byte_representation.rs +++ b/src/gadgets/byte_representation.rs @@ -2,7 +2,6 @@ use super::{byte_bit::RangeCheck256Lookup, is_zero::IsZeroGadget, rlc_randomness use crate::constraint_builder::{ AdviceColumn, ConstraintBuilder, Query, SecondPhaseAdviceColumn, SelectorColumn, }; -use ethers_core::types::{Address, H256}; use halo2_proofs::{ arithmetic::FieldExt, circuit::{Region, Value}, @@ -156,14 +155,6 @@ fn u128_to_big_endian(x: &u128) -> Vec { x.to_be_bytes().to_vec() } -fn address_to_big_endian(x: &Address) -> Vec { - x.0.to_vec() -} - -fn h256_to_big_endian(x: &H256) -> Vec { - x.0.to_vec() -} - fn fr_to_big_endian(x: &Fr) -> Vec { let mut bytes = x.to_bytes(); bytes.reverse(); diff --git a/src/gadgets/key_bit.rs b/src/gadgets/key_bit.rs index 5d4b2581..abeece53 100644 --- a/src/gadgets/key_bit.rs +++ b/src/gadgets/key_bit.rs @@ -2,7 +2,7 @@ use super::{ byte_bit::{ByteBitLookup, RangeCheck256Lookup, RangeCheck8Lookup}, canonical_representation::CanonicalRepresentationLookup, }; -use crate::constraint_builder::{AdviceColumn, ConstraintBuilder, Query, SelectorColumn}; +use crate::constraint_builder::{AdviceColumn, ConstraintBuilder, Query}; use halo2_proofs::{ arithmetic::FieldExt, circuit::Region, halo2curves::bn256::Fr, plonk::ConstraintSystem, }; @@ -13,8 +13,6 @@ pub trait KeyBitLookup { #[derive(Clone)] pub struct KeyBitConfig { - selector: SelectorColumn, // always enabled selector for constraints we want always enabled. - // Lookup columns value: AdviceColumn, // We're proving value.bit(i) = bit in this gadget index: AdviceColumn, // 0 <= index < 256 @@ -35,8 +33,7 @@ impl KeyBitConfig { range_check_256: &impl RangeCheck256Lookup, byte_bit: &impl ByteBitLookup, ) -> Self { - let ([selector], [], [value, index, bit, index_div_8, index_mod_8, byte]) = - cb.build_columns(cs); + let ([], [], [value, index, bit, index_div_8, index_mod_8, byte]) = cb.build_columns(cs); cb.add_lookup( "0 <= index < 256", @@ -76,7 +73,6 @@ impl KeyBitConfig { ); Self { - selector, value, index, bit, @@ -134,6 +130,7 @@ mod test { rlc_randomness::RlcRandomness, }; use super::*; + use crate::constraint_builder::SelectorColumn; use halo2_proofs::{ circuit::{Layouter, SimpleFloorPlanner}, dev::MockProver, diff --git a/src/gadgets/mpt_update.rs b/src/gadgets/mpt_update.rs index cedd72c4..268da6cc 100644 --- a/src/gadgets/mpt_update.rs +++ b/src/gadgets/mpt_update.rs @@ -31,7 +31,7 @@ use ethers_core::types::Address; use halo2_proofs::{ arithmetic::{Field, FieldExt}, circuit::{Region, Value}, - halo2curves::{bn256::Fr, group::ff::PrimeField}, + halo2curves::bn256::Fr, plonk::ConstraintSystem, }; use itertools::izip; @@ -902,13 +902,6 @@ fn new_right(config: &MptUpdateConfig) -> Query { + (Query::one() - config.direction.current()) * config.sibling.current() } -fn address_to_fr(a: Address) -> Fr { - let mut bytes = [0u8; 32]; - bytes[32 - 20..].copy_from_slice(a.as_bytes()); - bytes.reverse(); - Fr::from_repr(bytes).unwrap() -} - fn configure_segment_transitions( cb: &mut ConstraintBuilder, segment: &OneHot, diff --git a/src/lib.rs b/src/lib.rs index aa76d409..4c353b6b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -#![allow(dead_code)] #![allow(clippy::too_many_arguments)] #![deny(unsafe_code)] diff --git a/src/types.rs b/src/types.rs index 47dbf8c6..0c9d3fca 100644 --- a/src/types.rs +++ b/src/types.rs @@ -185,7 +185,6 @@ pub struct Proof { pub struct EthAccount { pub nonce: u64, pub code_size: u64, - poseidon_codehash: Fr, pub balance: Fr, pub keccak_codehash: U256, pub storage_root: Fr, @@ -196,7 +195,6 @@ impl From for EthAccount { Self { nonce: account_data.nonce, code_size: account_data.code_size, - poseidon_codehash: fr_from_biguint(&account_data.poseidon_code_hash), balance: fr_from_biguint(&account_data.balance), keccak_codehash: u256_from_biguint(&account_data.code_hash), storage_root: Fr::zero(), // TODO: fixmeeee!!! @@ -957,39 +955,10 @@ fn check_hash_traces_new(traces: &[(bool, HashDomain, Fr, Fr, Fr, bool, bool)]) } } -fn bits(x: usize, len: usize) -> Vec { - let mut bits = vec![]; - let mut x = x; - while x != 0 { - bits.push(x % 2 == 1); - x /= 2; - } - bits.resize(len, false); - bits.reverse(); - bits -} - fn fr(x: HexBytes<32>) -> Fr { Fr::from_bytes(&x.0).unwrap() } -fn split_word(x: U256) -> (Fr, Fr) { - let mut bytes = [0; 32]; - x.to_big_endian(&mut bytes); - let high_bytes: [u8; 16] = bytes[..16].try_into().unwrap(); - let low_bytes: [u8; 16] = bytes[16..].try_into().unwrap(); - - let high = Fr::from_u128(u128::from_be_bytes(high_bytes)); - let low = Fr::from_u128(u128::from_be_bytes(low_bytes)); - (high, low) - - // TODO: what's wrong with this? - // let [limb_0, limb_1, limb_2, limb_3] = key.0; - // let key_high = Fr::from_u128(u128::from(limb_2) + u128::from(limb_3) << 64); - // let key_low = Fr::from_u128(u128::from(limb_0) + u128::from(limb_1) << 64); - // hash(key_high, key_low) -} - fn big_uint_to_fr(i: &BigUint) -> Fr { i.to_u64_digits() .iter() diff --git a/src/util.rs b/src/util.rs index 33fb3360..9a366b38 100644 --- a/src/util.rs +++ b/src/util.rs @@ -2,7 +2,7 @@ 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}, + halo2curves::bn256::Fr, }; use hash_circuit::hash::Hashable; use num_bigint::BigUint; @@ -50,15 +50,6 @@ pub(crate) fn split_word(x: U256) -> (Fr, Fr) { // hash(key_high, key_low) } -pub(crate) fn hi_lo(x: &BigUint) -> (Fr, Fr) { - let mut u64_digits = x.to_u64_digits(); - u64_digits.resize(4, 0); - ( - Fr::from_u128((u128::from(u64_digits[3]) << 64) + u128::from(u64_digits[2])), - Fr::from_u128((u128::from(u64_digits[1]) << 64) + u128::from(u64_digits[0])), - ) -} - pub(crate) fn u256_hi_lo(x: &U256) -> (u128, u128) { let u64_digits = x.0; ( @@ -86,12 +77,6 @@ pub fn u256_from_biguint(x: &BigUint) -> U256 { U256::from_big_endian(&x.to_bytes_be()) } -pub fn u256_to_fr(x: U256) -> Fr { - let mut bytes = [0u8; 32]; - x.to_little_endian(&mut bytes); - Fr::from_repr(bytes).unwrap() -} - pub fn u256_to_big_endian(x: &U256) -> Vec { let mut bytes = [0; 32]; x.to_big_endian(&mut bytes);