# How the Compute Contract Works

## Overview

A Compute Contract combines:

* On-chain economic agreement
* Guardian-based threshold decryption
* Off-chain computation
* Verifiable result publication
* Automatic fund settlement

It ensures that computation happens only after economic terms are agreed upon, and payment is released only after execution is completed.

## Architecture Components

<figure><picture><source srcset="/files/tMwc7iPDuP1qCZZupHEm" media="(prefers-color-scheme: dark)"><img src="/files/R76YTRn0r6ro2sG680fG" alt=""></picture><figcaption></figcaption></figure>

####

**User**\
Initiates the request through a dApp.

**dApp**\
Creates the agreement and a compute request transaction.

**RPC Node**\
Gateway between the dApp and the Palliora network.

**Guardian Nodes**\
Selected nodes that:

* Agree to the computation terms
* Perform threshold decryption
* Coordinate secure execution

**Guardian Service**\
Service layer responsible for:

* Threshold decryption
* Forwarding decrypted payloads to the Compute Node

**Compute Node**\
Executes the requested computation (AI model, logic, etc.).

**Data Availability Layer**\
Stores published results with recoverability and proof guarantees.

**Consensus Layer**\
Finalizes transactions, locks funds, and triggers settlement.

## Step-by-Step Flow

***

### 1. Agreement Creation

The flow begins when the User interacts with the dApp.

The dApp creates a Compute Contract Agreement Request, which defines:

* Compute the cost the user is willing to pay
* Threshold decryption fees
* List of selected Guardians
* Execution parameters

This formalizes the economic and trust assumptions before any computation begins.

***

### 2. Agreement Submission

The dApp sends the Agreement Request to an RPC Node.

The transaction:

1. Enters the transaction mempool
2. Funds are locked
3. Is broadcast to the selected Guardians

Each Guardian reviews the request and submits an Agreement confirmation. When all required Guardians agree:

* The agreement is included in a block
* A unique Agreement ID is generated

At this stage, the Compute Contract is officially established on-chain.

***

### 3. Compute Request Submission

After the Agreement is finalized:

* The dApp submits the Compute Request
* The request references the Agreement ID
* The compute payload is submitted encrypted

The encryption ensures that no single Guardian can access the payload alone, and decryption requires the agreed threshold

***

### 4. Threshold Decryption

Once the Compute Request is confirmed on-chain:

* The Guardian Service initiates threshold decryption
* A minimum number of Guardians must participate
* The payload is decrypted collectively

This guarantees privacy, shared trust, and resistance to single-node compromise

***

### 5. Execution by Compute Node

After decryption:

* The request is forwarded to the Compute Node( Trusted or Confidential)
* The computation is executed

The Compute Node only processes the decrypted payload, and does not control private keys, nor can it alter economic terms

***

### 6. Result Publication

When computation completes:

* The result is published to the Data Availability Layer

The Data Availability Layer ensures Proof of existence, Data recoverability and Verifiability

***

### 7. Consensus & Fund Release

Once the result is published:

* The Consensus Layer finalizes it
* Settlement logic is triggered
* Funds are released according to the Agreement

Payments are distributed to the Compute provider and Guardians  who participated in threshold decryption

***

### 8. Result Retrieval

While execution happens off-chain:

* The dApp polls for the result
* When available, it retrieves it from the Data Availability Layer
* The result is presented to the User

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.palliora.org/learn/architecture/how-the-compute-contract-works.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
