This is a library meant to take care of the repetitive tasks of spinning up threads, checking if the computation is finished, returning the result, and even generating the inputs. The adaptor system allows you to compose different helpers in a modular way, as not all brute forcing is as simple as proof of work. The common assumption of this library is that each thread will be working off a state to be the first to find a result, and the computation will end once a result is found.
```rust use bruteforce::{bruteforce, adaptors}; use blake2::{Blake2b, Digest};
fn testproofofwork() { let config = bruteforce::Config::default(); let f = |nonce: &u64| { let digest = Blake2b::digest(&nonce.tolebytes()); digest.asslice()[..3] == [0; 3] }; let nonce = bruteforce(config, adaptors::outputinput(adaptors::autoadvance(f))); let digest = Blake2b::digest(&nonce.tolebytes()); assert!(digest.as_slice()[..3] == [0; 3]) } ```
Here, we use the auto_advance
adaptor to automatically generate nonces for us,
and we use the output_input
adaptor to automatically return the input nonce
used if a computation succeeds (instead of manually specifying the output).
For more examples, see the src/tests directory. For documentation on the config or adaptors, see the docs.