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

fix(runner): correct n_steps by removing erroneous -1 offsets - #10003

Merged
orizi merged 1 commit into
mainfrom
orizi/05-28-fix_runner_correct_n_steps_by_removing_erroneous_-1_offsets
May 28, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/05-28-fix_runner_correct_n_steps_by_removing_erroneous_-1_offsets

Conversation

@orizi

@orizi orizi commented May 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes an off-by-one error in the step count subtraction when calculating used_resources.n_steps. The - 1 was incorrectly applied when removing header and footer steps from the relocated trace, causing the step count to be under-subtracted by 1 for both the forward and reverse trace position lookups.


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 position() call on the relocated trace already returns a 0-based index representing the number of steps to exclude. Subtracting an additional 1 from each result caused the reported step count to be 2 steps higher than the actual number of steps executed by the user's code (1 step over-counted from the header, 1 from the footer).


What was the behavior or documentation before?

used_resources.n_steps was reduced by (position - 1) for both the header and footer, leaving 2 extra steps attributed to the user's function execution.


What is the behavior or documentation after?

used_resources.n_steps is now correctly reduced by the full position value for both the header and footer, accurately reflecting only the steps belonging to the user's code.


Related issue or discussion (if any)


Additional context

The fix applies symmetrically to both the forward trace scan (header exclusion) and the reverse trace scan (footer exclusion).

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented May 28, 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 May 28, 2026 12:55
@cursor

cursor Bot commented May 28, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Small accounting fix in runner metrics only; no execution, auth, or contract semantics change.

Overview
Corrects how used_resources.n_steps is computed after a Sierra function run by stripping entry header and footer steps from the VM relocated trace.

Previously each subtraction used position(...) - 1, which under-counted excluded steps by one on both the forward (header) and reverse (footer) scans—reported step usage was two steps too high relative to user code only. The logic now subtracts the full position values from both iterators.

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

@orizi
orizi force-pushed the orizi/05-28-fix_runner_correct_n_steps_by_removing_erroneous_-1_offsets branch from 094b650 to 8a421c1 Compare May 28, 2026 14:04

@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 1 file 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 May 28, 2026
Merged via the queue into main with commit df86e63 May 28, 2026
54 checks passed
@orizi
orizi deleted the orizi/05-28-fix_runner_correct_n_steps_by_removing_erroneous_-1_offsets branch May 29, 2026 16:31
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