2 stable releases

Uses new Rust 2024

new 1.0.1 Mar 20, 2025
1.0.0 Feb 10, 2025

#208 in HTTP client

Download history 95/week @ 2025-02-07 51/week @ 2025-02-14 47/week @ 2025-02-21 10/week @ 2025-02-28

113 downloads per month
Used in kkv

MIT/Apache

11KB
50 lines

Proof of Work

crates.io github docs.rs

Fork from Samuel Schlesinger repository for the kkv project.

A proof of work algorithm using the Blake3 cryptographic hash function.

let cost = 20;
let bytes = b"Hello, world!";
// client side
let nonce = blake3_pow::search(bytes, cost)?;
// server side
assert!(blake3_pow::verify(bytes, nonce, cost));

The main point is: we present some bytes and we say that a "proof of work" for some cost is a nonce : [u8; NONCE_SIZE] such that the hash of nonce concatenated to bytes has cost leading zeros.

To verify such a proof, we compute the hash and check if it has cost leading zeros. To search for such a proof, we continually generate random nonces until we guess one which constitutes a proof of work. That is to say, we randomly guess until we get it right.

Use Cases

When you want to expose functionality to the outside world without allowing bots to take advantage of it at any frequency, you must meter usage somehow. By requesting that API calls come affixed with a proof of costly work associated with the particular request, you can acheive this in a stateless way.

Why Blake3?

  • Efficient on consumer hardware
  • No known ASIC implementations
  • Awesome team behind it
  • Inverting seems incredibly hard to me, though that hardly counts as a security review

Examples

git clone https://gitlab.com/mateolafalce/blake3-pow.git
cd blake3-pow
cargo run --example http_pow

References

Dependencies

~3MB
~66K SLoC