Skip to content
Business logic Audit finding Beginner

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.

imare Follow with Walter, Malatrax and 13 others

Originally disclosed on Code4rena

Submitted by imare, also found by Walter, Malatrax, Hawkeye, hansfriese, Ch_301, KIntern_NA, bin2chen, rbserver, ladboy233, eccentricexit, 7siech, rvierdiiev, peakbolt, thecatking, and Ruhum

https://github.com/code-423n4/2023-01-popcorn/blob/d95fc31449c260901811196d617366d6352258cd/src/vault/adapter/abstracts/AdapterBase.sol#L86

https://github.com/code-423n4/2023-01-popcorn/blob/d95fc31449c260901811196d617366d6352258cd/src/vault/adapter/abstracts/AdapterBase.sol#L438-L450

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:

https://github.com/code-423n4/2023-01-popcorn/blob/d95fc31449c260901811196d617366d6352258cd/src/vault/adapter/abstracts/AdapterBase.sol#L86

and is not updated on strategy harvest method execution in the following lines:

https://github.com/code-423n4/2023-01-popcorn/blob/d95fc31449c260901811196d617366d6352258cd/src/vault/adapter/abstracts/AdapterBase.sol#L438-L450

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();
    }

RedVeil (Popcorn) confirmed


The original report as published on Code4rena, by imare. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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.

More by imare

View all

1 more disclosed report, best first.

More from Popcorn contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.