github.com/ethereum-optimism/optimism/l2geth@v0.0.0-20230612200230-50b04ade19e3/rollup/rcfg/system_address.go (about)

     1  package rcfg
     2  
     3  import (
     4  	"math/big"
     5  	"os"
     6  
     7  	"github.com/ethereum-optimism/optimism/l2geth/common"
     8  )
     9  
    10  // SystemAddress0 is the first deployable system address.
    11  var SystemAddress0 = common.HexToAddress("0x4200000000000000000000000000000000000042")
    12  
    13  // SystemAddress1 is the second deployable system address.
    14  var SystemAddress1 = common.HexToAddress("0x4200000000000000000000000000000000000014")
    15  
    16  // ZeroSystemAddress is the emprt system address.
    17  var ZeroSystemAddress common.Address
    18  
    19  // SystemAddressDeployer is a tuple containing the deployment
    20  // addresses for SystemAddress0 and SystemAddress1.
    21  type SystemAddressDeployer [2]common.Address
    22  
    23  // SystemAddressFor returns the system address for a given deployment
    24  // address. If no system address is configured for this deployer,
    25  // ZeroSystemAddress is returned.
    26  func (s SystemAddressDeployer) SystemAddressFor(addr common.Address) common.Address {
    27  	if s[0] == addr {
    28  		return SystemAddress0
    29  	}
    30  
    31  	if s[1] == addr {
    32  		return SystemAddress1
    33  	}
    34  
    35  	return ZeroSystemAddress
    36  }
    37  
    38  // SystemAddressFor is a convenience method that returns an environment-based
    39  // system address if the passed-in chain ID is not hardcoded.
    40  func SystemAddressFor(chainID *big.Int, addr common.Address) common.Address {
    41  	sysDeployer, hasHardcodedSysDeployer := SystemAddressDeployers[chainID.Uint64()]
    42  	if !hasHardcodedSysDeployer {
    43  		sysDeployer = envSystemAddressDeployer
    44  	}
    45  
    46  	return sysDeployer.SystemAddressFor(addr)
    47  }
    48  
    49  // SystemAddressDeployers maintains a hardcoded map of chain IDs to
    50  // system addresses.
    51  var SystemAddressDeployers = map[uint64]SystemAddressDeployer{
    52  	// Mainnet
    53  	10: {
    54  		common.HexToAddress("0xcDE47C1a5e2d60b9ff262b0a3b6d486048575Ad9"),
    55  		common.HexToAddress("0x53A6eecC2dD4795Fcc68940ddc6B4d53Bd88Bd9E"),
    56  	},
    57  
    58  	// Kovan
    59  	69: {
    60  		common.HexToAddress("0xd23eb5c2dd7035e6eb4a7e129249d9843123079f"),
    61  		common.HexToAddress("0xa81224490b9fa4930a2e920550cd1c9106bb6d9e"),
    62  	},
    63  
    64  	// Goerli
    65  	420: {
    66  		common.HexToAddress("0xc30276833798867c1dbc5c468bf51ca900b44e4c"),
    67  		common.HexToAddress("0x5c679a57e018f5f146838138d3e032ef4913d551"),
    68  	},
    69  
    70  	// Goerli nightly
    71  	421: {
    72  		common.HexToAddress("0xc30276833798867c1dbc5c468bf51ca900b44e4c"),
    73  		common.HexToAddress("0x5c679a57e018f5f146838138d3e032ef4913d551"),
    74  	},
    75  }
    76  
    77  var envSystemAddressDeployer SystemAddressDeployer
    78  
    79  func initEnvSystemAddressDeployer() {
    80  	deployer0Env := os.Getenv("SYSTEM_ADDRESS_0_DEPLOYER")
    81  	deployer1Env := os.Getenv("SYSTEM_ADDRESS_1_DEPLOYER")
    82  
    83  	if deployer0Env == "" && deployer1Env == "" {
    84  		return
    85  	}
    86  	if !common.IsHexAddress(deployer0Env) {
    87  		panic("SYSTEM_ADDRESS_0_DEPLOYER specified but invalid")
    88  	}
    89  	if !common.IsHexAddress(deployer1Env) {
    90  		panic("SYSTEM_ADDRESS_1_DEPLOYER specified but invalid")
    91  	}
    92  	envSystemAddressDeployer[0] = common.HexToAddress(deployer0Env)
    93  	envSystemAddressDeployer[1] = common.HexToAddress(deployer1Env)
    94  }
    95  
    96  func init() {
    97  	initEnvSystemAddressDeployer()
    98  }