250 Commits

Author SHA1 Message Date
Jonas Nick
73d5b6654d
musig: update to BIP v0.7.0 (NonceGen)
- 0.7.0: Change ''NonceGen'' such that output when message is not present is different from when message is present but has length 0.
- 0.6.0: Change order of arguments and serialization of the message in the ''NonceGen'' hash function
2023-02-13 14:03:51 +00:00
Jonas Nick
060887e9d7
musig: update to BIP v0.5.1 "Rename ordinary tweaking to plain" 2023-02-13 14:03:51 +00:00
Jonas Nick
cbe2815633
musig: update to BIP v0.4 "Allow the output of NonceAgg to be inf" 2023-01-23 09:36:46 +00:00
Jonas Nick
206017d67d
musig: update to BIP v0.3 (NonceGen)
- 0.3.0: Hash i - 1 instead of i in NonceGen
- 0.2.0: Change order of arguments in NonceGen hash function
2023-01-23 09:36:45 +00:00
Jonas Nick
d800dd55db
musig: remove test vectors
These vectors are superseded by test vectors in BIP MuSig2 which will be added
in a later commit.
2023-01-23 09:36:45 +00:00
Jesse Posner
dd83e72d52
Add ordinary tweak info 2022-09-01 22:39:34 -07:00
Jesse Posner
d26100cab2
Exclude nonce_process from pre-processing steps 2022-09-01 22:39:22 -07:00
Jesse Posner
b7607f93f2
Fix reference to xonly_tweak_add 2022-09-01 22:38:03 -07:00
Jonas Nick
f7e9a8544f
Merge elementsproject/secp256k1-zkp#201: rangeproof: add secp256k1_rangeproof_max_size function to estimate rangeproof size
6b6ced9839f2576898ba334e7ed2d550a2062b32 rangeproof: add more max_size tests (Jonas Nick)
34876ecb5facfc274580c0549df14e6664c03d82 rangeproof: add more static test vectors (Jonas Nick)
310e5170619b03977d471e9f7461bbaf5b607ca9 rangeproof: add a bunch more testing (Andrew Poelstra)
f1410cb67a2de45f8b1b1c14862656c0ae09ff87 rangeproof: add secp256k1_rangeproof_max_size function to estimate rangeproof size (Andrew Poelstra)

Pull request description:

ACKs for top commit:
  real-or-random:
    tACK 6b6ced9839f2576898ba334e7ed2d550a2062b32
  jonasnick:
    ACK 6b6ced9839f2576898ba334e7ed2d550a2062b32

Tree-SHA512: 421dfb0824f67f3822be729dc7f11e4654a21e32e3a6c5565e09b191ec57710b33a73c3d09c08f1d767d769f0957006ac257eabe00a2f37f88b99377644e8741
2022-08-25 20:21:47 +00:00
Jonas Nick
6b6ced9839 rangeproof: add more max_size tests 2022-08-25 14:26:02 +00:00
Jonas Nick
34876ecb5f rangeproof: add more static test vectors
Fixes #42
2022-08-25 14:26:02 +00:00
Andrew Poelstra
310e517061 rangeproof: add a bunch more testing
Add two new fixed rangeproof vectors; check that various extracted
values are correct; add a test for creating and verifying single-value
proofs.
2022-08-25 14:26:02 +00:00
Andrew Poelstra
f1410cb67a rangeproof: add secp256k1_rangeproof_max_size function to estimate rangeproof size
Provides a method that will give an upper bound on the size of a rangeproof,
given an upper bound on the value to be passed in and an upper bound on the
min_bits parameter.

There is a lot of design freedom here since the actual size of the rangeproof
depends on every parameter passed to rangeproof_sign, including the value to
be proven, often in quite intricate ways. For the sake of simplicity we assume
a nonzero `min_value` and that `exp` will be 0 (the default, and size-maximizing,
choice), and provide an exact value for a proof of the given value and min_bits.
2022-08-25 14:26:00 +00:00
Jonas Nick
0202d839fb
Merge elementsproject/secp256k1-zkp#199: surjectionproof: make sure that n_used_pubkeys > 0 in generate
5ac8fb035e8f0ad012d9f54b49e77b5d1f5e713a surjectionproof: make sure that n_used_pubkeys > 0 in generate (Jonas Nick)

Pull request description:

