core/vm: address comment

This commit is contained in:
Gary Rong 2026-04-14 16:11:00 +08:00
parent cb298098aa
commit 16162174ac
2 changed files with 56 additions and 49 deletions

View file

@ -17,43 +17,62 @@
package vm
import (
"encoding/hex"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
)
func decodeEIP7610AccountSet(str string) map[common.Address]struct{} {
if str == "" {
return make(map[common.Address]struct{})
}
b, err := hex.DecodeString(str)
if err != nil {
panic(err)
}
if len(b)%common.AddressLength != 0 {
panic(fmt.Sprintf("invalid length, %d", len(b)))
}
addresses := make(map[common.Address]struct{}, len(b)/common.AddressLength)
for i := 0; i < len(b)/common.AddressLength; i++ {
addresses[common.BytesToAddress(b[i*common.AddressLength:(i+1)*common.AddressLength])] = struct{}{}
}
return addresses
// eip7610Accounts lists the addresses eligible for contract deployment
// rejection under EIP-7610, keyed by chain ID. Only networks that adopted
// EIP-158 after genesis need an entry; all others have no pre-existing
// address collisions to guard against.
var eip7610Accounts = map[uint64][]common.Address{
params.MainnetChainConfig.ChainID.Uint64(): {
common.HexToAddress("0x02820E4bEE488C40f7455fDCa53125565148708F"),
common.HexToAddress("0x14725085d004f1b10Ee07234A4ab28c5Ad2a7b9E"),
common.HexToAddress("0x19272418753B90D9a3E3Efc8430b1612c55fcB3A"),
common.HexToAddress("0x2c081Ed1949D7Dd9447F9d96e509befE576D4461"),
common.HexToAddress("0x3311c08066580cb906a7287b6786E504C2EBD09f"),
common.HexToAddress("0x361d7a60b43587c7f6bbA4f9fD9642747F65210A"),
common.HexToAddress("0x40490C9c468622d5c89646D6F3097F8Eaf80c411"),
common.HexToAddress("0x4d149EB99BDEEFC1f858f8fd22289C6beAE99f2c"),
common.HexToAddress("0x5071cb62aA170b7f66b26cae8004d90E6078Bb1E"),
common.HexToAddress("0x50b1497068bAE652Df3562EB8Ea7677ff84477FA"),
common.HexToAddress("0x5983C6aC846DcF85fbBC4303F43eb91C379F79ae"),
common.HexToAddress("0x59EC0410867828E3b8c23Dd8A29d9796ef523b17"),
common.HexToAddress("0x5cC182faBFb81A056B6080d4200BC5150673D06f"),
common.HexToAddress("0x6f156dbf8Ed30e53F7C9Df73144E69f65cBB7E94"),
common.HexToAddress("0x7D6ae067De8d44Ae1A08750e7D626D61A623C44A"),
common.HexToAddress("0x8398fF6c618e9515468c1c4b198d53666CBe8462"),
common.HexToAddress("0xA21B22389bfC1cd6Bc7BA19A4Fc96aDC3D0FE074"),
common.HexToAddress("0xaDD92e0650457C5Db0c4c08cbf7cA580175d33d2"),
common.HexToAddress("0xAE3703584494Ade958AD27EC2d289b7a67c19E90"),
common.HexToAddress("0xb619f45637C39Ca49A41ac64c11637A0A194455E"),
common.HexToAddress("0xD8253352f6044cFE55bcC0748C3FA37b7dF81F98"),
common.HexToAddress("0xDB7C577B93Baeb56dAB50aF4D6f86F99A06B96a2"),
common.HexToAddress("0xdE425ad4B8d2d9E0E12F65CBcD6D55F447B44083"),
common.HexToAddress("0xe62dc49C92fA799033644d2A9aFD7e3BAbE5A80a"),
common.HexToAddress("0xF468BcBC4a0BFDB06336E773382C5202E674db71"),
common.HexToAddress("0xF4a835ec1364809003dE3925685F24cD360bdffe"),
common.HexToAddress("0xFc4465F84B29a1F8794Dc753F41BeF1F4b025ED2"),
common.HexToAddress("0xfeE7707fa4b8C0A923A0E40399Db3e7Ce26069C6"),
},
}
const mainnetEIP7610Data = "02820e4bee488c40f7455fdca53125565148708f14725085d004f1b10ee07234a4ab28c5ad2a7b9e19272418753b90d9a3e3efc8430b1612c55fcb3a2c081ed1949d7dd9447f9d96e509befe576d44613311c08066580cb906a7287b6786e504c2ebd09f361d7a60b43587c7f6bba4f9fd9642747f65210a40490c9c468622d5c89646d6f3097f8eaf80c4114d149eb99bdeefc1f858f8fd22289c6beae99f2c5071cb62aa170b7f66b26cae8004d90e6078bb1e50b1497068bae652df3562eb8ea7677ff84477fa5983c6ac846dcf85fbbc4303f43eb91c379f79ae59ec0410867828e3b8c23dd8a29d9796ef523b175cc182fabfb81a056b6080d4200bc5150673d06f6f156dbf8ed30e53f7c9df73144e69f65cbb7e947d6ae067de8d44ae1a08750e7d626d61a623c44a8398ff6c618e9515468c1c4b198d53666cbe8462a21b22389bfc1cd6bc7ba19a4fc96adc3d0fe074add92e0650457c5db0c4c08cbf7ca580175d33d2ae3703584494ade958ad27ec2d289b7a67c19e90b619f45637c39ca49a41ac64c11637a0a194455ed8253352f6044cfe55bcc0748c3fa37b7df81f98db7c577b93baeb56dab50af4d6f86f99a06b96a2de425ad4b8d2d9e0e12f65cbcd6d55f447b44083e62dc49c92fa799033644d2a9afd7e3babe5a80af468bcbc4a0bfdb06336e773382c5202e674db71f4a835ec1364809003de3925685f24cd360bdffefc4465f84b29a1f8794dc753f41bef1f4b025ed2fee7707fa4b8c0a923a0e40399db3e7ce26069c6"
const sepoliaEIP7610Data = ""
const holeskyEIP7610Data = ""
const hoodiEIP7610Data = ""
var (
mainnetEIP7610Accounts = decodeEIP7610AccountSet(mainnetEIP7610Data)
sepoliaEIP7610Accounts = decodeEIP7610AccountSet(sepoliaEIP7610Data)
holeskyEIP7610Accounts = decodeEIP7610AccountSet(hoodiEIP7610Data)
hoodiEIP7610Accounts = decodeEIP7610AccountSet(holeskyEIP7610Data)
)
// eip7610AccountSets is the membership-lookup form of eip7610Accounts,
// built once at init for O(1) containment checks.
var eip7610AccountSets = func() map[uint64]map[common.Address]struct{} {
sets := make(map[uint64]map[common.Address]struct{}, len(eip7610Accounts))
for chainID, addrs := range eip7610Accounts {
set := make(map[common.Address]struct{}, len(addrs))
for _, a := range addrs {
set[a] = struct{}{}
}
sets[chainID] = set
}
return sets
}()
// isEIP7610RejectedAccount reports whether the account identified by the
// address is eligible for contract deployment rejection due to having
@ -70,23 +89,10 @@ func isEIP7610RejectedAccount(chainID *big.Int, addr common.Address, isEIP158 bo
if !isEIP158 {
return false
}
var accountSet map[common.Address]struct{}
switch chainID {
case params.MainnetChainConfig.ChainID:
accountSet = mainnetEIP7610Accounts
case params.SepoliaChainConfig.ChainID:
accountSet = sepoliaEIP7610Accounts
case params.HoleskyChainConfig.ChainID:
accountSet = holeskyEIP7610Accounts
case params.HoodiChainConfig.ChainID:
accountSet = hoodiEIP7610Accounts
default:
// The network is unknown, so the account set must be provided by the
// network operators themselves. Notably, only a small number of
// networks enabled EIP-158 after genesis; for all others, this set
// will always be empty.
return false
}
_, exist := accountSet[addr]
// The network is unknown or has no rejected accounts; the set must be
// provided by the network operators themselves. Only a small number of
// networks enabled EIP-158 after genesis; for all others, this set
// will always be empty.
_, exist := eip7610AccountSets[chainID.Uint64()][addr]
return exist
}

View file

@ -18,14 +18,15 @@ package vm
import (
"fmt"
"maps"
"slices"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
)
func Example_mainnetEIP7610Accounts() {
list := slices.SortedFunc(maps.Keys(mainnetEIP7610Accounts), common.Address.Cmp)
list := slices.Clone(eip7610Accounts[params.MainnetChainConfig.ChainID.Uint64()])
slices.SortFunc(list, common.Address.Cmp)
for _, addr := range list {
fmt.Println(addr.Hex())
}