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

fix(sierra-gas): include RangeCheck96 in ConstCost::into_full_cost_iter - #10038

Merged
orizi merged 1 commit into
mainfrom
orizi/06-04-fix_sierra-gas_include_rangecheck96_in_constcost_into_full_cost_iter
Jun 7, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/06-04-fix_sierra-gas_include_rangecheck96_in_constcost_into_full_cost_iter

Conversation

@orizi

@orizi orizi commented Jun 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

RangeCheck96 is now included as a tracked cost token type in the PostCostTypeEx implementation for ConstCost, alongside the existing Step, Hole, and RangeCheck entries. This ensures range_checks96 from ConstCost is properly surfaced during gas cost computation.


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?

RangeCheck96 was already a recognized CostTokenType but was not being emitted by the PostCostTypeEx iterator for ConstCost. This meant 96-bit range check costs were silently omitted from gas solutions derived from ConstCost.


What was the behavior or documentation before?

Gas solution maps did not include a RangeCheck96 entry when computed via ConstCost::post_cost_type_ex.


What is the behavior or documentation after?

Gas solution maps now include RangeCheck96: 0 (or the appropriate non-zero value) in all cost breakdowns, consistent with how other token types are reported.


Related issue or discussion (if any)


Additional context

E2E test snapshots for metadata_computation have been updated to reflect the newly emitted RangeCheck96 field in all gas solution maps.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Jun 4, 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 4, 2026 14:47
@cursor

cursor Bot commented Jun 4, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes Sierra gas metadata accounting; incorrect costing could affect compiled gas bounds, though the change is a narrow omission fix with snapshot-only test impact here.

Overview
Fixes post-cost gas computation so 96-bit range check usage from ConstCost is no longer dropped when costs are expanded to full token maps.

ConstCost::into_full_cost_iter now emits CostTokenType::RangeCheck96 from range_checks96, alongside Step, Hole, and RangeCheck. Metadata e2e expectations were refreshed so gas solution snapshots include RangeCheck96 (still 0 in these fixtures).

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

  ConstCost::into_full_cost_iter emitted Step/Hole/RangeCheck but omitted
  range_checks96. In runtime-cost mode this iterator feeds
  GasInfo::variable_values, so the RangeCheck96 component (e.g. from circuit
  libfuncs) was silently dropped, under-counting gas for any code that uses it.
  Add the missing entry. Regenerates the metadata_computation e2e golden
  (rc96 costs now propagate).

SIERRA_UPDATE_NO_CHANGE_TAG=Has no effect on produced code.
@orizi
orizi force-pushed the orizi/06-04-fix_sierra-gas_include_rangecheck96_in_constcost_into_full_cost_iter branch from 49b5b44 to b4cd067 Compare June 4, 2026 14:48

@eytan-starkware eytan-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.

@eytan-starkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on orizi and TomerStarkware).


crates/cairo-lang-sierra-gas/src/compute_costs.rs line 807 at r1 (raw file):

            (CostTokenType::Hole, self.holes.into()),
            (CostTokenType::RangeCheck, self.range_checks.into()),
            (CostTokenType::RangeCheck96, self.range_checks96.into()),

Can this be used once so we see it doesnt crash?

@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 made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on eytan-starkware and TomerStarkware).


crates/cairo-lang-sierra-gas/src/compute_costs.rs line 807 at r1 (raw file):

Previously, eytan-starkware wrote…

Can this be used once so we see it doesnt crash?

this map is used only for testing - unlike Const and the pre-cost map - so no actual testable usage.

@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 all commit messages and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on eytan-starkware).

@eytan-starkware eytan-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.

:lgtm:

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

@orizi
orizi added this pull request to the merge queue Jun 7, 2026
Merged via the queue into main with commit 9028463 Jun 7, 2026
54 checks passed
@orizi
orizi deleted the orizi/06-04-fix_sierra-gas_include_rangecheck96_in_constcost_into_full_cost_iter branch June 7, 2026 11:25
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.

4 participants