Skip to content
Business logic Audit finding Intermediate

Wrong token allocation computation for token decimals != 18 if floor price not reached

The token allocation calculation in the launch event used the token's own decimals instead of a fixed 18-decimal scale, so for tokens with decimals other than 18 the result was wrong. When the floor price was not reached, this could allocate zero tokens to the pool instead of the correct reduced amount.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel

In LaunchEvent.createPair, when the floor price is not reached (floorPrice > wavaxReserve * 1e18 / tokenAllocated), the tokens to be sent to the pool are lowered to match the raised WAVAX at the floor price.

Note that the floorPrice is supposed to have a precision of 18:

/// @param _floorPrice Price of each token in AVAX, scaled to 1e18

The floorPrice > (wavaxReserve * 1e18) / tokenAllocated check is correct but the tokenAllocated computation involves the token decimals:

// @audit should be wavaxReserve * 1e18 / floorPrice
tokenAllocated = (wavaxReserve * 10**token.decimals()) / floorPrice;

This computation does not work for tokens that don’t have 18 decimals.

Example

Assume I want to sell 1.0 wBTC = 1e8 wBTC (8 decimals) at 2,000.0 AVAX = 2,000 * 1e18 AVAX. The floorPrice is 2000e18 * 1e18 / 1e8 = 2e31

Assume the Launch event only raised 1,000.0 AVAX - half of the floor price for the issued token amount of 1.0 WBTC (it should therefore allocate only half a WBTC) - and the token amount will be reduced as: floorPrice = 2e31 > 1000e18 * 1e18 / 1e8 = 1e31 = actualPrice. Then, tokenAllocated = 1000e18 * 1e8 / 2e31 = 1e29 / 2e31 = 0 and no tokens would be allocated, instead of 0.5 WBTC = 0.5e8 WBTC.

The computation should be tokenAllocated = wavaxReserve * 1e18 / floorPrice = 1000e18 * 1e18 / 2e31 = 1e39 / 2e31 = 10e38 / 2e31 = 5e7 = 0.5e8.

Recommendation

The new tokenAllocated computation should be tokenAllocated = wavaxReserve * 1e18 / floorPrice;.

cryptofish7 (Trader Joe) confirmed and commented:

Fix: https://github.com/traderjoe-xyz/rocket-joe/pull/76


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 allocation formula multiplied by the token's own decimal scale (10**token.decimals()) instead of the fixed 1e18 scale used by the floor price, producing a mismatched unit.

Impact

For tokens with decimals other than 18, when the floor price is not reached, the calculation could yield zero tokens allocated to the pool instead of the correct reduced amount, so the launch would not fund the pool as intended.

What the attacker needed

Token decimals not equal to 18; floor price not reached

The fix

The allocation should be computed as the raised WAVAX times 1e18 divided by the floor price, and the project confirmed a fix was made.

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 launch event sells a new token for AVAX and puts the raised AVAX plus some tokens into a trading pool. The code that decides how many tokens to put in the pool mixed up two different number scales, so for tokens that are not split into 18 decimal places it calculated the wrong amount, sometimes zero. That means the pool could end up with no tokens even though people had paid in.

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 Trader Joe 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.