-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* less verbose undo test, check roots undone correctly * fuzzing * fuzz in CI
- Loading branch information
Showing
7 changed files
with
200 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//go:build gofuzz | ||
// +build gofuzz | ||
|
||
package accumulator | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"reflect" | ||
) | ||
|
||
func undoOnceFuzzy(data *bytes.Buffer) error { | ||
f := NewForest(RamForest, nil, "", 0) | ||
|
||
seed0, err := data.ReadByte(); | ||
if err != nil { return nil } | ||
seed1, err := data.ReadByte(); | ||
if err != nil { return nil } | ||
seed := (int64(seed1) << 8) | int64(seed0) | ||
sc := newSimChainWithSeed(0x07, seed) | ||
if sc == nil { | ||
return nil | ||
} | ||
sc.lookahead = 0 | ||
for b := int32(0); ; b++ { | ||
numAdds, err := data.ReadByte() | ||
if err != nil { | ||
break | ||
} | ||
numAdds &= 0x1f | ||
|
||
adds, durations, delHashes := sc.NextBlock(uint32(numAdds)) | ||
|
||
bp, err := f.ProveBatch(delHashes) | ||
if err != nil { | ||
return err | ||
} | ||
beforeRoot := f.getRoots() | ||
ub, err := f.Modify(adds, bp.Targets) | ||
if err != nil { | ||
return err | ||
} | ||
err = f.PosMapSanity() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// undo every 3rd block | ||
if b%3 == 2 { | ||
err := f.Undo(*ub) | ||
if err != nil { | ||
return err | ||
} | ||
sc.BackOne(adds, durations, delHashes) | ||
afterRoot := f.getRoots() | ||
if !reflect.DeepEqual(beforeRoot, afterRoot) { | ||
return fmt.Errorf("undo mismatch") | ||
} | ||
} | ||
|
||
} | ||
return nil | ||
} | ||
|
||
func Fuzz(dataBytes []byte) int { | ||
data := bytes.NewBuffer(dataBytes) | ||
|
||
err := undoOnceFuzzy(data) | ||
if err != nil { | ||
panic("failed") | ||
} | ||
return 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters