Value of totalProfit might be wrong because of wrong logic in function sellMalt()
The sellMalt function returns early when the amount sold plus a dust threshold reaches the maximum, skipping the update of the totalProfit variable. As a result, totalProfit can be understated, affecting other contracts that rely on it.
minhquanym Follow with cccz and hansfriese
Originally disclosed on Code4rena
Submitted by minhquanym, also found by cccz and hansfriese
Contract SwingTraderManager has a totalProfit variable. It keeps track of total profit swing traders made during sellMalt(). However, the logic for accounting is wrong so it will not have the correct value. As the results, it can affect other contracts that integrate with SwingTraderManager and use this totalProfit variable.
Proof of Concept
if (amountSold + dustThreshold >= maxAmount) {
return maxAmount;
}
totalProfit += profit;
// @audit did not update because already return above
emit SellMalt(amountSold, profit);
Function sellMalt() has a dust check before returning result. totalProfit should be updated before this check as it returns the value immediately without updating totalProfit.
Recommended Mitigation Steps
Updating totalProfit before the dust check in function sellMalt().
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
The totalProfit value can be incorrect, which may affect other contracts that integrate with SwingTraderManager and use this variable.
What the attacker needed
None
The fix
The totalProfit update should be moved before the dust check in sellMalt.
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.
A smart contract keeps a running total of profits from selling a token. When a sale is large enough, the function exits early and forgets to add that profit to the total. Other programs that read this total will see a number that is too low.
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.