-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add an experimental batch module #1134
Open
siv2r
wants to merge
9
commits into
bitcoin-core:master
Choose a base branch
from
siv2r:batch-verify-interface
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
db210f4
batch: Initialize an experimental batch module
siv2r e0dbd66
batch: Add `create` and `destroy` APIs
siv2r b7c7b58
batch, ecmult: Add `batch_verify` API and refactor `strauss_batch`
siv2r 9c120ef
batch: Add `batch_add_*` APIs
siv2r b3d370f
batch: Add API usage example
siv2r d0446a8
batch,ecmult: Add tests for core batch APIs and `strauss_batch` refactor
siv2r 8a77b2c
batch: Add tests for `batch_add_*` APIs
siv2r d3fbae5
batch, extrakeys: Add benchmark for batch verify and `tweak_add_check`
siv2r eb49e93
batch: Generate graphs for batch verification speed up
siv2r 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 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 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ valgrind_ctime_test | |
ecdh_example | ||
ecdsa_example | ||
schnorr_example | ||
batch_example | ||
*.exe | ||
*.so | ||
*.a | ||
|
This file contains 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 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 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 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 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,15 @@ | ||
# Schnorrsig Batch Verification Speedup | ||
|
||
![Speedup over single verification](speedup-batch/schnorrsig-speedup-batch.png) | ||
|
||
# Tweak Pubkey Check Batch Verification Speedup | ||
|
||
![Speedup over single verification](speedup-batch/tweakcheck-speedup-batch.png) | ||
|
||
Build steps | ||
----------- | ||
To generate the above graphs on your local machine: | ||
|
||
$ cd doc/speedup-batch | ||
$ make | ||
$ make speedup-batch.png |
This file contains 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 @@ | ||
*.dat |
This file contains 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,23 @@ | ||
schnorrsig_data = schnorrsig_batch.dat schnorrsig_single.dat | ||
tweak_data = tweak_batch.dat tweak_single.dat | ||
|
||
bench_output.txt: bench.sh | ||
SECP256K1_BENCH_ITERS=500000 ./bench.sh bench_output.txt | ||
|
||
schnorrsig_batch.dat: bench_output.txt | ||
cat bench_output.txt | grep -v "schnorrsig_batch_verify_1 " | awk '{ gsub(/ /,""); print }' | awk -F, 'match($$0, /schnorrsig_batch_verify_([0-9]+)/, arr) {print arr[1] " " $$3}' > schnorrsig_batch.dat | ||
|
||
schnorrsig_single.dat: bench_output.txt | ||
cat bench_output.txt | awk '{ gsub(/ /,""); print }' | awk -F, 'match($$0, /schnorrsig_verify/) {print $$3}' > schnorrsig_single.dat | ||
|
||
tweak_batch.dat: bench_output.txt | ||
cat bench_output.txt | grep -v "tweak_check_batch_verify_1 " | awk '{ gsub(/ /,""); print }' | awk -F, 'match($$0, /tweak_check_batch_verify_([0-9]+)/, arr) {print arr[1] " " $$3}' > tweak_batch.dat | ||
|
||
tweak_single.dat: bench_output.txt | ||
cat bench_output.txt | awk '{ gsub(/ /,""); print }' | awk -F, 'match($$0, /tweak_add_check/) {print $$3}' > tweak_single.dat | ||
|
||
speedup-batch.png: $(schnorrsig_data) $(tweak_data) plot.gp | ||
gnuplot plot.gp | ||
|
||
clean: | ||
rm *.log *.txt *.dat *.png |
This file contains 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,13 @@ | ||
#!/bin/bash | ||
|
||
output_file=$1 | ||
cur_dir=$(pwd) | ||
|
||
cd ../../ | ||
echo "HEAD: $(git rev-parse --short HEAD)" > "$cur_dir/$output_file.log" | ||
make clean | ||
./autogen.sh | ||
./configure --enable-experimental --enable-module-batch --enable-module-schnorrsig >> "$cur_dir/$output_file.log" | ||
make -j | ||
./bench schnorrsig > "$cur_dir/$output_file" | ||
./bench extrakeys >> "$cur_dir/$output_file" |
This file contains 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,137 @@ | ||
Benchmark , Min(us) , Avg(us) , Max(us) | ||
|
||
schnorrsig_sign , 50.4 , 50.5 , 50.7 | ||
schnorrsig_verify , 89.1 , 89.2 , 89.3 | ||
schnorrsig_batch_verify_1 , 104.0 , 104.0 , 104.0 | ||
schnorrsig_batch_verify_2 , 89.0 , 89.1 , 89.1 | ||
schnorrsig_batch_verify_3 , 84.1 , 84.1 , 84.1 | ||
schnorrsig_batch_verify_4 , 81.5 , 81.5 , 81.5 | ||
schnorrsig_batch_verify_5 , 79.9 , 79.9 , 79.9 | ||
schnorrsig_batch_verify_7 , 78.0 , 78.1 , 78.3 | ||
schnorrsig_batch_verify_9 , 77.0 , 77.0 , 77.1 | ||
schnorrsig_batch_verify_11 , 76.2 , 76.3 , 76.3 | ||
schnorrsig_batch_verify_14 , 75.6 , 75.6 , 75.6 | ||
schnorrsig_batch_verify_17 , 75.2 , 75.2 , 75.2 | ||
schnorrsig_batch_verify_21 , 74.8 , 74.8 , 74.8 | ||
schnorrsig_batch_verify_26 , 74.5 , 74.6 , 74.9 | ||
schnorrsig_batch_verify_32 , 74.3 , 74.5 , 74.7 | ||
schnorrsig_batch_verify_39 , 74.1 , 74.1 , 74.1 | ||
schnorrsig_batch_verify_47 , 73.9 , 73.9 , 73.9 | ||
schnorrsig_batch_verify_57 , 74.5 , 74.5 , 74.5 | ||
schnorrsig_batch_verify_69 , 74.3 , 74.3 , 74.5 | ||
schnorrsig_batch_verify_83 , 74.1 , 74.1 , 74.2 | ||
schnorrsig_batch_verify_100 , 73.9 , 74.0 , 74.1 | ||
schnorrsig_batch_verify_121 , 74.1 , 74.1 , 74.2 | ||
schnorrsig_batch_verify_146 , 73.9 , 73.9 , 74.0 | ||
schnorrsig_batch_verify_176 , 74.0 , 74.2 , 74.5 | ||
schnorrsig_batch_verify_212 , 73.9 , 74.1 , 74.1 | ||
schnorrsig_batch_verify_255 , 74.0 , 74.0 , 74.1 | ||
schnorrsig_batch_verify_307 , 73.9 , 74.0 , 74.1 | ||
schnorrsig_batch_verify_369 , 73.9 , 73.9 , 73.9 | ||
schnorrsig_batch_verify_443 , 73.9 , 74.1 , 74.3 | ||
schnorrsig_batch_verify_532 , 74.0 , 74.0 , 74.1 | ||
schnorrsig_batch_verify_639 , 73.9 , 74.0 , 74.0 | ||
schnorrsig_batch_verify_767 , 73.9 , 73.9 , 73.9 | ||
schnorrsig_batch_verify_921 , 74.0 , 74.0 , 74.1 | ||
schnorrsig_batch_verify_1106 , 73.9 , 73.9 , 73.9 | ||
schnorrsig_batch_verify_1328 , 73.9 , 74.1 , 74.2 | ||
schnorrsig_batch_verify_1594 , 74.0 , 74.1 , 74.1 | ||
schnorrsig_batch_verify_1913 , 74.0 , 74.0 , 74.0 | ||
schnorrsig_batch_verify_2296 , 74.0 , 74.0 , 74.0 | ||
schnorrsig_batch_verify_2756 , 73.9 , 74.0 , 74.1 | ||
schnorrsig_batch_verify_3308 , 74.1 , 74.1 , 74.2 | ||
schnorrsig_batch_verify_3970 , 74.1 , 74.2 , 74.4 | ||
schnorrsig_batch_verify_4765 , 74.0 , 74.1 , 74.2 | ||
schnorrsig_batch_verify_5719 , 74.0 , 74.1 , 74.1 | ||
schnorrsig_batch_verify_6863 , 74.0 , 74.1 , 74.1 | ||
schnorrsig_batch_verify_8236 , 74.0 , 74.1 , 74.1 | ||
schnorrsig_batch_verify_9884 , 74.0 , 74.1 , 74.3 | ||
schnorrsig_batch_verify_11861 , 74.0 , 74.0 , 74.1 | ||
schnorrsig_batch_verify_14234 , 73.9 , 74.0 , 74.1 | ||
schnorrsig_batch_verify_17081 , 73.9 , 73.9 , 73.9 | ||
schnorrsig_batch_verify_20498 , 73.9 , 74.0 , 74.0 | ||
schnorrsig_batch_verify_24598 , 73.9 , 74.0 , 74.1 | ||
schnorrsig_batch_verify_29518 , 73.9 , 74.0 , 74.1 | ||
schnorrsig_batch_verify_35422 , 73.9 , 73.9 , 73.9 | ||
schnorrsig_batch_verify_42507 , 73.9 , 74.0 , 74.0 | ||
schnorrsig_batch_verify_51009 , 73.9 , 74.1 , 74.3 | ||
schnorrsig_batch_verify_61211 , 73.9 , 73.9 , 74.0 | ||
schnorrsig_batch_verify_73454 , 73.9 , 74.0 , 74.3 | ||
schnorrsig_batch_verify_88145 , 73.9 , 74.0 , 74.1 | ||
schnorrsig_batch_verify_105775 , 74.0 , 74.1 , 74.1 | ||
schnorrsig_batch_verify_126931 , 73.9 , 74.0 , 74.1 | ||
schnorrsig_batch_verify_152318 , 73.9 , 73.9 , 74.0 | ||
schnorrsig_batch_verify_182782 , 73.9 , 73.9 , 74.0 | ||
schnorrsig_batch_verify_219339 , 73.9 , 73.9 , 74.0 | ||
schnorrsig_batch_verify_263207 , 74.0 , 74.1 , 74.3 | ||
schnorrsig_batch_verify_315849 , 73.9 , 74.0 , 74.0 | ||
schnorrsig_batch_verify_379019 , 73.9 , 73.9 , 73.9 | ||
schnorrsig_batch_verify_454823 , 74.0 , 74.0 , 74.0 | ||
Benchmark , Min(us) , Avg(us) , Max(us) | ||
|
||
tweak_add_check , 64.7 , 64.7 , 65.0 | ||
tweak_check_batch_verify_1 , 69.7 , 69.8 , 69.8 | ||
tweak_check_batch_verify_2 , 57.2 , 57.2 , 57.3 | ||
tweak_check_batch_verify_3 , 52.0 , 52.1 , 52.2 | ||
tweak_check_batch_verify_4 , 49.4 , 49.5 , 49.5 | ||
tweak_check_batch_verify_5 , 47.9 , 47.9 , 47.9 | ||
tweak_check_batch_verify_7 , 46.1 , 46.1 , 46.2 | ||
tweak_check_batch_verify_9 , 45.2 , 45.2 , 45.4 | ||
tweak_check_batch_verify_11 , 44.5 , 44.6 , 44.6 | ||
tweak_check_batch_verify_14 , 43.9 , 43.9 , 43.9 | ||
tweak_check_batch_verify_17 , 43.5 , 43.5 , 43.5 | ||
tweak_check_batch_verify_21 , 43.1 , 43.1 , 43.1 | ||
tweak_check_batch_verify_26 , 42.8 , 42.8 , 42.8 | ||
tweak_check_batch_verify_32 , 42.5 , 42.6 , 42.6 | ||
tweak_check_batch_verify_39 , 42.3 , 42.4 , 42.4 | ||
tweak_check_batch_verify_47 , 42.2 , 42.2 , 42.2 | ||
tweak_check_batch_verify_57 , 42.1 , 42.2 , 42.3 | ||
tweak_check_batch_verify_69 , 42.0 , 42.1 , 42.1 | ||
tweak_check_batch_verify_83 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_100 , 41.8 , 41.9 , 41.9 | ||
tweak_check_batch_verify_121 , 42.1 , 42.1 , 42.1 | ||
tweak_check_batch_verify_146 , 42.0 , 42.0 , 42.0 | ||
tweak_check_batch_verify_176 , 41.9 , 41.9 , 42.0 | ||
tweak_check_batch_verify_212 , 41.8 , 41.9 , 41.9 | ||
tweak_check_batch_verify_255 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_307 , 41.8 , 41.9 , 41.9 | ||
tweak_check_batch_verify_369 , 41.9 , 42.0 , 42.1 | ||
tweak_check_batch_verify_443 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_532 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_639 , 41.9 , 41.9 , 42.0 | ||
tweak_check_batch_verify_767 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_921 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_1106 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_1328 , 41.9 , 41.9 , 42.0 | ||
tweak_check_batch_verify_1594 , 41.9 , 41.9 , 42.0 | ||
tweak_check_batch_verify_1913 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_2296 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_2756 , 41.8 , 41.9 , 41.9 | ||
tweak_check_batch_verify_3308 , 41.9 , 41.9 , 42.0 | ||
tweak_check_batch_verify_3970 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_4765 , 41.8 , 41.9 , 41.9 | ||
tweak_check_batch_verify_5719 , 41.9 , 42.0 , 42.1 | ||
tweak_check_batch_verify_6863 , 42.0 , 42.0 , 42.0 | ||
tweak_check_batch_verify_8236 , 42.0 , 42.0 , 42.0 | ||
tweak_check_batch_verify_9884 , 41.9 , 41.9 , 42.0 | ||
tweak_check_batch_verify_11861 , 41.9 , 42.0 , 42.1 | ||
tweak_check_batch_verify_14234 , 41.9 , 42.0 , 42.0 | ||
tweak_check_batch_verify_17081 , 41.8 , 41.9 , 41.9 | ||
tweak_check_batch_verify_20498 , 41.8 , 41.9 , 41.9 | ||
tweak_check_batch_verify_24598 , 41.8 , 41.9 , 41.9 | ||
tweak_check_batch_verify_29518 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_35422 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_42507 , 41.8 , 41.8 , 41.9 | ||
tweak_check_batch_verify_51009 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_61211 , 41.8 , 41.8 , 41.8 | ||
tweak_check_batch_verify_73454 , 41.8 , 42.0 , 42.2 | ||
tweak_check_batch_verify_88145 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_105775 , 41.8 , 41.8 , 41.8 | ||
tweak_check_batch_verify_126931 , 41.8 , 41.9 , 41.9 | ||
tweak_check_batch_verify_152318 , 41.8 , 41.9 , 42.0 | ||
tweak_check_batch_verify_182782 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_219339 , 41.9 , 42.0 , 42.0 | ||
tweak_check_batch_verify_263207 , 41.9 , 42.0 , 42.1 | ||
tweak_check_batch_verify_315849 , 41.9 , 41.9 , 41.9 | ||
tweak_check_batch_verify_379019 , 41.9 , 41.9 , 42.0 | ||
tweak_check_batch_verify_454823 , 41.9 , 41.9 , 41.9 |
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.
batch_verify_1 shouldn't be slower than non-batch verify. Is it possible to revert to using non-batch validation logic for this case?
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.
Not possible with the current design.
The non-batch validation (
secp256k1_schnorrsig_verify
) logic looks something like this:rj
usingsecp256k1_ecmult
: Rj = sG - ePrj
(gej) tor
(ge)r.x = sig[0:32]
andr.y = even
one schnorrsig occupies two points in the batch, and one tweak check occupies one point in the batch. If a batch contains two points, there is no guarantee that they are from a schnorrsig (R, P). It could be from two tweak checks. So, we can't use the
r.y = even
check.Hence, I tried implementing a slightly modified
schnorrsig_verify
logic (not implement in this PR):neg_rj
usingsecp256k1_ecmult
:neg_Rj = -s*G + batch.scalars[1]*batch.points[1]
neg_rj + batch.points[0] == inf
using_gej_add_var
batch.scalars[0] = 1
always. So, we don't need to useecmult
againThis gives somewhat better benchmarks than before:
But
schnorrsig_batch_verify_1
is still slower thanschnorrsig_verify
.