Skip to content
Smart contracts Audit finding Advanced

Divide before multiply

The report claims that a calculation in the Vader protocol divides before multiplying, which can round the result down to zero. An attacker could exploit this rounding to obtain a zero or incorrect value from the affected calculation.

Vader Protocol contest

Originally disclosed on Code4rena

Here you have more information: https://gist.github.com/alexon1234/e5038a9f66136ae210be692f8803d874

strictly-scarce (vader) questioned:

Can’t quite understand the assertion that a division is made before a multiply in the code outlined

uint _units = (((P * part1) + part2) / part3);
    return (_units * slipAdjustment) / one;  // Divide by 10**18

_units will be 0 -> 2**256. slipAdjustment will be 0 -> 10**18 one is 10**18

// returns 0
 return (0 * 10**18) / 10**18;
 return (2**256 * 0) / 10**18;
return (<10**9 * <10**9) / 10**18;
  // returns  non-zero
 return (>=10**9 * >=10**9) / 10**18;

The original report as published on Code4rena. 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 calculation performs integer division before a multiplication, so the intermediate value is truncated and the final result can be zero or too small.

What the attacker needed

Access to the affected contract 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.

Computers store whole numbers with a fixed size, and when you divide whole numbers the remainder is thrown away. If you divide too early in a calculation, a small number can become zero, and multiplying it afterwards stays zero. This report argues that the code does the division too soon, so the final result can be wrong.

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 Vader Protocol 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.