Skip to content
Business logic Audit finding Intermediate

Upon IncreaseAmount the lock may not align to the nearest weekly increment

The IncreaseAmount function sets the lock end time to the current block timestamp plus the lock duration without rounding down to the nearest weekly increment, unlike other lock creation paths. This misalignment can cause the checkpoint logic to compute incorrect slopes, leading to wrong voting power and relative votes.

gzeon Follow

Originally disclosed on Code4rena

Submitted by gzeon

Note: This audit was preceded by a Code4rena Test Coverage competition. While auditing was not the purpose of the testing phase, relevant and valuable findings reported during that phase were eligible to be judged. This finding [M-02] was discovered during that period and is being included here for completeness.

In most other places, locks are created with the end time rounded down to nearest weekly increment using the _floorToWeek function.

https://github.com/OpenCoreCH/test-squad-verwa/blob/461b7d99a30e8fee57ba97c2262f6b0c5e4704b6/src/VotingEscrow.sol#L422-L426

    // @dev Floors a timestamp to the nearest weekly increment
    // @param _t Timestamp to floor
    function _floorToWeek(uint256 _t) internal pure returns (uint256) {
        return (_t / WEEK) * WEEK;
    }

However in IncreaseAmount, it is simply set to block.timestamp + LOCKTIME without the rounding:

https://github.com/OpenCoreCH/test-squad-verwa/blob/461b7d99a30e8fee57ba97c2262f6b0c5e4704b6/src/VotingEscrow.sol#L301-L302

        newLocked.end = block.timestamp + LOCKTIME;

141345 (Lookout) commented:

Locked.end will affect the delegate/undelegate requirement, such as the following check.

File: src\VotingEscrow.sol
382:         require(toLocked.amount > 0, "Delegatee has no lock");
383:         require(toLocked.end > block.timestamp, "Delegatee lock expired");
384:         require(toLocked.end >= fromLocked.end, "Only delegate to longer lock");

OpenCoreCH (veRWA) confirmed and commented:

This was discovered during the testing contest and fixed before the audit contest, pasting my comment here for reference:

Good catch, I think that would mess up the _checkpoint logic which implicitly assumes that the lock times are aligned, so will definitely be fixed.

alcueca (Judge) commented:

Impact from sponsor:

These slope changes would not have been applied (neither the user-specific ones, nor the global ones), resulting in wrong slopes. And if many users did this, many slopes would be messed up at some point, leading to wrong votes / relative votes.


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

If many users increase their lock amount, many slopes would be messed up at some point, leading to wrong votes or relative votes.

What the attacker needed

User calls IncreaseAmount

The fix

The issue was fixed before the audit contest by ensuring the lock end time is aligned to the nearest weekly increment.

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.

In this voting system, lock end times are supposed to be rounded down to the nearest week so that the maths for calculating voting power works correctly. One function forgot to do that rounding, so the end time could be any day. That mismatch can make the system calculate the wrong voting power for users.

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 gzeon

View all

46 more disclosed reports, best first.

More from veRWA

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.