Skip to content

Commit 3fc2927

Browse files
committed
halfway change range constraints.
1 parent 85ebaea commit 3fc2927

File tree

6 files changed

+34
-22
lines changed

6 files changed

+34
-22
lines changed

executor/src/witgen/data_structures/mutable_state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ impl<'a, T: FieldElement, Q: QueryCallback<T>> MutableState<'a, T, Q> {
5555
&self,
5656
identity_id: u64,
5757
known_inputs: &BitVec,
58-
range_constraints: &[Option<RangeConstraint<T>>],
59-
) -> Option<Vec<Option<RangeConstraint<T>>>> {
58+
range_constraints: &[RangeConstraint<T>],
59+
) -> Option<Vec<RangeConstraint<T>>> {
6060
// TODO We are currently ignoring bus interaction (also, but not only because there is no
6161
// unique machine responsible for handling a bus send), so just answer "false" if the identity
6262
// has no responsible machine.

executor/src/witgen/jit/witgen_inference.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ impl<'a, T: FieldElement, FixedEval: FixedEvaluator<T>> WitgenInference<'a, T, F
246246
let range_constraints = evaluated
247247
.iter()
248248
.map(|e| e.as_ref().and_then(|e| e.range_constraint()))
249+
.map(|rc| rc.unwrap_or_default())
249250
.collect_vec();
250251
let known = evaluated.iter().map(|e| e.is_some()).collect();
251252

@@ -543,17 +544,17 @@ pub trait CanProcessCall<T: FieldElement> {
543544
&self,
544545
_identity_id: u64,
545546
_known_inputs: &BitVec,
546-
_range_constraints: &[Option<RangeConstraint<T>>],
547-
) -> Option<Vec<Option<RangeConstraint<T>>>>;
547+
_range_constraints: &[RangeConstraint<T>],
548+
) -> Option<Vec<RangeConstraint<T>>>;
548549
}
549550

550551
impl<T: FieldElement, Q: QueryCallback<T>> CanProcessCall<T> for &MutableState<'_, T, Q> {
551552
fn can_process_call_fully(
552553
&self,
553554
identity_id: u64,
554555
known_inputs: &BitVec,
555-
range_constraints: &[Option<RangeConstraint<T>>],
556-
) -> Option<Vec<Option<RangeConstraint<T>>>> {
556+
range_constraints: &[RangeConstraint<T>],
557+
) -> Option<Vec<RangeConstraint<T>>> {
557558
MutableState::can_process_call_fully(self, identity_id, known_inputs, range_constraints)
558559
}
559560
}

executor/src/witgen/machines/double_sorted_witness_machine_32.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ impl<'a, T: FieldElement> Machine<'a, T> for DoubleSortedWitnesses32<'a, T> {
190190
&mut self,
191191
identity_id: u64,
192192
known_arguments: &BitVec,
193-
range_constraints: &[Option<RangeConstraint<T>>],
194-
) -> Option<Vec<Option<RangeConstraint<T>>>> {
193+
range_constraints: &[RangeConstraint<T>],
194+
) -> Option<Vec<RangeConstraint<T>>> {
195195
assert!(self.parts.connections.contains_key(&identity_id));
196196
assert_eq!(known_arguments.len(), 4);
197197
assert_eq!(range_constraints.len(), 4);
@@ -206,16 +206,12 @@ impl<'a, T: FieldElement> Machine<'a, T> for DoubleSortedWitnesses32<'a, T> {
206206
// For the value, it depends: If we write, we need to know it, if we read we do not need to know it.
207207
if known_arguments[3] {
208208
// It is known, so we are good anyway.
209-
Some(vec![None; 4])
209+
Some(vec![RangeConstraint::unconstrained(); 4])
210210
} else {
211211
// It is not known, so we can only process if we do not write.
212-
range_constraints[0]
213-
.as_ref()
214-
.is_some_and(|rc| {
215-
!rc.allows_value(T::from(OPERATION_ID_BOOTLOADER_WRITE))
216-
&& !rc.allows_value(T::from(OPERATION_ID_WRITE))
217-
})
218-
.then(|| vec![None; 4])
212+
(!range_constraints[0].allows_value(T::from(OPERATION_ID_BOOTLOADER_WRITE))
213+
&& !range_constraints[0].allows_value(T::from(OPERATION_ID_WRITE)))
214+
.then(|| vec![RangeConstraint::unconstrained(); 4])
219215
}
220216
}
221217

executor/src/witgen/machines/fixed_lookup_machine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ impl<'a, T: FieldElement> Machine<'a, T> for FixedLookup<'a, T> {
302302
&mut self,
303303
identity_id: u64,
304304
known_arguments: &BitVec,
305-
range_constraints: &[Option<RangeConstraint<T>>],
306-
) -> Option<Vec<Option<RangeConstraint<T>>>> {
305+
range_constraints: &[RangeConstraint<T>],
306+
) -> Option<Vec<RangeConstraint<T>>> {
307307
if !Self::is_responsible(&self.connections[&identity_id]) {
308308
return None;
309309
}

executor/src/witgen/machines/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ pub trait Machine<'a, T: FieldElement>: Send + Sync {
6969
&mut self,
7070
_identity_id: u64,
7171
_known_arguments: &BitVec,
72-
_range_constraints: &[Option<RangeConstraint<T>>],
73-
) -> Option<Vec<Option<RangeConstraint<T>>>> {
72+
_range_constraints: &[RangeConstraint<T>],
73+
) -> Option<Vec<RangeConstraint<T>>> {
7474
None
7575
}
7676

@@ -189,8 +189,8 @@ impl<'a, T: FieldElement> Machine<'a, T> for KnownMachine<'a, T> {
189189
&mut self,
190190
identity_id: u64,
191191
known_arguments: &BitVec,
192-
range_constraints: &[Option<RangeConstraint<T>>],
193-
) -> Option<Vec<Option<RangeConstraint<T>>>> {
192+
range_constraints: &[RangeConstraint<T>],
193+
) -> Option<Vec<RangeConstraint<T>>> {
194194
match self {
195195
KnownMachine::SecondStageMachine(m) => {
196196
m.can_process_call_fully(identity_id, known_arguments, range_constraints)

executor/src/witgen/range_constraints.rs

+15
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ impl<T: FieldElement> RangeConstraint<T> {
6262
Self { mask, min, max }
6363
}
6464

65+
/// Returns a range constraint that allows any value.
66+
pub fn unconstrained() -> Self {
67+
Self {
68+
mask: !T::Integer::zero(),
69+
min: T::zero(),
70+
max: T::from(-1),
71+
}
72+
}
73+
6574
/// Returns a bit mask. This might be drastically under-fitted in case
6675
/// the constraint is more resembling an interval.
6776
/// Semantics: X & mask == X holds for all possible values of X.
@@ -202,6 +211,12 @@ impl<T: FieldElement> RangeConstraint<T> {
202211
}
203212
}
204213

214+
impl<T: FieldElement> Default for RangeConstraint<T> {
215+
fn default() -> Self {
216+
Self::unconstrained()
217+
}
218+
}
219+
205220
/// The number of elements in an (inclusive) min/max range.
206221
/// Works both if min is smaller than max and if it is larger (the inverted interval).
207222
fn range_width<T: FieldElement>(min: T, max: T) -> T::Integer {

0 commit comments

Comments
 (0)