{"id":"XE-0077","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"102","source_url":"https://github.com/xeprotocol/xe/issues/102","reporter_id":30,"title":"[SECURITY][Medium] SDK - holdLease aborts the whole hold on a partial-minute renewal step","area":"sdk-docs-web","claimed_tier":"medium","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:21.973809+00:00","updated_at":"2026-11-11T15:12:16.507996+00:00","source_created_at":"2026-10-27T17:59:46+00:00","told_at":"2026-11-10T00:15:48+00:00","status_changed_at":"2026-10-29T14:04:13.425719+00:00","url":"https://bounty.xe.network/XE-0077","body":"# [SECURITY] holdLease aborts the whole hold with a non-whole-minute renewal step\n\n| Field | Value |\n|---|---|\n| **Severity** | Medium |\n| **Area** | SDK — compute leasing |\n| **Component** | `src/hold.ts` |\n| **Status** | Reproduced (unit, deterministic) |\n| **Date** | 2026-10-27 |\n\n---\n\n## 1. Summary\n\n`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).\n\n`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.\n\n> **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.\n\n## 2. Affected code\n\n| File | Line | Issue |\n|---|---|---|\n| `src/hold.ts` | 86 | `const step = totalSecs === undefined ? renewSecs : minBig(renewSecs, totalSecs - lease.effectiveDuration)` — may yield a partial minute |\n| `src/hold.ts` | 90 | `renewBeforeExpiry(…, step, …)` → `renewLease` throws for a partial step; the `catch` at line 91 only maps `XePriceError`/`XeBudgetError`, so `XeUsageError` propagates |\n| `src/xe.ts` | 441 | `renewLease` calls `requireWholeMinutes(duration, 'renewLease')` → throws |\n| `src/lease.ts` | 22–26 | `requireWholeMinutes` rejects a duration that is not a multiple of 60 |\n\n## 3. Reproduction\n\nDeterministic — reproduces the step sequence without any network. Run with Node 20+.\n\n```javascript\n// step-math.mjs\nconst minBig = (a, b) => (a < b ? a : b)\nconst renewSecs = 60n\nfor (const totalSecs of [60n, 90n, 120n, 150n, 180n, 210n]) {\n  let eff = 0n, steps = [], guard = 0\n  while (eff < totalSecs && guard++ < 20) {\n    const step = minBig(renewSecs, totalSecs - eff)\n    steps.push(step)\n    if (step <= 0n) break\n    if (step % 60n !== 0n) { steps.push('<<< NON-WHOLE'); break }\n    eff += step\n  }\n  console.log(`totalSecs=${totalSecs}: [${steps.join(',')}]`)\n}\n```\n\n**Observed:**\n\n```\ntotalSecs=60:  [60]\ntotalSecs=90:  [60,30,<<< NON-WHOLE]\ntotalSecs=120: [60,60]\ntotalSecs=150: [60,60,30,<<< NON-WHOLE]\ntotalSecs=180: [60,60,60]\ntotalSecs=210: [60,60,60,30,<<< NON-WHOLE]\n```\n\nAnd the partial step is rejected by the renewal path:\n\n```javascript\n// whole-minute.mjs\nimport { requireWholeMinutes } from './dist/lease.js'\nfor (const s of [60n, 30n]) {\n  try { requireWholeMinutes(s, 'renewLease'); console.log(`step=${s}: OK`) }\n  catch (e) { console.log(`step=${s}: THROW ${e.name}: ${e.message}`) }\n}\n```\n\n**Observed:**\n\n```\nstep=60: OK\nstep=30: THROW XeUsageError: renewLease: duration must be a whole number of minutes (a multiple of 60s), got 30s\n```\n\nIn `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`.\n\n## 4. Impact\n\n- **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.\n- **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.\n- **Escrow is not lost, but time is.** The already-paid minutes are spent; the unreached term is simply never bought.\n- **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.\n- **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.\n\n> **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.\n\n## 5. Why the test suite misses it\n\n`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.\n\n## 6. Suggested fix\n\n1. 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`.\n2. 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.\n3. Map `XeUsageError` from the renewal path to a `done('target-reached')` result rather than letting it escape `holdLease`.\n4. Add a regression test that drives `holdLease` with a non-multiple `totalSecs` against a mock that enforces `requireWholeMinutes`.\n\n## 7. Duplicate check\n\n- `xeprotocol/xe` issue tracker scanned (98 items, open + closed + PRs) on 2026-10-27.\n- 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`.\n- 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.\n\n\n## 8. Submission checklist (per programme \"How to Report\")\n\n| Step | Requirement | Status |\n|---|---|---|\n| 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. |\n| 2 | GitHub issue with suggested severity tier and area | Tier: **Medium** · Area: **SDK — compute leasing (renewal)** |\n| 3 | Clear PoC + impact analysis (who is affected, worst case) | Included — sections 3 and 4 |\n| 4 | Critical/Severe goes to `security@xe.network` first | Not applicable — Medium is below Severe, so a public issue is the correct channel |\n| 5 | Triage by the core team | Awaiting |\n| 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) |\n\n---\n\n*Suggested tier: Medium (validation gap / incorrect error handling; ends a paid hold early)*","patch_refs":[{"id":200,"repo":"xeprotocol/sdk","kind":"pr","ref":"11","title":"","url":"https://github.com/xeprotocol/sdk/pull/11","note":"","state":"","author":"","added_by":"desk","created_at":"2026-10-29T14:22:09.061497+00:00"}],"thread":[{"id":25,"source":"github","source_ref":"6462218846","author":"arturbarszcz78","team":false,"body":"[comment from a blocked account removed]","created_at":"2026-10-28T06:20:25+00:00"},{"id":1576,"source":"github","source_ref":"6755094479","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-0077.","created_at":"2026-11-10T00:15:48+00:00"}]}