mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
Fuzz ProcessFinalUpdates (#4308)
This commit is contained in:
parent
30b4b045f5
commit
53b8eb57ee
@ -24,6 +24,7 @@ go_test(
|
||||
name = "go_default_test",
|
||||
size = "small",
|
||||
srcs = [
|
||||
"epoch_processing_fuzz_test.go",
|
||||
"epoch_processing_test.go",
|
||||
"participation_test.go",
|
||||
],
|
||||
@ -34,6 +35,7 @@ go_test(
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_google_gofuzz//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
],
|
||||
|
@ -286,6 +286,12 @@ func ProcessFinalUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
|
||||
|
||||
// Update effective balances with hysteresis.
|
||||
for i, v := range state.Validators {
|
||||
if v == nil {
|
||||
return nil, fmt.Errorf("validator %d is nil in state", i)
|
||||
}
|
||||
if i >= len(state.Balances) {
|
||||
return nil, fmt.Errorf("validator index exceeds validator length in state %d >= %d", i, len(state.Balances))
|
||||
}
|
||||
balance := state.Balances[i]
|
||||
halfInc := params.BeaconConfig().EffectiveBalanceIncrement / 2
|
||||
if balance < v.EffectiveBalance || v.EffectiveBalance+3*halfInc < balance {
|
||||
@ -298,10 +304,17 @@ func ProcessFinalUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
|
||||
|
||||
// Set total slashed balances.
|
||||
slashedExitLength := params.BeaconConfig().EpochsPerSlashingsVector
|
||||
state.Slashings[nextEpoch%slashedExitLength] = 0
|
||||
slashedEpoch := int(nextEpoch % slashedExitLength)
|
||||
if len(state.Slashings) != int(slashedExitLength) {
|
||||
return nil, fmt.Errorf("state slashing length %d different than EpochsPerHistoricalVector %d", len(state.Slashings), slashedExitLength)
|
||||
}
|
||||
state.Slashings[slashedEpoch] = 0
|
||||
|
||||
// Set RANDAO mix.
|
||||
randaoMixLength := params.BeaconConfig().EpochsPerHistoricalVector
|
||||
if len(state.RandaoMixes) != int(randaoMixLength) {
|
||||
return nil, fmt.Errorf("state randao length %d different than EpochsPerHistoricalVector %d", len(state.RandaoMixes), randaoMixLength)
|
||||
}
|
||||
mix := helpers.RandaoMix(state, currentEpoch)
|
||||
state.RandaoMixes[nextEpoch%randaoMixLength] = mix
|
||||
|
||||
|
18
beacon-chain/core/epoch/epoch_processing_fuzz_test.go
Normal file
18
beacon-chain/core/epoch/epoch_processing_fuzz_test.go
Normal file
@ -0,0 +1,18 @@
|
||||
package epoch
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
fuzz "github.com/google/gofuzz"
|
||||
ethereum_beacon_p2p_v1 "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
)
|
||||
|
||||
func TestFuzzFinalUpdates_10000(t *testing.T) {
|
||||
fuzzer := fuzz.NewWithSeed(0)
|
||||
state := ðereum_beacon_p2p_v1.BeaconState{}
|
||||
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
_, _ = ProcessFinalUpdates(state)
|
||||
}
|
||||
}
|
@ -477,11 +477,11 @@ func TestProcessEpochPrecompute_CanProcess(t *testing.T) {
|
||||
epoch := uint64(1)
|
||||
|
||||
atts := []*pb.PendingAttestation{{Data: ðpb.AttestationData{Target: ðpb.Checkpoint{}}}}
|
||||
|
||||
slashing := make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector)
|
||||
newState, err := state.ProcessEpochPrecompute(context.Background(), &pb.BeaconState{
|
||||
Slot: epoch*params.BeaconConfig().SlotsPerEpoch + 1,
|
||||
BlockRoots: make([][]byte, 128),
|
||||
Slashings: []uint64{0, 1e9, 1e9},
|
||||
Slashings: slashing,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
CurrentEpochAttestations: atts,
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{},
|
||||
|
Loading…
Reference in New Issue
Block a user