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)
  1. Encode the nonce as an 8-byte little-endian uint64
  2. Concatenate nonce_LE || blockHash (hex-decoded block hash)
  3. Compute Blake2b with an 8-byte output
  4. Interpret the result as a big-endian uint64
  5. 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:

  1. Encode nonce as 8-byte little-endian
  2. Concatenate with hex-decoded block hash
  3. Blake2b with 8-byte output
  4. Compare as big-endian uint64

[!TIP] Server-side fallback The node API also exposes POST /pow for server-side PoW computation. This is useful for clients that cannot perform the computation locally (e.g., low-power devices).

See also