Check remote previous txOut against the blockchain (#3411)
What changed, and why it matters
This commit fixes a security bug in Eclair's taproot channel splicing. When two users splice a Lightning channel, one side can describe its bitcoin inputs by sending only a small summary (the txOut) instead of the full previous transaction. Before this fix, Eclair trusted that summary without checking it against the actual blockchain. A dishonest peer could lie about the amount or script of its input, causing the splice transaction to be permanently unconfirmable. Because taproot signatures commit to the spent outputs, the victim would have already signed an invalid splice, while the attacker could later publish the old channel commitment and steal HTLCs (pending Lightning payments) after they time out. The fix fetches the real previous transaction from the user's own bitcoin node and aborts if the summary does not match.
Upgrade to a version containing this commit. Nodes running Eclair with taproot channel support should apply the patch promptly, as it closes a path for fund/HTLC loss via malicious peer input claims during splice.
Security signals we found
Missing cryptographic/chain validation of peer-supplied transaction data
Taproot signature commits to spent outputs, making a signed-but-unconfirmable splice possible
Potential HTLC theft via old commitment publication after splice timeout
Bypass of confirmed-input restriction for Phoenix swap-in inputs
New exception InvalidPreviousTxOut added and tested
Evidence from the diff
In InteractiveTxBuilder, remote inputs for taproot splices may be sent via tx_add_input with only a PrevTxOut TLV (txid, amount, script) and no previousTx_opt. The builder previously used this txOut directly for signature verification and confirmation checks without validating it against the chain. The patch introduces remoteInputsWithoutPreviousTx, a set tracking such inputs. Before signing, checkPreviousTxOuts queries wallet.getTransaction for each outPoint and compares the returned txOut to the one claimed by the peer; a mismatch throws InvalidPreviousTxOut and aborts the splice. This validation is placed before confirmation and plugin validation because downstream checks depend on the claimed txOut. A test simulates Alice lying about her wallet input amount and verifies Bob rejects the splice with InvalidPreviousTxOut.
Changed components
eclair-core/src/main/scala/fr/acinq/eclair/channel/fund/InteractiveTxBuilder.scalaeclair-core/src/main/scala/fr/acinq/einq/channel/ChannelExceptions.scalaTaproot channel splicing / interactive transaction constructionInspect captured patch +111 / −4
### eclair-core/src/main/scala/fr/acinq/eclair/channel/ChannelExceptions.scala
@@ -70,6 +70,7 @@ case class NonReplaceableInput (override val channelId: Byte
case class RelativeLockTimeInput (override val channelId: ByteVector32, serialId: UInt64, sequence: Long) extends ChannelException(channelId, s"input must not use a relative lock time (serial_id=${serialId.toByteVector.toHex}, nSequence=$sequence)")
case class NonSegwitInput (override val channelId: ByteVector32, serialId: UInt64, previousTxId: TxId, previousTxOutput: Long) extends ChannelException(channelId, s"$previousTxId:$previousTxOutput is not a native segwit input (serial_id=${serialId.toByteVector.toHex})")
case class PreviousTxMissing (override val channelId: ByteVector32, serialId: UInt64) extends ChannelException(channelId, s"previous tx missing from tx_add_input (serial_id=${serialId.toByteVector.toHex})")
+case class InvalidPreviousTxOut (override val channelId: ByteVector32, serialId: UInt64, previousTxId: TxId, previousTxOutput: Long) extends ChannelException(channelId, s"previous txOut doesn't match input $previousTxId:$previousTxOutput (serial_id=${serialId.toByteVector.toHex})")
case class InvalidSharedInput (override val channelId: ByteVector32, serialId: UInt64) extends ChannelException(channelId, s"invalid shared tx_add_input (serial_id=${serialId.toByteVector.toHex})")
case class OutputBelowDust (override val channelId: ByteVector32, serialId: UInt64, amount: Satoshi, dustLimit: Satoshi) extends ChannelException(channelId, s"invalid output amount=$amount below dust=$dustLimit (serial_id=${serialId.toByteVector.toHex})")
case class InvalidSharedOutputAmount (override val channelId: ByteVector32, serialId: UInt64, amount: Satoshi, expected: Satoshi) extends ChannelException(channelId, s"invalid shared output amount=$amount expected=$expected (serial_id=${serialId.toByteVector.toHex})")
### eclair-core/src/main/scala/fr/acinq/eclair/channel/fund/InteractiveTxBuilder.scala
@@ -490,6 +490,8 @@ private class InteractiveTxBuilder(replyTo: ActorRef[InteractiveTxBuilder.Respon
private val localFundingKey: PrivateKey = channelKeys.fundingKey(purpose.fundingTxIndex)
private val fundingPubkeyScript: ByteVector = Transactions.makeFundingScript(localFundingKey.publicKey, fundingParams.remoteFundingPubKey, fundingParams.commitmentFormat).pubkeyScript
private val remoteNodeId = channelParams.remoteParams.nodeId
+ // Remote inputs for which our peer only sent the previous txOut: we must check them before signing (see checkPreviousTxOuts).
+ private var remoteInputsWithoutPreviousTx = Set.empty[UInt64]
private val previousTransactions: Seq[InteractiveTxBuilder.SignedSharedTransaction] = purpose match {
case rbf: FundingTxRbf => rbf.previousTransactions
case rbf: SpliceTxRbf => rbf.previousTransactions
@@ -668,12 +670,16 @@ private class InteractiveTxBuilder(replyTo: ActorRef[InteractiveTxBuilder.Respon
replyTo ! RemoteFailure(f)
unlockAndStop(session)
case Right(input) =>
- val next = session.copy(
+ input match {
+ case _: Input.Remote if addInput.previousTx_opt.isEmpty => remoteInputsWithoutPreviousTx += input.serialId
+ case _ => ()
+ }
+ val session1 = session.copy(
remoteInputs = session.remoteInputs :+ input,
inputsReceivedCount = session.inputsReceivedCount + 1,
txCompleteReceived = None,
)
- send(next)
+ send(session1)
}
case addOutput: TxAddOutput =>
receiveOutput(session, addOutput) match {
@@ -691,6 +697,7 @@ private class InteractiveTxBuilder(replyTo: ActorRef[InteractiveTxBuilder.Respon
case removeInput: TxRemoveInput =>
session.remoteInputs.find(_.serialId == removeInput.serialId) match {
case Some(_) =>
+ remoteInputsWithoutPreviousTx -= removeInput.serialId
val next = session.copy(
remoteInputs = session.remoteInputs.filterNot(_.serialId == removeInput.serialId),
txCompleteReceived = None,
@@ -731,6 +738,8 @@ private class InteractiveTxBuilder(replyTo: ActorRef[InteractiveTxBuilder.Respon
val remoteOnlyInputs = session.remoteInputs.collect { case i: Input.Remote => i }
// Similarly, we ignore the shared output, which has been validated separately.
val remoteOnlyOutputs = session.remoteOutputs.collect { case o: Output.Remote => o }
+ val remoteInputsToCheck = remoteOnlyInputs.filter(i => remoteInputsWithoutPreviousTx.contains(i.serialId))
+ val previousTxOutValidation: () => Future[Unit] = () => checkPreviousTxOuts(remoteInputsToCheck)
val confirmationValidation: () => Future[Unit] = if (fundingParams.requireConfirmedInputs.forRemote) {
() => checkInputsConfirmed(remoteOnlyInputs, minConfirmations = 1, maxConfirmations_opt = None)
} else {
@@ -740,8 +749,8 @@ private class InteractiveTxBuilder(replyTo: ActorRef[InteractiveTxBuilder.Respon
case p: ValidateInteractiveTxPlugin => () => p.validateSharedTx(remoteNodeId, remoteOnlyInputs.map(i => i.outPoint -> i.txOut).toMap, remoteOnlyOutputs.map(o => TxOut(o.amount, o.pubkeyScript)))
}
// We run all checks, stopping at the first failing one. Note that plugin validation is only called if the previous
- // checks completed without errors.
- context.pipeToSelf((confirmationValidation +: pluginValidation).foldLeft(Future.successful(())) {
+ // checks completed without errors. The previous txOut validation comes first, since other checks use those txOuts.
+ context.pipeToSelf((previousTxOutValidation +: confirmationValidation +: pluginValidation).foldLeft(Future.successful(())) {
case (current, nextCheck) => current.flatMap(_ => nextCheck()) // NB: sequential execution
}) {
case Success(_) => ValidateSharedTx
@@ -769,6 +778,23 @@ private class InteractiveTxBuilder(replyTo: ActorRef[InteractiveTxBuilder.Respon
}
}
+ /**
+ * When splicing taproot channels, our peer may only send the txOut of their inputs instead of the previous transaction.
+ * Nothing guarantees that this txOut matches the actual output: our peer could lie about its amount or script. Since
+ * taproot signatures commit to every spent output, we would then sign a transaction that can never confirm, while our
+ * peer keeps our signature for the previous commitment. We thus check those txOuts against our bitcoin node, which
+ * finds both confirmed and mempool transactions (even if their outputs are spent by a previous attempt we're replacing
+ * with RBF). Our peer must send the previous transaction instead if it is unknown to our bitcoin node.
+ */
+ private def checkPreviousTxOuts(inputs: Seq[Input.Remote]): Future[Unit] = {
+ inputs.foldLeft(Future.successful(())) {
+ case (current, input) => current.flatMap(_ => wallet.getTransaction(input.outPoint.txid).map(_.txOut.lift(input.outPoint.index.toInt)).recover { case _ => None }.flatMap {
+ case Some(txOut) if txOut == input.txOut => Future.successful(())
+ case _ => Future.failed(InvalidPreviousTxOut(fundingParams.channelId, input.serialId, input.outPoint.txid, input.outPoint.index))
+ })
+ }
+ }
+
private def checkInputsConfirmed(inputs: Seq[Input.Remote], minConfirmations: Int, maxConfirmations_opt: Option[Int]): Future[Unit] = {
// We check inputs sequentially and stop at the first unconfirmed one.
inputs.map(_.outPoint).toSet.foldLeft(Future.successful(true)) {
### eclair-core/src/test/scala/fr/acinq/eclair/channel/InteractiveTxBuilderSpec.scala
@@ -2214,6 +2214,86 @@ class InteractiveTxBuilderSpec extends TestKitBaseClass with AnyFunSuiteLike wit
}
}
+ test("reject previous txOut that doesn't match the blockchain") {
+ val targetFeerate = FeeratePerKw(2_500 sat)
+ val fundingA1 = 100_000 sat
+ val utxosA = Seq(340_000 sat, 40_000 sat, 35_000 sat)
+ val fundingB1 = 80_000 sat
+ val utxosB = Seq(290_000 sat, 20_000 sat, 15_000 sat)
+ withFixture(ChannelTypes.SimpleTaprootChannel(), fundingA1, utxosA, fundingB1, utxosB, targetFeerate, 660 sat, 0, RequireConfirmedInputs(forLocal = false, forRemote = false)) { f =>
+ import f._
+
+ val probe = TestProbe()
+ alice ! Start(alice2bob.ref)
+ bob ! Start(bob2alice.ref)
+
+ // Alice --- tx_add_input --> Bob
+ fwd.forwardAlice2Bob[TxAddInput]
+ // Alice <-- tx_add_input --- Bob
+ fwd.forwardBob2Alice[TxAddInput]
+ // Alice --- tx_add_output --> Bob
+ fwd.forwardAlice2Bob[TxAddOutput]
+ // Alice <-- tx_add_output --- Bob
+ fwd.forwardBob2Alice[TxAddOutput]
+ // Alice --- tx_add_output --> Bob
+ fwd.forwardAlice2Bob[TxAddOutput]
+ // Alice <-- tx_complete --- Bob
+ fwd.forwardBob2Alice[TxComplete]
+ // Alice --- tx_complete --> Bob
+ fwd.forwardAlice2Bob[TxComplete]
+
+ val successA1 = alice2bob.expectMsgType[Succeeded]
+ val successB1 = bob2alice.expectMsgType[Succeeded]
+ val (txA1, commitmentA1, _, commitmentB1) = fixtureParams.exchangeSigsBobFirst(bobParams, successA1, successB1)
+ walletA.publishTransaction(txA1.signedTx).pipeTo(probe.ref)
+ probe.expectMsg(txA1.txId)
+
+ // Alice splices some funds in, which requires using an additional input.
+ val (sharedInputA, sharedInputB) = fixtureParams.sharedInputs(commitmentA1, commitmentB1)
+ val spliceFixtureParams = fixtureParams.createSpliceFixtureParams(fundingTxIndex = 1, fundingAmountA = 25_000 sat, fundingAmountB = 0 sat, aliceParams.targetFeerate, aliceParams.dustLimit, aliceParams.lockTime, sharedInputA = sharedInputA, sharedInputB = sharedInputB, requireConfirmedInputs = aliceParams.requireConfirmedInputs)
+ val aliceSplice = fixtureParams.spawnTxBuilderSpliceAlice(spliceFixtureParams.fundingParamsA, commitmentA1, walletA)
+ val bobSplice = fixtureParams.spawnTxBuilderSpliceBob(spliceFixtureParams.fundingParamsB, commitmentB1, walletB)
+ val fwdSplice = TypeCheckedForwarder(aliceSplice, bobSplice, alice2bob, bob2alice)
+
+ aliceSplice ! Start(alice2bob.ref)
+ bobSplice ! Start(bob2alice.ref)
+
+ // Alice only sends the txOut of her wallet input and lies about its amount. Since taproot signatures commit to the
+ // amounts of all spent outputs, the splice transaction would be invalid and could never confirm.
+ def replacePrevTxWithInvalidPrevTxOut(input: TxAddInput): TxAddInput = input.previousTx_opt match {
+ case None => input
+ case Some(tx) =>
+ val txOut = tx.txOut(input.previousTxOutput.toInt)
+ input.copy(previousTx_opt = None, tlvStream = TlvStream(TxAddInputTlv.PrevTxOut(tx.txid, txOut.amount + 10_000.sat, txOut.publicKeyScript)))
+ }
+
+ // Alice --- tx_add_input --> Bob
+ val input1 = alice2bob.expectMsgType[SendMessage].msg.asInstanceOf[TxAddInput]
+ bobSplice ! ReceiveMessage(replacePrevTxWithInvalidPrevTxOut(input1))
+ // Alice <-- tx_complete --- Bob
+ fwdSplice.forwardBob2Alice[TxComplete]
+ // Alice --- tx_add_input --> Bob
+ val input2 = alice2bob.expectMsgType[SendMessage].msg.asInstanceOf[TxAddInput]
+ bobSplice ! ReceiveMessage(replacePrevTxWithInvalidPrevTxOut(input2))
+ // Alice <-- tx_complete --- Bob
+ fwdSplice.forwardBob2Alice[TxComplete]
+ // Alice --- tx_add_output --> Bob
+ fwdSplice.forwardAlice2Bob[TxAddOutput]
+ // Alice <-- tx_complete --- Bob
+ fwdSplice.forwardBob2Alice[TxComplete]
+ // Alice --- tx_add_output --> Bob
+ fwdSplice.forwardAlice2Bob[TxAddOutput]
+ // Alice <-- tx_complete --- Bob
+ fwdSplice.forwardBob2Alice[TxComplete]
+ // Alice --- tx_complete --> Bob
+ fwdSplice.forwardAlice2Bob[TxComplete]
+
+ // Bob checks the txOut against his bitcoin node and aborts before signing.
+ val walletInput = Seq(input1, input2).find(_.previousTx_opt.nonEmpty).get
+ assert(bob2alice.expectMsgType[RemoteFailure].cause == InvalidPreviousTxOut(spliceFixtureParams.fundingParamsA.channelId,walletInput.serialId, walletInput.previousTx_opt.get.txid, walletInput.previousTxOutput))
+ }
+ }
+
test("not enough funds for rbf attempt") {
val targetFeerate = FeeratePerKw(10_000 sat)
val fundingA = 80_000 satWhy this scored 82/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.