Skip to content

Conversation

@FrancoGiachetta
Copy link
Contributor

@FrancoGiachetta FrancoGiachetta commented Mar 18, 2025

TITLE

Description

This PR solves an issue which was generated due to how we are loading the initial gas. Instead of doing it by executing an instruction, it is done in the rust side, updating the ap "by hand". Even though this is correct, there are other instructions like this one which rely on how many variables have already been allocated until that point to generate the correct instruction (it calls this method). Since there is no knowledge that the initial gas has been loaded, the casm builder does not take it into account and, thus, its variable counter is 1 unit behind the correct amount of current variables. This leads to instructions trying to access to memory cells which have already been written.

Refers to: #2011

Checklist

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

@github-actions
Copy link

github-actions bot commented Mar 18, 2025

**Hyper Thereading Benchmark results**




hyperfine -r 2 -n "hyper_threading_main threads: 1" 'RAYON_NUM_THREADS=1 ./hyper_threading_main' -n "hyper_threading_pr threads: 1" 'RAYON_NUM_THREADS=1 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 1
  Time (mean ± σ):     26.679 s ±  0.013 s    [User: 25.807 s, System: 0.870 s]
  Range (min … max):   26.670 s … 26.688 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     26.568 s ±  0.053 s    [User: 25.728 s, System: 0.838 s]
  Range (min … max):   26.531 s … 26.606 s    2 runs
 
Summary
  hyper_threading_pr threads: 1 ran
    1.00 ± 0.00 times faster than hyper_threading_main threads: 1




hyperfine -r 2 -n "hyper_threading_main threads: 2" 'RAYON_NUM_THREADS=2 ./hyper_threading_main' -n "hyper_threading_pr threads: 2" 'RAYON_NUM_THREADS=2 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 2
  Time (mean ± σ):     14.787 s ±  0.007 s    [User: 25.757 s, System: 0.906 s]
  Range (min … max):   14.781 s … 14.792 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     14.776 s ±  0.019 s    [User: 25.753 s, System: 0.897 s]
  Range (min … max):   14.763 s … 14.790 s    2 runs
 
Summary
  hyper_threading_pr threads: 2 ran
    1.00 ± 0.00 times faster than hyper_threading_main threads: 2




hyperfine -r 2 -n "hyper_threading_main threads: 4" 'RAYON_NUM_THREADS=4 ./hyper_threading_main' -n "hyper_threading_pr threads: 4" 'RAYON_NUM_THREADS=4 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 4
  Time (mean ± σ):     11.018 s ±  0.076 s    [User: 37.927 s, System: 1.007 s]
  Range (min … max):   10.964 s … 11.071 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):     10.623 s ±  0.126 s    [User: 37.596 s, System: 1.030 s]
  Range (min … max):   10.534 s … 10.712 s    2 runs
 
Summary
  hyper_threading_pr threads: 4 ran
    1.04 ± 0.01 times faster than hyper_threading_main threads: 4




hyperfine -r 2 -n "hyper_threading_main threads: 6" 'RAYON_NUM_THREADS=6 ./hyper_threading_main' -n "hyper_threading_pr threads: 6" 'RAYON_NUM_THREADS=6 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 6
  Time (mean ± σ):     10.547 s ±  0.012 s    [User: 38.275 s, System: 1.044 s]
  Range (min … max):   10.539 s … 10.555 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):     10.659 s ±  0.125 s    [User: 38.039 s, System: 1.053 s]
  Range (min … max):   10.571 s … 10.747 s    2 runs
 
Summary
  hyper_threading_main threads: 6 ran
    1.01 ± 0.01 times faster than hyper_threading_pr threads: 6




hyperfine -r 2 -n "hyper_threading_main threads: 8" 'RAYON_NUM_THREADS=8 ./hyper_threading_main' -n "hyper_threading_pr threads: 8" 'RAYON_NUM_THREADS=8 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 8
  Time (mean ± σ):     10.416 s ±  0.152 s    [User: 38.336 s, System: 1.054 s]
  Range (min … max):   10.308 s … 10.523 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):     10.253 s ±  0.014 s    [User: 38.826 s, System: 1.067 s]
  Range (min … max):   10.244 s … 10.263 s    2 runs
 
Summary
  hyper_threading_pr threads: 8 ran
    1.02 ± 0.01 times faster than hyper_threading_main threads: 8




