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:

text
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

#Difficulty constants

ConstantValueExpected attemptsTime (single core)
DefaultDifficulty0xfffff80000000000~2 million~1 second
TestDifficulty0x0000000000000002~1Instant

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.

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

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

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

go
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

#See also