Skip to content
Merged
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
19 changes: 19 additions & 0 deletions halo2_gadgets/src/utilities/lookup_range_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
.map(|inner| Self {
inner,
num_bits,
_phantom: PhantomData::default(),

Check warning on line 56 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

use of `default` to create a unit struct

warning: use of `default` to create a unit struct --> halo2_gadgets/src/utilities/lookup_range_check.rs:56:27 | 56 | _phantom: PhantomData::default(), | ^^^^^^^^^^^----------- | | | help: remove this call to `default` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_constructed_unit_structs
})
}
}
Expand Down Expand Up @@ -129,7 +129,7 @@
strict: bool,
) -> Result<RunningSum<F>, Error> {
layouter.assign_region(
|| format!("{:?} words range check", num_words),

Check warning on line 132 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> halo2_gadgets/src/utilities/lookup_range_check.rs:132:16 | 132 | || format!("{:?} words range check", num_words), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 132 - || format!("{:?} words range check", num_words), 132 + || format!("{num_words:?} words range check"), |

Check warning on line 132 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> halo2_gadgets/src/utilities/lookup_range_check.rs:132:16 | 132 | || format!("{:?} words range check", num_words), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 132 - || format!("{:?} words range check", num_words), 132 + || format!("{num_words:?} words range check"), |
|mut region| {
// Copy `element` and initialize running sum `z_0 = element` to decompose it.
let z_0 =
Expand Down Expand Up @@ -253,7 +253,7 @@
) -> Result<(), Error> {
assert!(num_bits < K);
layouter.assign_region(
|| format!("Range check {:?} bits", num_bits),

Check warning on line 256 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> halo2_gadgets/src/utilities/lookup_range_check.rs:256:16 | 256 | || format!("Range check {:?} bits", num_bits), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 256 - || format!("Range check {:?} bits", num_bits), 256 + || format!("Range check {num_bits:?} bits"), |

Check warning on line 256 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> halo2_gadgets/src/utilities/lookup_range_check.rs:256:16 | 256 | || format!("Range check {:?} bits", num_bits), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 256 - || format!("Range check {:?} bits", num_bits), 256 + || format!("Range check {num_bits:?} bits"), |
|mut region| {
// Copy `element` to use in the k-bit lookup.
let element =
Expand All @@ -276,7 +276,7 @@
) -> Result<AssignedCell<F, F>, Error> {
assert!(num_bits <= K);
layouter.assign_region(
|| format!("Range check {:?} bits", num_bits),

Check warning on line 279 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> halo2_gadgets/src/utilities/lookup_range_check.rs:279:16 | 279 | || format!("Range check {:?} bits", num_bits), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 279 - || format!("Range check {:?} bits", num_bits), 279 + || format!("Range check {num_bits:?} bits"), |

Check warning on line 279 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> halo2_gadgets/src/utilities/lookup_range_check.rs:279:16 | 279 | || format!("Range check {:?} bits", num_bits), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 279 - || format!("Range check {:?} bits", num_bits), 279 + || format!("Range check {num_bits:?} bits"), |
|mut region| {
// Witness `element` to use in the k-bit lookup.
let element = region.assign_advice(
Expand Down Expand Up @@ -471,7 +471,7 @@
let shifted = element.value().into_field() * F::from(1 << (K - num_bits));

region.assign_advice(
|| format!("element * 2^({}-{})", K, num_bits),

Check warning on line 474 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> halo2_gadgets/src/utilities/lookup_range_check.rs:474:16 | 474 | || format!("element * 2^({}-{})", K, num_bits), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 474 - || format!("element * 2^({}-{})", K, num_bits), 474 + || format!("element * 2^({K}-{num_bits})"), |

Check warning on line 474 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> halo2_gadgets/src/utilities/lookup_range_check.rs:474:16 | 474 | || format!("element * 2^({}-{})", K, num_bits), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 474 - || format!("element * 2^({}-{})", K, num_bits), 474 + || format!("element * 2^({K}-{num_bits})"), |
self.running_sum,
1,
|| shifted,
Expand All @@ -480,7 +480,7 @@
// Assign 2^{-num_bits} from a fixed column.
let inv_two_pow_s = F::from(1 << num_bits).invert().unwrap();
region.assign_advice_from_constant(
|| format!("2^(-{})", num_bits),

Check warning on line 483 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> halo2_gadgets/src/utilities/lookup_range_check.rs:483:16 | 483 | || format!("2^(-{})", num_bits), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 483 - || format!("2^(-{})", num_bits), 483 + || format!("2^(-{num_bits})"), |

Check warning on line 483 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> halo2_gadgets/src/utilities/lookup_range_check.rs:483:16 | 483 | || format!("2^(-{})", num_bits), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 483 - || format!("2^(-{})", num_bits), 483 + || format!("2^(-{num_bits})"), |
self.running_sum,
2,
inv_two_pow_s,
Expand Down Expand Up @@ -665,6 +665,25 @@
/// | 1 | X(S\[1\]) | Y(S\[1\]) | 5 |
/// | ... | ... | ... | 5 |
/// | 2^5-1 | X(S\[2^5-1\]) | Y(S\[2^5-1\]) | 5 |
///
/// # Rationale
///
/// While it is possible to avoid duplicated rows by using tags and storing them in an advice
/// column, as done in the spread table of the SHA-256 gadget, applying this technique to the
/// range check lookup table would significantly increase complexity.
///
/// Indeed, in the range check lookup tables, tags are currently computed on the fly and are not
/// stored in advice columns. Adopting the no duplicated rows approach would require modifying
/// the lookup chip to include an advice column for tags and updating the public API accordingly.
/// This tag column would need to be populated each time a range check lookup is performed.
/// Additionally, the current lookup range check implementation involves combinations of
/// multiple lookups, further complicating this approach.
///
/// The performance benefit would be minimal: our current table has 1072 rows (2^10 + 2^4 + 2^5),
/// and switching to the no duplicated-rows method would reduce it only slightly to 1024 rows
/// (2^10), while adding more logic and infrastructure to manage the tags.
///
/// Therefore, we retain the simpler duplicated-rows format for clarity and maintainability.
fn load(
&self,
generator_table_config: &GeneratorTableConfig,
Expand Down
Loading