Skip to content

[2.11.1] Implement blake libfunc #1160

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Conversation

FrancoGiachetta
Copy link
Contributor

This PR implements both blake related libfuncs

Closes #1148, #1149

/// The blake2s compress function, which takes a state, a byte count, and a message, and returns a
/// new state.
/// `byte_count` should be the total number of bytes hashed after hashing the current `msg`.
pub extern fn blake2s_compress(
    state: Blake2sState, byte_count: u32, msg: Blake2sInput,
) -> Blake2sState nopanic;


/// Similar to `blake2s_compress`, but used for the final block of the message.
pub extern fn blake2s_finalize(
    state: Blake2sState, byte_count: u32, msg: Blake2sInput,
) -> Blake2sState nopanic;

Checklist

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.

Copy link

github-actions bot commented Mar 31, 2025

Benchmark results Main vs HEAD.

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_insert.cairo (JIT) 5.460 ± 0.046 5.399 5.532 1.03 ± 0.01
base dict_insert.cairo (AOT) 5.276 ± 0.054 5.194 5.374 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_insert.cairo (JIT) 5.058 ± 0.034 5.022 5.131 1.02 ± 0.01
head dict_insert.cairo (AOT) 4.970 ± 0.042 4.922 5.063 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_snapshot.cairo (JIT) 5.293 ± 0.076 5.196 5.393 1.00 ± 0.02
base dict_snapshot.cairo (AOT) 5.281 ± 0.049 5.197 5.373 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_snapshot.cairo (JIT) 4.973 ± 0.034 4.920 5.034 1.03 ± 0.01
head dict_snapshot.cairo (AOT) 4.841 ± 0.046 4.765 4.899 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base factorial_2M.cairo (JIT) 5.746 ± 0.051 5.689 5.845 1.02 ± 0.01
base factorial_2M.cairo (AOT) 5.618 ± 0.044 5.558 5.693 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head factorial_2M.cairo (JIT) 5.318 ± 0.050 5.265 5.429 1.00
head factorial_2M.cairo (AOT) 5.351 ± 0.078 5.232 5.450 1.01 ± 0.02

Base

Command Mean [s] Min [s] Max [s] Relative
base fib_2M.cairo (JIT) 5.150 ± 0.065 5.048 5.264 1.00
base fib_2M.cairo (AOT) 5.157 ± 0.042 5.083 5.222 1.00 ± 0.02

Head

Command Mean [s] Min [s] Max [s] Relative
head fib_2M.cairo (JIT) 4.835 ± 0.037 4.794 4.898 1.00
head fib_2M.cairo (AOT) 4.850 ± 0.059 4.759 4.932 1.00 ± 0.01

Base

Command Mean [s] Min [s] Max [s] Relative
base linear_search.cairo (JIT) 5.476 ± 0.033 5.434 5.534 1.03 ± 0.01
base linear_search.cairo (AOT) 5.314 ± 0.068 5.214 5.403 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head linear_search.cairo (JIT) 5.205 ± 0.156 5.011 5.448 1.04 ± 0.04
head linear_search.cairo (AOT) 5.007 ± 0.092 4.883 5.211 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base logistic_map.cairo (JIT) 5.537 ± 0.059 5.426 5.633 1.03 ± 0.02
base logistic_map.cairo (AOT) 5.378 ± 0.054 5.278 5.441 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head logistic_map.cairo (JIT) 5.141 ± 0.028 5.100 5.175 1.04 ± 0.01
head logistic_map.cairo (AOT) 4.952 ± 0.033 4.907 4.995 1.00

Copy link

github-actions bot commented Mar 31, 2025

Benchmarking results

Benchmark for program dict_insert

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 11.482 ± 0.053 11.428 11.600 2.29 ± 0.02
cairo-native (embedded AOT) 5.018 ± 0.027 4.968 5.055 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 5.148 ± 0.075 5.038 5.263 1.03 ± 0.02

Benchmark for program dict_snapshot

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 808.7 ± 10.3 797.1 825.5 1.00
cairo-native (embedded AOT) 4906.5 ± 21.6 4873.7 4936.3 6.07 ± 0.08
cairo-native (embedded JIT using LLVM's ORC Engine) 5025.5 ± 50.0 4950.8 5112.5 6.21 ± 0.10

Benchmark for program factorial_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 5.284 ± 0.042 5.189 5.334 1.00
cairo-native (embedded AOT) 5.305 ± 0.027 5.258 5.338 1.00 ± 0.01
cairo-native (embedded JIT using LLVM's ORC Engine) 5.361 ± 0.029 5.315 5.414 1.01 ± 0.01

Benchmark for program fib_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 5.099 ± 0.015 5.067 5.115 1.05 ± 0.01
cairo-native (embedded AOT) 4.853 ± 0.031 4.810 4.897 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 4.866 ± 0.030 4.828 4.928 1.00 ± 0.01

Benchmark for program linear_search

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 836.8 ± 8.6 824.7 850.3 1.00
cairo-native (embedded AOT) 4950.7 ± 35.1 4915.5 5026.5 5.92 ± 0.07
cairo-native (embedded JIT using LLVM's ORC Engine) 5087.1 ± 32.6 5049.4 5165.7 6.08 ± 0.07

Benchmark for program logistic_map

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 541.3 ± 9.9 535.6 568.7 1.00
cairo-native (embedded AOT) 5001.2 ± 31.4 4954.0 5053.8 9.24 ± 0.18
cairo-native (embedded JIT using LLVM's ORC Engine) 5187.6 ± 27.3 5149.8 5241.9 9.58 ± 0.18

@codecov-commenter
Copy link

codecov-commenter commented Mar 31, 2025

Codecov Report

Attention: Patch coverage is 98.72340% with 3 lines in your changes missing coverage. Please review.

Project coverage is 80.63%. Comparing base (1ac7239) to head (b7713dc).

Files with missing lines Patch % Lines
src/types.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1160      +/-   ##
==========================================
+ Coverage   80.47%   80.63%   +0.15%     
==========================================
  Files         110      112       +2     
  Lines       29571    29801     +230     
==========================================
+ Hits        23798    24030     +232     
+ Misses       5773     5771       -2     

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

@FrancoGiachetta FrancoGiachetta self-assigned this Mar 31, 2025
Copy link
Contributor

@JulianGCalderon JulianGCalderon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @FrancoGiachetta! Left you some comments.

Copy link

github-actions bot commented Apr 8, 2025

✅ Code is now correctly formatted.

Copy link
Contributor

@JulianGCalderon JulianGCalderon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR is OK, but I'm not sure adding the blake utils to Native is the right choice:

  • Can we import them from the Cairo VM
  • Can we move them to a math-specific crate?

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.

[2.11.1] Implement Blake2s Compress Libfunc
3 participants