Buy fee PID is updated with wrong amounts leading to unexpected fee growth
The buy function updates the fee PID with the pre-fee Numa amount instead of the actual minted amount, causing the fee to grow incorrectly. This can lead to users paying higher fees than intended.
Source: https://github.com/sherlock-audit/2024-12-numa-audit-judging/issues/199
Found by
Afriaudit, OpaBatyo, zarkk01
Summary
Summary
updateBuyFeePID is invoked with Numa amount before fee, instead of the actual numa that was minted
Description
Let's take a look at the Numa buy flow.
uint256 numaAmount = vaultManager.tokenToNuma( // calculates how much numa we get for input amount reth
_inputAmount,
last_lsttokenvalueWei,
decimals,
_criticalScaleForNumaPriceAndSellFee
);
require(numaAmount > 0, "amount of numa is <= 0");
if (_transferREth) { // transfers the reth
SafeERC20.safeTransferFrom(
lstToken,
msg.sender,
address(this),
_inputAmount
);
}
uint fee = vaultManager.getBuyFee();
if (feeWhitelisted[msg.sender]) {
fee = 1 ether; // max percent (= no fee)
}
_numaOut = (numaAmount * fee) / 1 ether; // applies buy fee
require(_numaOut >= _minNumaAmount, "Min NUMA");
minterContract.mint(_receiver, _numaOut); // mint amount after fee
Buyers send their desired rETH which is exchanged for Numa and a buy fee is subtrtacted directly from the Numa they are owed. However at the end of the function, updateBuyFeePID is called in order to update the future buy fee of numa since supply increased.
vaultManager.updateBuyFeePID(numaAmount, true); // @audit-issue called with amount pre-tax
However the update function is invoked with numaAmount which is the number before the buy fee is applied. This is incorrect since the actual minted amount is smaller than what the updateBuyFeePID is called with. For instance, we send rETH to get 100 NUMA tokens, fee = 10%, we will get minted 90 NUMA tokens, however the vault manager will be updated as if 100 NUMA tokens were minted.
Let's have an example with a fee whitelisted user - they will pay no fees so _numaOut = numaAmount. If a whitelisted user deposits rETH to get 100 NUMA tokens, they will get minted 100 NUMA tokens and will invoke updateBuyFeePID with the 100 minted NUMA. Both users influenced the buy fee PID by 100 NUMA, however they got minted different amounts.
Further proof validating this issue can be seen in sell where updateBuyFeePID is invoked with the actual amount of Numa that was burnt, meaning that the amounts that are minted/burnt should be used in updating fee PID.
numa.burn(_numaAmount);
vaultManager.updateBuyFeePID(_numaAmount, false);
Root Cause
- In
NumaVault.buyNoMax,updateBuyFeePIDis invoked with wrong, inflated amount instead of the actual numa that was minted
Internal pre-conditions
none
External pre-conditions
none
Attack Path
none, wrong logic
Impact
- wrong fee calculation
- loss for users
PoC
No response
Mitigation
Invoke updateBuyFeePID with the actual minted amount in NumaVault.buyNoMax
Discussion
tibthecat
I don't think it makes a big difference. But I will check with team.
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
Impact
Users could pay higher fees over time due to incorrect fee growth.
What the attacker needed
None
The fix
The code should be fixed to call updateBuyFeePID with the actual minted amount.
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 you buy tokens, a fee is taken, so you get fewer tokens than the raw amount. The system also uses the raw amount to adjust future fees, which is wrong because it should use the actual tokens you received. This mistake makes fees grow too fast, costing users more.
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.