Skip to content

Commit fd576d5

Browse files
authored
Remove tracking of range constraint multiplicities (#2356)
This is not necessary anymore since #2319: We previously had a multiplicity witgen pass only for range constraints via lookups. Now we have it for all phantom lookups, which includes range constraints via lookups.
1 parent b63d963 commit fd576d5

File tree

3 files changed

+26
-87
lines changed

3 files changed

+26
-87
lines changed

executor/src/witgen/global_constraints.rs

+4-70
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use crate::Identity;
1818
use super::affine_expression::AlgebraicVariable;
1919
use super::evaluators::partial_expression_evaluator::PartialExpressionEvaluator;
2020
use super::evaluators::symbolic_evaluator::SymbolicEvaluator;
21-
use super::machines::Connection;
2221
use super::range_constraints::RangeConstraint;
2322
use super::util::try_to_simple_poly;
2423
use super::{Constraint, FixedData};
@@ -96,20 +95,10 @@ where
9695
}
9796
}
9897

99-
#[derive(Clone, Debug, PartialEq, Eq)]
100-
/// The RHS of a range constraint of the form `[ w ] in [ RANGE ]`, including the multiplicity column.
101-
pub struct PhantomRangeConstraintTarget {
102-
pub column: PolyID,
103-
pub multiplicity_column: PolyID,
104-
}
105-
10698
#[derive(Clone)]
10799
pub struct GlobalConstraints<T: FieldElement> {
108100
pub witness_constraints: WitnessColumnMap<Option<RangeConstraint<T>>>,
109101
pub fixed_constraints: FixedColumnMap<Option<RangeConstraint<T>>>,
110-
/// For range constraints which are enforced via phantom lookups, this maps the
111-
/// constrained column to the target and multiplicity column.
112-
pub phantom_range_constraints: BTreeMap<PolyID, PhantomRangeConstraintTarget>,
113102
}
114103

