Skip to content
Audit finding Beginner

Unnecessary precision loss due to division before multiplication in getDistribution()

The getDistribution() function performs division before multiplication, causing precision loss that can reduce the funds distributed to pot, yeetback, stakers, public goods, and treasury. An attacker could not directly exploit this, but the protocol and users may receive slightly less than expected.

h2134 Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

#41272 [SC-Insight] Unnecessary precision loss due to division before multiplication in `getDistribution()`

Submitted on Mar 13th 2025 at 07:50:55 UTC by @h2134 for Audit Comp | Yeet

Description

Brief/Intro

The calculation in getDistribution() performs division before multiplication, this can lead to unnecessary funds loss to the protocol and users.

Vulnerability Details

When calculates values to pot/yeetback/stakers/public goods/treasury, in getDistribution(), division operations are performed before multiplication operations, causes unnecessary precision loss.

Yeet::getDistribution():

Solidity
    function getDistribution(uint256 yeetAmount) public view returns (uint256, uint256, uint256, uint256, uint256) {
        uint256 scale = gameSettings.SCALE();

@>      uint256 valueAfterTax = (yeetAmount / scale) * (scale - TAX_PER_YEET);
@>      uint256 valueToYeetBack = (yeetAmount / scale) * (YEETBACK_PERCENTAGE);
@>      uint256 valueToPot = (yeetAmount / scale) * (scale - YEETBACK_PERCENTAGE - TAX_PER_YEET);
        uint256 tax = yeetAmount - valueAfterTax;

@>      uint256 valueToStakers = (tax / scale) * TAX_TO_STAKERS;
@>      uint256 publicGoods = (tax / scale) * TAX_TO_PUBLIC_GOODS;
@>      uint256 teamRevenue = (tax / scale) * TAX_TO_TREASURY;

        return (valueToPot, valueToYeetBack, valueToStakers, publicGoods, teamRevenue);
    }

Impact Details

Funds distributed to pot/yeetback/stakers/public goods/treasury can be less than expected, the loss is up to 9999 wei and is minimum though.

References

Perform multiplication operations first.

Solidity
    function getDistribution(uint256 yeetAmount) public view returns (uint256, uint256, uint256, uint256, uint256) {
        uint256 scale = gameSettings.SCALE();

        uint256 valueAfterTax = (yeetAmount * (scale - TAX_PER_YEET) / scale);
        uint256 valueToYeetBack = (yeetAmount * (YEETBACK_PERCENTAGE) / scale);
        uint256 valueToPot = (yeetAmount * (scale - YEETBACK_PERCENTAGE - TAX_PER_YEET) / scale);
        uint256 tax = yeetAmount - valueAfterTax;

        uint256 valueToStakers = (tax * TAX_TO_STAKERS / scale);
        uint256 publicGoods = (tax * TAX_TO_PUBLIC_GOODS / scale);
        uint256 teamRevenue = (tax * TAX_TO_TREASURY / scale);

        return (valueToPot, valueToYeetBack, valueToStakers, publicGoods, teamRevenue);
    }

Proof of Concept

Proof of Concept

Run the below test in Yeet.Test.sol:

Solidity
    function testAudit_GetDistributionPrecisionLoss() public {
        uint256 yeetAmount = 1e18 + 9999;
        (uint256 valueToPot, uint256 valueToYeetback, uint256 valueToStakers, uint256 publicGoods, uint256 teamRevenue) = yeet.getDistribution(yeetAmount);

        uint256 scale = 10000;
        uint256 TAX_PER_YEET = yeet.TAX_PER_YEET();
        uint256 YEETBACK_PERCENTAGE = yeet.YEETBACK_PERCENTAGE();

        uint256 expectedValueToPot = (yeetAmount * (scale - YEETBACK_PERCENTAGE - TAX_PER_YEET)) / scale;

        uint256 sum = valueToPot + valueToYeetback + valueToStakers + publicGoods + teamRevenue;
        console.log("sum:", sum);

        assertLt(valueToPot, expectedValueToPot);
    }

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

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 code performs integer division before multiplication, which truncates intermediate results and causes precision loss.

Impact

Funds distributed to pot/yeetback/stakers/public goods/treasury can be less than expected, with a loss of up to 9999 wei, which is minimal.

What the attacker needed

None

The fix

The code should be fixed by performing multiplication before division in the getDistribution() function.

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 a smart contract calculates how to split an amount of money, the order of operations matters. If you divide first and then multiply, you can lose small fractions of the amount due to rounding. This report shows that the contract does the division first, so the final amounts are slightly smaller than they should be.

More by h2134

View all

9 more disclosed reports, best first.

More from Yeet

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.