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

bugfix(sierra-sim): Fixed implementation of u128s_from_felt. - #10068

Merged
orizi merged 1 commit into
mainfrom
orizi/06-08-bugfix_sierra-sim_fixed_implementation_of_u128s_from_felt
Jun 8, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/06-08-bugfix_sierra-sim_fixed_implementation_of_u128s_from_felt

Conversation

@orizi

@orizi orizi commented Jun 8, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes the simulation of u128s_from_felt252 to correctly return both the high and low 128-bit components when the input Felt252 value does not fit in a u128. Previously, the failure branch returned only the RangeCheck value with no decomposition. Now, when the value exceeds u128::MAX, it is split via div_rem by 2^128 into a high part and a low part, both returned as Uint128 values alongside RangeCheck.


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?

The simulation of u128s_from_felt252 was incomplete: when the felt252 value was too large to fit in a u128, the failure branch only returned RangeCheck without providing the high and low decomposed u128 values. This made the simulation diverge from the actual semantics of the libfunc, which decomposes the value into (high, low) parts.


What was the behavior or documentation before?

When u128s_from_felt252 was simulated with a value that does not fit in a u128, the failure branch returned vec![CoreValue::RangeCheck] with no decomposition of the input value.


What is the behavior or documentation after?

The failure branch now computes (high, low) = value / 2^128 and returns vec![CoreValue::RangeCheck, CoreValue::Uint128(high), CoreValue::Uint128(low)], matching the expected libfunc semantics. Tests covering both the success case (e.g., 5) and the failure case (e.g., 3 * 2^128 + 7) are added.


Related issue or discussion (if any)

N/A


Additional context

N/A

SIERRA_UPDATE_NO_CHANGE_TAG=Sim change only.
@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@orizi
orizi marked this pull request as ready for review June 8, 2026 18:00
@cursor

cursor Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Changes only the Sierra libfunc simulator and tests; runtime semantics are unchanged and behavior is aligned with the existing libfunc contract.

Overview
Fixes Sierra simulation of u128s_from_felt252 when the input Felt252 does not fit in a single u128.

On the overflow branch (branch 1), the simulator now splits the value with div_rem by 2^128 and returns RangeCheck plus high and low Uint128 limbs, instead of only RangeCheck. The in-range path is unchanged.

Adds branch tests for a small felt (5) and a value 3·2^128 + 7.

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

@TomerStarkware TomerStarkware left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:lgtm:

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

@orizi
orizi added this pull request to the merge queue Jun 8, 2026
Merged via the queue into main with commit c752033 Jun 8, 2026
54 checks passed
@orizi
orizi deleted the orizi/06-08-bugfix_sierra-sim_fixed_implementation_of_u128s_from_felt branch June 9, 2026 08:11
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