Skip to content

StableMath::_calculateInvariant can, in fact, overflow #2491

Open
@xenide

Description

Would like to highlight 2 things:

  1. the comments written for the unchecked arithmetic in StableMath doesn't have much implication because almost all of the arithmetic done in _calculateInvariant actually makes use of the Math library, which actually checks for overflow.
  2. Albeit the point about normalized balances fitting into 172 bits is true, consider the following conditions:
    • if we have a token that has 0 decimal places
    • amount of tokens are at/near type(uint112).max

That would result in the invariant and D_P in the range of uint172, which will then cause an overflow when multiplying D_P with invariant on this line

Activity

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

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