-
Notifications
You must be signed in to change notification settings - Fork 966
chore(experiment): refactor blake2 input parsing #2734
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6daf284
blake2 refactor
kevaundray bf3f86a
blake2 bench
kevaundray bec55f3
refactor benchmarks
kevaundray a2d4c13
fmt
kevaundray 3a47170
add 100K and 200K
kevaundray fae3ba9
blackbox
kevaundray cddba02
unwrap
kevaundray bb4f22e
refactor g
kevaundray fc38b65
Merge branch 'main' into kw/blake2-experiments
kevaundray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| use criterion::{black_box, BenchmarkGroup}; | ||
| use primitives::hex; | ||
| use revm_precompile::blake2; | ||
|
|
||
| pub fn add_benches(group: &mut BenchmarkGroup<'_, criterion::measurement::WallTime>) { | ||
| // Test vectors from the blake2 test | ||
| let inputs = [ | ||
| hex!("0000000248c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001"), // 2 rounds | ||
| hex!("0000000448c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b616162636465666768696a6b6c6d6e6f700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001"), // 4 rounds | ||
| hex!("0000004048c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001"), // 64 rounds | ||
| hex!("0000000a48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001"), // 10 rounds (Blake2s standard) | ||
| hex!("0000000c48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001"), // 12 rounds (Blake2b standard) | ||
| hex!("0000020048c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001"), // 512 rounds | ||
| hex!("0000040048c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001"), // 1024 rounds | ||
| hex!("000186a048c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001"), // 100000 rounds (100K) | ||
| hex!("00030d4048c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001"), // 200000 rounds (200K) | ||
| ]; | ||
|
|
||
| // Benchmark with 2 rounds | ||
| group.bench_function("blake2/2_rounds", |b| { | ||
| let input = &inputs[0]; // 2 rounds | ||
| b.iter(|| { | ||
| black_box(blake2::run(black_box(input), u64::MAX).unwrap()); | ||
| }); | ||
| }); | ||
|
|
||
| // Benchmark with 4 rounds | ||
| group.bench_function("blake2/4_rounds", |b| { | ||
| let input = &inputs[1]; // 4 rounds | ||
| b.iter(|| { | ||
| black_box(blake2::run(black_box(input), u64::MAX).unwrap()); | ||
| }); | ||
| }); | ||
|
|
||
| // Benchmark with 64 rounds | ||
| group.bench_function("blake2/64_rounds", |b| { | ||
| let input = &inputs[2]; // 64 rounds | ||
| b.iter(|| { | ||
| black_box(blake2::run(black_box(input), u64::MAX).unwrap()); | ||
| }); | ||
| }); | ||
|
|
||
| // Benchmark with 10 rounds (Blake2s standard) | ||
| group.bench_function("blake2/10_rounds", |b| { | ||
| let input = &inputs[3]; // 10 rounds | ||
| b.iter(|| { | ||
| black_box(blake2::run(black_box(input), u64::MAX).unwrap()); | ||
| }); | ||
| }); | ||
|
|
||
| // Benchmark with 12 rounds (Blake2b standard) | ||
| group.bench_function("blake2/12_rounds", |b| { | ||
| let input = &inputs[4]; // 12 rounds | ||
| b.iter(|| { | ||
| black_box(blake2::run(black_box(input), u64::MAX).unwrap()); | ||
| }); | ||
| }); | ||
|
|
||
| // Benchmark with 512 rounds | ||
| group.bench_function("blake2/512_rounds", |b| { | ||
| let input = &inputs[5]; // 512 rounds | ||
| b.iter(|| { | ||
| black_box(blake2::run(black_box(input), u64::MAX).unwrap()); | ||
| }); | ||
| }); | ||
|
|
||
| // Benchmark with 1024 rounds | ||
| group.bench_function("blake2/1024_rounds", |b| { | ||
| let input = &inputs[6]; // 1024 rounds | ||
| b.iter(|| { | ||
| black_box(blake2::run(black_box(input), u64::MAX).unwrap()); | ||
| }); | ||
| }); | ||
|
|
||
| // Benchmark with 100K rounds | ||
| group.bench_function("blake2/100K_rounds", |b| { | ||
| let input = &inputs[7]; // 100000 rounds | ||
| b.iter(|| { | ||
| black_box(blake2::run(black_box(input), u64::MAX).unwrap()); | ||
| }); | ||
| }); | ||
|
|
||
| // Benchmark with 200K rounds | ||
| group.bench_function("blake2/200K_rounds", |b| { | ||
| let input = &inputs[8]; // 200000 rounds | ||
| b.iter(|| { | ||
| black_box(blake2::run(black_box(input), u64::MAX).unwrap()); | ||
| }); | ||
| }); | ||
|
|
||
| // Benchmark just the compression function with different round counts | ||
| group.bench_function("blake2/compress_12_rounds", |b| { | ||
| let h = [ | ||
| 0x6a09e667f3bcc908u64, | ||
| 0xbb67ae8584caa73bu64, | ||
| 0x3c6ef372fe94f82bu64, | ||
| 0xa54ff53a5f1d36f1u64, | ||
| 0x510e527fade682d1u64, | ||
| 0x9b05688c2b3e6c1fu64, | ||
| 0x1f83d9abfb41bd6bu64, | ||
| 0x5be0cd19137e2179u64, | ||
| ]; | ||
| let m = [0u64; 16]; | ||
| let t = [0u64, 0u64]; | ||
| b.iter(|| { | ||
| let mut h_copy = h; | ||
| blake2::algo::compress( | ||
| black_box(12), | ||
| &mut h_copy, | ||
| black_box(m), | ||
| black_box(t), | ||
| black_box(false), | ||
| ); | ||
| }); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably fine as endiness is the same for all targets that have avx