From 04487a4a764b8a6b1a3f968e1042aff80ed44aed Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 7 Feb 2018 17:17:46 -0800 Subject: [PATCH] utxonursery: fix witness overwriting bug Fixes a minor indexing bug that could cause the utxonursery to accidentally overwrite CSV witnesses with other CLTV witnesses when populating a sweep txn. Each type of output is treated separately internally, the bug is introduced by using the relative indexes of both sets as the final indexes into the txins. The fix adds an offset, equal to the number of CSV outputs, to the relative indexes of the CLTV inputs. This matches the order in which CSV and CLTV outputs are added to the raw txn. --- utxonursery.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utxonursery.go b/utxonursery.go index 87686c73..3c01967b 100644 --- a/utxonursery.go +++ b/utxonursery.go @@ -1095,8 +1095,12 @@ func (u *utxoNursery) populateSweepTx(txWeight uint64, classHeight uint32, return nil, err } } + + // Add offset to relative indexes so cltv witnesses don't overwrite csv + // witnesses. + offset := len(csvInputs) for i, input := range cltvInputs { - if err := addWitness(i, input); err != nil { + if err := addWitness(offset+i, input); err != nil { return nil, err } }