fhenix-gas-optimization

Installation
SKILL.md

Fhenix Gas Optimization

Overview

FHE operations are computationally expensive and each one emits an event for off-chain compute, so optimization is mostly about doing fewer, smaller FHE ops and batching on-chain settlement. (The official gas-and-benchmarks page is marked "Coming Soon" — these strategies come from the FHE best-practices guidance; benchmark on testnet for real numbers.)

Strategies

  1. Minimize FHE operations. Each FHE.* call adds overhead — combine/eliminate redundant ops. Reuse intermediate handles instead of recomputing.
  2. Use the smallest safe bit-width. euint8/euint16/euint32 over euint64/euint128 when the value range allows — narrower types are cheaper to compute on.
  3. Cache encrypted constants. Trivially-encrypt frequently used values (0, 1, thresholds) once (e.g. in the constructor), FHE.allowThis(...), and reuse — don't re-encrypt per call.
    euint32 ONE; 
    constructor() { ONE = FHE.asEuint32(1); FHE.allowThis(ONE); }
    function inc() external { counter = FHE.add(counter, ONE); FHE.allowThis(counter); }
    
  4. Batch decrypt settlement. Use FHE.publishDecryptResultBatch / FHE.verifyDecryptResultBatch to handle multiple results/signatures in one tx instead of N transactions.
  5. Avoid unnecessary select branches. Both branches of FHE.select always execute — precompute shared sub-expressions and don't put expensive ops in both paths.
  6. Don't store InE* inputs — convert to euintXX with FHE.asE… first (input structs carry extra metadata that costs gas).
Installs
1
First Seen
Jun 22, 2026
fhenix-gas-optimization — nickthelegend/fhenix-skills