ACKs for top commit:
  apoelstra:
    utACK 5ac8fb035e8f0ad012d9f54b49e77b5d1f5e713a

Tree-SHA512: 915f7181e69e2c4e1f830d6c2620a2d9b0af4d2ae8a63709b489b01ed9e13ccfeeaedebd4680cf2d927cd473a6ae88602cf29e2fdd116cb597fba6c0ab77720d
2022-08-18 19:54:00 +00:00
Jonas Nick
5ac8fb035e surjectionproof: make sure that n_used_pubkeys > 0 in generate
If the proof was generated with surjectionproof_initialize (as mandated by the
API docs), then n_used_pubkeys can never be 0. Without this commit, compilers
will (rightfully) warn that borromean_s[ring_input_index] is not initialized in
surjectionproof_generate. Therefore, this commit makes sure that n_used_pubkeys
is greater than 0 which ensures that the array is initialized at
ring_input_index.
2022-08-15 20:01:39 +00:00
Andrew Poelstra
5a40f3d99b replace memcmp with secp256k1_memcmp_var throughout the codebase
memcmp only appears in -zkp-specific modules. Fix those.
2022-08-10 22:14:31 +00:00
Andrew Poelstra
92820d944b rangeproof: add a test for all-zero blinding factors 2022-08-10 22:10:33 +00:00
Andrew Poelstra
347f96d94a fix include paths in all the -zkp modules
This is causing out-of-tree build failures in Elements.
2022-08-05 14:56:10 +00:00
Andrew Poelstra
d1175d265d
surjectionproof: use secp256k1_memcmp_var rather than bare memcmp
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
2022-07-29 21:04:04 +00:00
Andrew Poelstra
bf18ff5a8c surjectionproof: fix generation to fail when any input == the output
Verification will fail in this case, so don't "succeed" in generating a bad proof.
2022-07-26 17:14:49 +00:00
Andrew Poelstra
4ff6e4274d surjectionproof: add test for existing behavior on input=output proofs 2022-07-26 17:09:36 +00:00
Jon Griffiths
db648478c3
extrakeys: rename swap/swap64 to fix OpenBSD 7.1 compilation
OpenBSD defines swap64 in <endian.h>.
2022-07-18 12:29:54 +12:00
Jonas Nick
510b61a803 musig: add test vectors for applying multiple tweaks 2022-04-04 21:38:46 +00:00
Jonas Nick
8298c0c79b Merge commits 'c8aa516b 0a40a486 d8a24632 85b00a1c 59547943 5dcc6f8d 07752831 3ef94aa5 1253a277 64b34979 ac83be33 0e5cbd01 e0508ee9 587239db 1ac7e31c d0ad5814 912b7ccc 8746600e ' into temp-merge-1093
Revert: util: Remove endianness detection
2022-03-30 15:00:03 +00:00
Jonas Nick
eac0df1379 musig: mention how keyagg_cache tweak and parity relate to spec
Also rename internal_key_parity -> parity_acc because the former is
confusing.
2022-03-21 22:10:24 +00:00
Jonas Nick
57eb6b4167 musig-spec: move description of secret key negation to spec
Also fix bug in description that resulted in a wrong definition of t.
And rename keyagg coefficient from 'mu' to 'a' since we don't use the term "musig
coefficient" anymore and a is what is used in the paper.
2022-03-21 22:10:24 +00:00
Tim Ruffing
99e6568fc6 schnorrsig: Rename schnorrsig_sign to schnorsig_sign32 and deprecate 2022-03-17 22:41:36 +01:00
Tim Ruffing
3531a43b5b ecdh: Make generator_basepoint test depend on global iteration count
Co-authored-by: Elliott Jin <elliott.jin@gmail.com>
2022-02-11 16:39:04 +01:00
Tim Ruffing
c881dd49bd ecdh: Add test computing shared_secret=basepoint with random inputs 2022-02-11 16:39:04 +01:00
Jonas Nick
f0edc90755 musig: fix number of tweaks in tweak_test 2022-02-07 13:56:56 +00:00
Tim Ruffing
73f0cbd3cc
Merge ElementsProject/secp256k1-zkp#157: Add description of MuSig signing to musig-spec.md
69b392f3cbd4dbff953ec8f2ff44f6a8f612b661 musig: move explanation for aggnonce=inf to spec (Jonas Nick)
4824220bb71102064babf832372f4e5ae43ef16f musig-spec: describe NonceGen, NonceAgg, Sign,PartialSig{Verify,Agg} (Jonas Nick)
3c122d07807dfaea6457d8a48ba4adc7a15f1182 musig-spec: improve definition of lift_x (Jonas Nick)
e0bb2d7009eebe2b25dfe977fe3534ad507251ab musig-spec: improve KeyAgg description (Jonas Nick)
b8f4e75d89071515231be03727d47a34b1c12cab musig-spec: move to doc directory (Jonas Nick)

