-
Notifications
You must be signed in to change notification settings - Fork 1
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
Schnorr Batch Verification Interface #2
base: master
Are you sure you want to change the base?
Conversation
dc2944f
to
2cc0fca
Compare
There are two possible ways to design the build for the batch interface.
I have implemented the no new module build since it is less time-consuming, and the top priority is to get feedback on batch API design. I would be happy to change to new batch module build later (if that makes more sense). |
ecc8446
to
0daec31
Compare
I wanted to place But that may not be possible since, the |
That
|
This is not true. Even though |
The src/modules/schnorrsig/main_impl.h:116:13: error: static declaration of ‘secp256k1_schnorrsig_challenge’ follows non-static declaration
In file included from src/modules/musig/main_impl.h:11,
from src/secp256k1.c:818:
src/modules/musig/session_impl.h:457:5: note: previous implicit declaration of ‘secp256k1_schnorrsig_challenge’ was here
457 | secp256k1_schnorrsig_challenge(&session_i.challenge, fin_nonce, msg32, 32, agg_pk32); |
I have added the Todo's to the description of this PR. A detailed version of it can be found here. |
8add7ce
to
22342d4
Compare
The batch verification interface is now available as an optional batch module (experimental). To enable all batch APIs and example: Option 1: ./configure --enable-experimental --enable-module-batch --enable-module-schnorrsig --enable-examples
make Option 2: ./configure --enable-dev-mode
make Option 2 will enable all libsecp features (except external callbacks and test coverage) |
I would like to get a second opinion on the following questions. Q: What happens if the user enables only the batch module? (i.e,
I prefer option 3 since option 1 and option 2 assume the user might incorrectly build libsecp. We can easily avoid this through simple documentation. Q: Where should the
Choosing one option over another doesn't seem to make much difference. |
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.
Q: What happens if the user enables only the batch module? (i.e, ./configure --enable-module-batch --enable-experimental)
Agree with your analysis that option 3, do nothing, makes the most sense at this point.
Q: Where should the batch_add_* APIs be present?
- but the tests for these function will be present in modules/batch/tests_impl.h
Why place the tests there? They could also be in the test files for extrakeys and schnorrsig which seems way more natural with option 1.
I prefer option 1 because then all the schnorr code is in the schnorr module. It's possible to see batching more as a compile time feature than a module. Then it makes sense in the schnorrsig module to test for that feature and if so we compile schnorrsig_batch_add
. Moreover, most of the logic in that function is related to Schnorr sigs and not batching.
5f659e6
to
851c038
Compare
Ah, I see. Then, it makes more sense to have tests in the schnorrsig module. |
8a1da31
to
5bb9c26
Compare
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.
Created commit that enables batch in CI (untested): https://github.com/jonasnick/secp256k1/commits/batch-verify-interface-jn
eb671ed
to
49cb21a
Compare
Thanks! I have included them. |
41ad09e
to
e8ba116
Compare
option 1:
Benchmark , Min(us) , Avg(us) , Max(us)
schnorrsig_verify , 144.0 , 148.0 , 155.0
schnorrsigs_batch_verify , 163.0 , 272.0 , 286.0
Benchmark , Min(us) , Avg(us) , Max(us)
schnorrsig_verify , 144.0 , 147.0 , 150.0
schnorrsigs_batch_verify , 161.0 , 716.0 , 1283.0
option 2:
Benchmark , Min(us) , Avg(us) , Max(us)
schnorrsig_verify , 144.0 , 146.0 , 150.0
schnorrsigs_batch_verify , 156.0 , 159.0 , 164.0
Benchmark , Min(us) , Avg(us) , Max(us)
schnorrsig_verify , 144.0 , 145.0 , 150.0
schnorrsigs_batch_verify , 157.0 , 158.0 , 163.0 Observations:
|
0a5b190
to
19a74a2
Compare
I have created a new branch ( I compared the batch verify execution time by varying the To generate the benchmark CSV file (for various
|
Currently:
|
7e98853
to
8cbf70d
Compare
The following commits fixed the CI test fails:
I should avoid pushing new code if CI fails. It makes debugging troublesome at a later stage :'( |
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.
I added a commit that refactors the strauss batch code. This results in less code duplication, so I think this is a bit better than the existing code. Feel free to cherry-pick if you agree
https://github.com/jonasnick/secp256k1/commits/batch-verify-interface-jn.
Ok, cool, I agree. I think "terms" is slightly better because it's more neutral and may be more likely to not confuse users (who have some preconceived notions about what points are and how they are used, etc.). |
Currently, /* Check that `max_terms` is less than half the maximum size_t value. This is necessary because
* `batch_add_schnorrsig` appends two (scalar, point) pairs for one signature */
ARG_CHECK(max_terms <= SIZE_MAX / 2);
/* Check that max_terms is less than 2^31 to ensure the same behavior of this function on 32-bit
* and 64-bit platforms. */
ARG_CHECK(max_terms < ((uint32_t)1 << 31)); Since we plan to allocate only the Should the second check be changed to Although this is not significant since we have an internal |
3b27149
to
cee343c
Compare
I think with the |
8e9204a
to
3262ff4
Compare
This commit generates graphs that visualize the batch verify speed up over single verification (y-axis) wrt the number of signatures (or tweak checks) in the batch. The input data points are taken from the batch verify benchmark. GNU plot was used to generate these graphs. The instructions to reproduce these graphs (on your local machine) are given in doc/speedup-batch.md The value of `STRAUSS_MAX_TERMS_PER_BATCH` was calculated (approx) from the generated graphs. Relevant discussion: #2 (comment)
This commit adds the foundational configuration, build scripts, and an initial structure for experimental batch module.
This commit adds the _batch_create and _batch_destroy APIs. Relevant Links: 1. _batch_scratch_size allocation formula is taken from bench ecmult: https://github.com/bitcoin-core/secp256k1/blob/694ce8fb2d1fd8a3d641d7c33705691d41a2a860/src/bench_ecmult.c#L312. 2. aux_rand16 param in _batch_create enables synthetic randomness for randomizer generation: sipa/bips#204.
This commit refactors _ecmult_strauss_batch and adds _batch_verify API. The current _ecmult_strauss_batch only works on empty scratch space. To make _batch_verify work, we need _ecmult_strauss_batch to support a scratch space pre-filled with scalars and points. So, it was refactored to do exactly that. The _batch_verify API always uses the Strauss algorithm. It doesn't switch to Pippenger (unlike _ecmult_multi_var). _ecmult_pippenger_batch represents points as secp256k1_ge whereas _ecmult_strauss_batch represents points as secp256k1_gej. This makes supporting both Pippenger and Strauss difficult (at least with the current batch object design). Hence, _batch_verify only supports Strauss for simplicity.
This commit adds the batch APIs: 1. _batch_add_schnorrsig Adds a Schnorr signature to the batch. 2. _batch_add_xonlypub_tweak_check Adds a tweaked x-only pubkey check to the batch. 3. _batch_usable Checks if a batch can be used by _batch_add_* APIs. **Side Note:** Exposing batch_add_schnorrsig in the `secp256k1_schnorrsig.h` header file (with batch module header guards) will force the user to define ENABLE_MODULE_BATCH during their code compilation. Hence, it is in a standalone `secp256k1_schnorrsig_batch` header file. A similar argument could be made for batch_add_xonlypub_tweak_check.
This commit adds an example C program using the batch API. GNU Autotools will compile this example only if both batch and schnorrsig modules are enabled.
9152baf
to
db210f4
Compare
This commit generates two semi-log graphs that visualize the batch verification speed up over single verification (y-axis) wrt the number of signatures (or tweak checks) in the batch (x-axis). The input data points are taken from the batch verify benchmark. GNU plot was used to generate these graphs (plot.gp file). The instructions to reproduce these graphs (on your local machine) are given in doc/speedup-batch.md file. The value of `STRAUSS_MAX_TERMS_PER_BATCH` was calculated (approx) from the generated graphs. Relevant discussion: #2 (comment)
This commit adds the following tests: 1. Cirrus scripts 2. Batch API tests (ordered) 3. Tagged SHA256 test 4. BIP340 test vectors: https://github.com/bitcoin/bips/blob/master/bip-0340/test-vectors.csv 5. Large random test for `strauss_batch` refactor
This commit adds the following tests: 1. Random bitflip test for randomizer generating function 2. Random bitflip in Schnorr Signature (_batch_add_schnorrsig test) 3. NULL arg tests (for both _batch_add APIs)
This commit generates two semi-log graphs that visualize the batch verification speed up over single verification (y-axis) wrt the number of signatures (or tweak checks) in the batch (x-axis). The input data points are taken from the batch verify benchmark. GNU plot was used to generate these graphs (plot.gp file). The instructions to reproduce these graphs (on your local machine) are given in doc/speedup-batch.md file. The value of `STRAUSS_MAX_TERMS_PER_BATCH` was calculated (approx) from the generated graphs. Relevant discussion: #2 (comment)
98f6bd6
to
f48072a
Compare
This commit adds benchmarks for Schnorr signature batch verification,Tweaked pubkey check batch verification, and Tweaked pubkey check (single verification). For batch verify benchmark, the number of sigs (or checks) in the batch varies from 1 to SECP256K1_BENCH_ITERS with a 20% increment.
This commit generates two semi-log graphs that visualize the batch verification speed up over single verification (y-axis) wrt the number of signatures (or tweak checks) in the batch (x-axis). The input data points are taken from the batch verify benchmark. GNU plot was used to generate these graphs (plot.gp file). The instructions to reproduce these graphs (on your local machine) are given in doc/speedup-batch.md file. The value of `STRAUSS_MAX_TERMS_PER_BATCH` was calculated (approx) from the generated graphs. Relevant discussion: #2 (comment)
f48072a
to
eb49e93
Compare
This commit generates two semi-log graphs that visualize the batch verification speed up over single verification (y-axis) wrt the number of signatures (or tweak checks) in the batch (x-axis). The input data points are taken from the batch verify benchmark. GNU plot was used to generate these graphs (plot.gp file). The instructions to reproduce these graphs (on your local machine) are given in doc/speedup-batch.md file. The value of `STRAUSS_MAX_TERMS_PER_BATCH` was calculated (approx) from the generated graphs. Relevant discussion: siv2r#2 (comment)
This commit generates two semi-log graphs that visualize the batch verification speed up over single verification (y-axis) wrt the number of signatures (or tweak checks) in the batch (x-axis). The input data points are taken from the batch verify benchmark. GNU plot was used to generate these graphs (plot.gp file). The instructions to reproduce these graphs (on your local machine) are given in doc/speedup-batch.md file. The value of `STRAUSS_MAX_TERMS_PER_BATCH` was calculated (approx) from the generated graphs. Relevant discussion: siv2r#2 (comment)
This commit generates two semi-log graphs that visualize the batch verification speed up over single verification (y-axis) wrt the number of signatures (or tweak checks) in the batch (x-axis). The input data points are taken from the batch verify benchmark. GNU plot was used to generate these graphs (plot.gp file). The instructions to reproduce these graphs (on your local machine) are given in doc/speedup-batch.md file. The value of `STRAUSS_MAX_TERMS_PER_BATCH` was calculated (approx) from the generated graphs. Relevant discussion: siv2r#2 (comment)
This commit generates two semi-log graphs that visualize the batch verification speed up over single verification (y-axis) wrt the number of signatures (or tweak checks) in the batch (x-axis). The input data points are taken from the batch verify benchmark. GNU plot was used to generate these graphs (plot.gp file). The instructions to reproduce these graphs (on your local machine) are given in doc/speedup-batch.md file. The value of `STRAUSS_MAX_TERMS_PER_BATCH` was calculated (approx) from the generated graphs. Relevant discussion: siv2r#2 (comment)
This commit generates two semi-log graphs that visualize the batch verification speed up over single verification (y-axis) wrt the number of signatures (or tweak checks) in the batch (x-axis). The input data points are taken from the batch verify benchmark. GNU plot was used to generate these graphs (plot.gp file). The instructions to reproduce these graphs (on your local machine) are given in doc/speedup-batch.md file. The value of `STRAUSS_MAX_TERMS_PER_BATCH` was calculated (approx) from the generated graphs. Relevant discussion: siv2r#2 (comment)
This commit generates two semi-log graphs that visualize the batch verification speed up over single verification (y-axis) wrt the number of signatures (or tweak checks) in the batch (x-axis). The input data points are taken from the batch verify benchmark. GNU plot was used to generate these graphs (plot.gp file). The instructions to reproduce these graphs (on your local machine) are given in doc/speedup-batch.md file. The value of `STRAUSS_MAX_TERMS_PER_BATCH` was calculated (approx) from the generated graphs. Relevant discussion: siv2r#2 (comment)
This commit generates two semi-log graphs that visualize the batch verification speed up over single verification (y-axis) wrt the number of signatures (or tweak checks) in the batch (x-axis). The input data points are taken from the batch verify benchmark. GNU plot was used to generate these graphs (plot.gp file). The instructions to reproduce these graphs (on your local machine) are given in doc/speedup-batch.md file. The value of `STRAUSS_MAX_TERMS_PER_BATCH` was calculated (approx) from the generated graphs. Relevant discussion: siv2r#2 (comment)
This PR implements the proof of concept for the batch verification interface proposed here.
Todo
-
todo: fix warning on addingENABLE_MODULE_BATCH
for batch APIs in schnorrsig, extrakeys header file (ininclude/
)-
todo: implement tests