Merge pull request #741 from Foundation-Devices/sft-737-multisig-match-n
What changed, and why it matters
This firmware update fixes a bug in how the Passport hardware wallet matches multisignature (multisig) wallets. Previously, when looking for a saved wallet that matches the cosigners in a transaction, the device only checked that the cosigners overlapped. This meant a smaller wallet (for example, one needing 2 signatures out of 2 people) could be mistaken for a larger wallet (for example, 2 signatures out of 3 people) if the larger wallet contained the same people. The fix now also checks that the total number of cosigners (N) matches, so a smaller wallet is correctly treated as a separate wallet. The commit adds a test showing that a 2-of-2 wallet is no longer confused with a 2-of-3 wallet that shares two cosigners.
Review the change for completeness: ensure that all call sites of iter_wallets() and find_candidates() respect the new N parameter, and that user-facing import/registration flows also enforce N matching. Consider whether M-mismatch handling in has_similar() needs analogous tightening. Apply the firmware update to devices once validated.
Security signals we found
Incorrect multisig wallet matching could lead to signing with the wrong wallet policy
Subset-only cosigner matching allowed a smaller wallet to be conflated with a larger one
Fix adds N filter to wallet candidate enumeration
New regression test demonstrates the previously incorrect behavior
Evidence from the diff
In MultisigWallet.find_candidates(), the iteration over saved wallets now passes N=len(xfp_paths) to iter_wallets() in addition to the existing M and addr_fmt filters. The candidate search therefore requires the saved wallet’s total cosigner count to equal the PSBT’s named cosigner count, not merely a subset match. A new unit test (multisig_candidates.py) verifies that a 2-of-2 wallet over cosigners {A,B} is not treated as a duplicate of a saved 2-of-3 wallet {A,B,C}, and that find_candidates() returns the exact wallet whose cosigner set matches the PSBT.
Changed components
ports/stm32/boards/Passport/modules/multisig_wallet.pyports/stm32/boards/Passport/modules/tests/test_unit.pyports/stm32/boards/Passport/modules/tests/unit/multisig_candidates.pyInspect captured patch +59 / −2
### ports/stm32/boards/Passport/modules/multisig_wallet.py
@@ -263,11 +263,12 @@ def find_candidates(cls, xfp_paths, addr_fmt=None, M=None):
# - xpfs_paths hsould already be sorted
# - returns set of matches, of any M value
- # we know N, but not M at this point.
+ # we know N, but not M at this point. A wallet with a different N
+ # only shares some cosigners, so it is a different wallet.
N = len(xfp_paths)
matches = []
- for rv in cls.iter_wallets(M=M, addr_fmt=addr_fmt):
+ for rv in cls.iter_wallets(M=M, N=N, addr_fmt=addr_fmt):
if rv.matching_subpaths(xfp_paths):
matches.append(rv)
### ports/stm32/boards/Passport/modules/tests/test_unit.py
@@ -84,6 +84,10 @@ def test_multisig_save_task(test):
assert test('multisig_save_task.py') == b'OK'
+def test_multisig_candidates(test):
+ assert test('multisig_candidates.py') == b'OK'
+
+
def test_ui(test):
assert test('ui.py') == b'OK'
### ports/stm32/boards/Passport/modules/tests/unit/multisig_candidates.py
@@ -0,0 +1,52 @@
+# SPDX-FileCopyrightText: © 2026 Foundation Devices, Inc. <hello@foundation.xyz>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# A multisig wallet only matches a saved one with the same cosigner set:
+# sharing some cosigners with a larger wallet makes it a different wallet.
+
+import common
+
+from multisig_wallet import MultisigWallet
+from public_constants import AF_P2WSH
+
+DERIVATION = "m/48'/0'/0'/2'"
+A, B, C = 0x11111111, 0x22222222, 0x33333333
+
+
+def wallet(name, m, xfps):
+ keys = [(xfp, DERIVATION, 'xpub-{:08x}'.format(xfp)) for xfp in xfps]
+ return MultisigWallet(name, (m, len(xfps)), keys, 1, addr_fmt=AF_P2WSH, deriv=DERIVATION)
+
+
+class MockSettings:
+ def __init__(self, wallets):
+ self.records = [w.serialize() for w in wallets]
+
+ def get(self, key, default=None):
+ return self.records if key == 'multisig' else default
+
+
+original_settings = common.settings
+try:
+ common.settings = MockSettings([wallet('Vault', 2, [A, B, C])])
+
+ # A 2-of-2 over two of the vault's cosigners is a new wallet, not a
+ # duplicate of the vault.
+ assert wallet('Pair', 2, [A, B]).has_similar() == (None, [], 0)
+
+ # The same cosigner set is still recognized, as before.
+ assert wallet('Vault', 2, [A, B, C]).has_similar() == (None, [], 1)
+ _, diffs, count = wallet('Vault', 3, [A, B, C]).has_similar()
+ assert 'M differs' in diffs and count == 1
+
+ # Signing picks the wallet whose cosigner set the PSBT names, not a
+ # larger wallet that merely contains those cosigners.
+ common.settings = MockSettings([wallet('Vault', 2, [A, B, C]), wallet('Pair', 2, [A, B])])
+ pair_paths = wallet('Pair', 2, [A, B]).get_xfp_paths()
+ assert [w.name for w in MultisigWallet.find_candidates(pair_paths)] == ['Pair']
+ vault_paths = wallet('Vault', 2, [A, B, C]).get_xfp_paths()
+ assert [w.name for w in MultisigWallet.find_candidates(vault_paths)] == ['Vault']
+finally:
+ common.settings = original_settings
+
+return_value.write(b'OK')Why this scored 59/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.