Pull request description:

  Will wait before adding tweaking until #151 is merged.

ACKs for top commit:
  robot-dreams:
    ACK 69b392f3cbd4dbff953ec8f2ff44f6a8f612b661 based on:
  real-or-random:
    ACK 69b392f3cb I haven't looked at every detail but it's certainly ready to be merged as draft spec

Tree-SHA512: e3aa0265a9d7a7648e03ca42575397100edd5af43f0224937af51aa5c77efc451d7938149bdc711f69e24fb9291438453b8cd762affaa1a2e7bcc89f121485df
2022-01-25 10:55:25 +01:00
Tim Ruffing
8fd97d8116
Merge ElementsProject/secp256k1-zkp#158: Small musig improvements
d895b10c18b8aa19a77f0a80f318e1a2052e7c9b musig: mention musig.md in example (Jonas Nick)
588009d26ffc58864b6e9fc3f1ab2eae633476c3 musig: improve doc of partial_sig_verify regarding signing sessions (Jonas Nick)
b1094953c4497947222df12ef8f9adb2191e2b17 musig: remove superfluous comment (Jonas Nick)

Pull request description:

ACKs for top commit:
  robot-dreams:
    ACK d895b10c18b8aa19a77f0a80f318e1a2052e7c9b
  real-or-random:
    ACK d895b10c18b8aa19a77f0a80f318e1a2052e7c9b

Tree-SHA512: 35169240868500bb27e5a6b8779f090d3f33a6c0cb1a4574e6e53e9c52782f454fe7df6d49b68e0acdd174e25a756bf6267339f0d4e94f28d5ae49145f21e298
2022-01-25 10:53:38 +01:00
Tim Ruffing
772df3694e
Merge ElementsProject/secp256k1-zkp#151: MuSig: Add Minimal Compatibility with BIP32 Tweaking
8088eddc534cbbb89dd5f892828c4013416c4f2b musig: add test vector for ordinary (non xonly) tweaking (Elliott Jin)
57a17929fc0056efb5436a6001597d656591e1ad musig: add ordinary and xonly tweaking to the example (Jonas Nick)
37107361a0ff3b8764903e3b384cfc12ed484e7a musig: allow ordinary, non-xonly tweaking (Jonas Nick)
c519b468791670654f8b66368a675655cd337ae8 musig: add pubkey_get to obtain a full pubkey from a keyagg_cache (Jonas Nick)

Pull request description:

  In short, `musig_pubkey_tweak_add` now allows for xonly _and_ "ordinary" tweaking. Also, in order to allow using `ec_pubkey_tweak_add` on the non-xonly aggregate public key, there's a new function `musig_pubkey_get` that allows obtaining it from the `keyagg_cache`.

  One alternative would be that instead of adding `musig_pubkey_get`, we could change `pubkey_agg` to output an ordinary (non-xonly) pubkey. Then users of the API who do not need ordinary (BIP32) tweaking would be forced to call `xonly_pubkey_from_pubkey`. And we'd probably want to change the spec. And it would be a bit weird to output a pubkey that can't be directly schnorrsig_verify'd.

  Based on #131

ACKs for top commit:
  robot-dreams:
    ACK 8088eddc534cbbb89dd5f892828c4013416c4f2b based on https://github.com/ElementsProject/secp256k1-zkp/pull/151#issuecomment-1005198409 and the following `range-diff`:

