Skip to content
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

Consolidate Predeploy Addresses #931

Merged
merged 7 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion integration-tests/test/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -49,7 +50,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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -98,7 +97,7 @@ describe('BatchSubmitter', () => {
)
await AddressManager.setAddress(
'OVM_DecompressionPrecompileAddress',
DECOMPRESSION_ADDRESS
predeploys.OVM_SequencerEntrypoint
)

Mock__OVM_ExecutionManager = await smockit(
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand All @@ -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);


Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -570,9 +571,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)
)
));

Expand Down Expand Up @@ -848,7 +849,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));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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;
}
6 changes: 3 additions & 3 deletions packages/contracts/src/contract-deployment/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const makeContractDeployConfig = async (
await _sendTx(
l1EthGateway.initialize(
AddressManager.address,
'0x4200000000000000000000000000000000000006',
predeploys.OVM_ETH,
config.deployOverrides
)
)
Expand All @@ -151,7 +151,7 @@ export const makeContractDeployConfig = async (
await _sendTx(
AddressManager.setAddress(
'OVM_DecompressionPrecompileAddress',
'0x4200000000000000000000000000000000000005'
predeploys.OVM_SequencerEntrypoint
)
)
await _sendTx(
Expand Down Expand Up @@ -232,7 +232,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
],
},
Expand Down
3 changes: 1 addition & 2 deletions packages/contracts/src/state-dump/make-dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ export const makeStateDump = async (cfg: RollupDeployConfig): Promise<any> => {
},
ovmGlobalContext: {
ovmCHAINID: 420,
L2CrossDomainMessengerAddress:
'0x4200000000000000000000000000000000000007',
L2CrossDomainMessengerAddress: predeploys.OVM_L2CrossDomainMessenger,
},
transactionChainConfig: {
sequencer: signer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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'),
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -55,7 +56,7 @@ describe('[GAS BENCHMARK] OVM_CanonicalTransactionChain', () => {
)
await AddressManager.setAddress(
'OVM_DecompressionPrecompileAddress',
DECOMPRESSION_ADDRESS
predeploys.OVM_SequencerEntrypoint
)

Mock__OVM_ExecutionManager = await smockit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('OVM_CanonicalTransactionChain', () => {
)
await AddressManager.setAddress(
'OVM_DecompressionPrecompileAddress',
DECOMPRESSION_ADDRESS
predeploys.OVM_SequencerEntrypoint
)

Mock__OVM_ExecutionManager = await smockit(
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getStorageXOR,
encodeSolidityError,
} from '../../../../helpers'
import { predeploys } from '../../../../../src'

const CREATED_CONTRACT_1 = '0x2bda4a99d5be88609d23b1e4ab5d1d34fb1c2feb'
const CREATED_CONTRACT_2 = '0x2bda4a99d5be88609d23b1e4ab5d1d34fb1c2feb'
Expand Down Expand Up @@ -772,7 +773,7 @@ const test_ovmCREATE: TestDefinition = {
},
},
contractStorage: {
['0x4200000000000000000000000000000000000002']: {
[predeploys.OVM_DeployerWhitelist]: {
// initialized? true, allowArbitraryDeployment? false
'0x0000000000000000000000000000000000000000000000000000000000000000': getStorageXOR(
'0x0000000000000000000000000000000000000000000000000000000000000001'
Expand All @@ -788,7 +789,7 @@ const test_ovmCREATE: TestDefinition = {
},
},
verifiedContractStorage: {
['0x4200000000000000000000000000000000000002']: {
[predeploys.OVM_DeployerWhitelist]: {
'0x0000000000000000000000000000000000000000000000000000000000000000': 1,
[NON_WHITELISTED_DEPLOYER_KEY]: 1,
[WHITELISTED_DEPLOYER_KEY]: 1,
Expand Down Expand Up @@ -902,7 +903,7 @@ const test_ovmCREATE: TestDefinition = {
},
},
contractStorage: {
['0x4200000000000000000000000000000000000002']: {
[predeploys.OVM_DeployerWhitelist]: {
// initialized? true, allowArbitraryDeployment? true
'0x0000000000000000000000000000000000000000000000000000000000000000': getStorageXOR(
'0x0000000000000000000000000000000000000000000000000000000000000101'
Expand All @@ -918,7 +919,7 @@ const test_ovmCREATE: TestDefinition = {
},
},
verifiedContractStorage: {
['0x4200000000000000000000000000000000000002']: {
[predeploys.OVM_DeployerWhitelist]: {
'0x0000000000000000000000000000000000000000000000000000000000000000': 1,
[NON_WHITELISTED_DEPLOYER_KEY]: 1,
[WHITELISTED_DEPLOYER_KEY]: 1,
Expand Down
8 changes: 6 additions & 2 deletions packages/message-relayer/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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', {
Expand Down
6 changes: 2 additions & 4 deletions packages/smock/src/smockit/smockit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,11 @@ export const smockit = async (
// We attach a wallet to the contract so that users can send transactions *from* a smock.
await hre.network.provider.request({
method: 'hardhat_impersonateAccount',
params: [contract.address]
params: [contract.address],
})

// Now we actually get the signer and attach it to the mock.
contract.wallet = await (hre as any).ethers.getSigner(
contract.address
)
contract.wallet = await (hre as any).ethers.getSigner(contract.address)

// Start by smocking the fallback.
contract.smocked = {
Expand Down
10 changes: 4 additions & 6 deletions packages/smock/test/smockit/sending-from-mocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@ describe('[smock]: sending transactions from smock contracts', () => {

let TestHelpers_SenderAssertions: Contract
before(async () => {
TestHelpers_SenderAssertions = await(
await ethers.getContractFactory(
'TestHelpers_SenderAssertions'
)
TestHelpers_SenderAssertions = await (
await ethers.getContractFactory('TestHelpers_SenderAssertions')
).deploy()
})

it('should attach a signer for a mock with a random address', async () => {
const mock = await smockit('TestHelpers_BasicReturnContract')

expect(
await TestHelpers_SenderAssertions.connect(mock.wallet).getSender()
).to.equal(mock.address)
})

it('should attach a signer for a mock with a fixed address', async () => {
const mock = await smockit('TestHelpers_BasicReturnContract', {
address: '0x1234123412341234123412341234123412341234'
address: '0x1234123412341234123412341234123412341234',
})

expect(
Expand Down