-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathrandom.go
More file actions
88 lines (80 loc) · 1.86 KB
/
random.go
File metadata and controls
88 lines (80 loc) · 1.86 KB
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
88
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"
"github.com/holiman/uint256"
)
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.SetCodeAuthorization {
return types.SetCodeAuthorization{
ChainID: *uint256.NewInt(f.Uint64()),
Address: randomAddress(),
Nonce: f.Uint64(),
}
}
func RandomAuthList(f *filler.Filler, sk *ecdsa.PrivateKey) ([]types.SetCodeAuthorization, error) {
var authList []types.SetCodeAuthorization
entries := f.MemInt()
for i := 0; i < int(entries.Uint64()); i++ {
signed, err := types.SignSetCode(sk, randomAuthEntry(f))
if err != nil {
return nil, err
}
authList = append(authList, signed)
}
return authList, nil
}