{"id":"XE-0254","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":68,"title":"[SECURITY][Minor] SDK - attestedTime ignores the node's 10-minute skew window, so a renewal can be aborted by the SDK or rejected by the node","area":"sdk-docs-web","claimed_tier":"minor","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-02T16:39:05.657171+00:00","updated_at":"2026-11-08T20:17:41.885067+00:00","source_created_at":null,"told_at":"2026-11-08T20:18:49.736753+00:00","status_changed_at":"2026-11-08T20:18:33.171120+00:00","url":"https://bounty.xe.network/XE-0254","body":"# [SECURITY][Minor] SDK - attestedTime ignores the node's 10-minute skew window, so a renewal can be aborted by the SDK or rejected by the node\r\n\r\n| Field | Value |\r\n|---|---|\r\n| **Severity** | Minor |\r\n| **Area** | SDK — compute leasing (renewal) |\r\n| **Component** | `src/attestation.ts` (`attestedTime`, `gatherAttestations`), `src/xe.ts` (`renewLease`) |\r\n| **Version** | `xeprotocol/sdk` @ `0dbc92ecff709bee79768e4e37788c682a0f4525` (master, 2026-10-23) · `xeprotocol/xe` @ `978785929bc1` |\r\n| **Status** | Reproduced (unit, deterministic) |\r\n| **Date** | 2026-11-02 |\r\n| **Reporter** | Desk web account `xe:64e3ca3f…0cd4` (reporter id 68) — the same person who filed XE-0077 / XE-0078 / XE-0080 under the GitHub login `targammm` (reporter id 30). Please merge the two records so the award history is attributed once. |\r\n\r\n---\r\n\r\n## 1. Summary\r\n\r\nA lease renewal is timed by a threshold of timekeeper attestations. The node computes the renewal time\r\nitself, from the attestations it accepts:\r\n\r\n```go\r\n// core/attestation.go:53-107\r\nfunc ValidateAttestations(attestations []TimekeeperAttestation, leaseHash string, config *TimekeeperConfig, skipSkew bool) (int64, error) {\r\n    ...\r\n    for _, a := range attestations {\r\n        if !trusted[a.PublicKey] { continue }\r\n        if seen[a.PublicKey] { continue }\r\n        if err := VerifyAttestation(&a, leaseHash); err != nil { continue }\r\n        if !skipSkew {\r\n            delta := a.Timestamp - now\r\n            if delta < 0 { delta = -delta }\r\n            if delta > MaxAttestationSkew { continue }   // <-- 10-minute window (line 47)\r\n        }\r\n        seen[a.PublicKey] = true\r\n        validTimestamps = append(validTimestamps, a.Timestamp)\r\n    }\r\n    if len(validTimestamps) < config.Threshold {\r\n        return 0, fmt.Errorf(\"only %d valid attestations from trusted timekeepers, need %d\", len(validTimestamps), config.Threshold)\r\n    }\r\n    sort.Slice(validTimestamps, func(i, j int) bool { return validTimestamps[i] < validTimestamps[j] })\r\n    median := validTimestamps[(len(validTimestamps)-1)/2]\r\n    return median, nil\r\n}\r\n```\r\n\r\nThe SDK verifies the signature and the key membership — but **not** the skew window — and then takes the\r\nlower median over **every** attestation it gathered:\r\n\r\n```typescript\r\n// src/attestation.ts:26-30\r\nexport function attestedTime(atts: Attestation[]): bigint {\r\n  if (atts.length === 0) throw new XeUsageError('attestedTime: no attestations')\r\n  const sorted = atts.map((a) => a.timestamp).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))\r\n  return sorted[Math.floor((sorted.length - 1) / 2)]!\r\n}\r\n```\r\n\r\nThe median rule itself matches the node exactly. The **filter** does not. So whenever a timekeeper's clock is\r\nmore than 10 minutes off, the SDK's renewal time differs from the node's renewal time, and the SDK's renewal\r\ntime is the one it acts on:\r\n\r\n```typescript\r\n// src/xe.ts:457-465\r\nconst attestations = await this.#attest(leaseHash)\r\nconst renewTime = attestedTime(attestations)\r\nif (renewTime >= lease.effectiveExpiry) {\r\n  throw new XeUsageError(`renewLease: lease expired at ${lease.effectiveExpiry} before the renewal was attested`)\r\n}\r\n...\r\nconst epoch = await this.#epochAt(renewTime)\r\n```\r\n\r\n## 2. Affected code\r\n\r\n| File | Line | Issue |\r\n|---|---|---|\r\n| `src/attestation.ts` | 26–30 | `attestedTime` — lower median over **all** gathered attestations, no skew filter |\r\n| `src/attestation.ts` | 79–116 | `gatherAttestations` — checks signature and key membership, but not the ±10-minute window |\r\n| `src/xe.ts` | 457–458 | `renewLease` computes `renewTime` from the SDK's own median |\r\n| `src/xe.ts` | 459–461 | the expiry precheck uses the SDK's `renewTime` ⇒ a renewal the node would accept is aborted |\r\n| `src/xe.ts` | 465 | `#epochAt(renewTime)` picks the epoch to lock ⇒ the locked params can be the wrong epoch's |\r\n| `core/attestation.go` | 47–49 | `MaxAttestationSkew = 10 * time.Minute` |\r\n| `core/attestation.go` | 91–93 | the node drops any attestation outside the window |\r\n| `core/attestation.go` | 100 | the node needs `threshold` **survivors** |\r\n| `core/lease_renew.go` | 52 | the node computes `renewTime` with `ValidateAttestations` — its own filter |\r\n| `core/lease_renew.go` | 95 | `validateLockedEmissionAt(renewTime, b.LockedR, b.LockedCap, b.LockedTWAP, …)` |\r\n\r\n## 3. Reproduction\r\n\r\nDeterministic — the node rule is transcribed verbatim and the SDK's own `attestedTime` is imported from the\r\nbuilt SDK.\r\n\r\n```javascript\r\n// repro-attestation-skew.mjs\r\nimport { attestedTime } from './dist/attestation.js'\r\n\r\nconst MAX_SKEW = 10 * 60 * 1000\r\nfunction nodeAttestedTime(atts, trusted, threshold, now) {\r\n  const seen = new Set(); const valid = []\r\n  for (const a of atts) {\r\n    if (!trusted.has(a.publicKey)) continue\r\n    if (seen.has(a.publicKey)) continue\r\n    if (Math.abs(a.timestamp - now) > MAX_SKEW) continue     // the filter the SDK lacks\r\n    seen.add(a.publicKey); valid.push(a.timestamp)\r\n  }\r\n  if (valid.length < threshold) return { error: `only ${valid.length} valid attestations … need ${threshold}` }\r\n  valid.sort((a, b) => a - b)\r\n  return { time: valid[Math.floor((valid.length - 1) / 2)] }\r\n}\r\n\r\nconst now = 1_700_000_000_000\r\nconst atts = [\r\n  { publicKey: 'tk-a', timestamp: now },\r\n  { publicKey: 'tk-b', timestamp: now + 3 * 60_000 },\r\n  { publicKey: 'tk-c', timestamp: now + 15 * 60_000 },   // clock 15 min fast\r\n]\r\nconsole.log('node:', nodeAttestedTime(atts, trusted, 2, now).time)\r\nconsole.log('sdk :', attestedTime(atts.map(a => ({ ...a, timestamp: BigInt(a.timestamp) }))).toString())\r\n```\r\n\r\n**Observed:**\r\n\r\n```\r\nattestations (ms since epoch):\r\n  tk-a  t=1700000000000  skew=0.0 min  node keeps it: true\r\n  tk-b  t=1700000180000  skew=3.0 min  node keeps it: true\r\n  tk-c  t=1700000900000  skew=15.0 min  node keeps it: false\r\n\r\nnode attested time : 1700000000000 (0 min from now)\r\nSDK  attested time : 1700000180000 (3 min from now)\r\nDIVERGENCE         : 3 min\r\n```\r\n\r\nWith a lease whose effective expiry is 2 minutes away:\r\n\r\n```\r\nnode renewTime < expiry?  true   -> the node WOULD accept the renewal\r\nSDK  renewTime < expiry?  false  -> the SDK throws \"renewLease: lease expired at … before the renewal was attested\"\r\n=> the SDK ABORTS a renewal the node would have accepted. The lease is not renewed.\r\n```\r\n\r\nAnd with a threshold of 3 where two timekeepers have drifted:\r\n\r\n```\r\nSDK  gatherAttestations() returns 3 attestations and reports the threshold MET (>= 3)\r\nnode ValidateAttestations()   -> only 1 valid attestations from trusted timekeepers, need 3\r\n=> the SDK hands the caller a block the node refuses to accept.\r\n```\r\n\r\nFull script: `repro-attestation-skew.mjs`. It imports the SDK's real `attestedTime` from the **built** SDK\r\n(`sdk/dist/attestation.js`, built from `0dbc92ecff709bee79768e4e37788c682a0f4525`) and is attached, together\r\nwith its output.\r\n\r\n## 4. Impact\r\n\r\nTwo distinct consequences, both on the renewal path:\r\n\r\n- **The SDK aborts a renewal the node would accept.** The SDK's median is pulled forward by the skewed\r\n  attestation, so `renewTime` can land at or past `lease.effectiveExpiry` and the SDK throws\r\n  *\"lease expired … before the renewal was attested\"*. The lease is then not renewed and the machine is\r\n  released at its current expiry — the same consequence class as the already-accepted SDK renewal report\r\n  (XE-0077), reached through a different path.\r\n- **The node rejects a renewal the SDK built.** When enough attestations are outside the node's window, the\r\n  node's `ValidateAttestations` finds fewer than `threshold` survivors and rejects the block with\r\n  *\"only N valid attestations from trusted timekeepers, need M\"* — even though the SDK reported the threshold\r\n  met and handed the caller a complete block.\r\n- **The locked emission terms can come from the wrong epoch.** The SDK locks the params of the epoch at *its*\r\n  renewal time; the node checks them against the epoch at *its* renewal time\r\n  (`validateLockedEmissionAt`). When the two times straddle an epoch boundary and the params differ, the node\r\n  rejects the block with *\"lease_renew locked emission mismatch\"*.\r\n\r\n> **Honest boundary — this has no effect on the live testnet today.** The three public timekeepers' clocks are\r\n> within ~3 seconds of each other (re-measured 2026-11-02 16:20 UTC from the HTTP `Date` headers of\r\n> `ldn` / `nyc` / `ffm`: 16:20:30 / 16:20:32 / 16:20:33), so no attestation falls outside the 10-minute window\r\n> and the node drops none. And the per-epoch parameters are identical across the last 49 epochs — re-read live\r\n> on 2026-11-02, epochs 4870–4918 all carry `r_effective=2000`, `payout_cap=1527`, `twap_milli_usd=250`, i.e.\r\n> **one distinct parameter set** — so a divergence in renewal time cannot change the locked params either. The\r\n> defect is live in the SDK's logic and becomes observable the first time a timekeeper's clock drifts more than\r\n> 10 minutes — or when the epoch parameters start to differ. **This is a latent defect, not a live incident**,\r\n> which is why it is filed as Minor.\r\n\r\n## 5. Why the test suite misses it\r\n\r\nThe SDK's unit tests cover `attestedTime` as a pure median over a list, and `gatherAttestations` with mocked\r\ntimekeepers. There is no test in which an attestation is outside a skew window, because the SDK has no skew\r\nwindow. The node's behaviour is therefore only discoverable by reading `core/attestation.go` against\r\n`src/attestation.ts`.\r\n\r\n## 6. Suggested fix\r\n\r\n1. Apply the node's filter in the SDK before computing the median: drop any attestation whose timestamp is more\r\n   than `MaxAttestationSkew` (10 min) from the local clock, and **count only the survivors against the\r\n   threshold** — `gatherAttestations` should report failure when fewer than `threshold` survive.\r\n2. Keep the window in one exported constant so the SDK and the node cannot drift apart silently.\r\n3. Consider making the skew window configurable, since it is a node policy value (`MaxAttestationSkew` is a\r\n   `var`, not a `const`, in `core/attestation.go:49`) that the core team can change.\r\n4. Add a regression test: one attestation 15 minutes fast ⇒ the SDK's attested time equals the node's, and\r\n   `gatherAttestations` fails when the surviving count drops below the threshold.\r\n\r\n## 7. Duplicate check\r\n\r\n- `xeprotocol/sdk`: **0 issues, 14 PRs** (fetched 2026-11-02). No PR or issue mentions attestation skew, the\r\n  skew window, or `attestedTime`. PR #1 (the leasing feature) is the only PR that touches attestations.\r\n- `xeprotocol/xe`: **236 issues + PRs**, all fetched and searched 2026-11-02. The attestation-related entries\r\n  are node-side and different: **#19** / **#23** (the *sync* path skips the freshness check — a node consensus\r\n  issue, with a node PR open) and **#175** / **#176** (lease_accept locks terms from any of the last 4 epochs —\r\n  the node's epoch-candidate tolerance). Neither touches the SDK's renewal-time computation.\r\n- XE bounty desk: all **113 published tickets** searched 2026-11-02 — 0 hits for \"skew\"; the attestation hits\r\n  are XE-0010 (= upstream #19), XE-0030 (timekeeper attestation rate limit, node-side) and XE-0138\r\n  (`canAttest` provider identity, node-side).\r\n\r\n## 8. Submission checklist (per programme \"How to Report\")\r\n\r\n| Step | Requirement | Status |\r\n|---|---|---|\r\n| 1 | Reproduce against testnet; capture tx hashes / block heights | Reproduced locally and deterministically: the SDK's real `attestedTime` is compared with a verbatim transcription of `ValidateAttestations`. **Not** reproduced live — it needs a timekeeper whose clock is more than 10 minutes off, and the three public timekeepers are currently within ~3 s of each other (re-measured 2026-11-02). The live-state check is included as evidence that the defect is latent, not observed. The divergence is stated with that boundary rather than claimed as observed on the testnet. |\r\n| 2 | GitHub issue with suggested severity tier and area | Tier: **Minor** · Area: **SDK — compute leasing (renewal)** |\r\n| 3 | Clear PoC + impact analysis (who is affected, worst case) | Included — sections 3 and 4, with the live-state caveat stated up front |\r\n| 4 | Critical/Severe goes to `security@xe.network` first | Not applicable — Minor is below Severe, so a public issue is the correct channel |\r\n| 5 | Triage by the core team | Awaiting |\r\n| 6 | XE address for payout at genesis | `64e3ca3f6e9378cd549032de9f087b5496fd4100516c7bdb46c17b00d4220cd4` — XE native chain (block lattice, ed25519), derived from the reporter's recovery phrase via BIP39 → SLIP-0010 ed25519 `m/44'/1'/account'`; address = `sha256(\"xe/account/v1\" ‖ pubkey)` |\r\n\r\n---\r\n\r\n*Suggested tier: Minor (650 XE) — the SDK does not mirror the node's attestation acceptance rule; latent today, ends a renewal early when a timekeeper clock drifts*","patch_refs":[],"thread":[{"id":1152,"source":"desk","source_ref":"reply:704","author":"Joseph Denne","team":true,"body":"Thanks for the report and for stating clearly that this is latent on the current network. We have confirmed the parity gap you describe in the SDK's renewal path and it is being handled; we will update https://bounty.xe.network/XE-0254 when there is a fix to point at.","created_at":"2026-11-08T20:17:41.885067+00:00"}]}