fhevm-arithmetic-ops
FHE Arithmetic Operations
Use this skill when a contract performs computation on encrypted values. Every FHE operation
has constraints that differ from plaintext Solidity math. Some misuse panics immediately
(for example encrypted divisors in div/rem), while other mistakes create silent
fallbacks or inaccessible handles.
When To Use
- Writing arithmetic logic over
euint64,euint128, oreboolvalues - Reviewing whether division or modulo uses a plaintext divisor
- Checking for overflow in encrypted computations
- Deciding which operands should be public vs encrypted
- Optimizing gas by restructuring operations to use ciphertext-scalar forms
- Implementing comparisons or conditional logic with
FHE.select
Core Mental Model
FHE arithmetic produces new ciphertext handles. Every operation returns a fresh handle
More from z-korp/fhevm-cookbook
fhevm-router
Routes Zama FHEVM tasks to the right official docs path and next step
11fhevm-testing
Use when writing, structuring, or debugging tests for FHEVM contracts. Covers mocked mode vs real protocol, Hardhat decrypt helpers, input encryption in tests, and the false-confidence gap between local and testnet behavior.
11fhevm-acl-lifecycle
Use when granting, auditing, or debugging ACL permissions on encrypted handles in FHEVM. Covers FHE.allow, FHE.allowThis, FHE.allowTransient, and the critical rule that new handles do not inherit prior persistent ACL grants.
11fhevm-control-flow
Use when replacing if/else, require, or any conditional logic that depends on encrypted values in FHEVM. Covers FHE.select as the inline branching primitive, fallback semantics on encrypted conditions, and async public decryption when logic must branch back to plaintext state.
11oz-utils-safemath
Use when you need overflow-safe encrypted arithmetic on euint64 values. Covers the OpenZeppelin FHESafeMath library (tryIncrease, tryDecrease, tryAdd, trySub), uninitialized-handle semantics, and when to prefer it over raw FHE.add / FHE.sub.
11fhevm-public-decryption
Use when implementing two-step public decryption for state-changing operations in FHEVM. Covers makePubliclyDecryptable, off-chain proof retrieval, onchain verification with checkSignatures, and the critical single-step unwrap bug.
11