Skip to content
Business logic Audit finding Intermediate

Incorrect calculation of queued withdrawals can deflate TVL and increase ezETH mint rate

The function that calculates the protocol's total value locked (TVL) checks the wrong address when looking up queued withdrawal shares, so collateral in the withdrawal process is not counted. This makes TVL appear lower than it is, causing more ezETH to be minted for the same collateral and unfairly favouring new minters over existing holders.

LessDupes Follow with adam-idarrha, araj and 20 others

Originally disclosed on Code4rena

*Submitted by [LessDupes](https://github.com/code-423n4/2024-04-renzo-findings/issues/395), also found by [adam-idarrha](https://github.com/code-423n4/2024-04-renzo-findings/issues/394), [araj](https://github.com/code-423n4/2024-04-renzo-findings/issues/314), [zigtur](https://github.com/code-423n4/2024-04-renzo-findings/issues/313), [jokr](https://github.com/code-423n4/2024-04-renzo-findings/issues/312), [SBSecurity](https://github.com/code-423n4/2024-04-renzo-findings/issues/310), [fyamf](https://github.com/code-423n4/2024-04-renzo-findings/issues/309), [0xCiphky](https://github.com/code-423n4/2024-04-renzo-findings/issues/308), [Tendency](https://github.com/code-423n4/2024-04-renzo-findings/issues/307), [p0wd3r](https://github.com/code-423n4/2024-04-renzo-findings/issues/306), [bigtone](https://github.com/code-423n4/2024-04-renzo-findings/issues/305), [maxim371](https://github.com/code-423n4/2024-04-renzo-findings/issues/304), [NentoR](https://github.com/code-423n4/2024-04-renzo-findings/issues/303), [kennedy1030](https://github.com/code-423n4/2024-04-renzo-findings/issues/302), [mussucal](https://github.com/code-423n4/2024-04-renzo-findings/issues/300), [0xnightfall](https://github.com/code-423n4/2024-04-renzo-findings/issues/299), [FastChecker](https://github.com/code-423n4/2024-04-renzo-findings/issues/298), [baz1ka](https://github.com/code-423n4/2024-04-renzo-findings/issues/297), [aman](https://github.com/code-423n4/2024-04-renzo-findings/issues/296), [0xAadi](https://github.com/code-423n4/2024-04-renzo-findings/issues/295), [0xhacksmithh](https://github.com/code-423n4/2024-04-renzo-findings/issues/292), [0rpse](https://github.com/code-423n4/2024-04-renzo-findings/issues/291), and [KupiaSec](https://github.com/code-423n4/2024-04-renzo-findings/issues/45)*

The function [`OperatorDelegator.getTokenBalanceFromStrategy()`](https://github.com/code-423n4/2024-04-renzo/blob/519e518f2d8dec9acf6482b84a181e403070d22d/contracts/Delegation/OperatorDelegator.sol#L327) is used by the [`RestakeManager`](https://github.com/code-423n4/2024-04-renzo/blob/519e518f2d8dec9acf6482b84a181e403070d22d/contracts/RestakeManager.sol) to calculate the protocol TVL, which in turn is used to calculate the amount of ezETH to mint against a given value in collateral tokens.

This function, however, incorrectly checks for the queued amount of `address(this)` instead of `address(token)`; therefore, consistently failing to consider collaterals in the withdrawal process for calculation:

```
File: OperatorDelegator.sol
326:     /// @dev Gets the underlying token amount from the amount of shares + queued withdrawal shares
327:     function getTokenBalanceFromStrategy(IERC20 token) external view returns (uint256) {
328:         return
329:             queuedShares[address(this)] == 0
330:                 ? tokenStrategyMapping[token].userUnderlyingView(address(this))
331:                 : tokenStrategyMapping[token].userUnderlyingView(address(this)) +
332:                     tokenStrategyMapping[token].sharesToUnderlyingView(
333:                         queuedShares[address(token)]
334:                     );
335:     }
```

Within this code, `queuedShares[address(this)]` will always return `0`; therefore, missing the opportunity to count the contribution of `queuedShares[address(token)]`.

### Impact

Any amount of collateral in the `OperatorDelegator` withdrawal process will not be counted for TVL calculation. This causes the TVL to be low, so more ezETH will be minted for the same amount of collateral, unfairly favoring people who mint ezETH during an `OperatorDelegator` withdrawal, penalizing holders, and those who initiate a `RestakeManager` withdraw.

### Proof of Concept

The following PoC in Foundry shows how the issue can lead to a decrease in TVL. The PoC can be run in Foundry by using the setup and mock infra provided [here](https://gist.github.com/3docSec/a4bc6254f709a6218907a3de370ae84e).

```
pragma solidity ^0.8.19;

import "contracts/Errors/Errors.sol";
import "./Setup.sol";

contract H2 is Setup {

    function testH2() public {
        // we'll only be using stETH with unitary price for simplicity
        stEthPriceOracle.setAnswer(1e18);

        // and we start with 0 TVL
        (, , uint tvl) = restakeManager.calculateTVLs();
        assertEq(0, tvl);

        // now we have Alice depositing some stETH
        address alice = address(1234567890);
        stETH.mint(alice, 100e18);
        vm.startPrank(alice);
        stETH.approve(address(restakeManager), 100e18);
        restakeManager.deposit(IERC20(address(stETH)), 100e18);

        // �
 TVL and balance are as expected
        (, , tvl) = restakeManager.calculateTVLs();
        assertEq(100e18, tvl);
        assertEq(100e18, ezETH.balanceOf(alice));

        // Now some liquidity enters the withdraw sequence
        vm.startPrank(OWNER);

        IERC20[] memory tokens = new IERC20[](1);
        uint256[] memory tokenAmounts = new uint256[](1);

        tokens[0] = IERC20(address(stETH));
        tokenAmounts[0] = 50e18;

        operatorDelegator1.queueWithdrawals(tokens, tokenAmounts);

        // 🚨 The collateral queued for withdrawal does not show up in TVL,
        // so the mint rate is altered
        (, , tvl) = restakeManager.calculateTVLs();
        assertEq(50e18, tvl);
    }
}
```

### Tools Used

Foundry

### Recommended Mitigation Steps

Consider changing the address used for the mapping lookup:

```
    /// @dev Gets the underlying token amount from the amount of shares + queued withdrawal shares
    function getTokenBalanceFromStrategy(IERC20 token) external view returns (uint256) {
        return
-           queuedShares[address(this)] == 0
+           queuedShares[address(token)] == 0
                ? tokenStrategyMapping[token].userUnderlyingView(address(this))
                : tokenStrategyMapping[token].userUnderlyingView(address(this)) +
                    tokenStrategyMapping[token].sharesToUnderlyingView(
                        queuedShares[address(token)]
                    );
    }
```

**[jatinj615 (Renzo) confirmed](https://github.com/code-423n4/2024-04-renzo-findings/issues/395#event-12916027310)**

**[Renzo mitigated](https://github.com/code-423n4/2024-06-renzo-mitigation?tab=readme-ov-file#scope)**

**Status:** Mitigation confirmed. Full details in reports from [0xCiphky](https://github.com/code-423n4/2024-06-renzo-mitigation-findings/issues/9), [grearlake](https://github.com/code-423n4/2024-06-renzo-mitigation-findings/issues/51), [Fassi_Security](https://github.com/code-423n4/2024-06-renzo-mitigation-findings/issues/41), [Bauchibred](https://github.com/code-423n4/2024-06-renzo-mitigation-findings/issues/18), and [LessDupes](https://github.com/code-423n4/2024-06-renzo-mitigation-findings/issues/3).

---

The original report as published on Code4rena, by LessDupes. 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

The code checks queuedShares[address(this)] instead of queuedShares[address(token)], so the condition is always true and the queued shares are never added to the balance.

Impact

Any collateral in the withdrawal process is excluded from TVL, so more ezETH is minted for the same collateral, unfairly favouring new minters and penalising existing holders and those who withdraw.

What the attacker needed

Collateral queued for withdrawal; user deposits while withdrawal is pending

The fix

The lookup should use queuedShares[address(token)] instead of queuedShares[address(this)]; the report notes the issue was mitigated and the mitigation confirmed.

How it was found

  1. Set the stETH price oracle to a unitary price and confirm TVL is zero.
  2. Alice deposits 100 stETH and receives 100 ezETH; TVL is 100.
  3. The owner queues a withdrawal of 50 stETH from operatorDelegator1.
  4. TVL is recalculated and shows 50 instead of 100, because the queued 50 stETH is not counted.

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.

The protocol uses the total value of all deposits to decide how many new tokens to give when someone deposits. A mistake in the code means that money waiting to be withdrawn is not included in that total, so the total looks smaller than it really is. As a result, people who deposit while withdrawals are pending get more tokens than they should, which dilutes everyone else.

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 LessDupes

View all

6 more disclosed reports, best first.

More from Renzo

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.