Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.
Closed
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
52 changes: 38 additions & 14 deletions packages/contracts/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DepositFeedTest:test_depositTransaction_ContractCreationReverts() (gas: 9290)
DepositFeedTest:test_depositTransaction_NoValueContract() (gas: 24388)
DepositFeedTest:test_depositTransaction_NoValueEOA() (gas: 24734)
DepositFeedTest:test_depositTransaction_createWithZeroValueForContract() (gas: 24451)
DepositFeedTest:test_depositTransaction_createWithZeroValueForContract() (gas: 24384)
DepositFeedTest:test_depositTransaction_createWithZeroValueForEOA() (gas: 24707)
DepositFeedTest:test_depositTransaction_withEthValueAndContractContractCreation() (gas: 31429)
DepositFeedTest:test_depositTransaction_withEthValueAndEOAContractCreation() (gas: 22859)
Expand All @@ -13,25 +13,39 @@ L1BLockTest:test_number() (gas: 7555)
L1BLockTest:test_sequenceNumber() (gas: 7577)
L1BLockTest:test_timestamp() (gas: 7587)
L1CrossDomainMessenger_Test:testCannot_pause() (gas: 10843)
L1CrossDomainMessenger_Test:test_blockAndUnblockSuccessfulMessage() (gas: 105412)
L1CrossDomainMessenger_Test:test_pause() (gas: 31793)
L1CrossDomainMessenger_Test:test_blockAndUnblockSuccessfulMessage() (gas: 105390)
L1CrossDomainMessenger_Test:test_pause() (gas: 31771)
L1CrossDomainMessenger_Test:test_relayMessageBlockingAuth() (gas: 18542)
L1CrossDomainMessenger_Test:test_relayMessageInsideFraudProofWindow() (gas: 12305)
L1CrossDomainMessenger_Test:test_relayMessageSucceeds() (gas: 82425)
L1CrossDomainMessenger_Test:test_relayMessageToSystemContract() (gas: 30160)
L1CrossDomainMessenger_Test:test_relayMessageToSystemContract() (gas: 30138)
L1CrossDomainMessenger_Test:test_relayRevertOnBlockedMessage() (gas: 55761)
L1CrossDomainMessenger_Test:test_relayShouldRevertIfPaused() (gas: 41560)
L1CrossDomainMessenger_Test:test_relayShouldRevertSendingSameMessageTwice() (gas: 188)
L1CrossDomainMessenger_Test:test_revertOnInvalidOutputRootProof() (gas: 16067)
L1CrossDomainMessenger_Test:test_sendMessage() (gas: 44041)
L1CrossDomainMessenger_Test:test_sendMessageTwice() (gas: 49061)
L1CrossDomainMessenger_Test:test_sendMessageTwice() (gas: 49039)
L1CrossDomainMessenger_Test:test_xDomainMessageSenderResets() (gas: 81565)
L1StandardBridge_Test:test_L1BridgeSetsPortalAndL2Bridge() (gas: 14825)
L1StandardBridge_Test:test_L1BridgeDepositERC20() (gas: 338228)
L1StandardBridge_Test:test_L1BridgeDepositERC20To() (gas: 340083)
L1StandardBridge_Test:test_L1BridgeDepositETH() (gas: 50372)
L1StandardBridge_Test:test_L1BridgeDepositETHTo() (gas: 52608)
L1StandardBridge_Test:test_L1BridgeDonateETH() (gas: 17478)
L1StandardBridge_Test:test_L1BridgeFinalizeERC20Withdrawal() (gas: 434878)
L1StandardBridge_Test:test_L1BridgeFinalizeETHWithdrawal() (gas: 43863)
L1StandardBridge_Test:test_L1BridgeOnlyEOADepositERC20() (gas: 29789)
L1StandardBridge_Test:test_L1BridgeOnlyEOADepositETH() (gas: 35476)
L1StandardBridge_Test:test_L1BridgeOnlyL2BridgeFinalizeERC20Withdrawal() (gas: 25010)
L1StandardBridge_Test:test_L1BridgeOnlyL2BridgeFinalizeETHWithdrawal() (gas: 27791)
L1StandardBridge_Test:test_L1BridgeOnlyPortalFinalizeERC20Withdrawal() (gas: 17585)
L1StandardBridge_Test:test_L1BridgeOnlyPortalFinalizeETHWithdrawal() (gas: 19901)
L1StandardBridge_Test:test_L1BridgeReceiveETH() (gas: 48287)
L1StandardBridge_Test:test_L1BridgeSetsPortalAndL2Bridge() (gas: 14892)
L2CrossDomainMessenger_Test:test_L2MessengerCallsTarget() (gas: 64095)
L2CrossDomainMessenger_Test:test_L2MessengerCannotCallL2MessagePasser() (gas: 42128)
L2CrossDomainMessenger_Test:test_L2MessengerCannotRelaySameMessageTwice() (gas: 67491)
L2CrossDomainMessenger_Test:test_L2MessengerCorrectL1Messenger() (gas: 9762)
L2CrossDomainMessenger_Test:test_L2MessengerRevertInvalidL1XDomainMessenger() (gas: 11535)
L2CrossDomainMessenger_Test:test_L2MessengerRevertInvalidL1XDomainMessenger() (gas: 11557)
L2CrossDomainMessenger_Test:test_L2MessengerSendMessage() (gas: 122584)
L2CrossDomainMessenger_Test:test_L2MessengerSendSameMessageTwice() (gas: 162903)
L2CrossDomainMessenger_Test:test_L2MessengerXDomainMessageSenderReset() (gas: 69285)
Expand All @@ -41,21 +55,31 @@ L2OutputOracleTest:testCannot_appendEmptyOutput() (gas: 16724)
L2OutputOracleTest:testCannot_appendFutureTimestamp() (gas: 18642)
L2OutputOracleTest:testCannot_appendOutputIfNotSequencer() (gas: 16088)
L2OutputOracleTest:testCannot_appendUnexpectedTimestamp() (gas: 18893)
L2OutputOracleTest:testCannot_computePreHistoricalL2BlockNumber() (gas: 11048)
L2OutputOracleTest:testCannot_computePreHistoricalL2BlockNumber() (gas: 11070)
L2OutputOracleTest:testCannot_deleteL2Output_ifNotSequencer() (gas: 16287)
L2OutputOracleTest:testCannot_deleteL2Output_ifWrongOutput() (gas: 23243)
L2OutputOracleTest:test_appendingAnotherOutput() (gas: 47332)
L2OutputOracleTest:test_computeL2BlockNumber() (gas: 15003)
L2OutputOracleTest:test_deleteL2Output() (gas: 30647)
L2OutputOracleTest:test_getL2Output() (gas: 15071)
L2OutputOracleTest:test_getL2Output() (gas: 15093)
L2OutputOracleTest:test_latestBlockTimestamp() (gas: 9699)
L2OutputOracleTest:test_nextTimestamp() (gas: 12031)
L2OutputOracleTest:test_nextTimestamp() (gas: 12053)
L2OutputOracleTest_Constructor:test_constructor() (gas: 29173)
L2StandardBridge_Test:test_L2BridgeCorrectL1Bridge() (gas: 9726)
L2StandardBridge_Test:test_L2BridgeBadDeposit() (gas: 89330)
L2StandardBridge_Test:test_L2BridgeCorrectL1Bridge() (gas: 9727)
L2StandardBridge_Test:test_L2BridgeFinalizeDeposit() (gas: 56204)
L2StandardBridge_Test:test_L2BridgeFinalizeDepositRevertsOnCaller() (gas: 13753)
L2StandardBridge_Test:test_L2BridgeFinalizeETHDeposit() (gas: 39194)
L2StandardBridge_Test:test_L2BridgeFinalizeETHDepositWrongAmount() (gas: 100057)
L2StandardBridge_Test:test_L2BridgeRevertWithdraw() (gas: 20447)
L2StandardBridge_Test:test_L2BridgeRevertWithdrawETH() (gas: 11632)
L2StandardBridge_Test:test_L2BridgeWithdraw() (gas: 111806)
L2StandardBridge_Test:test_L2BridgeWithdrawETH() (gas: 95606)
L2StandardBridge_Test:test_L2BridgeWithdrawTo() (gas: 114318)
OptimismPortal_Test:test_receive_withEthValueFromEOA() (gas: 21979)
WithdrawalsRelay_finalizeWithdrawalTransaction_Test:test_cannotVerifyInvalidProof() (gas: 37418)
WithdrawalsRelay_finalizeWithdrawalTransaction_Test:test_cannotVerifyRecentWithdrawal() (gas: 33219)
WithdrawalsRelay_finalizeWithdrawalTransaction_Test:test_verifyWithdrawal() (gas: 190048)
WithdrawalsRelay_finalizeWithdrawalTransaction_Test:test_cannotVerifyInvalidProof() (gas: 37415)
WithdrawalsRelay_finalizeWithdrawalTransaction_Test:test_cannotVerifyRecentWithdrawal() (gas: 33241)
WithdrawalsRelay_finalizeWithdrawalTransaction_Test:test_verifyWithdrawal() (gas: 190003)
WithdawerBurnTest:test_burn() (gas: 50276)
WithdrawerTestInitiateWithdrawal:test_initiateWithdrawal_fromContract() (gas: 71990)
WithdrawerTestInitiateWithdrawal:test_initiateWithdrawal_fromEOA() (gas: 72475)
104 changes: 104 additions & 0 deletions packages/contracts/contracts/L1/messaging/IL1ERC20Bridge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// SPDX-License-Identifier: MIT
pragma solidity >0.5.0 <0.9.0;

