Skip to content
Business logic Audit finding Intermediate

UniswapHandler.maltMarketPrice returns wrong decimals

The UniswapHandler.maltMarketPrice function returns incorrect decimals for the price in one branch, which could cause callers to misinterpret the price and inflate or deflate amounts. However, the only current caller ignores the decimals, so no actual issue arises.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel, also found by gzeon

The UniswapHandler.maltMarketPrice function returns a tuple of the price and the decimals of the price. However, the returned decimals do not match the computed price for the else if (rewardDecimals < maltDecimals) branch:

else if (rewardDecimals < maltDecimals) {
  uint256 diff = maltDecimals - rewardDecimals;
  price = (rewardReserves.mul(10**diff)).mul(10**rewardDecimals).div(maltReserves);
  decimals = maltDecimals;
}

Note that rewardReserves are in reward token decimals, maltReserves is a malt balance amount (18 decimals). Then, the returned amount is in rewardDecimals + diffDecimals + rewardDecimals - maltDecimals = maltDecimals + rewardDecimals - maltDecimals = rewardDecimals. However decimals = maltDecimals is wrongly returned.

Impact

Callers to this function will receive a price in unexpected decimals and might inflate or deflate the actual amount. Luckily, the AuctionEscapeHatch decides to completely ignore the returned decimals and as all prices are effectively in rewardDecimals, even if stated in maltDecimals, it currently does not seem to lead to an issue.

Recommendation

Fix the function by returning rewardDecimals instead of maltDecimals in the rewardDecimals < maltDecimals branch.

0xScotch (sponsor) confirmed

Alex the Entreprenerd (judge) commented:

Finding is valid, because the returned value is unused, I agree with the medium severity

The original report as published on Code4rena, by cmichel. 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

Root cause

Likely, the function incorrectly returns maltDecimals instead of rewardDecimals in the branch where rewardDecimals is less than maltDecimals, due to a copy-paste or logic error.

Impact

Callers could receive a price with unexpected decimals and might inflate or deflate the actual amount, but the only current caller ignores the decimals, so no issue currently arises.

What the attacker needed

None

The fix

The function should be fixed by returning rewardDecimals instead of maltDecimals in the rewardDecimals < maltDecimals branch.

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.

This is a smart contract bug where a function that calculates a price also says how many decimal places that price has, but in one case it gives the wrong number. If another part of the code trusted that number, it could misjudge the price and send wrong amounts. Luckily, the code that uses this function ignores the decimal count, so nothing bad happened.

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 cmichel

View all

196 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.