Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove disallow dead code and remove it #103

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ fmt:
@cargo fmt

clippy:
@cargo clippy --all-features
@cargo clippy --all-features -- -D warnings
7 changes: 0 additions & 7 deletions src/constraint_builder/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ use halo2_proofs::{
poly::Rotation,
};

#[derive(Clone, Copy)]
pub enum ColumnType {
Advice,
Fixed,
Challenge,
}

#[derive(Clone)]
pub enum Query<F: Clone> {
Constant(F),
Expand Down
9 changes: 0 additions & 9 deletions src/gadgets/byte_representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -156,14 +155,6 @@ fn u128_to_big_endian(x: &u128) -> Vec<u8> {
x.to_be_bytes().to_vec()
}

fn address_to_big_endian(x: &Address) -> Vec<u8> {
x.0.to_vec()
}

fn h256_to_big_endian(x: &H256) -> Vec<u8> {
x.0.to_vec()
}

fn fr_to_big_endian(x: &Fr) -> Vec<u8> {
let mut bytes = x.to_bytes();
bytes.reverse();
Expand Down
9 changes: 3 additions & 6 deletions src/gadgets/key_bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -76,7 +73,6 @@ impl KeyBitConfig {
);

Self {
selector,
value,
index,
bit,
Expand Down Expand Up @@ -134,6 +130,7 @@ mod test {
rlc_randomness::RlcRandomness,
};
use super::*;
use crate::constraint_builder::SelectorColumn;
use halo2_proofs::{
circuit::{Layouter, SimpleFloorPlanner},
dev::MockProver,
Expand Down
9 changes: 1 addition & 8 deletions src/gadgets/mpt_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -902,13 +902,6 @@ fn new_right<F: FieldExt>(config: &MptUpdateConfig) -> Query<F> {
+ (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<F: FieldExt>(
cb: &mut ConstraintBuilder<F>,
segment: &OneHot<SegmentType>,
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(dead_code)]
#![allow(clippy::too_many_arguments)]
#![deny(unsafe_code)]

Expand Down
31 changes: 0 additions & 31 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -196,7 +195,6 @@ impl From<AccountData> 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!!!
Expand Down Expand Up @@ -957,39 +955,10 @@ fn check_hash_traces_new(traces: &[(bool, HashDomain, Fr, Fr, Fr, bool, bool)])
}
}

fn bits(x: usize, len: usize) -> Vec<bool> {
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()
Expand Down
17 changes: 1 addition & 16 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
(
Expand Down Expand Up @@ -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<u8> {
let mut bytes = [0; 32];
x.to_big_endian(&mut bytes);
Expand Down
Loading