Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cleanup] Initial documentation improvements and code cleanup #8

Merged
merged 35 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
11458c2
Update readme and godoc comments
h5law May 24, 2023
8b80a0c
Update README
h5law May 24, 2023
f315383
Update README.md
h5law May 25, 2023
0e5d4d0
Update workflow file
h5law May 25, 2023
db8d51b
Update fuzz workflow
h5law May 25, 2023
0cc5f71
Fix workflow
h5law May 25, 2023
3a72bcf
Update workflow name
h5law May 25, 2023
eb1d684
Address linter errors
h5law May 25, 2023
ad3f7c1
Add coverage file to codecov upload
h5law May 25, 2023
de15fba
Merge branch 'main' into documentation_cleanup
h5law May 25, 2023
671b17e
Update reviewpad workflows to remove unneeded jobs
h5law May 25, 2023
c3bb4f2
Remove executable permissions as for remote build on oss-fuzz
h5law May 25, 2023
5d396be
Change if statements in test workflow jobs
h5law May 25, 2023
1951c99
Revert if statement changes
h5law May 25, 2023
d663d97
Add missing env var to workflow
h5law May 25, 2023
c2882dc
Panic on errors in fuzz tests
h5law May 25, 2023
da85b29
Check for unknown errors in fuzzes only
h5law May 25, 2023
32a3085
Remove uneeded field call
h5law May 25, 2023
22c938b
Remove legacy fuzzes with go native fuzz, remove OSS-Fuzz build scrip…
h5law May 25, 2023
1d2fb80
Add comments to fuzz test and check root hash is behaving appropriate…
h5law May 26, 2023
ed8f9d7
Fix codecov upload file format
h5law May 28, 2023
353c30f
Revert to nil pointer interface implementation as this is the go idio…
h5law May 28, 2023
887969c
Update fuzz_test.go
h5law May 30, 2023
6e6d543
Update smt.go
h5law May 30, 2023
2f16a8b
Update fuzz_test.go
h5law May 30, 2023
b16f0f9
Update fuzz_test.go
h5law May 30, 2023
9538bba
Clarify comment
h5law May 30, 2023
cfada84
Add more explanations aroud node types, paths, hashers and digests
h5law May 30, 2023
7403924
Add line break between note
h5law May 30, 2023
5581c04
Clarify node storage
h5law May 30, 2023
91efe8f
Update workflow to use go 1.18
h5law May 31, 2023
0965b0a
Add PR Template file
h5law May 31, 2023
0931fa5
Add go report card and change workflow title
h5law May 31, 2023
51acc15
Update README.md
h5law Jun 1, 2023
86b4235
Add path visualisation
h5law Jun 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions .github/workflows/fuzz_build.yml

This file was deleted.

41 changes: 0 additions & 41 deletions fuzz/delete/fuzz.go

This file was deleted.

87 changes: 0 additions & 87 deletions fuzz/fuzz.go

This file was deleted.

103 changes: 103 additions & 0 deletions fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package smt

import (
"bytes"
"crypto/sha256"
"encoding/binary"
"math"
"testing"

"github.com/stretchr/testify/require"
)

func FuzzSMT(f *testing.F) {
h5law marked this conversation as resolved.
Show resolved Hide resolved
seeds := [][]byte{
[]byte(""),
[]byte("foo"),
{1, 2, 3, 4},
[]byte("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"),
nil,
}
for _, s := range seeds {
f.Add(s)
}
f.Fuzz(func(t *testing.T, input []byte) {
t.Log(input)
smn := NewSimpleMap()
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
tree := NewSparseMerkleTree(smn, sha256.New())

r := bytes.NewReader(input)
var keys [][]byte
key := func() []byte {
h5law marked this conversation as resolved.
Show resolved Hide resolved
if readByte(r) < math.MaxUint8/2 {
h5law marked this conversation as resolved.
Show resolved Hide resolved
k := make([]byte, readByte(r)/2)
if _, err := r.Read(k); err != nil {
return nil
}
keys = append(keys, k)
return k
}

if len(keys) == 0 {
return nil
}

return keys[int(readByte(r))%len(keys)]
}

for i := 0; r.Len() != 0; i++ {
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
h5law marked this conversation as resolved.
Show resolved Hide resolved
b, err := r.ReadByte()
if err != nil {
continue
}

op := op(int(b) % int(Noop))
switch op {
case Get:
_, err := tree.Get(key())
if err != nil {
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
require.ErrorIsf(t, err, ErrKeyNotPresent, "unknown error occured while getting")
}
case Update:
value := make([]byte, 32)
binary.BigEndian.PutUint64(value, uint64(i))
err := tree.Update(key(), value)
if err != nil {
require.ErrorIsf(t, err, ErrKeyNotPresent, "unknown error occured while updating")
}
case Delete:
err := tree.Delete(key())
if err != nil {
require.ErrorIsf(t, err, ErrKeyNotPresent, "unknown error occured while deleting")
}
case Prove:
_, err := tree.Prove(key())
if err != nil {
require.ErrorIsf(t, err, ErrKeyNotPresent, "unknown error occured while proving")
}
}

newRoot := tree.Root()
require.Greater(t, len(newRoot), 0, "new root is empty while err is nil")
h5law marked this conversation as resolved.
Show resolved Hide resolved
}
})
}

// Fuzzing helpers
type op int

const (
Get op = iota
Update
Delete
Prove
Noop
h5law marked this conversation as resolved.
Show resolved Hide resolved
)

func readByte(r *bytes.Reader) byte {
b, err := r.ReadByte()
if err != nil {
return 0
}
return b
}
6 changes: 0 additions & 6 deletions oss-fuzz-build.sh

This file was deleted.

2 changes: 1 addition & 1 deletion smt_testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (smt *SMTWithStorage) Delete(key []byte) error {

// Get gets the value of a key from the tree.
func (smt *SMTWithStorage) GetValue(key []byte) ([]byte, error) {
valueHash, err := smt.SMT.Get(key)
valueHash, err := smt.Get(key)
if err != nil {
return nil, err
}
Expand Down