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
MineResultcontainingnonce,hashandattempts. - 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.