Commit 1a55f640 authored by Kristijan Rebernisak's avatar Kristijan Rebernisak Committed by GitHub

Fix bridge contracts upgradeability (#533)

- Change Abs_L1TokenGateway.DEFAULT_FINALIZE_DEPOSIT_L2_GAS and Abs_L2DepositedToken.DEFAULT_FINALIZE_WITHDRAWAL_L1_GAS to internal constants
- Add virtual declaration to Abs_L1TokenGateway.getFinalizeDepositL2Gas fn
- Add virtual declaration to few more bridge gateway fn to improve extensibility
parent 8d4aae40
---
"@eth-optimism/contracts": patch
---
Fix bridge contracts upgradeability by changing `Abs_L1TokenGateway.DEFAULT_FINALIZE_DEPOSIT_L2_GAS` from a storage var to an internal constant.
Additionally, make some bridge functions virtual so they could be overriden in child contracts.
...@@ -53,7 +53,7 @@ abstract contract Abs_L1TokenGateway is iOVM_L1TokenGateway, OVM_CrossDomainEnab ...@@ -53,7 +53,7 @@ abstract contract Abs_L1TokenGateway is iOVM_L1TokenGateway, OVM_CrossDomainEnab
********************************/ ********************************/
// Default gas value which can be overridden if more complex logic runs on L2. // Default gas value which can be overridden if more complex logic runs on L2.
uint32 public DEFAULT_FINALIZE_DEPOSIT_L2_GAS = 1200000; uint32 internal constant DEFAULT_FINALIZE_DEPOSIT_L2_GAS = 1200000;
/** /**
* @dev Core logic to be performed when a withdrawal is finalized on L1. * @dev Core logic to be performed when a withdrawal is finalized on L1.
...@@ -96,10 +96,10 @@ abstract contract Abs_L1TokenGateway is iOVM_L1TokenGateway, OVM_CrossDomainEnab ...@@ -96,10 +96,10 @@ abstract contract Abs_L1TokenGateway is iOVM_L1TokenGateway, OVM_CrossDomainEnab
* dynamic, and the above public constant does not suffice. * dynamic, and the above public constant does not suffice.
* *
*/ */
function getFinalizeDepositL2Gas() function getFinalizeDepositL2Gas()
public public
view view
virtual
returns( returns(
uint32 uint32
) )
...@@ -118,8 +118,9 @@ abstract contract Abs_L1TokenGateway is iOVM_L1TokenGateway, OVM_CrossDomainEnab ...@@ -118,8 +118,9 @@ abstract contract Abs_L1TokenGateway is iOVM_L1TokenGateway, OVM_CrossDomainEnab
function deposit( function deposit(
uint _amount uint _amount
) )
public external
override override
virtual
{ {
_initiateDeposit(msg.sender, msg.sender, _amount); _initiateDeposit(msg.sender, msg.sender, _amount);
} }
...@@ -133,8 +134,9 @@ abstract contract Abs_L1TokenGateway is iOVM_L1TokenGateway, OVM_CrossDomainEnab ...@@ -133,8 +134,9 @@ abstract contract Abs_L1TokenGateway is iOVM_L1TokenGateway, OVM_CrossDomainEnab
address _to, address _to,
uint _amount uint _amount
) )
public external
override override
virtual
{ {
_initiateDeposit(msg.sender, _to, _amount); _initiateDeposit(msg.sender, _to, _amount);
} }
...@@ -196,6 +198,7 @@ abstract contract Abs_L1TokenGateway is iOVM_L1TokenGateway, OVM_CrossDomainEnab ...@@ -196,6 +198,7 @@ abstract contract Abs_L1TokenGateway is iOVM_L1TokenGateway, OVM_CrossDomainEnab
) )
external external
override override
virtual
onlyFromCrossDomainAccount(l2DepositedToken) onlyFromCrossDomainAccount(l2DepositedToken)
{ {
// Call our withdrawal accounting handler implemented by child contracts. // Call our withdrawal accounting handler implemented by child contracts.
......
...@@ -55,7 +55,6 @@ abstract contract Abs_L2DepositedToken is iOVM_L2DepositedToken, OVM_CrossDomain ...@@ -55,7 +55,6 @@ abstract contract Abs_L2DepositedToken is iOVM_L2DepositedToken, OVM_CrossDomain
* *
* @param _l1TokenGateway Address of the corresponding L1 gateway deployed to the main chain * @param _l1TokenGateway Address of the corresponding L1 gateway deployed to the main chain
*/ */
function init( function init(
iOVM_L1TokenGateway _l1TokenGateway iOVM_L1TokenGateway _l1TokenGateway
) )
...@@ -81,8 +80,8 @@ abstract contract Abs_L2DepositedToken is iOVM_L2DepositedToken, OVM_CrossDomain ...@@ -81,8 +80,8 @@ abstract contract Abs_L2DepositedToken is iOVM_L2DepositedToken, OVM_CrossDomain
* Overridable Accounting logic * * Overridable Accounting logic *
********************************/ ********************************/
// Default gas value which can be overridden if more complex logic runs on L2. // Default gas value which can be overridden if more complex logic runs on L1.
uint32 constant DEFAULT_FINALIZE_WITHDRAWAL_L1_GAS = 100000; uint32 internal constant DEFAULT_FINALIZE_WITHDRAWAL_L1_GAS = 100000;
/** /**
* @dev Core logic to be performed when a withdrawal from L2 is initialized. * @dev Core logic to be performed when a withdrawal from L2 is initialized.
...@@ -91,7 +90,6 @@ abstract contract Abs_L2DepositedToken is iOVM_L2DepositedToken, OVM_CrossDomain ...@@ -91,7 +90,6 @@ abstract contract Abs_L2DepositedToken is iOVM_L2DepositedToken, OVM_CrossDomain
* param _to Address being withdrawn to * param _to Address being withdrawn to
* param _amount Amount being withdrawn * param _amount Amount being withdrawn
*/ */
function _handleInitiateWithdrawal( function _handleInitiateWithdrawal(
address, // _to, address, // _to,
uint // _amount uint // _amount
...@@ -122,9 +120,7 @@ abstract contract Abs_L2DepositedToken is iOVM_L2DepositedToken, OVM_CrossDomain ...@@ -122,9 +120,7 @@ abstract contract Abs_L2DepositedToken is iOVM_L2DepositedToken, OVM_CrossDomain
/** /**
* @dev Overridable getter for the *L1* gas limit of settling the withdrawal, in the case it may be * @dev Overridable getter for the *L1* gas limit of settling the withdrawal, in the case it may be
* dynamic, and the above public constant does not suffice. * dynamic, and the above public constant does not suffice.
*
*/ */
function getFinalizeWithdrawalL1Gas() function getFinalizeWithdrawalL1Gas()
public public
view view
...@@ -150,6 +146,7 @@ abstract contract Abs_L2DepositedToken is iOVM_L2DepositedToken, OVM_CrossDomain ...@@ -150,6 +146,7 @@ abstract contract Abs_L2DepositedToken is iOVM_L2DepositedToken, OVM_CrossDomain
) )
external external
override override
virtual
onlyInitialized() onlyInitialized()
{ {
_initiateWithdrawal(msg.sender, _amount); _initiateWithdrawal(msg.sender, _amount);
...@@ -166,6 +163,7 @@ abstract contract Abs_L2DepositedToken is iOVM_L2DepositedToken, OVM_CrossDomain ...@@ -166,6 +163,7 @@ abstract contract Abs_L2DepositedToken is iOVM_L2DepositedToken, OVM_CrossDomain
) )
external external
override override
virtual
onlyInitialized() onlyInitialized()
{ {
_initiateWithdrawal(_to, _amount); _initiateWithdrawal(_to, _amount);
...@@ -221,6 +219,7 @@ abstract contract Abs_L2DepositedToken is iOVM_L2DepositedToken, OVM_CrossDomain ...@@ -221,6 +219,7 @@ abstract contract Abs_L2DepositedToken is iOVM_L2DepositedToken, OVM_CrossDomain
) )
external external
override override
virtual
onlyInitialized() onlyInitialized()
onlyFromCrossDomainAccount(address(l1TokenGateway)) onlyFromCrossDomainAccount(address(l1TokenGateway))
{ {
......
...@@ -66,7 +66,7 @@ describe('OVM_L1ERC20Gateway', () => { ...@@ -66,7 +66,7 @@ describe('OVM_L1ERC20Gateway', () => {
Mock__OVM_L1CrossDomainMessenger.address Mock__OVM_L1CrossDomainMessenger.address
) )
finalizeDepositGasLimit = await OVM_L1ERC20Gateway.DEFAULT_FINALIZE_DEPOSIT_L2_GAS() finalizeDepositGasLimit = await OVM_L1ERC20Gateway.getFinalizeDepositL2Gas()
}) })
describe('finalizeWithdrawal', () => { describe('finalizeWithdrawal', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment