Skip to content

starknet_os: os resources test - measure linear factor, add deploy#14134

Merged
dorimedini-starkware merged 1 commit into
mainfrom
05-22-starknet_os_os_resources_test_-_measure_linear_factor_add_deploy
Jun 7, 2026
Merged

starknet_os: os resources test - measure linear factor, add deploy#14134
dorimedini-starkware merged 1 commit into
mainfrom
05-22-starknet_os_os_resources_test_-_measure_linear_factor_add_deploy

Conversation

@dorimedini-starkware

Copy link
Copy Markdown
Collaborator

No description provided.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

@cursor

cursor Bot commented May 24, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Test-only and measurement-harness changes; no production execution or fee logic paths are modified in this diff.

Overview
Extends the OS resources regression harness so deploy is measured in-process and syscall costs with linear calldata factors are written into versioned constants in the right shape.

The Cairo1 OsResourcesTestContract now invokes deploy_syscall twice (empty vs length-1 constructor calldata) with a fixed salt and deploy_from_zero, matching the test’s need for stable address normalization. Deploy is removed from the unmeasurable syscall list.

test_os_resources_regression no longer records only flat ExecutionResources per trace. For syscalls listed in SYSCALLS_WITH_LINEAR_FACTOR (including Deploy and MetaTxV0), it consumes back-to-back traces of the same selector, derives an unscaled calldata factor from the delta, backs out the true base cost, and stores VariableResourceParams::WithFactor instead of a constant entry.

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

Comment thread crates/starknet_os_flow_tests/src/os_resources_test.rs

@yoavGrs yoavGrs 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.

@yoavGrs reviewed 5 files and all commit messages, made 9 comments, and resolved 3 discussions.
Reviewable status: all files reviewed, 9 unresolved discussions (waiting on dorimedini-starkware and Yoni-Starkware).


crates/starknet_os_flow_tests/src/os_resources_test.rs line 235 at r4 (raw file):

Previously, dorimedini-starkware wrote…

each measurable syscall can

  1. have a linear factor or not
  2. be a virtual builtin or not
  3. incur inner calls or not
  4. be keccak or not (which is in itself a special case)

since the above are not necessarily disjoint sets, I don't think an enum will help. what did you have in mind?

OK, I assumed the sets are disjoint.


crates/starknet_os_flow_tests/src/os_resources_test.rs line 79 at r5 (raw file):

/// Store a mapping from a linearly-charged syscall, with the number of "linear elements" in it's
/// base measurement. For example, if we measure the base and linear costs of a [Selector::Deploy]

Base is a measurement with no linear elements.

Suggestion:

first measurement

crates/starknet_os_flow_tests/src/os_resources_test.rs line 83 at r5 (raw file):

/// ```
/// deploy_syscall(stable_class_hash, 3, array![2, 0, 0].span(), true).unwrap_syscall();
/// deploy_syscall(stable_class_hash, 3, array![3, 0, 0, 0].span(), true).unwrap_syscall();

What will be the value in the mapping for this example?

Code quote:

/// deploy_syscall(stable_class_hash, 3, array![2, 0, 0].span(), true).unwrap_syscall();
/// deploy_syscall(stable_class_hash, 3, array![3, 0, 0, 0].span(), true).unwrap_syscall();

crates/starknet_os_flow_tests/src/os_resources_test.rs line 85 at r5 (raw file):

/// deploy_syscall(stable_class_hash, 3, array![3, 0, 0, 0].span(), true).unwrap_syscall();
/// ```
/// ... then the linear factor is exactly the difference between the two measurements, because the

Is the difference between the number of linear elements in both measurements always 1?

It would be more valuable to focus here on the assumptions about the linear syscalls in the contract (two consecutive readings), rather than the calculation details that covered in the code below.

Code quote:

exactly the difference between the two measurements

crates/starknet_os_flow_tests/src/os_resources_test.rs line 244 at r5 (raw file):

        // iterator.
        let inner_overhead = fetch_inner_resources(selector);
        // The resources measured here are one of two types: constant, or base cost of a syscall

It still includes the linear cost.
You can remove the whole comment.

Code quote:

or base cost

crates/starknet_os_flow_tests/src/os_resources_test.rs line 249 at r5 (raw file):

            (syscall_trace.get_resources().unwrap() - &inner_overhead).filter_unused_builtins();

        // If this if a syscall with a linear factor, the next syscall should be the linear cost.

Based on the second reading, we can infer the linear cost.

Code quote:

should be the linear cost

crates/starknet_os_flow_tests/src/os_resources_test.rs line 265 at r5 (raw file):

            let next_resources = (next_syscall_trace.get_resources().unwrap()
                - &next_inner_overhead)
                .filter_unused_builtins();

It is a duplication of the code above:

        let inner_overhead = fetch_inner_resources(selector);
        // The resources measured here are one of two types: constant, or base cost of a syscall
        // with a linear factor.
        let mut resources =
            (syscall_trace.get_resources().unwrap() - &inner_overhead).filter_unused_builtins();

Consider reuse.

Code quote:

            let next_inner_overhead = fetch_inner_resources(selector);
            let next_resources = (next_syscall_trace.get_resources().unwrap()
                - &next_inner_overhead)
                .filter_unused_builtins();

crates/starknet_os_flow_tests/src/os_resources_test.rs line 266 at r5 (raw file):

                - &next_inner_overhead)
                .filter_unused_builtins();
            let linear_factor_resources = (&next_resources - &resources).filter_unused_builtins();

Assuming the next syscall has exactly one more linear element. Is it the case?

Code quote:

let linear_factor_resources = (&next_resources - &resources).filter_unused_builtins();

crates/starknet_os_flow_tests/src/os_resources_test.rs line 270 at r5 (raw file):

            // Linear factor is computed; deduct the linear overhead from the base cost to get the
            // real base cost.
            resources = (&resources - &(&linear_factor_resources * *linear_count_in_base))

Suggestion:

constant_resources =

@dorimedini-starkware dorimedini-starkware force-pushed the 05-22-starknet_os_os_resources_test_-_measure_linear_factor_add_deploy branch from 1ae17f6 to a616966 Compare June 2, 2026 14:54
@dorimedini-starkware dorimedini-starkware changed the base branch from graphite-base/14134 to 05-21-starknet_os_os_resources_test_-_library_call June 2, 2026 14:55

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

@dorimedini-starkware made 8 comments and resolved 1 discussion.
Reviewable status: 6 of 7 files reviewed, 8 unresolved discussions (waiting on yoavGrs and Yoni-Starkware).


crates/starknet_os_flow_tests/src/os_resources_test.rs line 79 at r5 (raw file):

Previously, yoavGrs wrote…

Base is a measurement with no linear elements.

Done.


crates/starknet_os_flow_tests/src/os_resources_test.rs line 83 at r5 (raw file):

Previously, yoavGrs wrote…

What will be the value in the mapping for this example?

Done.


crates/starknet_os_flow_tests/src/os_resources_test.rs line 85 at r5 (raw file):

Previously, yoavGrs wrote…

Is the difference between the number of linear elements in both measurements always 1?

It would be more valuable to focus here on the assumptions about the linear syscalls in the contract (two consecutive readings), rather than the calculation details that covered in the code below.

added a comment about it, better?


crates/starknet_os_flow_tests/src/os_resources_test.rs line 244 at r5 (raw file):

Previously, yoavGrs wrote…

It still includes the linear cost.
You can remove the whole comment.

Done.


crates/starknet_os_flow_tests/src/os_resources_test.rs line 249 at r5 (raw file):

Previously, yoavGrs wrote…

Based on the second reading, we can infer the linear cost.

better?


crates/starknet_os_flow_tests/src/os_resources_test.rs line 265 at r5 (raw file):

Previously, yoavGrs wrote…

It is a duplication of the code above:

        let inner_overhead = fetch_inner_resources(selector);
        // The resources measured here are one of two types: constant, or base cost of a syscall
        // with a linear factor.
        let mut resources =
            (syscall_trace.get_resources().unwrap() - &inner_overhead).filter_unused_builtins();

Consider reuse.

consolidated


crates/starknet_os_flow_tests/src/os_resources_test.rs line 266 at r5 (raw file):

Previously, yoavGrs wrote…

Assuming the next syscall has exactly one more linear element. Is it the case?

I mention the +1 thing in the new comment above, good enough?
and yes, this is always the case


crates/starknet_os_flow_tests/src/os_resources_test.rs line 270 at r5 (raw file):

            // Linear factor is computed; deduct the linear overhead from the base cost to get the
            // real base cost.
            resources = (&resources - &(&linear_factor_resources * *linear_count_in_base))

Done.

@dorimedini-starkware dorimedini-starkware changed the base branch from 05-21-starknet_os_os_resources_test_-_library_call to graphite-base/14134 June 2, 2026 15:17
@dorimedini-starkware dorimedini-starkware force-pushed the 05-22-starknet_os_os_resources_test_-_measure_linear_factor_add_deploy branch from a616966 to da034b0 Compare June 2, 2026 15:17
@dorimedini-starkware dorimedini-starkware changed the base branch from graphite-base/14134 to main June 2, 2026 15:17
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

Artifacts upload workflows:

@dorimedini-starkware dorimedini-starkware force-pushed the 05-22-starknet_os_os_resources_test_-_measure_linear_factor_add_deploy branch from da034b0 to cf5157a Compare June 2, 2026 15:48

@yoavGrs yoavGrs 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.

@yoavGrs reviewed 2 files and all commit messages, made 3 comments, and resolved 6 discussions.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on dorimedini-starkware and Yoni-Starkware).


crates/starknet_os_flow_tests/src/os_resources_test.rs line 85 at r5 (raw file):

Previously, dorimedini-starkware wrote…

added a comment about it, better?

Best


crates/starknet_os_flow_tests/src/os_resources_test.rs line 234 at r6 (raw file):

                ExecutionResources::default()
            };
            (total - &to_deduct).filter_unused_builtins()

Consider, non-blocking

Suggestion:

            if selector.is_calling_syscall() {
                // TODO(Dori): Take opcodes (like blake) into account, instead of using the
                // vm_resources field.
                let to_deduct = inner_calls_iter.next().unwrap().resources.vm_resources;
                (total - &to_deduct).filter_unused_builtins()
            } else {
                total
            };
            

crates/starknet_os_flow_tests/src/os_resources_test.rs line 249 at r6 (raw file):

        let resources = maybe_deduct_inner(syscall_trace.get_resources().unwrap(), selector);

        // If this if a syscall with a linear factor, the next syscall should be an invocation of

Suggestion:

this is a

@dorimedini-starkware dorimedini-starkware force-pushed the 05-22-starknet_os_os_resources_test_-_measure_linear_factor_add_deploy branch from cf5157a to 7167361 Compare June 3, 2026 07:24

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

@dorimedini-starkware made 1 comment and resolved 1 discussion.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on yoavGrs and Yoni-Starkware).


crates/starknet_os_flow_tests/src/os_resources_test.rs line 249 at r6 (raw file):

        let resources = maybe_deduct_inner(syscall_trace.get_resources().unwrap(), selector);

        // If this if a syscall with a linear factor, the next syscall should be an invocation of

Done.

@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 7167361. Configure here.

Comment thread crates/starknet_os_flow_tests/src/os_resources_test.rs

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

@dorimedini-starkware made 1 comment.
Reviewable status: 6 of 7 files reviewed, 4 unresolved discussions (waiting on yoavGrs and Yoni-Starkware).

Comment thread crates/starknet_os_flow_tests/src/os_resources_test.rs

@yoavGrs yoavGrs 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.

@yoavGrs reviewed 1 file and all commit messages, and resolved 2 discussions.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on Yoni-Starkware).

@yoavGrs yoavGrs 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.

@yoavGrs reviewed 1 file and all commit messages, and resolved 2 discussions.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on Yoni-Starkware).

@dorimedini-starkware dorimedini-starkware force-pushed the 05-22-starknet_os_os_resources_test_-_measure_linear_factor_add_deploy branch from 7167361 to c34d43e Compare June 4, 2026 07:53
@dorimedini-starkware dorimedini-starkware force-pushed the 05-22-starknet_os_os_resources_test_-_measure_linear_factor_add_deploy branch from c34d43e to 55dfa63 Compare June 4, 2026 10:43

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

@dorimedini-starkware resolved 1 discussion.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on Yoni-Starkware).

@Yoni-Starkware Yoni-Starkware 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:

@Yoni-Starkware reviewed 2 files and all commit messages, and made 2 comments.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on dorimedini-starkware).

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

@dorimedini-starkware resolved 1 discussion and dismissed @Yoni-Starkware from a discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on dorimedini-starkware).

@dorimedini-starkware dorimedini-starkware added this pull request to the merge queue Jun 7, 2026
Merged via the queue into main with commit 2d7d8df Jun 7, 2026
29 checks passed
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