{"id":"XE-0703","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"274","source_url":"https://github.com/xeprotocol/xe/issues/274","reporter_id":7,"title":"CLI: `xe chat send` grinds CPU without limit when the node advertises a near-maximum chat PoW difficulty","area":"sdk-docs-web","claimed_tier":null,"assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"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-05T12:54:32.637729+00:00","updated_at":"2026-11-10T00:11:51.660123+00:00","source_created_at":"2026-11-05T12:54:00+00:00","told_at":"2026-11-08T20:19:10+00:00","status_changed_at":"2026-11-08T20:18:18.387067+00:00","url":"https://bounty.xe.network/XE-0703","body":"### Summary\n\n`xe chat send` takes the chat proof-of-work difficulty straight from the node it talks to and feeds it into the PoW solver with no upper bound, no timeout, and no sanity check. A node that advertises a difficulty close to `0xffffffffffffffff` makes the CLI burn CPU forever. The user sees nothing while this happens: no progress output, no warning, no error. The only way out is to kill the process.\n\n### Impact\n\nThis is a local denial of service against the user's own CLI session. The trigger is a malicious or compromised node, or a man-in-the-middle on a plaintext `XE_NODE=http://...` URL. The default node URL is `https://ldn.core.test.network`, so the realistic trigger is a node operator the user already points at. No funds move, no data leaks, and no other user is affected. The process ends cleanly on Ctrl-C or SIGTERM, with no message sent and no state corrupted. The harm is a hung terminal and wasted CPU until the user notices and kills it.\n\n### Root cause\n\nThe chain is short and has no guard anywhere along it:\n\n1. `client/chat.go:29-40`, `ChatPoWDifficulty()`: reads `chat_pow_difficulty` from `GET /node` and parses it with `strconv.ParseUint(s, 16, 64)`. There is no range check and no comparison against any known-good value. The only errors are an empty string or invalid hex.\n2. `cmd/xe/chat.go:110-122`, `chatSend()`: passes that difficulty straight into `chat.NewEnvelope(...)`. No cap, no timeout, no warning.\n3. `chat/envelope.go:78-80`, `NewEnvelope()`: when `difficulty > 0`, it calls `core.ComputePoWConcurrent(idBytes, difficulty, runtime.NumCPU())`.\n4. `core/pow.go:49-51`, `ComputePoWConcurrent()`: calls `ComputePoWWithContext(context.Background(), ...)`, so there is no deadline and no cancellation. The context-aware variant at `core/pow.go:54` already supports cancellation, but nothing in this path ever supplies a cancellable context.\n\nOnly chat takes its difficulty from the server. Every other PoW call site uses the constant `core.DefaultDifficulty` (`core/pow.go:17`): `cmdSend`, `cmdReceive`, `cmdMint`, `cmdBurn`, `cmdLease`, and `cmdSignBlock` in `cmd/xe/main.go`, plus `cmdNode`. The node itself defaults its advertised chat difficulty to `chat.DefaultPoWDifficulty` (`chat/envelope.go:17`, `node/node.go:217-219`), so a sane value already exists in the codebase. The CLI just never enforces it.\n\nThe difficulty is a 64-bit threshold on a uniform blake2b hash (`core/pow.go:35`, `ValidatePoW` checks `powHash >= difficulty`). Expected trials are `2^64 / (2^64 - difficulty)`. For the default `0xffffc00000000000` that is about 262,144 trials. For the advertised `0xfffffffffffffff0` in the test below it is about `2^60`, around `1.15 x 10^18` trials, which never finishes in practice.\n\n### Reproduction\n\nTested locally against a stub node on 127.0.0.1:18123, with a throwaway wallet and `XE_NODE=http://127.0.0.1:18123`. No testnet or mainnet traffic was involved. The CLI binary was built from the repository at commit `9787859`.\n\nControl run, stub advertising the normal difficulty `ffffc00000000000`:\n\n```\n./xe chat send fd1d0b073d2b42e073935cbe40fd38302cd7b1bebb1758b665e45deeeb3b201d \"r5-cli03-control\"\nSent 16 bytes to fd1d0b07...eb3b201d\n  ID: 5d56b5d01c2ee9f843c4f16ea3460a25ab2044b70132d3c327f6e504ef1f605e\nexit=0, wall time 0.19 s\n```\n\nThe stub log shows two `GET /node` requests followed by `POST /chat/send`. The command completes normally.\n\nAttack run, stub advertising `fffffffffffffff0`, same command under `timeout 15`, run twice:\n\n```\nwall time 15.01 s, exit code 124 (killed by timeout)\nstdout: empty\nstderr: empty\nstub log: GET /node only, no POST /chat/send\n```\n\nA second run sampled the child process directly. At 7 seconds elapsed it had used 8 CPU-seconds; at 11 seconds it had used 14 CPU-seconds, running 8 threads. It printed nothing, sent nothing, and was still grinding when the timeout killed it at 15 seconds.\n\n### Suggested fix\n\nReject a server-advertised difficulty above `chat.DefaultPoWDifficulty` (or a small multiple of it) in `ChatPoWDifficulty` or `chatSend`, and pass a context with a timeout into `ComputePoWWithContext`, which already accepts one. Printing progress while the PoW runs would also let the user see the CLI is grinding instead of hanging silently.\n\n### Method limits\n\nAll testing was local: a stub node on loopback, a throwaway wallet, and a CLI binary built from commit `9787859`. Nothing touched testnet or mainnet, and no real node was pointed at. The CPU figures come from a 4-vCPU VM, so absolute hash rates will differ on other machines; the point that stands on any machine is that the solver runs with no bound and stops only when killed. The tracker was checked live on 5 Nov 2026 (269 issues via the GitHub API) and no existing issue covers this root cause.","patch_refs":[{"id":312,"repo":"xeprotocol/xe","kind":"pr","ref":"286","title":"fix(cli,client,chat,node,api): harden CLI flag parsing, provider errors, chat PoW bounds, marketplace rate-limit, and API pagination","url":"https://github.com/xeprotocol/xe/pull/286","note":"","state":"open","author":"Khanhtnq","added_by":"desk","created_at":"2026-11-06T12:42:47.419656+00:00"},{"id":477,"repo":"xeprotocol/xe","kind":"pr","ref":"309","title":"fix(cli,chat): bound chat PoW difficulty and context timeout (fixes #274)","url":"https://github.com/xeprotocol/xe/pull/309","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-11-10T00:12:01.832547+00:00"}],"thread":[{"id":1176,"source":"github","source_ref":"6726599952","author":"Joseph Denne","team":true,"body":"Thanks for the report. We have confirmed the behaviour you describe in the CLI chat send path; it is being handled and we will update https://bounty.xe.network/XE-0703 when the fix has shipped.","created_at":"2026-11-08T20:19:10+00:00"}]}