@cofhe/foundry-plugin, write a contract that stores an encrypted uint32, and test the encrypt → store → decrypt flow under forge test.
Prerequisites
- Foundry (
forge,cast,anvil) - Node.js 18+ with npm/pnpm/yarn (for installing the plugin’s npm packages)
1. Install dependencies
The plugin and its CoFHE dependencies are distributed via npm. Install them as dev dependencies, thenforge install for forge-std:
2. Configure foundry.toml
foundry.toml
3. Configure remappings.txt
remappings.txt
hardhat/=node_modules/forge-std/src/ line is load-bearing — MockCoFHE.sol imports hardhat/console.sol, and this alias resolves it to forge-std’s compatible console.sol.
4. Write a contract
src/MyContract.sol
euint32— an encrypteduint32stored on-chain as a ciphertext handle.InEuint32— the encrypted input struct produced byCofheClient.FHE.allowThis/FHE.allowSender— grant the contract and caller permission to read the encrypted value (required by the ACL).
5. Write a test
test/MyContract.t.sol
6. Run
What just happened?
deployMocks()deployed the full CoFHE coprocessor mock stack (TaskManager, ACL, ZK verifier, threshold network) to the in-process EVM.createCofheClient()+bob.connect(BOB_PKEY)spun up an in-Solidity SDK shim bound tovm.addr(BOB_PKEY).bob.createInEuint32(42)produced a signedInEuint32— the same shape your contract receives on testnet, signed byMockZkVerifierSigner.vm.prank(bob.account())+setValue(...)called the contract as Bob. The contract stored the ciphertext handle and granted ACL access to itself and Bob.expectPlaintext(myContract.storedValue(), 42)read the on-chain plaintext directly fromMockTaskManager.mockStorage— no permit, no SDK round-trip.
Next steps
- Foundry Plugin → Getting Started — full plugin configuration and features.
- CofheTest —
deployMocks,expectPlaintext, log toggles. - CofheClient — encrypt inputs, decrypt for view / tx, permits.
- Testing — canonical test patterns for ACL, public-decrypt, and fuzzing.