Skip to content

Commit

Permalink
chore: clean unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
junyu0312 committed Aug 11, 2023
1 parent f9ecf25 commit 50d8cb9
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 307 deletions.
197 changes: 0 additions & 197 deletions src/circuits/rtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::config::POW_TABLE_LIMIT;
use super::utils::bn_to_field;
use crate::circuits::bit_table::BitTableOp;
use crate::constant_from;
use crate::traits::circuits::bit_range_table::BitRangeTable;
use halo2_proofs::arithmetic::FieldExt;
use halo2_proofs::circuit::Layouter;
use halo2_proofs::plonk::ConstraintSystem;
Expand All @@ -26,15 +25,6 @@ pub struct RangeTableConfig<F: FieldExt> {
// [0 .. 256)
u8_col: TableColumn,

// [0 .. 16)
u4_col: TableColumn,
// {(left, right, res, op) | op(left, right) = res}, encoded by concat(left, right, res) << op
u4_bop_calc_col: TableColumn,
// {0, 1, 1 << 12, 1 << 24 ...}
u4_bop_col: TableColumn,
// {0 | 1 | 0b1000000000000000, 0 | 2 | 0b110000000000000 ...}
offset_len_bits_col: TableColumn,

/*
{
0 | 0,
Expand Down Expand Up @@ -76,11 +66,7 @@ impl<F: FieldExt> RangeTableConfig<F> {
common_range_col: cols.next().unwrap(),
u16_col: cols.next().unwrap(),
u8_col: cols.next().unwrap(),
u4_col: cols.next().unwrap(),
u4_bop_calc_col: cols.next().unwrap(),
u4_bop_col: cols.next().unwrap(),
pow_col: [cols.next().unwrap(), cols.next().unwrap()],
offset_len_bits_col: cols.next().unwrap(),
u8_bit_op_col: cols.next().unwrap(),
_mark: PhantomData,
}
Expand Down Expand Up @@ -135,41 +121,6 @@ impl<F: FieldExt> RangeTableConfig<F> {
});
}

pub fn configure_in_u4_range(
&self,
meta: &mut ConstraintSystem<F>,
key: &'static str,
expr: impl FnOnce(&mut VirtualCells<'_, F>) -> Expression<F>,
) {
meta.lookup(key, |meta| vec![(expr(meta), self.u4_col)]);
}

pub fn configure_in_u4_bop_set(
&self,
meta: &mut ConstraintSystem<F>,
key: &'static str,
expr: impl FnOnce(&mut VirtualCells<'_, F>) -> Expression<F>,
) {
meta.lookup(key, |meta| vec![(expr(meta), self.u4_bop_col)]);
}

pub fn configure_in_u4_bop_calc_set(
&self,
meta: &mut ConstraintSystem<F>,
key: &'static str,
expr: impl FnOnce(
&mut VirtualCells<'_, F>,
) -> (Expression<F>, Expression<F>, Expression<F>, Expression<F>),
) {
meta.lookup(key, |meta| {
let (l, r, res, op) = expr(meta);
vec![(
(l * constant_from!(1u64 << 8) + r * constant_from!(1u64 << 4) + res) * op,
self.u4_bop_calc_col,
)]
});
}

pub fn configure_in_pow_set(
&self,
meta: &mut ConstraintSystem<F>,
Expand All @@ -181,40 +132,12 @@ impl<F: FieldExt> RangeTableConfig<F> {
vec![(e0, self.pow_col[0]), (e1, self.pow_col[1])]
});
}

pub fn configure_in_offset_len_bits_set(
&self,
meta: &mut ConstraintSystem<F>,
key: &'static str,
expr: impl FnOnce(&mut VirtualCells<'_, F>) -> Expression<F>,
) {
meta.lookup(key, |meta| vec![(expr(meta), self.offset_len_bits_col)]);
}
}

pub struct RangeTableChip<F: FieldExt> {
config: RangeTableConfig<F>,
}

pub fn bits_of_offset_len(offset: u64, len: u64) -> u64 {
let bits = (1 << len) - 1;
bits << offset
}

pub fn offset_len_bits_encode(offset: u64, len: u64) -> u64 {
assert!(offset < 16);
assert!(len == 1 || len == 2 || len == 4 || len == 8);
(offset << 20) + (len << 16) + bits_of_offset_len(offset, len)
}

pub fn offset_len_bits_encode_expr<F: FieldExt>(
offset: Expression<F>,
len: Expression<F>,
bits: Expression<F>,
) -> Expression<F> {
offset * constant_from!(1u64 << 20) + len * constant_from!(1u64 << 16) + bits
}

impl<F: FieldExt> RangeTableChip<F> {
pub fn new(config: RangeTableConfig<F>) -> Self {
RangeTableChip { config }
Expand Down Expand Up @@ -266,81 +189,6 @@ impl<F: FieldExt> RangeTableChip<F> {
},
)?;

layouter.assign_table(
|| "u4 range table",
|mut table| {
for i in 0..(1 << 4) {
table.assign_cell(
|| "range table",
self.config.u4_col,
i,
|| Ok(F::from(i as u64)),
)?;
}
Ok(())
},
)?;

layouter.assign_table(
|| "u4 bop set table",
|mut table| {
table.assign_cell(
|| "range table",
self.config.u4_bop_col,
0,
|| Ok(F::from(0 as u64)),
)?;
let mut offset = 1;
for i in BitOp::iter() {
table.assign_cell(
|| "range table",
self.config.u4_bop_col,
offset,
|| {
Ok(bn_to_field::<F>(
&(BigUint::from(1u64) << (12 * i as usize)),
))
},
)?;
offset += 1;
}
Ok(())
},
)?;

layouter.assign_table(
|| "u4 bop calc table",
|mut table| {
table.assign_cell(
|| "range table",
self.config.u4_bop_calc_col,
0,
|| Ok(F::from(0 as u64)),
)?;
let mut offset = 1;
for i in BitOp::iter() {
for l in 0..1 << 4 {
for r in 0..1 << 4 {
let res = i.eval(l, r);
table.assign_cell(
|| "range table",
self.config.u4_bop_calc_col,
offset as usize,
|| {
Ok(F::from((l * 256 + r * 16 + res) as u64)
* bn_to_field::<F>(
&(BigUint::from(1u64) << (i as usize * 12)),
))
},
)?;
offset += 1;
}
}
}
Ok(())
},
)?;

layouter.assign_table(
|| "pow table",
|mut table| {
Expand Down Expand Up @@ -376,31 +224,6 @@ impl<F: FieldExt> RangeTableChip<F> {
},
)?;

layouter.assign_table(
|| "offset len bits table",
|mut table| {
table.assign_cell(
|| "range table",
self.config.offset_len_bits_col,
0,
|| Ok(F::from(0 as u64)),
)?;
let mut offset = 1;
for i in 0..8 {
for j in vec![1, 2, 4, 8] {
table.assign_cell(
|| "range table",
self.config.offset_len_bits_col,
offset as usize,
|| Ok(F::from(offset_len_bits_encode(i, j))),
)?;
offset += 1;
}
}
Ok(())
},
)?;

{
let mut offset = 0;

Expand Down Expand Up @@ -438,23 +261,3 @@ impl<F: FieldExt> RangeTableChip<F> {
Ok(())
}
}

impl<F: FieldExt> BitRangeTable<F> for RangeTableConfig<F> {
fn configure_in_u4_range(
&self,
meta: &mut ConstraintSystem<F>,
key: &'static str,
expr: impl FnOnce(&mut VirtualCells<'_, F>) -> Expression<F>,
) {
self.configure_in_u4_range(meta, key, expr);
}

fn configure_in_u8_range(
&self,
meta: &mut ConstraintSystem<F>,
key: &'static str,
expr: impl FnOnce(&mut VirtualCells<'_, F>) -> Expression<F>,
) {
self.configure_in_u8_range(meta, key, expr);
}
}
2 changes: 1 addition & 1 deletion src/circuits/test_circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<F: FieldExt> Circuit<F> for TestCircuit<F> {
let mut cols = [(); VAR_COLUMNS].map(|_| meta.advice_column()).into_iter();

let rtable =
RangeTableConfig::configure([0; 10].map(|_| meta.lookup_table_column()).into_iter());
RangeTableConfig::configure([0; 6].map(|_| meta.lookup_table_column()).into_iter());
let image_table = ImageTableConfig::configure(meta);
let mtable = MemoryTableConfig::configure(meta, &mut cols, &rtable, &image_table);
let jtable = JumpTableConfig::configure(meta, &mut cols);
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub mod circuits;
pub mod cli;
pub mod foreign;
pub mod runtime;
pub mod traits;

#[cfg(feature = "checksum")]
pub mod image_hasher;
Expand Down
106 changes: 0 additions & 106 deletions src/traits/circuits/bit_range_table.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/traits/circuits/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/traits/mod.rs

This file was deleted.

0 comments on commit 50d8cb9

Please sign in to comment.