Skip to main content
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 all encrypted types.
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);

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. Reverts if any is invalid.
bool allValid = FHE.verifyDecryptResultBatch(handles, values, sigs);

verifyDecryptResultBatchSafe

Returns a bool[] indicating which entries are valid instead of reverting.
bool[] memory results = FHE.verifyDecryptResultBatchSafe(handles, values, sigs);

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
}