github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/core/blocks/block_operations_fuzz_test.go (about) 1 package blocks 2 3 import ( 4 "context" 5 "testing" 6 7 fuzz "github.com/google/gofuzz" 8 types "github.com/prysmaticlabs/eth2-types" 9 v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" 10 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" 11 pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" 12 eth "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 13 "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1/wrapper" 14 "github.com/prysmaticlabs/prysm/shared/params" 15 "github.com/prysmaticlabs/prysm/shared/testutil/require" 16 ) 17 18 func TestFuzzProcessAttestationNoVerify_10000(t *testing.T) { 19 fuzzer := fuzz.NewWithSeed(0) 20 ctx := context.Background() 21 state := &pb.BeaconState{} 22 att := ð.Attestation{} 23 24 for i := 0; i < 10000; i++ { 25 fuzzer.Fuzz(state) 26 fuzzer.Fuzz(att) 27 s, err := v1.InitializeFromProtoUnsafe(state) 28 require.NoError(t, err) 29 _, err = ProcessAttestationNoVerifySignature(ctx, s, att) 30 _ = err 31 } 32 } 33 34 func TestFuzzProcessBlockHeader_10000(t *testing.T) { 35 fuzzer := fuzz.NewWithSeed(0) 36 state := &pb.BeaconState{} 37 block := ð.SignedBeaconBlock{} 38 39 for i := 0; i < 10000; i++ { 40 fuzzer.Fuzz(state) 41 fuzzer.Fuzz(block) 42 43 s, err := v1.InitializeFromProtoUnsafe(state) 44 require.NoError(t, err) 45 _, err = ProcessBlockHeader(context.Background(), s, wrapper.WrappedPhase0SignedBeaconBlock(block)) 46 _ = err 47 } 48 } 49 50 func TestFuzzverifyDepositDataSigningRoot_10000(t *testing.T) { 51 fuzzer := fuzz.NewWithSeed(0) 52 var ba []byte 53 pubkey := [48]byte{} 54 sig := [96]byte{} 55 domain := [4]byte{} 56 var p []byte 57 var s []byte 58 var d []byte 59 for i := 0; i < 10000; i++ { 60 fuzzer.Fuzz(&ba) 61 fuzzer.Fuzz(&pubkey) 62 fuzzer.Fuzz(&sig) 63 fuzzer.Fuzz(&domain) 64 fuzzer.Fuzz(&p) 65 fuzzer.Fuzz(&s) 66 fuzzer.Fuzz(&d) 67 err := verifySignature(ba, pubkey[:], sig[:], domain[:]) 68 _ = err 69 err = verifySignature(ba, p, s, d) 70 _ = err 71 } 72 } 73 74 func TestFuzzProcessEth1DataInBlock_10000(t *testing.T) { 75 fuzzer := fuzz.NewWithSeed(0) 76 e := ð.Eth1Data{} 77 state := &v1.BeaconState{} 78 for i := 0; i < 10000; i++ { 79 fuzzer.Fuzz(state) 80 fuzzer.Fuzz(e) 81 s, err := ProcessEth1DataInBlock(context.Background(), state, e) 82 if err != nil && s != nil { 83 t.Fatalf("state should be nil on err. found: %v on error: %v for state: %v and eth1data: %v", s, err, state, e) 84 } 85 } 86 } 87 88 func TestFuzzareEth1DataEqual_10000(t *testing.T) { 89 fuzzer := fuzz.NewWithSeed(0) 90 eth1data := ð.Eth1Data{} 91 eth1data2 := ð.Eth1Data{} 92 93 for i := 0; i < 10000; i++ { 94 fuzzer.Fuzz(eth1data) 95 fuzzer.Fuzz(eth1data2) 96 AreEth1DataEqual(eth1data, eth1data2) 97 AreEth1DataEqual(eth1data, eth1data) 98 } 99 } 100 101 func TestFuzzEth1DataHasEnoughSupport_10000(t *testing.T) { 102 fuzzer := fuzz.NewWithSeed(0) 103 eth1data := ð.Eth1Data{} 104 var stateVotes []*eth.Eth1Data 105 for i := 0; i < 100000; i++ { 106 fuzzer.Fuzz(eth1data) 107 fuzzer.Fuzz(&stateVotes) 108 s, err := v1.InitializeFromProto(&pb.BeaconState{ 109 Eth1DataVotes: stateVotes, 110 }) 111 require.NoError(t, err) 112 _, err = Eth1DataHasEnoughSupport(s, eth1data) 113 _ = err 114 } 115 116 } 117 118 func TestFuzzProcessBlockHeaderNoVerify_10000(t *testing.T) { 119 fuzzer := fuzz.NewWithSeed(0) 120 state := &pb.BeaconState{} 121 block := ð.BeaconBlock{} 122 123 for i := 0; i < 10000; i++ { 124 fuzzer.Fuzz(state) 125 fuzzer.Fuzz(block) 126 s, err := v1.InitializeFromProtoUnsafe(state) 127 require.NoError(t, err) 128 _, err = ProcessBlockHeaderNoVerify(s, block.Slot, block.ProposerIndex, block.ParentRoot, []byte{}) 129 _ = err 130 } 131 } 132 133 func TestFuzzProcessRandao_10000(t *testing.T) { 134 fuzzer := fuzz.NewWithSeed(0) 135 state := &pb.BeaconState{} 136 b := ð.SignedBeaconBlock{} 137 138 for i := 0; i < 10000; i++ { 139 fuzzer.Fuzz(state) 140 fuzzer.Fuzz(b) 141 s, err := v1.InitializeFromProtoUnsafe(state) 142 require.NoError(t, err) 143 r, err := ProcessRandao(context.Background(), s, wrapper.WrappedPhase0SignedBeaconBlock(b)) 144 if err != nil && r != nil { 145 t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, b) 146 } 147 } 148 } 149 150 func TestFuzzProcessRandaoNoVerify_10000(t *testing.T) { 151 fuzzer := fuzz.NewWithSeed(0) 152 state := &pb.BeaconState{} 153 blockBody := ð.BeaconBlockBody{} 154 155 for i := 0; i < 10000; i++ { 156 fuzzer.Fuzz(state) 157 fuzzer.Fuzz(blockBody) 158 s, err := v1.InitializeFromProtoUnsafe(state) 159 require.NoError(t, err) 160 r, err := ProcessRandaoNoVerify(s, blockBody.RandaoReveal) 161 if err != nil && r != nil { 162 t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, blockBody) 163 } 164 } 165 } 166 167 func TestFuzzProcessProposerSlashings_10000(t *testing.T) { 168 fuzzer := fuzz.NewWithSeed(0) 169 state := &pb.BeaconState{} 170 p := ð.ProposerSlashing{} 171 ctx := context.Background() 172 for i := 0; i < 10000; i++ { 173 fuzzer.Fuzz(state) 174 fuzzer.Fuzz(p) 175 s, err := v1.InitializeFromProtoUnsafe(state) 176 require.NoError(t, err) 177 r, err := ProcessProposerSlashings(ctx, s, []*eth.ProposerSlashing{p}, v.SlashValidator) 178 if err != nil && r != nil { 179 t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and slashing: %v", r, err, state, p) 180 } 181 } 182 } 183 184 func TestFuzzVerifyProposerSlashing_10000(t *testing.T) { 185 fuzzer := fuzz.NewWithSeed(0) 186 state := &pb.BeaconState{} 187 proposerSlashing := ð.ProposerSlashing{} 188 for i := 0; i < 10000; i++ { 189 fuzzer.Fuzz(state) 190 fuzzer.Fuzz(proposerSlashing) 191 s, err := v1.InitializeFromProtoUnsafe(state) 192 require.NoError(t, err) 193 err = VerifyProposerSlashing(s, proposerSlashing) 194 _ = err 195 } 196 } 197 198 func TestFuzzProcessAttesterSlashings_10000(t *testing.T) { 199 fuzzer := fuzz.NewWithSeed(0) 200 state := &pb.BeaconState{} 201 a := ð.AttesterSlashing{} 202 ctx := context.Background() 203 for i := 0; i < 10000; i++ { 204 fuzzer.Fuzz(state) 205 fuzzer.Fuzz(a) 206 s, err := v1.InitializeFromProtoUnsafe(state) 207 require.NoError(t, err) 208 r, err := ProcessAttesterSlashings(ctx, s, []*eth.AttesterSlashing{a}, v.SlashValidator) 209 if err != nil && r != nil { 210 t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and slashing: %v", r, err, state, a) 211 } 212 } 213 } 214 215 func TestFuzzVerifyAttesterSlashing_10000(t *testing.T) { 216 fuzzer := fuzz.NewWithSeed(0) 217 state := &pb.BeaconState{} 218 attesterSlashing := ð.AttesterSlashing{} 219 ctx := context.Background() 220 for i := 0; i < 10000; i++ { 221 fuzzer.Fuzz(state) 222 fuzzer.Fuzz(attesterSlashing) 223 s, err := v1.InitializeFromProtoUnsafe(state) 224 require.NoError(t, err) 225 err = VerifyAttesterSlashing(ctx, s, attesterSlashing) 226 _ = err 227 } 228 } 229 230 func TestFuzzIsSlashableAttestationData_10000(t *testing.T) { 231 fuzzer := fuzz.NewWithSeed(0) 232 attestationData := ð.AttestationData{} 233 attestationData2 := ð.AttestationData{} 234 235 for i := 0; i < 10000; i++ { 236 fuzzer.Fuzz(attestationData) 237 fuzzer.Fuzz(attestationData2) 238 IsSlashableAttestationData(attestationData, attestationData2) 239 } 240 } 241 242 func TestFuzzslashableAttesterIndices_10000(t *testing.T) { 243 fuzzer := fuzz.NewWithSeed(0) 244 attesterSlashing := ð.AttesterSlashing{} 245 246 for i := 0; i < 10000; i++ { 247 fuzzer.Fuzz(attesterSlashing) 248 slashableAttesterIndices(attesterSlashing) 249 } 250 } 251 252 func TestFuzzProcessAttestations_10000(t *testing.T) { 253 fuzzer := fuzz.NewWithSeed(0) 254 state := &pb.BeaconState{} 255 b := ð.SignedBeaconBlock{} 256 ctx := context.Background() 257 for i := 0; i < 10000; i++ { 258 fuzzer.Fuzz(state) 259 fuzzer.Fuzz(b) 260 s, err := v1.InitializeFromProtoUnsafe(state) 261 require.NoError(t, err) 262 r, err := ProcessAttestations(ctx, s, wrapper.WrappedPhase0SignedBeaconBlock(b)) 263 if err != nil && r != nil { 264 t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, b) 265 } 266 } 267 } 268 269 func TestFuzzProcessAttestationsNoVerify_10000(t *testing.T) { 270 fuzzer := fuzz.NewWithSeed(0) 271 state := &pb.BeaconState{} 272 b := ð.SignedBeaconBlock{} 273 ctx := context.Background() 274 for i := 0; i < 10000; i++ { 275 fuzzer.Fuzz(state) 276 fuzzer.Fuzz(b) 277 s, err := v1.InitializeFromProtoUnsafe(state) 278 require.NoError(t, err) 279 r, err := ProcessAttestationsNoVerifySignature(ctx, s, wrapper.WrappedPhase0SignedBeaconBlock(b)) 280 if err != nil && r != nil { 281 t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, b) 282 } 283 } 284 } 285 286 func TestFuzzProcessAttestation_10000(t *testing.T) { 287 fuzzer := fuzz.NewWithSeed(0) 288 state := &pb.BeaconState{} 289 attestation := ð.Attestation{} 290 ctx := context.Background() 291 for i := 0; i < 10000; i++ { 292 fuzzer.Fuzz(state) 293 fuzzer.Fuzz(attestation) 294 s, err := v1.InitializeFromProtoUnsafe(state) 295 require.NoError(t, err) 296 r, err := ProcessAttestation(ctx, s, attestation) 297 if err != nil && r != nil { 298 t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, attestation) 299 } 300 } 301 } 302 303 func TestFuzzVerifyIndexedAttestationn_10000(t *testing.T) { 304 fuzzer := fuzz.NewWithSeed(0) 305 state := &pb.BeaconState{} 306 idxAttestation := ð.IndexedAttestation{} 307 ctx := context.Background() 308 for i := 0; i < 10000; i++ { 309 fuzzer.Fuzz(state) 310 fuzzer.Fuzz(idxAttestation) 311 s, err := v1.InitializeFromProtoUnsafe(state) 312 require.NoError(t, err) 313 err = VerifyIndexedAttestation(ctx, s, idxAttestation) 314 _ = err 315 } 316 } 317 318 func TestFuzzVerifyAttestation_10000(t *testing.T) { 319 fuzzer := fuzz.NewWithSeed(0) 320 state := &pb.BeaconState{} 321 attestation := ð.Attestation{} 322 ctx := context.Background() 323 for i := 0; i < 10000; i++ { 324 fuzzer.Fuzz(state) 325 fuzzer.Fuzz(attestation) 326 s, err := v1.InitializeFromProtoUnsafe(state) 327 require.NoError(t, err) 328 err = VerifyAttestationSignature(ctx, s, attestation) 329 _ = err 330 } 331 } 332 333 func TestFuzzProcessDeposits_10000(t *testing.T) { 334 fuzzer := fuzz.NewWithSeed(0) 335 state := &pb.BeaconState{} 336 deposits := make([]*eth.Deposit, 100) 337 ctx := context.Background() 338 for i := 0; i < 10000; i++ { 339 fuzzer.Fuzz(state) 340 for i := range deposits { 341 fuzzer.Fuzz(deposits[i]) 342 } 343 s, err := v1.InitializeFromProtoUnsafe(state) 344 require.NoError(t, err) 345 r, err := ProcessDeposits(ctx, s, deposits) 346 if err != nil && r != nil { 347 t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, deposits) 348 } 349 } 350 } 351 352 func TestFuzzProcessPreGenesisDeposit_10000(t *testing.T) { 353 fuzzer := fuzz.NewWithSeed(0) 354 state := &pb.BeaconState{} 355 deposit := ð.Deposit{} 356 ctx := context.Background() 357 358 for i := 0; i < 10000; i++ { 359 fuzzer.Fuzz(state) 360 fuzzer.Fuzz(deposit) 361 s, err := v1.InitializeFromProtoUnsafe(state) 362 require.NoError(t, err) 363 r, err := ProcessPreGenesisDeposits(ctx, s, []*eth.Deposit{deposit}) 364 if err != nil && r != nil { 365 t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, deposit) 366 } 367 } 368 } 369 370 func TestFuzzProcessDeposit_10000(t *testing.T) { 371 fuzzer := fuzz.NewWithSeed(0) 372 state := &pb.BeaconState{} 373 deposit := ð.Deposit{} 374 375 for i := 0; i < 10000; i++ { 376 fuzzer.Fuzz(state) 377 fuzzer.Fuzz(deposit) 378 s, err := v1.InitializeFromProtoUnsafe(state) 379 require.NoError(t, err) 380 r, err := ProcessDeposit(s, deposit, true) 381 if err != nil && r != nil { 382 t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, deposit) 383 } 384 } 385 } 386 387 func TestFuzzverifyDeposit_10000(t *testing.T) { 388 fuzzer := fuzz.NewWithSeed(0) 389 state := &pb.BeaconState{} 390 deposit := ð.Deposit{} 391 for i := 0; i < 10000; i++ { 392 fuzzer.Fuzz(state) 393 fuzzer.Fuzz(deposit) 394 s, err := v1.InitializeFromProtoUnsafe(state) 395 require.NoError(t, err) 396 err = verifyDeposit(s, deposit) 397 _ = err 398 } 399 } 400 401 func TestFuzzProcessVoluntaryExits_10000(t *testing.T) { 402 fuzzer := fuzz.NewWithSeed(0) 403 state := &pb.BeaconState{} 404 e := ð.SignedVoluntaryExit{} 405 ctx := context.Background() 406 for i := 0; i < 10000; i++ { 407 fuzzer.Fuzz(state) 408 fuzzer.Fuzz(e) 409 s, err := v1.InitializeFromProtoUnsafe(state) 410 require.NoError(t, err) 411 r, err := ProcessVoluntaryExits(ctx, s, []*eth.SignedVoluntaryExit{e}) 412 if err != nil && r != nil { 413 t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and exit: %v", r, err, state, e) 414 } 415 } 416 } 417 418 func TestFuzzProcessVoluntaryExitsNoVerify_10000(t *testing.T) { 419 fuzzer := fuzz.NewWithSeed(0) 420 state := &pb.BeaconState{} 421 e := ð.SignedVoluntaryExit{} 422 for i := 0; i < 10000; i++ { 423 fuzzer.Fuzz(state) 424 fuzzer.Fuzz(e) 425 s, err := v1.InitializeFromProtoUnsafe(state) 426 require.NoError(t, err) 427 r, err := ProcessVoluntaryExits(context.Background(), s, []*eth.SignedVoluntaryExit{e}) 428 if err != nil && r != nil { 429 t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, e) 430 } 431 } 432 } 433 434 func TestFuzzVerifyExit_10000(t *testing.T) { 435 fuzzer := fuzz.NewWithSeed(0) 436 ve := ð.SignedVoluntaryExit{} 437 val := v1.ReadOnlyValidator{} 438 fork := &pb.Fork{} 439 var slot types.Slot 440 441 for i := 0; i < 10000; i++ { 442 fuzzer.Fuzz(ve) 443 fuzzer.Fuzz(&val) 444 fuzzer.Fuzz(fork) 445 fuzzer.Fuzz(&slot) 446 err := VerifyExitAndSignature(val, slot, fork, ve, params.BeaconConfig().ZeroHash[:]) 447 _ = err 448 } 449 }