Zama Foundry forge-fhevm
forge-fhevm is Zama's Foundry-native toolkit for FHEVM testing and local development. When Forge tests inherit FhevmTest, it deploys real fhEVM host contracts in the test environment, including FHEVMExecutor, ACL, InputVerifier, and KMSVerifier, and tracks encrypted handles in a local plaintext database so tests can encrypt, compute, decrypt, and assert entirely within Foundry.
Contracts are still written with @fhevm/solidity: encrypted types, FHE.fromExternal, FHE.add/select/..., FHE.allowThis, FHE.allow, FHE.makePubliclyDecryptable, and the usual FHEVM patterns.
Which Reference to Read First
- Creating or fixing a Foundry project: read
references/foundry-project.md
- Writing deployment scripts: read
references/deploy.md
- Looking up the forge-fhevm API: read
references/api/README.md
- Getting oriented before writing tests: read
references/testing/README.md
- Testing encrypted inputs: read
references/testing/encrypt.md
- Testing decryption: read
references/testing/decrypt.md
- Testing ACL and permissions: read
references/testing/acl.md
- Testing ERC7984 tokens: read
references/testing/erc7984.md
- Fuzzing, failure paths, and troubleshooting: read
references/testing/fuzz-and-errors.md
Usage Principles
- Inspect the project's installed
forge-fhevm/FhevmTest.sol, deploy-local.sh, and deploy.sh before applying examples from these references.
forge-fhevm currently requires Solidity ^0.8.27 and evm_version = "cancun".
- Do not pin Soldeer dependencies such as
@fhevm-solidity or @encrypted-types to latest; start from the verified versions in this skill, and when upgrading, query the registry and update foundry.toml, soldeer.lock, and remappings.txt together.
- Call
super.setUp() first when overriding setUp() in Forge tests.
FhevmTest.decrypt is a test-only plaintext read and does not enforce ACL checks; permission-sensitive tests must cover publicDecrypt or userDecrypt.
- Do not store private keys in
.env files or scripts for real deployments; use the Foundry keystore, call vm.startBroadcast() in scripts, and select the signer on the command line with forge script --account <name>.
- An Anvil-only local demo deploy wrapper should set
LOCAL_STATE_RPC_NAMESPACE=anvil explicitly to avoid empty cast client detection; if deployment scripts write JSON, configure fs_permissions in foundry.toml.
- The local cleartext FHEVM stack is only for development and testing; it is not a production privacy deployment.
Upstream Source of Truth
The API and deployment guidance in this skill follows the zama-ai/forge-fhevm source and docs, especially src/FhevmTest.sol, docs/api/*.md, docs/guides/*.md, deploy-local.sh, and deploy.sh. If upstream API docs disagree with the installed source in the current project, treat the installed source as authoritative.
1---2name: zama-foundry-forge-fhevm3description: Use this skill when developing, testing, or deploying Zama FHEVM confidential contracts with Foundry and forge-fhevm. Covers FhevmTest, forge test, Foundry project setup, Solidity 0.8.27, Cancun EVM, encrypted input, direct/public/user decrypt, ACL, ERC7984 confidential tokens, fuzzing, and local/Sepolia/mainnet deployment.4---56# Zama Foundry forge-fhevm78`forge-fhevm` is Zama's Foundry-native toolkit for FHEVM testing and local development. When Forge tests inherit `FhevmTest`, it deploys real fhEVM host contracts in the test environment, including `FHEVMExecutor`, `ACL`, `InputVerifier`, and `KMSVerifier`, and tracks encrypted handles in a local plaintext database so tests can encrypt, compute, decrypt, and assert entirely within Foundry.910Contracts are still written with `@fhevm/solidity`: encrypted types, `FHE.fromExternal`, `FHE.add/select/...`, `FHE.allowThis`, `FHE.allow`, `FHE.makePubliclyDecryptable`, and the usual FHEVM patterns.1112## Which Reference to Read First1314- Creating or fixing a Foundry project: read `references/foundry-project.md`15- Writing deployment scripts: read `references/deploy.md`16- Looking up the forge-fhevm API: read `references/api/README.md`17- Getting oriented before writing tests: read `references/testing/README.md`18- Testing encrypted inputs: read `references/testing/encrypt.md`19- Testing decryption: read `references/testing/decrypt.md`20- Testing ACL and permissions: read `references/testing/acl.md`21- Testing ERC7984 tokens: read `references/testing/erc7984.md`22- Fuzzing, failure paths, and troubleshooting: read `references/testing/fuzz-and-errors.md`2324## Usage Principles2526- Inspect the project's installed `forge-fhevm/FhevmTest.sol`, `deploy-local.sh`, and `deploy.sh` before applying examples from these references.27- `forge-fhevm` currently requires Solidity `^0.8.27` and `evm_version = "cancun"`.28- Do not pin Soldeer dependencies such as `@fhevm-solidity` or `@encrypted-types` to `latest`; start from the verified versions in this skill, and when upgrading, query the registry and update `foundry.toml`, `soldeer.lock`, and `remappings.txt` together.29- Call `super.setUp()` first when overriding `setUp()` in Forge tests.30- `FhevmTest.decrypt` is a test-only plaintext read and does not enforce ACL checks; permission-sensitive tests must cover `publicDecrypt` or `userDecrypt`.31- Do not store private keys in `.env` files or scripts for real deployments; use the Foundry keystore, call `vm.startBroadcast()` in scripts, and select the signer on the command line with `forge script --account <name>`.32- An Anvil-only local demo deploy wrapper should set `LOCAL_STATE_RPC_NAMESPACE=anvil` explicitly to avoid empty `cast client` detection; if deployment scripts write JSON, configure `fs_permissions` in `foundry.toml`.33- The local cleartext FHEVM stack is only for development and testing; it is not a production privacy deployment.3435## Upstream Source of Truth3637The API and deployment guidance in this skill follows the `zama-ai/forge-fhevm` source and docs, especially `src/FhevmTest.sol`, `docs/api/*.md`, `docs/guides/*.md`, `deploy-local.sh`, and `deploy.sh`. If upstream API docs disagree with the installed source in the current project, treat the installed source as authoritative.