Consensus/proof_of_work library

Proof of Work (PoW) - production-minded simulation

A compact, auditable PoW miner framework that models the key engineering concerns for production systems: pluggable hash function, target difficulty, deterministic RNG for reproducible tests, mining loop with early exit, and serialization. The implementation is intentionally small, easy to audit, and suitable for unit tests and simulations rather than real cryptographic mining.

Contract:

  • Input: block data (string), difficulty (int, lower => harder), and a hash function that maps (data+nonce) -> int (lower means "better").
  • Output: a MineResult containing nonce, hash and attempts.
  • Errors: throws ArgumentError on invalid difficulty or missing hash.

Classes

MineResult
Result of a mining attempt.
ProofOfWork
Proof-of-Work helper built for deterministic simulation and testing.

Typedefs

BigHash = BigInt Function(String data, int nonce)
Hash function signature returning a BigInt-like value (lower = better).