Skip to content

Commit

Permalink
add log for revocation pk and local htlc pk.
Browse files Browse the repository at this point in the history
  • Loading branch information
ziggie1984 committed Jan 15, 2024
1 parent c6fcebb commit 809ea83
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions cmd/chantools/sweeptimelockmanual.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil/hdkeychain"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/txscript"
Expand Down Expand Up @@ -452,6 +453,16 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
return 0, nil, nil, nil, nil, err
}

// The easy part first, let's derive the delay base point.
htlcPath := []uint32{
lnd.HardenedKey(uint32(keychain.KeyFamilyHtlcBase)),
0, idx,
}
htlcPrivKey, err := lnd.PrivKeyFromPath(baseKey, htlcPath)
if err != nil {
return 0, nil, nil, nil, nil, err
}

// Get the revocation base point first, so we can calculate our
// commit point. We start with the old way where the revocation index
// was the same as the other indices. This applies to all channels
Expand All @@ -470,7 +481,7 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
// will take a long while as we both have to go through commit
// points and CSV values.
csvTimeout, script, scriptHash, commitPoint, err := bruteForceDelayPoint(
delayPrivKey.PubKey(), remoteRevPoint, revRoot, lockScript,
delayPrivKey.PubKey(), remoteRevPoint, htlcPrivKey.PubKey(), revRoot, lockScript,
startCsvTimeout, maxCsvTimeout, startNumChanUpdates,
maxNumChanUpdates)
if err == nil {
Expand Down Expand Up @@ -535,7 +546,7 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
}

csvTimeout, script, scriptHash, commitPoint, err = bruteForceDelayPoint(
delayPrivKey.PubKey(), remoteRevPoint, revRoot2, lockScript,
delayPrivKey.PubKey(), remoteRevPoint, htlcPrivKey.PubKey(), revRoot2, lockScript,
startCsvTimeout, maxCsvTimeout, startNumChanUpdates,
maxNumChanUpdates,
)
Expand Down Expand Up @@ -577,7 +588,7 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
}

csvTimeout, script, scriptHash, commitPoint, err = bruteForceDelayPoint(
delayPrivKey.PubKey(), remoteRevPoint, revRoot3, lockScript,
delayPrivKey.PubKey(), remoteRevPoint, htlcPrivKey.PubKey(), revRoot3, lockScript,
startCsvTimeout, maxCsvTimeout, startNumChanUpdates,
maxNumChanUpdates,
)
Expand All @@ -595,7 +606,7 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
return 0, nil, nil, nil, nil, fmt.Errorf("target script not derived")
}

func bruteForceDelayPoint(delayBase, revBase *btcec.PublicKey,
func bruteForceDelayPoint(delayBase, revBase, htlcBase *btcec.PublicKey,
revRoot *shachain.RevocationProducer, lockScript []byte,
startCsvTimeout, maxCsvTimeout uint16, startNumChanUpdates,
maxChanUpdates uint64) (int32, []byte, []byte, *btcec.PublicKey,
Expand All @@ -610,6 +621,12 @@ func bruteForceDelayPoint(delayBase, revBase *btcec.PublicKey,
}
commitPoint := input.ComputeCommitmentPoint(revPreimage[:])

log.Infof("RevocationPK(RIPEMD160): %v",
btcutil.Hash160(input.DeriveRevocationPubkey(revBase, commitPoint).SerializeCompressed()))

log.Infof("LocalHTLCPK: %v",
btcutil.Hash160(input.TweakPubKey(htlcBase, commitPoint).SerializeCompressed()))

log.Infof("CommitPoint at ChanUpdate#%v", i)

csvTimeout, script, scriptHash, err := bruteForceDelay(
Expand Down

0 comments on commit 809ea83

Please sign in to comment.