Open
Description
_🛠️ Refactor suggestion_
Missing overflow/underflow protection in vault balance updates
increaseVaultBalance
/decreaseVaultBalance
rely on Float.add
/ Float.sub
safety but:
increaseVaultBalance
does not capnewBalance
; an attacker can repeatedly deposittype(uint256).max
–1 to overflow the mantissa/exponent representation unlessLibDecimalFloat.add
reverts on overflow (not guaranteed).decreaseVaultBalance
subtracts first, then checks< 0
, which is fine, but for symmetry you may want to assertamount <= oldBalance
up-front for clearer error semantics.
Recommended minimal guard (pseudo-code):
if (amount.gt(Float.wrap(0))) {
require(oldBalance.add(amount).gte(oldBalance), "Float overflow");
}
and
require(oldBalance.gte(amount), "Insufficient vault balance");
These checks are cheap and eliminate silent wrap risk if LibDecimalFloat
ever changes implementation details.
Originally posted by @coderabbitai[bot] in #860 (comment)