Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Add wormhole bridge #59

Open
wants to merge 69 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
00158b8
Add prototype of wormhole bridge
krzkaczor Nov 9, 2021
06ce967
Start extracting WormholeGUID lib
krzkaczor Nov 12, 2021
e099a69
Extract WormholeGUID as lib
krzkaczor Nov 16, 2021
b76d3e6
Remove close features
krzkaczor Nov 16, 2021
849942f
Update interfaces
krzkaczor Nov 19, 2021
795e4da
Update contract name
krzkaczor Nov 22, 2021
3752c0c
Add basic test scaffolding
krzkaczor Nov 22, 2021
8d6a8f1
Adjust import paths
krzkaczor Nov 22, 2021
a65eb79
Add flush() test
krzkaczor Nov 23, 2021
49a2ea4
Fix code review comments
krzkaczor Nov 30, 2021
91716f2
Rename methods
olivdb Dec 2, 2021
be6b7c4
Merge pull request #62 from makerdao/oli/wormhole-bridge-fix
olivdb Dec 2, 2021
5c094ce
Address Sam's review comments
olivdb Dec 10, 2021
77284b7
Remove unused WormholeLib.getHash
olivdb Dec 10, 2021
c5a512a
Remove unused dependency
olivdb Dec 10, 2021
bfe5d03
Let flush be callable for 0 DAI settlements
olivdb Dec 10, 2021
618e27f
Merge pull request #63 from makerdao/oli/wh-bridge-fix
olivdb Dec 14, 2021
a308ec5
Add initWormhole tests
olivdb Dec 14, 2021
08993ac
Remove unused auth from L2DaiWormholeBridge
olivdb Dec 14, 2021
40a9391
Add L2DaiWormholeBridge tests
olivdb Dec 14, 2021
380fd86
Remove unused auth from L1DAIWormholeBridge
olivdb Dec 14, 2021
bf13328
Fix and tests for L1DAIWormholeBridge
olivdb Dec 15, 2021
5e18600
Rename constants
olivdb Dec 16, 2021
2754466
Add comments
olivdb Dec 17, 2021
b01234d
Revert "Remove unused auth from L2DaiWormholeBridge"
olivdb Dec 17, 2021
49df71b
Add close() to L2DaiWormholeBridge + auth tests
olivdb Dec 17, 2021
83a82e2
Remove mocking of router DAI transfer
olivdb Dec 17, 2021
b50934d
Add xchain revert tests to L1DAIWOrmholeBridge
olivdb Dec 17, 2021
9923b09
Add check for L1DAIWormholeBridge constructor
olivdb Dec 17, 2021
b2621cf
Cleanup
olivdb Dec 17, 2021
595cdec
Merge pull request #64 from makerdao/oli/moar-tests
olivdb Dec 17, 2021
2c3fbbc
Restrict Flush and Add Target Domain Whitelist (#65)
hexonaut Dec 17, 2021
eae61d7
Index targetDomain in Flushed event
olivdb Jan 4, 2022
24e8492
Merge pull request #67 from makerdao/oli/audit-fix
olivdb Jan 5, 2022
73d0e18
Add coverage
olivdb Jan 11, 2022
c924762
Improve L2DaiWormholeBridge coverage
olivdb Jan 11, 2022
ea97e16
Add coverage command
olivdb Jan 11, 2022
e92acb7
Skip test directory
olivdb Jan 11, 2022
212ffeb
Add domain separator test for l2Dai
olivdb Jan 11, 2022
906ea39
Add istanbul checks
olivdb Jan 11, 2022
8c9b9b0
Archive coverage artifacts
olivdb Jan 11, 2022
d2c41f9
Merge pull request #69 from makerdao/oli/coverage
olivdb Jan 12, 2022
bcac2da
Fix approve interface
olivdb Jan 13, 2022
f0e688c
Address slither issues
olivdb Jan 13, 2022
5086ac2
Merge pull request #70 from makerdao/oli/interface-fix
olivdb Jan 13, 2022
50fad1e
Change address to bytes32 in WormholeGUID struct
krzkaczor Jan 13, 2022
ce61379
Merge pull request #71 from makerdao/kk/address-bytes32
krzkaczor Jan 14, 2022
46a3656
Optimize calldata for common cases
krzkaczor Jan 19, 2022
6aba333
Merge pull request #72 from makerdao/kk/optimize-calldata
krzkaczor Jan 20, 2022
8bc48a8
Update router interface
krzkaczor Jan 25, 2022
50635b2
Merge pull request #73 from makerdao/kk/update-interface
krzkaczor Jan 25, 2022
680a536
Remove operator fee
krzkaczor Jan 28, 2022
c11e87b
Merge pull request #74 from makerdao/kk/remove-operator-fee
krzkaczor Jan 28, 2022
cd35af7
Revert "Remove operator fee"
krzkaczor Feb 3, 2022
a03f13a
Merge pull request #75 from makerdao/kk/operator-fee
krzkaczor Feb 3, 2022
e1c7698
Fix router interface
olivdb Feb 16, 2022
4f93de2
Merge pull request #77 from makerdao/update-router-interface
olivdb Feb 16, 2022
da0c874
Adjust naming of l1 wormhole public variables
krzkaczor Mar 9, 2022
5318012
Merge pull request #78 from makerdao/kk/adjust-naming
krzkaczor Mar 10, 2022
6a4c301
Extract interfaces for L1
krzkaczor Mar 17, 2022
676c343
Extract interfaces for L2
krzkaczor Mar 17, 2022
cd3aecc
Tweak router interface name
krzkaczor Mar 17, 2022
962ece1
Rename WormholeBridge to WormholeGateway
krzkaczor Mar 17, 2022
adc8723
Move slither changes
krzkaczor Mar 17, 2022
1cf3ea0
Merge pull request #79 from makerdao/kk/extract-common-interfaces
krzkaczor Mar 17, 2022
6adcb7b
Rename wormhole gateway to LxDaiWormholeGateway
krzkaczor Mar 20, 2022
9907e06
Merge pull request #80 from makerdao/kk/rename-wormhole-gateway
krzkaczor Mar 21, 2022
30d7d57
Add readme security note
krzkaczor Apr 26, 2022
d20e538
Merge pull request #82 from makerdao/kk/security-note
krzkaczor May 12, 2022
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
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"no-tabs": "error",
"no-this-before-super": "error",
"no-throw-literal": "error",
"no-unexpected-multiline": "error",
"no-unexpected-multiline": "off",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": [
"error",
Expand Down
49 changes: 0 additions & 49 deletions .github/workflows/check.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/slither.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Slither

on:
push:
branches:
- master
pull_request:

jobs:
analyze:
name: Slither
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Run Slither
uses: crytic/[email protected]
with:
node-version: 12
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ jobs:
- run: yarn codechecks # compares gas report
env: # Or as an environment variable
CC_SECRET: ${{ secrets.CC_SECRET }}
- run: yarn coverage
- name: Archive code coverage results
uses: actions/upload-artifact@v2
with:
name: code-coverage-artifacts
path: |
coverage
coverage.json

test-e2e:
name: Tests E2E
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ artifacts-ovm
cache-ovm
.env
gasReporterOutput.json
coverage*

# echidna
crytic-export/
Expand Down
5 changes: 5 additions & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
measureStatementCoverage: false,
measureFunctionCoverage: false,
skipFiles: ['test'],
}
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
[![Lint](https://github.com/makerdao/optimism-dai-bridge/actions/workflows/lint.yml/badge.svg)](https://github.com/makerdao/optimism-dai-bridge/actions/workflows/lint.yml)
[![Check](https://github.com/makerdao/optimism-dai-bridge/actions/workflows/check.yml/badge.svg)](https://github.com/makerdao/optimism-dai-bridge/actions/workflows/check.yml)
[![Slither](https://github.com/makerdao/optimism-dai-bridge/actions/workflows/slither.yml/badge.svg)](https://github.com/makerdao/optimism-dai-bridge/actions/workflows/slither.yml)
[![Tests](https://github.com/makerdao/optimism-dai-bridge/actions/workflows/tests.yml/badge.svg)](https://github.com/makerdao/optimism-dai-bridge/actions/workflows/tests.yml)
[![Fuzz](https://github.com/makerdao/optimism-dai-bridge/actions/workflows/fuzz.yml/badge.svg)](https://github.com/makerdao/optimism-dai-bridge/actions/workflows/fuzz.yml)

# Optimism Dai Bridge

Optimism Dai and upgradable token bridge

## Security

Smart contracts stored in this repository are part of the bug bounty. To disclose any vulnerability please refer to the
[bug bounty page](https://immunefi.com/bounty/makerdao/).

## Contracts

- `dai.sol` - Improved DAI contract.
Expand Down Expand Up @@ -137,13 +142,16 @@ Run `yarn test:fix` to run linting in fix mode, auto-formatting and unit tests.

Running `yarn test` makes sure that contracts are compiled. Running `yarn test-e2e` doesn't.

Run `yarn coverage` to run solidity-coverage.

## Fuzzing

### Install Echidna

- Precompiled Binaries (recommended)

Before starting, make sure Slither is installed:

```
$ pip3 install slither-analyzer
```
Expand Down
36 changes: 36 additions & 0 deletions contracts/common/WormholeGUID.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2021 Dai Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

pragma solidity >=0.7.6;

// Standard Maker Wormhole GUID
struct WormholeGUID {
bytes32 sourceDomain;
bytes32 targetDomain;
bytes32 receiver;
bytes32 operator;
uint128 amount;
uint80 nonce;
uint48 timestamp;
}

function bytes32ToAddress(bytes32 addr) pure returns (address) {
return address(uint160(uint256(addr)));
}

function addressToBytes32(address addr) pure returns (bytes32) {
return bytes32(uint256(uint160(addr)));
}
76 changes: 76 additions & 0 deletions contracts/common/WormholeInterfaces.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2021 Dai Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

pragma solidity >=0.7.6;
pragma abicoder v2;
import {WormholeGUID} from "./WormholeGUID.sol";

interface IL1WormholeRouter {
function requestMint(
WormholeGUID calldata wormholeGUID,
uint256 maxFeePercentage,
uint256 operatorFee
) external returns (uint256 postFeeAmount, uint256 totalFee);

function settle(bytes32 targetDomain, uint256 batchedDaiToFlush) external;
}

interface IL1WormholeGateway {
function l1Token() external view returns (address);

function l1Escrow() external view returns (address);

function l1WormholeRouter() external view returns (IL1WormholeRouter);

function l2WormholeGateway() external view returns (address);

function finalizeFlush(bytes32 targetDomain, uint256 daiToFlush) external;

function finalizeRegisterWormhole(WormholeGUID calldata wormhole) external;
}

interface IL2WormholeGateway {
event WormholeInitialized(WormholeGUID wormhole);
event Flushed(bytes32 indexed targetDomain, uint256 dai);

function l2Token() external view returns (address);

function l1WormholeGateway() external view returns (address);

function domain() external view returns (bytes32);

function initiateWormhole(
bytes32 targetDomain,
address receiver,
uint128 amount
) external;

function initiateWormhole(
bytes32 targetDomain,
address receiver,
uint128 amount,
address operator
) external;

function initiateWormhole(
bytes32 targetDomain,
bytes32 receiver,
uint128 amount,
bytes32 operator
) external;

function flush(bytes32 targetDomain) external;
}
75 changes: 75 additions & 0 deletions contracts/l1/L1DaiWormholeGateway.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2021 Dai Foundation
// @unsupported: ovm
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

pragma solidity >=0.7.6;
pragma abicoder v2;

import {iOVM_L1ERC20Bridge} from "@eth-optimism/contracts/iOVM/bridge/tokens/iOVM_L1ERC20Bridge.sol";
import {iOVM_L2ERC20Bridge} from "@eth-optimism/contracts/iOVM/bridge/tokens/iOVM_L2ERC20Bridge.sol";
import {OVM_CrossDomainEnabled} from "@eth-optimism/contracts/libraries/bridge/OVM_CrossDomainEnabled.sol";
import {WormholeGUID} from "../common/WormholeGUID.sol";
import {IL1WormholeGateway, IL1WormholeRouter} from "../common/WormholeInterfaces.sol";

interface TokenLike {
function approve(address, uint256) external returns (bool);

function transferFrom(
address _from,
address _to,
uint256 _value
) external returns (bool success);
}

contract L1DaiWormholeGateway is OVM_CrossDomainEnabled, IL1WormholeGateway {
address public immutable override l1Token;
address public immutable override l2WormholeGateway;
address public immutable override l1Escrow;
IL1WormholeRouter public immutable override l1WormholeRouter;

constructor(
address _l1Token,
address _l2WormholeGateway,
address _l1Messenger,
address _l1Escrow,
address _l1WormholeRouter
) OVM_CrossDomainEnabled(_l1Messenger) {
l1Token = _l1Token;
l2WormholeGateway = _l2WormholeGateway;
l1Escrow = _l1Escrow;
l1WormholeRouter = IL1WormholeRouter(_l1WormholeRouter);
// Approve the router to pull DAI from this contract during settle() (after the DAI has been pulled by this contract from the escrow)
TokenLike(_l1Token).approve(_l1WormholeRouter, type(uint256).max);
}

function finalizeFlush(bytes32 targetDomain, uint256 daiToFlush)
external
override
onlyFromCrossDomainAccount(l2WormholeGateway)
{
// Pull DAI from the escrow to this contract
TokenLike(l1Token).transferFrom(l1Escrow, address(this), daiToFlush);
// The router will pull the DAI from this contract
l1WormholeRouter.settle(targetDomain, daiToFlush);
}

function finalizeRegisterWormhole(WormholeGUID calldata wormhole)
external
override
onlyFromCrossDomainAccount(l2WormholeGateway)
{
l1WormholeRouter.requestMint(wormhole, 0, 0);
}
}
Loading