Skip to main content
This page summarizes the public surface of @cofhe/foundry-plugin. For task-oriented walkthroughs, see Getting Started and Testing.

CofheTest

Abstract test base. Inherit it instead of forge-std/Test (it inherits Test for you).
import { CofheTest } from "@cofhe/foundry-plugin/contracts/CofheTest.sol";

Setup

FunctionDescription
deployMocks()Deploy MockTaskManager, MockACL, MockZkVerifier, MockZkVerifierSigner, MockThresholdNetwork, MockThresholdNetworkSigner. Wires them via setACLContract / setVerifierSigner / setDecryptResultSigner. Funds the ZK signer with 10 ether. Call once in setUp().
createCofheClient()Returns a fresh CofheClient. Follow with client.connect(pkey).

Plaintext reads

FunctionDescription
getPlaintext(bytes32 handle)Returns the raw bytes32 plaintext from MockTaskManager.mockStorage.
getPlaintext(ebool) / (euint8) / (euint16) / (euint32) / (euint64) / (euint128) / (eaddress)Typed overloads returning bool / uint8uint128 / address.
expectPlaintext(handle, value)Assertion variant — typed overloads for the same set.
expectPlaintext(handle, value, "msg")With assertion message.
Reverts if the handle isn’t in mock storage.

Logging

FunctionDescription
enableLogs()Calls mockTaskManager.setLogOps(true).
disableLogs()Calls mockTaskManager.setLogOps(false).

Public state

FieldType
mockTaskManagerMockTaskManager
mockAclMockACL
mockZkVerifierMockZkVerifier
mockZkVerifierSignerMockZkVerifierSigner
mockThresholdNetworkMockThresholdNetwork
mockThresholdNetworkSignerMockThresholdNetworkSigner

CofheClient

Per-user shim. One client per scenario address.
import { CofheClient } from "@cofhe/foundry-plugin/contracts/CofheClient.sol";

Connection

FunctionDescription
connect(uint256 pkey)Set the connected account to vm.addr(pkey). Required before any createIn* or permit_* call.
account()Returns the connected address.

Encrypt inputs

FunctionReturns
createInEbool(bool)InEbool
createInEuint8(uint8)InEuint8
createInEuint16(uint16)InEuint16
createInEuint32(uint32)InEuint32
createInEuint64(uint64)InEuint64
createInEuint128(uint128)InEuint128
createInEaddress(address)InEaddress
All produce signed EncryptedInput shapes signed for account().

Decrypt

FunctionReturnsNotes
decryptForTx_withoutPermit(bytes32 ctHash)(bytes32, uint256, bytes)(ctHash, plaintext, signature). Signature consumable by FHE.publishDecryptResult. Requires FHE.allowPublic(handle) to have been called.
decryptForTx_withPermit(bytes32 ctHash, Permission permit)(bytes32, uint256, bytes)ACL-gated decryptForTx.
decryptForView(bytes32 ctHash, Permission permit)uint256Off-chain seal/unseal. Reverts on deny — to assert deny use mockThresholdNetwork.querySealOutput(...).

Permits

FunctionDescription
permit_createSelf()Self-permit for the connected account; sealing key auto-derived.
permit_createShared(address recipient)Issuer-side shared permit.
permit_exportShared(Permission perm)Strip sensitive fields → SharedPermitExport.
permit_importShared(SharedPermitExport export)Recipient-side completion. Reverts unless export.recipient == account().
createSealingKey(bytes32 seed)Custom sealing key (rarely needed).

Mock storage layout

MockTaskManager.mockStorage is the on-chain plaintext storage that backs getPlaintext / expectPlaintext. It only exists in the mock environment — getPlaintext reverts on real CoFHE networks.

foundry.toml requirements

[profile.default]
solc_version = "0.8.25"     # cofhe-contracts target
evm_version = "cancun"      # MockACL uses tstore/tload
auto_detect_remappings = false
code_size_limit = 100000    # mocks exceed 24 KB
libs = ["node_modules"]

remappings.txt (canonical shape)

forge-std/=node_modules/forge-std/src/
hardhat/=node_modules/forge-std/src/
@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/
@fhenixprotocol/cofhe-contracts/=node_modules/@fhenixprotocol/cofhe-contracts/
@cofhe/mock-contracts/=node_modules/@cofhe/mock-contracts/
@cofhe/foundry-plugin/=node_modules/@cofhe/foundry-plugin/
  • @cofhe/mock-contracts/ points at the package root, not …/contracts/. The plugin’s imports include the contracts/ segment themselves.
  • hardhat/=node_modules/forge-std/src/ is required so that MockCoFHE.sol’s import "hardhat/console.sol" resolves to forge-std’s compatible console.

Version pinning

@cofhe/foundry-plugin and @cofhe/mock-contracts pin @fhenixprotocol/cofhe-contracts exactly — keep all three CoFHE packages aligned. Known-good tuple as of the latest release:
PackageVersion
@cofhe/foundry-plugin0.5.1
@cofhe/mock-contracts0.5.1
@fhenixprotocol/cofhe-contracts0.1.3
See the Compatibility page for the canonical table.