Skip to content

fix: enforce legacy multisig public key limit - #166

Open
Harshil-1603 wants to merge 2 commits into
diybitcoinhardware:masterfrom
Harshil-1603:fix/checkmultisig-pubkey-limit
Open

Harshil-1603 wants to merge 2 commits into
diybitcoinhardware:masterfrom
Harshil-1603:fix/checkmultisig-pubkey-limit

Conversation

@Harshil-1603

Copy link
Copy Markdown

Legacy multi and sortedmulti currently pass verification with more than 20 public keys, producing scripts that Bitcoin's CHECKMULTISIG cannot execute. Reject these oversized legacy fragments during verification, including when they are parsed through a descriptor. Keep Taproot multi_a and sortedmulti_a independent of this legacy limit.

Fixes #139.

Validation:

  • Both new legacy-limit regression cases fail before the fix and pass afterward.
  • Boundary controls accept 20-key legacy fragments and 21-key Taproot fragments.
  • Full suite: 125 passed, 17 skipped; the skipped tests require optional native bindings.
  • Wheel/sdist build and repository artifact verification passed.
  • git diff --check passed. Whole-file Black checks report pre-existing spacing differences outside the changed code; those unrelated lines are preserved.

Implemented and tested with Codex assistance.

@fametrano fametrano left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 1bdd763

I ran 30 descriptors through getdescriptorinfo on Core v31.1.0 and through Descriptor.from_string on master and on this branch. Happy to share the script. With 21 keys, multi and sortedmulti are rejected under wsh(), sh(wsh()) and sh(), and multi nested in or_d(), as in Core. Master accepts all of these. Twenty keys still pass, and so do multi_a and sortedmulti_a with 21.

Two gaps remain. Core rejects sh(multi(...)) and sh(sortedmulti(...)) once the redeem script exceeds 520 bytes, which is 16 or more compressed keys. embit still accepts both with 16 to 20 keys, and that output cannot be spent. #168 closes it. Core also rejects sortedmulti nested in miniscript, as in wsh(or_d(sortedmulti(...),pk(...))), which embit accepts. #170 closes that.

@odudex

odudex commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Code looks good at 1bdd763: 21 keys are rejected for multi and sortedmulti under wsh(), sh(), sh(wsh()) and nested in or_d(), 20 still pass, and multi_a/sortedmulti_a are unaffected.

One thing to fix before merging: the new tests won't run under MicroPython. test_descriptor.py is imported by tests/tests/__init__.py, so it is part of micropython ./run_tests.py, and:

  • self.subTest is not defined in tests/unittest.py (the MicroPython shim), so both tests raise AttributeError there.
  • .sec().hex() and .xonly().hex(): the tests in the MicroPython list use hexlify rather than .hex(), which is not available on older MicroPython builds. hexlify(...).decode() is the safe form, and hexlify is already imported in this file.

CI only runs pytest, so this doesn't show up there. A plain for loop instead of subTest is enough.

Use plain loops instead of unsupported subTest contexts, preserving all
assertions. Use hexlify for older MicroPython builds where applicable.

Assisted-by: OpenAI Codex

This branch has not been deployed

No deployments
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.

Bare Miniscript multi(...) accepts more than 20 pubkeys and compiles anyway

3 participants