> ## 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

> publishDecryptResult, verifyDecryptResult, getDecryptResult — on-chain decryption result handling

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`.

<ParamField body="ctHash" type="ebool | euint8 | euint16 | euint32 | euint64 | euint128 | eaddress" required>
  Ciphertext handle
</ParamField>

<ParamField body="plaintext" type="bool | uint8 | uint16 | uint32 | uint64 | uint128 | address" required>
  Decrypted value from `decryptForTx`
</ParamField>

<ParamField body="signature" type="bytes" required>
  Threshold Network signature
</ParamField>

<Warning>
  Reverts if the signature is invalid. The value must have been granted public access via `allowPublic` before decryption was requested off-chain.
</Warning>

```solidity theme={null}
FHE.publishDecryptResult(encryptedBid, bidPlaintext, bidSignature);
```

### publishDecryptResultBatch

Publishes multiple results in a single call. Typed overloads exist for all encrypted types.

```solidity theme={null}
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`.

<Tip>
  Use this when you only need to act on the decrypted value within the transaction without making it permanently public.
</Tip>

```solidity theme={null}
require(
    FHE.verifyDecryptResult(encryptedAmount, amount, signature),
    "Invalid decrypt proof"
);
```

### verifyDecryptResultSafe

Like `verifyDecryptResult`, but returns `false` instead of reverting on invalid signature.

```solidity theme={null}
bool valid = FHE.verifyDecryptResultSafe(encryptedAmount, amount, signature);
if (valid) {
    // proceed
}
```

### verifyDecryptResultBatch

Verifies multiple signatures in a single call. Reverts if any is invalid.

```solidity theme={null}
bool allValid = FHE.verifyDecryptResultBatch(handles, values, sigs);
```

### verifyDecryptResultBatchSafe

Returns a `bool[]` indicating which entries are valid instead of reverting.

```solidity theme={null}
bool[] memory results = FHE.verifyDecryptResultBatchSafe(handles, values, sigs);
```

***

## Reading Results

### getDecryptResult

Retrieves a published decryption result. Reverts if not yet available.

```solidity theme={null}
uint256 result = FHE.getDecryptResult(ctHash);
```

### getDecryptResultSafe

Non-reverting version. Returns a tuple with the result and a boolean flag.

```solidity theme={null}
(uint256 result, bool decrypted) = FHE.getDecryptResultSafe(ctHash);
if (decrypted) {
    // use result
}
```
