Commit Graph
14 Commits
Author SHA1 Message Date
Jonas Nick 7cdaa7a183 bip-0327: isolate the range check in a PartialSigVerify test vector
The PartialSigVerify test vector with the partial signature n fails the
verification equation even without the range check. So it does not
detect implementations that omit the range check or that check s > n
instead of s >= n. Change the pubnonces of the test vector such that the
partial signature 0 is valid, keeping the aggregate nonce. Since
n*G = 0*G, the partial signature n then satisfies the verification
equation, and only the range check rejects it. The previous version of
the test vector detects no mistake that the new version does not detect,
so it is replaced rather than kept.

gen_vectors_helper.py computes the new pubnonces.
2026-11-16 09:29:52 +00:00
Jonas Nick b7557f897a bip-0327: add a NonceGen test vector without repeated bytes
In the previous NonceGen test vectors, every rand_ consists of the byte
0F repeated 32 times, every present sk of the byte 02 repeated 32 times,
and every pk has an even Y coordinate. Add a test vector whose rand_ and
sk are not a repeated byte and whose pk has an odd Y coordinate. It
detects implementations that reverse the byte order of rand_ or sk, that
replace the first byte of pk with 02, or that use only the first byte of
rand_.

With the last mistake, two NonceGen invocations with the same other
arguments return the same secnonce with probability 1/256, although the
BIP requires that Sign is never executed twice with the same secnonce.
2026-11-16 09:29:52 +00:00
Jonas Nick 17affe2861 bip-0327: add test vectors for a public key and its negation
A public key and its negation have the same X coordinate, and their
compressed encodings differ only in the first byte. Add a Sign test
vector with a secnonce generated for the negation of the signer's public
key, and a KeyAgg test vector with a public key and its negation. They
detect implementations that compare public keys only by their X
coordinates, in the public key check of Sign, in GetSecondKey, or in
KeyAggCoeffInternal. Distinct public keys in the previous test vectors
also have distinct X coordinates.

The public key check in Sign ensures that the secret key provided to
Sign is determined when NonceGen is invoked. Comparing only X
coordinates determines the secret key only up to negation.
2026-11-16 09:29:52 +00:00
Jonas Nick 0ba8e56a02 bip-0327: add test vectors for k2' >= n and 256-byte messages
Add Sign test vectors with k2' = n and k2' = n + 1. Together they
detect implementations that check the secret nonce values only for
zero, that check k2' <= n instead of k2' < n, or that reduce k2' mod n
before checking it for zero. No single value detects the last two:
among values of at least n, checking k2' <= n accepts only n, while
reducing first rejects only n. For k2' = n, the optional correctness
check at the end of Sign also fails, because k2'*G is infinity, so this
vector detects the k2' <= n mistake only in implementations that omit
that check.

Add NonceGen and DeterministicSign test vectors with a 256-byte
message. They detect implementations that encode only the low byte of
len(m); the longest message in the previous test vectors has 38 bytes.
DeterministicSign needs its own vector because it encodes len(m)
separately.
2026-11-16 09:29:52 +00:00
Jonas NickandFerdinando Ametrano 6e8dafd3c3 bip-0327: add test vectors and a README that describes them
Add Sign test vectors for a secnonce with k2' = 0 and for a secnonce
generated for a different public key. No previous test vector detected
an implementation that checks only k1', or one that omits the public
key check added in 1.0.0-rc.2.

Add test vectors for a single signer, a 4-byte extra_in, and plain and
x-only tweaks in DeterministicSign. They detect implementations that
reject a single signer, encode the length of extra_in as 32 whenever
extra_in is present, or treat every tweak in DeterministicSign as
x-only.

Add a README to the vectors directory. It states that the test vectors
only contain inputs whose length and number meet the specification of
BIP327, and that a test vector should only be added if it detects a
plausible implementation mistake that the other test vectors do not
detect. Name that mistake in the comment of each added test vector.

Co-authored-by: Ferdinando Ametrano <ferdinando@ametrano.net>
2026-11-16 09:29:52 +00:00
Ferdinando Ametrano 4f9567fd60 bip-0327: derive extra_in from secrets in the reference self-test
The self-test reads time.clock_gettime_ns(time.CLOCK_MONOTONIC) for
extra_in on even iterations. CPython documents both symbols
"Availability: Unix", so the attribute lookup raises AttributeError on
Windows and python3 reference.py does not run there.

Take extra_in from secrets instead, at a random length, so the self-test
also exercises extra_in of varying length. time has no other use in the
file, so its import goes too.
2026-09-10 15:55:28 +02:00
Sats And Sports ccb5415095 BIP-327: fix reference.py type errors failing tests.sh 2026-08-18 18:41:24 +02:00
Skylar RayandSnezhkko 9297c12729 BIPs 327, 340: remove unused imports
Co-authored-by: Snezhkko <snezhkodaria38@gmail.com>
2025-10-03 13:35:31 -06:00
8137279570 Monthly typo fixups
Co-authored-by: xiaobei0715 <1505929057@qq.com>
Co-authored-by: wgyt <wgythe@gmail.com>
Co-authored-by: Ragnar <rodiondenmark@gmail.com>
2025-04-28 10:29:11 -06:00
Jonas Nick 26bb1d8ea3 bip-0327: 1.0.1 -> 1.0.2
(cherry picked from commit 4f2e6e7ffbd2fdc095ab8d59827be9da18b790be)
2024-07-23 13:09:44 +05:30
siv2r 0d79b5eeb5 remove P = None check as cpoint never returns None 2024-07-19 23:52:53 +05:30
siv2r 1c6ac0c4cf bip327: minor fixes
- An error test vector doesn’t specify the InvalidContributionError type
- In *DeterministicSign*, use GetXonlyPubkey instead of GetPubkey
- The key_agg_and_tweak fn doesn’t specify the return type
- In partial_sig_verify_internal, the pubkey arg should be PlainPk
- Remove unused enumerate() fn calls
- In test_sign_verify, add an additional assert statement
2024-07-19 23:52:41 +05:30
siv2r 508e3a6a40 Fix the four test vectors
- first two vectors of verify_fail_test
- first two vectors of verify_error_test
2024-05-14 07:39:38 +05:30
Jonas Nick 87394eaeb4 Add BIP327: MuSig2 for BIP340-compatible Multi-Signatures 2023-03-27 11:48:22 +09:00