Missing stake limit validation on `RenzoAdapter._stake`
The RenzoAdapter contract's _stake function lacks a check for the staking limit, unlike other adapters. This could cause a denial of service if the total value locked (TVL) limit is reached, as the deposit would revert.
Bauer Follow with Ironsidesec, fandonov and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-05-napier-update-judging/issues/24
Found by
Bauer, Ironsidesec, fandonov, zzykxx
Summary
Every _stake function in adapter contracts like RsETHAdapter, PufETHAdapter, and RenzoAdapter has the below @dev comment to implement the stake limit validation.
/// @dev Need to check the current staking limit before staking to prevent DoS.
But only RsETHAdapter, PufETHAdapter validate the stake limits as shown below. But RenzoAdapter doesn't validate the stake limit and it reverts in an edge case.
File: 2024-05-napier-update\napier-uups-adapters\src\adapters\puffer\PufETHAdapter.sol
65: >>> /// @dev Need to check the current staking limit before staking to prevent DoS.
66: function _stake(uint256 stakeAmount) internal override returns (uint256) {
67: if (stakeAmount == 0) return 0;
68:
69: uint256 stakeLimit = STETH.getCurrentStakeLimit();
70: >>> if (stakeAmount > stakeLimit) {
71: // Cap stake amount
72: stakeAmount = stakeLimit;
73: }
File: 2024-05-napier-update\napier-uups-adapters\src\adapters\kelp\RsETHAdapter.sol
66: >>> /// @dev Need to check the current staking limit before staking to prevent DoS.
67: function _stake(uint256 stakeAmount) internal override returns (uint256) {
68: if (stakeAmount == 0) return 0;
69:
70: // Check LRTDepositPool stake limit
71: uint256 stakeLimit = RSETH_DEPOSIT_POOL.getAssetCurrentLimit(Constants.ETH);
72: >>> if (stakeAmount > stakeLimit) {
73: // Cap stake amount
74: stakeAmount = stakeLimit;
75: }
Vulnerability Detail
RenzoAdapter._stakecallsdepositETHonRENZO_RESTAKE_MANAGER
File: 2024-05-napier-update\napier-uups-adapters\src\adapters\renzo\RenzoAdapter.sol
60: >>> /// @dev Need to check the current staking limit before staking to prevent DoS.
61: function _stake(uint256 stakeAmount) internal override returns (uint256) {
62: if (stakeAmount == 0) return 0;
63: if (RENZO_RESTAKE_MANAGER.paused()) revert ProtocolPaused();
64: uint256 balanceBefore = EZETH.balanceOf(address(this));
65: IWETH9(Constants.WETH).withdraw(stakeAmount);
66: RENZO_RESTAKE_MANAGER.depositETH{value: stakeAmount}(0); // @audit-medium no referral id
67: uint256 newBalance = EZETH.balanceOf(address(this));
68: if (newBalance - balanceBefore == 0) revert InvariantViolation();
69:
70: return stakeAmount;
70: }
- And look at
depositETHline highlighted with>>>below, it checks theMaxTVLReached, and it will revert if max TVL is reached. Maybe someone manipulated to cause DOS or unmanipulatedly hit the threshold triggering the revert. And the comment on_stakesays to check the current limit to prevent DOS. ButRenzoAdapter._stakeis missing that.
https://etherscan.io/address/0xbaacd5f849024dcc80520baa952f11adfc59f9d0#code#F1#L558 Line 558 on https://etherscan.deth.net/address/0xbaacd5f849024dcc80520baa952f11adfc59f9d0
function depositETH(uint256 _referralId) public payable nonReentrant notPaused {
// Get the total TVL
(, , uint256 totalTVL) = calculateTVLs();
// Enforce TVL limit if set
>>> if (maxDepositTVL != 0 && totalTVL + msg.value > maxDepositTVL) {
revert MaxTVLReached();
}
...
}
Impact
DOS or Missing validation the dev intended to make but didn't implement.
Code Snippet
https://etherscan.io/address/0xbaacd5f849024dcc80520baa952f11adfc59f9d0#code#F1#L558
Line 558 on https://etherscan.deth.net/address/0xbaacd5f849024dcc80520baa952f11adfc59f9d0
Tool used
Manual Review
Recommendation
function _stake(uint256 stakeAmount) internal override returns (uint256) {
if (stakeAmount == 0) return 0;
if (RENZO_RESTAKE_MANAGER.paused()) revert ProtocolPaused();
+ uint maxDepositTVL = RENZO_RESTAKE_MANAGER.maxDepositTVL();
+ uint totalTVL = RENZO_RESTAKE_MANAGER.totalTVL();
+ if (maxDepositTVL != 0 && totalTVL + stakeAmount > maxDepositTVL) {
+ stakeAmount = maxDepositTVL - totalTVL;
+ }
uint256 balanceBefore = EZETH.balanceOf(address(this));
IWETH9(Constants.WETH).withdraw(stakeAmount);
RENZO_RESTAKE_MANAGER.depositETH{value: stakeAmount}(0); // @audit-medium no referral id
uint256 newBalance = EZETH.balanceOf(address(this));
if (newBalance - balanceBefore == 0) revert InvariantViolation();
return stakeAmount;
}
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/napierfi/napier-uups-adapters/pull/11
zzykxx
An edge case in the proposed fix was found: _stake() reverts if totalTVL is greater than maxDepositTVL. It has been fixed in new PR: https://github.com/napierfi/napier-uups-adapters/pull/22
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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
This could cause a denial of service for staking operations when the TVL limit is reached, as deposits would revert.
What the attacker needed
TVL limit is reached or exceeded
The fix
The issue was fixed by adding a check to cap the stake amount to the remaining TVL limit before depositing.
How it was found
- Call RenzoAdapter._stake with a stakeAmount.
- The function calls RENZO_RESTAKE_MANAGER.depositETH with that amount.
- If the total TVL plus the stake amount exceeds maxDepositTVL, depositETH reverts with MaxTVLReached.
- The _stake function does not cap the stake amount to the remaining limit, so the transaction fails.
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.
In a smart contract, a staking limit is a maximum amount that can be deposited. If the limit is reached, further deposits fail. Here, one adapter contract forgot to check this limit before trying to deposit, so deposits could fail unexpectedly, blocking users.
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.