In ReaperVaultV2 , we should update lockedProfit and lastReport before changing lockedProfitDegradation
The contract's locked profit calculation uses the current degradation rate over the entire period since the last report, so changing that rate retroactively alters how much profit is considered unlocked. A malicious depositor could front-run the admin's rate change with a large deposit to capture extra yield that was not previously available.
Originally disclosed on Code4rena
Submitted by hansfriese
The locked profit degradation for the past will be changed with the new lockedProfitDegradation.
As a result, malicious users can steal others’ rewards by frontrunning.
Proof of Concept
setLockedProfitDegradation() is used to change lockedProfitDegradation by admin.
function setLockedProfitDegradation(uint256 degradation) external {
_atLeastRole(ADMIN);
require(degradation <= DEGRADATION_COEFFICIENT, "Degradation cannot be more than 100%");
lockedProfitDegradation = degradation;
emit LockedProfitDegradationUpdated(degradation);
}
And lockedProfitDegradation is used to calculate the locked profit.
function _calculateLockedProfit() internal view returns (uint256) {
uint256 lockedFundsRatio = (block.timestamp - lastReport) * lockedProfitDegradation;
if (lockedFundsRatio < DEGRADATION_COEFFICIENT) {
return lockedProfit - ((lockedFundsRatio * lockedProfit) / DEGRADATION_COEFFICIENT);
}
return 0;
}
But it doesn’t update lockedProfit and lastReport before changing lockedProfitDegradation so the below scenario would be possible.
- Let’s assume
lockedProfit = 200, lastReport = block.timestampafter callingreport(),lockedProfitDegradationare6 hours in blocks. - 3 hours later, 100 tokens of
lockedProfitare released and added to the free funds. We can assumereport()wasn’t called for 3 hours. - At that time,
lockedProfitDegradationis changed to4 hours in blocksand it means200 * 3 / 4 = 150tokens are released. As a result, free funds are increased by 50 inside the same block. - So a malicious user(it should be a pool) can front run
deposit()with huge amounts beforelockedProfitDegradationis changed and charge most of the new rewards(=50).
Similarly, already unlocked funds will be treated as locked again if lockedProfitDegradation is decreased.
Even if there is no front run as all depositors are pools, it’s not fair to change locked/unlocked amounts that are confirmed already.
Recommended Mitigation Steps
We should modify setLockedProfitDegradation() like below.
function setLockedProfitDegradation(uint256 degradation) external {
_atLeastRole(ADMIN);
require(degradation <= DEGRADATION_COEFFICIENT, "Degradation cannot be more than 100%");
// update lockedProfit and lastReport
lockedProfit = _calculateLockedProfit();
lastReport = block.timestamp;
lockedProfitDegradation = degradation;
emit LockedProfitDegradationUpdated(degradation);
}
Trust (judge) increased severity to High
tess3rac7 (Ethos Reserve) disagreed with severity and commented:
I don’t think this qualifies as a “high”. It relies on a large harvest, followed by no harvests for a considerable amount of time, followed by the ADMIN (multisig) calling
setLockedProfitDegradation()to set the degradation to a smaller value and being front-run by a malicious user callingdeposit().
- depositors are whitelisted via the
DEPOSITORrole, so in this case they are trusted- the ADMIN multisig wouldn’t randomly change the degradation value without a really good reason to do so
- even if a whitelisted depositor turns malicious, and the ADMIN multisig ends up invoking
setLockedProfitDegradation(), and ADMIN’s TX gets front-run by said malicious depositor, it would, at best, result in some extra yield being squeezed by the malicious depositor—ONLY IF they have enough capital to overshadow the vault’s TVL. There would be no loss of principal assets whatsoever for any depositor.There is slim chance for favorable conditions for this type of attack to succeed, and the capital requirements for the attacker would be quite high. And even after doing all this, they would at best earn a few more tokens out of the locked yield without impact any other user’s deposits. It’s not even a repeatable attack because ADMIN won’t keep calling
setLockedProfitDegradation()over and over. Very low risk in my opinion.
Trust (judge) decreased severity to Medium
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 setter changes the degradation rate without first checkpointing the locked profit and last report time, so the new rate is applied retroactively to the whole elapsed period.
Impact
A malicious depositor could capture extra yield, but only if they have enough capital to overshadow the vault's total value locked, and there is no loss of principal; the project argued the conditions are unlikely and the admin would not change the rate often.
What the attacker needed
Admin changes the degradation rate; attacker is a whitelisted depositor; attacker front-runs the admin transaction; attacker has large capital
The fix
The setter should first update the locked profit and last report time using the old rate, then apply the new degradation rate.
How it was found
- A report sets locked profit and last report time with a six-hour degradation rate.
- Three hours pass without another report, so part of the locked profit is considered unlocked.
- The admin changes the degradation rate to four hours, which recalculates the whole three-hour period and releases more profit.
- A malicious depositor front-runs the admin's transaction with a large deposit to capture most of the newly released profit.
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 holds profit that unlocks gradually over time. The speed of unlocking is set by an admin. If the admin changes that speed, the contract recalculates the whole past period at the new speed, which can suddenly release more profit. Someone who sees the admin's change coming can deposit just before it and take a share of that extra profit.
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.