What changed, and why it matters
This commit tightens a check in Electrum's submarine-swap code that pulls a secret 'preimage' from a Bitcoin transaction's witness data. Previously, the code only checked whether the witness existed; now it also requires at least two witness elements before reading the second one. This prevents an index-out-of-bounds read and makes the extraction more robust, especially for unsigned or unusually constructed transactions. It is a defensive hardening fix rather than a clear-cut exploitable vulnerability.
Treat as a low-to-moderate hardening patch. Review whether extract_preimage callers handle None/empty returns safely, and consider adding unit tests for malformed witness inputs. No immediate emergency response is indicated from the diff alone.
Security signals we found
Bounds-check hardening on witness parsing
Submarine-swap preimage extraction path
Potential IndexError on malformed/single-element witness
Defensive fix in on-chain Lightning/refund logic
Evidence from the diff
In electrum/submarine_swaps.py, extract_preimage() iterates over a claim transaction’s inputs and reads witness[1] as the payment preimage. The old guard ‘if not witness:’ was true only for an empty witness list, so a single-element witness would pass and then crash on witness[1]. The new guard ‘if not witness or len(witness) < 2:’ skips any input whose witness has fewer than two elements. This avoids an IndexError and may also avoid misinterpreting malformed or segwit-version-0 signatures as preimages.
Changed components
electrum/submarine_swaps.pySwapManager.extract_preimage()Inspect captured patch +1 / −1
diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py
index aa5399c..9a968da 100644
--- a/electrum/submarine_swaps.py
+++ b/electrum/submarine_swaps.py
@@ -384,7 +384,7 @@ class SwapManager(Logger):
def extract_preimage(cls, swap: SwapData, claim_tx: Transaction) -> Optional[bytes]:
for txin in claim_tx.inputs():
witness = txin.witness_elements()
- if not witness:
+ if not witness or len(witness) < 2:
# tx may be unsigned
continue
preimage = witness[1]
Why this scored 57/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.