Commit fd1c3d05 authored by Maurelian's avatar Maurelian

fix(ctb): revert if fee vault recipient reverts.

Fixes an issue in the account of FeeVault.sol where insufficient gas
could result in the value of totalProcessed being incremented, even
if the RECIPIENT reverts.
parent 710ca379
......@@ -552,11 +552,12 @@ SafeCall_Test:test_callWithMinGas_noLeakageHigh_succeeds() (gas: 1021670598)
SafeCall_Test:test_callWithMinGas_noLeakageLow_succeeds() (gas: 1095190710)
Semver_Test:test_behindProxy_succeeds() (gas: 506748)
Semver_Test:test_version_succeeds() (gas: 9418)
SequencerFeeVault_L2Withdrawal_Test:test_withdraw_toL2_succeeds() (gas: 78286)
SequencerFeeVault_L2Withdrawal_Test:test_withdraw_toL2_succeeds() (gas: 78333)
SequencerFeeVault_L2Withdrawal_Test:test_withdraw_toL2recipientReverts_fails() (gas: 46486)
SequencerFeeVault_Test:test_constructor_succeeds() (gas: 5526)
SequencerFeeVault_Test:test_minWithdrawalAmount_succeeds() (gas: 5464)
SequencerFeeVault_Test:test_receive_succeeds() (gas: 17373)
SequencerFeeVault_Test:test_withdraw_notEnough_reverts() (gas: 9331)
SequencerFeeVault_Test:test_withdraw_notEnough_reverts() (gas: 9332)
SequencerFeeVault_Test:test_withdraw_toL1_succeeds() (gas: 169242)
SetPrevBaseFee_Test:test_setPrevBaseFee_succeeds() (gas: 11515)
StandardBridge_Stateless_Test:test_isCorrectTokenPair_succeeds() (gas: 49936)
......
......@@ -3,7 +3,6 @@ pragma solidity 0.8.15;
import { L2StandardBridge } from "../L2/L2StandardBridge.sol";
import { Predeploys } from "../libraries/Predeploys.sol";
import { SafeCall } from "../libraries/SafeCall.sol";
/// @title FeeVault
/// @notice The FeeVault contract contains the basic logic for the various different vault contracts
......@@ -76,7 +75,8 @@ abstract contract FeeVault {
emit Withdrawal(value, RECIPIENT, msg.sender, WITHDRAWAL_NETWORK);
if (WITHDRAWAL_NETWORK == WithdrawalNetwork.L2) {
SafeCall.send(RECIPIENT, gasleft(), value);
(bool success, ) = RECIPIENT.call{ value: value }(hex"");
require(success, "FeeVault: failed to send ETH to L2 fee recipient");
} else {
L2StandardBridge(payable(Predeploys.L2_STANDARD_BRIDGE)).bridgeETHTo{ value: value }(
RECIPIENT,
......
......@@ -2,7 +2,7 @@
pragma solidity 0.8.15;
// Testing utilities
import { FeeVault_Initializer } from "./CommonTest.t.sol";
import { FeeVault_Initializer, Reverter } from "./CommonTest.t.sol";
import { StandardBridge } from "../src/universal/StandardBridge.sol";
// Libraries
......@@ -137,4 +137,25 @@ contract SequencerFeeVault_L2Withdrawal_Test is FeeVault_Initializer {
assertEq(address(vault).balance, ZERO_VALUE);
assertEq(recipient.balance, amount);
}
/// @dev Tests that `withdraw` fails if the Recipient reverts. This also serves to simulate
/// a situation where insufficient gas is provided to the RECIPIENT.
function test_withdraw_toL2recipientReverts_fails() external {
uint256 amount = vault.MIN_WITHDRAWAL_AMOUNT();
vm.deal(address(vault), amount);
// No ether has been withdrawn yet
assertEq(vault.totalProcessed(), 0);
// Ensure the RECIPIENT reverts
vm.etch(vault.RECIPIENT(), type(Reverter).runtimeCode);
// The entire vault's balance is withdrawn
vm.expectCall(recipient, address(vault).balance, bytes(""));
vm.expectRevert(
"FeeVault: failed to send ETH to L2 fee recipient"
);
vault.withdraw();
assertEq(vault.totalProcessed(), 0);
}
}
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