grin/core/fuzz
hashmap 1f5de6beb9
Verify headers and blocks only when needed (#3023)
* Verify headers and blocks only when needed

Curretnly we have some lightweigt validation implemented as part of
entity deserialization, which is safer and allows us to not parse the
entire object if some part is invalid. At the same time this logic
always applies when we read an entity, eg when reading from DB.

This PR introduces UntrustedHeader/Block which is used when we read from
the network. It does partial validation during read, then it is supposed
to be converted into regular header/block which doesn't validate itself.

Also this PR adds "lightweight" validation to block header read like we have
for block body, so we don't parse block body if the header is invalid.

Fixes #1642

* Move version validation to untrusted header

* update fuzz tests
2019-10-27 08:40:52 +01:00
..
fuzz_targets Verify headers and blocks only when needed (#3023) 2019-10-27 08:40:52 +01:00
src [1.1.0] Bring fuzz test back (#2675) 2019-03-15 15:32:14 +01:00
.gitignore Introduce fuzz tests for core (#844) 2018-03-22 16:53:47 +00:00
Cargo.lock Verify headers and blocks only when needed (#3023) 2019-10-27 08:40:52 +01:00
Cargo.toml Support protocol version 1 and 2 in fuzz targets (#3073) 2019-10-03 09:08:40 +02:00
README.md [1.1.0] Bring fuzz test back (#2675) 2019-03-15 15:32:14 +01:00

Fuzz testing

Installation

You have to use Rust nightly at the moment. Cargo-fuzz (https://github.com/rust-fuzz/cargo-fuzz) has been used. To install it:

cargo install cargo-fuzz

Pattern generation for corpus

This step is optional, libFuzz will generate random patterns to populate corpus (in folder corpus). However we can genearete more meaningful pattern e.g. use serialized form of a real block or transaction. To generate them:

cd fuzz

cargo run --bin  gen-corpus

Run tests

Fuzz test is basically infinite test, run it for some period of time then stop if no failures are found. To run the tests make sure youre in folder core otherwise you may get some misleading errors, then run one of the following tests:

cargo fuzz run transaction_read

cargo fuzz run block_read

cargo fuzz run compact_block_read

Run

cargo fuzz list

or check fuzz/Cargo.toml for the full list of targets.