Skip to content

Commit

Permalink
contracts: import messengers (ethereum-optimism#393)
Browse files Browse the repository at this point in the history
* chore: copy L1 and L2 Messengers from Monorepo

* test: Add Messenger test files

Monorepo test cases are copied in as comments from the monorepo ts tests.

* chore: Add OZ upgradable contracts

New remappings were also added in order to avoid excessively

long import statements.

* chore: Importe OZ and OP contracts as node_modules

Necessary because hardhat does not support remappings!?!

y u no?

* refactor: Remove replayMessage()

We no longer need this function as it was only necessary when the CTC
a maximum gas limit per epoch concept. In order to remove the function
I had to copy in the L1xDM interface rather than import from the
node_modules.

* chore: Remove unused files

The ts test file is made redundant by an itest in the itest package.
The sol test file was not being used for anything

* refactor: Remove Address Manager and Resolver

Instead the CTC and SCC are state variables

* refactor: Replace CTC with OptimismPortal

* refactor: Remove SCC

We don't need to replace it with the L2OutputOracle in the L1xDM,
because the verification is now done in the OptimismPortal itself.

* forge install: forge-std

* forge install: ds-test

* refactor: Move boilerplate test code into CommonTest

* test: Add sendMessage and pause tests for L1xDM

* test: L1CrossDomainMessenger sendMessage and pause

* refactor: replace L2ToL1MessagePasser with Withdrawer contract

Also adds a lib with constant values for new bedrock predeploys.

* chore: Make functions external, and reorder for CEI

For whatever reason a bunch of functions on the messengers were public,
when they could have been external. I fixed that, and removed the
slither annotations. Where possible (in the sendMessage functions), I
also reordered the events and calls to respect
Checks-Effects-Interactions. There was no risk previously, but this
removes any question, and quiets slither.

* refactor: Reorganize ts helpers

Move helpers/index into utils.ts, and add other files which are exported in

the new index.ts.

* test: Add mock proof generation script and helpers

* test: Add L1xDM relayMessageSucceeds tests

* test: Add proof generation scripts and helpers

* refactor: Add l2Sender check in L2xDM

* refactor: Copy in the L1 and L2 standard bridge

At this point they are simply verbatim.

* refactor: Bridges - fix import paths

* refactor: Token Bridge - replace messengers with Portal
Also remove the CrossDomainEnabled lib.

refactor: Token Bridge - replace messengers with Portal
Also remove the CrossDomainEnabled lib.

* style: Address/remove some slither disable comments

style: Address/remove some slither disable comments

* refactor: extract l2Sender check into a modifier

* refactor: Support deposits of ETH in L2 Bridge

This copies in the IL2ERC20Bridge interface so that payable can be added.

In the case that the L2 token address matches OVM_ETH, the value of the

call will be forwarded.

* interface: add IWithdrawer.sol

* contracts: add comments to L1 contracts

* contracts: use unchecked

* contracts: fix imports in common test

* test: L1CrossDomainMessenger

* test: L2CrossDomainMessenger

* contracts: fix typo

* tests: bridge tests

* contracts: remove extra message assignment

* contracts: update gas snapshot

* forge install: solmate

* contracts: remove usage of OVM_ETH

All `OVM_ETH` will be migrated to `ETH` with the upgrade
to bedrock. We do not want to allow for the creation of new
`OVM_ETH` by depositing `ETH` into the bridge and have it
create `OVM_ETH` on L2.

* contracts: add in L2StandardERC20

* contracts: add in token factory

The token factory will deploy tokens on L2
that correspond to tokens on L1. This allows for
easy deposits through the bridge.

* contracts: test rlp lib for computing contract addrs

This library lets you compute the contract address
based on the deployment account and nonce.

h/t @t11s

* contracts: test infra for bridge

* contracts: add note to self

* contracts: fix compiler warnings

* contracts: update snapshot

* contracts: add IDepositFeed

* contracts: type cast uint256 to uint64 in messenger

* test: fix merge

* contracts: modify paths to compile with hardhat

* hardhat: update config

* contracts: fix build

* forge tests: first yarn install

* contracts: lint

* contracts: update snapshot

Co-authored-by: Maurelian <maurelian@protonmail.ch>
  • Loading branch information
tynes and maurelian authored Apr 30, 2022
1 parent 31d9a92 commit 0c05488
Show file tree
Hide file tree
Showing 51 changed files with 3,300 additions and 635 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/solidity-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jobs:
with:
version: nightly

- name: Install deps
run: yarn install

- name: Build with Forge
run: yarn build:forge

Expand Down
14 changes: 4 additions & 10 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
[submodule "packages/contracts/lib/ds-test"]
path = packages/contracts/lib/ds-test
url = https://github.com/dapphub/ds-test
[submodule "packages/contracts/lib/openzeppelin-contracts"]
path = packages/contracts/lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
[submodule "packages/contracts/lib/forge-std"]
path = packages/contracts/lib/forge-std
url = https://github.com/brockelmore/forge-std
[submodule "packages/contracts/lib/optimism"]
path = packages/contracts/lib/optimism
url = https://github.com/ethereum-optimism/optimism
url = https://github.com/foundry-rs/forge-std
[submodule "packages/contracts/lib/solmate"]
path = packages/contracts/lib/solmate
url = https://github.com/rari-capital/solmate
75 changes: 50 additions & 25 deletions packages/contracts/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,35 +1,60 @@
DepositFeedTest:test_depositTransaction_ContractCreationReverts() (gas: 11325)
DepositFeedTest:test_depositTransaction_NoValueContract() (gas: 21066)
DepositFeedTest:test_depositTransaction_NoValueEOA() (gas: 21531)
DepositFeedTest:test_depositTransaction_createWithZeroValueForContract() (gas: 21084)
DepositFeedTest:test_depositTransaction_createWithZeroValueForEOA() (gas: 21571)
DepositFeedTest:test_depositTransaction_withEthValueAndContractContractCreation() (gas: 28107)
DepositFeedTest:test_depositTransaction_ContractCreationReverts() (gas: 11345)
DepositFeedTest:test_depositTransaction_NoValueContract() (gas: 26479)
DepositFeedTest:test_depositTransaction_NoValueEOA() (gas: 26944)
DepositFeedTest:test_depositTransaction_createWithZeroValueForContract() (gas: 26497)
DepositFeedTest:test_depositTransaction_createWithZeroValueForEOA() (gas: 26984)
DepositFeedTest:test_depositTransaction_withEthValueAndContractContractCreation() (gas: 33520)
DepositFeedTest:test_depositTransaction_withEthValueAndEOAContractCreation() (gas: 25135)
DepositFeedTest:test_depositTransaction_withEthValueFromContract() (gas: 27775)
DepositFeedTest:test_depositTransaction_withEthValueFromEOA() (gas: 28511)
DepositFeedTest:test_depositTransaction_withEthValueFromContract() (gas: 33188)
DepositFeedTest:test_depositTransaction_withEthValueFromEOA() (gas: 33924)
L1BLockTest:test_basefee() (gas: 7509)
L1BLockTest:test_hash() (gas: 7508)
L1BLockTest:test_number() (gas: 7509)
L1BLockTest:test_timestamp() (gas: 7463)
L2OutputOracleTest:testCannot_appendCurrentTimestamp() (gas: 20880)
L2OutputOracleTest:testCannot_appendEmptyOutput() (gas: 19077)
L2OutputOracleTest:testCannot_appendFutureTimestamp() (gas: 21023)
L2OutputOracleTest:testCannot_appendOutputIfNotSequencer() (gas: 18306)
L2OutputOracleTest:testCannot_appendUnexpectedTimestamp() (gas: 21226)
L2OutputOracleTest:testCannot_computePreHistoricalL2BlockNumber() (gas: 13134)
L2OutputOracleTest:testCannot_deleteL2Output_ifNotSequencer() (gas: 18381)
L2OutputOracleTest:testCannot_deleteL2Output_ifWrongOutput() (gas: 25541)
L2OutputOracleTest:test_appendingAnotherOutput() (gas: 49539)
L2OutputOracleTest:test_computeL2BlockNumber() (gas: 14981)
L2OutputOracleTest:test_deleteL2Output() (gas: 32908)
L1CrossDomainMessenger_Test:testCannot_pause() (gas: 13061)
L1CrossDomainMessenger_Test:test_blockAndUnblockSuccessfulMessage() (gas: 108194)
L1CrossDomainMessenger_Test:test_pause() (gas: 31719)
L1CrossDomainMessenger_Test:test_relayMessageBlockingAuth() (gas: 20956)
L1CrossDomainMessenger_Test:test_relayMessageInsideFraudProofWindow() (gas: 14531)
L1CrossDomainMessenger_Test:test_relayMessageSucceeds() (gas: 84960)
L1CrossDomainMessenger_Test:test_relayMessageToSystemContract() (gas: 32472)
L1CrossDomainMessenger_Test:test_relayRevertOnBlockedMessage() (gas: 58192)
L1CrossDomainMessenger_Test:test_relayShouldRevertIfPaused() (gas: 43739)
L1CrossDomainMessenger_Test:test_relayShouldRevertSendingSameMessageTwice() (gas: 210)
L1CrossDomainMessenger_Test:test_revertOnInvalidOutputRootProof() (gas: 18192)
L1CrossDomainMessenger_Test:test_sendMessage() (gas: 46192)
L1CrossDomainMessenger_Test:test_sendMessageTwice() (gas: 49016)
L1CrossDomainMessenger_Test:test_xDomainMessageSenderResets() (gas: 83962)
L1StandardBridge_Test:test_L1BridgeSetsPortalAndL2Bridge() (gas: 14780)
L2CrossDomainMessenger_Test:test_L2MessengerCallsTarget() (gas: 66275)
L2CrossDomainMessenger_Test:test_L2MessengerCannotCallL2MessagePasser() (gas: 44127)
L2CrossDomainMessenger_Test:test_L2MessengerCannotRelaySameMessageTwice() (gas: 69883)
L2CrossDomainMessenger_Test:test_L2MessengerCorrectL1Messenger() (gas: 9688)
L2CrossDomainMessenger_Test:test_L2MessengerRevertInvalidL1XDomainMessenger() (gas: 13781)
L2CrossDomainMessenger_Test:test_L2MessengerSendMessage() (gas: 124835)
L2CrossDomainMessenger_Test:test_L2MessengerSendSameMessageTwice() (gas: 162907)
L2CrossDomainMessenger_Test:test_L2MessengerXDomainMessageSenderReset() (gas: 71843)
L2CrossDomainMessenger_Test:test_L2MessengerxDomainMsgSender() (gas: 13320)
L2OutputOracleTest:testCannot_appendCurrentTimestamp() (gas: 20865)
L2OutputOracleTest:testCannot_appendEmptyOutput() (gas: 19041)
L2OutputOracleTest:testCannot_appendFutureTimestamp() (gas: 21020)
L2OutputOracleTest:testCannot_appendOutputIfNotSequencer() (gas: 18309)
L2OutputOracleTest:testCannot_appendUnexpectedTimestamp() (gas: 21223)
L2OutputOracleTest:testCannot_computePreHistoricalL2BlockNumber() (gas: 13139)
L2OutputOracleTest:testCannot_deleteL2Output_ifNotSequencer() (gas: 18390)
L2OutputOracleTest:testCannot_deleteL2Output_ifWrongOutput() (gas: 25529)
L2OutputOracleTest:test_appendingAnotherOutput() (gas: 49533)
L2OutputOracleTest:test_computeL2BlockNumber() (gas: 14972)
L2OutputOracleTest:test_deleteL2Output() (gas: 32896)
L2OutputOracleTest:test_getL2Output() (gas: 15093)
L2OutputOracleTest:test_latestBlockTimestamp() (gas: 9654)
L2OutputOracleTest:test_nextTimestamp() (gas: 12009)
L2OutputOracleTest_Constructor:test_constructor() (gas: 29100)
L2OutputOracleTest:test_latestBlockTimestamp() (gas: 9669)
L2OutputOracleTest:test_nextTimestamp() (gas: 12024)
L2OutputOracleTest_Constructor:test_constructor() (gas: 29190)
L2StandardBridge_Test:test_L2BridgeCorrectL1Bridge() (gas: 9629)
OptimismPortal_Test:test_receive_withEthValueFromEOA() (gas: 24189)
WithdrawalsRelay_finalizeWithdrawalTransaction_Test:test_cannotVerifyInvalidProof() (gas: 43987)
WithdrawalsRelay_finalizeWithdrawalTransaction_Test:test_cannotVerifyRecentWithdrawal() (gas: 39686)
WithdrawalsRelay_finalizeWithdrawalTransaction_Test:test_verifyWithdrawal() (gas: 200132)
WithdrawalsRelay_finalizeWithdrawalTransaction_Test:test_cannotVerifyInvalidProof() (gas: 39599)
WithdrawalsRelay_finalizeWithdrawalTransaction_Test:test_cannotVerifyRecentWithdrawal() (gas: 35297)
WithdrawalsRelay_finalizeWithdrawalTransaction_Test:test_verifyWithdrawal() (gas: 192101)
WithdawerBurnTest:test_burn() (gas: 50276)
WithdrawerTestInitiateWithdrawal:test_initiateWithdrawal_fromContract() (gas: 72023)
WithdrawerTestInitiateWithdrawal:test_initiateWithdrawal_fromEOA() (gas: 72488)
2 changes: 1 addition & 1 deletion packages/contracts/contracts/L1/L2OutputOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.10;

/* Library Imports */
import { Ownable } from "../../lib/openzeppelin-contracts/contracts/access/Ownable.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";

/**
* @title L2OutputOracle
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/contracts/L1/abstracts/DepositFeed.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//SPDX-License-Identifier: MIT
pragma solidity 0.8.10;

import { IDepositFeed } from "./IDepositFeed.sol";

/* Library Imports */
import {
AddressAliasHelper
} from "../../../lib/optimism/packages/contracts/contracts/standards/AddressAliasHelper.sol";
import { AddressAliasHelper } from "@eth-optimism/contracts/standards/AddressAliasHelper.sol";

/**
* @title DepositFeed
* @notice Implements the logic for depositing from L1 to L2.
*/
abstract contract DepositFeed {
abstract contract DepositFeed is IDepositFeed {
/**********
* Errors *
**********/
Expand Down
11 changes: 11 additions & 0 deletions packages/contracts/contracts/L1/abstracts/IDepositFeed.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pragma solidity ^0.8.10;

interface IDepositFeed {
function depositTransaction(
address _to,
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
) external payable;
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ abstract contract WithdrawalsRelay {
bytes calldata _withdrawalProof
) external {
// Check that the timestamp is sufficiently finalized.
// The timestamp corresponds to a particular L2 output,
// so it is safe to be passed in by a user.
unchecked {
if (block.timestamp < _timestamp + FINALIZATION_PERIOD) {
revert NotYetFinal();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

/* Library Imports */
import { Lib_OVMCodec } from "@eth-optimism/contracts/libraries/codec/Lib_OVMCodec.sol";

/* Interface Imports */
import {
ICrossDomainMessenger
} from "@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol";

/**
* @title IL1CrossDomainMessenger
*/
interface IL1CrossDomainMessenger is ICrossDomainMessenger {
/*******************
* Data Structures *
*******************/

struct L2MessageInclusionProof {
bytes32 stateRoot;
Lib_OVMCodec.ChainBatchHeader stateRootBatchHeader;
Lib_OVMCodec.ChainInclusionProof stateRootProof;
bytes stateTrieWitness;
bytes storageTrieWitness;
}

/********************
* Public Functions *
********************/

/**
* Relays a cross domain message to a contract.
* @param _target Target contract address.
* @param _sender Message sender address.
* @param _message Message to send to the target.
* @param _messageNonce Nonce for the provided message.
*/
function relayMessage(
address _target,
address _sender,
bytes memory _message,
uint256 _messageNonce
) external;
}
Loading

0 comments on commit 0c05488

Please sign in to comment.