Skip to content

Commit c334934

Browse files
decompose_running_sum: Move range_check gate outside the helper.
1 parent 6982de1 commit c334934

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

halo2_gadgets/src/ecc/chip/mul_fixed.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::{
22
add, add_incomplete, EccBaseFieldElemFixed, EccScalarFixed, EccScalarFixedShort, FixedPoint,
33
NonIdentityEccPoint, FIXED_BASE_WINDOW_SIZE, H,
44
};
5-
use crate::utilities::decompose_running_sum::RunningSumConfig;
5+
use crate::utilities::{decompose_running_sum::RunningSumConfig, range_check};
66

77
use std::marker::PhantomData;
88

@@ -67,6 +67,17 @@ impl<FixedPoints: super::FixedPoints<pallas::Affine>> Config<FixedPoints> {
6767
let q_running_sum = meta.selector();
6868
let running_sum_config = RunningSumConfig::configure(meta, q_running_sum, window);
6969

70+
// Range-check each window in the running sum decomposition.
71+
meta.create_gate("range check", |meta| {
72+
let q_range_check = meta.query_selector(running_sum_config.q_range_check());
73+
let word = running_sum_config.window_expr(meta);
74+
75+
Constraints::with_selector(
76+
q_range_check,
77+
Some(range_check(word, 1 << FIXED_BASE_WINDOW_SIZE)),
78+
)
79+
});
80+
7081
let config = Self {
7182
running_sum_config,
7283
lagrange_coeffs,

halo2_gadgets/src/utilities/decompose_running_sum.rs

+9-23
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@
2525
use ff::PrimeFieldBits;
2626
use halo2_proofs::{
2727
circuit::{AssignedCell, Region, Value},
28-
plonk::{
29-
Advice, Column, ConstraintSystem, Constraints, Error, Expression, Selector, VirtualCells,
30-
},
28+
plonk::{Advice, Column, ConstraintSystem, Error, Expression, Selector, VirtualCells},
3129
poly::Rotation,
3230
};
3331

34-
use super::range_check;
35-
3632
use std::marker::PhantomData;
3733

3834
/// The running sum $[z_0, ..., z_W]$. If created in strict mode, $z_W = 0$.
@@ -86,10 +82,6 @@ impl<F: PrimeFieldBits, const WINDOW_NUM_BITS: usize> RunningSumConfig<F, WINDOW
8682

8783
/// `perm` MUST include the advice column `z`.
8884
///
89-
/// # Panics
90-
///
91-
/// Panics if WINDOW_NUM_BITS > 3.
92-
///
9385
/// # Side-effects
9486
///
9587
/// `z` will be equality-enabled.
@@ -98,25 +90,19 @@ impl<F: PrimeFieldBits, const WINDOW_NUM_BITS: usize> RunningSumConfig<F, WINDOW
9890
q_range_check: Selector,
9991
z: Column<Advice>,
10092
) -> Self {
101-
assert!(WINDOW_NUM_BITS <= 3);
102-
10393
meta.enable_equality(z);
10494

105-
let config = Self {
95+
// It is the caller's responsibility to enforce the range-check using q_range_check.
96+
// The selector q_range_check will be enabled on every row of the decomposition,
97+
// but is not tied to a gate or expression within this helper.
98+
//
99+
// This is to support different range check methods (e.g. expression, lookup).
100+
101+
Self {
106102
q_range_check,
107103
z,
108104
_marker: PhantomData,
109-
};
110-
111-
// https://p.z.cash/halo2-0.1:decompose-short-range
112-
meta.create_gate("range check", |meta| {
113-
let q_range_check = meta.query_selector(config.q_range_check);
114-
let word = config.window_expr(meta);
115-
116-
Constraints::with_selector(q_range_check, Some(range_check(word, 1 << WINDOW_NUM_BITS)))
117-
});
118-
119-
config
105+
}
120106
}
121107

122108
/// Expression for a window

0 commit comments

Comments
 (0)