Skip to content
Business logic Audit finding Intermediate

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.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

CrvDepositor.sol#L127-L134

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:

  1. Change L94-102 to:

CrvDepositor.sol#L94-L102

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;
  1. 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:

code-423n4/2022-05-aura#6


The original report as published on Code4rena, by WatchPug. 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

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.

More by WatchPug

View all

197 more disclosed reports, best first.

More from Aura Finance 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.