Skip to content
Business logic Audit finding Intermediate

User cannot withdraw stakingToken due to incorrect calculation of _totalSupply

0xAnmol Follow with 0xvj, 9oelm and 33 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-03-zivoe-judging/issues/31

Found by

0xAnmol, 0xvj, 9oelm, AMOW, Afriaudit, Audinarey, Aymen0909, CL001, Dliteofficial, Drynooo, Ironsidesec, JigglypuffAndPikachu, KingNFT, Ruhum, Shield, SilverChariot, Tendency, Varun_05, amar, araj, asui, beWater0given, denzi_, dimulski, forgebyola, lemonmon, marchev, mt030d, rbserver, saidam017, sakshamguruji, samuraii77, sl1, supercool, t0x1c, zarkk01

Summary

User cannot withdraw stakingToken due to incorrect calculation of _totalSupply

Vulnerability Detail

Given:

1.userA VestingSchedule amountToVest= 20 ether ,daysToCliff=30 , daysToVest=120

2.userB VestingSchedule amountToVest= 30 ether , daysToCliff=30, daysToVest=120 _totalSupply =20 +30= 50

3.skip 60 days userB withdraw (amountWithdrawable =15) _totalSupply = 50-15=35

4.revoke userB VestingSchedule _totalSupply = 35-30=5 https://github.com/sherlock-audit/2024-03-zivoe/blob/d4111645b19a1ad3ccc899bea073b6f19be04ccd/zivoe-core-foundry/src/ZivoeRewardsVesting.sol#L451

5.skip 60 days (120 days later) userA withdraw (amountWithdrawable =20) _totalSupply = 5-20 lead to revert https://github.com/sherlock-audit/2024-03-zivoe/blob/d4111645b19a1ad3ccc899bea073b6f19be04ccd/zivoe-core-foundry/src/ZivoeRewardsVesting.sol#L508

POC: src/TESTS_Core/Test_ZivoeRewardsVesting.sol

Solidity

    function testpoc() public{
        assert(zvl.try_createVestingSchedule(
            address(vestZVE), 
            address(qcp), 
            30, 
            120,
            20 ether, 
            true
        ));
        assert(zvl.try_createVestingSchedule(
            address(vestZVE), 
            address(pam), 
            30, 
            120,
            30 ether, 
            true
        ));


        hevm.warp(block.timestamp + 60 days);

        vestZVE.amountWithdrawable(address(pam));
        //pam withdraw
         hevm.startPrank(address(pam));
        vestZVE.withdraw();
        hevm.stopPrank();
        vestZVE.totalSupply();

        //revokeVesting
        hevm.startPrank(address(zvl));
        vestZVE.revokeVestingSchedule(address(pam));
        hevm.stopPrank();
        vestZVE.totalSupply();

        //qcp withdraw
        hevm.warp(block.timestamp + 60 days);
        vestZVE.amountWithdrawable(address(qcp));
         hevm.startPrank(address(qcp));
        vestZVE.withdraw();
        hevm.stopPrank(); 
    }
[FAIL. Reason: panic: arithmetic underflow or overflow (0x11)] testpoc() (gas: 795816)

Impact

User cannot withdraw stakingToken

Code Snippet

https://github.com/sherlock-audit/2024-03-zivoe/blob/d4111645b19a1ad3ccc899bea073b6f19be04ccd/zivoe-core-foundry/src/ZivoeRewardsVesting.sol#L451

Tool used

Manual Review

Recommendation

Solidity
   function revokeVestingSchedule(address account) external updateReward(account) onlyZVLOrITO nonReentrant {
        require(
            vestingScheduleSet[account], 
            "ZivoeRewardsVesting::revokeVestingSchedule() !vestingScheduleSet[account]"
        );
        require(
            vestingScheduleOf[account].revokable, 
            "ZivoeRewardsVesting::revokeVestingSchedule() !vestingScheduleOf[account].revokable"
        );
        
        uint256 amount = amountWithdrawable(account);
        uint256 vestingAmount = vestingScheduleOf[account].totalVesting;

        vestingTokenAllocated -= amount;

        vestingScheduleOf[account].totalWithdrawn += amount;
        vestingScheduleOf[account].totalVesting = vestingScheduleOf[account].totalWithdrawn;
        vestingScheduleOf[account].cliff = block.timestamp - 1;
        vestingScheduleOf[account].end = block.timestamp;

        vestingTokenAllocated -= (vestingAmount - vestingScheduleOf[account].totalWithdrawn);

     -  _totalSupply = _totalSupply.sub(vestingAmount);
     + _totalSupply = _totalSupply.sub(amount);

Discussion

pseudonaut

Valid

sherlock-admin3

1 comment(s) were left on this issue during the judging contest.

panprog commented:

high. Incorrect (reduced) totalSupply will make late users being unable to claim their reward

pseudonaut

Recommended suggestion seems invalid, example (only one vesting schedule):

1,000 initial vesting schedule 200 claimed already 100 claimable

As a result of the 200 claimed already, totalSupply() should have decreased from 1000 -> 800

Given current logic, once the vesting schedule is revoked, it would reduce totalSupply() by amount only, from 800 -> 700 ... this leaves surplus of stake ... it should reduce total by the full amount of 800 so that totalSupply() at the end is 0 not 700

Calculation (as suggested in other PR) should be as follows:

Solidity
_totalSupply = _totalSupply.sub(vestingAmount - vestingScheduleOf[account].totalWithdrawn + amount);

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/Zivoe/zivoe-core-foundry/pull/268

sherlock-admin2

The Lead Senior Watson signed off on the fix.

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is known

A high-severity business logic bug in Zivoe. Sherlock made it public on 12 May 2024. Found in the 280 audit contest (finding H-3), also found by 35 other wardens.

About Business logic

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

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 0xAnmol

View all

7 more disclosed reports, best first.

More from Zivoe

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.