-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathrandom.go
87 lines (79 loc) · 1.79 KB
/
random.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package txfuzz
import (
"crypto/ecdsa"
"crypto/rand"
"fmt"
mathRand "math/rand"
"github.com/MariusVanDerWijden/FuzzyVM/filler"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
)
const (
maxDataPerTx = 1 << 17 // 128Kb
)
func randomHash() common.Hash {
b := make([]byte, 32)
_, err := rand.Read(b)
if err != nil {
panic(err)
}
return common.BytesToHash(b)
}
func randomAddress() common.Address {
switch mathRand.Int31n(8) {
case 0, 1, 2:
b := make([]byte, 20)
_, err := rand.Read(b)
if err != nil {
panic(err)
}
return common.BytesToAddress(b)
case 3:
return common.Address{}
case 4:
return common.HexToAddress(ADDR)
case 5:
return params.BeaconRootsAddress
case 6:
return params.WithdrawalQueueAddress
case 7:
return params.ConsolidationQueueAddress
case 8:
return params.SystemAddress
case 9:
return params.HistoryStorageAddress
}
return common.Address{}
}
func randomBlobData() ([]byte, error) {
size := mathRand.Intn(maxDataPerTx)
data := make([]byte, size)
n, err := rand.Read(data)
if err != nil {
return nil, err
}
if n != size {
return nil, fmt.Errorf("could not create random blob data with size %d: %v", size, err)
}
return data, nil
}
func randomAuthEntry(f *filler.Filler) *types.Authorization {
return &types.Authorization{
ChainID: f.Uint64(),
Address: randomAddress(),
Nonce: f.Uint64(),
}
}
func RandomAuthList(f *filler.Filler, sk *ecdsa.PrivateKey) (types.AuthorizationList, error) {
var authList types.AuthorizationList
entries := f.MemInt()
for i := 0; i < int(entries.Uint64()); i++ {
signed, err := types.SignAuth(randomAuthEntry(f), sk)
if err != nil {
return nil, err
}
authList = append(authList, signed)
}
return authList, nil
}