Skip to content

Commit 2a8bb5a

Browse files
committed
Fixup: add test to verify shared input weights
1 parent 15102e2 commit 2a8bb5a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

eclair-core/src/main/scala/fr/acinq/eclair/channel/fund/InteractiveTxBuilder.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,12 @@ object InteractiveTxBuilder {
126126
}
127127

128128
case class Musig2Input(info: InputInfo, fundingTxIndex: Long, remoteFundingPubkey: PublicKey, commitIndex: Long) extends SharedFundingInput {
129-
override val weight: Int = 234
129+
// witness is a single 64 bytes signature, weight = 1 (# of items) + 1 (size) + 64 = 66
130+
// weight is 4 * (unsigned input weight) + witness weight = 4 * (32 + 4 + 4 + 1) + 66 = 230
131+
override val weight: Int = 230
130132

131-
override def sign(keyManager: ChannelKeyManager, params: ChannelParams, tx: Transaction): ByteVector64 = ByteVector64.Zeroes
133+
// a valid signature for this input MUST be the Musig2 aggregation of local and remote partial signatures
134+
override def sign(keyManager: ChannelKeyManager, params: ChannelParams, tx: Transaction): ByteVector64 = ???
132135
}
133136

134137
/**

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,14 +490,6 @@ object Scripts {
490490
// @formatter:on
491491
}
492492

493-
def isClaimHtlcTimeoutWitness(witness: ScriptWitness): Boolean = witness.stack match {
494-
case sig :: script :: controlBlock :: Nil if sig.size == 64 && script.size == 41 && controlBlock.size == 65 => Script.parse(script) match {
495-
case OP_PUSHDATA(x, _) :: OP_CHECKSIGVERIFY :: OP_1 :: OP_CHECKSEQUENCEVERIFY :: OP_VERIFY :: _ :: OP_CHECKLOCKTIMEVERIFY :: Nil if x.size == 32 => true
496-
case _ => false
497-
}
498-
case _ => false
499-
}
500-
501493
/**
502494
* Script that can be spent when a received (incoming) HTLC is fulfilled.
503495
* It is spent using a pre-signed HTLC transaction signed with both keys and the preimage.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import fr.acinq.eclair.TestUtils.randomTxId
2525
import fr.acinq.eclair._
2626
import fr.acinq.eclair.blockchain.fee.{ConfirmationTarget, FeeratePerKw}
2727
import fr.acinq.eclair.channel.Helpers.Funding
28+
import fr.acinq.eclair.channel.fund.InteractiveTxBuilder.{Multisig2of2Input, Musig2Input}
2829
import fr.acinq.eclair.transactions.CommitmentOutput.{InHtlc, OutHtlc}
2930
import fr.acinq.eclair.transactions.Scripts._
3031
import fr.acinq.eclair.transactions.Transactions.AnchorOutputsCommitmentFormat.anchorAmount
@@ -555,6 +556,8 @@ class TransactionsSpec extends AnyFunSuite with Logging {
555556
val commitTx = Transactions.addAggregatedSignature(txInfo, sig)
556557
val expectedCommitTxWeight = commitmentFormat.commitWeight + 5 * commitmentFormat.htlcOutputWeight
557558
assertWeightMatches(commitTx.tx.weight(), expectedCommitTxWeight, commitmentFormat)
559+
val sharedInput = Musig2Input(InputInfo.TaprootInput(fundingTxOutpoint, fundingOutput, Taproot.musig2Aggregate(localFundingPriv.publicKey, remoteFundingPriv.publicKey), InputInfo.RedeemPath.KeyPath(None)), 0, remoteFundingPriv.publicKey, 0)
560+
assertWitnessWeightMatches(commitTx.tx.txIn(0).witness, sharedInput.weight, commitmentFormat)
558561
commitTx
559562
case DefaultCommitmentFormat | _: AnchorOutputsCommitmentFormat =>
560563
val localSig = txInfo.sign(localFundingPriv, TxOwner.Local, commitmentFormat)
@@ -563,6 +566,8 @@ class TransactionsSpec extends AnyFunSuite with Logging {
563566
val expectedCommitTxWeight = commitmentFormat.commitWeight + 5 * commitmentFormat.htlcOutputWeight
564567
// we cannot do exact matches because DER signature encoding is variable length
565568
assertWeightMatches(commitTx.tx.weight(), expectedCommitTxWeight, commitmentFormat)
569+
val sharedInput = Multisig2of2Input(InputInfo.SegwitInput(fundingTxOutpoint, fundingOutput, Scripts.multiSig2of2(localFundingPriv.publicKey, remoteFundingPriv.publicKey)), 0, remoteFundingPriv.publicKey)
570+
assertWitnessWeightMatches(commitTx.tx.txIn(0).witness, sharedInput.weight, commitmentFormat)
566571
commitTx
567572
}
568573
assert(checkSpendable(commitTx).isSuccess)

0 commit comments

Comments
 (0)