Skip to content
Business logic Audit finding Advanced

InitiateETHWithdrawalsFromLido decreases totalA

The vault's internal counter for ETH locked in Lido is incremented by the requested amount, but the actual stETH transferred can differ by a few wei due to a known Lido rounding corner case. This makes totalAssets() slightly lower after the call, so depositors before the call receive more shares than depositors after it.

OxDEADBEEF Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

29060 - [SC - Medium] initiateETHWithdrawalsFromLido decreases totalA...

Submitted on Mar 6th 2024 at 02:04:33 UTC by @OxDEADBEEF for Boost | Puffer Finance

Report ID: #29060

Report type: Smart Contract

Report severity: Medium

Target: https://etherscan.io/address/0xd9a442856c234a39a81a089c06451ebaa4306a72

Impacts:

  • Permanent freezing of funds

Description

Brief/Intro

When a user deposits stETH into the PufferVault - he will receive shares based on the total assets the vault holds.

The assets amount calculation adds all the floating eth values that are deposited into other platforms for yield and current stETH and eth balance.

When an operator calls initiateETHWithdrawalsFromLido - the vault transfers stETH to LIDO and increases an internal counter (lidoLockedETH).

However - the amount transferred and the amount the counter is increment can be different.

Vulnerability Details

The main issue is with how stETH balance is calculated. There is a known 1-2 wei corner case (https://docs.lido.fi/guides/lido-tokens-integration-guide/#1-2-wei-corner-case) which impacts the exact number of tokens moved.

Therefore when initiateETHWithdrawalsFromLido is called lidoLockedETH can be incremented to a higher value then the actual amount of stETH moved.

Solidity
    function initiateETHWithdrawalsFromLido(uint256[] calldata amounts)
        external
        virtual
        restricted
        returns (uint256[] memory requestIds)
    {
        VaultStorage storage $ = _getPufferVaultStorage();

        uint256 lockedAmount;
        for (uint256 i = 0; i < amounts.length; ++i) {
            lockedAmount += amounts[i];
        }
        $.lidoLockedETH += lockedAmount;

        SafeERC20.safeIncreaseAllowance(_ST_ETH, address(_LIDO_WITHDRAWAL_QUEUE), lockedAmount);
        requestIds = _LIDO_WITHDRAWAL_QUEUE.requestWithdrawals(amounts, address(this));

        for (uint256 i = 0; i < requestIds.length; ++i) {
            $.lidoWithdrawals.add(requestIds[i]);
        }
        emit RequestedWithdrawals(requestIds);
        return requestIds;
    }

Impact Details

the call to initiateETHWithdrawalsFromLido will decrease totalAssets().

Depositors that deposit before initiateETHWithdrawalsFromLido will receive more shares then depositors that deposit after initiateETHWithdrawalsFromLido

Proof of Concept

This POC shows that a depositor before initiateETHWithdrawalsFromLido will earn more shares then a deposit after initiateETHWithdrawalsFromLido.

Add the following test to test/Integration/PufferTest.integration.t.sol

Solidity
    function testBug() external giveToken(BLAST_DEPOSIT, address(stETH), alice, 1000 ether) {
        // Deposit to vault 1000 ether
        vm.startPrank(alice);
        SafeERC20.safeIncreaseAllowance(IERC20(stETH), address(pufferVault), type(uint256).max);
        uint256 aliceMinted = pufferVault.deposit(1000 ether, alice);
        vm.stopPrank();

        // Calculate shares to receive before withdrawal request
        uint256 sharesBeforeWithdrawalRequest = pufferVault.previewDeposit(1000 ether);

        // Operator request to withdraw 1000 ether from LIDO 
        uint256[] memory amounts = new uint256[](1);
        amounts[0] = 1000 ether; // steth Amount
        vm.prank(OPERATIONS_MULTISIG);
        uint256[] memory requestIds = pufferVault.initiateETHWithdrawalsFromLido(amounts);
        
        // Calculate shares to receive after withdrawal request
        uint256 sharesAfterWithdrawalRequest= pufferVault.previewDeposit(1000 ether);

        // Validate that sharesBeforeWithdrawalRequest is smaller then sharesAfterWithdrawalRequest
        assertGt(sharesBeforeWithdrawalRequest, sharesAfterWithdrawalRequest);
    }

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

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 code increments the internal lidoLockedETH counter by the requested amounts rather than the actual stETH balance change, ignoring Lido's known 1-2 wei rounding corner case.

Impact

Depositors before the call receive more shares than depositors after it, and the report claims this could lead to permanent freezing of funds, though the proof of concept only shows the share-price difference.

What the attacker needed

Operator role can call the function; vault holds stETH

How it was found

  1. Deposit stETH into the vault and note the shares previewed for a further deposit.
  2. Call initiateETHWithdrawalsFromLido as the operator with a withdrawal amount.
  3. Preview the shares for the same deposit again and observe they are lower than before.

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 vault lets people deposit a token and gives them shares representing their portion of everything the vault holds. When the vault moves some of that token to another service, it records the amount it thinks it moved. Because of a tiny rounding difference in that other service, the recorded amount can be a little higher than what actually left, so the vault looks slightly poorer afterwards. People who deposited before that moment end up with a slightly better share price than people who deposit after.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by OxDEADBEEF

View all

2 more disclosed reports, best first.

More from Puffer Finance

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.