fix: use u64 in BaseSplitGenerator (#1647)

The BaseSplitGenerator was casting fields (which fit in u64) into usize.
This doesn't work in 32-bit architectures where usize is 32 bits, like
wasm32.  Keeping the value at u64 allows it to work in 32-bit
architectures.
This commit is contained in:
Eduard S. 2025-01-13 18:18:52 +01:00 committed by GitHub
parent 02e80e9af0
commit 892f51bd12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -194,9 +194,9 @@ impl<F: RichField + Extendable<D>, const B: usize, const D: usize> SimpleGenerat
) -> Result<()> {
let sum_value = witness
.get_target(Target::wire(self.row, BaseSumGate::<B>::WIRE_SUM))
.to_canonical_u64() as usize;
.to_canonical_u64();
debug_assert_eq!(
(0..self.num_limbs).fold(sum_value, |acc, _| acc / B),
(0..self.num_limbs).fold(sum_value, |acc, _| acc / (B as u64)),
0,
"Integer too large to fit in given number of limbs"
);
@ -205,9 +205,9 @@ impl<F: RichField + Extendable<D>, const B: usize, const D: usize> SimpleGenerat
.map(|i| Target::wire(self.row, i));
let limbs_value = (0..self.num_limbs)
.scan(sum_value, |acc, _| {
let tmp = *acc % B;
*acc /= B;
Some(F::from_canonical_usize(tmp))
let tmp = *acc % (B as u64);
*acc /= B as u64;
Some(F::from_canonical_u64(tmp))
})
.collect::<Vec<_>>();