Skip to content
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

implement blake opcode in runner #1922

Closed
wants to merge 1 commit into from
Closed

Conversation

ohad-nir-starkware
Copy link
Collaborator

@ohad-nir-starkware ohad-nir-starkware commented Jan 24, 2025

Blake2s opcode runner

Description

Adding two opcodes for Blake2s: Blake2s and Blake2sLastBlock.
Both expect op0 to be a pointer to a sequence of 9 felts and and op1 to be a pointer to a sequence of 16 felts.
Said felts should represent u32 integers, i.e. have value of at most 2**32-1.
The first 8 felts of op0 represent a state and the 9th represents a counter.
The 16 felts of op1 represent a message.
The "output" consists of 9 felts representing u32 numbers. The first 8 are the output of the appropriate Blake2s compression (either of a final block or a non final block) and the 9th is the updated counter.
in both cases dst should be a pointer, it points to a sequence of 9 cells which each should either be uninitialised or already contain a value matching that of the output at the same index.
The opcode inserts the aforementioned output into the 9 cells [dst], [dst+1], ... [dst+8] (and yields an error if one of said cells already contains a value differing from the output).

Currently Blake2sLastBlock assumes that [op1]!=0 and if 0<=j<=15 is the last index for which [op1+j]!=0 then the final block of the message is only 4*(j+1) bytes long.
Currently Blake2s and Blake2sLastBlock have opcode_num 8 and 16 respectively, meaning encoded_instr is expanded to 128 bits with the 63 most significant bits expected to be 0 (otherwise yield an error).

The motivation is that it has been decided at Starkware that Blake2s is to be implemented at an opcode, thus it needs to be supported by the runner.

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.

Copy link

github-actions bot commented Jan 24, 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 ± σ):     31.976 s ±  0.013 s    [User: 31.213 s, System: 0.762 s]
  Range (min … max):   31.967 s … 31.984 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     27.836 s ±  0.151 s    [User: 27.062 s, System: 0.771 s]
  Range (min … max):   27.729 s … 27.942 s    2 runs
 
Summary
  hyper_threading_pr threads: 1 ran
    1.15 ± 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 ± σ):     17.707 s ±  0.006 s    [User: 31.021 s, System: 0.796 s]
  Range (min … max):   17.703 s … 17.712 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     15.514 s ±  0.025 s    [User: 27.332 s, System: 0.769 s]
  Range (min … max):   15.497 s … 15.532 s    2 runs
 
Summary
  hyper_threading_pr threads: 2 ran
    1.14 ± 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 ± σ):     12.428 s ±  0.216 s    [User: 43.420 s, System: 0.925 s]
  Range (min … max):   12.275 s … 12.581 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):     11.589 s ±  0.435 s    [User: 40.749 s, System: 0.910 s]
  Range (min … max):   11.281 s … 11.896 s    2 runs
 
Summary
  hyper_threading_pr threads: 4 ran
    1.07 ± 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 ± σ):     12.188 s ±  0.405 s    [User: 43.707 s, System: 0.954 s]
  Range (min … max):   11.902 s … 12.474 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):     11.266 s ±  0.019 s    [User: 40.919 s, System: 0.938 s]
  Range (min … max):   11.253 s … 11.279 s    2 runs
 
Summary
  hyper_threading_pr threads: 6 ran
    1.08 ± 0.04 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 ± σ):     12.242 s ±  0.125 s    [User: 43.956 s, System: 0.982 s]
  Range (min … max):   12.154 s … 12.330 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):     11.176 s ±  0.035 s    [User: 41.093 s, System: 0.974 s]
  Range (min … max):   11.151 s … 11.201 s    2 runs
 
Summary
  hyper_threading_pr threads: 8 ran
    1.10 ± 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 ± σ):     11.781 s ±  0.257 s    [User: 44.297 s, System: 1.077 s]
  Range (min … max):   11.600 s … 11.963 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):     11.091 s ±  0.201 s    [User: 41.760 s, System: 1.053 s]
  Range (min … max):   10.949 s … 11.233 s    2 runs
 
Summary
  hyper_threading_pr threads: 16 ran
    1.06 ± 0.03 times faster than hyper_threading_main threads: 16


Copy link

github-actions bot commented Jan 24, 2025

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.538 ± 0.079 2.469 2.747 1.15 ± 0.04
head big_factorial 2.198 ± 0.012 2.185 2.225 1.00
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.458 ± 0.060 2.398 2.595 1.13 ± 0.03
head big_fibonacci 2.169 ± 0.010 2.154 2.182 1.00
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 9.165 ± 0.112 8.995 9.344 1.12 ± 0.02
head blake2s_integration_benchmark 8.213 ± 0.073 8.108 8.338 1.00
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.571 ± 0.040 2.535 2.665 1.13 ± 0.02
head compare_arrays_200000 2.285 ± 0.013 2.268 2.310 1.00
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.684 ± 0.046 1.650 1.788 1.11 ± 0.03
head dict_integration_benchmark 1.512 ± 0.013 1.498 1.543 1.00
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.421 ± 0.015 1.399 1.436 1.11 ± 0.01
head field_arithmetic_get_square_benchmark 1.286 ± 0.005 1.278 1.293 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 9.189 ± 0.115 9.063 9.325 1.11 ± 0.02
head integration_builtins 8.279 ± 0.070 8.184 8.377 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 9.420 ± 0.090 9.327 9.602 1.11 ± 0.01
head keccak_integration_benchmark 8.491 ± 0.059 8.406 8.602 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.585 ± 0.055 2.539 2.709 1.13 ± 0.03
head linear_search 2.283 ± 0.014 2.266 2.310 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.735 ± 0.042 1.708 1.850 1.11 ± 0.03
head math_cmp_and_pow_integration_benchmark 1.564 ± 0.005 1.558 1.571 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.705 ± 0.042 1.663 1.776 1.11 ± 0.03
head math_integration_benchmark 1.531 ± 0.006 1.523 1.539 1.00
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.431 ± 0.015 1.409 1.448 1.13 ± 0.01
head memory_integration_benchmark 1.268 ± 0.004 1.263 1.277 1.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.815 ± 0.032 1.779 1.894 1.10 ± 0.02
head operations_with_data_structures_benchmarks 1.648 ± 0.015 1.635 1.690 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 585.8 ± 5.8 578.2 593.2 1.07 ± 0.01
head pedersen 548.3 ± 1.5 545.6 550.1 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 698.2 ± 6.9 690.3 714.0 1.07 ± 0.01
head poseidon_integration_benchmark 655.2 ± 2.7 650.8 658.7 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 2.073 ± 0.015 2.047 2.088 1.08 ± 0.02
head secp_integration_benchmark 1.922 ± 0.031 1.900 2.004 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 682.3 ± 7.0 675.5 699.0 1.06 ± 0.01
head set_integration_benchmark 643.7 ± 2.6 641.0 649.1 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 5.084 ± 0.116 4.953 5.293 1.12 ± 0.03
head uint256_integration_benchmark 4.523 ± 0.018 4.497 4.550 1.00

@ohad-nir-starkware ohad-nir-starkware force-pushed the ohadn/blake-runner branch 2 times, most recently from 00b734b to f634f80 Compare January 25, 2025 09:04
Copy link

codecov bot commented Jan 25, 2025

Codecov Report

Attention: Patch coverage is 97.93814% with 4 lines in your changes missing coverage. Please review.

Project coverage is 96.34%. Comparing base (5af5924) to head (bc57aa5).

Files with missing lines Patch % Lines
vm/src/vm/vm_core.rs 92.59% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #1922    +/-   ##
========================================
  Coverage   96.34%   96.34%            
========================================
  Files         102      103     +1     
  Lines       40830    41012   +182     
========================================
+ Hits        39336    39513   +177     
- Misses       1494     1499     +5     

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

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.

1 participant