Skip to content
Smart contracts Audit finding Intermediate

EarlyZEROVesting is having a rounding issue and

The EarlyZEROVesting contract splits a vesting amount into upfront and pending portions using two separate percentage calculations, so the two rounded parts can add up to less than the original amount. It also transfers a vested NFT to the staking bonus contract without first approving that contract, so the staking path always reverts.

dontonka Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

29225 - [SC - Insight] EarlyZEROVesting is having a rounding issue and...

Submitted on Mar 11th 2024 at 06:28:52 UTC by @dontonka for Boost | ZeroLend

Report ID: #29225

Report type: Smart Contract

Report severity: Insight

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

Impacts:

  • EarlyZEROVesting contract improvement: rounding issue and missing approval

Description

Brief/Intro

EarlyZEROVesting is having at least two minor issues which would need to be addressed. There is one rounding issue and one missing approval in order to transfer the vested NFT to the staking bonus contract.

Vulnerability Details

Rounding issue

If we take the following example calling startVesting with an amount of 99.

pending = 74.25 = (amount * 75) / 100 --> 74

upfront = 24.75 = (amount * 25) / 100 --> 24

spent = 99

As you can see, the NFT will represent a value of 98 (74 + 24) instead of 99, which is a loss of 1 wei.

Missing approval

When startVesting with staking operation, the current implementation will not work as it is missing an approval operation, so currently the vesting.safeTransferFrom will always revert.

Impact Details

  • 1 Wei precision lost per startVesting call.
  • Missing approval when staking, which will make this always reverts.

Recommendation

Apply the following changes in order to fix the two issues reported in this report.

Diff
    function startVesting(uint256 amount, bool stake) external {
        require(enableVesting || stake, "vesting not enabled; staking only");
        earlyZERO.burnFrom(msg.sender, amount);

        // vesting for earlyZERO is 25% upfront, 1 month cliff and
        // the rest (75%) across 3 months

+        //@audit: this will fix the 1 wei loss in precicion rounding issue.
+        uint256 upfront = (amount * 25) / 100;
+        uint256 pending = amount - upfront; 

        uint256 id = vesting.mint(
            stake ? address(this) : msg.sender, // address _who,
-            (amount * 75) / 100, // uint256 _pending,
-            (amount * 25) / 100, // uint256 _upfront,
+            pending, // uint256 _pending,
+            upfront, // uint256 _upfront,
            86400 * 30 * 3, // uint256 _linearDuration,
            86400 * 30, // uint256 _cliffDuration,
            block.timestamp, // uint256 _unlockDate,
            false, // bool _hasPenalty
            IVestedZeroNFT.VestCategory.EARLY_ZERO
        );

        // if the user chooses to stake then make sure to give the staking bonus
        if (stake) {
+           //@audit: this will fix the missing approval
+           vesting.approve(address(vesting), id);
            vesting.safeTransferFrom(
                address(this),
                stakingBonus,
                id,
                abi.encode(true, msg.sender)
            );
        }

        spent += amount;
    }

Proof of Concept

Not applicable really, simple by inspecting the code.

The original report as published on Immunefi, by dontonka. 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 contract computes the pending and upfront shares independently with integer division instead of deriving one from the other, and it calls safeTransferFrom without an approve call.

Impact

Each vesting call loses one wei of precision, and the staking option always reverts because the approval is missing.

What the attacker needed

Calling startVesting; staking option selected for the revert

The fix

The report recommends computing the upfront share first and subtracting it from the total to get the pending share, and adding an approve call before the transfer; the text does not say whether this was applied.

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 smart contract is a program on a blockchain that holds and moves digital tokens. When it splits an amount into two parts by multiplying and dividing, the leftover fraction gets dropped, so the parts can add up to slightly less than the whole. Separately, moving a token that represents ownership (an NFT) on someone else's behalf usually needs a permission step first, and here that step is missing, so the transfer fails.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by dontonka

View all

10 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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.