ampleforth-contracts
ampleforth-contracts copied to clipboard
lib/Select: Average computation can overflow
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.