-
Notifications
You must be signed in to change notification settings - Fork 4k
l2geth: Add support for system addresses #2256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mslipper
merged 1 commit into
ethereum-optimism:develop
from
mslipper:feat/system-address
Mar 7, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@eth-optimism/integration-tests': patch | ||
| '@eth-optimism/l2geth': patch | ||
| '@eth-optimism/contracts': patch | ||
| --- | ||
|
|
||
| Add support for system addresses |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* Imports: External */ | ||
| import { BigNumber, Contract, ContractFactory, utils, Wallet } from 'ethers' | ||
| import { ethers } from 'hardhat' | ||
| import { futurePredeploys } from '@eth-optimism/contracts' | ||
|
|
||
| /* Imports: Internal */ | ||
| import { expect } from './shared/setup' | ||
| import { OptimismEnv } from './shared/env' | ||
| import { envConfig } from './shared/utils' | ||
|
|
||
| const SYSTEM_ADDRESSES = [futurePredeploys.System0, futurePredeploys.System1] | ||
|
|
||
| describe('System addresses', () => { | ||
| let env: OptimismEnv | ||
|
|
||
| let deployerWallets: Wallet[] = [] | ||
|
|
||
| let contracts: Contract[] | ||
|
|
||
| let Factory__ERC20: ContractFactory | ||
|
|
||
| before(async function () { | ||
| if (!envConfig.RUN_SYSTEM_ADDRESS_TESTS) { | ||
| console.log('Skipping system address tests.') | ||
| this.skip() | ||
| return | ||
| } | ||
|
|
||
| env = await OptimismEnv.new() | ||
|
|
||
| deployerWallets = [ | ||
| new Wallet(process.env.SYSTEM_ADDRESS_0_DEPLOYER_KEY, env.l2Provider), | ||
| new Wallet(process.env.SYSTEM_ADDRESS_1_DEPLOYER_KEY, env.l2Provider), | ||
| ] | ||
| for (const deployer of deployerWallets) { | ||
| await env.l2Wallet.sendTransaction({ | ||
| to: deployer.address, | ||
| value: utils.parseEther('0.1'), | ||
| }) | ||
| } | ||
| contracts = [] | ||
|
|
||
| Factory__ERC20 = await ethers.getContractFactory('ERC20', env.l2Wallet) | ||
| }) | ||
|
|
||
| it('should have no code for the system addresses initially', async () => { | ||
| for (const addr of SYSTEM_ADDRESSES) { | ||
| const code = await env.l2Provider.getCode(addr, 'latest') | ||
| expect(code).to.eq('0x') | ||
| } | ||
| }) | ||
|
|
||
| it('should deploy to the system address', async () => { | ||
| for (let i = 0; i < deployerWallets.length; i++) { | ||
| const contract = await Factory__ERC20.connect(deployerWallets[i]).deploy( | ||
| 100000000, | ||
| 'OVM Test', | ||
| 8, | ||
| 'OVM' | ||
| ) | ||
| // have to use the receipt here since ethers calculates the | ||
| // contract address on-the-fly | ||
| const receipt = await contract.deployTransaction.wait() | ||
| expect(receipt.contractAddress).to.eq(SYSTEM_ADDRESSES[i]) | ||
|
|
||
| const fetchedReceipt = await env.l2Provider.getTransactionReceipt( | ||
| receipt.transactionHash | ||
| ) | ||
| expect(fetchedReceipt.contractAddress).to.eq(SYSTEM_ADDRESSES[i]) | ||
|
|
||
| contracts.push(await ethers.getContractAt('ERC20', SYSTEM_ADDRESSES[i])) | ||
| } | ||
| }) | ||
|
|
||
| it('contracts deployed at the system addresses should function', async () => { | ||
| expect(contracts.length).to.eq(2) | ||
|
|
||
| for (let i = 0; i < contracts.length; i++) { | ||
| const wallet = deployerWallets[i] | ||
| const contract = contracts[i].connect(wallet) | ||
| const code = await env.l2Provider.getCode(contract.address, 'latest') | ||
| expect(code).not.to.eq('0x') | ||
|
|
||
| const tx = await contract.transfer(env.l2Wallet.address, 1000) | ||
| await tx.wait() | ||
| const bal = await contract.balanceOf(env.l2Wallet.address) | ||
| expect(bal).to.deep.equal(BigNumber.from(1000)) | ||
| } | ||
| }) | ||
|
|
||
| it('should not deploy any additional contracts from the deployer at the system address', async () => { | ||
| for (let i = 0; i < deployerWallets.length; i++) { | ||
| const contract = await Factory__ERC20.connect(deployerWallets[i]).deploy( | ||
| 100000000, | ||
| 'OVM Test', | ||
| 8, | ||
| 'OVM' | ||
| ) | ||
| await contract.deployed() | ||
| const receipt = await contract.deployTransaction.wait() | ||
| expect(receipt.contractAddress).not.to.eq(SYSTEM_ADDRESSES[i]) | ||
| expect(receipt.contractAddress).not.to.eq(null) | ||
| } | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| package rcfg | ||
|
|
||
| import ( | ||
| "math/big" | ||
| "os" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/l2geth/common" | ||
| ) | ||
|
|
||
| // SystemAddress0 is the first deployable system address. | ||
| var SystemAddress0 = common.HexToAddress("0x4200000000000000000000000000000000000042") | ||
|
|
||
| // SystemAddress1 is the second deployable system address. | ||
| var SystemAddress1 = common.HexToAddress("0x4200000000000000000000000000000000000014") | ||
|
|
||
| // ZeroSystemAddress is the emprt system address. | ||
| var ZeroSystemAddress common.Address | ||
|
|
||
| // SystemAddressDeployer is a tuple containing the deployment | ||
| // addresses for SystemAddress0 and SystemAddress1. | ||
| type SystemAddressDeployer [2]common.Address | ||
|
|
||
| // SystemAddressFor returns the system address for a given deployment | ||
| // address. If no system address is configured for this deployer, | ||
| // ZeroSystemAddress is returned. | ||
| func (s SystemAddressDeployer) SystemAddressFor(addr common.Address) common.Address { | ||
| if s[0] == addr { | ||
| return SystemAddress0 | ||
| } | ||
|
|
||
| if s[1] == addr { | ||
| return SystemAddress1 | ||
| } | ||
|
|
||
| return ZeroSystemAddress | ||
| } | ||
|
|
||
| // SystemAddressFor is a convenience method that returns an environment-based | ||
| // system address if the passed-in chain ID is not hardcoded. | ||
| func SystemAddressFor(chainID *big.Int, addr common.Address) common.Address { | ||
| sysDeployer, hasHardcodedSysDeployer := SystemAddressDeployers[chainID.Uint64()] | ||
| if !hasHardcodedSysDeployer { | ||
| sysDeployer = envSystemAddressDeployer | ||
| } | ||
|
|
||
| return sysDeployer.SystemAddressFor(addr) | ||
| } | ||
|
|
||
| // SystemAddressDeployers maintains a hardcoded map of chain IDs to | ||
| // system addresses. | ||
| var SystemAddressDeployers = map[uint64]SystemAddressDeployer{ | ||
| // Mainnet | ||
| 10: { | ||
| common.HexToAddress("0xcDE47C1a5e2d60b9ff262b0a3b6d486048575Ad9"), | ||
| common.HexToAddress("0x53A6eecC2dD4795Fcc68940ddc6B4d53Bd88Bd9E"), | ||
| }, | ||
|
|
||
| // Kovan | ||
| 69: { | ||
| common.HexToAddress("0xd23eb5c2dd7035e6eb4a7e129249d9843123079f"), | ||
| common.HexToAddress("0xa81224490b9fa4930a2e920550cd1c9106bb6d9e"), | ||
| }, | ||
|
|
||
| // Goerli | ||
| 420: { | ||
| common.HexToAddress("0xc30276833798867c1dbc5c468bf51ca900b44e4c"), | ||
| common.HexToAddress("0x5c679a57e018f5f146838138d3e032ef4913d551"), | ||
| }, | ||
| } | ||
|
|
||
| var envSystemAddressDeployer SystemAddressDeployer | ||
|
|
||
| func initEnvSystemAddressDeployer() { | ||
| deployer0Env := os.Getenv("SYSTEM_ADDRESS_0_DEPLOYER") | ||
| deployer1Env := os.Getenv("SYSTEM_ADDRESS_1_DEPLOYER") | ||
|
|
||
|
mslipper marked this conversation as resolved.
Outdated
|
||
| if deployer0Env == "" && deployer1Env == "" { | ||
| return | ||
| } | ||
| if !common.IsHexAddress(deployer0Env) { | ||
| panic("SYSTEM_ADDRESS_0_DEPLOYER specified but invalid") | ||
| } | ||
| if !common.IsHexAddress(deployer1Env) { | ||
| panic("SYSTEM_ADDRESS_1_DEPLOYER specified but invalid") | ||
| } | ||
| envSystemAddressDeployer[0] = common.HexToAddress(deployer0Env) | ||
| envSystemAddressDeployer[1] = common.HexToAddress(deployer1Env) | ||
| } | ||
|
|
||
| func init() { | ||
| initEnvSystemAddressDeployer() | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.