Incorrect multiplication in _computeSingleOutGivenPoolIn of IndexPool
The `_computeSingleOutGivenPoolIn` function in `IndexPool` used raw multiplication instead of the `_mul` helper for fixed-point arithmetic, causing `zaz` to be 10^18 times too large and leading to an integer underflow when computing `amountOut`. This prevented anyone from successfully calling the function.
Submitted by broccoli
Impact
The _computeSingleOutGivenPoolIn function of IndexPool uses the raw multiplication (i.e., *) to calculate the zaz variable. However, since both (BASE - normalizedWeight) and _swapFee are in WAD, the _mul function should be used instead to calculate the correct value of zaz. Otherwise, zaz would be 10 ** 18 times larger than the expected value and causes an integer underflow when calculating amountOut. The incorrect usage of multiplication prevents anyone from calling the function successfully.
Proof of Concept
Referenced code: IndexPool.sol#L282
Recommended Mitigation Steps
Change (BASE - normalizedWeight) * _swapFee to _mul((BASE - normalizedWeight), _swapFee).
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 developer used raw multiplication instead of the `_mul` helper for fixed-point values, causing an incorrect scaling.
Impact
The incorrect multiplication prevented anyone from successfully calling the function, effectively breaking that functionality.
What the attacker needed
None
The fix
The multiplication should be changed to use the `_mul` function to correctly handle fixed-point arithmetic.
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 arithmetic to handle decimals, where numbers are scaled by a large factor like 10^18. The code mistakenly used normal multiplication instead of a special function that accounts for this scaling, making a value far too big and causing a calculation to fail. As a result, a key function in the pool could not be used at all.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.