Fix M31 field arithmetic collision in bitwise constraint verification #12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The bitwise constraint functions (
and_constraint,or_constraint,xor_constraint, and their immediate variants) attempted to reconstruct 32-bit values using bit 31 with weight2^31in M31 field arithmetic. Since2^31 ≡ 1 (mod 2^31-1), this created exploitable collisions where distinct 32-bit values like0x00000001and0x80000000both mapped toM31(1), allowing forged proofs for incorrect bitwise operations.Changes
Constraint functions: Modified 6 functions to use only bits 0-30, removing bit 31 handling
and_constraint,or_constraint,xor_constraintandi_constraint,ori_constraint,xori_constraintTests: Added validation that values exceeding 31-bit range fail verification
Before/After
Operations now treat values as signed 31-bit, preventing the collision attack while maintaining correct verification for the representable range.
Original prompt
M31Field Arithmetic inxor_constraintConstraint Verification #11✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.