fhenix-encrypted-arithmetic
Encrypted math on euint8..128 — add, sub, mul, div, rem, square. Covers unchecked wrap-around (no overflow revert, by design), the div/rem-by-zero behavior, same-type operand rule, and direct-call vs library-binding syntax.
Works with
--- name: fhenix-encrypted-arithmetic description: Encrypted math on euint8..128 — add, sub, mul, div, rem, square. Covers unchecked wrap-around (no overflow revert, by design), the div/rem-by-zero behavior, same-type operand rule, and direct-call vs library-binding syntax. license: MIT --- # Fhenix Encrypted Arithmetic ## Overview Arithmetic works on `euint8 | euint16 | euint32 | euint64 | euint128` (not `ebool`/`eaddress`). **Both operands must be the same type.** Available via direct calls (`FHE.add(a,b)`) or bindings (`a.add(b)`). | Op | Function | Operator | Notes | | --- | --- | --- | --- | | Addition | `add` | `+` | wraps on overflow | | Subtraction | `sub` | `-` | wraps on underflow | | Multiplication | `mul` | `*` | wraps on overflow | | Division | `div` | `/` | divisor 0 → encrypted max value | | Remainder | `rem` | `%` | divisor 0 → encrypted max value | | Square | `square` | — | `a²` | ```solidity euint32 sum = FHE.add(a, b); euint32 product = a.mul(b); // library binding euint32 sq = FHE.square(a); ``` ## Unchecked by design (no overflow revert) Solidity's "revert on overflow" is **not** supported for `euint` — reverting would leak information about the encrypted operands. So encrypted arithmetic is always **unchecked**: it wraps around modulo `2^bits`. Size your types so wrap-around can't corrupt logic (e.g. use `euint64`/`euint128` for token balances). ## Division / remainder by zero Per the core-concepts guide, `div`/`rem` by an encrypted `0` return an **encrypted representation of the type's maximum value** (e.g. encrypted `255` for `euint8`) — this prevents leaking whether the divisor was zero. (The fhe-sol reference page phrases this as a revert; either way, **guard the divisor** when correctness matters, e.g. via `FHE.select` to substitute a safe denominator.) ```solidity // Safe division: avoid a 0 divisor producing the max-value sentinel ebool isZero = FHE.eq(divisor, FHE.asEuint32(0)); euint32 safeDiv = FHE.select(isZero, FHE.asEuint32(1), divisor); euint32 result = FHE.div(numerator, safeDiv); ``` ## Common pitfalls - Mixing widths (`euint32` with `euint64`) — convert first with `FHE.asEuintXX`. - Assuming overflow protection — there is none; it wraps. - Forgetting `FHE.allowThis(result)` before storing the result in state. ## Source docs - [`fhe-library/core-concepts/encrypted-operations.mdx`](../fhenix-docs/fhe-library/core-concepts/encrypted-operations.mdx) - [`fhe-library/reference/fhe-sol/arithmetic.mdx`](../fhenix-docs/fhe-library/reference/fhe-sol/arithmetic.mdx) - Division/leakage guidance: `fhenix-best-practices`; branchless guards: `fhenix-encrypted-conditionals`. ## AI Agent Prompt > "Write a `euint64` library with `safeDiv`/`safeRem` that uses `FHE.select` to replace a zero divisor, plus a note on why encrypted arithmetic wraps instead of reverting on overflow."
More Security skills
azure-cost
microsoft/azure-skills
Azure cost management: query costs, forecast spending, optimize to reduce waste. WHEN: \"Azure costs\", \"Azure bill\", \"cost breakdown\", \"how much am I spending\", \"forecast spending\", \"optimize costs\", \"reduce spending\", \"orphaned resources\", \"rightsize VMs\", \"cost spike\", \"reduce storage costs\", \"AKS cost\". DO NOT USE FOR: deploying resources, provisioning, diagnostics, or security audits.
entra-app-registration
microsoft/azure-skills
Guides Microsoft Entra ID app registration, OAuth 2.0 authentication, and MSAL integration. USE FOR: create app registration, register Azure AD app, configure OAuth, set up authentication, add API permissions, generate service principal, MSAL example, console app auth, Entra ID setup, Azure AD authentication. DO NOT USE FOR: Key Vault secrets (use azure-keyvault-expiration-audit), general Azure resource security guidance.
azure-messaging
microsoft/azure-skills
Troubleshoot and resolve issues with Azure Messaging SDKs for Event Hubs and Service Bus. Covers connection failures, authentication errors, message processing issues, and SDK configuration problems. WHEN: event hub SDK error, service bus SDK issue, messaging connection failure, AMQP error, event processor host issue, message lock lost, message lock expired, lock renewal, lock renewal batch, send timeout, receiver disconnected, SDK troubleshooting, azure messaging SDK, event hub consumer, service bus queue issue, topic subscription error, enable logging event hub, service bus logging, eventhub python, servicebus java, eventhub javascript, servicebus dotnet, event hub checkpoint, event hub not receiving messages, service bus dead letter, batch processing lock, session lock expired, idle timeout, connection inactive, link detach, slow reconnect, session error, duplicate events, offset reset, receive batch.

