{"id":"XE-0092","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"152","source_url":"https://github.com/xeprotocol/xe/issues/152","reporter_id":31,"title":"[Medium] VerifyMultisigAny ignores Keyset.Threshold - lease family authorised by 1-of-N (supporting #6/#93, PRs #7/#110 unmerged)","area":null,"claimed_tier":"medium","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0068","tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T13:57:25.934324+00:00","updated_at":"2026-11-10T00:11:29.183869+00:00","source_created_at":"2026-10-29T00:54:11+00:00","told_at":"2026-11-05T22:05:59+00:00","status_changed_at":"2026-11-05T22:05:50.539554+00:00","url":"https://bounty.xe.network/XE-0092","body":"## Summary\n\n`VerifyMultisigAny` (`core/multisig.go:114-138`) accepts **any single** valid signature from a keyset member and never compares against `Keyset.Threshold`. Because `IsSpendingOp` (`core/multisig.go:140-147`) omits `lease_accept`, `lease_settle`, `lease_cancel` and `lease_force_settle`, all four of those fund-moving operations take that weak path in `verifyBlockCredential` (`core/ledger.go:1436-1442`).\n\nNet effect on a 2-of-2 multisig account: **one** compromised signer can accept a lease, cancel a lease, or settle a lease unilaterally, while a plain `send` on the same account correctly demands both signatures.\n\n**Suggested severity:** Medium (2,500 XE) - validation gap. I am filing this as supporting evidence for the existing reports rather than as a new discovery; see \"Relationship to existing issues\" below.\n\n## Relationship to existing issues (please read before triaging)\n\nI want to be explicit that this is **not** a new finding:\n\n- **#93** already reports `lease_accept` bypassing the multisig threshold, and **#110** is an open PR fixing exactly that.\n- **#6** (section 1, item 2) already reports all four lease types missing from `IsSpendingOp`, and **#7** is an open PR claiming to fix them.\n\nWhat I am adding that is not in either report:\n\n1. **`VerifyMultisigAny` isolated as a defective primitive.** Neither #6 nor #93 tests the function directly. Both describe the symptom at the call site. The function itself is the defect: it returns `nil` on the first valid signature and never reads `ks.Threshold` (line 133-135). Any future block type that is not added to `IsSpendingOp` inherits the same 1-of-N bypass silently. A regression test pinned to the primitive would catch that class of mistake; a test pinned to `lease_accept` would not.\n2. **Proof that the pending PRs are not merged and the bug is still live.** Both #7 and #110 are `state: open` as of 2026-10-29. Master is still `9787859` (2026-10-15), and `git log -S 'BlockLeaseAccept' -- core/multisig.go` returns nothing. I verified this against a fresh `git clone --depth 1` of master, not just my local copy.\n3. **A differential test** showing `VerifyMultisig` and `VerifyMultisigAny` disagreeing on byte-identical input, which makes the intent gap unambiguous.\n\nIf the team considers this a duplicate of #93, that is a fair call and I would rather it be closed as such than padded. The `VerifyMultisigAny` primitive test is the part I would ask to be kept regardless.\n\n## Affected code\n\n`core/multisig.go:114-138`\n```go\nfunc VerifyMultisigAny(hash string, sigs []BlockSignature, ks *Keyset) error {\n\tif len(sigs) == 0 {\n\t\treturn fmt.Errorf(\"no signatures\")\n\t}\n\t...\n\tfor _, sig := range sigs {\n\t\tif !keysetMap[sig.PublicKey] {\n\t\t\tcontinue\n\t\t}\n\t\tif err := VerifyHexSignature(sig.PublicKey, sig.Sig, hashBytes); err == nil {\n\t\t\treturn nil          // <-- ks.Threshold is never consulted\n\t\t}\n\t}\n\treturn fmt.Errorf(\"no valid signature from any keyset member\")\n}\n```\n\n`core/multisig.go:140-147`\n```go\nfunc IsSpendingOp(t BlockType) bool {\n\tswitch t {\n\tcase BlockSend, BlockBurn, BlockLease, BlockLeaseRenew,\n\t     BlockMultisigOpen, BlockMultisigUpdate, BlockMint:\n\t\treturn true\n\tdefault:\n\t\treturn false           // <-- lease_accept/settle/cancel/force_settle land here\n\t}\n}\n```\n\n`core/ledger.go:1436-1442`\n```go\nif IsSpendingOp(b.Type) {\n\tif err := VerifyMultisig(b.Hash, b.Signatures, ks); err != nil {   // threshold enforced\n\t\treturn fmt.Errorf(\"multisig: %w\", err)\n\t}\n\treturn nil\n}\nif err := VerifyMultisigAny(b.Hash, b.Signatures, ks); err != nil {   // 1-of-N accepted\n\treturn fmt.Errorf(\"multisig: %w\", err)\n}\n```\n\n## Reproduction\n\nRepository: `github.com/xeprotocol/xe` @ master `9787859`.\nEnvironment: Go 1.24.3, Linux x86-64.\n\nThe signature material is real ed25519, generated with `openssl genpkey -algorithm ed25519` and signed over the 32-byte digest `f9c195734f05a628640961c117eb7b4aa616e95251080dcc8f9f5688a7842e4c`. No dummy hex, no mocked verifier.\n\nKeyset under test: 3-of-5, threshold 3.\n\n```\nkeys[0] = 334610fc39650a013e2ec6e767f018f45c38a21956b8bb94bbae8ae3e41859e4\nkeys[1] = 404f5bc1f208b4b80c931a6f32619d6ea6accc58372f2e419cec99ca2d520f4f\nkeys[2] = afe99c7ae6e8dc2d2d67ce289bbb46d46fd4908360a481cee613b8874144418e\nkeys[3] = 5a2c2a1cff8e0c2a168358ceef3fd53b4e22ecac274770ed8968d59b6d3dca3c\nkeys[4] = 58c0159266ff3697c8c646df7b806095a6d41fa208cc9c8c50316cbcacbb16aa\n```\n\nOne valid signature from `keys[0]`:\n```\nsig = 46ba415b70375f75d6734c579799a3b52953f4beee97801f8238a767b577ce05\n      da69ad83d3a2633a03813520276b2f617aa61b72ae365497cb83f188c0b3f508\n```\n\n### Observed\n\n```\nVerifyMultisigAny(1 valid sig, threshold=3) -> ACCEPTED\nVerifyMultisig(1 valid sig, threshold=3)    -> rejected: insufficient signatures: got 1, need 3\n  => the two paths disagree on identical input\n\nIsSpendingOp(lease_accept)      = false\nIsSpendingOp(lease_settle)      = false\nIsSpendingOp(lease_cancel)      = false\nIsSpendingOp(lease_force_settle)= false\nIsSpendingOp(receive)           = false\n```\n\n### End-to-end control through the real Ledger\n\nTo confirm the threshold is genuinely enforced elsewhere, the same test opens a real 2-of-2 multisig account (fresh keypair per run, so the address differs each time) and then submits a `send` signed by only one member:\n\n```\n2-of-2 multisig account opened: <fresh address per run>\ncontrol (send, 1-of-2 sig) -> REJECTED: multisig: insufficient signatures: got 1, need 2\n  => send correctly enforces the threshold\n```\n\nSo the ledger is capable of enforcing the threshold; the lease family simply never reaches that check.\n\n### Repetitions\n\nThree consecutive runs, all PASS, all producing identical output:\n\n| # | Condition | Result |\n|---|---|---|\n| 1 | local clone, `go test -count=1` | PASS |\n| 2 | after `go clean -testcache`, full rebuild | PASS |\n| 3 | fresh `git clone --depth 1` of master into a clean directory | PASS |\n\n### Test file\n\n```go\npackage core_test\n\nimport (\n\t\"testing\"\n\n\t\"github.com/xeprotocol/xe/core\"\n)\n\nfunc TestMedium_LeaseAcceptBypassesMultisigThreshold(t *testing.T) {\n\tks := &core.Keyset{Keys: []string{\n\t\t\"334610fc39650a013e2ec6e767f018f45c38a21956b8bb94bbae8ae3e41859e4\",\n\t\t\"404f5bc1f208b4b80c931a6f32619d6ea6accc58372f2e419cec99ca2d520f4f\",\n\t\t\"afe99c7ae6e8dc2d2d67ce289bbb46d46fd4908360a481cee613b8874144418e\",\n\t\t\"5a2c2a1cff8e0c2a168358ceef3fd53b4e22ecac274770ed8968d59b6d3dca3c\",\n\t\t\"58c0159266ff3697c8c646df7b806095a6d41fa208cc9c8c50316cbcacbb16aa\",\n\t}, Threshold: 3}\n\n\thash := \"f9c195734f05a628640961c117eb7b4aa616e95251080dcc8f9f5688a7842e4c\"\n\tone := []core.BlockSignature{{\n\t\tPublicKey: \"334610fc39650a013e2ec6e767f018f45c38a21956b8bb94bbae8ae3e41859e4\",\n\t\tSig: \"46ba415b70375f75d6734c579799a3b52953f4beee97801f8238a767b577ce05da69ad83d3a2633a03813520276b2f617aa61b72ae365497cb83f188c0b3f508\",\n\t}}\n\n\tif err := core.VerifyMultisigAny(hash, one, ks); err != nil {\n\t\tt.Errorf(\"VerifyMultisigAny rejected a valid single signature: %v\", err)\n\t} else {\n\t\tt.Log(\"VerifyMultisigAny(1 valid sig, threshold=3) -> ACCEPTED\")\n\t}\n\n\tif err := core.VerifyMultisig(hash, one, ks); err != nil {\n\t\tt.Logf(\"VerifyMultisig(1 valid sig, threshold=3) -> rejected: %v\", err)\n\t}\n\n\tfor _, bt := range []core.BlockType{\n\t\tcore.BlockLeaseSettle, core.BlockLeaseForceSettle,\n\t\tcore.BlockLeaseCancel, core.BlockLeaseAccept, core.BlockReceive,\n\t} {\n\t\tt.Logf(\"IsSpendingOp(%s) = %v\", bt, core.IsSpendingOp(bt))\n\t}\n}\n```\n\n## Impact\n\n- **`lease_accept`** - debits the provider's balance by `LeaseStake(cost)` and legally binds the provider's machine. One signer can commit the account.\n- **`lease_cancel`** - refunds escrow to the consumer. One signer can unwind an active lease.\n- **`lease_settle` / `lease_force_settle`** - move emission to the provider. These additionally require timekeeper attestations, so the practical exposure is lower than for accept/cancel; I am flagging them for completeness, not claiming they are equally exploitable.\n- **`receive`** - `updateDelegation` (`core/ledger.go:2614-2622`) applies `newBlock.Representative` for every block, and `validateAndAddReceive` never inspects that field. Combined with the 1-of-N path this is the consensus-weight hijack described in #6 section 1 item 1. Also still unpatched.\n\n## Recommendation\n\n1. Add `BlockLeaseAccept`, `BlockLeaseCancel`, `BlockLeaseForceSettle`, `BlockLeaseSettle` and `BlockReceive` to `IsSpendingOp`, as #7 and #110 already propose.\n2. Independently, make `VerifyMultisigAny` safe by construction: either enforce `len(valid) >= ks.Threshold` inside it, or delete it and have `verifyBlockCredential` call `VerifyMultisig` unconditionally. Leaving a threshold-ignoring verifier in the package is what allowed this to recur across four block types.\n3. Add the primitive-level regression test above, so the next block type added to the enum fails CI rather than shipping.\n\n## Note on a withdrawn finding\n\nWhile investigating I briefly concluded that `multisig_open` was unreachable because `DeriveMultisigAddress` (`sha256(threshold‖count‖keys)`) can never equal `DeriveAddress` (`sha256(\"xe/account/v1\"‖pubkey)`), which `ValidatePubKeyDeclaration` demands for open blocks. **That conclusion was wrong and I am withdrawing it.** `ValidatePubKeyDeclaration` returns `nil` immediately when `len(b.Signatures) > 0` (`core/crypto.go:120-125`), before the pub_key branch is ever reached, and `verifyBlockCredential` then validates the signatures against `b.MSKeyset`. I verified with the real `Ledger` that a 2-of-3 `multisig_open` with genuine threshold signatures is admitted and the keyset installed, and that a forged signature is rejected with `multisig: sig from ...: signature verification failed`. No report was filed for it. I mention it only so the team knows it was checked and is not an issue.\n\n## Payout\n\nXE address to be provided on request. I am not claiming a bounty for the duplicate portion; if the team awards anything, the `VerifyMultisigAny` primitive analysis and the unmerged-PR verification are the parts I consider mine.\n","patch_refs":[],"thread":[{"id":353,"source":"github","source_ref":"6670767309","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0068, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, reply with what differs and we will look again.","created_at":"2026-11-05T22:05:59+00:00"}]}