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

Ohadn/blake2s last block opcode vm #1932

Open
wants to merge 2 commits into
base: ohadn/blake2s_opcode_runner
Choose a base branch
from

Conversation

ohad-nir-starkware
Copy link
Collaborator

Blake2sLastBlock opcode runner

Description

Adding the opcode Blake2sLastBlock to the VM.
Expects 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, the 9th represents the counter and the 10th represents counter+n_bytes i.e. the total length of the entire message.
The 16 felts of op1 represent a message.
The "output" consists of 8 felts representing u32 numbers of the Blake2s compression of the last block.
dst should be a pointer, it points to a sequence of 8 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 8 cells [dst], [dst+1], ... [dst+7] (and yields an error if one of said cells already contains a value differing from the output).

Currently Blake2sLastBlock has opcode_num 16, 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 Blake2sLastBlock 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.

@ohad-nir-starkware ohad-nir-starkware self-assigned this Jan 29, 2025
@ohad-nir-starkware ohad-nir-starkware changed the base branch from main to ohadn/blake2s_opcode_runner January 29, 2025 14:48
Copy link

**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 ± σ):     32.938 s ±  0.783 s    [User: 32.145 s, System: 0.792 s]
  Range (min … max):   32.385 s … 33.492 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     28.201 s ±  0.019 s    [User: 27.421 s, System: 0.778 s]
  Range (min … max):   28.187 s … 28.215 s    2 runs
 
Summary
  hyper_threading_pr threads: 1 ran
    1.17 ± 0.03 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 ± σ):     18.028 s ±  0.179 s    [User: 31.487 s, System: 0.806 s]
  Range (min … max):   17.902 s … 18.154 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     15.394 s ±  0.002 s    [User: 27.145 s, System: 0.805 s]
  Range (min … max):   15.392 s … 15.395 s    2 runs
 
Summary
  hyper_threading_pr threads: 2 ran
    1.17 ± 0.01 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.292 s ±  0.657 s    [User: 43.442 s, System: 0.942 s]
  Range (min … max):   11.827 s … 12.756 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):     11.563 s ±  0.066 s    [User: 41.485 s, System: 0.959 s]
  Range (min … max):   11.516 s … 11.609 s    2 runs
 
Summary
  hyper_threading_pr threads: 4 ran
    1.06 ± 0.06 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.086 s ±  0.421 s    [User: 43.591 s, System: 0.966 s]
  Range (min … max):   11.789 s … 12.384 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):     11.323 s ±  0.066 s    [User: 41.639 s, System: 0.967 s]
  Range (min … max):   11.277 s … 11.370 s    2 runs
 
Summary
  hyper_threading_pr threads: 6 ran
    1.07 ± 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 ± σ):     11.968 s ±  0.186 s    [User: 44.071 s, System: 1.016 s]
  Range (min … max):   11.837 s … 12.100 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):     11.296 s ±  0.166 s    [User: 41.996 s, System: 0.997 s]
  Range (min … max):   11.179 s … 11.413 s    2 runs
 
Summary
  hyper_threading_pr threads: 8 ran
    1.06 ± 0.02 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.979 s ±  0.600 s    [User: 44.352 s, System: 1.108 s]
  Range (min … max):   11.555 s … 12.404 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):     11.309 s ±  0.166 s    [User: 42.135 s, System: 1.076 s]
  Range (min … max):   11.192 s … 11.426 s    2 runs
 
Summary
  hyper_threading_pr threads: 16 ran
    1.06 ± 0.06 times faster than hyper_threading_main threads: 16


Copy link

github-actions bot commented Jan 29, 2025

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.539 ± 0.050 2.472 2.619 1.15 ± 0.02
head big_factorial 2.216 ± 0.021 2.194 2.257 1.00
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.479 ± 0.086 2.419 2.718 1.15 ± 0.04
head big_fibonacci 2.159 ± 0.022 2.138 2.202 1.00
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 9.152 ± 0.158 9.038 9.571 1.15 ± 0.02
head blake2s_integration_benchmark 7.977 ± 0.073 7.924 8.148 1.00
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.590 ± 0.030 2.558 2.659 1.14 ± 0.01
head compare_arrays_200000 2.265 ± 0.011 2.248 2.281 1.00
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.730 ± 0.042 1.700 1.835 1.15 ± 0.03
head dict_integration_benchmark 1.498 ± 0.005 1.492 1.507 1.00
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.464 ± 0.064 1.409 1.586 1.14 ± 0.05
head field_arithmetic_get_square_benchmark 1.280 ± 0.015 1.265 1.302 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 9.180 ± 0.053 9.089 9.247 1.14 ± 0.01
head integration_builtins 8.047 ± 0.058 7.971 8.145 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 9.631 ± 0.327 9.363 10.397 1.16 ± 0.04
head keccak_integration_benchmark 8.298 ± 0.064 8.199 8.394 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.532 ± 0.016 2.508 2.552 1.12 ± 0.01
head linear_search 2.257 ± 0.020 2.233 2.296 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.760 ± 0.025 1.737 1.814 1.11 ± 0.02
head math_cmp_and_pow_integration_benchmark 1.581 ± 0.013 1.567 1.604 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.722 ± 0.048 1.680 1.837 1.13 ± 0.03
head math_integration_benchmark 1.526 ± 0.005 1.517 1.537 1.00
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.437 ± 0.022 1.415 1.494 1.13 ± 0.02
head memory_integration_benchmark 1.272 ± 0.012 1.264 1.303 1.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.839 ± 0.031 1.809 1.917 1.11 ± 0.02
head operations_with_data_structures_benchmarks 1.652 ± 0.009 1.639 1.674 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 596.5 ± 9.4 588.0 620.7 1.09 ± 0.02
head pedersen 547.9 ± 2.2 545.7 552.3 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 690.8 ± 4.7 686.1 701.0 1.05 ± 0.02
head poseidon_integration_benchmark 660.8 ± 8.7 645.1 673.0 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 2.101 ± 0.021 2.076 2.144 1.09 ± 0.01
head secp_integration_benchmark 1.926 ± 0.009 1.915 1.941 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 747.4 ± 10.7 733.2 769.6 1.09 ± 0.02
head set_integration_benchmark 683.6 ± 2.6 680.0 689.2 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 5.175 ± 0.155 5.072 5.576 1.15 ± 0.04
head uint256_integration_benchmark 4.484 ± 0.030 4.453 4.534 1.00

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

Attention: Patch coverage is 98.38710% with 1 line in your changes missing coverage. Please review.

Project coverage is 96.34%. Comparing base (912b050) to head (4919048).

Files with missing lines Patch % Lines
cairo-vm-tracer/src/tracer_data.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                       Coverage Diff                       @@
##           ohadn/blake2s_opcode_runner    #1932      +/-   ##
===============================================================
- Coverage                        96.35%   96.34%   -0.02%     
===============================================================
  Files                              102      102              
  Lines                            41071    41087      +16     
===============================================================
+ Hits                             39574    39585      +11     
- Misses                            1497     1502       +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