lambdaclass / cairo-vm

cairo-vm is a Rust implementation of the Cairo VM. Cairo (CPU Algebraic Intermediate Representation) is a programming language for writing provable programs, where one party can prove to another that a certain computation was executed correctly without the need for this party to re-execute the same program.
https://lambdaclass.github.io/cairo-vm
Apache License 2.0
485 stars 132 forks source link

[Cairo 1] Filter implicit arguments from return value #1775

Closed fmoletta closed 1 month ago

fmoletta commented 1 month ago

Currently, we take the last ret_type from the function's signature as the function's return type. This works well for programs that have a return values, or programs that don't return anything but don't use any implicit arguments. But when we run a program with implicit arguments (such as builtin pointers), the last ret_type will be an implicit return value's type, and the cli will panick when trying to serialize the program output. This PR checks if the last ret_type is an implicit type (aka builtins, gas, system type) and sets the return type to None if true.

github-actions[bot] commented 1 month ago
**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 ± σ):     28.011 s ±  0.034 s    [User: 27.204 s, System: 0.806 s]
  Range (min … max):   27.987 s … 28.035 s    2 runs

Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     28.068 s ±  0.021 s    [User: 27.243 s, System: 0.824 s]
  Range (min … max):   28.053 s … 28.083 s    2 runs

Summary
  'hyper_threading_main threads: 1' ran
    1.00 ± 0.00 times faster than 'hyper_threading_pr 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 ± σ):     15.301 s ±  0.320 s    [User: 27.747 s, System: 0.817 s]
  Range (min … max):   15.075 s … 15.527 s    2 runs

Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     15.041 s ±  0.017 s    [User: 27.383 s, System: 0.878 s]
  Range (min … max):   15.028 s … 15.053 s    2 runs

Summary
  'hyper_threading_pr threads: 2' ran
    1.02 ± 0.02 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.366 s ±  0.095 s    [User: 39.219 s, System: 0.975 s]
  Range (min … max):   11.299 s … 11.434 s    2 runs

Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):     11.077 s ±  0.437 s    [User: 39.163 s, System: 1.082 s]
  Range (min … max):   10.767 s … 11.386 s    2 runs

Summary
  'hyper_threading_pr threads: 4' ran
    1.03 ± 0.04 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.984 s ±  0.010 s    [User: 39.437 s, System: 0.922 s]
  Range (min … max):   10.977 s … 10.991 s    2 runs

Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):     10.872 s ±  0.157 s    [User: 39.471 s, System: 1.029 s]
  Range (min … max):   10.762 s … 10.983 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 ± σ):     10.701 s ±  0.032 s    [User: 39.916 s, System: 0.998 s]
  Range (min … max):   10.679 s … 10.724 s    2 runs

Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):     10.753 s ±  0.072 s    [User: 39.789 s, System: 1.036 s]
  Range (min … max):   10.702 s … 10.804 s    2 runs

Summary
  'hyper_threading_main threads: 8' ran
    1.00 ± 0.01 times faster than 'hyper_threading_pr 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.609 s ±  0.058 s    [User: 39.949 s, System: 1.101 s]
  Range (min … max):   10.568 s … 10.650 s    2 runs

Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):     11.061 s ±  0.251 s    [User: 40.982 s, System: 1.085 s]
  Range (min … max):   10.883 s … 11.238 s    2 runs

Summary
  'hyper_threading_main threads: 16' ran
    1.04 ± 0.02 times faster than 'hyper_threading_pr threads: 16'
codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 94.77%. Comparing base (26043e6) to head (5660763).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1775 +/- ## ======================================= Coverage 94.77% 94.77% ======================================= Files 101 101 Lines 38982 38991 +9 ======================================= + Hits 36944 36955 +11 + Misses 2038 2036 -2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

github-actions[bot] commented 1 month ago

Benchmark Results for unmodified programs :rocket:

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.102 ± 0.025 2.065 2.145 1.00
head big_factorial 2.108 ± 0.033 2.078 2.193 1.00 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.046 ± 0.012 2.021 2.061 1.00 ± 0.02
head big_fibonacci 2.043 ± 0.028 2.018 2.114 1.00
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 7.938 ± 0.469 7.690 9.224 1.00
head blake2s_integration_benchmark 8.149 ± 0.679 7.685 9.891 1.03 ± 0.10
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.182 ± 0.051 2.146 2.318 1.00 ± 0.02
head compare_arrays_200000 2.172 ± 0.016 2.147 2.204 1.00
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.416 ± 0.009 1.406 1.435 1.00
head dict_integration_benchmark 1.443 ± 0.019 1.424 1.494 1.02 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.312 ± 0.015 1.289 1.325 1.00 ± 0.02
head field_arithmetic_get_square_benchmark 1.310 ± 0.014 1.299 1.333 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 7.791 ± 0.119 7.672 7.946 1.00
head integration_builtins 7.826 ± 0.117 7.677 7.999 1.00 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 8.078 ± 0.103 7.938 8.233 1.00
head keccak_integration_benchmark 8.087 ± 0.122 7.935 8.237 1.00 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.122 ± 0.025 2.096 2.169 1.00
head linear_search 2.144 ± 0.023 2.119 2.203 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.706 ± 0.019 1.687 1.744 1.00
head math_cmp_and_pow_integration_benchmark 1.731 ± 0.037 1.708 1.835 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.614 ± 0.013 1.601 1.645 1.00
head math_integration_benchmark 1.622 ± 0.008 1.614 1.637 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.208 ± 0.007 1.201 1.221 1.00
head memory_integration_benchmark 1.229 ± 0.019 1.213 1.282 1.02 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.840 ± 0.043 1.808 1.934 1.00 ± 0.02
head operations_with_data_structures_benchmarks 1.837 ± 0.004 1.829 1.842 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 516.9 ± 2.3 513.0 519.4 1.00
head pedersen 518.7 ± 3.6 513.5 525.8 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 962.5 ± 7.2 955.7 978.6 1.00
head poseidon_integration_benchmark 973.5 ± 21.5 958.0 1032.2 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.877 ± 0.013 1.862 1.902 1.00 ± 0.01
head secp_integration_benchmark 1.872 ± 0.007 1.858 1.880 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 667.2 ± 2.8 663.7 673.6 1.00
head set_integration_benchmark 669.5 ± 1.9 666.6 672.6 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.267 ± 0.048 4.222 4.348 1.00
head uint256_integration_benchmark 4.387 ± 0.052 4.319 4.493 1.03 ± 0.02