fhevm-testing

A set of Hardhat testing rules for Zama FHEVM contracts. Hardhat is a tool for testing and developing Ethereum smart contracts, while FHEVM tests can use simulated encrypted values or real encryption on the Sepolia test network.

In plain words
What is it for?
Use it to write and debug tests that create encrypted inputs, decrypt encrypted numbers, booleans or addresses, use the FHEVM Hardhat plugin, or run tests against a local node or Sepolia.
Why use it?
It helps tests use the correct encryption and decryption functions for each encrypted type, avoiding mistakes that can produce incorrect results or failed tests. It also explains the available local, mock and network test modes.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/zunmax/fhevm-skill/fhevm-testing
Clone the repo
git clone --depth 1 https://github.com/zunmax/fhevm-skill

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,910 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01910
Opus 5 $0.00000 $0.00955
Sonnet 5 $0.00000 $0.00382
Haiku 4.5 $0.00000 $0.00191

Measured 2d ago against content hash 5f240e66e794, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

fhevm-testing scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/fhevm-testing.mdc · 173 lines

How it starts

The opening of the file, as written. The whole thing — 173 lines — stays where its author put it; the contents beside it link to each section on GitHub.

FHEVM Hardhat Testing Rules

Setup

import { fhevm } from "hardhat";
import { FhevmType } from "@fhevm/hardhat-plugin";

Test Modes

Mode Command Encryption Speed
Mock npx hardhat test Simulated Fast
Local node npx hardhat test --network localhost Simulated Fast
Sepolia npx hardhat test --network sepolia Real FHE Slow

Encrypting Values

const input = fhevm.createEncryptedInput(contractAddress, signer.address);
input.add64(1000n);
const encrypted = await input.encrypt();
/* encrypted.handles[0] - bytes32 handle (order matches add*() call order) */
/* encrypted.inputProof - shared proof for all handles */

Decrypt Functions - Three Different Signatures

/* euint types - FhevmType IS REQUIRED */
const val: bigint = await fhevm.userDecryptEuint(
    FhevmType.euint64, handle, contractAddr, signer
);

/* ebool - NO FhevmType parameter */
const flag: boolean = await fhevm.userDecryptEbool(
    handle, contractAddr, signer
);

/* eaddress - NO FhevmType parameter */
const addr: string = await fhevm.userDecryptEaddress(
    handle, contractAddr, signer
);

This is the #1 testing mistake: adding FhevmType.ebool to userDecryptEbool by analogy with euint.

Public Decrypt - Same Pattern

const val = await fhevm.publicDecryptEuint(FhevmType.euint64, handle);
const flag = await fhevm.publicDecryptEbool(handle);
const addr = await fhevm.publicDecryptEaddress(handle);
/* No signer or contractAddress needed */

Custom Tasks

Custom Hardhat tasks MUST call await fhevm.initializeCLIApi() before using the fhevm API. Tests auto-initialize - only tasks need this.

Never Use in Tests

  • fhevmjs - deprecated, use @fhevm/hardhat-plugin
  • @fhevm/sdk - does not exist
  • fhevm.createInstance() - exists on the implementation class but NOT on the public typed HardhatFhevmRuntimeEnvironment interface; use fhevm.createEncryptedInput() directly

Read the full file on GitHub · 173 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 173 lines · 0 tokens per session scan A 5f240e66e794

Subscribe to this mod's changes

fhevm-testing is a cursor rule published in the GitHub repository zunmax/fhevm-skill (2 stars, last pushed 2mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,910 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.