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 Blake2s opcode in runner #1927

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ohad-nir-starkware
Copy link
Collaborator

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

Blake2s opcode runner

Description

Adding the opcode Blake2s 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 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 (non last block) Blake2s compression and the 9th is the updated counter.
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 Blake2s has opcode_num 8, meaning encoded_instr can use all 64 bits and InstructionNonZeroHighBits is no longer needed as 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 26, 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 ± σ):     32.122 s ±  0.003 s    [User: 31.347 s, System: 0.773 s]
  Range (min … max):   32.120 s … 32.124 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     31.690 s ±  0.025 s    [User: 30.898 s, System: 0.790 s]
  Range (min … max):   31.672 s … 31.707 s    2 runs
 
Summary
  hyper_threading_pr threads: 1 ran
    1.01 ± 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 ± σ):     17.895 s ±  0.013 s    [User: 31.360 s, System: 0.806 s]
  Range (min … max):   17.886 s … 17.904 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     17.647 s ±  0.058 s    [User: 30.870 s, System: 0.787 s]
  Range (min … max):   17.606 s … 17.688 s    2 runs
 
Summary
  hyper_threading_pr threads: 2 ran
    1.01 ± 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.071 s ±  0.323 s    [User: 44.268 s, System: 0.917 s]
  Range (min … max):   11.842 s … 12.299 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):     12.485 s ±  0.280 s    [User: 43.887 s, System: 0.957 s]
  Range (min … max):   12.287 s … 12.683 s    2 runs
 
Summary
  hyper_threading_main threads: 4 ran
    1.03 ± 0.04 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 ± σ):     12.317 s ±  0.223 s    [User: 44.065 s, System: 0.934 s]
  Range (min … max):   12.160 s … 12.475 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):     12.116 s ±  0.288 s    [User: 44.046 s, System: 0.928 s]
  Range (min … max):   11.913 s … 12.320 s    2 runs
 
Summary
  hyper_threading_pr threads: 6 ran
    1.02 ± 0.03 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.892 s ±  0.294 s    [User: 44.406 s, System: 0.961 s]
  Range (min … max):   11.684 s … 12.100 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):     11.973 s ±  0.104 s    [User: 44.476 s, System: 0.968 s]
  Range (min … max):   11.900 s … 12.046 s    2 runs
 
Summary
  hyper_threading_main threads: 8 ran
    1.01 ± 0.03 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 ± σ):     11.829 s ±  0.057 s    [User: 44.476 s, System: 1.025 s]
  Range (min … max):   11.789 s … 11.870 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):     12.041 s ±  0.286 s    [User: 44.507 s, System: 1.051 s]
  Range (min … max):   11.839 s … 12.242 s    2 runs
 
Summary
  hyper_threading_main threads: 16 ran
    1.02 ± 0.02 times faster than hyper_threading_pr threads: 16


@ohad-nir-starkware ohad-nir-starkware force-pushed the ohadn/blake2s_opcode_runner branch from 4f6a596 to 13d5632 Compare January 26, 2025 19:06
@ohad-nir-starkware ohad-nir-starkware removed the request for review from YairVaknin-starkware January 26, 2025 19:34
Copy link

codecov bot commented Jan 26, 2025

Codecov Report

Attention: Patch coverage is 98.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 96.33%. Comparing base (5af5924) to head (da32b91).

Files with missing lines Patch % Lines
vm/src/vm/vm_core.rs 97.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1927      +/-   ##
==========================================
- Coverage   96.34%   96.33%   -0.01%     
==========================================
  Files         102      102              
  Lines       40830    40894      +64     
==========================================
+ Hits        39336    39397      +61     
- Misses       1494     1497       +3     

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

Copy link

github-actions bot commented Jan 27, 2025

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.537 ± 0.071 2.474 2.726 1.02 ± 0.03
head big_factorial 2.498 ± 0.026 2.473 2.543 1.00
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.472 ± 0.030 2.425 2.521 1.00
head big_fibonacci 2.503 ± 0.096 2.419 2.765 1.01 ± 0.04
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 9.404 ± 0.446 9.105 10.565 1.03 ± 0.05
head blake2s_integration_benchmark 9.132 ± 0.203 8.991 9.511 1.00
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.563 ± 0.025 2.537 2.600 1.00
head compare_arrays_200000 2.581 ± 0.036 2.541 2.648 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.701 ± 0.033 1.671 1.766 1.00
head dict_integration_benchmark 1.714 ± 0.017 1.685 1.738 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.445 ± 0.015 1.419 1.472 1.00 ± 0.01
head field_arithmetic_get_square_benchmark 1.443 ± 0.015 1.416 1.467 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 9.258 ± 0.084 9.119 9.388 1.01 ± 0.02
head integration_builtins 9.194 ± 0.124 9.048 9.433 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 9.540 ± 0.114 9.394 9.780 1.02 ± 0.01
head keccak_integration_benchmark 9.390 ± 0.062 9.304 9.523 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.577 ± 0.038 2.532 2.638 1.00
head linear_search 2.594 ± 0.057 2.530 2.720 1.01 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.746 ± 0.032 1.713 1.819 1.00
head math_cmp_and_pow_integration_benchmark 1.747 ± 0.018 1.716 1.780 1.00 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.684 ± 0.014 1.658 1.705 1.00
head math_integration_benchmark 1.727 ± 0.060 1.689 1.887 1.03 ± 0.04
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.462 ± 0.029 1.423 1.506 1.00 ± 0.03
head memory_integration_benchmark 1.459 ± 0.023 1.429 1.491 1.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.824 ± 0.035 1.794 1.903 1.00 ± 0.02
head operations_with_data_structures_benchmarks 1.815 ± 0.025 1.793 1.872 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 585.8 ± 4.1 579.4 592.4 1.00
head pedersen 595.0 ± 5.4 588.6 607.5 1.02 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 715.5 ± 9.2 711.0 740.9 1.00
head poseidon_integration_benchmark 718.7 ± 2.8 714.1 723.0 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 2.086 ± 0.020 2.059 2.126 1.00 ± 0.01
head secp_integration_benchmark 2.081 ± 0.016 2.065 2.117 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 690.4 ± 6.7 682.1 700.5 1.00
head set_integration_benchmark 698.0 ± 9.3 688.3 719.8 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 5.116 ± 0.054 5.058 5.231 1.00 ± 0.02
head uint256_integration_benchmark 5.106 ± 0.096 5.006 5.278 1.00

@ohad-nir-starkware ohad-nir-starkware force-pushed the ohadn/blake2s_opcode_runner branch from 6738a48 to da32b91 Compare January 27, 2025 12:44
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