Skip to content

Conversation

@vadorovsky
Copy link
Contributor

Before this change, we were enforcing only the upper limit of the byte input lenghts in hash_bytes_be and hash_bytes_le methods. The limit is indicated by the amount of bytes needed to represent the modulus of the given prime field. For the Fr field, the limit is 32 bytes.

At the same time, we were allowing smaller byte slices. For example, we were allowing either a full 32-byte array with explicit padding:

[
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 1
]

Or smaller arrays with smaller amount of leading or trailing bytes (depending on endianness):

[0, 0, 0, 0, 0, 0, 0, 1]
[0, 0, 0, 1]
[0, 1]
[1]

All these inputs produce the same hashes.

To avoid confusion, do not allow smaller inputs the modulus and make padding mandatory.

Before this change, we were enforcing only the upper limit of the byte
input lenghts in `hash_bytes_be` and `hash_bytes_le` methods. The limit
is indicated by the amount of bytes needed to represent the modulus of
the given prime field. For the `Fr` field, the limit is 32 bytes.

At the same time, we were allowing smaller byte slices. For example,
we were allowing either a full 32-byte array with explicit padding:

```
[
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 1
]
```

Or smaller arrays with smaller amount of leading or trailing bytes
(depending on endianness):

```
[0, 0, 0, 0, 0, 0, 0, 1]
[0, 0, 0, 1]
[0, 1]
[1]
```

All these inputs produce the same hashes.

To avoid confusion, do not allow smaller inputs the modulus and make
padding mandatory.
@vadorovsky vadorovsky force-pushed the enforce-modulus-size branch from 273ec55 to 6d3488d Compare August 19, 2025 14:11
@ananas-block ananas-block merged commit 92ce32a into Lightprotocol:main Aug 19, 2025
2 checks passed
@vadorovsky vadorovsky deleted the enforce-modulus-size branch August 19, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants