forked from ethereum-optimism/optimism
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddresses.go
66 lines (60 loc) · 1.87 KB
/
addresses.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
package e2eutils
import (
"bytes"
"sort"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-chain-ops/crossdomain"
)
func collectAllocAddrs(alloc core.GenesisAlloc) []common.Address {
var out []common.Address
for addr := range alloc {
out = append(out, addr)
}
// make output deterministic
sort.Slice(out, func(i, j int) bool {
return bytes.Compare(out[i][:], out[j][:]) < 0
})
return out
}
// CollectAddresses constructs a lists of addresses that may be used as fuzzing corpora
// or random address selection.
func CollectAddresses(sd *SetupData, dp *DeployParams) (out []common.Address) {
// This should be seeded with:
// - reserve 0 for selecting nil (contract creation)
out = append(out, common.Address{})
// - zero address
out = append(out, common.Address{})
// - addresses of signing accounts
out = append(out, dp.Addresses.All()...)
// prefunded L1/L2 accounts for testing
out = append(out, collectAllocAddrs(sd.L1Cfg.Alloc)...)
out = append(out, collectAllocAddrs(sd.L2Cfg.Alloc)...)
// - addresses of system contracts
out = append(out,
sd.L1Cfg.Coinbase,
sd.L2Cfg.Coinbase,
dp.Addresses.SequencerP2P,
predeploys.SequencerFeeVaultAddr,
sd.RollupCfg.BatchInboxAddress,
sd.RollupCfg.Genesis.SystemConfig.BatcherAddr,
sd.RollupCfg.DepositContractAddress,
)
// - precompiles
for i := 0; i <= 0xff; i++ {
out = append(out, common.Address{19: byte(i)})
}
// - masked L2 version of all the original addrs
original := out[:]
for _, addr := range original {
masked := crossdomain.ApplyL1ToL2Alias(addr)
out = append(out, masked)
}
// - unmasked L1 version of all the original addrs
for _, addr := range original {
unmasked := crossdomain.UndoL1ToL2Alias(addr)
out = append(out, unmasked)
}
return out
}