Skip to content

Add test for simulated builtins #2167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 20, 2025
Merged

Add test for simulated builtins #2167

merged 13 commits into from
Aug 20, 2025

Conversation

JulianGCalderon
Copy link
Contributor

@JulianGCalderon JulianGCalderon commented Aug 12, 2025

Add test for simulated builtins

This PR adds an usage example (and test) for the simulated builtins feature.

When a builtin is specified in the layout of the Cairo runner, then:

  1. The associated builtin runner is initialized before execution.
  2. The builtin segment pointer is passed as an argument to the program.
  3. Reading and writing to the builtin segment is automatically managed by the builtin runner.
  4. The builtin will be proved by dedicated AIRs after execution.

The PR #1956 introduced a way of using builtins without being specified in the layout. This implies that some of the steps mentioned must me done manually.

  1. The simulated builtin runners must be initialized manually.
  2. A mechanism is needed for accessing the builtin segment from the Cairo program. The example simulated_builtins.cairo uses a hint for this.
  3. Reading and writing to the builtin segment is automatically managed by the simulated builtin runner. (just like before)
  4. At the end of the execution (in the Cairo program), we must verify the correctness of the simulated builtin runner. See simple_bootloader.cairo for an example.

Closes #2155

Copy link

github-actions bot commented Aug 12, 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 ± σ):     24.412 s ±  0.186 s    [User: 23.525 s, System: 0.885 s]
  Range (min … max):   24.280 s … 24.544 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     24.246 s ±  0.017 s    [User: 23.391 s, System: 0.852 s]
  Range (min … max):   24.234 s … 24.258 s    2 runs
 
Summary
  hyper_threading_pr threads: 1 ran
    1.01 ± 0.01 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 ± σ):     13.249 s ±  0.023 s    [User: 23.573 s, System: 0.906 s]
  Range (min … max):   13.233 s … 13.266 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     13.250 s ±  0.056 s    [User: 23.571 s, System: 0.906 s]
  Range (min … max):   13.210 s … 13.289 s    2 runs
 
Summary
  hyper_threading_main threads: 2 ran
    1.00 ± 0.00 times faster than hyper_threading_pr 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 ± σ):      9.925 s ±  0.208 s    [User: 36.339 s, System: 1.082 s]
  Range (min … max):    9.778 s … 10.071 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):     10.082 s ±  0.224 s    [User: 35.869 s, System: 1.031 s]
  Range (min … max):    9.924 s … 10.241 s    2 runs
 
Summary
  hyper_threading_main threads: 4 ran
    1.02 ± 0.03 times faster than hyper_threading_pr 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 ± σ):      9.857 s ±  0.044 s    [User: 36.330 s, System: 1.095 s]
  Range (min … max):    9.826 s …  9.888 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):      9.748 s ±  0.037 s    [User: 36.514 s, System: 1.102 s]
  Range (min … max):    9.722 s …  9.774 s    2 runs
 
Summary
  hyper_threading_pr threads: 6 ran
    1.01 ± 0.01 times faster than hyper_threading_main 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 ± σ):      9.873 s ±  0.237 s    [User: 36.555 s, System: 1.115 s]
  Range (min … max):    9.705 s … 10.041 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):      9.840 s ±  0.082 s    [User: 36.512 s, System: 1.110 s]
  Range (min … max):    9.782 s …  9.898 s    2 runs
 
Summary
  hyper_threading_pr threads: 8 ran
    1.00 ± 0.03 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 ± σ):      9.995 s ±  0.139 s    [User: 36.801 s, System: 1.174 s]
  Range (min … max):    9.897 s … 10.094 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):      9.889 s ±  0.004 s    [User: 36.722 s, System: 1.187 s]
  Range (min … max):    9.886 s …  9.892 s    2 runs
 
Summary
  hyper_threading_pr threads: 16 ran
    1.01 ± 0.01 times faster than hyper_threading_main threads: 16


Copy link

github-actions bot commented Aug 12, 2025

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.056 ± 0.026 2.028 2.122 1.00 ± 0.02
head big_factorial 2.055 ± 0.032 2.025 2.115 1.00
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 1.969 ± 0.020 1.954 2.019 1.00 ± 0.01
head big_fibonacci 1.966 ± 0.009 1.955 1.985 1.00
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 7.036 ± 0.029 7.005 7.104 1.00
head blake2s_integration_benchmark 7.084 ± 0.049 7.013 7.148 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.111 ± 0.010 2.094 2.129 1.00
head compare_arrays_200000 2.115 ± 0.009 2.105 2.133 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.389 ± 0.005 1.383 1.398 1.00
head dict_integration_benchmark 1.410 ± 0.008 1.396 1.422 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.171 ± 0.004 1.167 1.179 1.00
head field_arithmetic_get_square_benchmark 1.189 ± 0.005 1.182 1.197 1.02 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 7.156 ± 0.034 7.106 7.214 1.00
head integration_builtins 7.161 ± 0.018 7.134 7.187 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 7.202 ± 0.040 7.145 7.286 1.00
head keccak_integration_benchmark 7.203 ± 0.024 7.162 7.239 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.083 ± 0.006 2.075 2.094 1.00 ± 0.01
head linear_search 2.081 ± 0.017 2.067 2.120 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.470 ± 0.015 1.454 1.496 1.00
head math_cmp_and_pow_integration_benchmark 1.479 ± 0.015 1.465 1.518 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.414 ± 0.006 1.406 1.425 1.00
head math_integration_benchmark 1.428 ± 0.010 1.419 1.455 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.188 ± 0.012 1.177 1.220 1.00 ± 0.01
head memory_integration_benchmark 1.186 ± 0.006 1.177 1.195 1.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.499 ± 0.017 1.485 1.543 1.00
head operations_with_data_structures_benchmarks 1.505 ± 0.004 1.498 1.514 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 521.6 ± 3.8 518.5 532.0 1.00 ± 0.01
head pedersen 519.4 ± 1.6 517.0 521.9 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 595.7 ± 4.8 591.1 604.8 1.00 ± 0.01
head poseidon_integration_benchmark 595.0 ± 2.1 591.3 598.4 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.749 ± 0.008 1.742 1.765 1.00
head secp_integration_benchmark 1.754 ± 0.012 1.745 1.781 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 619.2 ± 2.2 616.0 623.1 1.00 ± 0.00
head set_integration_benchmark 619.0 ± 1.4 617.3 622.4 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.021 ± 0.046 3.992 4.145 1.00
head uint256_integration_benchmark 4.023 ± 0.016 4.005 4.061 1.00 ± 0.01

Copy link

codecov bot commented Aug 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.68%. Comparing base (cfe117c) to head (916f768).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2167   +/-   ##
=======================================
  Coverage   96.67%   96.68%           
=======================================
  Files         103      104    +1     
  Lines       43954    44014   +60     
=======================================
+ Hits        42493    42553   +60     
  Misses       1461     1461           

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

@JulianGCalderon JulianGCalderon added the tests Implementation of tests label Aug 12, 2025
@JulianGCalderon JulianGCalderon marked this pull request as ready for review August 12, 2025 20:40
@gabrielbosio gabrielbosio enabled auto-merge August 20, 2025 12:41
@gabrielbosio gabrielbosio added this pull request to the merge queue Aug 20, 2025
Merged via the queue into main with commit c42f95a Aug 20, 2025
93 checks passed
@gabrielbosio gabrielbosio deleted the simulated-builtin-test branch August 20, 2025 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Implementation of tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tests for simulated builtin runners usage
4 participants