{"id":"XE-0003","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"10","source_url":"https://github.com/xeprotocol/xe/issues/10","reporter_id":658,"title":"Audit: Lease Stake Oversubscription Race, sys.timekeepers Key Hex/Deduplication Bypass, Memo Unicode C1/Bidi Injection, and Lease Cancel Uint64 Overflow","area":"leasing-ledger","claimed_tier":"high","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":true,"internal_ref":"","internal_url":null,"status":"accepted","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T13:57:13.403507+00:00","updated_at":"2026-11-10T11:38:25.793077+00:00","source_created_at":"2026-10-18T12:18:30+00:00","told_at":"2026-11-10T00:15:57+00:00","status_changed_at":"2026-10-29T14:04:13.915573+00:00","url":"https://bounty.xe.network/XE-0003","body":"### Security Audit Report: XE Protocol (Track 1 Bug Bounty)\n\nThis audit report identifies 4 high/medium severity vulnerabilities across consensus, ledger state transitions, statechain DAO configuration validation, and node lease orchestration, accompanied by unit tests with 100% pass rates.\n\n---\n\n### Finding 1: Provider Lease Accept & Marketplace Stake Oversubscription Race Condition\n- **Severity**: High\n- **Components**: \\\node/node.go\\ (\\handleMarketplace\\, \\\u0007utoAcceptLease\\)\n- **Vulnerability**:\n  When a node acts as a compute provider, leases require committing XUSD stake (\\core.LeaseStake(amount)\\). While resource metrics (VCPUs, Memory, Disk) are tracked in \\\reservedRes\\ during the async VM provisioning window, in-flight XUSD stake commitments are not tracked.\n  1. Concurrently incoming lease requests check \\\n.Ledger.GetAssetBalances(myAddr)[\"XUSD\"]\\ before provisioning. Because the on-chain \\BlockLeaseAccept\\ block is only minted *after* VM provisioning completes, concurrent lease acceptance routines believe the entire unreserved balance is available.\n  2. Both VMs are provisioned, but the second routine acquires \\\blockCreateMu\\, discovers \\stake > xusdBal\\, and aborts with \\\"XUSD balance changed during provisioning (...) tearing down\"\\.\n  3. Consequently, the consumer's on-chain lease is left unfulfilled, causing the provider to suffer reputation penalties (\\EventLeaseUnfulfilled\\) and wasting node compute.\n  4. Similarly, \\handleMarketplace\\ publishes signed \\ResourceOffer\\ messages against current unreserved balance without factoring in in-flight lease acceptances.\n- **Resolution**:\n  Added \\\reservedStake uint64\\ protected by \\\reservedResMu\\ to track active in-flight stake commitments. In \\\u0007utoAcceptLease\\, stake is reserved prior to VM provisioning and atomically released via \\defer\\. In \\handleMarketplace\\, offer evaluation subtracts \\\reservedStake\\ from available XUSD.\n\n---\n\n### Finding 2: Incomplete \\sys.timekeepers\\ Key Validation (Missing Hex Decoding & Duplicate Key Permissibility)\n- **Severity**: High\n- **Components**: \\statechain/kvstore.go\\ (\\\u000balidateSysKeyValue\\)\n- **Vulnerability**:\n  Unlike \\sys.dao_keyset\\, \\sys.minter\\, and \\sys.oracle\\ which strictly decode keys with \\hex.DecodeString(k)\\ and enforce uniqueness (\\seen[k]\\), \\sys.timekeepers\\ only validated key length (\\len(k) != 64\\).\n  1. A malicious or misconfigured DAO transaction can set invalid non-hex characters or duplicate timekeeper public keys.\n  2. If duplicate keys are accepted (e.g. \\[K, K]\\ with \\\threshold: 2\\), a single compromised timekeeper key satisfies the multi-party quorum, bypassing threshold assumptions.\n  3. Non-hex characters pass KV validation but later fail and abort subsequent timekeeper attestation verification routines (\\core.ValidateAttestations\\).\n- **Resolution**:\n  Enforced \\hex.DecodeString(k)\\ and duplicate key rejection (\\seen[k]\\) in \\statechain/kvstore.go\\ for \\sys.timekeepers\\, matching the invariants of \\sys.dao_keyset\\ and \\sys.minter\\.\n\n---\n\n### Finding 3: Missing Uint64 Arithmetic Overflow Check in \\\u000balidateAndAddLeaseCancel\\\n- **Severity**: High\n- **Components**: \\core/ledger.go\\ (\\\u000balidateAndAddLeaseCancel\\)\n- **Vulnerability**:\n  In \\\u000balidateAndAddLeaseCancel\\, the expected refund balance calculation:\n  \\\\\\go\n  oldBal := l.getAssetBalanceOverlay(b.Account, \"XUSD\")\n  expectedBal := oldBal + leaseBlock.Amount\n  \\\\\\\n  omitted the uint64 overflow check present in \\\u000balidateAndAddReceive\\ and \\\u000balidateAndAddLeaseForceSettle\\. If \\oldBal + leaseBlock.Amount\\ overflows \\math.MaxUint64\\, \\expectedBal\\ silently wraps around. An attacker or edge case could submit or validate invalid balance assertions resulting in balance truncation or state corruption.\n- **Resolution**:\n  Added explicit overflow check:\n  \\\\\\go\n  if expectedBal < oldBal {\n      return fmt.Errorf(\"lease_cancel would overflow uint64 balance\")\n  }\n  \\\\\\\n\n---\n\n### Finding 4: Unicode C1 Control Character & Bidirectional / Invisible Format Spoofing Injection in \\ValidateMemo\\\n- **Severity**: Medium\n- **Components**: \\core/memo.go\\ (\\ValidateMemo\\)\n- **Vulnerability**:\n  \\ValidateMemo\\ checked ASCII control bytes using \\c < 0x20 || c == 0x7F\\ by indexing raw bytes. In UTF-8, non-ASCII codepoints are encoded as multi-byte sequences where every byte has the high bit set (\\>= 0x80\\).\n  1. C1 control codes (\\U+0080\\ to \\U+009F\\, including CSI \\U+009B\\ and OSC \\U+009D\\) completely bypassed the check. These codes are utilized in ANSI escape sequences for terminal command execution and log injection.\n  2. Unicode Bidirectional Overrides (\\U+202E\\ RLO) and zero-width/formatting characters (\\U+200B\\, \\U+2066..U+2069\\, \\U+FEFF\\) bypassed the validation, enabling visual address/memo spoofing on block explorers, wallets, and CLI interfaces.\n- **Resolution**:\n  Iterate over decoded runes in \\ValidateMemo\\ and enforce rejection via \\unicode.IsControl(r)\\ (covering C0, DEL, and C1 control blocks) and \\unicode.Is(unicode.Cf, r)\\ (covering bidirectional overrides and formatting code points).\n\n---\n\n### Verification & Unit Tests\nComprehensive unit tests covering all 4 vulnerabilities were created and verified:\n- \\core/memo_test.go\\: 18 test cases validating ASCII, C0, C1 (NEL, CSI, OSC), Bidi (RLO, LRI), zero-width spaces, and BOM rejections.\n- \\core/ledger_test.go\\: Verification of overflow rejection on \\\u000balidateAndAddLeaseCancel\\ as well as valid cancellation handling.\n- \\statechain/kvstore_test.go\\: Validation of \\sys.timekeepers\\ hex validity, duplicate key detection, threshold boundaries, and key lengths.\n- \\\node/node_test.go\\: Concurrency test proving that \\\reservedStake\\ prevents oversubscription across parallel lease accepts.\n\nAll packages compile and pass tests cleanly (\\go test ./...\\ -> 0 failures).\n\nA companion Pull Request with the fixes and tests has been submitted.","patch_refs":[{"id":112,"repo":"xeprotocol/xe","kind":"pr","ref":"11","title":"fix(core,node,statechain): harden lease stake reservation, sys.timekeepers hex/uniqueness validation, memo unicode controls, and lease cancel overflow","url":"https://github.com/xeprotocol/xe/pull/11","note":"","state":"open","author":"ocakciomursel-pixel","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"}],"thread":[{"id":1585,"source":"github","source_ref":"6755097130","author":"XE desk","team":true,"body":"Read and accepted. It is tracked internally and the fix will land in a public PR; this issue is\nupdated when it does, and the tier and award follow the fix. The desk entry is https://bounty.xe.network/XE-0003.","created_at":"2026-11-10T00:15:57+00:00"}]}