Commit 62a6c531 authored by Rajiv Patel-O'Connor's avatar Rajiv Patel-O'Connor Committed by Kelvin Fichter

Consolidate Predeploy Addresses (#931)

* added library for predeploy addresses

* refactor tests and other packages to use exported predeploys

* revert library usage in OVM_ECDSAContractAccount

* lint

* added newline

* fixed address typos
Co-authored-by: default avatarrajivpo <rajivpatel-oconnor@Rajivs-MacBook-Pro-2.local>
Co-authored-by: default avatarsmartcontracts <kelvinfichter@gmail.com>
parent 4e0461dc
......@@ -3,6 +3,7 @@ import { Direction, waitForXDomainTransaction } from './watcher-utils'
import {
getContractFactory,
getContractInterface,
predeploys,
} from '@eth-optimism/contracts'
import { remove0x, Watcher } from '@eth-optimism/core-utils'
import {
......@@ -54,7 +55,7 @@ export const l2Wallet = l1Wallet.connect(l2Provider)
// Predeploys
export const PROXY_SEQUENCER_ENTRYPOINT_ADDRESS =
'0x4200000000000000000000000000000000000004'
export const OVM_ETH_ADDRESS = '0x4200000000000000000000000000000000000006'
export const OVM_ETH_ADDRESS = predeploys.OVM_ETH
export const getAddressManager = (provider: any) => {
return getContractFactory('Lib_AddressManager')
......
......@@ -9,7 +9,7 @@ import sinon from 'sinon'
import { Web3Provider } from '@ethersproject/providers'
import scc from '@eth-optimism/contracts/artifacts/contracts/optimistic-ethereum/OVM/chain/OVM_StateCommitmentChain.sol/OVM_StateCommitmentChain.json'
import { getContractInterface } from '@eth-optimism/contracts'
import { getContractInterface, predeploys } from '@eth-optimism/contracts'
import { smockit, MockContract } from '@eth-optimism/smock'
/* Internal Imports */
......@@ -38,7 +38,6 @@ import {
} from '@eth-optimism/core-utils'
import { Logger, Metrics } from '@eth-optimism/common-ts'
const DECOMPRESSION_ADDRESS = '0x4200000000000000000000000000000000000008'
const DUMMY_ADDRESS = '0x' + '00'.repeat(20)
const EXAMPLE_STATE_ROOT =
'0x16b7f83f409c7195b1f4fde5652f1b54a4477eacb6db7927691becafba5f8801'
......@@ -98,7 +97,7 @@ describe('BatchSubmitter', () => {
)
await AddressManager.setAddress(
'OVM_DecompressionPrecompileAddress',
DECOMPRESSION_ADDRESS
predeploys.OVM_SequencerEntrypoint
)
Mock__OVM_ExecutionManager = await smockit(
......@@ -484,7 +483,7 @@ describe('Batch Submitter with Ganache', () => {
gasPrices.push(gasPrice)
const tx = signer.sendTransaction({
to: DECOMPRESSION_ADDRESS,
to: predeploys.OVM_SequencerEntrypoint,
value: 88,
nonce: 0,
gasPrice,
......
......@@ -3,6 +3,7 @@ pragma solidity >0.5.0 <0.8.0;
/* Library Imports */
import { Lib_Bytes32Utils } from "../../libraries/utils/Lib_Bytes32Utils.sol";
import { Lib_PredeployAddresses } from "../../libraries/constants/Lib_PredeployAddresses.sol";
import { Lib_ExecutionManagerWrapper } from "../../libraries/wrappers/Lib_ExecutionManagerWrapper.sol";
/**
......@@ -29,7 +30,6 @@ contract OVM_ProxyEOA {
* Constants *
*************/
address constant DEFAULT_IMPLEMENTATION = 0x4200000000000000000000000000000000000003;
bytes32 constant IMPLEMENTATION_KEY = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; //bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1);
......@@ -98,7 +98,7 @@ contract OVM_ProxyEOA {
address implementation = Lib_Bytes32Utils.toAddress(addr32);
if (implementation == address(0)) {
return DEFAULT_IMPLEMENTATION;
return Lib_PredeployAddresses.ovmECDSAContractAccount;
} else {
return implementation;
}
......
......@@ -7,6 +7,7 @@ import { Lib_AddressResolver } from "../../../libraries/resolver/Lib_AddressReso
import { Lib_OVMCodec } from "../../../libraries/codec/Lib_OVMCodec.sol";
import { Lib_AddressManager } from "../../../libraries/resolver/Lib_AddressManager.sol";
import { Lib_SecureMerkleTrie } from "../../../libraries/trie/Lib_SecureMerkleTrie.sol";
import { Lib_PredeployAddresses } from "../../../libraries/constants/Lib_PredeployAddresses.sol";
import { Lib_CrossDomainUtils } from "../../../libraries/bridge/Lib_CrossDomainUtils.sol";
/* Interface Imports */
......@@ -407,7 +408,7 @@ contract OVM_L1CrossDomainMessenger is
bool exists,
bytes memory encodedMessagePassingAccount
) = Lib_SecureMerkleTrie.get(
abi.encodePacked(0x4200000000000000000000000000000000000000),
abi.encodePacked(Lib_PredeployAddresses.ovmL2ToL1MessagePasser),
_proof.stateTrieWitness,
_proof.stateRoot
);
......
......@@ -8,6 +8,7 @@ import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import { Lib_AddressResolver } from "../../libraries/resolver/Lib_AddressResolver.sol";
import { Lib_EthUtils } from "../../libraries/utils/Lib_EthUtils.sol";
import { Lib_ErrorUtils } from "../../libraries/utils/Lib_ErrorUtils.sol";
import { Lib_PredeployAddresses } from "../../libraries/constants/Lib_PredeployAddresses.sol";
/* Interface Imports */
import { iOVM_ExecutionManager } from "../../iOVM/execution/iOVM_ExecutionManager.sol";
......@@ -551,9 +552,9 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
address proxyEOA = Lib_EthUtils.createContract(abi.encodePacked(
hex"600D380380600D6000396000f3",
ovmEXTCODECOPY(
0x4200000000000000000000000000000000000009,
Lib_PredeployAddresses.ovmProxyEOA,
0,
ovmEXTCODESIZE(0x4200000000000000000000000000000000000009)
ovmEXTCODESIZE(Lib_PredeployAddresses.ovmProxyEOA)
)
));
......@@ -829,7 +830,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
// the deployer ovmCALLing the whitelist. This is fine--in a sense, we are forcing them to.
(bool success, bytes memory data) = ovmCALL(
gasleft(),
0x4200000000000000000000000000000000000002,
Lib_PredeployAddresses.ovmDeployerWhitelist,
abi.encodeWithSignature("isDeployerAllowed(address)", _deployerAddress)
);
bool isAllowed = abi.decode(data, (bool));
......
// SPDX-License-Identifier: MIT
pragma solidity >0.5.0 <0.8.0;
/**
* @title Lib_PredeployAddresses
*/
library Lib_PredeployAddresses {
address public constant ovmL2ToL1MessagePasser = 0x4200000000000000000000000000000000000000;
address public constant ovmL1MessageSender = 0x4200000000000000000000000000000000000001;
address public constant ovmDeployerWhitelist = 0x4200000000000000000000000000000000000002;
address public constant ovmECDSAContractAccount = 0x4200000000000000000000000000000000000003;
address public constant ovmSequencerEntrypoint = 0x4200000000000000000000000000000000000005;
address public constant ovmETH = 0x4200000000000000000000000000000000000006;
address public constant ovmL2CrossDomainMessenger = 0x4200000000000000000000000000000000000007;
address public constant libAddressManager = 0x4200000000000000000000000000000000000008;
address public constant ovmProxyEOA = 0x4200000000000000000000000000000000000009;
address public constant ERC1820Registry = 0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24;
}
......@@ -122,7 +122,7 @@ export const makeContractDeployConfig = async (
await _sendTx(
l1EthGateway.initialize(
AddressManager.address,
'0x4200000000000000000000000000000000000006',
predeploys.OVM_ETH,
config.deployOverrides
)
)
......@@ -149,7 +149,7 @@ export const makeContractDeployConfig = async (
await _sendTx(
AddressManager.setAddress(
'OVM_DecompressionPrecompileAddress',
'0x4200000000000000000000000000000000000005'
predeploys.OVM_SequencerEntrypoint
)
)
await _sendTx(
......@@ -230,7 +230,7 @@ export const makeContractDeployConfig = async (
OVM_ETH: {
factory: getContractFactory('OVM_ETH'),
params: [
'0x4200000000000000000000000000000000000007',
predeploys.OVM_L2CrossDomainMessenger,
'0x0000000000000000000000000000000000000000', // will be overridden by geth when state dump is ingested. Storage key: 0x0000000000000000000000000000000000000000000000000000000000000008
],
},
......
......@@ -105,8 +105,7 @@ export const makeStateDump = async (cfg: RollupDeployConfig): Promise<any> => {
},
ovmGlobalContext: {
ovmCHAINID: 420,
L2CrossDomainMessengerAddress:
'0x4200000000000000000000000000000000000007',
L2CrossDomainMessengerAddress: predeploys.OVM_L2CrossDomainMessenger,
},
transactionChainConfig: {
sequencer: signer,
......
......@@ -21,6 +21,7 @@ import {
encodeXDomainCalldata,
} from '../../../../helpers'
import { keccak256 } from 'ethers/lib/utils'
import { predeploys } from '../../../../../src'
const MAX_GAS_LIMIT = 8_000_000
......@@ -269,8 +270,6 @@ describe('OVM_L1CrossDomainMessenger', () => {
calldata = encodeXDomainCalldata(target, sender, message, 0)
const precompile = '0x4200000000000000000000000000000000000000'
const storageKey = keccak256(
keccak256(
calldata + remove0x(Mock__OVM_L2CrossDomainMessenger.address)
......@@ -289,7 +288,7 @@ describe('OVM_L1CrossDomainMessenger', () => {
const generator = await TrieTestGenerator.fromAccounts({
accounts: [
{
address: precompile,
address: predeploys.OVM_L2ToL1MessagePasser,
nonce: 0,
balance: 0,
codeHash: keccak256('0x1234'),
......@@ -303,8 +302,11 @@ describe('OVM_L1CrossDomainMessenger', () => {
stateRoot: toHexString(generator._trie.root),
stateRootBatchHeader: DUMMY_BATCH_HEADERS[0],
stateRootProof: DUMMY_BATCH_PROOFS[0],
stateTrieWitness: (await generator.makeAccountProofTest(precompile))
.accountTrieWitness,
stateTrieWitness: (
await generator.makeAccountProofTest(
predeploys.OVM_L2ToL1MessagePasser
)
).accountTrieWitness,
storageTrieWitness: (
await storageGenerator.makeInclusionProofTest(storageKey)
).proof,
......
......@@ -20,10 +20,11 @@ import {
getNextBlockNumber,
} from '../../../helpers'
import { predeploys } from '../../../../src'
// Still have some duplication from OVM_CanonicalTransactionChain.spec.ts, but it's so minimal that
// this is probably cleaner for now. Particularly since we're planning to move all of this out into
// core-utils soon anyway.
const DECOMPRESSION_ADDRESS = '0x4200000000000000000000000000000000000008'
const MAX_GAS_LIMIT = 8_000_000
const appendSequencerBatch = async (
......@@ -55,7 +56,7 @@ describe('[GAS BENCHMARK] OVM_CanonicalTransactionChain', () => {
)
await AddressManager.setAddress(
'OVM_DecompressionPrecompileAddress',
DECOMPRESSION_ADDRESS
predeploys.OVM_SequencerEntrypoint
)
Mock__OVM_ExecutionManager = await smockit(
......
......@@ -27,9 +27,9 @@ import {
getBlockTime,
mineBlock,
} from '../../../helpers'
import { predeploys } from '../../../../src'
const ELEMENT_TEST_SIZES = [1, 2, 4, 8, 16]
const DECOMPRESSION_ADDRESS = '0x4200000000000000000000000000000000000008'
const MAX_GAS_LIMIT = 8_000_000
const getQueueLeafHash = (index: number): string => {
......@@ -105,7 +105,7 @@ describe('OVM_CanonicalTransactionChain', () => {
)
await AddressManager.setAddress(
'OVM_DecompressionPrecompileAddress',
DECOMPRESSION_ADDRESS
predeploys.OVM_SequencerEntrypoint
)
Mock__OVM_ExecutionManager = await smockit(
......@@ -604,7 +604,7 @@ describe('OVM_CanonicalTransactionChain', () => {
})
it('should successfully verify against a valid sequencer transaction', async () => {
const entrypoint = DECOMPRESSION_ADDRESS
const entrypoint = predeploys.OVM_SequencerEntrypoint
const gasLimit = MAX_GAS_LIMIT
const data = '0x' + '12'.repeat(1234)
const timestamp = (await getEthTime(ethers.provider)) - 10
......
......@@ -14,6 +14,7 @@ import {
getStorageXOR,
encodeSolidityError,
} from '../../../../helpers'
import { predeploys } from '../../../../../src'
const CREATED_CONTRACT_1 = '0x2bda4a99d5be88609d23b1e4ab5d1d34fb1c2feb'
const CREATED_CONTRACT_2 = '0x2bda4a99d5be88609d23b1e4ab5d1d34fb1c2feb'
......@@ -772,7 +773,7 @@ const test_ovmCREATE: TestDefinition = {
},
},
contractStorage: {
['0x4200000000000000000000000000000000000002']: {
[predeploys.OVM_DeployerWhitelist]: {
// initialized? true, allowArbitraryDeployment? false
'0x0000000000000000000000000000000000000000000000000000000000000000': getStorageXOR(
'0x0000000000000000000000000000000000000000000000000000000000000001'
......@@ -788,7 +789,7 @@ const test_ovmCREATE: TestDefinition = {
},
},
verifiedContractStorage: {
['0x4200000000000000000000000000000000000002']: {
[predeploys.OVM_DeployerWhitelist]: {
'0x0000000000000000000000000000000000000000000000000000000000000000': 1,
[NON_WHITELISTED_DEPLOYER_KEY]: 1,
[WHITELISTED_DEPLOYER_KEY]: 1,
......@@ -902,7 +903,7 @@ const test_ovmCREATE: TestDefinition = {
},
},
contractStorage: {
['0x4200000000000000000000000000000000000002']: {
[predeploys.OVM_DeployerWhitelist]: {
// initialized? true, allowArbitraryDeployment? true
'0x0000000000000000000000000000000000000000000000000000000000000000': getStorageXOR(
'0x0000000000000000000000000000000000000000000000000000000000000101'
......@@ -918,7 +919,7 @@ const test_ovmCREATE: TestDefinition = {
},
},
verifiedContractStorage: {
['0x4200000000000000000000000000000000000002']: {
[predeploys.OVM_DeployerWhitelist]: {
'0x0000000000000000000000000000000000000000000000000000000000000000': 1,
[NON_WHITELISTED_DEPLOYER_KEY]: 1,
[WHITELISTED_DEPLOYER_KEY]: 1,
......
......@@ -8,7 +8,11 @@ import { fromHexString, sleep } from '@eth-optimism/core-utils'
import { BaseService } from '@eth-optimism/common-ts'
import SpreadSheet from './spreadsheet'
import { loadContract, loadContractFromManager } from '@eth-optimism/contracts'
import {
loadContract,
loadContractFromManager,
predeploys,
} from '@eth-optimism/contracts'
import { StateRootBatchHeader, SentMessage, SentMessageProof } from './types'
interface MessageRelayerOptions {
......@@ -132,7 +136,7 @@ export class MessageRelayerService extends BaseService<MessageRelayerOptions> {
this.logger.info('Connecting to OVM_L2ToL1MessagePasser...')
this.state.OVM_L2ToL1MessagePasser = loadContract(
'OVM_L2ToL1MessagePasser',
'0x4200000000000000000000000000000000000000',
predeploys.OVM_L2ToL1MessagePasser,
this.options.l2RpcProvider
)
this.logger.info('Connected to OVM_L2ToL1MessagePasser', {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment