Merge pull request #2628 from fametrano/musig2-bip327-vectors
What changed, and why it matters
This commit updates the test data and test code for the MuSig2 multi-signature implementation in btcd to match the latest official BIP 327 test vectors. It does not change the cryptographic implementation itself, only the test fixtures and how the tests read them. There is no indication of a security vulnerability being fixed.
No security action required. Treat as routine test maintenance. Reviewers may verify that the new vectors match the published BIP 327 vectors if desired.
Security signals we found
No production code changes
Test-only data refresh
No vulnerability description in commit or references
Evidence from the diff
The commit refreshes BIP 327 MuSig2 test vectors across JSON data files and adjusts Go test code to consume the updated vector format. Changes include: new key sort vector entries; nonce generation vectors now use a non-zero rand value and separate expected_secnonce/expected_pubnonce fields; signature aggregation vectors add a contrib field; sign/verify vectors add new valid cases (empty message, 38-byte message), update some signature values, and clarify an optional error test. Test code removes a memsetRandReader helper in favor of bytes.NewReader and skips sign tests for non-32-byte messages because the API requires a 32-byte message. No production code is modified.
Changed components
btcec/schnorr/musig2 test suitebtcec/schnorr/musig2/data/*.json test vectorsInspect captured patch +67 / −43
### btcec/schnorr/musig2/data/key_sort_vectors.json
@@ -4,12 +4,14 @@
"02F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9",
"03DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659",
"023590A94E768F8E1815C2F24B4D80A8E3149316C3518CE7B7AD338368D038CA66",
+ "02DD308AFEC5777E13121FA72B9CC1B7CC0139715309B086C960E18FD969774EFF",
"02DD308AFEC5777E13121FA72B9CC1B7CC0139715309B086C960E18FD969774EB8"
],
"sorted_pubkeys": [
"023590A94E768F8E1815C2F24B4D80A8E3149316C3518CE7B7AD338368D038CA66",
"02DD308AFEC5777E13121FA72B9CC1B7CC0139715309B086C960E18FD969774EB8",
"02DD308AFEC5777E13121FA72B9CC1B7CC0139715309B086C960E18FD969774EB8",
+ "02DD308AFEC5777E13121FA72B9CC1B7CC0139715309B086C960E18FD969774EFF",
"02F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9",
"03DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659"
]
### btcec/schnorr/musig2/data/nonce_gen_vectors.json
@@ -1,40 +1,44 @@
{
"test_cases": [
{
- "rand_": "0000000000000000000000000000000000000000000000000000000000000000",
+ "rand_": "0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F",
"sk": "0202020202020202020202020202020202020202020202020202020202020202",
"pk": "024D4B6CD1361032CA9BD2AEB9D900AA4D45D9EAD80AC9423374C451A7254D0766",
"aggpk": "0707070707070707070707070707070707070707070707070707070707070707",
"msg": "0101010101010101010101010101010101010101010101010101010101010101",
"extra_in": "0808080808080808080808080808080808080808080808080808080808080808",
- "expected": "227243DCB40EF2A13A981DB188FA433717B506BDFA14B1AE47D5DC027C9C3B9EF2370B2AD206E724243215137C86365699361126991E6FEC816845F837BDDAC3024D4B6CD1361032CA9BD2AEB9D900AA4D45D9EAD80AC9423374C451A7254D0766"
+ "expected_secnonce": "B114E502BEAA4E301DD08A50264172C84E41650E6CB726B410C0694D59EFFB6495B5CAF28D045B973D63E3C99A44B807BDE375FD6CB39E46DC4A511708D0E9D2024D4B6CD1361032CA9BD2AEB9D900AA4D45D9EAD80AC9423374C451A7254D0766",
+ "expected_pubnonce": "02F7BE7089E8376EB355272368766B17E88E7DB72047D05E56AA881EA52B3B35DF02C29C8046FDD0DED4C7E55869137200FBDBFE2EB654267B6D7013602CAED3115A"
},
{
- "rand_": "0000000000000000000000000000000000000000000000000000000000000000",
+ "rand_": "0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F",
"sk": "0202020202020202020202020202020202020202020202020202020202020202",
"pk": "024D4B6CD1361032CA9BD2AEB9D900AA4D45D9EAD80AC9423374C451A7254D0766",
"aggpk": "0707070707070707070707070707070707070707070707070707070707070707",
"msg": "",
"extra_in": "0808080808080808080808080808080808080808080808080808080808080808",
- "expected": "CD0F47FE471D6788FF3243F47345EA0A179AEF69476BE8348322EF39C2723318870C2065AFB52DEDF02BF4FDBF6D2F442E608692F50C2374C08FFFE57042A61C024D4B6CD1361032CA9BD2AEB9D900AA4D45D9EAD80AC9423374C451A7254D0766"
+ "expected_secnonce": "E862B068500320088138468D47E0E6F147E01B6024244AE45EAC40ACE5929B9F0789E051170B9E705D0B9EB49049A323BBBBB206D8E05C19F46C6228742AA7A9024D4B6CD1361032CA9BD2AEB9D900AA4D45D9EAD80AC9423374C451A7254D0766",
+ "expected_pubnonce": "023034FA5E2679F01EE66E12225882A7A48CC66719B1B9D3B6C4DBD743EFEDA2C503F3FD6F01EB3A8E9CB315D73F1F3D287CAFBB44AB321153C6287F407600205109"
},
{
- "rand_": "0000000000000000000000000000000000000000000000000000000000000000",
+ "rand_": "0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F",
"sk": "0202020202020202020202020202020202020202020202020202020202020202",
"pk": "024D4B6CD1361032CA9BD2AEB9D900AA4D45D9EAD80AC9423374C451A7254D0766",
"aggpk": "0707070707070707070707070707070707070707070707070707070707070707",
"msg": "2626262626262626262626262626262626262626262626262626262626262626262626262626",
"extra_in": "0808080808080808080808080808080808080808080808080808080808080808",
- "expected": "011F8BC60EF061DEEF4D72A0A87200D9994B3F0CD9867910085C38D5366E3E6B9FF03BC0124E56B24069E91EC3F162378983F194E8BD0ED89BE3059649EAE262024D4B6CD1361032CA9BD2AEB9D900AA4D45D9EAD80AC9423374C451A7254D0766"
+ "expected_secnonce": "3221975ACBDEA6820EABF02A02B7F27D3A8EF68EE42787B88CBEFD9AA06AF3632EE85B1A61D8EF31126D4663A00DD96E9D1D4959E72D70FE5EBB6E7696EBA66F024D4B6CD1361032CA9BD2AEB9D900AA4D45D9EAD80AC9423374C451A7254D0766",
+ "expected_pubnonce": "02E5BBC21C69270F59BD634FCBFA281BE9D76601295345112C58954625BF23793A021307511C79F95D38ACACFF1B4DA98228B77E65AA216AD075E9673286EFB4EAF3"
},
{
- "rand_": "0000000000000000000000000000000000000000000000000000000000000000",
+ "rand_": "0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F",
"sk": null,
"pk": "02F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9",
"aggpk": null,
"msg": null,
"extra_in": null,
- "expected": "890E83616A3BC4640AB9B6374F21C81FF89CDDDBAFAA7475AE2A102A92E3EDB29FD7E874E23342813A60D9646948242646B7951CA046B4B36D7D6078506D3C9402F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9"
+ "expected_secnonce": "89BDD787D0284E5E4D5FC572E49E316BAB7E21E3B1830DE37DFE80156FA41A6D0B17AE8D024C53679699A6FD7944D9C4A366B514BAF43088E0708B1023DD289702F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9",
+ "expected_pubnonce": "02C96E7CB1E8AA5DAC64D872947914198F607D90ECDE5200DE52978AD5DED63C000299EC5117C2D29EDEE8A2092587C3909BE694D5CFF0667D6C02EA4059F7CD9786"
}
]
-}
\ No newline at end of file
+}
### btcec/schnorr/musig2/data/sig_agg_vectors.json
@@ -143,9 +143,10 @@
],
"error": {
"type": "invalid_contribution",
- "signer": 1
+ "signer": 1,
+ "contrib": "psig"
},
"comment": "Partial signature is invalid because it exceeds group size"
}
]
-}
\ No newline at end of file
+}
### btcec/schnorr/musig2/data/sign_verify_vectors.json
@@ -15,7 +15,7 @@
"0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F817980279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798",
"032DE2662628C90B03F5E720284EB52FF7D71F4284F627B68A853D78C78E1FFE9303E4C5524E83FFE1493B9077CF1CA6BEB2090C93D930321071AD40B2F44E599046",
"0237C87821AFD50A8644D820A8F3E02E499C931865C2360FB43D0A0D20DAFE07EA0387BF891D2A6DEAEBADC909352AA9405D1428C15F4B75F04DAE642A95C2548480",
- "020000000000000000000000000000000000000000000000000000000000000009"
+ "0200000000000000000000000000000000000000000000000000000000000000090287BF891D2A6DEAEBADC909352AA9405D1428C15F4B75F04DAE642A95C2548480"
],
"aggnonces": [
"028465FCF0BBDBCF443AABCCE533D42B4B5A10966AC09A49655E8C42DAAB8FCD61037496A3CC86926D452CAFCFD55D25972CA1675D549310DE296BFF42F72EEEA8C9",
@@ -62,6 +62,24 @@
"signer_index": 0,
"expected": "AE386064B26105404798F75DE2EB9AF5EDA5387B064B83D049CB7C5E08879531",
"comment": "Both halves of aggregate nonce correspond to point at infinity"
+ },
+ {
+ "key_indices": [0, 1, 2],
+ "nonce_indices": [0, 1, 2],
+ "aggnonce_index": 0,
+ "msg_index": 1,
+ "signer_index": 0,
+ "expected": "D7D63FFD644CCDA4E62BC2BC0B1D02DD32A1DC3030E155195810231D1037D82D",
+ "comment": "Empty message"
+ },
+ {
+ "key_indices": [0, 1, 2],
+ "nonce_indices": [0, 1, 2],
+ "aggnonce_index": 0,
+ "msg_index": 2,
+ "signer_index": 0,
+ "expected": "E184351828DA5094A97C79CABDAAA0BFB87608C32E8829A4DF5340A6F243B78C",
+ "comment": "38-byte message"
}
],
"sign_error_test_cases": [
@@ -74,7 +92,7 @@
"type": "value",
"message": "The signer's pubkey must be included in the list of pubkeys."
},
- "comment": "The signers pubkey is not in the list of pubkeys"
+ "comment": "The signers pubkey is not in the list of pubkeys. This test case is optional: it can be skipped by implementations that do not check that the signer's pubkey is included in the list of pubkeys."
},
{
"key_indices": [1, 0, 3],
@@ -139,15 +157,15 @@
],
"verify_fail_test_cases": [
{
- "sig": "97AC833ADCB1AFA42EBF9E0725616F3C9A0D5B614F6FE283CEAAA37A8FFAF406",
+ "sig": "FED54434AD4CFE953FC527DC6A5E5BE8F6234907B7C187559557CE87A0541C46",
"key_indices": [0, 1, 2],
"nonce_indices": [0, 1, 2],
"msg_index": 0,
"signer_index": 0,
"comment": "Wrong signature (which is equal to the negation of valid signature)"
},
{
- "sig": "68537CC5234E505BD14061F8DA9E90C220A181855FD8BDB7F127BB12403B4D3B",
+ "sig": "012ABBCB52B3016AC03AD82395A1A415C48B93DEF78718E62A7A90052FE224FB",
"key_indices": [0, 1, 2],
"nonce_indices": [0, 1, 2],
"msg_index": 0,
@@ -165,7 +183,7 @@
],
"verify_error_test_cases": [
{
- "sig": "68537CC5234E505BD14061F8DA9E90C220A181855FD8BDB7F127BB12403B4D3B",
+ "sig": "012ABBCB52B3016AC03AD82395A1A415C48B93DEF78718E62A7A90052FE224FB",
"key_indices": [0, 1, 2],
"nonce_indices": [4, 1, 2],
"msg_index": 0,
@@ -178,7 +196,7 @@
"comment": "Invalid pubnonce"
},
{
- "sig": "68537CC5234E505BD14061F8DA9E90C220A181855FD8BDB7F127BB12403B4D3B",
+ "sig": "012ABBCB52B3016AC03AD82395A1A415C48B93DEF78718E62A7A90052FE224FB",
"key_indices": [3, 1, 2],
"nonce_indices": [0, 1, 2],
"msg_index": 0,
### btcec/schnorr/musig2/musig2_test.go
@@ -431,17 +431,6 @@ func TestMuSigEarlyNonce(t *testing.T) {
}
}
-type memsetRandReader struct {
- i int
-}
-
-func (mr *memsetRandReader) Read(buf []byte) (n int, err error) {
- for i := range buf {
- buf[i] = byte(mr.i)
- }
- return len(buf), nil
-}
-
// TestSigningWithAggregatedNonce tests the aggregated nonce signing flow where
// nonces are aggregated externally and provided to participants via
// RegisterCombinedNonce, rather than each participant aggregating nonces
### btcec/schnorr/musig2/nonces_test.go
@@ -9,6 +9,7 @@ import (
"fmt"
"os"
"path"
+ "strings"
"testing"
"github.com/stretchr/testify/require"
@@ -22,7 +23,8 @@ type nonceGenTestCase struct {
ExtraIn string `json:"extra_in"`
Pk string `json:"pk"`
- Expected string `json:"expected"`
+ ExpectedSecNonce string `json:"expected_secnonce"`
+ ExpectedPubNonce string `json:"expected_pubnonce"`
}
type nonceGenTestCases struct {
@@ -51,8 +53,9 @@ func TestMusig2NonceGenTestVectors(t *testing.T) {
for i, testCase := range testCases.TestCases {
testCase := testCase
+ randBytes := mustParseHex(testCase.Rand)
customOpts := nonceGenOpts{
- randReader: &memsetRandReader{i: 0},
+ randReader: bytes.NewReader(randBytes),
secretKey: mustParseHex(testCase.Sk),
combinedKey: mustParseHex(testCase.AggPk),
auxInput: mustParseHex(testCase.ExtraIn),
@@ -68,12 +71,14 @@ func TestMusig2NonceGenTestVectors(t *testing.T) {
t.Fatalf("err gen nonce aux bytes %v", err)
}
- expectedBytes, _ := hex.DecodeString(testCase.Expected)
- if !bytes.Equal(nonce.SecNonce[:], expectedBytes) {
-
- t.Fatalf("nonces don't match: expected %x, got %x",
- expectedBytes, nonce.SecNonce[:])
- }
+ require.Equal(
+ t, strings.ToLower(testCase.ExpectedSecNonce),
+ hex.EncodeToString(nonce.SecNonce[:]),
+ )
+ require.Equal(
+ t, strings.ToLower(testCase.ExpectedPubNonce),
+ hex.EncodeToString(nonce.PubNonce[:]),
+ )
})
}
}
### btcec/schnorr/musig2/sign_test.go
@@ -119,6 +119,14 @@ func TestMusig2SignVerify(t *testing.T) {
testName := fmt.Sprintf("valid_case_%v", i)
t.Run(testName, func(t *testing.T) {
+ msgBytes := mustParseHex(
+ testCases.Msgs[testCase.MsgIndex],
+ )
+ if len(msgBytes) != 32 {
+ t.Skipf("Sign takes a 32-byte message, got %d",
+ len(msgBytes))
+ }
+
pubKeys, err := keysFromIndices(
t, testCase.Indices, testCases.PubKeys,
)
@@ -132,7 +140,7 @@ func TestMusig2SignVerify(t *testing.T) {
require.NoError(t, err)
var msg [32]byte
- copy(msg[:], mustParseHex(testCases.Msgs[testCase.MsgIndex]))
+ copy(msg[:], msgBytes)
var secNonce [SecNonceSize]byte
copy(secNonce[:], mustParseHex(testCases.PrivNonces[0]))
@@ -218,10 +226,8 @@ func TestMusig2SignVerify(t *testing.T) {
mustParseHex(testCases.Msgs[testCase.MsgIndex]),
)
- var secNonce [SecNonceSize]byte
- copy(secNonce[:], mustParseHex(testCases.PrivNonces[0]))
-
- signerNonce := secNonceToPubNonce(secNonce)
+ signerNonce := pubNonces[testCase.SignerIndex]
+ signerKey := pubKeys[testCase.SignerIndex]
var partialSig PartialSignature
err = partialSig.Decode(
@@ -233,8 +239,7 @@ func TestMusig2SignVerify(t *testing.T) {
err = verifyPartialSig(
&partialSig, signerNonce, combinedNonce,
- pubKeys, privKey.PubKey().SerializeCompressed(),
- msg,
+ pubKeys, signerKey.SerializeCompressed(), msg,
)
require.Error(t, err)
})Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.