A starter template for developing Fully Homomorphic Encryption (FHE) smart contracts using Fhenix CoFHE and Foundry.
# Clone the repository
git clone <repo-url>
cd cofhe-foundry-starter
# Install Solidity dependencies
npm install
# Compile contracts
forge build
# Run tests
forge test -vvv├── src/
│ └── Counter.sol # Example FHE counter contract
├── test/
│ └── Counter.t.sol # Comprehensive Solidity tests
├── script/
│ ├── DeployCounter.s.sol # Deployment script
│ ├── IncrementCounter.s.sol # Increment interaction
│ └── ResetCounter.s.sol # Reset with encrypted input
├── foundry.toml # Foundry configuration
├── package.json # npm dependencies
└── remappings.txt # Solidity import remappings
Tests use CoFheTest from @cofhe/mock-contracts, which provides mock contract deployment, encrypted input creation, plaintext assertions, and permission testing -- all in Solidity with no JS SDK needed.
For the full testing guide covering all helper functions, FHE operations, ACL, permits, and patterns, see TESTING.md.
cp .env.example .env
# Edit .env with your private key and RPC URLs# Ethereum Sepolia
npm run deploy:eth-sepolia
# Arbitrum Sepolia
npm run deploy:arb-sepolia
# Base Sepolia
npm run deploy:base-sepolia# Set the deployed contract address
export COUNTER_ADDRESS=0x...
# Increment the counter
source .env && forge script script/IncrementCounter.s.sol --rpc-url eth-sepolia --broadcastnpm run test:gas| Package | Purpose |
|---|---|
@fhenixprotocol/cofhe-contracts |
FHE type definitions and operations (FHE.sol) |
@cofhe/mock-contracts |
Mock contracts for local testing + Foundry helpers |
@openzeppelin/contracts |
Standard contract utilities |
forge-std |
Foundry standard library (Test, Script, cheatcodes) |
- EVM Version:
cancun— required for MockACL's transient storage (tstore/tload) - Code Size Limit:
100000— mock contracts exceed the default 24KB limit - Solidity Version:
0.8.25— compatible with CoFHE contracts