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

Standard token bridge #988

Merged
merged 97 commits into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
358b351
Remove abstract token gateway and deposited token implementations
elenadimitrova May 28, 2021
ff2ee60
Further simplification of bridge contracts
elenadimitrova May 28, 2021
2a2031e
Standart token bridge and L2 token implementation
elenadimitrova May 31, 2021
11d71b0
Fix spacing
elenadimitrova May 31, 2021
2dfdf00
Implement case when a bad deposit happens to a nonexistent L1<>L2 tok…
elenadimitrova May 31, 2021
b979dee
Use SafeMath in common token bridge accounting
elenadimitrova May 31, 2021
da670bc
test(contracts): fix finalizeWithdrawal test
maurelian Jun 1, 2021
ce8071b
fix(contracts): use SafeERC20 on token deposits
maurelian Jun 1, 2021
55da41e
Rename OVM_L1ERC20Gateway to OVM_L1ERC20Bridge contract
elenadimitrova Jun 1, 2021
c51a13f
Rename iOVM_L1ERC20Gateway to iOVM_L1ERC20Bridge contract
elenadimitrova Jun 1, 2021
57fe141
Cleanup gateway to bridge rename
elenadimitrova Jun 1, 2021
bd663b0
Better name for the mapping holding l1->l2 deposit amounts
elenadimitrova Jun 1, 2021
0c54793
Use OZ SafeMath
elenadimitrova Jun 1, 2021
24798d4
Rename local variables in OVM_L2DepositedERC20 from gateway to bridge
elenadimitrova Jun 1, 2021
7e4a404
Merge ETH and ERC20 bridge contracts
elenadimitrova Jun 2, 2021
b4c99c4
Rename OVM_L1ERC20Bridge to OVM_L1StandardBridge and fix tests from m…
elenadimitrova Jun 2, 2021
959f638
Better name for iAbs_BaseCrossDomainMessenger -> iOVM_CrossDomainMess…
elenadimitrova Jun 2, 2021
37bc32a
Correct the bounce back of deposit sender and recipient properties
elenadimitrova Jun 2, 2021
d6e9d8b
Remove obsoleted event from OVM_L2DepositedERC20
elenadimitrova Jun 2, 2021
bcc3d5e
chore(contracts): change references from ETHGateway to Bridge
maurelian Jun 2, 2021
2ad7ba0
Fix a linting error
elenadimitrova Jun 2, 2021
a1bc46e
fix(contracts): add bridge to deployer
maurelian Jun 2, 2021
11d5b95
Split off ERC20Bridge interface for the purposes
elenadimitrova Jun 3, 2021
68277c9
Split off interface natspec definitions
elenadimitrova Jun 3, 2021
e0bdbf0
Draft version of OVM_L2DepositedERC20 splitted into a standard L2 erc…
elenadimitrova Jun 3, 2021
cf8efa3
style(contracts): define L1_ETH_ADDRESS as constant
maurelian Jun 3, 2021
8199da4
test(integration): update interface to use depositETH
maurelian Jun 3, 2021
c7d5618
test(contracts): fix OVM_L1StandardBridge tests
maurelian Jun 4, 2021
44f2171
test(contracts): fix L2 Standard Bridge tests
maurelian Jun 4, 2021
563f1f2
test(contracts): lint and remove an obsolete test case
maurelian Jun 4, 2021
43bd46c
Fix modifier check to comply with the L2 bridge distinction from L2 t…
elenadimitrova Jun 4, 2021
6494a0b
Simplify address <> interface casting in bridges
elenadimitrova Jun 4, 2021
1d082ec
Ensure natspec comments are correct
elenadimitrova Jun 4, 2021
579fdd4
Fix issues in L1 and L2 bridges to ensure
elenadimitrova Jun 4, 2021
e8c37d2
Remove AddressManager from the L1 standard bridge
elenadimitrova Jun 4, 2021
b748d0a
REVERT ME: instruments cross domain enabled
maurelian Jun 4, 2021
415a8a9
fix(contracts): remove Address Manager from L1 Bridge
maurelian Jun 4, 2021
99bfc07
feat(contracts): make L2 Standard Bridge a predeploy
maurelian Jun 4, 2021
842453c
WIP: update deployments for standard bridges
maurelian Jun 4, 2021
0b572f3
WIP: update deployments for standard bridges
maurelian Jun 4, 2021
25862b8
l2geth: TEMP log contract calls
tynes May 26, 2021
d41ec59
chore(l2geth): replace eth gateway with standard bridge
maurelian Jun 3, 2021
0cc04da
fix(contracts): make contract-deployment/config work
maurelian Jun 5, 2021
06228d0
WIP fix(integration): update integration tests for bridge
maurelian Jun 5, 2021
2b4d79a
Remove ovmEth from L1 Standard bridge as obsoleted
elenadimitrova Jun 7, 2021
1643aba
Separate ERC20 standard implementation from L2 bridge
elenadimitrova Jun 8, 2021
19b6863
Formatting fixes
elenadimitrova Jun 8, 2021
1ca991a
chore(l2geth): replace eth gateway with standard bridge
maurelian Jun 3, 2021
931fd0f
Revert "REVERT ME: instruments cross domain enabled"
maurelian Jun 7, 2021
cbe81b3
fix: lint ts
maurelian Jun 8, 2021
236ee76
Implement EIP-165 in the Standard L2 ERC20 token
elenadimitrova Jun 8, 2021
2893827
fix(contracts): add deployment check on bridge proxy
maurelian Jun 8, 2021
6955c1b
Remove dependency on Ownable contract for the StandardERC20 token on L2
elenadimitrova Jun 8, 2021
946b990
fix(contracts): update deployment scripts
maurelian Jun 8, 2021
c906ade
fix: lint
maurelian Jun 8, 2021
55f8132
remove debugging code
maurelian Jun 8, 2021
1657211
fix: correct rpc get balance slot
maurelian Jun 9, 2021
56c3856
restore l2 cross domain messenger
maurelian Jun 9, 2021
5dce352
fix: lint
maurelian Jun 9, 2021
f8a54da
Add a test for a non compliant token deposit
elenadimitrova Jun 8, 2021
b2b96f1
Only allow EOAs to deposit ETH and ERC20
elenadimitrova Jun 9, 2021
41e17a8
Add comments and tests for ERC165 implementation
elenadimitrova Jun 9, 2021
41d9869
Decide against using explicit ETH MOCK address as we're not using it …
elenadimitrova Jun 9, 2021
e6a3e79
Fix linting issues
elenadimitrova Jun 9, 2021
834b968
Add onlyEOAContract restriction to standard bridge withdrawals
elenadimitrova Jun 9, 2021
163780e
Update codehashes in L2 Standard bridge
elenadimitrova Jun 9, 2021
b9f1c36
fix(ops): remove unintentionally added file
maurelian Jun 9, 2021
083c9f4
feat(contracts): add expectApproxGasCost function
maurelian Jun 9, 2021
41d658f
fix(integration): proper arrayify input on fundUser
maurelian Jun 9, 2021
5ec47be
fix(integration): proper gas value checks
maurelian Jun 9, 2021
0e20447
Revert "Add onlyEOAContract restriction to standard bridge withdrawals"
maurelian Jun 9, 2021
2c1619a
fix(contracts): removed unused expectApproxGasCost for now
maurelian Jun 9, 2021
f7e364e
fix(contracts): update OVM_SequencerFeeVault for bridge changes
maurelian Jun 10, 2021
604cc03
lint
maurelian Jun 10, 2021
3993263
Update deployment for L1 Bridge w/ ChugSplash
maurelian Jun 10, 2021
eeee932
Revert "l2geth: TEMP log contract calls"
maurelian Jun 10, 2021
7deec7c
Apply suggestions from code review
maurelian Jun 10, 2021
cef69d6
Apply suggestions from code review
maurelian Jun 10, 2021
f50068c
fix(contracts): deploy with chugsplash proxy
maurelian Jun 10, 2021
189d712
fix(contracts): add working bridge and chugsplash proxy deployment
maurelian Jun 10, 2021
8aeb842
fix(contracts,integration): 500k gas for depositETH
maurelian Jun 10, 2021
3e40476
comment(contracts): describe failed deposit handling on l2
maurelian Jun 10, 2021
23956e5
Apply suggestions from code review
maurelian Jun 10, 2021
0854e04
docs: add changeset
maurelian Jun 10, 2021
44e361a
fix(integration): set working l2 gas amount on funduser
maurelian Jun 10, 2021
e27a3a9
test(integration): add receive() test
maurelian Jun 10, 2021
97c3135
fix(contracts): reset receive to 1.2MM l2 gas
maurelian Jun 10, 2021
c39bf33
test(examples): skip l1-l2 example test for now
maurelian Jun 11, 2021
1dd2a40
fix(contracts): drop hardcoded gas to 500k in receive()
maurelian Jun 11, 2021
098cbe0
fix(contracts): use abi.encodeWithSignature
maurelian Jun 11, 2021
a73c949
fix(contracts): resolve merge conflicts
maurelian Jun 11, 2021
41decf8
feat(integration): add expectApprox for flexible gas testing
maurelian Jun 11, 2021
454c219
fix(integration): fix failing gas tests
maurelian Jun 11, 2021
fafece9
fix: incorrect l2 gas for deposit
smartcontracts Jun 11, 2021
7b33da3
Update utils.ts
smartcontracts Jun 11, 2021
c67f903
fix(workflow): disable l1-l2 example until npm imports are fixed
ben-chain Jun 11, 2021
bae3976
chore: final round of PR review nits and tests
ben-chain Jun 11, 2021
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
Prev Previous commit
Next Next commit
Add onlyEOAContract restriction to standard bridge withdrawals
  • Loading branch information
elenadimitrova authored and maurelian committed Jun 11, 2021
commit 834b968bfb810389863935685373cc7f287f2189
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { iOVM_L2ERC20Bridge } from "../../../iOVM/bridge/tokens/iOVM_L2ERC20Brid
/* Library Imports */
import { ERC165Checker } from "@openzeppelin/contracts/introspection/ERC165Checker.sol";
import { OVM_CrossDomainEnabled } from "../../../libraries/bridge/OVM_CrossDomainEnabled.sol";
import { OVM_EOACodeHashSet } from "../../../libraries/bridge/OVM_EOACodeHashSet.sol";
import { Lib_PredeployAddresses } from "../../../libraries/constants/Lib_PredeployAddresses.sol";

/* Contract Imports */
Expand All @@ -25,7 +26,7 @@ import { IL2StandardERC20 } from "../../../libraries/standards/IL2StandardERC20.
* Compiler used: optimistic-solc
* Runtime target: OVM
*/
contract OVM_L2StandardBridge is iOVM_L2ERC20Bridge, OVM_CrossDomainEnabled {
contract OVM_L2StandardBridge is iOVM_L2ERC20Bridge, OVM_EOACodeHashSet, OVM_CrossDomainEnabled {

/********************************
* External Contract References *
smartcontracts marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -66,6 +67,7 @@ contract OVM_L2StandardBridge is iOVM_L2ERC20Bridge, OVM_CrossDomainEnabled {
external
override
virtual
onlyEOAContract()
{
_initiateWithdrawal(
_l2Token,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// SPDX-License-Identifier: MIT
pragma solidity >0.5.0 <0.8.0;

/* External Imports */
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { EnumerableSet } from "@openzeppelin/contracts/utils/EnumerableSet.sol";

/**
* @title OVM_EOACodeHashSet
* @dev Helper contract used to keep track of OVM EOA contract set (OVM specific)
*
* The OVM implements a basic form of account abstraction. In effect, this means
* that the only type of account is a smart contract (no EOAs), and all user wallets
* are in fact smart contract wallets. So to check for EOA, we need to actually check if
* the sender is an OVM_ProxyEOA contract, which gets deployed by the ovmCREATEEOA opcode.
*
* As the OVM_ProxyEOA.sol contract source could potentially change in the future (i.e., due to a fork),
* here we actually track a set of possible EOA proxy contracts.
*
* Compiler used: optimistic-solc
* Runtime target: OVM
*/
contract OVM_EOACodeHashSet is Ownable {
// Add the EnumerableSet library
using EnumerableSet for EnumerableSet.Bytes32Set;

// Declare a Bytes32Set of code hashes
EnumerableSet.Bytes32Set private s_codeHasheSet;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see this included! 🙌

There was/is a typo here. It should actually be named s_codeHashesSet or s_codeHashSet.


// Declare the genesis OVM_ProxyEOA.sol EXTCODEHASH
bytes32 constant OVM_EOA_CODE_HASH_V0 = 0x93bb081a7dd92bde63b4d0aa9b8612352b2ec585176a80efc0a2a277ecfc010e;
bytes32 constant OVM_EOA_CODE_HASH_V1 = 0x8b4ea2cb36c232a7bab9d385b7054ff04752ec4c0fad5dc2ed4b1c18d982154c;
bytes32 constant OVM_EOA_CODE_HASH_V2 = 0xb6268ee2707994607682cc0e3b288cdd71acc63df8de0e6baa39a31a2b91d0ad;
bytes32 constant OVM_EOA_CODE_HASH_V3 = 0x93fae832274ff6aa942fa0c287fc0d8fe180f26b36c92e83d9be7e39309d3464;
// Optimism v0.3.0-rc
bytes32 constant OVM_EOA_CODE_HASH_V4 = 0xef2ab076db773ffc554c9f287134123439a5228e92f5b3194a28fec0a0afafe3;

constructor() {
s_codeHasheSet.add(OVM_EOA_CODE_HASH_V0);
s_codeHasheSet.add(OVM_EOA_CODE_HASH_V1);
s_codeHasheSet.add(OVM_EOA_CODE_HASH_V2);
s_codeHasheSet.add(OVM_EOA_CODE_HASH_V3);
s_codeHasheSet.add(OVM_EOA_CODE_HASH_V4);
}

/// @notice Reverts if called by anyone other than whitelisted EOA contracts.
modifier onlyEOAContract() {
require(_isEOAContract(msg.sender), "Only callable by whitelisted EOA");
_;
}

/**
* @dev Returns true if the EOA contract code hash value is in the set. O(1).
*
* @param value EOA contract code hash to check
*/
function containsEOACodeHash(
bytes32 value
)
public
view
returns (bool)
{
return s_codeHasheSet.contains(value);
}

/**
* @dev Adds a EOA contract code hash value to the set. O(1).
*
* Returns true if the value was added to the set, that is if it was not already present.
* @param value EOA contract code hash to add
*/
function addEOACodeHash(
bytes32 value
)
public
onlyOwner()
returns (bool)
{
return s_codeHasheSet.add(value);
}

/**
* @dev Removes a EOA contract code hash value from the set. O(1).
*
* Returns true if the value was removed from the set, that is if it was present.
* @param value EOA contract code hash to remove
*/
function removeEOACodeHash(
bytes32 value
)
public
onlyOwner()
returns (bool)
{
return s_codeHasheSet.remove(value);
}

/**
* @dev Returns the codehash for `account`.
* @param account Address to get codehash for
*/
function getCodeHash(
address account
)
public
view
returns (bytes32)
{
bytes32 codehash;

assembly { codehash := extcodehash(account) }

return codehash;
}

/**
* @dev Returns true if `account` is a whitelisted EOA contract.
* @param account Address to check
*/
function _isEOAContract(
address account
)
internal
view
returns (bool)
{
bytes32 codehash;

assembly { codehash := extcodehash(account) }
return s_codeHasheSet.contains(codehash);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from '../../../../setup'

/* External Imports */
import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract } from 'ethers'
import { Signer, ContractFactory, Contract, constants } from 'ethers'
import { Interface } from 'ethers/lib/utils'
import {
smockit,
Expand All @@ -14,7 +14,7 @@ import {
/* Internal Imports */
import { NON_NULL_BYTES32, NON_ZERO_ADDRESS } from '../../../../helpers'

import { getContractInterface } from '../../../../../src'
import { getContractInterface, predeploys } from '../../../../../src'

const ERR_INVALID_MESSENGER = 'OVM_XCHAIN: messenger contract unauthenticated'
const ERR_INVALID_X_DOMAIN_MSG_SENDER =
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('OVM_L2StandardBridge', () => {

it('should initilise a withdrawal if the L2 token is not compliant', async () => {
// Deploy a non compliant ERC20
let NonCompilantERC20 = await (
const NonCompilantERC20 = await (
await ethers.getContractFactory(
'@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20'
)
Expand Down Expand Up @@ -215,7 +215,12 @@ describe('OVM_L2StandardBridge', () => {
})

it('withdraw() burns and sends the correct withdrawal message', async () => {
await OVM_L2StandardBridge.withdraw(
// whitelist Alice's EOA contract in the Bridge for withdraw
const codeHash = await OVM_L2StandardBridge.getCodeHash(aliceAddress)
await OVM_L2StandardBridge.addEOACodeHash(codeHash)

// call withdraw
await OVM_L2StandardBridge.connect(alice).withdraw(
SmoddedL2Token.address,
withdrawAmount,
0,
Expand Down Expand Up @@ -259,6 +264,17 @@ describe('OVM_L2StandardBridge', () => {
expect(withdrawalCallToMessenger._gasLimit).to.equal(0)
})

it('withdraw() cannot be called by a non whitelisted EOA', async () => {
expect(
OVM_L2StandardBridge.connect(alice).withdraw(
SmoddedL2Token.address,
withdrawAmount,
0,
NON_NULL_BYTES32
)
).to.be.revertedWith('Only callable by whitelisted EOA')
})

it('withdrawTo() burns and sends the correct withdrawal message', async () => {
await OVM_L2StandardBridge.withdrawTo(
SmoddedL2Token.address,
Expand Down