Skip to content

_🛠️ Refactor suggestion_ #1736

Open
@thedavidmeister

Description

@thedavidmeister
          _🛠️ Refactor suggestion_

Missing overflow/underflow protection in vault balance updates

increaseVaultBalance/decreaseVaultBalance rely on Float.add / Float.sub safety but:

  1. increaseVaultBalance does not cap newBalance; an attacker can repeatedly deposit type(uint256).max–1 to overflow the mantissa/exponent representation unless LibDecimalFloat.add reverts on overflow (not guaranteed).
  2. decreaseVaultBalance subtracts first, then checks < 0, which is fine, but for symmetry you may want to assert amount <= 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)

Metadata

Metadata

Labels

contractRelated to solidity contracts

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions