{"id":"XE-13399","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"561","source_url":"https://github.com/xeprotocol/xe/issues/561","reporter_id":2381,"title":"Node.Stop() stalls ~65–70 s on an in-flight performance-certificate benchmark","area":"node-api","claimed_tier":"minor","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":true,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:17.186658+00:00","updated_at":"2026-11-20T19:47:47.075382+00:00","source_created_at":"2026-11-14T11:50:56+00:00","told_at":"2026-11-20T19:46:17+00:00","status_changed_at":"2026-11-20T19:45:44.558993+00:00","url":"https://bounty.xe.network/XE-13399","body":"**Severity: Minor** (XE tier ceiling 650 XE). **CVSS 3.1: 4.0 (AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L)** — CVSS Medium at the boundary; XE tier Minor per the bounty tier table (see §7).\n\n**Target:** `github.com/xeprotocol/xe` @ `89a542ea51d38375299aee54c6c99102e9bfa666` (\"release: testnet-0005 quorum withhold fix\", 2026-11-10). Go 1.25.0.\n\n## 1. Impact (read this first)\n\n`Node.Stop()` waits out a running performance-certificate benchmark whenever a certificate attempt is in flight: an operator who stops the node during a cert attempt waits **~65–70 s with no response** (no timeout, no interrupt). Measured at HEAD: benchmark wall **68.17 s**, Stop latency **70.20 s** — Stop issued 1 s into a live `maintainCertificate` attempt waited out the in-flight benchmark.\n\nThe stall is bounded: after a failed attempt the loop re-checks ctx and returns, so `Stop()` waits at most ONE attempt (~64–68 s), not the whole retry chain. The benchmark runs at node start (no cert yet) and at each renewal (`certRenewalDelay`), so the window recurs on every cert cycle, not just once. No remote trigger, no crash, no leak, no state corruption, no funds: a bounded shutdown delay. That is why this is Minor.\n\n## 2. Root cause\n\nA ~64–68 s CPU-bound, non-cancellable unit of work sits inside a wg-tracked goroutine whose only ctx checks are between attempts. `generatePerformanceCertificate` (`node/perf.go:34`) calls `perf.RunBenchmark(seed, perf.PoWPuzzles)` (`node/perf.go:58`; `perf/benchmark.go:114-130`, `PoWPuzzles = 1024` (`perf/benchmark.go:15`), 19-bit puzzles (`PoWDifficultyBits = 19`, `:17`), `solvePuzzle` workers with no ctx). It is called from `certGenerationLoop` (`node/perf.go:201`, ctx checked only BETWEEN attempts) inside `maintainCertificate` (`node/perf.go:158`), spawned as a wg-tracked goroutine at `node/node.go:557`. `Stop()` (`node/node.go:1301-1308`) `wg.Wait()`s it with no timeout. Neither the benchmark nor the cert loop checks ctx mid-attempt, so there is nothing for `Stop()` to interrupt — it waits for the puzzles to finish.\n\n## 3. Scenario (how it happens)\n\n1. A node starts (no certificate yet) or reaches a certificate renewal: `maintainCertificate` begins a `generatePerformanceCertificate` attempt — 1024 sequential 19-bit puzzles, ~64–68 s of CPU work.\n2. The operator stops the node (`Node.Stop()`, e.g. SIGTERM during an upgrade or restart) while the attempt is in flight.\n3. `Stop()` calls `n.cancel()` and then `n.wg.Wait()` — and waits. The benchmark does not observe the cancelled ctx. Shutdown is unresponsive for the remainder of the attempt (~65–70 s from the operator's point of view). After the attempt fails/completes, the loop re-checks ctx and returns, and `Stop()` proceeds — at most one attempt's worth of delay.\n\n## 4. Proof of concept (local, deterministic)\n\nPoC: `hunt-v3/stage3/tests/` — `TestT38_BenchmarkWallTime` (`node/`, **NO `-race`**, 139.40 s), re-run byte-identical at HEAD in an isolated worktree copy with temp data dirs. The `-race` run was infeasible in V3 (>13 min, killed by a runtime restart — race-detector overhead ~10–15× on this CPU-bound code), so the no-race run is authoritative, exactly as in V3.\n\nRe-run result at HEAD (2026-11-14), same magnitude as V3 (2026-11-11):\n\n| Observation | V3 | Re-run at HEAD |\n|---|---|---|\n| `RunBenchmark(seed, 1024)` wall | 64.24 s (score 0.0156) | **68.17 s** (result.Elapsed 68.167 s, score 0.0147) |\n| Stop latency (issued 1 s into a live attempt) | 65.48 s | **70.20 s** |\n| Mechanism | `H-D MECHANISM CONFIRMED` | `H-D MECHANISM CONFIRMED` |\n| Race detector | 0 `DATA RACE` | 0 `DATA RACE` |\n\nThe ~4 s / ~5 s increases vs V3 are run-to-run CPU variance on the shared VM (same 1024-puzzle workload, same code path); magnitude and mechanism are unchanged.\n\nLog: `hunt-v4-followup/stage3-minors/logs/t38-reverify-norace.log`. The test files were copied byte-identical (`cmp` clean; sha256 `6c42779aeb57a66bada81445b9174de806f025a8d9196a7761eeb17f894888a7` for `node/stage3_lifecycle_test.go`).\n\n## 5. Attacker prerequisites\n\n- **None — local only, no attacker.** The trigger is a local operator stopping the node during a cert attempt. No remote step, no privilege on the victim. The window recurs at node start and at each renewal, so an operator stopping the node has a realistic chance of hitting it — but hitting it costs only time.\n\n## 6. Independent validation and false-positive assessment\n\n- **Deterministic reproduction, twice:** V3 (2026-11-11) and the HEAD re-run (2026-11-14) give the same magnitude (64.24 s → 68.17 s wall, 65.48 s → 70.20 s Stop). The stall is measured wall time, not a pattern match.\n- **Disproof attempted:** (a) checked whether the benchmark or the cert loop checks ctx mid-attempt — neither does; (b) checked whether the stall could be the whole retry chain — disproved, bounded to one attempt by the ctx re-check after a failed attempt; (c) checked whether `waitForAttestationPeers` could extend it — it is ctx-guarded, so no.\n- **Duplicate check (fresh, DB 2,421 entries as of 2026-11-14 ~17:00 WIB):** all 7 benchmark/certificate hits are *trust* reports (forged benchmark scores, unverified work proofs, expired-cert acceptance — XE-4975, xe#354, XE-5677, xe#392, XE-0001/xe#6), not shutdown latency. The closest same-class report is XE-0920 (queued VM provision blocks shutdown — different function, unbounded, stand-in-sleep PoC). XE-0041/xe#60 is a SIGTERM sync hang (different function, no benchmark). xe#348/PR #349 is a wg-*registration* race on a running node; PR #349 (full body + files list read this run) never mentions `perf/`, `RunBenchmark`, `generatePerformanceCertificate`, `maintainCertificate`, or `certGenerationLoop`, and adds no `Stop()` timeout — it does not fix this. Classification: **NOVEL on public data** (private Critical/Severe reports may exist; uniqueness is not guaranteed). Full analysis: `duplicate-intel/reports/v4f-hd-benchmark-duplicate-analysis.md`.\n\n## 7. Severity justification (Minor, ceiling 650 XE)\n\nCVSS 3.1: **4.0 (AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L)**. Attack vector is local (a local operator stopping the node); complexity is Low (stop during a cert attempt — a window that recurs at start and at each renewal); no privileges or user interaction; availability impact is Low (a bounded ~65–70 s unresponsive shutdown; the node stops cleanly afterwards, no crash, no state impact, no funds). The CVSS score sits exactly on the Low/Medium boundary (4.0); the XE tier is Minor because the bounty tier table prices this class — a bounded shutdown delay with no remote trigger and no lasting effect — as Minor, and the CVSS number is informational here.\n\nWhy not higher: the delay is bounded to one attempt, the node always stops cleanly afterwards, and nothing is lost or corrupted.\n\n## 8. Fix suggestion\n\nMake the benchmark ctx-aware: chunk the 1024 puzzles with ctx checks between chunks (or pass the ctx into `RunBenchmark`/`runCPUChain`), so `Stop()`'s cancel interrupts the attempt — or run the cert attempt outside `n.wg` with a timeout so `Stop()` does not wait it out. Either fix must keep the certificate issuance semantics (a cancelled attempt simply retries on the next cycle, as the existing between-attempt re-check already does).\n\n## 9. Caveats (kept in the report)\n\n1. The `-race` run is infeasible (>13 min, killed in V3); the no-race numbers are the production-relevant ones.\n2. The ~4–5 s increases vs V3 are run-to-run CPU variance on the shared VM, not a code change.\n3. The stall is bounded to ONE attempt by the ctx re-check after a failed attempt; it is not the whole retry chain.\n4. NOVEL means no matching *public* finding as of the 2026-11-14 ~17:00 WIB check (DB 2,421 entries); private reports may exist.\n\n## 10. Reproduction (for the committee)\n\nLocal only, worktree copy at `89a542e`, isolated temp data dirs:\n\n```bash\nexport PATH=~/workspace/go/go/bin:$PATH\nexport TMPDIR=~/workspace/xe-bounty/.tmp\ncd <worktree>/node\ngo test -count=1 -timeout 20m -run 'TestT38_BenchmarkWallTime$' -v ./...\n# Expected: PASS (exit 0), ~140 s — read the numbers from the log:\n# RunBenchmark wall ~68 s, Stop latency ~70 s, H-D MECHANISM CONFIRMED.\n# Do NOT add -race (infeasible on this CPU-bound code, >13 min).\n```\n\nPoC: `hunt-v3/stage3/tests/` (`node/stage3_lifecycle_test.go`). Log: `hunt-v4-followup/stage3-minors/logs/t38-reverify-norace.log`. Full analysis: `hunt-v3/stage3/STAGE3_VERDICT.md` §H-D; duplicate analysis: `duplicate-intel/reports/v4f-hd-benchmark-duplicate-analysis.md`.","patch_refs":[],"thread":[{"id":15194,"source":"github","source_ref":"7049040013","author":"Joseph Denne","team":true,"body":"Thanks for the report. We have read it against the code and confirmed the behaviour you describe. It is being handled, and this ticket will be updated when there is a change to check.","created_at":"2026-11-20T19:46:17+00:00"}]}