calculateTVL may run out of gas for modest number of operators and tokens breaking deposits, withdrawals, and trades
The calculateTVLs function uses nested loops over operator delegators and tokens, causing gas costs to grow quadratically. With a modest number of operators and tokens, the gas required could exceed the block gas limit, making deposits, withdrawals, and trades unusable.
Submitted by guhu95, also found by zzykxx, LessDupes, ilchovski, and Bauchibred
The calculateTVLs function in the RestakeManager contains two nested loops: one loop for each operator delegator (OD), and an internal loop for each token. In each internal loop:
- The OD’s
getTokenBalanceFromStrategyfunction is called for the token, which in turn calls the Eigenlayer strategy for the shares balance. - The
renzoOracleis called for the token value, which in turns calls the respective oracle. - Additionally, memory is allocated for all the results and intermediate call outputs, incurring high quadratic memory expansion costs.
Due to the the nested loop structure, the gas consumption in the case of several operator delegators, and several tokens used is quadratic: n-OD x n-Tokens. Crucially, this method is called in most user flows: deposits, withdrawals, and Balancer trades.
Impact
An even small number of operators and supported tokens will render the protocol unusable, up to running out of block gas limit.
Currently, with 1 OD and 2 tokens, calculateTVLs consumes approximately 450K gas (see the example transaction gas profiling section).
For reasonable values, such as 12 ODs and 12 tokens (Eigenlayer supports 12 tokens), there would be 144 nested loop iterations instead of just 2 iterations in the current version and configuration. A simple extrapolation, without adding the cost of operations added in the new version, and without estimating the additional quadratic memory expansion costs, would suggest that 144 iterations, instead of the current 2, would cost 32M gas (450K * 144 / 2), exceeding the block gas limit.
However, an earlier limiting factor will be encountered because calculateTVL is called in most user interactions with Renzo: deposit, withdrawal, and Balancer trade. Thus, exceeding even 1M-2M gas on L1 will render most protocol methods practically unusable for users.
Proof of Concept
- With 1 OD and 2 tokens,
calculateTVLsconsumes approximately 450K gas (see the example transaction gas profiling section) - For reasonable values, such as 12 ODs and 12 tokens currently supported by EigenLayer, there would be 144 nested loop iterations instead of the current 2 .
- A simple extrapolation, would suggest that 144 iterations, instead of the current 2, would cost 32M gas (
450K * 144 / 2), exceeding the block gas limit. Moreover, this is an underestimate, due to not adding the cost of operations added in the new version (relative to the deployed one), and without estimating the additional quadratic memory expansion costs.
Recommended Mitigation Steps
Instead of “pulling” operator delegator token balances, a “pushing” pattern can be used:
- Instead of “pulling” token TVLs from each component, the aggregated TVL sums should be maintained and “pushed” by each OD when its TVL changes (on OD deposits and withdrawals). This way, during admin’s OD operations, the RM’s TVL cache and each token’s total protocol balance is updated.
- Then, total token balances can be used to calculate TVL from
RenzoOracle.lookupTokenValuesonce, which will result in a single loop over the tokens only. - For enabling
chooseOperatorDelegatorForDeposita Set of ODs that can accept a deposit (are below allocation) can be maintained via “push” updates.
This will remove all loops during the calculation, except for the loop needed to iterate over the token oracles (once).
Alternatively, an off-chain custom TVL oracle can be used, for example, via a custom Chainlink oracle.
Assessed type
DoS
jatinj615 (Renzo) acknowledged
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
Impact
With a modest number of operators and tokens, calculateTVLs could exceed the block gas limit, rendering deposits, withdrawals, and trades unusable.
What the attacker needed
Multiple operator delegators; multiple supported tokens
The fix
The function should be refactored to use a push pattern where operator delegators update aggregated TVL sums, eliminating nested loops, or an off-chain TVL oracle should be used.
How it was found
- With 1 OD and 2 tokens, calculateTVLs consumes approximately 450K gas.
- For 12 ODs and 12 tokens, there would be 144 nested loop iterations instead of 2.
- Extrapolating, 144 iterations would cost 32M gas, exceeding the block gas limit.
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 function that calculates the total value locked (TVL) uses two loops: one for each operator and one for each token. Each loop iteration costs gas, and because the loops are nested, the total gas grows very quickly as more operators and tokens are added. If the gas needed exceeds the block gas limit, the function cannot run, and users cannot deposit, withdraw, or trade.
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.