updateYieldStrategy will freeze some funds with the old Strategy if yieldStrategy fails to withdraw all the funds because of liquidity issues
The updateYieldStrategy function attempts to withdraw all funds from the old strategy and then unconditionally removes it, but if the strategy cannot withdraw all funds due to liquidity issues, the remaining funds become frozen because the old strategy only allows the Sherlock contract to withdraw. An attacker could not directly exploit this, but the protocol itself could lose access to funds.
Submitted by hyh, also found by harleythedog, GreyArt, and pauliax
Part of the funds held with the strategy can be frozen if the current strategy has tight liquidity when updateYieldStrategy is run as this function makes an attempt to withdraw all the funds and then unconditionally removes the strategy.
The Sherlock to YieldStrategy link will be broken as a result: Sherlock points to the new Strategy, while old Strategy still allows only this Sherlock contract to withdraw.
This way back and forth switches will be required in the future to return the funds: withdraw all from new strategy and switch to old, withdraw all from old and point to new one again, reinvest there.
Proof of Concept
In peer-to-peer lending protocols it is not always possible for the token supplier to withdraw all what’s due. This happens on high utilization of the market (when it has a kind of liquidity crunch).
This way yieldStrategy.withdrawAll is not guaranteed to obtain all the funds held with the strategy:
The worst case scenario here seems to be the remainder funds to be left frozen within the strategy.
For example, AaveV2Strategy withdraw and withdrawAll have onlySherlockCore modifier:
While Sherlock core is immutable for the Strategy by default:
Recommended Mitigation Steps
Consider implementing a new method that fails whenever a strategy cannot withdraw all what’s due now, and rename current implementation to, for example, forceUpdateYieldStrategy, to have a degree of flexibility around liquidity issues.
Also, to avoid back and forth switching, a strategy argument can be introduced to yieldStrategyWithdrawAll to allow withdrawals from any (not only current) yieldStrategy:
Now:
function yieldStrategyWithdrawAll() external override onlyOwner {
To be (if _yieldStrategy is zero then utilize current):
function yieldStrategyWithdrawAll(IStrategyManager _yieldStrategy) external override onlyOwner {
Evert0x (Sherlock) disagreed with Medium severity and commented:
I think this should be low risk but it’s an interesting feature to add
Jack the Pug (judge) commented:
I think this worths a
Med, the scenario is not impossible to happen, and the handling in the current implementation is quite rough.
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 updateYieldStrategy function does not verify that withdrawAll succeeded before removing the old strategy, and the old strategy restricts withdrawals to the Sherlock contract, which loses its link after the update.
Impact
Some funds could become frozen in the old strategy if it has liquidity issues, requiring manual back-and-forth switching to recover them.
What the attacker needed
Strategy has liquidity issues; owner calls updateYieldStrategy
The fix
The update function should fail if the strategy cannot withdraw all funds, and a separate force update function should be provided; also, yieldStrategyWithdrawAll should accept a strategy argument to allow withdrawals from any strategy.
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.
This is a smart contract bug where a function that switches investment strategies tries to take all money out of the old strategy but doesn't check if it succeeded. If the old strategy can't return all the money (for example, because it lent it out), the remaining money gets stuck because only the main contract is allowed to withdraw from the old strategy, and the main contract no longer points to it.
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.