Skip to content

Commit 5bf60e0

Browse files
decompose_running_sum: Move range_check gate outside the helper.
1 parent c215aa4 commit 5bf60e0

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-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

@@ -70,6 +70,17 @@ impl<FixedPoints: super::FixedPoints<pallas::Affine>> Config<FixedPoints> {
7070
let q_running_sum = meta.selector();
7171
let running_sum_config = RunningSumConfig::configure(meta, q_running_sum, window);
7272

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

halo2_gadgets/src/utilities/decompose_running_sum.rs

+10-23
Original file line numberDiff line numberDiff line change
@@ -25,13 +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;
3532
use pasta_curves::arithmetic::FieldExt;
3633
use std::marker::PhantomData;
3734

@@ -45,7 +42,7 @@ pub struct RunningSum<F: FieldExt + PrimeFieldBits, const WINDOW_NUM_BITS: usize
4542

4643
impl<F: FieldExt + PrimeFieldBits, const WINDOW_NUM_BITS: usize> RunningSum<F, WINDOW_NUM_BITS> {
4744
/// Returns windows derived from the intermediate values of the running sum.
48-
pub(crate) fn windows(&self) -> Vec<Option<F>> {
45+
pub(crate) fn windows(&self) -> Vec<Value<F>> {
4946
let mut windows = Vec::new();
5047
// k_i = z_i - (2^K * z_{i+1})
5148
for i in 0..(self.zs.len() - 1) {
@@ -88,10 +85,6 @@ impl<F: FieldExt + PrimeFieldBits, const WINDOW_NUM_BITS: usize>
8885

8986
/// `perm` MUST include the advice column `z`.
9087
///
91-
/// # Panics
92-
///
93-
/// Panics if WINDOW_NUM_BITS > 3.
94-
///
9588
/// # Side-effects
9689
///
9790
/// `z` will be equality-enabled.
@@ -100,25 +93,19 @@ impl<F: FieldExt + PrimeFieldBits, const WINDOW_NUM_BITS: usize>
10093
q_range_check: Selector,
10194
z: Column<Advice>,
10295
) -> Self {
103-
assert!(WINDOW_NUM_BITS <= 3);
104-
10596
meta.enable_equality(z);
10697

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

124111
/// Expression for a window

0 commit comments

Comments
 (0)