Skip to content

Commit 895b762

Browse files
committed
utils: document raw-key normalization semantics
Document that Loop's raw-key MuSig2 helper and hash-derived internal-key helper both rely on btcec.PrivKeyFromBytes normalization semantics. This makes the current protocol behavior explicit without changing it.
1 parent 533e626 commit 895b762

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

loopin.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,10 @@ func (s *loopInSwap) setState(state loopdb.SwapState) {
12141214
}
12151215

12161216
// sharedSecretFromHash derives the shared secret from the swap hash using the
1217-
// swap.KeyFamily family and zero as index.
1217+
// swap.KeyFamily family and zero as index. The swap hash is first interpreted
1218+
// with btcec.PrivKeyFromBytes semantics, so the derived ephemeral pubkey uses
1219+
// the same modulo-N normalization as the internal-key code paths that consume
1220+
// the resulting shared secret.
12181221
func sharedSecretFromHash(ctx context.Context, signer lndclient.SignerClient,
12191222
hash lntypes.Hash) ([32]byte, error) {
12201223

utils/musig.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ import (
1010
)
1111

1212
// MuSig2Sign will create a MuSig2 signature for the passed message using the
13-
// passed raw private keys. It expects at least two signing keys.
13+
// passed raw private keys. Raw keys are interpreted with
14+
// btcec.PrivKeyFromBytes semantics, which normalize 32-byte inputs modulo the
15+
// secp256k1 group order instead of rejecting out-of-range values. It expects
16+
// at least two signing keys.
1417
func MuSig2Sign(version input.MuSig2Version, keys [][32]byte,
1518
tweaks *input.MuSig2Tweaks, msg [32]byte) ([]byte, error) {
1619

1720
privKeys := make([]*btcec.PrivateKey, len(keys))
1821
pubKeys := make([]*btcec.PublicKey, len(keys))
1922

2023
// First parse the raw private keys and also create the corresponding
21-
// public keys.
24+
// public keys. This preserves the same normalization semantics used
25+
// when these raw keys are turned into pubkeys elsewhere in the protocol.
2226
for i, key := range keys {
2327
privKeys[i], pubKeys[i] = btcec.PrivKeyFromBytes(key[:])
2428

0 commit comments

Comments
 (0)