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>
This commit is contained in:
Jonas NickandFerdinando Ametrano committed 2026-11-16 09:29:52 +00:00
1 parent a0c977f375
commit 6e8dafd3c3
7 files changed
+97 -5

No files matched your search

+9 -1
View File
@@ -80,7 +80,7 @@ def sig_agg_vectors():
"75448A87274B056468B977BE06EB1E9F657577B7320B0A3376EA51FD420D18A8"])
msg = bytes.fromhex("599C67EA410D005B9DA90817CF03ED3B1C868E4DA4EDF00A5880B0082C237869")
psigs = [None] * 9
psigs = [None] * 10
valid_test_cases = [
{
@@ -111,6 +111,14 @@ def sig_agg_vectors():
"tweak_indices": [0, 1, 2],
"is_xonly": [True, False, True],
"psig_indices": [6, 7],
}, {
"aggnonce": None,
"nonce_indices": [0],
"key_indices": [0],
"tweak_indices": [],
"is_xonly": [],
"psig_indices": [9],
"comment": "A single signer. Detects implementations that reject a single signer in PartialSigAgg.",
},
]
for (i, test_case) in enumerate(valid_test_cases):
+8
View File
@@ -0,0 +1,8 @@
# BIP327 test vectors
BIP327 specifies the length and number of the inputs of each algorithm, for example that each tweak is a 32-byte array and that there is one tweak mode for each tweak.
The test vectors only contain inputs that meet these specifications.
Since BIP327 does not specify how algorithms handle other inputs, such as a 31-byte tweak or a missing tweak mode, the test vectors do not test them.
A test vector should only be added if it detects a plausible implementation mistake that the other test vectors do not detect.
The comment of the test vector names the mistake, for example "Detects implementations that set gacc to g instead of multiplying it by g".
+14
View File
@@ -64,6 +64,20 @@
"7B1246C5889E59CB0375FA395CC86AC42D5D7D59FD8EAB4FDF1DCAB2B2F006EA"
],
"comment": "Tweaked public key"
},
{
"rand": "0000000000000000000000000000000000000000000000000000000000000000",
"aggothernonce": "032DE2662628C90B03F5E720284EB52FF7D71F4284F627B68A853D78C78E1FFE9303E4C5524E83FFE1493B9077CF1CA6BEB2090C93D930321071AD40B2F44E599046",
"key_indices": [0, 1, 2],
"tweaks": ["E8F791FF9225A2AF0102AFFF4A9A723D9612A682A25EBE79802B263CDFCD83BB", "AE2EA797CC0FE72AC5B97B97F3C6957D7E4199A167A58EB08BCAFFDA70AC0455"],
"is_xonly": [false, true],
"msg_index": 0,
"signer_index": 0,
"expected": [
"0216794FAEAAED862634A73DBCE667395FE479CF0986B0111451F6C0EF8B82C04702BE7347E8CFF7540585ACC13D3B727372263E65A0E034D90CC3B2DF22603EF972",
"324600EDB5B0321F47C27D7843EA38A4B61A80C276AB3EA5E9435B254D135B6B"
],
"comment": "Plain and x-only tweaks. Detects implementations that treat every tweak as x-only."
}
],
"error_test_cases": [
+11
View File
@@ -39,6 +39,17 @@
"extra_in": null,
"expected_secnonce": "89BDD787D0284E5E4D5FC572E49E316BAB7E21E3B1830DE37DFE80156FA41A6D0B17AE8D024C53679699A6FD7944D9C4A366B514BAF43088E0708B1023DD289702F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9",
"expected_pubnonce": "02C96E7CB1E8AA5DAC64D872947914198F607D90ECDE5200DE52978AD5DED63C000299EC5117C2D29EDEE8A2092587C3909BE694D5CFF0667D6C02EA4059F7CD9786"
},
{
"rand_": "0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F",
"sk": "0202020202020202020202020202020202020202020202020202020202020202",
"pk": "024D4B6CD1361032CA9BD2AEB9D900AA4D45D9EAD80AC9423374C451A7254D0766",
"aggpk": "0707070707070707070707070707070707070707070707070707070707070707",
"msg": "0101010101010101010101010101010101010101010101010101010101010101",
"extra_in": "08080808",
"expected_secnonce": "8BEDC2ABC2D7F00976C8A932314683C9A9BE9B8A71A7C2F3F54B9C303215AE7C13C471707BA3CDC623D7B4F9B6BF3AFD140B9A3C936F6FE05FF22F344387D853024D4B6CD1361032CA9BD2AEB9D900AA4D45D9EAD80AC9423374C451A7254D0766",
"expected_pubnonce": "0357C9EEBFFA55BF667E0AACF5412C1E9EBDEBEFFC764F9FCBEA748BBFD275C4400303C378032670DCBC1D9ACDF8EC113FE863A249FC74D3E88F898C1B2540A7CC00",
"comment": "extra_in shorter than 32 bytes. Detects implementations that encode the length of extra_in as 32 whenever extra_in is present. This test case is optional: it can be skipped by implementations that only support a 32-byte extra_in."
}
]
}
+18 -1
View File
@@ -27,7 +27,8 @@
"DDEF427BBB847CC027BEFF4EDB01038148917832253EBC355FC33F4A8E2FCCE4",
"97B890A26C981DA8102D3BC294159D171D72810FDF7C6A691DEF02F0F7AF3FDC",
"53FA9E08BA5243CBCB0D797C5EE83BC6728E539EB76C2D0BF0F971EE4E909971",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141",
"03E2479CF7C582CB216D2411DFEAA169037639E77FA0A7440DF5BCC2359E072D"
],
"msg": "599C67EA410D005B9DA90817CF03ED3B1C868E4DA4EDF00A5880B0082C237869",
"valid_test_cases": [
@@ -114,6 +115,22 @@
7
],
"expected": "839B08820B681DBA8DAF4CC7B104E8F2638F9388F8D7A555DC17B6E6971D7426CE07BF6AB01F1DB50E4E33719295F4094572B79868E440FB3DEFD3FAC1DB589E"
},
{
"aggnonce": "036E5EE6E28824029FEA3E8A9DDD2C8483F5AF98F7177C3AF3CB6F47CAF8D94AE902DBA67E4A1F3680826172DA15AFB1A8CA85C7C5CC88900905C8DC8C328511B53E",
"nonce_indices": [
0
],
"key_indices": [
0
],
"tweak_indices": [],
"is_xonly": [],
"psig_indices": [
9
],
"comment": "A single signer. Detects implementations that reject a single signer in PartialSigAgg.",
"expected": "0EAAB454E75DF2C5B4B7AA07126D4525171B6331A5E6A074C75924738709A1B603E2479CF7C582CB216D2411DFEAA169037639E77FA0A7440DF5BCC2359E072D"
}
],
"error_test_cases": [
+36 -2
View File
@@ -8,7 +8,9 @@
],
"secnonces": [
"508B81A611F100A6B2B6B29656590898AF488BCF2E1F55CF22E5CFB84421FE61FA27FD49B1D50085B481285E1CA205D55C82CC1B31FF5CD54A489829355901F703935F972DA013F80AE011890FA89B67A27B7BE6CCB24D3274D18B2D4067F261A9",
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003935F972DA013F80AE011890FA89B67A27B7BE6CCB24D3274D18B2D4067F261A9"
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003935F972DA013F80AE011890FA89B67A27B7BE6CCB24D3274D18B2D4067F261A9",
"508B81A611F100A6B2B6B29656590898AF488BCF2E1F55CF22E5CFB84421FE61000000000000000000000000000000000000000000000000000000000000000003935F972DA013F80AE011890FA89B67A27B7BE6CCB24D3274D18B2D4067F261A9",
"508B81A611F100A6B2B6B29656590898AF488BCF2E1F55CF22E5CFB84421FE61FA27FD49B1D50085B481285E1CA205D55C82CC1B31FF5CD54A489829355901F702F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9"
],
"pnonces": [
"0337C87821AFD50A8644D820A8F3E02E499C931865C2360FB43D0A0D20DAFE07EA0287BF891D2A6DEAEBADC909352AA9405D1428C15F4B75F04DAE642A95C2548480",
@@ -22,7 +24,8 @@
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"048465FCF0BBDBCF443AABCCE533D42B4B5A10966AC09A49655E8C42DAAB8FCD61037496A3CC86926D452CAFCFD55D25972CA1675D549310DE296BFF42F72EEEA8C9",
"028465FCF0BBDBCF443AABCCE533D42B4B5A10966AC09A49655E8C42DAAB8FCD61020000000000000000000000000000000000000000000000000000000000000009",
"028465FCF0BBDBCF443AABCCE533D42B4B5A10966AC09A49655E8C42DAAB8FCD6102FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC30"
"028465FCF0BBDBCF443AABCCE533D42B4B5A10966AC09A49655E8C42DAAB8FCD6102FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC30",
"0337C87821AFD50A8644D820A8F3E02E499C931865C2360FB43D0A0D20DAFE07EA0287BF891D2A6DEAEBADC909352AA9405D1428C15F4B75F04DAE642A95C2548480"
],
"msgs": [
"F95466D086770E689964664219266FE5ED215C92AE20BAB5C9D79ADDDDF3C0CF",
@@ -80,6 +83,15 @@
"signer_index": 0,
"expected": "E184351828DA5094A97C79CABDAAA0BFB87608C32E8829A4DF5340A6F243B78C",
"comment": "38-byte message"
},
{
"key_indices": [0],
"nonce_indices": [0],
"aggnonce_index": 5,
"msg_index": 0,
"signer_index": 0,
"expected": "22D1B07E5D00C726B7E1362C87166935722EE66E7D8312182085D3010D71A536",
"comment": "A single signer. Detects implementations that reject a single signer in Sign or PartialSigVerify."
}
],
"sign_error_test_cases": [
@@ -153,6 +165,28 @@
"message": "first secnonce value is out of range."
},
"comment": "Secnonce is invalid which may indicate nonce reuse"
},
{
"key_indices": [0, 1, 2],
"aggnonce_index": 0,
"msg_index": 0,
"secnonce_index": 2,
"error": {
"type": "value",
"message": "second secnonce value is out of range."
},
"comment": "Secnonce is invalid because its second half is zero. Detects implementations that check only that k2' < n and omit the optional verification at the end of Sign."
},
{
"key_indices": [0, 1, 2],
"aggnonce_index": 0,
"msg_index": 0,
"secnonce_index": 3,
"error": {
"type": "value",
"message": "Public key does not match nonce_gen argument"
},
"comment": "Secnonce was generated for another signer's public key. Detects implementations that check only that secnonce[64:97] is one of the public keys."
}
],
"verify_fail_test_cases": [