### 3 unstable releases

Uses new Rust 2021

0.2.1 | Jan 17, 2022 |
---|---|

0.2.0 | Jan 17, 2022 |

0.1.0 | Jan 17, 2022 |

#**896** in Cryptography

**MIT/Apache**

7KB

89 lines

# Proof of Work

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

and we say that a "proof of work"
for some `bytes`

is a `cost`

such that the hash of `nonce : [u8; NONCE_SIZE]`

`nonce`

concatenated to `bytes`

has `cost`

leading zeros.To

such a proof, we compute the hash and check if it has `verify`

leading
zeros. To `cost`

for such a proof, we continually generate random `search`

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
`nonce`

in order to stop after a certain number of attempts.`meter : u32`

## 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

## References

#### Dependencies

~2MB

~44K SLoC