Proof of Work
Proof of Work
Proof of work in the XE network is an anti-spam mechanism, not a consensus mechanism. It rate-limits block creation to approximately 1 block per second per account, preventing flooding attacks without requiring fees.
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 JavaScript wallet must follow this convention exactly.
Difficulty constants
Constant
Value
Expected attempts
Time (single core)
DefaultDifficulty
0xfffff80000000000
~2 million
~1 second
TestDifficulty
0x0000000000000002
~1
Instant
The default 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.
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 := pow.ComputePoW(blockHash, pow.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.
nonce := pow.ComputePoWConcurrent(blockHash, pow.DefaultDifficulty, 4)ComputePoWWithContext(ctx, blockHash, difficulty, numWorkers) → nonce, error
Cancellable parallel search. Returns an error if the context is cancelled before a solution is found.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
nonce, err := pow.ComputePoWWithContext(ctx, blockHash, pow.DefaultDifficulty, 4)ValidatePoW(blockHash, nonce, difficulty) → bool
Verify that a given nonce meets the difficulty threshold. Used by validators when processing incoming blocks.
valid := pow.ValidatePoW(blockHash, nonce, pow.DefaultDifficulty)Client-side PoW
The web wallet computes proof of work in the browser using blakejs. 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
[!TIP] Server-side fallback The node API also exposes
POST /powfor server-side PoW computation. This is useful for clients that cannot perform the computation locally (e.g., low-power devices).
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
- API Reference --
POST /powendpoint