Skip to content
Smart contracts Audit finding Intermediate

customPrecisionMultipliers would be rounded to zero and break the pool

The custom precision multipliers in the pool constructor are calculated by multiplying the original precision multiplier by the target price and dividing by 10^18. If the target price is less than 10^18, the result rounds down to zero, breaking the pool and locking all funds.

jonah1005 Follow

Originally disclosed on Code4rena

Submitted by jonah1005

Impact

CustomPrecisionMultipliers are set in the constructor:

customPrecisionMultipliers[0] = targetPriceStorage.originalPrecisionMultipliers[0].mul(_targetPrice).div(10 ** 18);

originalPrecisionMultipliers equal to 1 if the token’s decimal = 18. The targe price could only be an integer.

If the target price is bigger than 10**18, the user can deposit and trade in the pool. Though, the functionality would be far from the spec.

If the target price is set to be smaller than 10**18, the pool would be broken and all funds would be stuck.

I consider this is a high-risk issue.

Proof of Concept

Please refer to the implementation. Swap.sol#L184-L187

We can also trigger the bug by setting a pool with target price = 0.5. (0.5 * 10**18)

Tools Used

None

Recommended Mitigation Steps

I recommend providing extra 10**18 in both multipliers.

customPrecisionMultipliers[0] = targetPriceStorage.originalPrecisionMultipliers[0].mul(_targetPrice).mul(10**18).div(10 ** 18);
customPrecisionMultipliers[1] = targetPriceStorage.originalPrecisionMultipliers[1].mul(10**18);

The customswap only supports two tokens in a pool, there’s should be enough space. Recommend the devs to go through the trade-off saddle finance has paid to support multiple tokens. The code could be more clean and efficient if the pools’ not support multiple tokens.

chickenpie347 (Boot Finance) confirmed

The original report as published on Code4rena, by jonah1005. 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 integer division truncation: the multiplication result is divided by 10^18 without scaling up first, so any target price below 10^18 yields zero.

What the attacker needed

Pool deployed with target price < 10^18

The fix

The multipliers should be scaled by an extra 10^18 before division to avoid rounding to zero.

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 number is calculated by multiplying and then dividing by a large constant. If the multiplication result is smaller than the divisor, the division rounds down to zero. That zero multiplier then breaks the pool's maths, so users cannot withdraw their money.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by jonah1005

View all

39 more disclosed reports, best first.

More from Boot Finance contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.