Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cofhe-docs.fhenix.zone/llms.txt

Use this file to discover all available pages before exploring further.

Decryption in CoFHE is a two-phase process:
  1. On-chain: Mark a value as decryptable with FHE.allowPublic(ctHash)
  2. Off-chain: Client calls decryptForTx(ctHash) via the SDK to get { plaintext, signature }
  3. On-chain: Submit the result via publishDecryptResult or verifyDecryptResult

Publishing Results

publishDecryptResult

Publishes a decrypted result on-chain by verifying the Threshold Network signature. The plaintext is stored and can be read via getDecryptResultSafe.
ctHash
ebool | euint8 | euint16 | euint32 | euint64 | euint128 | eaddress
required
Ciphertext handle
plaintext
bool | uint8 | uint16 | uint32 | uint64 | uint128 | address
required
Decrypted value from decryptForTx
signature
bytes
required
Threshold Network signature
Reverts if the signature is invalid. The value must have been granted public access via allowPublic before decryption was requested off-chain.
FHE.publishDecryptResult(encryptedBid, bidPlaintext, bidSignature);

publishDecryptResultBatch

Publishes multiple results in a single call. Typed overloads exist for every encrypted type:
Handle array typeResult array type
ebool[]bool[]
euint8[]uint8[]
euint16[]uint16[]
euint32[]uint32[]
euint64[]uint64[]
euint128[]uint128[]
eaddress[]address[]
euint64[] memory handles = new euint64[](2);
handles[0] = encryptedBid1;
handles[1] = encryptedBid2;

uint64[] memory values = new uint64[](2);
values[0] = bid1Plaintext;
values[1] = bid2Plaintext;

bytes[] memory sigs = new bytes[](2);
sigs[0] = sig1;
sigs[1] = sig2;

FHE.publishDecryptResultBatch(handles, values, sigs);
The compiler resolves the overload from the handle array’s element type. There is also a “raw” overload that takes uint256[] ctHashes if you only have raw handles to hand.

Verifying Results

verifyDecryptResult

Verifies a Threshold Network signature without storing the plaintext on-chain. Returns bool.
Use this when you only need to act on the decrypted value within the transaction without making it permanently public.
require(
    FHE.verifyDecryptResult(encryptedAmount, amount, signature),
    "Invalid decrypt proof"
);

verifyDecryptResultSafe

Like verifyDecryptResult, but returns false instead of reverting on invalid signature.
bool valid = FHE.verifyDecryptResultSafe(encryptedAmount, amount, signature);
if (valid) {
    // proceed
}

verifyDecryptResultBatch

Verifies multiple signatures in a single call. Returns true only if every entry is valid; reverts if any signature fails to recover (consistent with the single-entry verifyDecryptResult). Typed overloads exist for every encrypted type — same handle/result type table as publishDecryptResultBatch.
bool allValid = FHE.verifyDecryptResultBatch(handles, values, sigs);

verifyDecryptResultBatchSafe

Returns a bool[] indicating which entries are valid instead of reverting. Typed overloads cover every encrypted type — same handle/result type table as publishDecryptResultBatch.
bool[] memory results = FHE.verifyDecryptResultBatchSafe(handles, values, sigs);
The batch verify functions (verifyDecryptResultBatch, verifyDecryptResultBatchSafe) were added in cofhe-contracts@v0.1.2. Earlier versions only exposed the single-entry verifyDecryptResult / verifyDecryptResultSafe.

Reading Results

getDecryptResult

Retrieves a published decryption result. Reverts if not yet available.
uint256 result = FHE.getDecryptResult(ctHash);

getDecryptResultSafe

Non-reverting version. Returns a tuple with the result and a boolean flag.
(uint256 result, bool decrypted) = FHE.getDecryptResultSafe(ctHash);
if (decrypted) {
    // use result
}