Vested tokens are counted as accumulated revenue
The contract's accumulated revenue calculation incorrectly treats vested staking tokens as revenue because unstaking reduces totalSupply without transferring tokens. An attacker could trigger reward distribution that swaps these tokens for vault shares, leaving insufficient balance to honour vested withdrawals and causing protocol insolvency.
Originally disclosed on Immunefi
- Disclosed after under an hour
#41365 [SC-Critical] Vested tokens are counted as accumulated revenue
Submitted on Mar 14th 2025 at 11:42:08 UTC by @armormadeofwoe for Audit Comp | Yeet
- Report ID: #41365
- Report Type: Smart Contract
- Report severity: Critical
- Target: https://github.com/immunefi-team/audit-comp-yeet/blob/main/src/StakeV2.sol
- Impacts:
- Protocol insolvency
- Theft of unclaimed yield
- Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield
Description
Brief/Intro
accumulatedDeptRewardsYeet incorrectly counts all vested staking tokens as revenue, allowing them to be swapped for vault shares and distributed as rewards to all stakers.
Vulnerability Details
accumulatedDeptRewardsYeet considers the difference between the live stakingToken.balanceOf(address(this)) and the user-deposited totalSupply as revenue.
function accumulatedDeptRewardsYeet() public view returns (uint256) {
return stakingToken.balanceOf(address(this)) - totalSupply;
}
Afterwards this amount can be swapped for additional rewards via executeRewardDistributionYeet
function executeRewardDistributionYeet(
IZapper.SingleTokenSwap calldata swap,
IZapper.KodiakVaultStakingParams calldata stakingParams,
IZapper.VaultDepositParams calldata vaultParams
) external onlyManager nonReentrant {
@> uint256 accRevToken0 = accumulatedDeptRewardsYeet();
require(accRevToken0 > 0, "No rewards to distribute");
@> require(swap.inputAmount <= accRevToken0, "Insufficient rewards to distribute");
The issue here lies within startUnstake, due to it subtracting the unstaked tokens from the totalSupply without transferring or accounting the stakingToken they should receive.
function startUnstake(uint256 unStakeAmount) external {
require(unStakeAmount > 0, "Amount must be greater than 0");
require(stakedTimes[msg.sender] < STAKING_LIMIT, "Amount must be less then the STAKING_LIMIT constant");
_updateRewards(msg.sender);
uint256 amount = balanceOf[msg.sender];
require(amount >= unStakeAmount, "Insufficient balance");
balanceOf[msg.sender] -= unStakeAmount;
@> totalSupply -= unStakeAmount;
@> // MISSING TRANSFER OR INTERNAL ACCOUNTING
uint256 start = block.timestamp;
uint256 end = start + VESTING_PERIOD;
vestings[msg.sender].push(Vesting(unStakeAmount, start, end));
stakedTimes[msg.sender]++;
}
So what happened is:
- User started and unstake which vests their token for 10 days
totalSupplywent down, however no token transfers took place- Calling
accumulatedDeptRewardsYeetwill return value equal to the vested amount
Let's see a practical example.
Assume there is no revenue, balanceOf(address(StakingV2)) == totalSupply == 100 tokens
- Bob unstakes his 60 tokens by calling
startUnstake totalSupply = 100 - 60 = 40, 10 day vesting period starts for Bob- Admin calls
executeRewardDistributionYeetwith input amount ==accumulatedDeptRewardsYeet == 60 - 60 staking tokens are swapped through the Zapper for vault shares
_handleVaultShareshandles reward distribution by updating the reward index.- 10 days pass
- Bob calls
unstake, however the method reverts sincebalanceOf(address(StakingV2)) = 40whileunlockedAmount = 60
NB! This example is severely simplified for illustrative purposes. One might argue that the admin would not perform the call, knowing that there is no current revenue. However under normal working conditions, the protocol will have hundreds/thousands of actors and it is not possible to track which funds are part of the vestings and which are accumulated revenue.
Impact Details
Protocol becomes insolvent since balanceOf(address(StakingV2)) < owed amount to unstaking parties.
Last person to withdraw their funds will be unable to due to insufficient balance.
Rewards had been stolen and distributed to other Yeet participants.
References
Proof of Concept
Proof of Concept
Attaching step-by-step from main body
Let's see a practical example.
Assume there is no revenue, balanceOf(address(StakingV2)) == totalSupply == 100 tokens
- Bob unstakes his 60 tokens by calling
startUnstake totalSupply = 100 - 60 = 40, 10 day vesting period starts for Bob- Admin calls
executeRewardDistributionYeetwith input amount ==accumulatedDeptRewardsYeet == 60 - 60 staking tokens are swapped through the Zapper for vault shares
_handleVaultShareshandles reward distribution by updating the reward index.- 10 days pass
- Bob calls
unstake, however the method reverts sincebalanceOf(address(StakingV2)) = 40whileunlockedAmount = 60
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 startUnstake function reduces totalSupply without transferring or internally accounting for the staking tokens, so the revenue calculation mistakenly includes vested amounts.
Impact
The protocol could become insolvent because its token balance falls below the amount owed to unstaking parties, and rewards may be stolen and distributed to other participants.
What the attacker needed
A user unstakes tokens; admin calls reward distribution
The fix
The startUnstake function should transfer the unstaked tokens to a vesting contract or adjust internal accounting so that vested tokens are not counted as revenue.
How it was found
- Bob unstakes his 60 tokens by calling startUnstake
- totalSupply becomes 40 and a 10-day vesting period starts for Bob
- Admin calls executeRewardDistributionYeet with input amount equal to accumulatedDeptRewardsYeet (60)
- 60 staking tokens are swapped through the Zapper for vault shares
- _handleVaultShares updates the reward index to distribute rewards
- After 10 days, Bob calls unstake but the transaction reverts because the contract balance is 40 while unlockedAmount is 60
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.
When a user unstakes, the contract reduces its record of total staked tokens but does not actually move the tokens out. The contract then thinks the difference between its actual token balance and the recorded total is profit, so it uses that 'profit' to pay rewards. This means users who are still waiting to withdraw their vested tokens may find the contract no longer has enough tokens to pay them.
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.