Skip to content
Smart contracts Audit finding Intermediate

Incorrect usage of _pow in _computeSingleOutGivenPoolIn of IndexPool

The IndexPool contract's _computeSingleOutGivenPoolIn function passes an exponent in WAD (18-decimal fixed point) to the _pow function, which expects a plain integer exponent. This causes an integer overflow that prevents the function from being called, blocking the associated pool operation.

broccoli Follow

Originally disclosed on Code4rena

Submitted by broccoli

Impact

The _computeSingleOutGivenPoolIn function of IndexPool uses the _pow function to calculate tokenOutRatio with the exponent in WAD (i.e., in 18 decimals of precision). However, the _pow function assumes that the given exponent n is not in WAD. (for example, _pow(5, BASE) returns 5 ** (10 ** 18) instead of 5 ** 1). The misuse of the _pow function could causes an integer overflow in the _computeSingleOutGivenPoolIn function and thus prevent any function from calling it.

Proof of Concept

Referenced code: IndexPool.sol#L279

Recommended Mitigation Steps

Change the _pow function to the _compute function, which supports exponents in WAD.

maxsam4 (Sushi) confirmed

The original report as published on Code4rena, by broccoli. 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

The _pow helper expects an unscaled integer exponent, but the caller supplied a WAD-scaled exponent, producing an enormous exponentiation that overflows.

Impact

The overflow could prevent _computeSingleOutGivenPoolIn from being called, blocking the pool operation that depends on it.

What the attacker needed

None

The fix

The _pow call should be replaced with the _compute function, which supports WAD-scaled exponents.

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.

Smart contracts often use fixed-point maths to handle decimals, storing numbers multiplied by 10^18 (called WAD). One helper function expected a normal whole number but was given a WAD-scaled number, so it tried to compute an astronomically large power. That overflowed the number type and made the function unusable.

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 broccoli

View all

16 more disclosed reports, best first.

More from Sushi Trident contest phase 1

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.