<!-- XE-13366 · Laporan bug · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13366>. The page is the record; this is the same page for reading.*

XE-13366 · Bounty

# Laporan bug

Closed · duplicate
—
[xe#509](https://github.com/xeprotocol/xe/issues/509)
filed 2026-11-12 16:21 UTC
by Gib230223

Verdict
:   Duplicate

Tier
:   —

Claimed
:   —

Area
:   Node / API

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-20 00:38 UTC

Told
:   2026-11-20 00:34 UTC

### Patches

- [xe#514](https://github.com/xeprotocol/xe/pull/514) open by arturbarszcz78
  fix(node): return created block hash from CreateLeaseBlock and RequestAndCreateLease (fixes #509)

### History

- [554012](https://bounty.xe.network/log/554012) 2026-11-20 00:34 UTC reply.mirrored
- [553997](https://bounty.xe.network/log/553997) 2026-11-20 00:34 UTC github.state\_pushed
- [553996](https://bounty.xe.network/log/553996) 2026-11-20 00:34 UTC github.labels
- [552444](https://bounty.xe.network/log/552444) 2026-11-20 00:33 UTC proposal.adopted
- [552443](https://bounty.xe.network/log/552443) 2026-11-20 00:33 UTC reply.sent
- [552442](https://bounty.xe.network/log/552442) 2026-11-20 00:33 UTC ticket.status new → closed
- [551831](https://bounty.xe.network/log/551831) 2026-11-20 00:33 UTC proposal.adopted
- [551830](https://bounty.xe.network/log/551830) 2026-11-20 00:33 UTC ticket.facts area
- [551829](https://bounty.xe.network/log/551829) 2026-11-20 00:33 UTC proposal.adopted
- [551828](https://bounty.xe.network/log/551828) 2026-11-20 00:33 UTC ticket.facts
- [551827](https://bounty.xe.network/log/551827) 2026-11-20 00:33 UTC proposal.adopted
- [551826](https://bounty.xe.network/log/551826) 2026-11-20 00:33 UTC ticket.facts

[Full history](https://bounty.xe.network/log?ref=XE-13366) · [JSON](https://bounty.xe.network/v1/tickets/XE-13366) · [markdown](https://bounty.xe.network/XE-13366.md)

### Report

# XE Bounty — Laporan siap file (temuan pass 5 #2)

File issue baru di: https://github.com/xeprotocol/xe/issues/new
Paste judul \+ isi di bawah. Akun GitHub: Gib230223.

---

## Judul

\[Low\] RequestAndCreateLease returns the chain tail as the lease hash, so a concurrent block makes POST /lease/request hand back the WRONG lease

## Isi

## Summary

`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.

`CreateLeaseBlock` itself computes the block hash internally and never returns it — the fix is to return it (or hold `blockCreateMu` across the read).

## Evidence

```
// node/vm.go:169-183 RequestAndCreateLease:
offer, err := n.RequestLease(...)            // marketplace round-trip
if err := n.CreateLeaseBlock(...); err != nil {   // holds blockCreateMu throughout
    return "", fmt.Errorf("create lease block: %w", err)
}
chain := n.Ledger.GetChain(n.KeyPair.Address())
if len(chain) == 0 { return "", fmt.Errorf("no blocks after lease creation") }
last := chain[len(chain)-1]
return last.Hash, nil                        // <-- assumes tail == the lease just created
```

```
// node/node.go:2086-2088 CreateLeaseBlock — the lock does NOT cover the tail read:
func (n *Node) CreateLeaseBlock(...) error {
    n.blockCreateMu.Lock()
    defer n.blockCreateMu.Unlock()
    // ... builds, signs, AddBlock, Publish — then returns, lock released
}
```

```
// api/vm.go:143-151 handleLeaseRequest — returns the hash verbatim:
leaseHash, err := h.node.RequestAndCreateLease(r.Context(), ...)
writeJSON(w, http.StatusCreated, map[string]string{
    "lease_hash": leaseHash,
})
```

Single-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.

## Impact (Low)

Wrong 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).

## Reproduction (PoC)

Real 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`.

Coordinator re-run (2026-11-12 \~23:12 WIB), 2/5 runs reproduce (subagent B's run: 3/5; combined 5/10):

```
run 4: 16 results, 14 distinct hashes, 17 lease blocks on chain
BUG 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
run 5: 16 results, 14 distinct hashes, 17 lease blocks on chain
BUG REPRODUCED (duplicate): callers 10 and 15 both returned 63be57ff4a695e096122fea1c074872620ba527de4274ea9ccb6fa33f998ebaf — but 17 distinct leases were created
```

The 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.

## Suggested fix

Return 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.

## Novelty note

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

Repo: github.com/xeprotocol/xe, HEAD 89a542e, testnet-0005.

### Thread

**Joseph Denne**team2026-11-20 00:34 UTCgithub

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the
first verifiable submission, so this one closes as a duplicate. If you believe it is a different
bug, file a new report that links https://bounty.xe.network/XE-13366 and says what differs; it is read like any other.