Tree-SHA512: a4a0100f0470c870f88a8da27dbcc4684fcc2caabb368d4340e962e08d5ee04634e6289bafa3448dbfd0b5793a3e70de5bd6ddca7a619cc3220ff762d518a8fe
2022-01-25 10:18:40 +01:00
Jonas Nick
69b392f3cb musig: move explanation for aggnonce=inf to spec 2022-01-24 15:50:42 +00:00
Jonas Nick
b8f4e75d89 musig-spec: move to doc directory 2022-01-24 15:45:51 +00:00
Elliott Jin
8088eddc53 musig: add test vector for ordinary (non xonly) tweaking 2022-01-21 17:07:06 +00:00
Jonas Nick
37107361a0 musig: allow ordinary, non-xonly tweaking 2022-01-21 17:07:06 +00:00
Jonas Nick
c519b46879 musig: add pubkey_get to obtain a full pubkey from a keyagg_cache 2022-01-21 17:07:06 +00:00
Kalle Rosenbaum
44001ad716
Typo fix, add subscript i 2022-01-15 12:31:00 +01:00
Andrew Poelstra
11d675dce8 whitelist: remove ability to specific nonce function
This functionality is inappropriate to expose for a zero-knowledge proof,
and was confusingly (and potentially dangerously) implemented.
2022-01-06 19:12:14 +00:00
Jonas Nick
b7ebe6436c Test APIs of funcs that need an ecmult_gen ctx with static ctx
The API tests of upstream functions were similarly amended in commit 3b0c2185eab0fe5cb910fffee4c88e134f6d3cad.
2022-01-04 12:57:57 +00:00
Jonas Nick
72c8deac03 Merge commits with sync-upstream.sh
da0092bc 10f9bd84 297ce820 f34b5cae 920a0e5f 9526874d aa1b889b 20d791ed 3e7b2ea1 21c188b3 8fa41201 515a5dbd c74a7b7e 74c34e72 7006f1b9 ea5e8a9c 793ad901 2e5e4b67 fecf436d 49f608de 49002274 6ad908aa 4f01840b 61ae37c6 486205aa 5d0dbef0 0559fc6e be6944ad a69df3ad b39d431a 0b83b203 09971a3f 9281c9f4 423b6d19 a310e79e 39a36db9 a1102b12

Deal with
  - secp256k1_test_rng removal in commit
    77a19750b46916b93bb6a08837c26f585bd940fa
  - ecmult_gen context simplification after making table static in commit
    3b0c2185eab0fe5cb910fffee4c88e134f6d3cad
2022-01-02 16:11:15 +00:00
Jonas Nick
b1094953c4 musig: remove superfluous comment
This was simply forgotten to be removed.
2021-12-30 17:52:03 +00:00
Pieter Wuille
77a19750b4 Use xoshiro256++ PRNG instead of RFC6979 in tests 2021-12-24 11:19:29 -05:00
Pieter Wuille
5f2efe684e secp256k1_testrand_int(2**N) -> secp256k1_testrand_bits(N) 2021-12-24 10:56:16 -05:00
Tim Ruffing
b2206619e6
Merge ElementsProject/secp256k1-zkp#131: Replace MuSig(1) module with MuSig2
ac1e36769dda3964f7294319ecb06fb5c414938d musig: turn off multiexponentiation for now (Jonas Nick)
3c79d97bd92ec22cc204ff5a08c9b0e5adda12e6 ci: increase timeout for macOS tasks (Jonas Nick)
22c88815c76e6edb23baf9401f820e1a944c3ecf musig: replace MuSig(1) with MuSig2 (Jonas Nick)

