Crates.io | blake3-proof-of-work |
lib.rs | blake3-proof-of-work |
version | 0.2.1 |
source | src |
created_at | 2022-01-17 05:12:57.420724 |
updated_at | 2022-01-17 07:25:03.521532 |
description | A basic proof of work scheme using the blake3 hash function |
homepage | |
repository | https://github.com/samuelSchlesinger/proof-of-work |
max_upload_size | |
id | 515302 |
size | 7,006 |
A simple proof of work algorithm using the Blake3 cryptographic hash function.
let cost = 22;
let bytes = b"Hello, world!";
let meter = 10000000;
let nonce = proof_of_work::search(bytes, cost, meter);
assert!(proof_of_work::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 nonce
s until
we guess one which constitutes a proof of work. That is to say, we randomly
guess until we get it right. Given that this could go on forever, we pass in a
meter : u32
in order to stop after a certain number of attempts.
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.