Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion circuit-std-rs/src/logup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl LogUpRangeProofTable {
let rem = n % self.rangeproof_bits;
let shift = self.rangeproof_bits - rem;
let constant = (1 << shift) - 1;
let mut mul_factor = 0;
let mut mul_factor = 1;
mul_factor <<= n;
let a_shift = builder.mul(constant, mul_factor);
Comment on lines +429 to 431
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While initializing mul_factor to 1 is the correct fix, the code can be made more robust. The type of mul_factor is inferred by the compiler and could overflow if n is large (e.g., > 31). To prevent potential overflows and align with the implementation in the rangeproof function, it's better to explicitly type mul_factor as u128 and convert it to a circuit variable before the multiplication.

A similar issue exists for constant on line 428, which would also benefit from an explicit type like u128 to prevent potential overflows.

Suggested change
let mut mul_factor = 1;
mul_factor <<= n;
let a_shift = builder.mul(constant, mul_factor);
let mul_factor: u128 = 1 << n;
let mul_factor_u256 = U256::new(mul_factor);
let mul_factor_var = builder.constant(CircuitField::<C>::from_u256(mul_factor_u256));
let a_shift = builder.mul(constant, mul_factor_var);

new_a = builder.add(a, a_shift);
Expand Down