Skip to content
Smart contracts Audit finding Intermediate

Rounding down in Quote calculation allows underpriced LaunchToken purchases by Malicious user, compounding protocol loss over multiple buys.

The bonding curve contract calculates the quote amount for token purchases using integer division, which truncates fractional remainders. An attacker can make small buys that underpay for tokens, and the reduced quote reserve compounds the error over repeated purchases, draining quote tokens from the protocol.

Ayomiposi233 Follow with EtherEngineer, harry and 7 others

Originally disclosed on Code4rena

Submitted by Ayomiposi233, also found by EtherEngineer, harry, hgrano, lioblaze, Manga, oracle-script, ret2basic, taticuvostru, and VAD37

  • launchpad/Launchpad.sol #L272-L305
  • launchpad/BondingCurves/SimpleBondingCurve.sol #L98-L105
  • launchpad/BondingCurves/SimpleBondingCurve.sol #L202-L210

The _getQuoteAmount function in the SimpleBondingCurve contract uses integer division for calculating the quote amount required for a given base amount during token buys on the Launchpad.

function _getQuoteAmount(uint256 baseAmount, uint256 quoteReserve, uint256 baseReserve, bool isBuy)
        internal
        pure
        returns (uint256 quoteAmount)
    {
        uint256 baseReserveAfter = isBuy ? baseReserve - baseAmount : baseReserve + baseAmount;

        return (quoteReserve * baseAmount) / baseReserveAfter;
    }

specifically, the last line of the function return (quoteReserve * baseAmount) / baseReserveAfter; will truncate any fractional remainder towards zero due to Solidity’s integer arithmetic. This results in a floored quote value, allowing users to pay less than the mathematically ideal amount for tokens.

Minor division issues might be negligible in integer-based systems, but this particularly flawed implementation poses too much of a risk, as a Malicious user can make targeted small buys that exploit this error, underpaying for purchased LaunchAssets with the following impacts:

  • The underpayment directly reduces the quoteReserve added to the curve.
  • Subsequent calculations use this understated reserve, causing the error to compound: Future buys are also underpriced relative to the ideal constant product invariant.
  • Attackers can strategically select baseAmount values (as long as they meet the minimum) to maximize the truncation effect, repeatedly buying at a discount until the curve is drained or the bonding phase ends.

Over relatively short time, this can lead to significant quote token losses for the protocol, and it also advantages early exploiters at the expense of later participants. The issue is reproducible as long as the curve is active and the buys are calculated by the user, as shown in the PoC.

Recommended mitigation steps

This can be mitigated by using a higher minimumBase amount, however, this is not a complete solution as the attacker can still buy with a calculated base amount such that the quote returned is rounded down. only much larger buys wont be feasible as numerator will be much larger compared to the denominator hence the rounding down effect will be less pronounced.

A better solution would be to implement a mechanism to handle the rounding error, such as a precision factor or fixed point arithmetic library that can handle decimals more accurately.

View detailed Proof of Concept


The original report as published on Code4rena, by Ayomiposi233. 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 in the quote amount calculation, which floors the result and undercharges buyers.

Impact

A malicious user could repeatedly buy tokens at a discount, reducing the quote reserve and compounding the loss, potentially draining the curve or causing significant quote token losses for the protocol.

What the attacker needed

Active bonding curve; attacker can choose base amount; minimum buy amount met

The fix

The rounding error should be handled with a precision factor or fixed-point arithmetic library, as a higher minimum base amount alone is not a complete solution.

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.

When you buy tokens on a bonding curve, the price is calculated with a formula. The code uses whole-number division, which throws away any fraction, so the buyer pays slightly less than the exact price. By making many small buys, an attacker can exploit this rounding error repeatedly and take value from the system.

What is Smart contracts?

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

More from GTE Perps and Launchpad

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.