Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
Fix issues in L1 and L2 bridges to ensure
Browse files Browse the repository at this point in the history
cross domain messages are sent only between the two bridges
also adjusted withdrawals to send to either finalizeETHWithdrawal or finalizeERC20Withdrawal
depending on which asset is being withdrawn
  • Loading branch information
elenadimitrova authored and maurelian committed Jun 5, 2021
1 parent 23fc0d5 commit 0707d2b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ contract OVM_L1StandardBridge is iOVM_L1StandardBridge, OVM_CrossDomainEnabled,

// Send calldata into L2
sendCrossDomainMessage(
ovmEth,
l2TokenBridge,
_l2Gas,
message
);
Expand Down Expand Up @@ -255,7 +255,7 @@ contract OVM_L1StandardBridge is iOVM_L1StandardBridge, OVM_CrossDomainEnabled,

// Send calldata into L2
sendCrossDomainMessage(
_l2Token,
l2TokenBridge,
_l2Gas,
message
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ pragma solidity >0.5.0 <0.8.0;
pragma experimental ABIEncoderV2;

/* Interface Imports */
import { iOVM_L1StandardBridge } from "../../../iOVM/bridge/tokens/iOVM_L1StandardBridge.sol";
import { iOVM_L1ERC20Bridge } from "../../../iOVM/bridge/tokens/iOVM_L1ERC20Bridge.sol";
import { iOVM_L2ERC20Bridge } from "../../../iOVM/bridge/tokens/iOVM_L2ERC20Bridge.sol";

/* Library Imports */
import { OVM_CrossDomainEnabled } from "../../../libraries/bridge/OVM_CrossDomainEnabled.sol";
import { Lib_PredeployAddresses } from "../../../libraries/constants/Lib_PredeployAddresses.sol";

/* Contract Imports */
import { L2StandardERC20 } from "../../../libraries/standards/L2StandardERC20.sol";
Expand Down Expand Up @@ -125,15 +127,28 @@ contract OVM_L2StandardBridge is iOVM_L2ERC20Bridge, OVM_CrossDomainEnabled {

// Construct calldata for l1TokenBridge.finalizeERC20Withdrawal(_to, _amount)
address l1Token = L2StandardERC20(_l2Token).l1Token();
bytes memory message = abi.encodeWithSelector(
iOVM_L1ERC20Bridge.finalizeERC20Withdrawal.selector,
l1Token,
_l2Token,
_from,
_to,
_amount,
_data
);
bytes memory message;

if (_l2Token == Lib_PredeployAddresses.OVM_ETH) {
// do we need to require that the l1 token is 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE ? Probably not
message = abi.encodeWithSelector(
iOVM_L1StandardBridge.finalizeETHWithdrawal.selector,
_from,
_to,
_amount,
_data
);
} else {
message = abi.encodeWithSelector(
iOVM_L1ERC20Bridge.finalizeERC20Withdrawal.selector,
l1Token,
_l2Token,
_from,
_to,
_amount,
_data
);
}

// Send message up to L1 bridge
sendCrossDomainMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ describe('OVM_L1StandardBridge', () => {
expect(bridgeBalance).to.equal(depositAmount)

// Check the correct cross-chain call was sent:
// Message should be sent to the L2ETHToken on L2
expect(depositCallToMessenger._target).to.equal(Mock__OVM_ETH.address)
// Message should be sent to the L2 bridge
expect(depositCallToMessenger._target).to.equal(DUMMY_L2_BRIDGE_ADDRESS)
// Message data should be a call telling the L2ETHToken to finalize the deposit

// the L1 bridge sends the correct message to the L1 messenger
Expand Down Expand Up @@ -181,8 +181,8 @@ describe('OVM_L1StandardBridge', () => {
expect(bridgeBalance).to.equal(depositAmount)

// Check the correct cross-chain call was sent:
// Message should be sent to the L2ETHToken on L2
expect(depositCallToMessenger._target).to.equal(Mock__OVM_ETH.address)
// Message should be sent to the L2 bridge
expect(depositCallToMessenger._target).to.equal(DUMMY_L2_BRIDGE_ADDRESS)
// Message data should be a call telling the L2ETHToken to finalize the deposit

// the L1 bridge sends the correct message to the L1 messenger
Expand Down Expand Up @@ -363,8 +363,8 @@ describe('OVM_L1StandardBridge', () => {
expect(bridgeBalance).to.equal(depositAmount)

// Check the correct cross-chain call was sent:
// Message should be sent to the L2DepositedERC20 on L2
expect(depositCallToMessenger._target).to.equal(DUMMY_L2_ERC20_ADDRESS)
// Message should be sent to the L2 bridge
expect(depositCallToMessenger._target).to.equal(DUMMY_L2_BRIDGE_ADDRESS)
// Message data should be a call telling the L2DepositedERC20 to finalize the deposit

// the L1 bridge sends the correct message to the L1 messenger
Expand Down Expand Up @@ -407,7 +407,7 @@ describe('OVM_L1StandardBridge', () => {

// Check the correct cross-chain call was sent:
// Message should be sent to the L2DepositedERC20 on L2
expect(depositCallToMessenger._target).to.equal(DUMMY_L2_ERC20_ADDRESS)
expect(depositCallToMessenger._target).to.equal(DUMMY_L2_BRIDGE_ADDRESS)
// Message data should be a call telling the L2DepositedERC20 to finalize the deposit

// the L1 bridge sends the correct message to the L1 messenger
Expand Down

0 comments on commit 0707d2b

Please sign in to comment.