AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 62 Bitcoin

Merge bitcoin/bitcoin#36338: BIP-352: fix P2PKH pubkey extraction from malleated scriptSig

Public commit record

What the developer wrote

Authored by merge-script

100/100 · Strong
Merge bitcoin/bitcoin#36338: BIP-352: fix P2PKH pubkey extraction from malleated scriptSig

cdfaa534d006f0effeb0ece3fb9aa5e53177a3fd BIP-352: fix P2PKH pubkey extraction from malleated scriptSig (Sebastian Falbesoner)
c35b99251450c9c8edd36b3e2a7594aa57a7f426 test: characterize buggy BIP-352 P2PKH extraction on malleated scriptSig (Sebastian Falbesoner)

Pull request description:

This PR fixes a Silent Payments pubkey extraction issue for P2PKH inputs: a third party can malleate the `scriptSig` such that it contains an OP_CHECKSIG that fails in real validation but succeeds with the dummy signature checker currently used (which accepts any non-empty signature). E.g. for a P2PKH spend with scriptSig

`<sig> <pubkey> <bogus_sig> OP_OVER OP_CHECKSIG OP_IF <wrong_pubkey> OP_ENDIF`

the `EvalScript` call would currently result in `wrong_pubkey` as the top stack item instead of `pubkey` and thus lead to an incorrect extraction (see the test added in the first commit). Fix this by parsing the scriptSig manually via a `.GetOp(...)` iteration, looking at all 33-byte data pushes to find the one where the Hash160 (SHA-256 + RIPEMD-160) matches the one in the output script.

Note that an alternative fix would be to keep using `EvalScript` but use an actual signature checker instead of the dummy one, but for that we need more transaction data in order to enable sighash calculation. Also involving a full script interpreter run including signature checks merely for extracting a public key seems overblown.

This issue was reported by [Project Loupe](https://github.com/project-loupe/) earlier this week (thanks!). From what I saw, none of the existing Silent Payments implementations are affected. I'm planning to add the test case to the BIP-352 test vectors in the BIPs repository as well, next to the existing ones that cover P2PKH malleation.

ACKs for top commit:
achow101:
ACK cdfaa534d006f0effeb0ece3fb9aa5e53177a3fd
fametrano:
tACK cdfaa534d006f0effeb0ece3fb9aa5e53177a3fd
Yudis-bit:
Tested ACK cdfaa534d006f0effeb0ece3fb9aa5e53177a3fd
sedited:
ACK cdfaa534d006f0effeb0ece3fb9aa5e53177a3fd

Tree-SHA512: 45a8027d854e8f63d696aca4a885d94308082e134261d6a0d1dfc470838cfdf89d000a71d1d28599766654caeada700855346f5708ad81dfea50d71c4cda8b16
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This update fixes a bug in how Bitcoin Core extracts public keys from certain old-style (P2PKH) transaction inputs when calculating Silent Payments. A troublemaker could tweak the input's script so that, during normal Bitcoin validation, the real public key is used, but the previous extraction method would pick a fake public key instead. That could cause a Silent Payments receiver to compute the wrong payment address and miss a payment. The fix manually scans the input for the public key whose fingerprint matches the output, instead of running the script with a dummy signature checker.

Recommended action

Apply the patch. Ensure downstream Silent Payments implementations that extract P2PKH pubkeys do not rely on EvalScript with a dummy checker; they should parse scriptSig directly and match the pubkey hash as specified by BIP-352.

Security signals we found

01

Silent Payments public-key extraction bug

02

P2PKH scriptSig third-party malleability

03

Dummy signature checker bypass

04

Wrong pubkey could be extracted from malleated input

05

Hash160-based pubkey matching fix

Risk score

Why this scored 62/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 10/15
Affected reach 8/15
Confidence 9/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.