Strategy can’t earn yields for user as underlyingBalance is not updated when strategy deposits
The adapter's underlyingBalance is not increased when a strategy deposits harvested funds, so it stays equal to totalSupply and users earn no yield from the strategy. An attacker could not directly exploit this, but users lose expected returns.
Originally disclosed on Code4rena
Submitted by rvierdiiev
Impact
Strategy can’t earn yields for user as underlyingBalance is not updated when strategy deposits.
Proof of Concept
When someone deposits/withdraws from adapter, then underlyingBalance variable is updated with deposited/withdrawn to the vault shares amount.
Only when user deposits or withdraws, then AdapterBase changes totalSupply(it mints or burns shares).
This is how shares of users are calculated inside BeefyAdapter:
function convertToUnderlyingShares(uint256, uint256 shares)
public
view
override
returns (uint256)
{
uint256 supply = totalSupply();
return
supply == 0
? shares
: shares.mulDiv(underlyingBalance, supply, Math.Rounding.Up);
}
As you can see, when user provides amount of shares that he wants to withdraw, then these shares are recalculated in order to receive shares amount inside vault. This depends on underlyingBalance and totalSupply.
Each adapter can have a strategy that can withdraw harvest and then redeposit it inside the vault. In this case users should earn new shares.
When adapter wants to deposit to vault it should call strategyDeposit function.
function strategyDeposit(uint256 amount, uint256 shares)
public
onlyStrategy
{
_protocolDeposit(amount, shares);
}
This function is just sending all amounts to the vault.
But actually it should also increase underlyingBalance with shares amount that it will receive by depositing. Because this is not happening, underlyingBalance always equal to totalSupply and users do not earn any yields using strategy as convertToUnderlyingShares function will just return same value as provided shares. So currently users can’t earn any yields using strategy.
Note: this was discussed with protocol developer and he explained to me how it should work.
Tools Used
VS Code
Recommended Mitigation Steps
Increase underlyingBalance with shares amount that it will receive by depositing. But do not mint shares.
RedVeil (Popcorn) acknowledged
LSDan (judge) decreased severity to Medium and commented:
I’m bringing this back as a Medium risk due to additional context provided by the warden (note: see conversation on original submission for full details)
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 strategyDeposit function calls _protocolDeposit without also increasing underlyingBalance by the shares received.
Impact
Users cannot earn any yield from the strategy because their shares never increase in value.
What the attacker needed
Adapter has an active strategy; strategy harvests and redeposits funds
The fix
The strategyDeposit function should increase underlyingBalance by the shares received from depositing, without minting new shares.
How it was found
- A user deposits into the adapter, which updates underlyingBalance and mints shares.
- The strategy harvests yield and calls strategyDeposit to redeposit funds.
- strategyDeposit calls _protocolDeposit but does not update underlyingBalance.
- Because underlyingBalance remains equal to totalSupply, convertToUnderlyingShares returns the same value and users earn no yield.
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 tracks how many shares users own and how much underlying value those shares represent. When a strategy adds profit, the vault should record the extra value so each share is worth more. Here it forgets to record the profit, so shares never grow in value and users get no yield.
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.