From 7b002175f4281ef5b818c0705f1617dc581d3ff7 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 29 Jul 2017 18:39:58 -0700 Subject: [PATCH] lnwallet: update state hint derivation to match BOLT-0003 --- lnwallet/wallet.go | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 8de8204a..50c6a264 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -1339,22 +1339,24 @@ func (l *LightningWallet) deriveMasterRevocationRoot() (*btcec.PrivateKey, error } // deriveStateHintObfuscator derives the bytes to be used for obfuscating the -// state hints from the root to be used for a new channel. The -// obfuscator is generated by performing an additional sha256 hash of the first -// child derived from the revocation root. The leading 4 bytes are used for the -// obfuscator. -func deriveStateHintObfuscator(producer shachain.Producer) ([StateHintSize]byte, error) { +// state hints from the root to be used for a new channel. The obsfucsator is +// generated via the following computation: +// +// * sha256(initiatorKey || responderKey)[:6] +// * where both keys are the multi-sig keys of the respective parties +// +// The first 6 bytes of the resulting hash are used as the state hint. +func deriveStateHintObfuscator(key1, key2 *btcec.PublicKey) [StateHintSize]byte { + h := sha256.New() + h.Write(key1.SerializeCompressed()) + h.Write(key2.SerializeCompressed()) + + sha := h.Sum(nil) + var obfuscator [StateHintSize]byte + copy(obfuscator[:], sha[:]) - firstChild, err := producer.AtIndex(0) - if err != nil { - return obfuscator, err - } - - grandChild := sha256.Sum256(firstChild[:]) - copy(obfuscator[:], grandChild[:]) - - return obfuscator, nil + return obfuscator } // initStateHints properly sets the obsfucated state hints on both commitment @@ -1408,8 +1410,8 @@ func selectInputs(amt btcutil.Amount, coins []*Utxo) (btcutil.Amount, []*wire.Ou return satSelected, selectedUtxos, nil } -// coinSelect attemps to select a sufficient amount of coins, including a -// change output to fund amt satoshis, adhearing to the specified fee rate. The +// coinSelect attempts to select a sufficient amount of coins, including a +// change output to fund amt satoshis, adhering to the specified fee rate. The // specified fee rate should be expressed in sat/byte for coin selection to // function properly. func coinSelect(feeRate uint64, amt btcutil.Amount,