Skip to content
Business logic Audit finding Intermediate

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

https://github.com/code-423n4/2023-02-malt/blob/700f9b468f9cf8c9c5cffaa1eba1b8dea40503f9/contracts/StabilityPod/SwingTraderManager.sol#L252-L258

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().

0xScotch (Malt) confirmed


The original report as published on Code4rena, by minhquanym. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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.

More by minhquanym

View all

28 more disclosed reports, best first.

More from Malt Protocol - Versus contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.