hyperfine -r 2 -n "hyper_threading_main threads: 16" 'RAYON_NUM_THREADS=16 ./hyper_threading_main' -n "hyper_threading_pr threads: 16" 'RAYON_NUM_THREADS=16 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 16
  Time (mean ± σ):     10.496 s ±  0.159 s    [User: 38.588 s, System: 1.201 s]
  Range (min … max):   10.384 s … 10.608 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):     10.293 s ±  0.097 s    [User: 38.772 s, System: 1.169 s]
  Range (min … max):   10.225 s … 10.361 s    2 runs
 
Summary
  hyper_threading_pr threads: 16 ran
    1.02 ± 0.02 times faster than hyper_threading_main threads: 16


@github-actions
Copy link

github-actions bot commented Mar 18, 2025

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.111 ± 0.011 2.101 2.139 1.00
head big_factorial 2.132 ± 0.013 2.112 2.160 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.103 ± 0.050 2.033 2.156 1.03 ± 0.03
head big_fibonacci 2.051 ± 0.027 2.028 2.099 1.00
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 7.633 ± 0.157 7.470 7.920 1.00
head blake2s_integration_benchmark 7.744 ± 0.139 7.501 7.987 1.01 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.163 ± 0.011 2.153 2.187 1.00
head compare_arrays_200000 2.232 ± 0.063 2.164 2.350 1.03 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.483 ± 0.021 1.457 1.530 1.00
head dict_integration_benchmark 1.532 ± 0.039 1.476 1.588 1.03 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.245 ± 0.007 1.237 1.265 1.01 ± 0.01
head field_arithmetic_get_square_benchmark 1.238 ± 0.010 1.226 1.254 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 7.793 ± 0.238 7.583 8.208 1.01 ± 0.03
head integration_builtins 7.733 ± 0.124 7.615 8.015 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 7.896 ± 0.065 7.797 8.021 1.00
head keccak_integration_benchmark 7.997 ± 0.108 7.878 8.229 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.208 ± 0.051 2.156 2.291 1.03 ± 0.03
head linear_search 2.142 ± 0.018 2.125 2.189 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.514 ± 0.014 1.493 1.543 1.00
head math_cmp_and_pow_integration_benchmark 1.519 ± 0.011 1.504 1.545 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.451 ± 0.009 1.442 1.468 1.00
head math_integration_benchmark 1.455 ± 0.005 1.450 1.468 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.215 ± 0.006 1.210 1.228 1.00
head memory_integration_benchmark 1.233 ± 0.012 1.217 1.250 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.581 ± 0.020 1.556 1.613 1.01 ± 0.01
head operations_with_data_structures_benchmarks 1.562 ± 0.004 1.556 1.569 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 534.3 ± 3.7 530.9 541.6 1.00 ± 0.01
head pedersen 532.0 ± 1.1 530.6 533.6 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 637.2 ± 6.2 631.1 649.1 1.00
head poseidon_integration_benchmark 650.0 ± 6.7 642.7 666.2 1.02 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.842 ± 0.011 1.830 1.870 1.00
head secp_integration_benchmark 1.849 ± 0.008 1.840 1.867 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 624.6 ± 2.6 621.0 628.9 1.00
head set_integration_benchmark 628.1 ± 3.3 623.4 634.2 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.193 ± 0.027 4.148 4.235 1.00 ± 0.01
head uint256_integration_benchmark 4.183 ± 0.025 4.144 4.221 1.00

@codecov
Copy link

codecov bot commented Mar 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.53%. Comparing base (04e5e8d) to head (a4178d9).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2015   +/-   ##
=======================================
  Coverage   96.53%   96.53%           
=======================================
  Files         102      102           
  Lines       42725    42720    -5     
=======================================
- Hits        41245    41241    -4     
+ Misses       1480     1479    -1     

☔ 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.

@FrancoGiachetta FrancoGiachetta changed the title Fix WriteReturnFp and other issues related to the initial gas loading Fix CantWriteReturnFp and other issues related to the initial gas loading Mar 18, 2025
@gabrielbosio gabrielbosio added this pull request to the merge queue Mar 19, 2025
Merged via the queue into main with commit 5307101 Mar 19, 2025
93 checks passed
@gabrielbosio gabrielbosio deleted the fix-write-return-fp-error branch March 19, 2025 17:58
gabrielbosio pushed a commit that referenced this pull request May 21, 2025
…ding (#2015)

* fix issues like WriteReturnFp due to the gas builtin

* try fix tests and update changelog

* fix test
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