/bn-fhevm:fhevm-testingfrom bn-fhevm
Used when writing or debugging Mocha / Hardhat tests for FHEVM contracts. Covers the fhevm.isMock gate pattern, encrypted input creation via fhevm.createEncryptedInput + FHE.fromExternal, test-time decryption via fhevm.userDecryptEuint and fhevm.publicDecrypt, EIP-712 PublicDecryptVerification proofs using the mock KMS private key, Sepolia timeout / retry conventions, and the three-gate deployment checklist (mock → Sepolia → pre-mainnet review). Triggers on @fhevm/hardhat-plugin, @fhevm/mock-utils, hre.fhevm, createEncryptedInput, userDecryptEuint, publicDecrypt, EmptyDecryptionProof in tests, or writing a first Hardhat test for an FHEVM contract.
Ships in bn-fhevm. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Test patterns for FHEVM contracts under Mocha + Hardhat. The mock coprocessor from @fhevm/[email protected] runs in-process on the hardhat network; the real protocol runs on Sepolia. A single test file should handle both by gating on hre.fhevm.isMock. The full API catalog with signatures and proof-construction snippets lives in references/testing-guide.md — this file is the routing core.
Default workflow: write tests for mock mode (hre.fhevm.isMock === true), iterate fast, then opt into Sepolia for the same test suite via npm run test:sepolia. Never ship a contract without both passing. Mock catches logic bugs; Sepolia catches real-network issues (relayer timing, KMS signature formats, gas).
hre.fhevm.isMockit("reveals the tally", async () => {
/* ... shared setup ... */
if (fhevm.isMock) {
/* mock path: faster, in-process KMS */
} else {
/* Sepolia path: may need timeouts, retries, real relayer */
}
});
A branchless test that calls, e.g., an Express proxy for local mock but a real HTTPS relayer for Sepolia will fail on one or the other.
fhevm.createEncryptedInput(contract, user)The plugin injects fhevm.createEncryptedInput(contractAddress, userAddress) as a helper that produces (handles[], inputProof) bound to (contract, user) — identical semantics to the browser SDK, but in-process. Any test that calls a function taking externalEuint* + bytes proof must use this.
const input = fhevm.createEncryptedInput(contract.target, user.address);
input.add64(42n);
const { handles, inputProof } = await input.encrypt();
await contract.connect(user).increment(handles[0], inputProof);
Two test helpers match the two production flows — see fhevm-decryption for the protocol view.
const clear = await fhevm.userDecryptEuint(FhevmType.euint64, handle, contractAddress, user); — asserts the user has ACL permission on the handle and returns the cleartext. The 4th argument is the user's signer; the 3rd is the contract address that holds the handle.const clear = await fhevm.publicDecryptEuint(FhevmType.euint64, handle); — returns the cleartext. (The bare fhevm.publicDecrypt(handles[]) exists too but takes an array and returns a PublicDecryptResults object; use the per-type wrapper publicDecryptEuint for single-handle scalar reads.)For contract-side FHE.checkSignatures verification in tests, you must sign with the mock KMS private key — see references/testing-guide.md § mock KMS proof construction.
EmptyDecryptionProof() in tests → the proof is empty or misbuiltMock mode is NOT a no-op. FHE.checkSignatures verifies the EIP-712 signature even in mock tests. Feeding "0x" into a finalize(clear, proof) call fails. Construct a valid proof with the mock KMS key or use fhevm.publicDecrypt which returns a proof alongside the cleartext.
Before moving a contract from draft to production, pass three gates:
npm test (mock mode) green. Exercises logic, ACL, input-proof flow, both decryption paths.npm run test:sepolia green. Same assertions against the real relayer and real KMS. Catches relayer-URL config errors, real-network timing, gas misestimates.fhevm-antipatterns checklist scanned, slither . clean, and at least one auditor sign-off on FHE.allow* placements and FHE.makePubliclyDecryptable irreversibility.Skipping gate 2 is the most common shipping mistake — mock mode hides relayer configuration bugs.
import { expect } from "chai";
import { ethers, fhevm } from "hardhat";
import { FhevmType } from "@fhevm/hardhat-plugin";
import type { ConfidentialCounter } from "../typechain-types";
describe("ConfidentialCounter", () => {
let counter: ConfidentialCounter;
let owner: HardhatEthersSigner, user: HardhatEthersSigner;
beforeEach(async () => {
[owner, user] = await ethers.getSigners();
const Factory = await ethers.getContractFactory("ConfidentialCounter");
counter = await Factory.deploy();
await counter.waitForDeployment();
});
it("increments by an encrypted delta and the user can decrypt", async () => {
const input = fhevm.createEncryptedInput(counter.target, user.address);
input.add64(7n);
const { handles, inputProof } = await input.encrypt();
await counter.connect(user).increment(handles[0], inputProof);
const handle = await counter.countHandle();
const clear = await fhevm.userDecryptEuint(
FhevmType.euint64,
handle,
await counter.getAddress(),
user,
);
expect(clear).to.equal(7n);
});
it("publicly reveals the count after makePubliclyDecryptable", async () => {
/* setup + increment ... */
const handle = await counter.countHandle();
await counter.requestReveal(); // calls makePubliclyDecryptable
const clear = await fhevm.publicDecryptEuint(FhevmType.euint64, handle);
expect(clear).to.be.a("bigint");
if (fhevm.isMock) {
// Mock-only: assert the in-process coprocessor produced the expected state.
}
});
});
Full snippets for multi-handle public decryption, encoded-cleartext proof construction, ACL assertions, and Sepolia timeout/retry patterns are in references/testing-guide.md.
For full worked examples covering user decryption, ERC-7984 wrap/unwrap roundtrips, and public-decrypt finalization with checkSignatures, see the test suites in Zama's official dApps repo.
Sepolia variants of mock tests typically live in matching test/<Contract>Sepolia.ts files and run via npm run test:sepolia.
createEncryptedInput).userDecryptEuint, publicDecrypt).PublicDecryptVerification proofs with the mock KMS key.fhevm-contracts.fhevm-decryption.hardhat vars / Sepolia secrets → fhevm-setup.ACLNotAllowed() / DeclarationError → fhevm-antipatterns.fhevm-frontend.references/testing-guide.md § createEncryptedInput.references/testing-guide.md § userDecryptEuint / publicDecrypt.EmptyDecryptionProof() in mock mode." → Essential Principle 5 + references/testing-guide.md § mock KMS proof construction.references/testing-guide.md § Sepolia gating.Canonical pinned versions and Zama documentation links live in fhevm-overview. Testing-specific extras: @fhevm/[email protected] (injects hre.fhevm), @fhevm/[email protected], @nomicfoundation/hardhat-chai-matchers@^2.1.x, chai@^4.5.x, mocha@^11.x. Testing-guide URL: https://docs.zama.org/protocol/solidity-guides/development-guide/testing.
What SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (bootnodedev/zama-s2-bounty-skills) — no native marketplace selected
npx claudepluginhub p/bootnodedev-bn-fhevm10 skills in this plugin
/create-templateUse when scaffolding a new FHEVM workspace -- contracts, Next.js frontend, or Vite frontend. Copies the canonical bundled template (project/ or templates/frontend-{next,vite}/) into a target directory and customizes package metadata, env-var defaults, and the Sepolia RPC URL via an interactive AskUserQuestion wizard./fhevm-antipatternsUsed when reviewing, debugging, auditing, or pre-commit-checking FHEVM Solidity or client code. Catalogues the v0.11-era breaking renames (TFHE→FHE, SepoliaZamaFHEVMConfig→ZamaEthereumConfig, ConfidentialFungibleToken→ERC7984, TFHESafeMath→FHESafeMath, tokenURI→contractURI, isUserAllowed→canTransact), the removed FHE.requestDecryption API, deprecated fhevmjs, and high-frequency footguns (missing FHE.allowThis after state writes, view functions returning encrypted types, .env-based Hardhat secrets). Triggers on FHEVM code review, anti-pattern, audit, migration from pre-v0.9/v0.11, pre-commit check, ACLNotAllowed, EmptyDecryptionProof, or DeclarationError.Other plugins' skills for the same job
/fhevm-contractsUsed when writing, refactoring, or reviewing FHEVM Solidity contracts against the @fhevm/[email protected] API. Covers encrypted types (ebool, euint8..256, eaddress), FHE operations (arithmetic, comparison, FHE.select), the ACL lifecycle (FHE.allow, allowThis, allowTransient, isSenderAllowed, makePubliclyDecryptable), and the input-proof flow (externalEuint* + FHE.fromExternal). Triggers on FHEVM contract patterns, encrypted types, FHE.* library calls, ACL permissions, input proofs, ciphertext handles, ZamaEthereumConfig, or writing a confidential counter / voting / auction / vault contract.