Skip to content
Race condition Audit finding Advanced

Possible reentrancy and fund theft in withdrawDETH() of GiantSavETHVaultPool because there is no whitelist check for user provided Vaults and there is no reentrancy defense

The withdrawDETH function in GiantSavETHVaultPool accepts user-supplied vault addresses without validation and makes external calls to them before transferring the calculated dETH amount, with no reentrancy protection. An attacker could supply a malicious vault contract that reenters or manipulates the contract's dETH balance during the call, causing the contract to transfer more dETH than owed.

unforgiven Follow

Originally disclosed on Code4rena

Submitted by unforgiven

Function withdrawDETH() in GiantSavETHVaultPool allows a user to burn their giant LP in exchange for dETH that is ready to withdraw from a set of savETH vaults. This function make external calls to user provided addresses without checking those addresses and send increased dETH balance of contract during the call to user. User can provide malicious addresses to contract and then took the execution flow during the transaction and increase dETH balance of contract by other calls and make contract to transfer them to him.

Proof of Concept

This is withdrawDETH() in GiantSavETHVaultPool code:

    /// @notice Allow a user to burn their giant LP in exchange for dETH that is ready to withdraw from a set of savETH vaults
    /// @param _savETHVaults List of savETH vaults being interacted with
    /// @param _lpTokens List of savETH vault LP being burnt from the giant pool in exchange for dETH
    /// @param _amounts Amounts of giant LP the user owns which is burnt 1:1 with savETH vault LP and in turn that will give a share of dETH
    function withdrawDETH(
        address[] calldata _savETHVaults,
        LPToken[][] calldata _lpTokens,
        uint256[][] calldata _amounts
    ) external {
        uint256 numOfVaults = _savETHVaults.length;
        require(numOfVaults > 0, "Empty arrays");
        require(numOfVaults == _lpTokens.length, "Inconsistent arrays");
        require(numOfVaults == _amounts.length, "Inconsistent arrays");

        // Firstly capture current dETH balance and see how much has been deposited after the loop
        uint256 dETHReceivedFromAllSavETHVaults = getDETH().balanceOf(address(this));
        for (uint256 i; i < numOfVaults; ++i) {
            SavETHVault vault = SavETHVault(_savETHVaults[i]);

            // Simultaneously check the status of LP tokens held by the vault and the giant LP balance of the user
            for (uint256 j; j < _lpTokens[i].length; ++j) {
                LPToken token = _lpTokens[i][j];
                uint256 amount = _amounts[i][j];

                // Check the user has enough giant LP to burn and that the pool has enough savETH vault LP
                _assertUserHasEnoughGiantLPToClaimVaultLP(token, amount);

                require(vault.isDETHReadyForWithdrawal(address(token)), "dETH is not ready for withdrawal");

                // Giant LP is burned 1:1 with LPs from sub-networks
                require(lpTokenETH.balanceOf(msg.sender) >= amount, "User does not own enough LP");

                // Burn giant LP from user before sending them dETH
                lpTokenETH.burn(msg.sender, amount);

                emit LPBurnedForDETH(address(token), msg.sender, amount);
            }

            // Ask
            vault.burnLPTokens(_lpTokens[i], _amounts[i]);
        }

        // Calculate how much dETH has been received from burning
        dETHReceivedFromAllSavETHVaults = getDETH().balanceOf(address(this)) - dETHReceivedFromAllSavETHVaults;

        // Send giant LP holder dETH owed
        getDETH().transfer(msg.sender, dETHReceivedFromAllSavETHVaults);
    }

As you can see first contract save the dETH balance of contract by this line: uint256 dETHReceivedFromAllSavETHVaults = getDETH().balanceOf(address(this)); and then it loops through user provided vaults addresses and call those vaults to withdraw dETH and in the end it calculates dETHReceivedFromAllSavETHVaults and transfer those dETH to user: getDETH().transfer(msg.sender, dETHReceivedFromAllSavETHVaults);. attacker can perform these steps:

  1. create a malicious contract AttackerVault which is copy of SavETHVault with modifiction.
  2. call withdrawDETH() with Vault list [ValidVault1, ValidVault2, AttackerVault, ValidVaul3].
  3. contract would save the dETH balance of itself and then loops through Vaults to validate and burn LPTokens.
  4. contract would reach Vault AttackerVault and call attacker controlled address.
  5. attacker contract call other functions to increase dETH balance of contract (if it’s not possible to increase dETH balance of contract by other way so there is no need to save contract initial balance of dETH before the loop and dETH balance of contract would be zero always)
  6. withdrawDETH() would finish the loop and transfer all the increase dETH balance to attacker which includes extra amounts.

Because contract don’t check the provided addresses and calls them and there is no reentrancy defense mechanism there is possibility of reentrancy attack which can cause fund lose.

Tools Used

VIM

Recommended Mitigation Steps

Check the provided addresses and also have some reentrancy defense mechanisim.

vince0656 (Stakehouse) confirmed


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

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

Likely the function performs external calls to unvalidated user-supplied vault addresses and calculates the dETH payout from a balance difference without a reentrancy guard, allowing an attacker-controlled vault to alter the contract's dETH balance during execution.

Impact

An attacker could steal funds by causing the contract to transfer more dETH than they are owed, though the report does not demonstrate a working exploit and notes that increasing the contract's dETH balance may not be possible.

What the attacker needed

Attacker can deploy a malicious vault contract; attacker has some giant LP to burn; attacker can increase contract dETH balance during call

The fix

The function should validate the provided vault addresses and include a reentrancy guard.

How it was found

  1. Create a malicious contract that copies SavETHVault with modifications.
  2. Call withdrawDETH with a list of vaults that includes valid vaults and the attacker vault.
  3. The contract saves its dETH balance and loops through the vaults to validate and burn LP tokens.
  4. The loop reaches the attacker vault and calls the attacker-controlled address.
  5. The attacker contract calls other functions to increase the contract's dETH balance.
  6. withdrawDETH finishes the loop and transfers the increased dETH balance to the attacker.

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 is a program on a blockchain that can hold and send digital tokens. This report says one function trusts any address a user gives it and calls that address before finishing its own accounting, so a malicious address can run its own code in the middle and trick the function into sending too many tokens. The missing protection is called reentrancy, where an external call lets an attacker re-enter or interfere with the contract before it finishes.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by unforgiven

View all

50 more disclosed reports, best first.

More from LSD Network - Stakehouse contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.