Bounty
XE-0077 · Bounty

[SECURITY][Medium] SDK - holdLease aborts the whole hold on a partial-minute renewal step

Accepted claimed Medium xe#102 filed 2026-10-27 17:59 UTC by targammm

Report

[SECURITY] holdLease aborts the whole hold with a non-whole-minute renewal step

Field Value
Severity Medium
Area SDK — compute leasing
Component src/hold.ts
Status Reproduced (unit, deterministic)
Date 2026-10-27

1. Summary

holdLease keeps an accepted lease alive by renewing it in fixed renewSecs segments until the lease's effective term reaches totalSecs. The size of the final segment is computed as min(renewSecs, totalSecs − effectiveDuration). When totalSecs is not an exact multiple of renewSecs, that final segment is a partial minute (e.g. 30 s).

renewLease requires a whole number of minutes and throws XeUsageError on a partial one. holdLease does not catch that error, so the entire hold aborts — the lease is left to run out at its current expiry and the machine is released early, even though the caller asked for a longer term and has budget for it.

Trigger: any totalSecs that is not a multiple of renewSecs. With the documented default renewSecs = 60, any totalSecs that is not a multiple of 60 (e.g. 90, 150, 210 seconds; or MINUTES = 2.5 in the tutorial) hits it.

2. Affected code

File Line Issue
src/hold.ts 86 const step = totalSecs === undefined ? renewSecs : minBig(renewSecs, totalSecs - lease.effectiveDuration) — may yield a partial minute
src/hold.ts 90 renewBeforeExpiry(…, step, …) → renewLease throws for a partial step; the catch at line 91 only maps XePriceError/XeBudgetError, so XeUsageError propagates
src/xe.ts 441 renewLease calls requireWholeMinutes(duration, 'renewLease') → throws
src/lease.ts 22–26 requireWholeMinutes rejects a duration that is not a multiple of 60

3. Reproduction

Deterministic — reproduces the step sequence without any network. Run with Node 20+.

// step-math.mjs
const minBig = (a, b) => (a < b ? a : b)
const renewSecs = 60n
for (const totalSecs of [60n, 90n, 120n, 150n, 180n, 210n]) {
  let eff = 0n, steps = [], guard = 0
  while (eff < totalSecs && guard++ < 20) {
    const step = minBig(renewSecs, totalSecs - eff)
    steps.push(step)
    if (step <= 0n) break
    if (step % 60n !== 0n) { steps.push('<<< NON-WHOLE'); break }
    eff += step
  }
  console.log(`totalSecs=${totalSecs}: [${steps.join(',')}]`)
}

Observed:

totalSecs=60:  [60]
totalSecs=90:  [60,30,<<< NON-WHOLE]
totalSecs=120: [60,60]
totalSecs=150: [60,60,30,<<< NON-WHOLE]
totalSecs=180: [60,60,60]
totalSecs=210: [60,60,60,30,<<< NON-WHOLE]

And the partial step is rejected by the renewal path:

// whole-minute.mjs
import { requireWholeMinutes } from './dist/lease.js'
for (const s of [60n, 30n]) {
  try { requireWholeMinutes(s, 'renewLease'); console.log(`step=${s}: OK`) }
  catch (e) { console.log(`step=${s}: THROW ${e.name}: ${e.message}`) }
}

Observed:

step=60: OK
step=30: THROW XeUsageError: renewLease: duration must be a whole number of minutes (a multiple of 60s), got 30s

In holdLease this XeUsageError is thrown out of the try at line 90, is not one of the two mapped error types, and propagates out of the function — the hold ends with an exception rather than a HoldReason.

4. Impact

  • Paid hold ends early. The caller asked to hold a machine for totalSecs; the hold stops at the last whole minute instead. The lease is not renewed further and runs out at its current expiry, so the rented machine is released early.
  • Workload interruption. Anything running on the leased VM (a job, a service) is cut off when the lease expires, mid-task, with no clean stop.
  • Escrow is not lost, but time is. The already-paid minutes are spent; the unreached term is simply never bought.
  • The failure is loud, not silent. holdLease throws XeUsageError out to the caller, so the defect is observable and diagnosable. The cost is the wasted minutes and the interrupted workload, not an undetected failure.
  • The documented tutorial is affected. examples/typescript/06-holding-a-lease-open.md exposes MINUTES to the reader; a non-integer-minute value aborts the hold the same way.

Honest boundary: no funds are stolen or minted, and no consensus rule is bypassed. The defect is a control-flow bug that ends a paid hold early and surfaces as a thrown XeUsageError. It is fully recoverable by re-running with a whole-minute target, and it requires the caller to pass a totalSecs that is not a multiple of renewSecs. This is a validation gap / incorrect-error-handling defect, not a targeted DoS or a sustained degradation an unprivileged client can cause — hence Medium, not High.

5. Why the test suite misses it

test/unit/lease.test.ts exercises holdLease against a mocked Xe whose renewLease does not call requireWholeMinutes, so a partial step is accepted in tests and never throws. The tests also use renewSecs: 1, where every step is whole only by the mock's leniency. A real Xe rejects the same input.

6. Suggested fix

  1. Clamp the final step to a whole minute: let step = minBig(renewSecs, totalSecs - lease.effectiveDuration); step -= step % 60n; and treat step === 0n as target-reached rather than calling renewLease.
  2. Or validate up front: reject a totalSecs that is not a whole number of minutes relative to renewSecs, with a clear message, before the first renewal.
  3. Map XeUsageError from the renewal path to a done('target-reached') result rather than letting it escape holdLease.
  4. Add a regression test that drives holdLease with a non-multiple totalSecs against a mock that enforces requireWholeMinutes.

7. Duplicate check

  • xeprotocol/xe issue tracker scanned (98 items, open + closed + PRs) on 2026-10-27.
  • No issue or PR references holdLease, hold_lease, renewSecs, or a whole-minute renewal step. All 17 PRs touch Go node/core/net/statechain or DAO Python — none touch the SDK hold.ts.
  • Related but distinct: #97 (lease_renew accepts any retained certificate), #92 (cancel refunds only base cost), #21 (escrow without service) — all node-side ledger issues, not this SDK control-flow bug.

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

Step Requirement Status
1 Reproduce against testnet; capture tx hashes / block heights Reproduced locally and deterministically, with no network dependency: the step sequence is computed from src/hold.ts:86 and the rejection comes from src/lease.ts:22-26. Not yet exercised against test.network — doing so would require renting a machine and running the hold to a partial-minute boundary, which spends real testnet escrow. The code path is fully deterministic and the fix is verifiable by unit test.
2 GitHub issue with suggested severity tier and area Tier: Medium · Area: SDK — compute leasing (renewal)
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 — Medium 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: Medium (validation gap / incorrect error handling; ends a paid hold early)

Thread

arturbarszcz782026-10-28 06:20 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-0077.