CrvDepositor.sol Wrong implementation of the 2-week buffer for lock
The lock-extension logic in CrvDepositor compared a value in seconds against the number 2, so the intended two-week buffer behaved like a two-second buffer. This let the lock be extended as soon as a new week began rather than waiting two weeks.
Submitted by WatchPug
uint256 unlockAt = block.timestamp + MAXTIME;
uint256 unlockInWeeks = (unlockAt/WEEK)*WEEK;
//increase time too if over 2 week buffer
if(unlockInWeeks.sub(unlockTime) > 2){
IStaker(staker).increaseTime(unlockAt);
unlockTime = unlockInWeeks;
}
In _lockCurve(), unlockInWeeks - unlockTime is being used as a number in weeks, while it actually is a number in seconds.
Thus, comparing it with 2 actually means a 2 seconds buffer instead of a 2 weeks buffer.
The intention is to wait for 2 weeks before extending the lock time again, but the current implementation allows the extension of the lock once a new week begins.
Recommended Mitigation Steps
Consider changing the name of unlockTime to unlockTimeInWeeks, and:
- Change L94-102 to:
uint256 unlockAt = block.timestamp + MAXTIME;
uint256 unlockInWeeks = unlockAt / WEEK;
//release old lock if exists
IStaker(staker).release();
//create new lock
uint256 crvBalanceStaker = IERC20(crvBpt).balanceOf(staker);
IStaker(staker).createLock(crvBalanceStaker, unlockAt);
unlockTimeInWeeks = unlockInWeeks;
- Change L127-L134 to:
uint256 unlockAt = block.timestamp + MAXTIME;
uint256 unlockInWeeks = unlockAt / WEEK;
//increase time too if over 2 week buffer
if(unlockInWeeks.sub(unlockTime) > 2){
IStaker(staker).increaseTime(unlockAt);
unlockTimeInWeeks = unlockInWeeks;
}
0xMaharishi (Aura Finance) confirmed and resolved:
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 code subtracted a timestamp in seconds from a week count and compared the result to 2, mixing units so the two-week buffer became a two-second one.
Impact
The lock could be extended once a new week begins instead of after a two-week buffer, so the intended delay was not enforced.
What the attacker needed
None
The fix
The team confirmed and resolved it by keeping the unlock time in weeks and comparing week counts, as the report recommended.
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 contract locks tokens for a period and sometimes extends that lock. The code meant to wait two weeks before extending again, but it measured time in seconds while comparing against the number 2, so it only waited about two seconds. The result is that the lock gets extended far more often than intended.
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.