Sitelet https://github.com/starkware-libs/cairo/pull/9988
Skip to content

Removed non-safe variant of array-hash. - #9988

Merged
orizi merged 1 commit into
mainfrom
orizi/05-27-removed_non-safe_variant_of_array-hash
May 27, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/05-27-removed_non-safe_variant_of_array-hash

Conversation

@orizi

@orizi orizi commented May 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

compute_sha512_u64_array_safe has been removed and merged into compute_sha512_u64_array, which now directly accepts last_input_num_bytes as a u3 (a BoundedInt<0, 7>) instead of a u32. The old compute_sha512_u64_array wrapper that performed a runtime downcast and panicked on values greater than 7 has been eliminated. Tests have been updated to call compute_sha512_u64_array directly.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

Having two separate functions — one that panicked at runtime and one that enforced the bound via the type system — was redundant. The u3 type already statically guarantees that last_input_num_bytes is in the range 0..=7, making the runtime-panicking wrapper unnecessary. Consolidating into a single function with a typed parameter removes the possibility of a runtime panic and simplifies the public API.


What was the behavior or documentation before?

compute_sha512_u64_array accepted a u32 for last_input_num_bytes and panicked at runtime if the value exceeded 7. A separate compute_sha512_u64_array_safe function accepted a u3 to enforce the bound at the type level.


What is the behavior or documentation after?

compute_sha512_u64_array now accepts last_input_num_bytes as a u3 directly, enforcing the 0..=7 bound at compile time. compute_sha512_u64_array_safe no longer exists.


Related issue or discussion (if any)


Additional context

The u3 type alias (BoundedInt<0, 7>) remains part of the public API in sha512.

orizi commented May 27, 2026

Copy link
Copy Markdown
Collaborator Author

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

@dorimedini-starkware dorimedini-starkware left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@dorimedini-starkware reviewed 2 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on dorimedini-starkware and TomerStarkware).

@orizi
orizi marked this pull request as ready for review May 27, 2026 12:20
@cursor

cursor Bot commented May 27, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Breaking change for callers that passed last_input_num_bytes as u32 or used compute_sha512_u64_array_safe; hash logic is unchanged when inputs satisfy the bound.

Overview
Consolidates the SHA-512 u64-array API by removing the redundant compute_sha512_u64_array_safe name and the old compute_sha512_u64_array wrapper that accepted last_input_num_bytes as u32 and could panic when the value was greater than 7.

compute_sha512_u64_array is now the single entry point: it takes last_input_num_bytes as u3 (BoundedInt<0, 7>), so the 0..=7 bound is enforced at compile time instead of via runtime downcast. Docs and examples are updated accordingly; compute_sha512_byte_array and tests call the renamed function. Test literals drop redundant _u64 suffixes only.

Reviewed by Cursor Bugbot for commit 1751c55. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b6814882cb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread corelib/src/sha512.cairo

@dorimedini-starkware dorimedini-starkware left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on orizi and TomerStarkware).

@orizi
orizi force-pushed the orizi/05-27-removed_non-safe_variant_of_array-hash branch from b681488 to 06e0d00 Compare May 27, 2026 13:12

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@orizi resolved 1 discussion.
Reviewable status: 1 of 2 files reviewed, all discussions resolved (waiting on dorimedini-starkware and TomerStarkware).

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 06e0d00. Configure here.

Comment thread corelib/src/sha512.cairo
No need for compatibility with old version of sha256 - as existed only
to not break the existing interfaces.
@orizi
orizi force-pushed the orizi/05-27-removed_non-safe_variant_of_array-hash branch from 06e0d00 to 1751c55 Compare May 27, 2026 13:34

@dorimedini-starkware dorimedini-starkware left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@dorimedini-starkware reviewed 1 file and all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on orizi and TomerStarkware).

@orizi
orizi enabled auto-merge May 27, 2026 13:50
@orizi
orizi added this pull request to the merge queue May 27, 2026
Merged via the queue into main with commit 6e33a25 May 27, 2026
54 checks passed
@orizi
orizi deleted the orizi/05-27-removed_non-safe_variant_of_array-hash branch May 27, 2026 14:00
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.

3 participants