utilities::range_check: Correct range_check expression

Previously, we were multiplying the expression by 0, which led it
to always evaluate to true.
This commit is contained in:
therealyingtong 2021-07-09 22:03:26 +08:00
parent 8a9f8218e9
commit 6c41c72e66
1 changed files with 3 additions and 4 deletions

View File

@ -123,10 +123,9 @@ pub fn bitrange_subset<F: FieldExt + PrimeFieldBits>(field_elem: F, bitrange: Ra
/// Check that an expression is in the small range [0..range),
/// i.e. 0 ≤ word < range.
pub fn range_check<F: FieldExt>(word: Expression<F>, range: usize) -> Expression<F> {
(0..range)
.map(|i| Expression::Constant(F::from_u64(i as u64)))
.reduce(|acc, i| acc * (word.clone() - i))
.expect("range > 0")
(1..range).fold(word.clone(), |acc, i| {
acc * (word.clone() - Expression::Constant(F::from_u64(i as u64)))
})
}
#[cfg(test)]