Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions op-e2e/e2eutils/addresses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package e2eutils

import (
"bytes"
"sort"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"

"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,
sd.RollupCfg.P2PSequencerAddress,
sd.RollupCfg.FeeRecipientAddress,
sd.RollupCfg.BatchInboxAddress,
sd.RollupCfg.BatchSenderAddress,
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
}
21 changes: 21 additions & 0 deletions op-e2e/e2eutils/addresses_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package e2eutils

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestCollectAddresses(t *testing.T) {
tp := &TestParams{
MaxSequencerDrift: 40,
SequencerWindowSize: 120,
ChannelTimeout: 120,
}
dp := MakeDeployParams(t, tp)
alloc := &AllocParams{PrefundTestUsers: true}
sd := Setup(t, dp, alloc)
addrs := CollectAddresses(sd, dp)
require.NotEmpty(t, addrs)
require.Contains(t, addrs, dp.Addresses.Batcher)
}