absolute difference is not calculated properly when a > b in MathUtils
The difference function in MathUtils.sol incorrectly computes the absolute difference when a > b, causing within1 to return wrong results. An attacker could manipulate pool calculations to make within1 fail, potentially affecting the HybridPool.
Submitted by hack3r-0m, also found by broccoli
the difference is computed incorrectly when a > b. MathUtils.sol L22
As it only used in within1 function, scope narrows down to where difference(a, b) <= 1; is exploitable.
cases where difference(a, b) <= 1 should be true but is reported false:
- where b = a-1 (returned value is
type(uint256).max)
cases where difference(a, b) <= 1 should be false but is reported true:
- where a =
type(uint256).max and b = 0, it returns 1 but it should ideally returntype(uint256).max
within1 is used at the following locations:
It is possible to decrease the denominator and increase the value of the numerator (when calculating y) using constants and input to make within1 fail
Mitigation:
Add else condition to mitigate it.
unchecked {
if (a > b) {
diff = a - b;
}
else {
diff = b - a;
}
}
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
Impact
An attacker could cause within1 to fail by manipulating pool inputs, potentially disrupting pool operations or enabling value extraction.
What the attacker needed
Ability to interact with HybridPool
The fix
The fix is to add an else branch that computes b - a when a is not greater than b.
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.
A smart contract function that calculates the difference between two numbers has a bug: when the first number is larger, it returns a huge number instead of the correct difference. This can make a check that should pass fail, which might let someone manipulate the pool's calculations.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.