Pull request description:

  The main commit comprises `905 insertions(+), 1253 deletions(-)`. The diff isn't as small as I had hoped, but that's mostly because it was possible to simplify the API quite substantially which required rewriting large parts. Sorry, almost all of the changes are in one big commit which makes the diff very hard to read. Perhaps best to re-review most parts from scratch.

  A few key changes:

  - Obviously no commitment round. No big session struct and no `verifier` sessions. No `signer` struct.
  - There's a new `secnonce` struct that is the output of musig_nonce_gen and derived from a uniformly random session_id32. The derivation can be strengthened by adding whatever session parameters (combined_pk, msg) are available. The nonce function is my ad-hoc construction that allows for these optional inputs. Please have a look at that.
  - The secnonce is made invalid after being used in partial_sign.
  - Adaptor signatures basically work as before, according to https://github.com/ElementsProject/scriptless-scripts/pull/24 (with the exception that they operate on aggregate instead of partial sigs)
  - To avoid making this PR overly complex I did not consider how this implementation interacts with nested-MuSig, sign-to-contract, and antiklepto.
  - Testing should be close to complete. There's no reachable line or branch that isn't exercised by the tests.
  - [x] ~In the current implementation when a signer sends an invalid nonce (i.e. some garbage that can't be mapped to a group element), it is ignored when combining nonces. Only after receiving the signers partial signature and running `partial_sig_verify` will we notice that the signer misbehaved. The reason for this is that 1) this makes the API simpler and 2) malicious peers don't gain any additional powers because they can always interrupt the protocol by refusing to sign. However, this is up for discussion.~ EDIT: this is not the case anymore since invalid nonces are rejected when they're parsed.
  - [x] ~For every partial signature we verify we have to parse the pubnonce (two compressed points), despite having parsed it in `process_nonces` already. This is not great. `process_nonces` could optionally output the array of parsed pubnonces.~ EDIT: fixed by having a dedicated type for nonces.
  - [x] ~I left `src/modules/musig/musig.md` unchanged for now. Perhaps we should merge it with the `musig-spec`~ EDIT: musig.md is updated
  - [x] partial verification should use multiexp to compute `R1 + b*R2 + c*P`, but this can be done in a separate PR
  - [x] renaming wishlist
      - pre_session -> keyagg_cache (because there is no session anymore)
      - pubkey_combine, nonce_combine, partial_sig_combine -> pubkey_agg, nonce_agg, partial_sig_agg (shorter, matches terminology in musig2)
      - musig_session_init -> musig_start (shorter, simpler) or [musig_generate_nonce](https://github.com/ElementsProject/secp256k1-zkp/pull/131#discussion_r654190890) or musig_prepare
      - musig_partial_signature to musig_partial_sig (shorter)
  - [x] perhaps remove pubnonces and n_pubnonces argument from process_nonces (and then also add a opaque type for the combined nonce?)
  - [x] write the `combined_pubkey` into the `pre_session` struct (as suggested [below](https://github.com/ElementsProject/secp256k1-zkp/pull/131#issuecomment-866904975): then 1) session_init and process_nonces don't need a combined_pk argument (and there can't be mix up between tweaked and untweaked keys) and 2) pubkey_tweak doesn't need an input_pubkey and the output_pubkey can be written directly into the pre_session (reducing frustration such as Replace MuSig(1) module with MuSig2 #131 (comment))
  - [x] perhaps allow adapting both partial sigs (`partial_sig` struct) and aggregate partial sigs (64 raw bytes) as suggested [below](https://github.com/ElementsProject/secp256k1-zkp/pull/131#issuecomment-867281531).

  Based on #120.

ACKs for top commit:
  robot-dreams:
    ACK ac1e36769dda3964f7294319ecb06fb5c414938d
  real-or-random:
    ACK ac1e36769dda3964f7294319ecb06fb5c414938d

Tree-SHA512: 916b42811aa5c00649cfb923d2002422c338106a6936a01253ba693015a242f21f7f7b4cce60d5ab5764a129926c6fd6676977c69c9e6e0aedc51b308ac6578d
2021-12-20 15:14:44 +01:00
Jonas Nick
ac1e36769d musig: turn off multiexponentiation for now
Before turning it on we need to have a discussion about our confidence in the
correctness of the multiexponentiation code.
2021-12-17 13:47:43 +00:00
Jonas Nick
22c88815c7 musig: replace MuSig(1) with MuSig2 2021-12-17 13:47:23 +00:00
Tim Ruffing
3b0c2185ea ecmult_gen: Simplify ecmult_gen context after making table static
This is a backwards-compatible API change: Before this commit, a context
initialized for signing was required to call functions that rely on
ecmult_gen. After this commit, this is no longer necessary because the
static ecmult_gen table is always present. In practice this means that
the corresponding functions will just work instead of calling the
illegal callback when given a context which is not (officially)
initialized for signing.

This is in line with 6815761, which made the analogous change with
respect to ecmult and contexts initialized for signing. But as opposed
to 681571, which removed the ecmult context entirely, we cannot remove
the ecmult_gen context entirely because it is still used for random
blinding. Moreover, since the secp256k1_context_no_precomp context is
const and cannot meaningfully support random blinding, we refrain (for
now) from changing its API, i.e., the illegal callback will still be
called when trying to use ecmult_gen operations with the static
secp256k1_context_no_precomp context.
2021-12-03 11:23:33 +01:00
Pieter Wuille
af6abcb3d0 Make bench support selecting which benchmarks to run 2021-11-05 17:48:18 -04:00