Skip to content

feature(sierra): Added a split fn from u128 to u32 guarantees.#9778

Merged
orizi merged 1 commit intomainfrom
orizi/03-22-feature_sierra_added_a_split_fn_from_u128_to_u32_guarantees
Mar 29, 2026
Merged

feature(sierra): Added a split fn from u128 to u32 guarantees.#9778
orizi merged 1 commit intomainfrom
orizi/03-22-feature_sierra_added_a_split_fn_from_u128_to_u32_guarantees

Conversation

@orizi
Copy link
Copy Markdown
Collaborator

@orizi orizi commented Mar 24, 2026

Summary

Adds a new u128_to_u32_guarantees libfunc that splits a u128 value into four u32 guarantee values using iterative DivMod hints and verification.


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?

This libfunc provides an efficient way to decompose u128 values into their constituent u32 parts with mathematical guarantees, which is useful for operations that need to work with smaller integer components or for cryptographic applications that require bounded integer guarantees.


What was the behavior or documentation before?

There was no built-in way to split a u128 into guaranteed u32 components in the Sierra instruction set.


What is the behavior or documentation after?

The new u128_to_u32_guarantees libfunc takes a u128 input and returns four BoundedIntGuarantee<0, 4294967295> values representing the u32 components. The implementation uses DivMod hints to perform the splitting and verifies the reconstruction using Horner's method. The libfunc has an AP change cost of 9 and a gas cost of 7 steps.


Related issue or discussion (if any)

None specified.


Additional context

The implementation includes comprehensive test coverage and the libfunc has been added to the allowed libfuncs list for Starknet classes. The verification process ensures mathematical correctness by reconstructing the original u128 value from the four u32 components.


Note

Medium Risk
Introduces a new Sierra libfunc with custom CASM generation and new AP/gas accounting, which could affect compilation determinism and cost metering if the implementation or constants are incorrect.

Overview
Adds a new Sierra libfunc, u128_to_u32_guarantees, that decomposes a u128 into four BoundedIntGuarantee<0, 2^32-1> outputs.

Implements CASM lowering using iterative DivMod hints plus reconstruction asserts, wires the new variant through bounded-int libfunc specialization, and assigns fixed metering (ApChange::Known(9) and ConstCost::steps(7)). The libfunc is added to Starknet’s allowed_libfuncs list and covered by a new bounded-int e2e test vector.

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

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Collaborator Author

orizi commented Mar 24, 2026

Copy link
Copy Markdown

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

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: 83b4037790

ℹ️ 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".

Copy link
Copy Markdown

@cursor cursor bot left a comment

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.

@orizi orizi force-pushed the orizi/03-22-feature_sierra_added_boundedintguarantee_and_verify_libfunc branch from c12a37d to 43f2917 Compare March 24, 2026 11:03
@orizi orizi force-pushed the orizi/03-22-feature_sierra_added_a_split_fn_from_u128_to_u32_guarantees branch from 83b4037 to 16934fb Compare March 24, 2026 11:03
Copy link
Copy Markdown
Collaborator Author

@orizi orizi left a comment

Choose a reason for hiding this comment

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

@orizi made 1 comment.
Reviewable status: 0 of 6 files reviewed, 2 unresolved discussions (waiting on ilyalesokhin-starkware).

Copy link
Copy Markdown
Contributor

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

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

@ilyalesokhin-starkware reviewed 5 files and all commit messages.
Reviewable status: 5 of 6 files reviewed, 2 unresolved discussions.

@orizi orizi changed the base branch from orizi/03-22-feature_sierra_added_boundedintguarantee_and_verify_libfunc to graphite-base/9778 March 26, 2026 15:32
@orizi orizi force-pushed the graphite-base/9778 branch from 43f2917 to 8b488ea Compare March 26, 2026 15:34
@orizi orizi force-pushed the orizi/03-22-feature_sierra_added_a_split_fn_from_u128_to_u32_guarantees branch from 16934fb to 357be6f Compare March 26, 2026 15:34
Copy link
Copy Markdown
Collaborator Author

@orizi orizi left a comment

Choose a reason for hiding this comment

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

@orizi made 1 comment and resolved 1 discussion.
Reviewable status: 5 of 6 files reviewed, 1 unresolved discussion (waiting on ilyalesokhin-starkware).

@orizi orizi changed the base branch from graphite-base/9778 to orizi/03-22-feature_sierra_added_boundedintguarantee_and_verify_libfunc March 26, 2026 15:34
@orizi orizi force-pushed the orizi/03-22-feature_sierra_added_a_split_fn_from_u128_to_u32_guarantees branch from 357be6f to e35621c Compare March 27, 2026 09:59
@orizi orizi force-pushed the orizi/03-22-feature_sierra_added_boundedintguarantee_and_verify_libfunc branch from 8b488ea to 3814e9a Compare March 27, 2026 09:59
Copy link
Copy Markdown
Contributor

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

@ilyalesokhin-starkware reviewed 5 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on orizi).

@orizi orizi changed the base branch from orizi/03-22-feature_sierra_added_boundedintguarantee_and_verify_libfunc to graphite-base/9778 March 29, 2026 06:33
SIERRA_UPDATE_MINOR_CHANGE_TAG=New libfunc.
@orizi orizi force-pushed the graphite-base/9778 branch from 3814e9a to da9e014 Compare March 29, 2026 07:45
@orizi orizi force-pushed the orizi/03-22-feature_sierra_added_a_split_fn_from_u128_to_u32_guarantees branch from e35621c to bc7d580 Compare March 29, 2026 07:45
@orizi orizi changed the base branch from graphite-base/9778 to main March 29, 2026 07:45
Copy link
Copy Markdown
Collaborator Author

@orizi orizi left a comment

Choose a reason for hiding this comment

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

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

@orizi orizi enabled auto-merge March 29, 2026 07:46
@orizi orizi added this pull request to the merge queue Mar 29, 2026
Merged via the queue into main with commit 30746c2 Mar 29, 2026
105 checks passed
@orizi orizi deleted the orizi/03-22-feature_sierra_added_a_split_fn_from_u128_to_u32_guarantees branch March 29, 2026 08:01
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