diff --git a/op-e2e/e2eutils/addresses.go b/op-e2e/e2eutils/addresses.go new file mode 100644 index 0000000000000..637cc4faa709b --- /dev/null +++ b/op-e2e/e2eutils/addresses.go @@ -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 +} diff --git a/op-e2e/e2eutils/addresses_test.go b/op-e2e/e2eutils/addresses_test.go new file mode 100644 index 0000000000000..e4a5df73bd45f --- /dev/null +++ b/op-e2e/e2eutils/addresses_test.go @@ -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) +}