From 83b770777a16f72de935e10bc535ec817a3ae43b Mon Sep 17 00:00:00 2001 From: Jonas Nick Date: Mon, 9 Nov 2026 20:54:53 +0000 Subject: [PATCH] bip-0327: add test vectors for the signs of accumulated tweaks ApplyTweak multiplies gacc by g, which is -1 if an x-only tweak negates the aggregate public key. In every previous tweak sequence, the product of all values of g equals the last one. Add a test vector with two x-only tweaks, of which only the first negates the aggregate public key. It detects implementations that set gacc to g instead of multiplying it by g. PartialSigAgg adds e*g*tacc, where g is -1 if the aggregate public key Q has an odd Y coordinate. In the previous PartialSigAgg test vectors, tacc is 0 whenever Q has an odd Y coordinate. Add a test vector with a plain tweak and an odd Q, generated by gen_vectors_helper.py. It detects implementations that omit g. --- bip-0327/gen_vectors_helper.py | 15 +++++++++++++-- bip-0327/vectors/sig_agg_vectors.json | 27 ++++++++++++++++++++++++++- bip-0327/vectors/tweak_vectors.json | 9 +++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/bip-0327/gen_vectors_helper.py b/bip-0327/gen_vectors_helper.py index 32b3e35f..8b254466 100644 --- a/bip-0327/gen_vectors_helper.py +++ b/bip-0327/gen_vectors_helper.py @@ -112,7 +112,7 @@ def sig_agg_vectors(): "75448A87274B056468B977BE06EB1E9F657577B7320B0A3376EA51FD420D18A8"]) msg = bytes.fromhex("599C67EA410D005B9DA90817CF03ED3B1C868E4DA4EDF00A5880B0082C237869") - psigs = [None] * 10 + psigs = [None] * 12 valid_test_cases = [ { @@ -151,6 +151,14 @@ def sig_agg_vectors(): "is_xonly": [], "psig_indices": [9], "comment": "A single signer. Detects implementations that reject a single signer in PartialSigAgg.", + }, { + "aggnonce": None, + "nonce_indices": [0, 5], + "key_indices": [0, 1], + "tweak_indices": [2], + "is_xonly": [False], + "psig_indices": [10, 11], + "comment": "The tweaked aggregate public key has an odd Y coordinate. Detects implementations that omit g in e*g*tacc.", }, ] for (i, test_case) in enumerate(valid_test_cases): @@ -175,11 +183,14 @@ def sig_agg_vectors(): sig = partial_sig_agg([psigs[i] for i in psig_indices], session_ctx) keygen_ctx = key_agg_and_tweak(vec_pubkeys, vec_tweaks, is_xonly) # To maximize coverage of the sig_agg algorithm, we want one public key - # point with an even and one with an odd Y coordinate. + # point with an even and one with an odd Y coordinate, and one tweaked + # public key point with an odd Y coordinate. if i == 0: assert(has_even_y(keygen_ctx[0])) if i == 1: assert(not has_even_y(keygen_ctx[0])) + if i == 5: + assert(not has_even_y(keygen_ctx[0]) and keygen_ctx[2] != 0) aggpk = get_xonly_pk(keygen_ctx) assert schnorr_verify(msg, aggpk, sig) test_case["expected"] = sig.hex().upper() diff --git a/bip-0327/vectors/sig_agg_vectors.json b/bip-0327/vectors/sig_agg_vectors.json index 031b0a34..08808fe8 100644 --- a/bip-0327/vectors/sig_agg_vectors.json +++ b/bip-0327/vectors/sig_agg_vectors.json @@ -28,7 +28,9 @@ "97B890A26C981DA8102D3BC294159D171D72810FDF7C6A691DEF02F0F7AF3FDC", "53FA9E08BA5243CBCB0D797C5EE83BC6728E539EB76C2D0BF0F971EE4E909971", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", - "03E2479CF7C582CB216D2411DFEAA169037639E77FA0A7440DF5BCC2359E072D" + "03E2479CF7C582CB216D2411DFEAA169037639E77FA0A7440DF5BCC2359E072D", + "32D55C70B8AD7CA5C6C04271B1AC8FDB8AE08C926DDE6A5DD3876CFE5BFFA312", + "9F8D1B300A571F9958B84412B0D01B3DE4D5ED5D9DEF63357C707AF1A49E6B3A" ], "msg": "599C67EA410D005B9DA90817CF03ED3B1C868E4DA4EDF00A5880B0082C237869", "valid_test_cases": [ @@ -131,6 +133,29 @@ ], "comment": "A single signer. Detects implementations that reject a single signer in PartialSigAgg.", "expected": "0EAAB454E75DF2C5B4B7AA07126D4525171B6331A5E6A074C75924738709A1B603E2479CF7C582CB216D2411DFEAA169037639E77FA0A7440DF5BCC2359E072D" + }, + { + "aggnonce": "0312046E1C8A4DAC758DB7C86A31480439EA3125696BD035A4F2E3AED426E04C5E02A6A5697B14CC0D44A71DEC4FBA75B8B40CED9C71E090D2EADDD661BC90630306", + "nonce_indices": [ + 0, + 5 + ], + "key_indices": [ + 0, + 1 + ], + "tweak_indices": [ + 2 + ], + "is_xonly": [ + false + ], + "psig_indices": [ + 10, + 11 + ], + "comment": "The tweaked aggregate public key has an odd Y coordinate. Detects implementations that omit g in e*g*tacc.", + "expected": "AC72289943B24BF57EAC882DE6490D39B69B894F27E94E8B54E7A3971EFCD358ED75884545D1AAE735F101578FCC1DB195B478FC2A9E1BA7EF4D9D119D4F7428" } ], "error_test_cases": [ diff --git a/bip-0327/vectors/tweak_vectors.json b/bip-0327/vectors/tweak_vectors.json index d0a7cfe8..ed62b245 100644 --- a/bip-0327/vectors/tweak_vectors.json +++ b/bip-0327/vectors/tweak_vectors.json @@ -65,6 +65,15 @@ "signer_index": 2, "expected": "B255FDCAC27B40C7CE7848E2D3B7BF5EA0ED756DA81565AC804CCCA3E1D5D239", "comment": "Four tweaks: x-only, plain, x-only, plain. If an implementation prohibits applying plain tweaks after x-only tweaks, it can skip this test vector or return an error." + }, + { + "key_indices": [1, 2, 0], + "nonce_indices": [1, 2, 0], + "tweak_indices": [1, 2], + "is_xonly": [true, true], + "signer_index": 2, + "expected": "25414E2E06EAF13CB3FA6BB84A5E65C0A576D7230A6D2193A481B4EEC51AE5FD", + "comment": "Two x-only tweaks, of which only the first negates the aggregate public key. Detects implementations that set gacc to g instead of multiplying it by g." } ], "error_test_cases": [