-
Notifications
You must be signed in to change notification settings - Fork 94
Fuzz tests for commitment
packages and check in corpus
#305
Comments
Created fuzz test which spotted and exploited just one bug:
sequential trie trace of adding two balance updates:
batch trie trace with same updates:
and hashes they produces:
Deep dive shown that problem is hidden in process of obtaining erigon-lib/commitment/hex_patricia_hashed.go Line 722 in 92fc721
when depth is 0. But from the other hand, seems like hashes of size 65 are expected too. Another suspect is erigon-lib/commitment/hex_patricia_hashed.go Line 1177 in 92fc721
when applying one by one, while update by batch led us to default section of that switch, where correct node hash is evaluated. |
Firstly, hash of length 33 is returned by After I noticed that sequential apply led to different tree due to usage of root node as a leaf. I decided instead of putting first update into root create branch with one leaf - and test on Unique Representation has passed for two updates applied sequentially/by batch. Adding third update to test case led to hash mismatch because sequential insert of third element into a branch changes hash of node inserted right before current, and leaving very first hash unchanged: sequential updateright after second update
right after third update
batch update
As i understand, adding new neighbour should not change old neighbours hash, but change overall branch hash, but maybe i'm wrongly read trace log and that is how it should be. traces
|
Assuming that the implementation of
hex_patricia_hashed
is now correct (it correctly calculates state root for all block up to 5.2m on Ethereum main net so far), we can autogenerate tests for coverage, similar to how it is done in other packages, likepatricia
:erigon-lib/patricia/patricia_fuzz_test.go
Line 27 in 92fc721
The main task is to come with the deserialisation of a string of bytes into input key/value pairs, and apply the logic like this in this test:
erigon-lib/commitment/hex_patricia_hashed_test.go
Line 378 in 92fc721
Then select the corpus of tests that gives a good coverage (fuzz does it automatically) and then convert them into regular tests and assert the result of invocation of
hph.Root()
The text was updated successfully, but these errors were encountered: