Skip to content
DoS Audit finding Intermediate

boostedValue should be added to permanentTotalSupply for permanently locked tokens

The boosted value added to a token's locked amount was not included in permanentTotalSupply, so the last user to unlock a permanent lock could cause an underflow and be unable to unlock. This could leave the last user's tokens temporarily locked.

KupiaSec Follow with nnez

Originally disclosed on Code4rena

Submitted by KupiaSec, also found by nnez

Unlocking tokens from the permanent locking can be DoSed.

Proof of Concept

In the VotingEscrowUpgradeableV2._processLockChange function, boostedValue is added to the token’s locked amount at L465. However, boostedValue is not added to permanentTotalSupply for permanently locked tokens at L470.

File: contracts\core\VotingEscrowUpgradeableV2.sol
465:@>       newLocked.amount += LibVotingEscrowUtils.toInt128(boostedValue);
466:         uint256 diff = LibVotingEscrowUtils.toUint256(newLocked.amount - oldLocked_.amount);
467:         uint256 supplyBefore = supply;
468:         supply += diff;
469:         if (newLocked.isPermanentLocked) {
470:@>           permanentTotalSupply += amount_;
471:         }

In the unlockPermanent function, the token’s locked amount is subtracted from permanentTotalSupply at L219.

File: contracts\core\VotingEscrowUpgradeableV2.sol
219:         permanentTotalSupply -= LibVotingEscrowUtils.toUint256(state.locked.amount);

As a result, calling this function may be reverted by the underflow.

Let’s consider the following scenario:

  1. Alice and Bob each create locks with 100 FNX for a 1-week duration (< veBoostCached.getMinLockedTimeForBoost).

  2. Alice and Bob lock their tokens permanently: permanentTotalSupply = 100 + 100 = 200.

  3. Alice deposits 1000 FNX (>= veBoostCached.getMinFNXAmountForBoost), and _boostFNXPercentage is 1000 (10%):

    • boostedValue: 100.
    • Total locked amount: 100 + 1000 + 100 = 1200.
    • permanentTotalSupply: 200 + 1000 = 1200.
  4. Alice unlocks her token from the permanent lock: permanentTotalSupply = 1200 - 1200 = 0.

  5. Bob tries to unlock his token from the permanent lock, but it is reverted because permanentTotalSupply is 0.

Recommended Mitigation Steps

It is recommended to change the code in the VotingEscrowUpgradeableV2._processLockChange function as the following:

        if (newLocked.isPermanentLocked) {
-           permanentTotalSupply += amount_;
+           permanentTotalSupply = permanentTotalSupply + amount_ + boostedValue;
        }

Assessed type

DoS

b-hrytsak (Fenix) confirmed and commented:

Indeed. After refactoring and changes, this point, although known, was missed in the new code.

It is difficult to understand the severity of this issue, it seems to be Overseverity. If we go with the worst-case scenario, the last user/users will not be able to unlock the permanent lock on their veNFTs, which will lead them to some additional temporary lock until the problem is resolved, as they would have to wait 182 days for full unlocking anyway.

alcueca (judge) decreased severity to Medium

KupiaSec (warden) commented:

@alcueca - I think this is high severity. This vulnerability leads not only to a DoS but also to an incorrect calculation of voting power in the _balanceOfNFT function due to the incorrect accumulation of permanentTotalSupply.

File: contracts\core\VotingEscrowUpgradeableV2.sol
532:     function _checkpoint(uint256 tokenId_, LockedBalance memory oldLocked_, LockedBalance memory newLocked_) internal {
             [...]
616:@>       last_point.permanent = LibVotingEscrowUtils.toInt128(permanentTotalSupply);
File: contracts\core\VotingEscrowUpgradeableV2.sol
647:     function _balanceOfNFT(uint256 tokenId_, uint256 timestamp_) internal view returns (uint256 balance) {
649:         if (pointEpoch > 0) {
650:             Point memory lastPoint = nftPointHistory[tokenId_][pointEpoch];
651:             if (lastPoint.permanent > 0) {
652:@>               return LibVotingEscrowUtils.toUint256(lastPoint.permanent);

alcueca (judge) increased severity to High and commented:

This vulnerability leads … also to an incorrect calculation of voting power

This was not pointed out in the original submission, but it is right.

b-hrytsak (Fenix) commented:

@KupiaSec, @alcueca - In the balanceOfNFT calculation, data regarding the permanentTotalSupply is not used, and the impact of not accounting boostedValue in permanentTotalSupply is limited only to the calculation of the total voting power. This does not affect on votes processing, but only the outcome (votingPowerTotalSupply()). The voting power for a user’s veNFT will still be calculated correctly.

This statement most likely arose because similar structures and pieces of code are used for the general voting power calculation and for the user. However, last_point in _checkpoint is from supplyPointsHistory, whereas in balanceOfNFT, nftPointHistory is used.

Ch_301 (warden) commented:

@alcueca, @KupiaSec - I believe there is some wrong assumption in this issue. The last_point.permanent and lastPoint.permanent are not the same thing in this logic.

last_point.permanent is related to supplyPointsHistory[] this mapping which is tracking the total supply changes.

However, lastPoint.permanent that used in _balanceOfNFT() is from nftPointHistory[][] this mapping which is recording the changes over time for every veNFT.

The value of lastPoint.permanent is updated here

            u_new.permanent = permanent;
            nftPointHistory[tokenId_][nftStates[tokenId_].pointEpoch] = u_new;
        }

Which is acutely only this amount here. The impact is more like this QA (not a duplicate) last user can’t call unlockPermanent() successfully.

KupiaSec (warden) commented:

There is a confusion for two variables and I agree there is no incorrect calculation of voting power by the permanentTotalSupply. But there still exists DoS vulnerability.

Ch_301 (warden) commented:

@KupiaSec, I’m not sure if we can call this denial-of-service, because only the last permanent-lock is affected by losing his locked FNX tokens!

alcueca (judge) decreased severity to Medium and commented:

I think the last permanent lock being affected reasonably often merits a medium severity. Thanks @KupiaSec for retracting your previous statement about permanentTotalSupply.

Note: For full discussion, see here.


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

Likely the boostedValue was added to the locked amount but not to permanentTotalSupply when a lock became permanent.

Impact

The last user to unlock a permanent lock could be unable to do so, leaving their tokens temporarily locked; the text notes they would have to wait 182 days for full unlocking anyway.

What the attacker needed

A user locks tokens permanently; another user deposits enough to get a boost; the boosted user unlocks first

The fix

The code should be changed so that permanentTotalSupply is increased by both amount_ and boostedValue when a lock becomes permanent.

How it was found

  1. Alice and Bob each create locks with 100 FNX for a 1-week duration.
  2. Alice and Bob lock their tokens permanently, making permanentTotalSupply 200.
  3. Alice deposits 1000 FNX, which adds a boostedValue of 100 to her locked amount.
  4. Alice unlocks her token from the permanent lock, reducing permanentTotalSupply to 0.
  5. Bob tries to unlock his token from the permanent lock, but the transaction reverts because permanentTotalSupply is 0.

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.

When you lock tokens permanently, the contract keeps a running total of all permanently locked tokens. A bonus amount was added to individual locks but not to that total, so when the last person tried to unlock, the contract tried to subtract more than the total and failed. This meant the last user could not unlock their tokens until the issue was fixed.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by KupiaSec

View all

28 more disclosed reports, best first.

More from Fenix Finance Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.