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

Fix: assert uses of size hint in release mode #13

Merged
merged 3 commits into from
Apr 15, 2023
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
22 changes: 10 additions & 12 deletions halo2-base/src/gates/flex_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub trait GateInstructions<F: ScalarField> {
return ctx.assign_region_last([start], []);
}
let (len, hi) = a.size_hint();
debug_assert_eq!(Some(len), hi);
assert_eq!(Some(len), hi);

let mut sum = *start.value();
let cells = iter::once(start).chain(a.flat_map(|a| {
Expand Down Expand Up @@ -320,7 +320,7 @@ pub trait GateInstructions<F: ScalarField> {
return Box::new(iter::once(ctx.assign_region_last([start], [])));
}
let (len, hi) = a.size_hint();
debug_assert_eq!(Some(len), hi);
assert_eq!(Some(len), hi);

let mut sum = *start.value();
let cells = iter::once(start).chain(a.flat_map(|a| {
Expand Down Expand Up @@ -532,7 +532,7 @@ pub trait GateInstructions<F: ScalarField> {
let mut sum = F::zero();
let a = a.into_iter();
let (len, hi) = a.size_hint();
debug_assert_eq!(Some(len), hi);
assert_eq!(Some(len), hi);

let cells = std::iter::once(Constant(F::zero())).chain(
a.zip(indicator.into_iter()).flat_map(|(a, ind)| {
Expand All @@ -555,7 +555,7 @@ pub trait GateInstructions<F: ScalarField> {
{
let cells = cells.into_iter();
let (len, hi) = cells.size_hint();
debug_assert_eq!(Some(len), hi);
assert_eq!(Some(len), hi);

let ind = self.idx_to_indicator(ctx, idx, len);
self.select_by_indicator(ctx, cells, ind)
Expand Down Expand Up @@ -706,15 +706,14 @@ impl<F: ScalarField> GateChip<F> {
[a, b, Witness(sum)]
}));

let gate_offsets = if ctx.witness_gen_only() {
vec![]
if ctx.witness_gen_only() {
ctx.assign_region(cells, vec![]);
} else {
let (lo, hi) = cells.size_hint();
debug_assert_eq!(Some(lo), hi);
let cells = cells.collect::<Vec<_>>();
let lo = cells.len();
let len = lo / 3;
(0..len).map(|i| 3 * i as isize).collect()
ctx.assign_region(cells, (0..len).map(|i| 3 * i as isize));
};
ctx.assign_region(cells, gate_offsets);
b_starts_with_one
}
}
Expand Down Expand Up @@ -899,8 +898,7 @@ impl<F: ScalarField> GateInstructions<F> for GateChip<F> {
.iter()
.flat_map(|byte| (0..8).map(|i| (*byte as u64 >> i) & 1))
.map(|x| Witness(F::from(x)))
.take(range_bits)
.collect::<Vec<_>>();
.take(range_bits);

let mut bit_cells = Vec::with_capacity(range_bits);
let row_offset = ctx.advice.len();
Expand Down