-
Notifications
You must be signed in to change notification settings - Fork 40
/
naive.go
69 lines (64 loc) · 1.34 KB
/
naive.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
package fuzzing
import (
"crypto/rand"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/holiman/goevmlab/ops"
"github.com/holiman/goevmlab/program"
)
func fillNaive(gst *GstMaker, fork string) {
// The accounts which we want to be able to invoke
addrs := []common.Address{
common.HexToAddress("0xF1"),
}
forkDef := ops.LookupFork(fork)
if forkDef == nil {
panic("bad fork")
}
for _, addr := range addrs {
gst.AddAccount(addr, GenesisAccount{
Code: randomBytecode(forkDef),
Balance: new(big.Int),
Storage: RandStorage(15, 20),
})
}
// The transaction
gst.SetTx(&StTransaction{
// 8M gaslimit
GasLimit: []uint64{8000000},
Nonce: 0,
Value: []string{randHex(4)},
Data: []string{randHex(100)},
GasPrice: big.NewInt(0x10),
To: addrs[0].Hex(),
Sender: sender,
PrivateKey: pKey,
})
}
// randomBytecode returns a pretty simplistic bytecode, 1024 ops.
func randomBytecode(f *ops.Fork) []byte {
b := make([]byte, 1024)
_, _ = rand.Read(b)
i := 0
var next = func() byte {
x := b[i]
i++
if i >= len(b) {
_, _ = rand.Read(b)
i = 0
}
return x
}
p := program.NewProgram()
p.Push(next())
p.Push(next())
p.Push(next())
p.Push(next())
p.Push(next())
p.Push(next())
p.Push(next())
for p.Size() < 1024 {
p.Op(f.RandomOp(next()))
}
return p.Bytecode()
}