{"id":"XE-13366","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"509","source_url":"https://github.com/xeprotocol/xe/issues/509","reporter_id":1981,"title":"Laporan bug","area":"node-api","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"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-11-14T20:42:12.183519+00:00","updated_at":"2026-11-20T00:38:15.062125+00:00","source_created_at":"2026-11-12T16:21:06+00:00","told_at":"2026-11-20T00:34:49+00:00","status_changed_at":"2026-11-20T00:33:18.674217+00:00","url":"https://bounty.xe.network/XE-13366","body":"# XE Bounty — Laporan siap file (temuan pass 5 #2)\n\nFile issue baru di: https://github.com/xeprotocol/xe/issues/new\nPaste judul + isi di bawah. Akun GitHub: Gib230223.\n\n---\n\n## Judul\n\n[Low] RequestAndCreateLease returns the chain tail as the lease hash, so a concurrent block makes POST /lease/request hand back the WRONG lease\n\n## Isi\n\n## Summary\n\n`Node.RequestAndCreateLease` creates the lease block under `blockCreateMu`, then reads the chain tail *after* the lock is released and returns it as the new lease's hash. Any other block created on the same account in between — a concurrent `RequestAndCreateLease`, a `Send`, a settle/accept block on a combined consumer+provider node — lands on top, and the caller is handed that block's hash as `lease_hash`. The API returns it verbatim. The operator then renews/queries the wrong lease: renew on a non-lease hash 400s, renew on *another lease's* hash acts on a lease the caller did not just create.\n\n`CreateLeaseBlock` itself computes the block hash internally and never returns it — the fix is to return it (or hold `blockCreateMu` across the read).\n\n## Evidence\n\n```go\n// node/vm.go:169-183 RequestAndCreateLease:\noffer, err := n.RequestLease(...)            // marketplace round-trip\nif err := n.CreateLeaseBlock(...); err != nil {   // holds blockCreateMu throughout\n    return \"\", fmt.Errorf(\"create lease block: %w\", err)\n}\nchain := n.Ledger.GetChain(n.KeyPair.Address())\nif len(chain) == 0 { return \"\", fmt.Errorf(\"no blocks after lease creation\") }\nlast := chain[len(chain)-1]\nreturn last.Hash, nil                        // <-- assumes tail == the lease just created\n```\n\n```go\n// node/node.go:2086-2088 CreateLeaseBlock — the lock does NOT cover the tail read:\nfunc (n *Node) CreateLeaseBlock(...) error {\n    n.blockCreateMu.Lock()\n    defer n.blockCreateMu.Unlock()\n    // ... builds, signs, AddBlock, Publish — then returns, lock released\n}\n```\n\n```go\n// api/vm.go:143-151 handleLeaseRequest — returns the hash verbatim:\nleaseHash, err := h.node.RequestAndCreateLease(r.Context(), ...)\nwriteJSON(w, http.StatusCreated, map[string]string{\n    \"lease_hash\": leaseHash,\n})\n```\n\nSingle-threaded use never triggers it (verified: the sequential control call always returns its own lease). The window is microseconds per call and needs a concurrent block on the same account — but the consequence is a wrong identity returned by a live operator endpoint, and the fix is one line.\n\n## Impact (Low)\n\nWrong lease identity from a live API endpoint. An operator (or automation) that renews, cancels, or tracks by the returned hash acts on the wrong lease — or fails confusingly on a non-lease hash. Severity is Low, not higher: narrow race window, requires concurrency on the same account, and the returned hash is always a real block on that account's chain (never a foreign account's data).\n\n## Reproduction (PoC)\n\nReal two-host libp2p mesh, live marketplace offer responder, 16 concurrent `RequestAndCreateLease` calls plus a background `Send` interleaver on the same account. A duplicate returned hash (two callers, one hash, while 17 distinct leases exist) proves the bug. Test: `node/poc5_tailhash_test.go`, `TestPoc5RequestLeaseTailHash`, `go test ./node/ -run TestPoc5RequestLeaseTailHash -v -count=5 -timeout 300s`.\n\nCoordinator re-run (2026-11-12 ~23:12 WIB), 2/5 runs reproduce (subagent B's run: 3/5; combined 5/10):\n\n```\nrun 4: 16 results, 14 distinct hashes, 17 lease blocks on chain\nBUG REPRODUCED (duplicate): callers 7 and 10 both returned 32e9342067b0849d833a611bbe3fba2d2b00840924566549a930197b5608751b — but 17 distinct leases were created; the tail read handed one caller another lease's hash\nrun 5: 16 results, 14 distinct hashes, 17 lease blocks on chain\nBUG REPRODUCED (duplicate): callers 10 and 15 both returned 63be57ff4a695e096122fea1c074872620ba527de4274ea9ccb6fa33f998ebaf — but 17 distinct leases were created\n```\n\nThe non-reproducing runs fail cleanly (race window did not fire, not a code error). All returned hashes in the reproducing runs were lease blocks — i.e. callers received *each other's* lease hashes, the exact failure mode.\n\n## Suggested fix\n\nReturn the created block's hash from `CreateLeaseBlock` (it already computes it) and have `RequestAndCreateLease` return that value instead of re-reading the chain tail. Alternatively, hold `blockCreateMu` across the tail read in `RequestAndCreateLease` — but returning the hash is the cleaner fix and removes the assumption entirely. Note `cmdLease` (`cmd/xe/main.go`) already uses `b.Hash` directly — it does not have this bug.\n\n## Novelty note\n\nNo ticket covers the tail-hash read. Closest, all verified: XE-3091 (SDK `holdLease` re-signs a duplicate paid renewal after an ambiguous submit failure — client-side SDK retry loop in another component, retrying after a *lost response*; this is the node returning a *wrong but confidently-presented* hash from its own read-after-unlock — different location, trigger, consequence, fix); XE-6576 (MaxConcurrent accept policy checked once against a stale count — capacity accounting, not hash identity); pass-4 #1 (publish-after-commit double-charge — `CreateLeaseBlock` returning a publish error after commit; this is `RequestAndCreateLease` misreading the chain tail — the two can compose but are different defects). GitHub closest: #276 (SDK `leaseCost` duration bounds — unrelated, matched on lease wording). Checked the live bounty board (High+Medium and Minor views) and the GitHub repo issues (live `search_issues`), 2026-11-12.\n\nRepo: github.com/xeprotocol/xe, HEAD 89a542e, testnet-0005.\n","patch_refs":[{"id":560,"repo":"xeprotocol/xe","kind":"pr","ref":"514","title":"fix(node): return created block hash from CreateLeaseBlock and RequestAndCreateLease (fixes #509)","url":"https://github.com/xeprotocol/xe/pull/514","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-11-14T20:42:20.129552+00:00"}],"thread":[{"id":13215,"source":"github","source_ref":"7026486369","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, 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-13366 and says what differs; it is read like any other.","created_at":"2026-11-20T00:34:49+00:00"}]}