forked from prysmaticlabs/prysm
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fuzzing core/state package without skip slot cache (prysmaticlabs#4883)
* fuzzing core/state package * named error msg * err comment * terence feedback * preston feedback * preston feedback Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8f03a76
commit df2e59e
Showing
10 changed files
with
488 additions
and
6 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
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,60 @@ | ||
package state | ||
|
||
import ( | ||
"testing" | ||
|
||
fuzz "github.com/google/gofuzz" | ||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" | ||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" | ||
) | ||
|
||
func TestGenesisBeaconState_1000(t *testing.T) { | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
deposits := make([]*ethpb.Deposit, 300000) | ||
var genesisTime uint64 | ||
eth1Data := ðpb.Eth1Data{} | ||
for i := 0; i < 1000; i++ { | ||
fuzzer.Fuzz(&deposits) | ||
fuzzer.Fuzz(&genesisTime) | ||
fuzzer.Fuzz(eth1Data) | ||
gs, err := GenesisBeaconState(deposits, genesisTime, eth1Data) | ||
if err != nil { | ||
if gs != nil { | ||
t.Fatalf("Genesis state should be nil on err. found: %v on error: %v for inputs deposit: %v "+ | ||
"genesis time: %v eth1data: %v", gs, err, deposits, genesisTime, eth1Data) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func TestOptimizedGenesisBeaconState_1000(t *testing.T) { | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
var genesisTime uint64 | ||
preState := &stateTrie.BeaconState{} | ||
eth1Data := ðpb.Eth1Data{} | ||
for i := 0; i < 1000; i++ { | ||
fuzzer.Fuzz(&genesisTime) | ||
fuzzer.Fuzz(eth1Data) | ||
fuzzer.Fuzz(preState) | ||
gs, err := OptimizedGenesisBeaconState(genesisTime, preState, eth1Data) | ||
if err != nil { | ||
if gs != nil { | ||
t.Fatalf("Genesis state should be nil on err. found: %v on error: %v for inputs genesis time: %v "+ | ||
"pre state: %v eth1data: %v", gs, err, genesisTime, preState, eth1Data) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func TestIsValidGenesisState_100000(t *testing.T) { | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
var chainStartDepositCount, currentTime uint64 | ||
for i := 0; i < 100000; i++ { | ||
fuzzer.Fuzz(&chainStartDepositCount) | ||
fuzzer.Fuzz(¤tTime) | ||
IsValidGenesisState(chainStartDepositCount, currentTime) | ||
} | ||
} |
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,204 @@ | ||
package state | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
fuzz "github.com/google/gofuzz" | ||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" | ||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" | ||
) | ||
|
||
func TestFuzzExecuteStateTransition_1000(t *testing.T) { | ||
ctx := context.Background() | ||
state := &stateTrie.BeaconState{} | ||
sb := ðpb.SignedBeaconBlock{} | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
for i := 0; i < 1000; i++ { | ||
fuzzer.Fuzz(state) | ||
fuzzer.Fuzz(sb) | ||
s, err := ExecuteStateTransition(ctx, state, sb) | ||
if err != nil && s != nil { | ||
t.Fatalf("state should be nil on err. found: %v on error: %v for state: %v and signed block: %v", s, err, state, sb) | ||
} | ||
} | ||
} | ||
|
||
func TestFuzzExecuteStateTransitionNoVerifyAttSigs_1000(t *testing.T) { | ||
ctx := context.Background() | ||
state := &stateTrie.BeaconState{} | ||
sb := ðpb.SignedBeaconBlock{} | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
for i := 0; i < 1000; i++ { | ||
fuzzer.Fuzz(state) | ||
fuzzer.Fuzz(sb) | ||
s, err := ExecuteStateTransitionNoVerifyAttSigs(ctx, state, sb) | ||
if err != nil && s != nil { | ||
t.Fatalf("state should be nil on err. found: %v on error: %v for state: %v and signed block: %v", s, err, state, sb) | ||
} | ||
} | ||
} | ||
|
||
func TestFuzzCalculateStateRoot_1000(t *testing.T) { | ||
ctx := context.Background() | ||
state := &stateTrie.BeaconState{} | ||
sb := ðpb.SignedBeaconBlock{} | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
for i := 0; i < 1000; i++ { | ||
fuzzer.Fuzz(state) | ||
fuzzer.Fuzz(sb) | ||
stateRoot, err := CalculateStateRoot(ctx, state, sb) | ||
if err != nil && stateRoot != [32]byte{} { | ||
t.Fatalf("state root should be empty on err. found: %v on error: %v for signed block: %v", stateRoot, err, sb) | ||
} | ||
} | ||
} | ||
|
||
func TestFuzzProcessSlot_1000(t *testing.T) { | ||
ctx := context.Background() | ||
state := &stateTrie.BeaconState{} | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
for i := 0; i < 1000; i++ { | ||
fuzzer.Fuzz(state) | ||
s, err := ProcessSlot(ctx, state) | ||
if err != nil && s != nil { | ||
t.Fatalf("state should be nil on err. found: %v on error: %v for state: %v", s, err, state) | ||
} | ||
} | ||
} | ||
|
||
func TestFuzzProcessSlots_1000(t *testing.T) { | ||
ctx := context.Background() | ||
state := &stateTrie.BeaconState{} | ||
slot := uint64(0) | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
for i := 0; i < 1000; i++ { | ||
fuzzer.Fuzz(state) | ||
fuzzer.Fuzz(&slot) | ||
s, err := ProcessSlots(ctx, state, slot) | ||
if err != nil && s != nil { | ||
t.Fatalf("state should be nil on err. found: %v on error: %v for state: %v", s, err, state) | ||
} | ||
} | ||
} | ||
|
||
func TestFuzzProcessBlock_1000(t *testing.T) { | ||
ctx := context.Background() | ||
state := &stateTrie.BeaconState{} | ||
sb := ðpb.SignedBeaconBlock{} | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
for i := 0; i < 1000; i++ { | ||
fuzzer.Fuzz(state) | ||
fuzzer.Fuzz(sb) | ||
s, err := ProcessBlock(ctx, state, sb) | ||
if err != nil && s != nil { | ||
t.Fatalf("state should be nil on err. found: %v on error: %v for signed block: %v", s, err, sb) | ||
} | ||
} | ||
} | ||
|
||
func TestFuzzProcessBlockNoVerifyAttSigs_1000(t *testing.T) { | ||
ctx := context.Background() | ||
state := &stateTrie.BeaconState{} | ||
sb := ðpb.SignedBeaconBlock{} | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
for i := 0; i < 1000; i++ { | ||
fuzzer.Fuzz(state) | ||
fuzzer.Fuzz(sb) | ||
s, err := ProcessBlockNoVerifyAttSigs(ctx, state, sb) | ||
if err != nil && s != nil { | ||
t.Fatalf("state should be nil on err. found: %v on error: %v for signed block: %v", s, err, sb) | ||
} | ||
} | ||
} | ||
|
||
func TestFuzzProcessOperations_1000(t *testing.T) { | ||
ctx := context.Background() | ||
state := &stateTrie.BeaconState{} | ||
bb := ðpb.BeaconBlockBody{} | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
for i := 0; i < 1000; i++ { | ||
fuzzer.Fuzz(state) | ||
fuzzer.Fuzz(bb) | ||
s, err := ProcessOperations(ctx, state, bb) | ||
if err != nil && s != nil { | ||
t.Fatalf("state should be nil on err. found: %v on error: %v for block body: %v", s, err, bb) | ||
} | ||
} | ||
} | ||
|
||
func TestFuzzprocessOperationsNoVerify_1000(t *testing.T) { | ||
ctx := context.Background() | ||
state := &stateTrie.BeaconState{} | ||
bb := ðpb.BeaconBlockBody{} | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
for i := 0; i < 1000; i++ { | ||
fuzzer.Fuzz(state) | ||
fuzzer.Fuzz(bb) | ||
s, err := processOperationsNoVerify(ctx, state, bb) | ||
if err != nil && s != nil { | ||
t.Fatalf("state should be nil on err. found: %v on error: %v for block body: %v", s, err, bb) | ||
} | ||
} | ||
} | ||
|
||
func TestFuzzverifyOperationLengths_10000(t *testing.T) { | ||
state := &stateTrie.BeaconState{} | ||
bb := ðpb.BeaconBlockBody{} | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
for i := 0; i < 10000; i++ { | ||
fuzzer.Fuzz(state) | ||
fuzzer.Fuzz(bb) | ||
verifyOperationLengths(state, bb) | ||
} | ||
} | ||
|
||
func TestFuzzCanProcessEpoch_10000(t *testing.T) { | ||
state := &stateTrie.BeaconState{} | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
for i := 0; i < 10000; i++ { | ||
fuzzer.Fuzz(state) | ||
CanProcessEpoch(state) | ||
} | ||
} | ||
|
||
func TestFuzzProcessEpochPrecompute_1000(t *testing.T) { | ||
ctx := context.Background() | ||
state := &stateTrie.BeaconState{} | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
for i := 0; i < 1000; i++ { | ||
fuzzer.Fuzz(state) | ||
s, err := ProcessEpochPrecompute(ctx, state) | ||
if err != nil && s != nil { | ||
t.Fatalf("state should be nil on err. found: %v on error: %v for state: %v", s, err, state) | ||
} | ||
} | ||
} | ||
|
||
func TestFuzzcomputeStateRoot_1000(t *testing.T) { | ||
ctx := context.Background() | ||
state := &stateTrie.BeaconState{} | ||
sb := ðpb.SignedBeaconBlock{} | ||
fuzzer := fuzz.NewWithSeed(0) | ||
fuzzer.NilChance(0.1) | ||
for i := 0; i < 1000; i++ { | ||
fuzzer.Fuzz(state) | ||
fuzzer.Fuzz(sb) | ||
s, err := computeStateRoot(ctx, state, sb) | ||
if err != nil && s != nil { | ||
t.Fatalf("state should be nil on err. found: %v on error: %v for signed block: %v", s, err, sb) | ||
} | ||
} | ||
} |
Oops, something went wrong.