`currentStakeLimit` depletes faster in some adapters, due to actual amount spent less than the input `stakeAmount`
The stake limit is reduced by the requested stake amount before staking, but the actual amount staked can be lower, so the limit depletes faster than intended. An attacker could repeatedly trigger deposits where the actual stake is less than requested, draining the stake limit and preventing legitimate deposits.
Source: https://github.com/sherlock-audit/2024-05-napier-update-judging/issues/8
Found by
Varun_05, blutorque
Summary
Vulnerability Detail
In the BaseLSTAdapterUpgradeable.prefundedDeposit(), the stake amount is capped to the currentStakeLimit.This is to prevent the buffer from being completed drained.
// Update the stake limit state in the storage
$.packedStakeLimitData.setStorageStakeLimitStruct(data.updatePrevStakeLimit(currentStakeLimit - stakeAmount));
Before the staking occur, its checks whether the stakeAmount exceed current stakeLimit, if not modify the new stake limit to currentStakeLimit - stakeAmount. The issue is, the actual amount going to be spent could possibly lower than the stakeAmount
// Actual amount of ETH spent may be less than the requested amount.
stakeAmount = _stake(stakeAmount); // stake amount can be 0
which means the stake limit that was updated previously does not account for the actual amount that we staked. I found one instance of adapters where this could possibly occur,
kelp/RsETHAdapter.sol: Input stakeAmount modified to lower value if its greater than the stakeLimit of RsETHDeposit pool,
Impact
With every prefundedDeposit call where excess WETH is left to stake, the stake limit will deplete faster.
Code Snippet
Tool used
Manual Review
Recommendation
The _stake() method do returns the actual spent amount, therefore I suggest to update the staking limit after the staking has been done.
/// INTERACT ///
// Deposit into the yield source
// Actual amount of ETH spent may be less than the requested amount.
stakeAmount = _stake(stakeAmount); // stake amount can be 0
/// WRITE ///
// Update the stake limit state in the storage
$.packedStakeLimitData.setStorageStakeLimitStruct(data.updatePrevStakeLimit(currentStakeLimit - stakeAmount));
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/napierfi/napier-v1/pull/219 https://github.com/napierfi/napier-uups-adapters/pull/9
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
Root cause
Likely the stake limit is updated using the requested stake amount before the actual stake amount is known, and the actual amount may be lower.
Impact
The stake limit depletes faster than intended, which could prevent legitimate deposits once the limit is exhausted.
What the attacker needed
Ability to call prefundedDeposit; adapter where actual stake < requested
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 stake limit is like a daily spending cap to prevent draining a buffer. The code subtracts the requested amount from the cap before actually spending, but sometimes it spends less, so the cap goes down too much. This means the cap can be used up faster than it should be.
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.