What changed, and why it matters
This commit fixes a crash bug in Eclair, a Bitcoin Lightning Network node implementation. When processing certain encrypted payment messages (onion packets) that travel through unusually long routes—especially those using 'blinded paths'—the software could throw an IndexOutOfBoundsException and fail to handle the message. The fix makes the code safely ignore attribution data in those cases instead of crashing. Attribution data is best-effort diagnostic information, not payment-critical data, so ignoring it does not risk funds.
Upgrade to the release containing this commit. Nodes should not accept or process untrusted attribution data from peers without the bounds/Try hardening. Operators running versions prior to this fix should monitor logs for crashes during onion packet processing and apply the patch promptly, as the crash is remotely triggerable via long routes/blinded paths.
Security signals we found
Denial-of-service vector: unhandled IndexOutOfBoundsException during onion packet processing on long/blinded routes
Input from untrusted peers (attribution data) was not fully sanitized before array indexing
Fix converts all attribution-decryption failures into safe None results, consistent with best-effort reporting semantics
No evidence of funds loss or cryptographic key compromise in the diff
Evidence from the diff
Sphinx.Attribution.decrypt in eclair-core previously called computeHmacs with remainingHops, which could exceed maxNumHops (20). On long routes, especially those involving blinded paths with many blinded hops, this caused computeHmacs to throw an IndexOutOfBoundsException. The patch bounds remainingHops to 1..maxNumHops, returning None for out-of-range cases, and wraps the rest of the decryption in Try so any unexpected error is treated as invalid attribution data rather than propagating. Tests were added for routes longer than 20 hops and for malformed attribution payloads.
Changed components
eclair-core/src/main/scala/fr/acinq/eclair/crypto/Sphinx.scalaSphinx.Attribution.decryptSuccessPacket.decryptFailurePacket.decryptInspect captured patch +47 / −15
### eclair-core/src/main/scala/fr/acinq/eclair/crypto/Sphinx.scala
@@ -535,22 +535,33 @@ object Sphinx extends Logging {
* @param remainingHops number of remaining downstream nodes.
*/
def decrypt(attribution: ByteVector, payload_opt: Option[ByteVector], sharedSecret: SharedSecret, remainingHops: Int): Option[PerHopAttribution] = {
- val decrypted = wrap(attribution.take(totalLength), sharedSecret.secret)
- val holdTime = (uint32.decode(decrypted.take(holdTimeLength).bits).require.value * 100).milliseconds
- val holdTimes = decrypted.take(maxNumHops * holdTimeLength)
- val hmacs = getHmacs(decrypted)
- val macKey = generateKey("um", sharedSecret.secret)
- val expectedHmacs = computeHmacs(Hmac256(macKey), payload_opt.getOrElse(ByteVector.empty), holdTimes, hmacs.drop(1), remainingHops)
- if (expectedHmacs == hmacs.head.drop(maxNumHops - remainingHops)) {
- // The attribution data from this node is valid: we shift it to access attribution data from the downstream nodes.
- val downstreamHoldTimes = decrypted.slice(holdTimeLength, maxNumHops * holdTimeLength) ++ zeroes(holdTimeLength)
- val downstreamHmacs = ByteVector.concat((hmacs.drop(1) :+ Seq()).map(s => zeroes(hmacLength) ++ ByteVector.concat(s)))
- Some(PerHopAttribution(HoldTime(holdTime, sharedSecret.remoteNodeId), downstreamHoldTimes ++ downstreamHmacs))
- } else {
- // The attribution data from this node is invalid or missing. This doesn't necessarily mean that this node was
- // malicious: they could be inside a blinded path, in which case they don't return any attribution data, which
- // is fine (we only care about attribution outside the blinded path).
+ if (remainingHops <= 0 || remainingHops > maxNumHops) {
+ // Attribution data only supports routes of at most maxNumHops nodes: routes can be longer than that (for
+ // example when using blinded paths), in which case we cannot extract attribution data for the nodes that are
+ // too far away from the end of the route.
None
+ } else {
+ // Attribution data comes from untrusted nodes and is only used for best-effort reporting (e.g. hold times): we
+ // never want to throw while processing it, so any unexpected error is treated like invalid attribution data.
+ Try {
+ val decrypted = wrap(attribution.take(totalLength), sharedSecret.secret)
+ val holdTime = (uint32.decode(decrypted.take(holdTimeLength).bits).require.value * 100).milliseconds
+ val holdTimes = decrypted.take(maxNumHops * holdTimeLength)
+ val hmacs = getHmacs(decrypted)
+ val macKey = generateKey("um", sharedSecret.secret)
+ val expectedHmacs = computeHmacs(Hmac256(macKey), payload_opt.getOrElse(ByteVector.empty), holdTimes, hmacs.drop(1), remainingHops)
+ if (expectedHmacs == hmacs.head.drop(maxNumHops - remainingHops)) {
+ // The attribution data from this node is valid: we shift it to access attribution data from the downstream nodes.
+ val downstreamHoldTimes = decrypted.slice(holdTimeLength, maxNumHops * holdTimeLength) ++ zeroes(holdTimeLength)
+ val downstreamHmacs = ByteVector.concat((hmacs.drop(1) :+ Seq()).map(s => zeroes(hmacLength) ++ ByteVector.concat(s)))
+ Some(PerHopAttribution(HoldTime(holdTime, sharedSecret.remoteNodeId), downstreamHoldTimes ++ downstreamHmacs))
+ } else {
+ // The attribution data from this node is invalid or missing. This doesn't necessarily mean that this node was
+ // malicious: they could be inside a blinded path, in which case they don't return any attribution data, which
+ // is fine (we only care about attribution outside the blinded path).
+ None
+ }
+ }.toOption.flatten
}
}
}
### eclair-core/src/test/scala/fr/acinq/eclair/crypto/SphinxSpec.scala
@@ -512,6 +512,27 @@ class SphinxSpec extends AnyFunSuite {
}
}
+ test("ignore attribution data for routes that are too long") {
+ // Attribution data supports routes of at most 20 nodes, but routes may be longer (e.g. when using blinded paths).
+ val sharedSecrets = (0 until 21).map(_ => SharedSecret(ByteVector32(randomBytes(32)), randomKey().publicKey)).toList
+ val attribution = randomBytes(Attribution.totalLength)
+ val success = SuccessPacket.decrypt(Some(randomBytes(100)), Some(attribution), sharedSecrets)
+ assert(success.holdTimes.isEmpty)
+ val failure = FailurePacket.decrypt(randomBytes(292), Some(attribution), sharedSecrets)
+ assert(failure.holdTimes.isEmpty)
+ assert(failure.failure.isLeft)
+ }
+
+ test("ignore malformed attribution data") {
+ val sharedSecrets = (0 until 3).map(_ => SharedSecret(ByteVector32(randomBytes(32)), randomKey().publicKey)).toList
+ // Our peers cannot send attribution data with an invalid length, but we never want to throw if that happens.
+ Seq(ByteVector.empty, hex"0102").foreach { attribution =>
+ assert(Attribution.decrypt(attribution, None, sharedSecrets.head, sharedSecrets.length).isEmpty)
+ assert(SuccessPacket.decrypt(None, Some(attribution), sharedSecrets).holdTimes.isEmpty)
+ assert(FailurePacket.decrypt(randomBytes(292), Some(attribution), sharedSecrets).holdTimes.isEmpty)
+ }
+ }
+
test("failing node tries to hide its identity") {
for ((payloads, packetPayloadLength) <- Seq((referencePaymentPayloads, 1300), (paymentPayloadsFull, 1300))) {
// origin build the onion packetWhy this scored 47/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.