fhenix-encrypted-comparisons

Encrypted comparisons returning ebool — eq/ne (all types incl. eaddress), lt/lte/gt/gte and min/max (euint8..128). Comparisons can't branch directly; pair the ebool with FHE.select. Covers operand-type rules and the bid/threshold pattern.

nickthelegend/fhenix-skills1 installsMITSynced Aug 26

Works with

Claude CodeCursorCodex CLIGitHub CopilotGemini CLI

Agent Skills format with YAML frontmatter. Claude Code reads it as-is.

---
name: "fhenix-encrypted-comparisons"
description: "Encrypted comparisons returning ebool — eq/ne (all types incl. eaddress), lt/lte/gt/gte and min/max (euint8..128). Comparisons can't branch directly; pair the ebool with FHE.select. Covers operand-type rules and the bid/threshold pattern."
license: "MIT"
---

# Fhenix Encrypted Comparisons

## Overview
Comparisons evaluate homomorphically and return an **`ebool`** (encrypted boolean) — you can't read the result directly. To act on it, feed the `ebool` into `FHE.select` (see `fhenix-encrypted-conditionals`).

| Function | Result | Operand types |
| --- | --- | --- |
| `eq` / `ne` | `ebool` | all encrypted types **including `eaddress`** |
| `lt` / `lte` / `gt` / `gte` | `ebool` | `euint8…128` |
| `min` / `max` | `euintXX` | `euint8…128` |

```solidity
ebool   isHigher = FHE.gt(newBid, highestBid);
ebool   sameAddr = FHE.eq(owner, candidate);   // eaddress equality
euint32 higher   = FHE.max(newBid, highestBid);
```

## Comparisons + select (the core pattern)
```solidity
// Keep the larger bid without revealing either value
ebool   isHigher = bid.gt(highestBid);
euint32 newHigh  = FHE.select(isHigher, bid, highestBid);
FHE.allowThis(newHigh);
highestBid = newHigh;
```

## Eligibility / threshold example
```solidity
function isEligible(euint32 reputation) public returns (ebool) {
    ebool ok = FHE.gte(reputation, FHE.asEuint32(MIN_REP));
    FHE.allowThis(ok);
    return ok; // reveal later via decrypt flow if needed
}
```

## Common pitfalls
- **Trying to `if`/`require` on an `ebool`** — impossible; it's encrypted. Use `FHE.select` and resolve true/false off-chain via decryption when you must branch.
- Ordering ops (`lt`/`gt`/`min`/`max`) on `ebool`/`eaddress` — unsupported; only `eq`/`ne` apply there.
- Mismatched widths — convert first.

## Source docs
- [`fhe-library/core-concepts/encrypted-operations.mdx`](../fhenix-docs/fhe-library/core-concepts/encrypted-operations.mdx)
- [`fhe-library/reference/fhe-sol/comparison.mdx`](../fhenix-docs/fhe-library/reference/fhe-sol/comparison.mdx)
- [`fhe-library/core-concepts/conditions.mdx`](../fhenix-docs/fhe-library/core-concepts/conditions.mdx)

## AI Agent Prompt
> "Implement a private auction `placeBid(InEuint32)` that compares the new bid to the stored highest with `FHE.gt`, updates via `FHE.select`, and re-grants ACL — never branching on the encrypted comparison."

More General & Other skills

← All General & Other skills

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY