Commit bf51c493 authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: L2StandardBridge legacy `withdraw`

Adds a test for the legacy withdraw functionality on the
L2StandardBridge. Previously there were no tests for
withdrawing ether via `withdraw`. This adds coverage.
Also natspec is added to describe that these functions
are not useful for being able to withdraw native L2 tokens.
The modern functions must be used to withdraw native
L2 tokens, the legacy functions assume that the withdrawal
is working on a OptimismMintableERC20 token.

Also regenerate the bindings for the slight change to the
bytecode where we save a call in the withdrawal path
if we don't need to make the call.
parent 4f54bcdb
This diff is collapsed.
......@@ -167,20 +167,21 @@ L2OutputOracleUpgradeable_Test:test_initValuesOnProxy_succeeds() (gas: 26093)
L2OutputOracleUpgradeable_Test:test_initializeImpl_alreadyInitialized_reverts() (gas: 15149)
L2OutputOracleUpgradeable_Test:test_initializeProxy_alreadyInitialized_reverts() (gas: 20131)
L2OutputOracleUpgradeable_Test:test_upgrading_succeeds() (gas: 180413)
L2StandardBridge_BridgeERC20To_Test:test_bridgeERC20To_succeeds() (gas: 387796)
L2StandardBridge_BridgeERC20To_Test:test_withdrawTo_withdrawingERC20_succeeds() (gas: 388044)
L2StandardBridge_BridgeERC20To_Test:test_bridgeERC20To_succeeds() (gas: 387797)
L2StandardBridge_BridgeERC20To_Test:test_withdrawTo_withdrawingERC20_succeeds() (gas: 388045)
L2StandardBridge_BridgeERC20_Test:test_bridgeERC20_succeeds() (gas: 383520)
L2StandardBridge_BridgeERC20_Test:test_withdraw_notEOA_reverts() (gas: 251687)
L2StandardBridge_BridgeERC20_Test:test_withdraw_withdrawingERC20_succeeds() (gas: 383722)
L2StandardBridge_BridgeERC20_Test:test_withdraw_withdrawingERC20_succeeds() (gas: 383723)
L2StandardBridge_Bridge_Test:test_finalizeBridgeETH_incorrectValue_reverts() (gas: 23798)
L2StandardBridge_Bridge_Test:test_finalizeBridgeETH_sendToMessenger_reverts() (gas: 23960)
L2StandardBridge_Bridge_Test:test_finalizeBridgeETH_sendToSelf_reverts() (gas: 23848)
L2StandardBridge_Bridge_Test:test_finalizeDeposit_depositingERC20_succeeds() (gas: 91011)
L2StandardBridge_Bridge_Test:test_finalizeDeposit_depositingETH_succeeds() (gas: 89843)
L2StandardBridge_Bridge_Test:test_finalizeDeposit_depositingERC20_succeeds() (gas: 91013)
L2StandardBridge_Bridge_Test:test_finalizeDeposit_depositingETH_succeeds() (gas: 89845)
L2StandardBridge_FinalizeBridgeETH_Test:test_finalizeBridgeETH_succeeds() (gas: 43155)
L2StandardBridge_Test:test_initialize_succeeds() (gas: 24247)
L2StandardBridge_Test:test_receive_succeeds() (gas: 177167)
L2StandardBridge_Test:test_withdraw_insufficientValue_reverts() (gas: 19637)
L2StandardBridge_Test:test_receive_succeeds() (gas: 173990)
L2StandardBridge_Test:test_withdraw_ether_success() (gas: 140478)
L2StandardBridge_Test:test_withdraw_insufficientValue_reverts() (gas: 16463)
L2ToL1MessagePasserTest:test_burn_succeeds() (gas: 112572)
L2ToL1MessagePasserTest:test_initiateWithdrawal_fromContract_succeeds() (gas: 70423)
L2ToL1MessagePasserTest:test_initiateWithdrawal_fromEOA_succeeds() (gas: 75874)
......
......@@ -85,6 +85,8 @@ contract L2StandardBridge is StandardBridge, Semver {
/**
* @custom:legacy
* @notice Initiates a withdrawal from L2 to L1.
* This function only works with OptimismMintableERC20 tokens or ether. Use the
* `bridgeERC20` function to bridge native L2 tokens to L1.
*
* @param _l2Token Address of the L2 token to withdraw.
* @param _amount Amount of the L2 token to withdraw.
......@@ -107,6 +109,8 @@ contract L2StandardBridge is StandardBridge, Semver {
* be locked in the L1StandardBridge. ETH may be recoverable if the call can be
* successfully replayed by increasing the amount of gas supplied to the call. If the
* call will fail for any amount of gas, then the ETH will be locked permanently.
* This function only works with OptimismMintableERC20 tokens or ether. Use the
* `bridgeERC20To` function to bridge native L2 tokens to L1.
*
* @param _l2Token Address of the L2 token to withdraw.
* @param _to Recipient account on L1.
......@@ -126,7 +130,8 @@ contract L2StandardBridge is StandardBridge, Semver {
/**
* @custom:legacy
* @notice Finalizes a deposit from L1 to L2.
* @notice Finalizes a deposit from L1 to L2. To finalize a deposit of ether, use address(0)
* and the l1Token and the Legacy ERC20 ether predeploy address as the l2Token.
*
* @param _l1Token Address of the L1 token to deposit.
* @param _l2Token Address of the corresponding L2 token.
......@@ -179,10 +184,10 @@ contract L2StandardBridge is StandardBridge, Semver {
uint32 _minGasLimit,
bytes memory _extraData
) internal {
address l1Token = OptimismMintableERC20(_l2Token).l1Token();
if (_l2Token == Predeploys.LEGACY_ERC20_ETH) {
_initiateBridgeETH(_from, _to, _amount, _minGasLimit, _extraData);
} else {
address l1Token = OptimismMintableERC20(_l2Token).l1Token();
_initiateBridgeERC20(_l2Token, l1Token, _from, _to, _amount, _minGasLimit, _extraData);
}
}
......
......@@ -118,6 +118,43 @@ contract L2StandardBridge_Test is Bridge_Initializer {
vm.prank(alice, alice);
L2Bridge.withdraw(address(Predeploys.LEGACY_ERC20_ETH), 100, 1000, hex"");
}
/**
* @notice Use the legacy `withdraw` interface on the L2StandardBridge to
* withdraw ether from L2 to L1.
*/
function test_withdraw_ether_success() external {
assertTrue(alice.balance >= 100);
assertEq(Predeploys.L2_TO_L1_MESSAGE_PASSER.balance, 0);
vm.expectEmit(true, true, true, true, address(L2Bridge));
emit WithdrawalInitiated({
l1Token: address(0),
l2Token: Predeploys.LEGACY_ERC20_ETH,
from: alice,
to: alice,
amount: 100,
data: hex""
});
vm.expectEmit(true, true, true, true, address(L2Bridge));
emit ETHBridgeInitiated({
from: alice,
to: alice,
amount: 100,
data: hex""
});
vm.prank(alice, alice);
L2Bridge.withdraw{ value: 100 }({
_l2Token: Predeploys.LEGACY_ERC20_ETH,
_amount: 100,
_minGasLimit: 1000,
_extraData: hex""
});
assertEq(Predeploys.L2_TO_L1_MESSAGE_PASSER.balance, 100);
}
}
contract PreBridgeERC20 is Bridge_Initializer {
......
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