near / nearcore

Reference client for NEAR Protocol
https://near.org
GNU General Public License v3.0
2.32k stars 619 forks source link

Fuzzing the entire runtime #4374

Closed matklad closed 2 years ago

matklad commented 3 years ago

[OKR 2021Q4] At a high level, our runtime is a pure function which takes some state, a bunch of actions, interprets those actions and returns a new state. We also care a lot about runtime being correct even in the phase of adversary inputs. So it behooves us to implement fuzzing of the runtime. This article (and it's bibliography) give a good overview of state of the art fuzzing in Rust: https://fitzgeraldnick.com/2020/08/24/writing-a-test-case-generator.html.

The TL;DR is that the best approach is structured, coverage guided fuzzing. We use something like libfuzzer to generate random inputs &[u8], then we use this input as a seed to generate a random sequence of valid actions, then we feed this input into the runtime. The fuzzer then observes code coverage as the runtime executes the input, and uses that info to generate better seeds to cover more of the branches, and to minimize failures for free.

Practically, that means that we should:

bowenwang1996 commented 3 years ago

Regarding fuzz testing function calls, I think we should focus on the following:

posvyatokum commented 3 years ago

Pushed more code to #4546 Right now switching to #4550 to run current fuzzer in CI