Would like to highlight 2 things:
- 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.
- 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