Skip to content

lib/Select: Average computation can overflow #234

Description

@pmerkleplant

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions