Skip to content

Commit f0e0a20

Browse files
committed
Match against all commitment formats explicitly
1 parent 5cf79ac commit f0e0a20

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ object Helpers {
381381
val fundingScript = Taproot.musig2FundingScript(fundingPubkey1, fundingPubkey2)
382382
val fundingTxOut = TxOut(fundingSatoshis, fundingScript)
383383
InputInfo.TaprootInput(OutPoint(fundingTxId, fundingTxOutputIndex), fundingTxOut, Taproot.musig2Aggregate(fundingPubkey1, fundingPubkey2), None, ByteVector32.Zeroes)
384-
case _ =>
384+
case DefaultCommitmentFormat | _: AnchorOutputsCommitmentFormat =>
385385
val fundingScript = multiSig2of2(fundingPubkey1, fundingPubkey2)
386386
val fundingTxOut = TxOut(fundingSatoshis, pay2wsh(fundingScript))
387387
InputInfo.SegwitInput(OutPoint(fundingTxId, fundingTxOutputIndex), fundingTxOut, write(fundingScript))

eclair-core/src/main/scala/fr/acinq/eclair/channel/fsm/Channel.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import fr.acinq.eclair.io.Peer.LiquidityPurchaseSigned
4848
import fr.acinq.eclair.payment.relay.Relayer
4949
import fr.acinq.eclair.payment.{Bolt11Invoice, PaymentSettlingOnChain}
5050
import fr.acinq.eclair.router.Announcements
51-
import fr.acinq.eclair.transactions.Transactions.ClosingTx
51+
import fr.acinq.eclair.transactions.Transactions.{AnchorOutputsCommitmentFormat, ClosingTx, DefaultCommitmentFormat, SimpleTaprootChannelCommitmentFormat}
5252
import fr.acinq.eclair.transactions._
5353
import fr.acinq.eclair.wire.protocol._
5454

@@ -2152,7 +2152,7 @@ class Channel(val nodeParams: NodeParams, val wallet: OnChainChannelFunder with
21522152

21532153
case Event(c: CMD_BUMP_FORCE_CLOSE_FEE, d: DATA_CLOSING) =>
21542154
d.commitments.params.commitmentFormat match {
2155-
case _: Transactions.AnchorOutputsCommitmentFormat =>
2155+
case SimpleTaprootChannelCommitmentFormat | _: Transactions.AnchorOutputsCommitmentFormat =>
21562156
val lcp1 = d.localCommitPublished.map(lcp => Closing.LocalClose.claimAnchors(keyManager, d.commitments.latest, lcp, c.confirmationTarget))
21572157
val rcp1 = d.remoteCommitPublished.map(rcp => Closing.RemoteClose.claimAnchors(keyManager, d.commitments.latest, rcp, c.confirmationTarget))
21582158
val nrcp1 = d.nextRemoteCommitPublished.map(nrcp => Closing.RemoteClose.claimAnchors(keyManager, d.commitments.latest, nrcp, c.confirmationTarget))
@@ -2174,7 +2174,7 @@ class Channel(val nodeParams: NodeParams, val wallet: OnChainChannelFunder with
21742174
c.replyTo ! RES_FAILURE(c, CommandUnavailableInThisState(d.channelId, "rbf-force-close", stateName))
21752175
stay()
21762176
}
2177-
case _ =>
2177+
case DefaultCommitmentFormat =>
21782178
log.warning("cannot bump force-close fees, channel is not using anchor outputs")
21792179
c.replyTo ! RES_FAILURE(c, CommandUnavailableInThisState(d.channelId, "rbf-force-close", stateName))
21802180
stay()

eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ object Transactions {
142142
/** Sighash flags to use when signing the transaction. */
143143
def sighash(txOwner: TxOwner, commitmentFormat: CommitmentFormat): Int = commitmentFormat match {
144144
case SimpleTaprootChannelCommitmentFormat => SIGHASH_DEFAULT
145-
case _ => SIGHASH_ALL
145+
case DefaultCommitmentFormat | _:AnchorOutputsCommitmentFormat => SIGHASH_ALL
146146
}
147147

148148
def sign(key: PrivateKey, txOwner: TxOwner, commitmentFormat: CommitmentFormat): ByteVector64 = {
@@ -567,7 +567,7 @@ object Transactions {
567567
outputs.append(CommitmentOutputLink(
568568
TxOut(htlc.add.amountMsat.truncateToSatoshi, pay2tr(localRevocationPubkey.xOnly, Some(offeredHtlcTree))), localRevocationPubkey.xOnly, offeredHtlcTree, OutHtlc(htlc)
569569
))
570-
case _ =>
570+
case DefaultCommitmentFormat | _: AnchorOutputsCommitmentFormat =>
571571
val redeemScript = htlcOffered(localHtlcPubkey, remoteHtlcPubkey, localRevocationPubkey, ripemd160(htlc.add.paymentHash.bytes), commitmentFormat)
572572
outputs.append(CommitmentOutputLink(TxOut(htlc.add.amountMsat.truncateToSatoshi, pay2wsh(redeemScript)), redeemScript, OutHtlc(htlc)))
573573
}
@@ -580,7 +580,7 @@ object Transactions {
580580
outputs.append(CommitmentOutputLink(
581581
TxOut(htlc.add.amountMsat.truncateToSatoshi, pay2tr(localRevocationPubkey.xOnly, Some(receivedHtlcTree))), localRevocationPubkey.xOnly, receivedHtlcTree, InHtlc(htlc)
582582
))
583-
case _ =>
583+
case DefaultCommitmentFormat | _: AnchorOutputsCommitmentFormat =>
584584
val redeemScript = htlcReceived(localHtlcPubkey, remoteHtlcPubkey, localRevocationPubkey, ripemd160(htlc.add.paymentHash.bytes), htlc.add.cltvExpiry, commitmentFormat)
585585
outputs.append(CommitmentOutputLink(TxOut(htlc.add.amountMsat.truncateToSatoshi, pay2wsh(redeemScript)), redeemScript, InHtlc(htlc)))
586586
}
@@ -597,16 +597,16 @@ object Transactions {
597597
if (toLocalAmount >= localDustLimit) {
598598
commitmentFormat match {
599599
case SimpleTaprootChannelCommitmentFormat =>
600-
val toLocalScriptTree = Scripts.Taproot.toLocalScriptTree(localRevocationPubkey, toLocalDelay, localDelayedPaymentPubkey)
601-
outputs.append(CommitmentOutputLink(
602-
TxOut(toLocalAmount, pay2tr(XonlyPublicKey(NUMS_POINT), Some(toLocalScriptTree))),
603-
NUMS_POINT.xOnly, toLocalScriptTree,
604-
ToLocal))
605-
case _ =>
606-
outputs.append(CommitmentOutputLink(
607-
TxOut(toLocalAmount, pay2wsh(toLocalDelayed(localRevocationPubkey, toLocalDelay, localDelayedPaymentPubkey))),
608-
toLocalDelayed(localRevocationPubkey, toLocalDelay, localDelayedPaymentPubkey),
609-
ToLocal))
600+
val toLocalScriptTree = Scripts.Taproot.toLocalScriptTree(localRevocationPubkey, toLocalDelay, localDelayedPaymentPubkey)
601+
outputs.append(CommitmentOutputLink(
602+
TxOut(toLocalAmount, pay2tr(XonlyPublicKey(NUMS_POINT), Some(toLocalScriptTree))),
603+
NUMS_POINT.xOnly, toLocalScriptTree,
604+
ToLocal))
605+
case DefaultCommitmentFormat | _: AnchorOutputsCommitmentFormat =>
606+
outputs.append(CommitmentOutputLink(
607+
TxOut(toLocalAmount, pay2wsh(toLocalDelayed(localRevocationPubkey, toLocalDelay, localDelayedPaymentPubkey))),
608+
toLocalDelayed(localRevocationPubkey, toLocalDelay, localDelayedPaymentPubkey),
609+
ToLocal))
610610
}
611611
}
612612

@@ -1182,7 +1182,7 @@ object Transactions {
11821182

11831183
def makeHtlcPenaltyTx(commitTx: Transaction, htlcOutputIndex: Int, internalKey: XonlyPublicKey, scriptTree: ScriptTree, localDustLimit: Satoshi, localFinalScriptPubKey: ByteVector, feeratePerKw: FeeratePerKw): Either[TxGenerationSkipped, HtlcPenaltyTx] = {
11841184
import KotlinUtils._
1185-
1185+
11861186
val input = InputInfo.TaprootInput(OutPoint(commitTx, htlcOutputIndex), commitTx.txOut(htlcOutputIndex), internalKey, Some(scriptTree), scriptTree.hash())
11871187
// unsigned transaction
11881188
val tx = Transaction(

eclair-core/src/test/scala/fr/acinq/eclair/transactions/TransactionsSpec.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ class TransactionsSpec extends AnyFunSuite with Logging {
741741
}
742742

743743
test("generate valid commitment and htlc transactions (simple taproot channels)") {
744-
val commitmentFormat = SimpleTaprootChannelCommitmentFormat
744+
val commitmentFormat: CommitmentFormat = SimpleTaprootChannelCommitmentFormat
745745
val finalPubKeyScript = Script.write(Script.pay2wpkh(PrivateKey(randomBytes32()).publicKey))
746746
// funding tx sends to musig2 aggregate of local and remote funding keys
747747
val fundingTx = Transaction(version = 2, txIn = Nil, txOut = TxOut(Btc(1), Script.pay2tr(Taproot.musig2Aggregate(localFundingPriv.publicKey, remoteFundingPriv.publicKey), None)) :: Nil, lockTime = 0)
@@ -779,7 +779,7 @@ class TransactionsSpec extends AnyFunSuite with Logging {
779779
sig <- Musig2.aggregateTaprootSignatures(Seq(localPartialSig, remotePartialSig), txInfo.tx, 0, Seq(fundingOutput), publicKeys, publicNonces, None)
780780
} yield sig
781781
Transactions.addAggregatedSignature(txInfo, sig)
782-
case _ =>
782+
case DefaultCommitmentFormat | _: AnchorOutputsCommitmentFormat =>
783783
val localSig = txInfo.sign(localPaymentPriv, TxOwner.Local, commitmentFormat)
784784
val remoteSig = txInfo.sign(remotePaymentPriv, TxOwner.Remote, commitmentFormat)
785785
Transactions.addSigs(txInfo, localFundingPriv.publicKey, remoteFundingPriv.publicKey, localSig, remoteSig)
@@ -820,7 +820,7 @@ class TransactionsSpec extends AnyFunSuite with Logging {
820820
// local spends local anchor
821821
val anchorKey = commitmentFormat match {
822822
case SimpleTaprootChannelCommitmentFormat => localDelayedPaymentPriv
823-
case _ => localFundingPriv
823+
case DefaultCommitmentFormat | _: AnchorOutputsCommitmentFormat => localFundingPriv
824824
}
825825
val Right(claimAnchorOutputTx) = makeClaimLocalAnchorOutputTx(commitTx.tx, anchorKey.publicKey, ConfirmationTarget.Absolute(BlockHeight(0)))
826826
assert(checkSpendable(claimAnchorOutputTx).isFailure)
@@ -832,7 +832,7 @@ class TransactionsSpec extends AnyFunSuite with Logging {
832832
// remote spends remote anchor
833833
val anchorKey = commitmentFormat match {
834834
case SimpleTaprootChannelCommitmentFormat => remotePaymentPriv
835-
case _ => remoteFundingPriv
835+
case DefaultCommitmentFormat | _: AnchorOutputsCommitmentFormat => remoteFundingPriv
836836
}
837837
val Right(claimAnchorOutputTx) = makeClaimLocalAnchorOutputTx(commitTx.tx, anchorKey.publicKey, ConfirmationTarget.Absolute(BlockHeight(0)))
838838
assert(checkSpendable(claimAnchorOutputTx).isFailure)
@@ -955,7 +955,7 @@ class TransactionsSpec extends AnyFunSuite with Logging {
955955
case SimpleTaprootChannelCommitmentFormat =>
956956
val scriptTree = Taproot.offeredHtlcScriptTree(localHtlcPriv.publicKey, remoteHtlcPriv.publicKey, htlc1.paymentHash)
957957
makeHtlcPenaltyTx(commitTx.tx, htlcOutputIndex, localRevocationPriv.publicKey.xOnly, scriptTree, localDustLimit, finalPubKeyScript, feeratePerKw)
958-
case _ =>
958+
case DefaultCommitmentFormat | _: AnchorOutputsCommitmentFormat =>
959959
val script = Script.write(Scripts.htlcOffered(localHtlcPriv.publicKey, remoteHtlcPriv.publicKey, localRevocationPriv.publicKey, Crypto.ripemd160(htlc1.paymentHash), commitmentFormat))
960960
makeHtlcPenaltyTx(commitTx.tx, htlcOutputIndex, script, localDustLimit, finalPubKeyScript, feeratePerKw)
961961
}
@@ -973,7 +973,7 @@ class TransactionsSpec extends AnyFunSuite with Logging {
973973
case SimpleTaprootChannelCommitmentFormat =>
974974
val scriptTree = Taproot.receivedHtlcScriptTree(localHtlcPriv.publicKey, remoteHtlcPriv.publicKey, htlc.paymentHash, htlc.cltvExpiry)
975975
makeHtlcPenaltyTx(commitTx.tx, htlcOutputIndex, localRevocationPriv.publicKey.xOnly, scriptTree, localDustLimit, finalPubKeyScript, feeratePerKw)
976-
case _ =>
976+
case DefaultCommitmentFormat | _: AnchorOutputsCommitmentFormat =>
977977
val script = Script.write(Scripts.htlcReceived(localHtlcPriv.publicKey, remoteHtlcPriv.publicKey, localRevocationPriv.publicKey, Crypto.ripemd160(htlc.paymentHash), htlc.cltvExpiry, commitmentFormat))
978978
makeHtlcPenaltyTx(commitTx.tx, htlcOutputIndex, script, localDustLimit, finalPubKeyScript, feeratePerKw)
979979
}

0 commit comments

Comments
 (0)