ReaperBaseStrategyv4.harvest() might revert in an emergency.
The harvest function in a strategy contract could revert when there is no position on the Aave lending pool because Aave does not allow zero-amount withdrawals. This could prevent the strategy from liquidating positions during an emergency, potentially locking funds.
Originally disclosed on Code4rena
Submitted by hansfriese
https://github.com/code-423n4/2023-02-ethos/blob/73687f32b934c9d697b97745356cdf8a1f264955/Ethos-Vault/contracts/abstract/ReaperBaseStrategyv4.sol#L109 https://github.com/code-423n4/2023-02-ethos/blob/73687f32b934c9d697b97745356cdf8a1f264955/Ethos-Vault/contracts/ReaperStrategyGranarySupplyOnly.sol#L200
ReaperBaseStrategyv4.harvest() might revert in an emergency if there is no position on the lending pool.
As a result, the funds might be locked inside the strategy.
Proof of Concept
The main problem is that Aave lending pool doesn’t allow 0 withdrawals.
function validateWithdraw(
address reserveAddress,
uint256 amount,
uint256 userBalance,
mapping(address => DataTypes.ReserveData) storage reservesData,
DataTypes.UserConfigurationMap storage userConfig,
mapping(uint256 => address) storage reserves,
uint256 reservesCount,
address oracle
) external view {
require(amount != 0, Errors.VL_INVALID_AMOUNT);
So the below scenario would be possible.
- After depositing and withdrawing from the Aave lending pool, the current position is 0 and the strategy is in debt.
- It’s possible that the strategy has some want balance in the contract but no position on the lending pool. It’s because
_adjustPosition()remains the debt during reinvesting and also, there is anauthorizedWithdrawUnderlying()forSTRATEGISTto withdraw from the lending pool. - If the strategy is in an emergency,
harvest()tries to liquidate all positions(=0 actually) and it will revert because of 0 withdrawal from Aave. - Also,
withdraw()will revert at L98 as the strategy is in the debt.
As a result, the funds might be locked inside the strategy unless the emergency mode is canceled.
Recommended Mitigation Steps
We should check 0 withdrawal in _withdrawUnderlying().
function _withdrawUnderlying(uint256 _withdrawAmount) internal {
uint256 withdrawable = balanceOfPool();
_withdrawAmount = MathUpgradeable.min(_withdrawAmount, withdrawable);
if(_withdrawAmount != 0) {
ILendingPool(ADDRESSES_PROVIDER.getLendingPool()).withdraw(address(want), _withdrawAmount, address(this));
}
}
Very interesting edge case.
tess3rac7 (Ethos Reserve) disagreed with severity and commented:
Valid edge case in as far as harvests would fail. However, funds won’t get locked in the strategy. They can still be withdrawn through an appropriate withdraw() TX. Recommend downgrading to low since this is purely about state handling without putting any assets at risk. See screenshot below for simulation:
Medium severity is also appropriate when core functionality is impaired, even if there is no lasting damage.
tess3rac7 (Ethos Reserve) confirmed
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
The strategy calls Aave's withdraw function with an amount of zero when there is no position, and Aave's validation logic rejects zero withdrawals.
Impact
The harvest function could revert during an emergency, potentially locking funds inside the strategy unless emergency mode is cancelled; however, the project team stated that funds can still be withdrawn through a separate withdraw transaction.
What the attacker needed
Strategy has no position on Aave; strategy is in debt; emergency mode triggered
The fix
The withdrawal function should check if the withdrawal amount is zero and skip the call to Aave in that case.
How it was found
- After depositing and withdrawing from the Aave lending pool, the current position is 0 and the strategy is in debt.
- The strategy has some want balance in the contract but no position on the lending pool.
- In an emergency, harvest() tries to liquidate all positions (0 actually) and reverts because of 0 withdrawal from Aave.
- withdraw() also reverts because the strategy is in debt.
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 strategy tries to withdraw all its funds from a lending pool during an emergency, but the pool rejects a request to withdraw zero tokens. This causes the emergency function to fail, and the contract's funds might get stuck until the emergency mode is turned off.
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.