/**
* @title IL1ERC20Bridge
*/
interface IL1ERC20Bridge {
/**********
* Events *
**********/

event ERC20DepositInitiated(
address indexed _l1Token,
address indexed _l2Token,
address indexed _from,
address _to,
uint256 _amount,
bytes _data
);

event ERC20WithdrawalFinalized(
address indexed _l1Token,
address indexed _l2Token,
address indexed _from,
address _to,
uint256 _amount,
bytes _data
);

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

/**
* @dev get the address of the corresponding L2 bridge contract.
* @return Address of the corresponding L2 bridge contract.
*/
function l2TokenBridge() external returns (address);

/**
* @dev deposit an amount of the ERC20 to the caller's balance on L2.
* @param _l1Token Address of the L1 ERC20 we are depositing
* @param _l2Token Address of the L1 respective L2 ERC20
* @param _amount Amount of the ERC20 to deposit
* @param _l2Gas Gas limit required to complete the deposit on L2.
* @param _data Optional data to forward to L2. This data is provided
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function depositERC20(
address _l1Token,
address _l2Token,
uint256 _amount,
uint32 _l2Gas,
bytes calldata _data
) external;

/**
* @dev deposit an amount of ERC20 to a recipient's balance on L2.
* @param _l1Token Address of the L1 ERC20 we are depositing
* @param _l2Token Address of the L1 respective L2 ERC20
* @param _to L2 address to credit the withdrawal to.
* @param _amount Amount of the ERC20 to deposit.
* @param _l2Gas Gas limit required to complete the deposit on L2.
* @param _data Optional data to forward to L2. This data is provided
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function depositERC20To(
address _l1Token,
address _l2Token,
address _to,
uint256 _amount,
uint32 _l2Gas,
bytes calldata _data
) external;

/*************************
* Cross-chain Functions *
*************************/

/**
* @dev Complete a withdrawal from L2 to L1, and credit funds to the recipient's balance of the
* L1 ERC20 token.
* This call will fail if the initialized withdrawal from L2 has not been finalized.
*
* @param _l1Token Address of L1 token to finalizeWithdrawal for.
* @param _l2Token Address of L2 token where withdrawal was initiated.
* @param _from L2 address initiating the transfer.
* @param _to L1 address to credit the withdrawal to.
* @param _amount Amount of the ERC20 to deposit.
* @param _data Data provided by the sender on L2. This data is provided
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function finalizeERC20Withdrawal(
address _l1Token,
address _l2Token,
address _from,
address _to,
uint256 _amount,
bytes calldata _data
) external;
}
75 changes: 75 additions & 0 deletions packages/contracts/contracts/L1/messaging/IL1StandardBridge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// SPDX-License-Identifier: MIT
pragma solidity >0.5.0 <0.9.0;

import "./IL1ERC20Bridge.sol";

/**
* @title IL1StandardBridge
*/
interface IL1StandardBridge is IL1ERC20Bridge {
/**********
* Events *
**********/
event ETHDepositInitiated(
address indexed _from,
address indexed _to,
uint256 _amount,
bytes _data
);

event ETHWithdrawalFinalized(
address indexed _from,
address indexed _to,
uint256 _amount,
bytes _data
);

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

/**
* @dev Deposit an amount of the ETH to the caller's balance on L2.
* @param _l2Gas Gas limit required to complete the deposit on L2.
* @param _data Optional data to forward to L2. This data is provided
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function depositETH(uint32 _l2Gas, bytes calldata _data) external payable;

/**
* @dev Deposit an amount of ETH to a recipient's balance on L2.
* @param _to L2 address to credit the withdrawal to.
* @param _l2Gas Gas limit required to complete the deposit on L2.
* @param _data Optional data to forward to L2. This data is provided
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function depositETHTo(
address _to,
uint32 _l2Gas,
bytes calldata _data
) external payable;

/*************************
* Cross-chain Functions *
*************************/

/**
* @dev Complete a withdrawal from L2 to L1, and credit funds to the recipient's balance of the
* L1 ETH token. Since only the xDomainMessenger can call this function, it will never be called
* before the withdrawal is finalized.
* @param _from L2 address initiating the transfer.
* @param _to L1 address to credit the withdrawal to.
* @param _amount Amount of the ERC20 to deposit.
* @param _data Optional data to forward to L2. This data is provided
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function finalizeETHWithdrawal(
address _from,
address _to,
uint256 _amount,
bytes calldata _data
) external payable;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ import {
/**
* @title L1CrossDomainMessenger
* @dev The L1 Cross Domain Messenger contract sends messages from L1 to L2, and relays messages
* from L2 onto L1. In the event that a message sent from L1 to L2 is rejected for exceeding the L2
* epoch gas limit, it can be resubmitted via this contract's replay function.
*
* from L2 onto L1.
*/
contract L1CrossDomainMessenger is
IL1CrossDomainMessenger,
Expand Down
31 changes: 23 additions & 8 deletions packages/contracts/contracts/L1/messaging/L1StandardBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
pragma solidity ^0.8.9;

/* Interface Imports */
import { IL1StandardBridge } from "@eth-optimism/contracts/L1/messaging/IL1StandardBridge.sol";
import { IL1ERC20Bridge } from "@eth-optimism/contracts/L1/messaging/IL1ERC20Bridge.sol";
import { IL2ERC20Bridge } from "@eth-optimism/contracts/L2/messaging/IL2ERC20Bridge.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { OptimismPortal } from "../OptimismPortal.sol";
import { IL1StandardBridge } from "./IL1StandardBridge.sol";
import { IL1ERC20Bridge } from "./IL1ERC20Bridge.sol";

/* Library Imports */
import {
Expand Down Expand Up @@ -77,14 +77,14 @@ contract L1StandardBridge is IL1StandardBridge {
* default amount is forwarded to L2.
*/
receive() external payable onlyEOA {
_initiateETHDeposit(msg.sender, msg.sender, 200_000, bytes(""));
_initiateETHDeposit(msg.sender, msg.sender, msg.value, 200_000, bytes(""));
}

/**
* @inheritdoc IL1StandardBridge
*/
function depositETH(uint32 _l2Gas, bytes calldata _data) external payable onlyEOA {
_initiateETHDeposit(msg.sender, msg.sender, _l2Gas, _data);
_initiateETHDeposit(msg.sender, msg.sender, msg.value, _l2Gas, _data);
}

/**
Expand All @@ -95,7 +95,7 @@ contract L1StandardBridge is IL1StandardBridge {
uint32 _l2Gas,
bytes calldata _data
) external payable {
_initiateETHDeposit(msg.sender, _to, _l2Gas, _data);
_initiateETHDeposit(msg.sender, _to, msg.value, _l2Gas, _data);
}

/**
Expand All @@ -111,13 +111,28 @@ contract L1StandardBridge is IL1StandardBridge {
function _initiateETHDeposit(
address _from,
address _to,
uint256 _amount,
uint32 _l2Gas,
bytes memory _data
) internal {
emit ETHDepositInitiated(_from, _to, msg.value, _data);
emit ETHDepositInitiated(_from, _to, _amount, _data);

// Send calldata into L2
optimismPortal.depositTransaction{ value: msg.value }(_to, msg.value, _l2Gas, false, _data);
optimismPortal.depositTransaction{ value: _amount }(
Lib_PredeployAddresses.L2_STANDARD_BRIDGE,
_amount,
_l2Gas,
false,
abi.encodeWithSelector(
IL2ERC20Bridge.finalizeDeposit.selector,
address(0),
Lib_PredeployAddresses.OVM_ETH,
_from,
_to,
_amount,
_data
)
);
}

/**
Expand Down Expand Up @@ -231,7 +246,7 @@ contract L1StandardBridge is IL1StandardBridge {
address _to,
uint256 _amount,
bytes calldata _data
) external onlyL2Bridge {
) external payable onlyL2Bridge {
emit ETHWithdrawalFinalized(_from, _to, _amount, _data);

(bool success, ) = _to.call{ value: _amount }(new bytes(0));
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/contracts/L2/messaging/IL2ERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface IL2ERC20Bridge {
uint256 _amount,
uint32 _l1Gas,
bytes calldata _data
) external;
) external payable;

/**
* @dev initiate a withdraw of some token to a recipient's account on L1.
Expand All @@ -78,7 +78,7 @@ interface IL2ERC20Bridge {
uint256 _amount,
uint32 _l1Gas,
bytes calldata _data
) external;
) external payable;

/*************************
* Cross-chain Functions *
Expand All @@ -104,5 +104,5 @@ interface IL2ERC20Bridge {
address _to,
uint256 _amount,
bytes calldata _data
) external;
) external payable;
}
Loading