Revoking vesting schedule does not subtract user votes correctly
Source: https://github.com/sherlock-audit/2024-03-zivoe-judging/issues/118
Found by
0xAnmol, 0xpiken, 0xvj, 9oelm, Afriaudit, Ironsidesec, JigglypuffAndPikachu, KingNFT, KupiaSec, Ruhum, SilverChariot, Tendency, Tychai0s, Varun_05, amar, denzi_, dimulski, ether_sky, lemonmon, marchev, mt030d, rbserver, saidam017, sakshamguruji, samuraii77
Summary
ZivoeVestingRewards.revokeVestingSchedule() should reduce the voting power of the user with the withdrawable amount plus the revoked amount. However, it reduces it only by the withdrawable amount.
Vulnerability Detail
When called, revokeVestingSchedule() fetches the withdrawable amount by the user at that moment.
uint256 amount = amountWithdrawable(account);
The revoke logic is executed and the user's checkpoint value is decreased by amount.
_writeCheckpoint(_checkpoints[account], _subtract, amount);
The code ignores the amount that's being revoked and the user keeps more voting power than he has to.
Imagine the following:
totalVested = 1000
withdrawable = 0
If the schedule gets revoked, the user's checkpoint value will not be decreased at all because there is nothing to be withdrawn. The user can later use their voting power to vote on governance proposals.
In fact, amountWithdrawable(account) being close to 0 has a very high likelihood because:
- the user can frontrun the transaction and withdraw the tokens they are entitled to
- it's highly likely that a vesting schedule will be removed shortly after creating it.
However, even if amountWithdrawable() is not equal to 0, the user would still be left with more voting power.
Impact
Users keep voting power that must have been taken away.
Code Snippet
POC to be run in Test_ZivoeRewardsVesting.sol
function test_revoking_leaves_votes() public {
assert(zvl.try_createVestingSchedule(
address(vestZVE),
address(moe),
0,
360,
6000 ether,
true
));
// Vesting succeeded
assertEq(vestZVE.balanceOf(address(moe)), 6000 ether);
hevm.roll(block.number + 1);
// User votes have increased
assertEq(vestZVE.getPastVotes(address(moe), block.number - 1), 6000 ether);
assert(zvl.try_revokeVestingSchedule(address(vestZVE), address(moe)));
// Revoking succeeded
assertEq(vestZVE.balanceOf(address(moe)), 0);
hevm.roll(block.number + 1);
// User votes have not been decreased at all
assertEq(vestZVE.getPastVotes(address(moe), block.number - 1), 6000 ether);
}
Tool used
Foundry
Recommendation
Subtract the correct amount from the checkpoint's value
- _writeCheckpoint(_checkpoints[account], _subtract, amount);
+ _writeCheckpoint(_checkpoints[account], _subtract, vestingAmount - vestingScheduleOf[account].totalWithdrawn + amount)
Discussion
sherlock-admin4
1 comment(s) were left on this issue during the judging contest.
panprog commented:
high, incorrect checkpoints amount subtracted during
revokeVestingSchedulecauses permanent inflated amount of user votes.
pseudonaut
Recommended suggestion seems incorrect
It doesn't address the totalSupplyCheckpoints right above that line (both should be in tandem):
_writeCheckpoint(_totalSupplyCheckpoints, _subtract, vestingAmount - vestingScheduleOf[account].totalWithdrawn + amount);
_writeCheckpoint(_checkpoints[account], _subtract, 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.
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-4), also found by 24 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.