Skip to content

Commit

Permalink
fixup! 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 16, 2024
1 parent 809ea83 commit cda34bf
Showing 1 changed file with 42 additions and 11 deletions.
53 changes: 42 additions & 11 deletions cmd/chantools/sweeptimelockmanual.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error
startNumChannelsTotal = c.StartNumChannelsTotal
maxNumChannelsTotal = c.MaxNumChannelsTotal
remoteRevocationBasePoint = c.RemoteRevocationBasePoint
multiSigIdx uint32
)

// We either support specifying the remote revocation base point
Expand Down Expand Up @@ -231,6 +232,17 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error
startNumChannelsTotal = uint16(delayPath[4])
maxNumChannelsTotal = startNumChannelsTotal + 1

multiSigKeyPath, err := lnd.ParsePath(
backupChan.LocalChanCfg.MultiSigKey.Path,
)
if err != nil {
return fmt.Errorf("error parsing multisigkey path: %w", err)
}
if len(multiSigKeyPath) != 5 {
return fmt.Errorf("invalid delay path '%v'", delayPath)
}
multiSigIdx = multiSigKeyPath[4]

case c.ChannelBackup != "" && c.RemoteRevocationBasePoint != "":
return fmt.Errorf("cannot use both --frombackup and " +
"--remoterevbasepoint at the same time")
Expand All @@ -250,15 +262,15 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error

return sweepTimeLockManual(
extendedKey, c.APIURL, c.SweepAddr, c.TimeLockAddr,
remoteRevPoint, startCsvLimit, maxCsvLimit,
remoteRevPoint, multiSigIdx, startCsvLimit, maxCsvLimit,
startNumChannelsTotal, maxNumChannelsTotal,
c.StartNumChanUpdates, c.MaxNumChanUpdates, c.Publish,
c.FeeRate,
)
}

func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
sweepAddr, timeLockAddr string, remoteRevPoint *btcec.PublicKey,
sweepAddr, timeLockAddr string, remoteRevPoint *btcec.PublicKey, multiSigIdx uint32,
startCsvTimeout, maxCsvTimeout, startNumChannels, maxNumChannels uint16,
startNumChanUpdates, maxNumChanUpdates uint64, publish bool,
feeRate uint32) error {
Expand Down Expand Up @@ -326,7 +338,7 @@ func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
log.Infof("Trying RevocationRoot at %v", i)

csvTimeout, script, scriptHash, commitPoint, delayDesc, err = tryKey(
baseKey, remoteRevPoint, startCsvTimeout, maxCsvTimeout,
baseKey, remoteRevPoint, multiSigIdx, startCsvTimeout, maxCsvTimeout,
lockScript, uint32(i), startNumChanUpdates,
maxNumChanUpdates,
)
Expand Down Expand Up @@ -439,8 +451,9 @@ func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
}

func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
startCsvTimeout, maxCsvTimeout uint16, lockScript []byte, idx uint32,
startNumChanUpdates, maxNumChanUpdates uint64) (int32, []byte, []byte,
multiSigIdx uint32, startCsvTimeout, maxCsvTimeout uint16,
lockScript []byte, idx uint32, startNumChanUpdates,
maxNumChanUpdates uint64) (int32, []byte, []byte,
*btcec.PublicKey, *keychain.KeyDescriptor, error) {

// The easy part first, let's derive the delay base point.
Expand Down Expand Up @@ -528,10 +541,13 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
)), 0, idx,
}

if multiSigIdx == 0 {
multiSigIdx = idx
}
// Now we try the same with the new revocation producer format.
multiSigPath := []uint32{
lnd.HardenedKey(uint32(keychain.KeyFamilyMultiSig)),
0, idx,
0, multiSigIdx,
}
multiSigPrivKey, err := lnd.PrivKeyFromPath(baseKey, multiSigPath)
if err != nil {
Expand Down Expand Up @@ -570,10 +586,14 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
)), 0, idx + 1,
}

if multiSigIdx == 0 {
multiSigIdx = idx
}

// Now we try the same with the new revocation producer format.
multiSigPath = []uint32{
lnd.HardenedKey(uint32(keychain.KeyFamilyMultiSig)),
0, idx,
0, multiSigIdx,
}
multiSigPrivKey, err = lnd.PrivKeyFromPath(baseKey, multiSigPath)
if err != nil {
Expand All @@ -587,6 +607,11 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
return 0, nil, nil, nil, nil, err
}

log.Infof("MultiSigBase: %x",
multiSigPrivKey.PubKey().SerializeCompressed())

log.Infof("ShaRootPath: %v", revPath3)

csvTimeout, script, scriptHash, commitPoint, err = bruteForceDelayPoint(
delayPrivKey.PubKey(), remoteRevPoint, htlcPrivKey.PubKey(), revRoot3, lockScript,
startCsvTimeout, maxCsvTimeout, startNumChanUpdates,
Expand Down Expand Up @@ -621,13 +646,19 @@ func bruteForceDelayPoint(delayBase, revBase, htlcBase *btcec.PublicKey,
}
commitPoint := input.ComputeCommitmentPoint(revPreimage[:])

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

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

log.Infof("DelayedBase: %x",
delayBase.SerializeCompressed())

log.Infof("HTLCBase: %x",
htlcBase.SerializeCompressed())

log.Infof("CommitPoint at ChanUpdate#%v", i)
log.Infof("CommitPoint at ChanUpdate#%v, CPoint=%x", i, commitPoint.SerializeCompressed())

csvTimeout, script, scriptHash, err := bruteForceDelay(
input.TweakPubKey(delayBase, commitPoint),
Expand Down

0 comments on commit cda34bf

Please sign in to comment.