ampleforth-contracts icon indicating copy to clipboard operation
ampleforth-contracts copied to clipboard

lib/Select: Average computation can overflow

Open pmerkleplant opened this issue 2 years ago • 0 comments

The average computation in the Select.sol library can overflow because the average is computed with (a + b) / 2 (see here). An overflow would be caught by Open Zeppelin's SafeMath library, but this would lead to reverting the transaction.

Even though the real values in the Ampleforth oracles are not big enough for overflows, consider distributing the computation with (a / 2) + (b / 2) + (((a % 2) + (b % 2)) / 2) to avoid the possibility altogether and improve the re-use of the Select.sol library.

pmerkleplant avatar Apr 14 '22 09:04 pmerkleplant