Skip to content

external_signer: add interactive Taproot anti-exfil signing - #129

Open
Sjors wants to merge 13 commits into
masterfrom
2026/10/taproot-anti-exfil
Open

Sjors wants to merge 13 commits into
masterfrom
2026/10/taproot-anti-exfil

Conversation

@Sjors

@Sjors Sjors commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Add opt-in -signerantiexfil protection to external-signer wallets. Core generates an independent random scalar for each target input, sends its commitment to the signer, records the returned full nonce point, and reveals the scalar in a second signtx call. It accepts a signature only after independently verifying BIP340 validity and the prescribed nonce relation.

A valid transaction signature can still encode a secret through a maliciously selected nonce. Transaction integrity checks and mempool admission do not address that channel. This implements the single-signer additive protocol from the companion BIP draft, without changing transaction consensus rules or the on-chain format.

Stack and dependencies

This is stacked on the external-signer hardening work associated with bitcoin/bitcoin PR 36114, through iwyu: Fix warnings in src/external_signer.cpp and treat them as errors. When restacking, preserve the hardening dependency and replay only these five increments:

Commit subject Increment
pubkey: verify interactive Schnorr anti-exfil proofs Host commitment and independent signature/nonce-relation verification helpers.
external_signer: require interactive Taproot anti-exfil signing Core-generated entropy, two-round coordination, transcript validation, and functional coverage. Includes the direct headers required by IWYU.
external_signer: retain unfinalized anti-exfil signatures across wallet passes Treat an already signed, unfinalized PSBT as a successful no-op.
external_signer: keep anti-exfil transcripts out of error diagnostics Reduce untrusted subprocess/JSON/parser errors to fixed diagnostics during managed sessions.
external_signer: reject caller transcripts before ordinary signing Reject caller-supplied ae fields in global, input, and output maps regardless of the protection setting.
Companion PR Relationship
BIP draft Transcript, PSBT fields, domains, and independent vectors; specification dependency.
HWI Runtime bridge for physical devices and emulators. Core's functional mock tests do not require HWI. Its description links the firmware dependencies.
libsecp256k1 Companion signing API, not a compile dependency. This PR does not modify the vendored subtree; Core's host verifier uses existing public curve and Schnorr APIs.

Behavior and review details

Only unsigned single-signer Taproot key-path targets with DEFAULT or ALL are supported. Each target has its own entropy and nonce. Core freezes the complete unsigned transaction, including sequences, and the UTXOs and transcript. A PSBTv2 unique identifier alone is insufficient because it excludes sequences.

Raw responses are checked before PSBT merging can preserve Core's conflicting values or fill omissions. Early signatures, missing or changed fields, unexpected fields, finalized inputs, untargeted signatures, changed transactions or UTXOs, and invalid proofs fail. Core copies only verified signatures back into the caller's PSBT; nonce transcripts and other device-supplied metadata are discarded.

A fully signed but unfinalized PSBT succeeds on later wallet passes without starting a new session. Caller-provided ae fields are rejected because Core manages its own sessions and must not downgrade an explicit request through ordinary signing. Managed-session subprocess, JSON, and PSBT-parser errors cannot expose raw transcripts through RPC errors or routine debug logs.

There is no automatic retry with fresh entropy. Failures after a commitment explain the selective-abort concern, including subprocess/JSON failures. Interrupted transcripts are not persisted across RPC calls or restart; automatic resumption would require retaining and reusing the exact tuple. A new user-initiated signing attempt is not a transparent protocol retry.

The experimental ae fields work with PSBTv0 and PSBTv2. BIP-EXFIL/host and BIP-EXFIL/nonce remain placeholders; BIP assignment requires coordinated domain changes and regenerated vectors. MuSig2/FROST, script-path signing, ECDSA, and general sign-to-contract are outside this PR.

Validation

  • key_tests and psbt_tests: all 17 relevant cases passed.
  • wallet_signer_anti_exfil.py: DEFAULT/ALL, PSBTv0/v2, two inputs, transaction preservation, transcript removal, fourteen dishonest/malformed/process-failure cases, eight transcript-error channels, twelve caller-field downgrade cases, unfinalized/repeated signing, and final broadcast/confirmation passed.
  • Existing wallet_signer.py and rpc_signer.py passed.
  • The preset build and full containerized Core lint passed. The IWYU include correction was also checked at its introducing commit and final tip with LLVM 23, the CI mappings/check settings, and fix_includes.py --nosafe_headers --dry_run; no edits remained. The corrected stack passed the preset rebuild, unit suites, include lint, and all three external-signer functional tests.
  • Actual Core C++ host → HWI subprocess → modified Ledger emulator signing passed, including wallet processing, mempool acceptance, broadcast, and confirmation.

These are local validation results. GitHub CI for the corrected pushed branch is still in progress; earlier Docker-layer download failures occurred before compilation.

Sjors and others added 11 commits September 28, 2026 08:40
The external signer mock previously replayed a PSBT that the test
prepared in advance. This makes it difficult to test more complicated
scenarios like a misbehaving wallet and (MuSig2) multisig.

Instead, give the mock its own descriptor wallet. The test provides a
dedicated node for this wallet and keeps it offline, so the mock can't
cheat by e.g. inspecting the UTXO set. The mock creates the wallet on
first use and signs with walletprocesspsbt.

wallet_signer.py now funds all four descriptor types and spends them
in a single transaction, exercising every signing code path.
Co-authored-by: brunoerg <brunoely.gc@gmail.com>
Reject a signer response with a different PSBT version and report the expected and returned versions. Document the requirement and test a v0 response to a v2 request.
A signature with SIGHASH_NONE or SIGHASH_SINGLE doesn't commit to all
outputs, letting anyone alter them after signing. Reject a PSBT from
an external signer that declares such a sighash type or contains
signatures made with one.

SIGHASH_ANYONECANPAY is still accepted: it only permits adding inputs,
which does not affect us.

The mock signer produces real signatures for these scenarios by
letting its wallet sign with the requested sighash type, optionally
hiding the declared sighash type field so that only the signatures
themselves reveal it.

Co-authored-by: brunoerg <brunoely.gc@gmail.com>
Previously the PSBT returned by the external signer replaced the
original wholesale, trusting the signer not to modify the transaction.
Merge it instead. This rejects a response that describes a different
transaction.

Merging also supports signers that strip fields they don't need from
their response. New tests cover both scenarios.

Also test a signer that changes a PSBT v2 input sequence before signing.
The transaction identifier used for merging ignores sequences, but the
merge preserves the original sequence, leaving the signatures invalid
for the wallet's transaction. This and a corrupted signature must leave
the original transaction unchanged and return an incomplete PSBT. Test
ECDSA and Schnorr signatures independently.

Suggested in: bitcoin#36114 (comment)

Co-authored-by: brunoerg <brunoely.gc@gmail.com>
Require signer responses to keep signatures in non-final fields and leave finalization to Bitcoin Core. Document the requirement in the signer API.

Test final scriptSig and witness fields independently, including responses that finalize only one input.
Sjors added 2 commits October 25, 2026 07:00
Add opt-in -signerantiexfil protection with Core-generated randomness, two
signtx calls and provisional BIP-EXFIL PSBT fields. Validate immutable
requests and raw transcripts before merging, and accept only independently
verified key-path signatures. Never retry a failed exchange automatically
with fresh entropy.

Cover DEFAULT and ALL in PSBT v0/v2, two inputs, transcript removal,
transaction preservation and fourteen malformed or dishonest signer cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant