> ## Documentation Index
> Fetch the complete documentation index at: https://fhenix-docs-deep-dive-rewrite.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# FHE Operation Request Flow

> How an FHE operation travels from a smart contract call through the coprocessor to an onchain commitment

This page follows a single FHE operation from the contract call that requests it to the commitment that anchors its result onchain. The request itself is synchronous: the contract gets a handle for the result immediately, while the coprocessor computes the actual ciphertext in the background.

## Key components

| Component                                                                 | Description                                                                                  |
| ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| **Your contract**                                                         | Requests FHE operations through the FHE.sol library                                          |
| **FHE.sol**                                                               | The Solidity library providing FHE operation functions                                       |
| **[TaskManager](/deep-dive/cofhe-components/task-manager)**               | Validates requests, checks the [ACL](/deep-dive/cofhe-components/acl), and emits task events |
| **[FHE Engine](/deep-dive/cofhe-components/fhe-engine)**                  | Picks up task events, validates and orders the work, executes it, and commits the result     |
| **[CommitmentRegistry](/deep-dive/cofhe-components/commitment-registry)** | Records a hash commitment for every result ciphertext                                        |

## Flow diagram

```mermaid theme={null}
%%{init: {"theme": "base", "themeVariables": {"fontFamily": "Menlo, Monaco, Consolas, monospace", "fontSize": "16px", "primaryColor": "#8FBAF5", "primaryBorderColor": "#2E7CF6", "primaryTextColor": "#0A1626", "lineColor": "#4C8DFF", "signalColor": "#4C8DFF", "signalTextColor": "#8FA3BF", "actorBkg": "#8FBAF5", "actorBorder": "#2E7CF6", "actorTextColor": "#0A1626", "actorLineColor": "#3D4654", "noteBkgColor": "#14171C", "noteBorderColor": "#3D4654", "noteTextColor": "#AFC3DE", "activationBkgColor": "#1E3A5F", "activationBorderColor": "#4C8DFF", "clusterBkg": "#14171C", "clusterBorder": "#3D4654", "titleColor": "#E7EAEE", "edgeLabelBackground": "#8FBAF5", "textColor": "#AFC3DE", "labelTextColor": "#E7EAEE", "tertiaryColor": "#14171C", "loopTextColor": "#AFC3DE", "labelBoxBkgColor": "#1E3A5F", "labelBoxBorderColor": "#4C8DFF"}, "sequence": {"actorFontFamily": "Menlo, Monaco, Consolas, monospace", "messageFontFamily": "Menlo, Monaco, Consolas, monospace", "noteFontFamily": "Menlo, Monaco, Consolas, monospace", "width": 220, "actorFontSize": 16, "messageFontSize": 16, "noteFontSize": 15}}}%%
sequenceDiagram
    participant Contract as Your contract (FHE.sol)
    participant TM as TaskManager
    participant Engine as FHE Engine
    participant CR as CommitmentRegistry

    Contract->>TM: FHE.add(lhs, rhs) calls createTask
    TM->>TM: validate inputs, check ACL
    TM-->>Contract: result handle (synchronous)
    TM->>Engine: TaskCreated event
    Engine->>Engine: validate and order the task
    Engine->>Engine: execute op, store ciphertext under the handle
    Engine->>CR: postCommitments (batched)
```

## Step-by-step flow

<Steps>
  <Step title="Encrypt the input with the Client SDK">
    The application encrypts its input client-side and proves it valid, producing an encrypted-input handle plus a batch proof the contract can accept. The [Encryption Request Flow](/deep-dive/data-flows/encryption-request-flow) covers this step.

    <Note>
      This step happens on the client side, before any blockchain interaction.
    </Note>
  </Step>

  <Step title="Request an FHE operation">
    Import the FHE library in Solidity:

    ```solidity theme={null}
    import "@fhenixprotocol/cofhe-contracts/FHE.sol";
    ```

    Call the appropriate FHE function from the imported library:

    ```solidity theme={null}
    // Using trivial encrypt or the handle and proof from the previous step.
    function addExample(externalEuint32 input, bytes calldata proof) public {
        euint32 lhs = FHE.asEuint32(input, proof);
        euint32 rhs = FHE.asEuint32(10);

        // Request an operation (addition in this example)
        euint32 result = FHE.add(lhs, rhs);
    }
    ```

    FHE.sol forwards the request to the TaskManager contract.
  </Step>

  <Step title="TaskManager processing">
    The TaskManager is the gateway for all FHE operation requests. It:

    1. Validates the request structure, so all inputs are properly formatted.
    2. Verifies access permissions: the caller must have ACL access to every encrypted input.
    3. Generates a unique handle that will reference the future ciphertext result.
    4. Returns the handle to the calling contract, synchronously. Subsequent operations can chain on it right away.
    5. Emits a `TaskCreated` event with the operation details for the offchain services.
  </Step>

  <Step title="FHE Engine pickup">
    The [FHE Engine](/deep-dive/cofhe-components/fhe-engine) subscribes to TaskManager events on every host chain and picks up the `TaskCreated` event. It checks that the operation is well formed and that the inputs it references exist. An operation that arrives before its inputs finish computing is deferred and released once they land.
  </Step>

  <Step title="Execution">
    The engine then:

    1. Executes the requested operation on the encrypted data.
    2. Stores the result ciphertext in the ciphertext database, keyed by the handle.
    3. Releases any dependent operations that were deferred while waiting for this result.
  </Step>

  <Step title="Commitment posting">
    The engine produces a commitment for the result, the hash of the stored ciphertext bytes, and posts it in a batch to the CommitmentRegistry on the registry chain. The commitment anchors the result. Teecryptor will only decrypt ciphertext bytes that hash to a registered commitment.

    At this point the operation cycle is complete, and the confidentiality of every encrypted value is preserved.
  </Step>
</Steps>
