From c8f436b5987b66552cb940dd1ec58aa7891eed52 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Sun, 25 Oct 2026 05:43:49 +0000 Subject: [PATCH 1/2] crypto: use libngu with interactive Schnorr anti-exfil Build on experimental libngu commit 933adde, based on upstream master ff4db2c. The fork URL is needed until that dependency lands upstream. --- .gitmodules | 2 +- external/libngu | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 29a70517f..43d445385 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,7 +10,7 @@ url = https://github.com/coinkite/mpy-qr.git [submodule "external/libngu"] path = external/libngu - url = https://github.com/switck/libngu.git + url = https://github.com/Sjors/libngu.git [submodule "stm32/mk4-bootloader/hal"] path = stm32/mk4-bootloader/hal url = https://github.com/STMicroelectronics/STM32CubeL4.git diff --git a/external/libngu b/external/libngu index ff4db2c3b..933adde10 160000 --- a/external/libngu +++ b/external/libngu @@ -1 +1 @@ -Subproject commit ff4db2c3b6d3f02eb31ff2b020a4c1502a76d70b +Subproject commit 933adde10243cdeede753e446f532cff35e8f647 From fe253f04e82543685077e25f8b4a298aa5d71746 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Sun, 25 Oct 2026 05:46:22 +0000 Subject: [PATCH 2/2] psbt: implement interactive anti-exfil for BIP86 inputs # Conflicts: # shared/psbt.py --- docs/anti-exfil.md | 50 +++++++++++++++++++++++ shared/anti_exfil.py | 40 +++++++++++++++++++ shared/manifest.py | 1 + shared/psbt.py | 59 +++++++++++++++++++++++++--- testing/devtest/anti_exfil_fields.py | 45 +++++++++++++++++++++ 5 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 docs/anti-exfil.md create mode 100644 shared/anti_exfil.py create mode 100644 testing/devtest/anti_exfil_fields.py diff --git a/docs/anti-exfil.md b/docs/anti-exfil.md new file mode 100644 index 000000000..d46d8ef5f --- /dev/null +++ b/docs/anti-exfil.md @@ -0,0 +1,50 @@ +# Experimental interactive Taproot anti-exfil + +This branch implements the draft BIP-EXFIL protocol for BIP86 key-path inputs. +It supports PSBT versions 0 and 2 and SIGHASH_DEFAULT or SIGHASH_ALL. It does +not implement this protocol for MuSig2, script paths, registered Miniscript +wallets, or Taproot outputs with a script-tree commitment. + +The host first adds a proprietary per-input key +`fc02616500 || output_key32` with a 32-byte host commitment. On approval, +the firmware adds `fc02616501 || output_key32` containing its full compressed +33-byte nonce point, and returns a PSBT without signatures. A retry of this +same request derives the same point, including its parity. + +The host records that point before revealing its 32-byte nonzero scalar in +`fc02616502 || output_key32`. In the second invocation the firmware rederives +and checks both previous fields, adds the host contribution to its nonce, +verifies the resulting BIP340 signature, and returns the normal Taproot key +signature. The current UI requests transaction approval in both invocations. +No secret nonce state needs to survive between invocations. + +The host must verify the original nonce relation and the signature before +using either. A bridge that only preserves unknown PSBT fields does not provide +this protection. Transcript fields remain in the response until the host +verifies it; the host must remove them before exporting the completed PSBT. +They must not be included in routine diagnostic logs. Automatic retries after +a nonce commitment must reuse the original transcript, rather than obtain new +host randomness. + +Protected requests reject incomplete or noncanonical fields, more than one +signing key per input, mixed rounds, fields outside input maps, existing target +signatures/finalization, other sighashes, and unsupported spending paths. Only +targeted inputs receive new signatures. Input ownership, change checking, +transaction approval, and normal Taproot key-tweak checks still apply. + +The native primitive comes from the linked experimental `Sjors/libngu` branch +`2026/10/taproot-anti-exfil`. Its nested libsecp256k1 version is unchanged. +`BIP-EXFIL/host` and `BIP-EXFIL/nonce` remain provisional domains; assigning a +BIP number requires coordinated vector regeneration and implementation changes. +This implementation has not received cryptographic review. + +Tests for a native simulator build: + +``` +unix/coldcard-mpy external/libngu/ngu/ngu_tests/test_anti_exfil.py +env MICROPYPATH=shared unix/coldcard-mpy testing/devtest/anti_exfil_fields.py +``` + +HWI's corresponding branch includes device tests for both rounds, reconnecting, +firmware rejection of a bad reveal or nonce, both PSBT versions and supported +sighashes, and finalization, mempool acceptance, broadcast and confirmation. diff --git a/shared/anti_exfil.py b/shared/anti_exfil.py new file mode 100644 index 000000000..c4c5afa39 --- /dev/null +++ b/shared/anti_exfil.py @@ -0,0 +1,40 @@ +# (c) Copyright 2026 by Sjors Provoost. This file is covered by license found in COPYING-CC. +# Experimental BIP-EXFIL proprietary PSBT input fields. + +from uio import BytesIO +from serializations import deser_compact_size + +PREFIX = b'\xfc\x02ae' + +def read_fields(proxy, allowed=True): + # Unknown PSBT fields are coordinates into the original uploaded PSBT. + # Return one signing key and its complete host request, without changing + # the original fields that must survive through host verification. + fields = {} + pubkey = None + finalized = False + for key_coord, value_coord in proxy.unknown or (): + key = proxy.get(key_coord) + if key[0] in (7, 8): + finalized = True + if key[0] != 0xfc: + continue + stream = BytesIO(key[1:]) + size = deser_compact_size(stream) + if stream.read(size) != b'ae': + continue + assert allowed, 'Anti-exfil fields outside input' + assert len(key) == 37 and key[:4] == PREFIX, 'Anti-exfil key encoding' + subtype = key[4] + assert subtype in (0, 1, 2), 'Anti-exfil subtype' + assert pubkey is None or pubkey == key[5:], 'Multiple anti-exfil keys' + assert subtype not in fields, 'Duplicate anti-exfil field' + value = proxy.get(value_coord) + assert len(value) == (33 if subtype == 1 else 32), 'Anti-exfil value length' + pubkey = key[5:] + fields[subtype] = value + if fields: + assert not finalized, 'Finalized anti-exfil target' + assert set(fields) in ({0}, {0, 1, 2}), 'Incomplete anti-exfil request' + return pubkey, fields + return None diff --git a/shared/manifest.py b/shared/manifest.py index 04c743421..1532f3bf9 100644 --- a/shared/manifest.py +++ b/shared/manifest.py @@ -43,6 +43,7 @@ 'pincodes.py', 'precomp_tag_hash.py', 'psbt.py', + 'anti_exfil.py', 'psram.py', 'pwsave.py', 'qrs.py', diff --git a/shared/psbt.py b/shared/psbt.py index 8a5cf644a..ad82efdd4 100644 --- a/shared/psbt.py +++ b/shared/psbt.py @@ -707,7 +707,8 @@ class psbtInputProxy(psbtProxy): 'taproot_merkle_root', 'taproot_script_sigs', 'taproot_scripts', 'taproot_subpaths', 'taproot_internal_key', 'taproot_key_sig', 'tr_added_sigs', 'ik_idx', 'musig_pubkeys', 'musig_pubnonces', 'musig_part_sigs', 'musig_agg_idx', - 'musig_added_pubnonces', 'musig_added_sigs', 'wif_key', 'wif_redeem_script' + 'musig_added_pubnonces', 'musig_added_sigs', 'wif_key', 'wif_redeem_script', + 'ae_request', 'ae_added_nonce' ) def __init__(self, fd, idx): @@ -1308,6 +1309,10 @@ def serialize(self, out_fd, is_v2): if self.taproot_key_sig: wr(PSBT_IN_TAP_KEY_SIG, self.taproot_key_sig) + if self.ae_added_nonce: + pubkey, nonce = self.ae_added_nonce + wr(PSBT_PROPRIETARY, nonce, b'\x02ae\x01' + pubkey) + if self.sighash is not None: wr(PSBT_IN_SIGHASH_TYPE, pack('