Bounty
XE-0703 · Bounty

CLI: `xe chat send` grinds CPU without limit when the node advertises a near-maximum chat PoW difficulty

Triaging xe#274 filed 2026-11-05 12:54 UTC by rusdiwireng

Report

Summary

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.

Impact

This 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.

Root cause

The chain is short and has no guard anywhere along it:

  1. 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.
  2. cmd/xe/chat.go:110-122, chatSend(): passes that difficulty straight into chat.NewEnvelope(...). No cap, no timeout, no warning.
  3. chat/envelope.go:78-80, NewEnvelope(): when difficulty > 0, it calls core.ComputePoWConcurrent(idBytes, difficulty, runtime.NumCPU()).
  4. 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.

Only 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.

The 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.

Reproduction

Tested 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.

Control run, stub advertising the normal difficulty ffffc00000000000:

./xe chat send fd1d0b073d2b42e073935cbe40fd38302cd7b1bebb1758b665e45deeeb3b201d "r5-cli03-control"
Sent 16 bytes to fd1d0b07...eb3b201d
  ID: 5d56b5d01c2ee9f843c4f16ea3460a25ab2044b70132d3c327f6e504ef1f605e
exit=0, wall time 0.19 s

The stub log shows two GET /node requests followed by POST /chat/send. The command completes normally.

Attack run, stub advertising fffffffffffffff0, same command under timeout 15, run twice:

wall time 15.01 s, exit code 124 (killed by timeout)
stdout: empty
stderr: empty
stub log: GET /node only, no POST /chat/send

A 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.

Suggested fix

Reject 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.

Method limits

All 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.

Thread

Joseph Denneteam2026-11-08 20:19 UTCgithub

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.