cool down time period is not properly respected for the harvest method
The harvest cooldown was not enforced because the lastHarvest timestamp was never updated after a harvest, so the strategy was called on every deposit or withdrawal. An attacker could repeatedly trigger harvest calls, defeating the intended rate limit.
Submitted by imare, also found by Walter, Malatrax, Hawkeye, hansfriese, Ch_301, KIntern_NA, bin2chen, rbserver, ladboy233, eccentricexit, 7siech, rvierdiiev, peakbolt, thecatking, and Ruhum
Vulnerability details
Harvest method is called on every deposit or withdraw into the Vault which further calls into the provided strategy.
This calling into strategy is limited by the cool down period. But in the current implementation is not properly respected.
Impact
Setting the cool down period for a strategy harvest callback method is not working properly so that on every deposit/withdraw into Vault also the strategy is called every time.
Proof of Concept
The main problem is that lastHarvest state variable is only set in the constructor:
and is not updated on strategy harvest method execution in the following lines:
Recommended Mitigation Steps
For the cool down period to work correctly, update tha lastHarvest state variable like this:
function harvest() public takeFees {
if (
address(strategy) != address(0) &&
((lastHarvest + harvestCooldown) < block.timestamp)
) {
+
+ lastHarvest = block.timestamp;
+
// solhint-disable
address(strategy).delegatecall(
abi.encodeWithSignature("harvest()")
);
}
emit Harvested();
}
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
The strategy harvest callback could be invoked on every deposit or withdrawal, so the configured cooldown period had no effect.
What the attacker needed
None
The fix
The harvest function should set lastHarvest to the current block timestamp before calling the strategy, so the cooldown is respected.
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 has a cooldown meant to stop a function from running too often. The code checked the time but forgot to record when the function last ran, so the check always passed. This meant the function could run every time someone deposited or withdrew money.
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.