Proof of Work
Proof of Work
Proof of work in the XE network is an anti-spam mechanism, not a consensus mechanism. Every block carries a nonce that costs roughly a second of single-core CPU to find, which rate-limits block creation without requiring fees.
[!NOTE] PoW mints nothing PoW gates block submission only. There is no mining and no PoW self-minting: solving a nonce never creates funds. XUSD is issued by an authorized minter via
mintblocks.
Algorithm
The PoW algorithm uses Blake2b with an 8-byte digest:
result = blake2b_8(nonce_LE || blockHash)- Encode the nonce as an 8-byte little-endian
uint64 - Concatenate
nonce_LE || blockHash(hex-decoded block hash) - Compute Blake2b with an 8-byte output
- Interpret the result as a big-endian
uint64 - The PoW is valid if
result >= difficulty
[!WARNING] Byte order matters The nonce is encoded as little-endian, but the Blake2b output is compared as big-endian. Both the Go node and the browser wallet must follow this convention exactly.
Difficulty constants
| Constant | Value | Expected attempts | Time (single core) |
|---|---|---|---|
core.DefaultDifficulty | 0xfffff80000000000 | ~2 million | ~1 second |
core.TestDifficulty | 0x0000000000000002 | ~1 | Instant |
chat.DefaultPoWDifficulty | 0xffffc00000000000 | ~2¹⁸ | ~0.1 second |
The default block difficulty is calibrated so that a single CPU core finds a valid nonce in roughly 1 second. This is fast enough to be imperceptible for legitimate users but expensive enough to prevent spam.
TestDifficulty is used in tests and development -- almost any nonce satisfies it.
Chat envelopes carry their own, cheaper PoW under a separate constant, because chat spam and block spam are different cost targets and must be tunable independently.
A node advertises the thresholds it enforces in GET /node as hex strings
(pow_difficulty, chat_pow_difficulty); "0" means the node has PoW disabled. Clients
should read them from the node rather than hardcoding a value.
Validation
The ledger validates PoW on every block it accepts, provided a non-zero difficulty is
configured. xe node configures core.DefaultDifficulty. A block whose nonce fails the
threshold is rejected with ErrInvalidPoW.
Functions
ComputePoW(blockHash, difficulty) → nonce
Deprecated: loops indefinitely with no cancellation. Prefer ComputePoWWithContext for production use.
Single-threaded brute-force search starting from a random nonce. Increments until a valid nonce is found.
nonce := core.ComputePoW(blockHash, core.DefaultDifficulty)ComputePoWConcurrent(blockHash, difficulty, numWorkers) → nonce
Parallel search using multiple goroutines. Each worker starts from a different random offset. The first worker to find a valid nonce wins. A convenience wrapper around ComputePoWWithContext with a background context.
nonce := core.ComputePoWConcurrent(blockHash, core.DefaultDifficulty, 4)ComputePoWWithContext(ctx, blockHash, difficulty, numWorkers) → nonce, error
Cancellable parallel search. Returns ErrPoWCancelled if the context is cancelled before a solution is found.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
nonce, err := core.ComputePoWWithContext(ctx, blockHash, core.DefaultDifficulty, 4)ValidatePoW(blockHash, nonce, difficulty) → bool
Verify that a given nonce meets the difficulty threshold. Used by the ledger when processing incoming blocks.
valid := core.ValidatePoW(blockHash, nonce, core.DefaultDifficulty)Client-side PoW
The web UI computes proof of work in the browser, in a bundled Blake2b
module shipped with the UI (assets/blake2b.js and assets/pow.js). The algorithm is
identical to the Go implementation:
- Encode nonce as 8-byte little-endian
- Concatenate with hex-decoded block hash
- Blake2b with 8-byte output
- Compare as big-endian uint64
The browser solver yields to the event loop periodically so the page stays responsive,
and reads the target difficulty from GET /node.
[!WARNING] There is no server-side PoW endpoint
POST /powwas removed: an unauthenticated endpoint that grinds a nonce for any caller is a free compute oracle and a denial-of-service surface. Clients must compute their own proof of work. Requests to/powreturn404.
See also
- Cryptography -- hashing and signing primitives
- Binary Encoding -- how the PoW nonce is encoded in full block serialization
- Constants -- difficulty values and other system constants