Bounty
XE-0078 · Bounty

[SECURITY][Minor] SDK - rentLease skips its cancel on a non-retryable wait error

Accepted claimed Minor xe#103 filed 2026-10-27 17:59 UTC by targammm

Report

[SECURITY] rentLease skips its cancel on a non-retryable wait error

Field Value
Severity Minor
Area SDK — compute leasing
Component src/xe.ts (rentLease)
Status Reproduced (control-flow)
Date 2026-10-27

1. Summary

rentLease opens a lease (escrowing XUSD), waits for the provider to accept it, and on failure cancels the lease to refund the escrow. The cancel path is only reached when the wait error is retryable. For any other error the function re-throws immediately, before cancelLease runs:

// src/xe.ts:322–331
try {
  const lease = await this.waitForLease(opened.hash, ['accepted'], { timeoutMs: … })
  return { lease, opened, attempts: attempt }
} catch (err) {
  lastError = err
  if (!(err instanceof XeApiError && err.retryable)) throw err   // ← leaves without cancelling
}
try {
  await this.cancelLease(opened.hash)                              // ← refund path, skipped
  await this.waitForLease(opened.hash, ['cancelled'], { timeoutMs: 30_000 })
} catch (err) { … }

Two distinct error shapes reach that guard:

  • A terminal-state XeUsageError — waitForLease throws this when the lease reaches settled, cancelled, unfulfilled or expired (src/xe.ts:410).
  • A non-retryable XeApiError — e.g. a 400 from client.lease() while the lease is still created.

In the first case the escrow has already been resolved by the ledger (see §4), so the missing cancel costs nothing. In the second case the lease is still created and the escrow genuinely stays locked — but it is recoverable by a manual cancelLease.

2. Affected code

File Line Issue
src/xe.ts 329–331 Non-retryable error re-thrown before cancelLease — escrow not refunded
src/xe.ts 333–339 The only cancel path; unreachable when the throw above fires
src/xe.ts 394–418 waitForLease throws XeUsageError on a terminal state (settled|cancelled|unfulfilled|expired)
src/xe.ts 493–508 cancelLease requires state created; only refunds an unaccepted lease

3. Reproduction

Deterministic control-flow reproduction — models the exact branch structure of rentLease with a waitForLease that throws a terminal-state error.

// rentlease-flow.mjs
const calls = []
const openLease    = async () => { calls.push('openLease');    return { hash: 'h' } }
const waitForLease = async () => { calls.push('waitForLease'); throw new Error('lease ended unfulfilled') }
const cancelLease  = async () => { calls.push('cancelLease') }
const isRetryable  = () => false

try {
  for (let attempt = 1; attempt <= 3; attempt++) {
    const opened = await openLease()
    try {
      await waitForLease()
    } catch (err) {
      if (!(err instanceof Error && isRetryable())) throw err   // mirrors src/xe.ts:331
    }
    await cancelLease()
  }
} catch { /* rentLease throws here */ }

console.log('calls:', calls.join(' -> '))

Observed:

calls: openLease -> waitForLease
        (cancelLease is never reached — escrow not refunded)

4. Impact

The impact depends entirely on which error shape fires, and the two are very different. This distinction was checked against the ledger and store code rather than assumed:

Case 1 — terminal-state XeUsageError: no escrow impact

Terminal state How it is reached Escrow at that moment
settled Provider settled the lease Already credited back to the consumer by the settle block
cancelled Someone cancelled it Already refunded by the cancel block
unfulfilled Only reachable after a successful lease_force_settle — ledger.go:1983 sets UnfulfillLeaseHash, and the store requires state == LeaseAccepted first (mem_store.go:413) Already returned by that force-settle
expired node.archiveExpiredLease() Already burned by the node — and that burn happens on the expiry timer regardless of this SDK defect

So in Case 1 the missing cancelLease call is a no-op: there is nothing left to refund, and nothing the SDK could have recovered.

Case 2 — non-retryable XeApiError while the lease is still created: escrow locked, recoverable

  • Escrow stays locked. The lease remains in created with its XUSD escrow, and rentLease throws without attempting a cancel.
  • Recoverable. The consumer can call cancelLease(hash) directly afterwards — the lease is still created, which is exactly the state cancelLease requires (src/xe.ts:493–508). The funds are not lost.
  • Cost is delay and manual work, not value: the escrow is out of the consumer's spendable balance until they notice and cancel, and if they never do, the lease eventually expires and the node burns it — the same outcome as any abandoned lease, not one caused by this bug.
  • Requires a specific server response. The node must return a non-retryable error (e.g. 400) during the acceptance poll. A 503 or a retryable error takes the cancel path correctly, and a 404 is retried until timeout, which then throws a retryable 503 and also cancels correctly.

Honest boundary: no funds are permanently lost as a result of this defect. In the terminal-state case the ledger has already resolved the escrow before the SDK sees the error; in the non-retryable case the escrow is recoverable by a manual cancelLease. The defect is a missing cleanup on an error path — a robustness and accounting-hygiene issue that leaves a consumer's escrow locked longer than intended. That places it at Minor, not Medium.

5. Suggested fix

  1. Cancel before re-throwing: run the cancelLease block for every wait failure, not only retryable ones, then re-throw the original error if the cancel also fails.
  2. Use a try/finally that guarantees a cancel attempt whenever a lease was opened but not accepted before the function returns or throws.
  3. Treat unfulfilled/expired as an explicit done()-style outcome rather than an exception, so the caller receives a typed result and the escrow state, not a bare throw.

6. Duplicate check

  • xeprotocol/xe issue tracker scanned (98 items, open + closed + PRs) on 2026-10-27.
  • No issue or PR references rentLease, rent_lease, or an escrow-lock on a non-retryable wait error. All 17 PRs touch Go node/core/net/statechain or DAO Python.
  • Related but distinct ledger-side issues exist (#92 cancel refunds only base cost, #21 escrow without service, #38/#39 lease_cancel unwinding) — all node-side, none about the SDK rentLease control flow.

7. Submission checklist (per programme "How to Report")

Step Requirement Status
1 Reproduce against testnet; capture tx hashes / block heights Reproduced locally by control-flow modelling of src/xe.ts:322-339. Not yet exercised against test.network — triggering it live needs the node to return a non-retryable error mid-poll, which is not reproducible on demand. The branch structure is confirmed by direct source reading.
2 GitHub issue with suggested severity tier and area Tier: Minor · Area: SDK — compute leasing (cancellation)
3 Clear PoC + impact analysis (who is affected, worst case) Included — sections 3 and 4
4 Critical/Severe goes to security@xe.network first Not applicable — Minor is below Severe, so a public issue is the correct channel
5 Triage by the core team Awaiting
6 XE address for payout at genesis d31bab17b9fd6635aa6cce191b4bea87e51d8ae8c93860537febe4294b01d05a — XE native chain (block lattice, ed25519), BIP39 24-word + SLIP-0010 ed25519 m/44'/1'/account'; backup phrase in xe-payout-wallet.secret (0600)

Suggested tier: Minor (650 XE) — missing cleanup on an error path; escrow recoverable, no permanent loss

Thread

arturbarszcz782026-10-28 06:22 UTCgithub

[comment from a blocked account removed]

XE deskteam2026-11-10 00:15 UTCgithub

Read and accepted. It is tracked internally and the fix will land in a public PR; this issue is updated when it does, and the tier and award follow the fix. The desk entry is https://bounty.xe.network/XE-0078.