Skip to content

Conversation

@ArmanKolozyan
Copy link
Contributor

This pull request adds a missing range check in the ShaBytesDynamic template to address the vulnerability described in the following issue:

  • Missing Range Constraints for Sha256Bytes Allow Forged Inputs to Pass Verification #578
    The Sha256Bytes template assumes that the input length (in_len_padded_bytes * 8) is constrained to fit within ceil(log2(8 * max_num_bytes)) bits. However, this assumption is not enforced at the call sites in this project. In particular, in_len_padded_bytes * 8 is passed to subtemplates like Sha256General, where it is used in comparison and selector logic without first constraining it to the required bitwidth.

To fix this, we add an explicit Num2Bits constraint on in_len_padded_bytes * 8 inside ShaBytesDynamic.

This prevents potential overflow-based exploits that could bypass internal constraints and produce incorrect outputs while still satisfying the circuit.

Closes #578.

motemotech and others added 4 commits April 17, 2025 15:57
* make contract sdk simpler

* reduce root inputs

* delete convert function

* summarize our library

* update npm package

* update package version

* update attestation id

* add util function to get revealed data
@remicolin
Copy link
Collaborator

remicolin commented May 30, 2025

hey @ArmanKolozyan, nice catch!
thanks for raising this PR, we'll have to add the same range check to Sha1Bytes
could you dm me on telegram so we can keep chatting about the issue?

@remicolin remicolin changed the base branch from main to dev May 30, 2025 16:30
@ArmanKolozyan
Copy link
Contributor Author

Thanks a lot for the quick response, and I just DMed you on Telegram!

@ArmanKolozyan
Copy link
Contributor Author

ArmanKolozyan commented May 30, 2025

@remicolin Just wanted to let you know that I added the range check for Sha1Bytes and also documented the assumptions in both Sha1Bytes and Sha1General. Please let me know if there is anything else I can do to help get these changes ready for merging!

@remicolin remicolin self-requested a review June 3, 2025 11:18
@remicolin remicolin merged commit 0c8c873 into selfxyz:dev Jun 3, 2025
1 check passed
remicolin added a commit that referenced this pull request Jun 12, 2025
remicolin added a commit that referenced this pull request Jun 12, 2025
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.

Missing Range Constraints for Sha256Bytes Allow Forged Inputs to Pass Verification

3 participants