Skip to content
Business logic Audit finding Intermediate

Lack of check for Lockend in merge LockerToken

The merge function combined two locked NFTs without checking that the resulting lock span stayed within the maximum allowed time, so the merged NFT could have a longer duration than permitted. An attacker could use this to inflate the voting power of a locker in governance.

offside0011 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

28885 - [SC - Medium] Lack of check for Lockend in merge LockerToken ...

Submitted on Feb 29th 2024 at 22:55:06 UTC by @offside0011 for Boost | ZeroLend

Report ID: #28885

Report type: Smart Contract

Report severity: Medium

Target: https://github.com/zerolend/governance

Impacts:

  • Manipulation of governance voting result deviating from voted outcome and resulting in a direct change from intended effect of original results

Description

Brief/Intro

When merging two Locker NFTs, there were no strict restrictions on the start and end times of the two NFTs. This resulted in the final merged NFT having a time range that exceeded the preset maximum time, consequently increasing the locking power.

Vulnerability Details

In the file BaseLocker.sol, the maximum time that an NFT can be set is externally passed in. For LockerToken, it is set as 4 * 365 * 86400, and for LockerLP, it is 365 * 86400. The staking duration is crucial for the final power calculation. In the _calculatePower function, the formula is ((lock.end - lock.start) * lock.amount) / MAXTIME;. Therefore, there are strict restrictions in both the _createLock and increaseUnlockTime functions to ensure that the time span(lock.end - lock.start) of an NFT does not exceed MAXTIME.

In the merge function, two NFTs can be combined, and the end time is selected from the later time of the two NFTs. In the _depositFor function, there is no further check on the time span.

Taking LockerLP as an example, suppose an attacker initially stakes an NFT (NFT1) for 1 year, then, after a month, stakes another NFT (NFT2) for 1 year. The attacker then calls the merge function,

merge(NFT2, NFT1);

In the merge function,

uint256 end = _locked0.end >= _locked1.end
    ? _locked0.end
    : _locked1.end;

selects the time of the later NFT and assigns it to the second parameter "to", which is NFT1. At this point, the final NFT has a start of NFT1's start and an end of NFT2's end, resulting in a time span of 1 year and 1 month. In the final calculation of _calculatePower, the returned formula is

function _calculatePower(
    LockedBalance memory lock
) internal view returns (uint256) {
     return ((lock.end - lock.start) * lock.amount) / MAXTIME;
}

, which amplifies the nft's Power.

Impact Details

Amplifying the power of a locker in the governance

References

https://github.com/zerolend/governance/blob/main/contracts/locker/BaseLocker.sol#L183

Proof of Concept (Take LockerLP as Example)

  1. call createLockFor, _lockDuration = 4 * 365 * 86400 return nftid=1
  2. vm.wrap(block.timestamp + 86400 * 30)
  3. call createLockFor, _lockDuration = 4 * 365 * 86400 return nftid=2
  4. merge(2, 1)# 2 is burned and locker(1).end = locker(2).end

The original report as published on Immunefi, by offside0011. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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 merge function picks the later end time of the two locks and deposits into the target without re-validating that the resulting span does not exceed MAXTIME.

Impact

The inflated lock duration could amplify a locker's power in governance, potentially manipulating voting results away from the intended outcome.

What the attacker needed

Ability to create locks and merge NFTs

The fix

The merge function should re-check that the resulting lock span does not exceed MAXTIME before depositing.

How it was found

  1. Create a first lock with the maximum duration, producing one NFT.
  2. Advance time by about a month.
  3. Create a second lock with the maximum duration, producing a second NFT.
  4. Merge the second NFT into the first so the first keeps its earlier start but takes the later end.

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 locker lets you lock tokens for a set period, and the longer you lock, the more voting power you get. The code caps how long a lock can last, but when two locks are merged the cap was not re-checked, so the combined lock could last longer than allowed and give extra voting power.

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 offside0011

View all

4 more disclosed reports, best first.

More from ZeroLend

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.