115104
impl<T: FieldElement> RangeConstraintSet<&AlgebraicReference, T> for GlobalConstraints<T> {
@@ -153,12 +142,10 @@ pub fn set_global_constraints<'a, T: FieldElement>(
153142

154143
let mut retained_identities = vec![];
155144
let mut removed_identities = vec![];
156-
let mut range_constraint_multiplicities = BTreeMap::new();
157145
for identity in identities.into_iter() {
158146
let remove = propagate_constraints(
159147
&fixed_data.intermediate_definitions,
160148
&mut known_constraints,
161-
&mut range_constraint_multiplicities,
162149
identity,
163150
&full_span,
164151
);
@@ -183,17 +170,6 @@ pub fn set_global_constraints<'a, T: FieldElement>(
183170
log::debug!(" {id}");
184171
}
185172

186-
if !range_constraint_multiplicities.is_empty() {
187-
log::debug!("Recorded the following range constraint multiplicity columns:");
188-
}
189-
for (poly_id, target) in &range_constraint_multiplicities {
190-
log::debug!(
191-
" {} -> {}",
192-
fixed_data.column_name(poly_id),
193-
fixed_data.column_name(&target.multiplicity_column)
194-
);
195-
}
196-
197173
let mut witness_constraints: WitnessColumnMap<Option<RangeConstraint<T>>> =
198174
fixed_data.witness_map_with(None);
199175
for (poly_id, con) in known_constraints {
@@ -211,7 +187,6 @@ pub fn set_global_constraints<'a, T: FieldElement>(
211187
let global_constraints = GlobalConstraints {
212188
witness_constraints,
213189
fixed_constraints,
214-
phantom_range_constraints: range_constraint_multiplicities,
215190
};
216191

217192
(
@@ -260,7 +235,6 @@ fn add_constraint<T: FieldElement>(
260235
fn propagate_constraints<T: FieldElement>(
261236
intermediate_definitions: &BTreeMap<AlgebraicReferenceThin, AlgebraicExpression<T>>,
262237
known_constraints: &mut BTreeMap<PolyID, RangeConstraint<T>>,
263-
range_constraint_multiplicities: &mut BTreeMap<PolyID, PhantomRangeConstraintTarget>,
264238
identity: &Identity<T>,
265239
full_span: &BTreeSet<PolyID>,
266240
) -> bool {
@@ -303,21 +277,14 @@ fn propagate_constraints<T: FieldElement>(
303277
// In that case, we can remove the lookup, because its only function is to enforce
304278
// the range constraint.
305279
if right.expressions.len() == 1 {
306-
if let (Some(left_ref), Some(right_ref)) = (
280+
if let (Some(_), Some(right_ref)) = (
281+
// The range constraint has been transferred from right to left
282+
// by the above code iff. both expressions can be converted to
283+
// simple polynomials.
307284
try_to_simple_poly(&left.expressions[0]),
308285
try_to_simple_poly(&right.expressions[0]),
309286
) {
310287
if full_span.contains(&right_ref.poly_id) {
311-
let connection = Connection::try_from(identity).unwrap();
312-
if let Some(multiplicity) = connection.multiplicity_column {
313-
let target = PhantomRangeConstraintTarget {
314-
column: right_ref.poly_id,
315-
multiplicity_column: multiplicity,
316-
};
317-
assert!(range_constraint_multiplicities
318-
.insert(left_ref.poly_id, target)
319-
.is_none());
320-
}
321288
return true;
322289
}
323290
}
@@ -557,12 +524,10 @@ namespace Global(2**20);
557524
.into_iter()
558525
.collect()
559526
);
560-
let mut range_constraint_multiplicities = BTreeMap::new();
561527
for identity in &analyzed.identities {
562528
propagate_constraints(
563529
&BTreeMap::new(),
564530
&mut known_constraints,
565-
&mut range_constraint_multiplicities,
566531
identity,
567532
&full_span,
568533
);
@@ -649,12 +614,10 @@ namespace Global(2**20);
649614
.into_iter()
650615
.collect()
651616
);
652-
let mut range_constraint_multiplicities = BTreeMap::new();
653617
for identity in &analyzed.identities {
654618
propagate_constraints(
655619
&BTreeMap::new(),
656620
&mut known_constraints,
657-
&mut range_constraint_multiplicities,
658621
identity,
659622
&full_span,
660623
);
@@ -680,33 +643,6 @@ namespace Global(2**20);
680643
.into_iter()
681644
.collect::<BTreeMap<_, _>>()
682645
);
683-
assert_eq!(
684-
range_constraint_multiplicities,
685-
vec![
686-
(
687-
// Global.B
688-
witness_poly_id(3),
689-
PhantomRangeConstraintTarget {
690-
// Global.BYTE
691-
column: constant_poly_id(0),
692-
// Global.byte_multiplicities
693-
multiplicity_column: witness_poly_id(0)
694-
}
695-
),
696-
(
697-
// Global.D
698-
witness_poly_id(5),
699-
PhantomRangeConstraintTarget {
700-
// Global.BYTE
701-
column: constant_poly_id(0),
702-
// Global.byte_multiplicities
703-
multiplicity_column: witness_poly_id(0)
704-
}
705-
),
706-
]
707-
.into_iter()
708-
.collect::<BTreeMap<_, _>>()
709-
)
710646
}
711647

712648
#[test]
@@ -726,12 +662,10 @@ namespace Global(1024);
726662
let mut known_constraints = vec![(constant_poly_id(0), RangeConstraint::from_max_bit(7))]
727663
.into_iter()
728664
.collect();
729-
let mut range_constraint_multiplicities = BTreeMap::new();
730665
assert_eq!(analyzed.identities.len(), 1);
731666
let removed = propagate_constraints(
732667
&BTreeMap::new(),
733668
&mut known_constraints,
734-
&mut range_constraint_multiplicities,
735669
analyzed.identities.first().unwrap(),
736670
&Default::default(),
737671
);

executor/src/witgen/machines/machine_extractor.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,7 @@ impl<'a, T: FieldElement> MachineExtractor<'a, T> {
7979
let mut machines: Vec<KnownMachine<T>> = vec![];
8080

8181
let mut publics = PublicsTracker::default();
82-
let range_constraint_multiplicities = self
83-
.fixed
84-
.global_range_constraints
85-
.phantom_range_constraints
86-
.values()
87-
.map(|prc| prc.multiplicity_column)
88-
.collect::<HashSet<_>>();
89-
let mut remaining_witnesses = current_stage_witnesses
90-
.difference(&range_constraint_multiplicities)
91-
.cloned()
92-
.collect::<HashSet<_>>();
82+
let mut remaining_witnesses = current_stage_witnesses.clone();
9383
let mut base_identities = identities.clone();
9484
let mut extracted_prover_functions = HashSet::new();
9585
let mut id_counter = 0;
@@ -222,24 +212,40 @@ impl<'a, T: FieldElement> MachineExtractor<'a, T> {
222212
.filter_map(|(i, &pf)| (!extracted_prover_functions.contains(&i)).then_some(pf))
223213
.collect::<Vec<_>>();
224214

215+
// In the remaining witness, we might still have some multiplicity columns
216+
// of fixed lookups, because they are not referenced by any "normal"
217+
// first-stage identities. As the main machine should not be on the
218+
// receiving end of a lookup, we remove any multiplicity columns here.
219+
// Note that we don't use the passed identities, because we want to
220+
// include removed range constraints.
221+
let multiplicity_columns = self
222+
.fixed
223+
.analyzed
224+
.identities
225+
.iter()
226+
.filter_map(|identity| Connection::try_from(identity).ok()?.multiplicity_column)
227+
.collect::<HashSet<_>>();
228+
let main_witnesses = remaining_witnesses
229+
.difference(&multiplicity_columns)
230+
.cloned()
231+
.collect::<HashSet<_>>();
232+
225233
log::trace!(
226234
"\nThe base machine contains the following witnesses:\n{}\n identities:\n{}\n and prover functions:\n{}",
227-
remaining_witnesses
235+
main_witnesses
228236
.iter()
229237
.map(|s| self.fixed.column_name(s))
230238
.sorted()
231239
.format(", "),
232-
base_identities
233-
.iter()
234-
.format("\n"),
240+
base_identities.iter().format("\n"),
235241
base_prover_functions.iter().format("\n")
236242
);
237243

238244
let base_parts = MachineParts::new(
239245
self.fixed,
240246
Default::default(),
241247
base_identities,
242-
remaining_witnesses,
248+
main_witnesses,
243249
base_prover_functions,
244250
);
245251

executor/src/witgen/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ impl<'a, T: FieldElement> FixedData<'a, T> {
379379
let global_range_constraints = GlobalConstraints {
380380
witness_constraints: WitnessColumnMap::new(None, witness_cols.len()),
381381
fixed_constraints: FixedColumnMap::new(None, fixed_cols.len()),
382-
phantom_range_constraints: BTreeMap::new(),
383382
};
384383

385384
FixedData {

0 commit comments

Comments
 (0)