Skip to content

Conversation

@GarmashAlex
Copy link
Contributor

@GarmashAlex GarmashAlex commented Oct 28, 2025

Enforce documented strict inequality in BytesToNative() and () by introducing assertBytesLt and using it when WithAllowOverflow is not set.
Prevents accepting byte arrays equal to the field modulus, which previously allowed a non-unique representation of zero and could be exploited by malicious hints.Adds a negative test for the “bytes == modulus” case in BytesToNative().
Emulated conversions already enforced strictness; bringing native conversions into alignment with docs and intent.


Note

Enforces strict less-than modulus in BytesToNative/NativeToBytes by extending assertBytesLeq with a disallowEquality flag and adds tests, while preserving overflow-allowed behavior.

  • Conversion:
    • BytesToNative and NativeToBytes now enforce strict < modulus by calling assertBytesLeq(api, ..., field, true).
    • Extend assertBytesLeq to assertBytesLeq(api, b, bound, disallowEquality) to optionally forbid equality.
  • Tests:
    • Add negative/positive cases where bytes equal the modulus (invalid without overflow; valid with WithAllowOverflow).
    • Update AssertBytesLeq circuit and test matrix to pass disallowEquality and validate both strict and non-strict comparisons.

Written by Cursor Bugbot for commit ba04639. This will update automatically on new commits. Configure here.

@ivokub ivokub changed the base branch from master to typo/fixes-v15 December 18, 2025 00:32
Copy link
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I refactored to have a single implementation with a switch and added a few tests.

@ivokub ivokub merged commit d148214 into Consensys:typo/fixes-v15 Dec 18, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants