Closed c4-bot-8 closed 1 month ago
alcueca marked the issue as primary issue
Hi, thanks for your submission.
When dettach , the new balance may actually be higher than the previous one because it includes a reward, as a result, the supply will not be updated by the amount of this reward
It seems that this is an Overseverity for this issue, the only consequences are the withdraw calls that will not be possible for the latest veNFTs due to a mathematics error, with a simple mitigation for help this veNFTs
_withdrawClearNftInfo():
510: supply -= amount;
Thank you for your participation
I'd like to add some more information here for the judge and sponsors to consider as I also consider submitting this issue but later decided not to due to following reasons:
lockedRewards
comes from harvesting the distributed rewards in ManagedNFT's strategy
The strategy distributes the reward via compound
function
https://github.com/code-423n4/2024-09-fenix-finance/blob/main/contracts/nest/CompoundVeFNXManagedNFTStrategyUpgradeable.sol#L129-L139
function compound() external {
IERC20Upgradeable fenixCache = IERC20Upgradeable(fenix);
uint256 currentBalance = fenixCache.balanceOf(address(this));
if (currentBalance > 0) {
address votingEscrowCache = votingEscrow;
fenixCache.safeApprove(votingEscrowCache, currentBalance);
IVotingEscrowV1_2(votingEscrowCache).deposit_for_without_boost(managedTokenId, currentBalance);
ISingelTokenVirtualRewarder(virtualRewarder).notifyRewardAmount(currentBalance);
emit Compound(msg.sender, currentBalance);
}
}
and we can see here that the rewards are deposited and locked into the corresponding mVeNFT which increases the supply accordingly.
Therefore, VeNFT.supply
will already have been accounted for lockedRewards
I assumed that the protocol doesn't deduct the supply
as they already accounted for this in how the strategy contract distributes the rewards.
So, deduction again in veNFT.onDettachFromManagedNFT
would result in a wrong accounting of total supply.
It's either the strategy contract or veNFT contract that has the incorrect implementation. It can't be both.
@Nnez thank you. Since the reward is already contained in the mVeNFT, the methods onAttachToManagedNFT
and onDetachFromManagedNFT
only redistribute the existing balance between veNFT and mVeNFT, which does not change the total supply. The supply should only change when new tokens are added to the contract or withdrawn, which does not occur in the attachment or detachment methods. Since the reward is added through the compound method, it is already accounted for in the total supply.
alcueca marked the issue as unsatisfactory: Invalid
Lines of code
https://github.com/code-423n4/2024-09-fenix-finance/blob/main/contracts/core/VotingEscrowUpgradeableV2.sol#L295-L314
Vulnerability details
Impact
Withdrawing can be DoSed.
Proof of Concept
In the
VotingEscrowUpgradeableV2.onDetachFromManagedNFT
function, the locked amount is updated asnewBalance_
at L309.newBalance_
is greater than the actual deposited amount because it includeslockedRewards
received frommanagedNFTManager
at L218.When users withdraw their tokens, the locked amount including
lockedRewards
is subtracted fromsupply
at L510, butsupply
only cumulated actual deposited amount, not includinglockedRewards
. When users withdraw their tokens, the locked amount, includinglockedRewards
, is subtracted fromsupply
at L510. However,supply
only accumulates the actual deposited amount and does not account forlockedRewards
.As a result, this can cause withdrawing DoSed.
Let's consider the following scenario:
supply = 200
.supply = 200 - 100 = 100
.managedToken
and receives 1 FNX aslockedRewards
frommanagedNFTManager
. Her locked amount is then updated to 101 FNX, and the locking end time is updated tomaxUnlockTimestamp
.maxUnlockTimestamp
, Alice tries to withdraw her tokens, but the operation is reverted due to an underflow:supply = 100 < 101
.Tools Used
Manual Review
Recommended Mitigation Steps
It is recommended to change the code as following:
Assessed type
Other