oz-utils-safemath

Installation
SKILL.md

FHESafeMath for Confidential Contracts

Use this skill when a contract mutates encrypted euint64 balances or counters and must detect overflow, underflow, or uninitialized-handle edge cases. Raw FHE.add and FHE.sub wrap silently and do not tell you whether the result was valid. FHESafeMath wraps those operations, returns an ebool success flag, and provides explicit fallback behavior when the operation would have been unsafe.

When To Use

  • Updating encrypted balances in an ERC7984-style token, vault, or ledger
  • Incrementing or decrementing encrypted counters where overflow is possible
  • Summing encrypted deltas from untrusted sources (user deposits, stream flows)
  • Handling the case where an operand may still be an uninitialized handle
  • Replacing ad-hoc FHE.select(FHE.ge(...), newValue, oldValue) patterns with the library form

If the operands are bounded by construction (for example, a small fixed-length tally where you know the sum fits in euint64), raw FHE.add is fine. Use FHESafeMath where the risk of wrap-around is real.

Related skills
Installs
11
First Seen
Apr 14, 2026