Skip to content

Conversation

@dorimedini-starkware
Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware commented May 25, 2025

Implemented prevent_segment_execution function

Description:

In the Starknet OS's bytecode_hash_internal_node implementation, we have this snippet:

            // Set the first felt of the bytecode to -1 to make sure that the execution cannot jump
            // to this segment (-1 is an invalid opcode).
            // The hash in this case is guessed and the actual bytecode is unconstrained (except for
            // the first felt).
            %{
                # Sanity check.
                assert not is_accessed(ids.data_ptr), "The segment is skipped but was accessed."
                del memory.data[ids.data_ptr]
            %}
            assert data_ptr[0] = -1;

This PR is to support the above logic: marking a segment as non-executable, and complying with the assert data_ptr[0] = -1 after the hint.

Checklist

  • Linked to Github Issue
  • [v] Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.
    • [v] CHANGELOG has been updated.

@dorimedini-starkware dorimedini-starkware self-assigned this May 25, 2025
@dorimedini-starkware dorimedini-starkware force-pushed the dori/prevent-segment-execution branch 2 times, most recently from af680c4 to 96cfd47 Compare May 25, 2025 11:53
@github-actions
Copy link

github-actions bot commented May 25, 2025

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.161 ± 0.029 2.135 2.229 1.00
head big_factorial 2.179 ± 0.021 2.160 2.219 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.082 ± 0.012 2.068 2.103 1.00
head big_fibonacci 2.101 ± 0.007 2.092 2.117 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 7.780 ± 0.030 7.752 7.855 1.00
head blake2s_integration_benchmark 7.903 ± 0.088 7.848 8.147 1.02 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.234 ± 0.014 2.212 2.256 1.00 ± 0.01
head compare_arrays_200000 2.233 ± 0.010 2.211 2.244 1.00
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.452 ± 0.014 1.438 1.492 1.01 ± 0.01
head dict_integration_benchmark 1.440 ± 0.004 1.432 1.445 1.00
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.246 ± 0.007 1.237 1.260 1.00
head field_arithmetic_get_square_benchmark 1.251 ± 0.015 1.242 1.293 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 7.825 ± 0.042 7.768 7.898 1.00
head integration_builtins 7.916 ± 0.034 7.865 7.960 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 8.084 ± 0.023 8.051 8.114 1.00
head keccak_integration_benchmark 8.201 ± 0.019 8.171 8.229 1.01 ± 0.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.199 ± 0.015 2.179 2.233 1.00
head linear_search 2.209 ± 0.015 2.185 2.235 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.533 ± 0.005 1.528 1.546 1.00
head math_cmp_and_pow_integration_benchmark 1.537 ± 0.006 1.529 1.548 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.483 ± 0.004 1.477 1.489 1.00 ± 0.00
head math_integration_benchmark 1.481 ± 0.003 1.474 1.484 1.00
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.224 ± 0.004 1.216 1.230 1.00
head memory_integration_benchmark 1.236 ± 0.007 1.224 1.247 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.607 ± 0.014 1.595 1.643 1.00 ± 0.01
head operations_with_data_structures_benchmarks 1.604 ± 0.010 1.593 1.631 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 540.6 ± 4.6 537.6 553.0 1.00
head pedersen 541.8 ± 3.2 538.5 548.8 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 647.6 ± 4.2 638.9 652.9 1.00
head poseidon_integration_benchmark 653.9 ± 2.4 650.4 657.0 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.847 ± 0.017 1.827 1.877 1.00
head secp_integration_benchmark 1.863 ± 0.022 1.847 1.922 1.01 ± 0.02
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 630.0 ± 0.9 628.8 631.3 1.00
head set_integration_benchmark 681.0 ± 1.9 678.2 684.1 1.08 ± 0.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.312 ± 0.030 4.274 4.381 1.00
head uint256_integration_benchmark 4.334 ± 0.016 4.297 4.363 1.00 ± 0.01

@dorimedini-starkware dorimedini-starkware force-pushed the dori/prevent-segment-execution branch 5 times, most recently from f94c831 to a3c1001 Compare May 25, 2025 15:06
@codecov
Copy link

codecov bot commented May 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.66%. Comparing base (cd6164e) to head (9f2c412).
Report is 1 commits behind head on 2.x.y.

Additional details and impacted files
@@           Coverage Diff           @@
##            2.x.y    #2099   +/-   ##
=======================================
  Coverage   96.65%   96.66%           
=======================================
  Files         103      103           
  Lines       43548    43645   +97     
=======================================
+ Hits        42093    42190   +97     
  Misses       1455     1455           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dorimedini-starkware dorimedini-starkware force-pushed the dori/prevent-segment-execution branch 2 times, most recently from 02d88ce to 7b20139 Compare May 26, 2025 12:01
@dorimedini-starkware dorimedini-starkware changed the title feat: implemented prevent_segment_execution function feat: implemented delete_unaccessed function May 27, 2025
@dorimedini-starkware dorimedini-starkware force-pushed the dori/prevent-segment-execution branch from 7b20139 to 79e6554 Compare May 27, 2025 07:21
@dorimedini-starkware dorimedini-starkware force-pushed the dori/prevent-segment-execution branch 2 times, most recently from 7fe90b9 to 3908d84 Compare May 27, 2025 12:38
@dorimedini-starkware dorimedini-starkware force-pushed the dori/prevent-segment-execution branch from 3908d84 to 668dd3b Compare May 28, 2025 15:29
Copy link
Contributor

@JulianGCalderon JulianGCalderon left a comment

Choose a reason for hiding this comment

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

LGTM, Could you add a link to the related OS code in the description?

@dorimedini-starkware
Copy link
Collaborator Author

LGTM, Could you add a link to the related OS code in the description?

done

@dorimedini-starkware
Copy link
Collaborator Author

LGTM, Could you add a link to the related OS code in the description?

done

Could you add the link in the delete_unaccessed documentation?

done

@dorimedini-starkware dorimedini-starkware force-pushed the dori/prevent-segment-execution branch from a1c9e5f to 9f2c412 Compare May 28, 2025 17:28
Copy link
Contributor

@JulianGCalderon JulianGCalderon left a comment

Choose a reason for hiding this comment

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

LGTM

@gabrielbosio gabrielbosio added this pull request to the merge queue May 28, 2025
Merged via the queue into 2.x.y with commit 5dde706 May 28, 2025
92 checks passed
@gabrielbosio gabrielbosio deleted the dori/prevent-segment-execution branch May 28, 2025 18:32
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.

6 participants