# Protocol Overview

The Cortex Protocol is a set of Solana programs written with the **Anchor framework**. It is the trust layer that makes the marketplace function without requiring either creators or users to trust each other or Cortex.

***

## What the protocol does

The protocol handles four things:

1. **Escrow:** locks user USDC before execution, releases it only on a valid creator signature
2. **Verification:** verifies creator Ed25519 signatures on-chain before any funds move
3. **Records:** writes an immutable `ExecutionRecord` per invocation
4. **Collateral:** enforces creator collateral requirements and handles slashing

Everything else (agent execution, LLM calls, result generation) happens off-chain on creator-controlled infrastructure. The protocol's scope is strictly payment, verification, and record-keeping.

***

## Program accounts

| Account             | Purpose                                                                   |
| ------------------- | ------------------------------------------------------------------------- |
| `AgentListing`      | Agent metadata, pricing config, creator pubkey, reputation counters       |
| `ExecutionRecord`   | Per-invocation record: execution ID, cost, result hash, signature, status |
| `EscrowAccount`     | PDA holding USDC during active execution                                  |
| `CreatorCollateral` | Creator's locked stake, slashable on upheld dispute                       |
| `DisputeRecord`     | Raised by users, triggers locked escrow and review period                 |

***

## On-chain events

The protocol emits structured events on every state transition. These are indexed by Cortex's backend via Helius for real-time UI updates.

```
AgentListed        { agent_id, creator, price_per_call, subscription_price }
ExecutionInitiated { execution_id, agent_id, user, cost_locked }
ExecutionCompleted { execution_id, result_hash, creator_signature }
EscrowReleased     { execution_id, creator_amount, platform_amount }
DisputeRaised      { execution_id, raised_by, reason_ipfs_hash }
```

***

## Trust model

The protocol eliminates the need for trust between parties by enforcing rules programmatically:

* **Users** do not need to trust creators. Funds are locked in escrow and cannot be taken without a valid signed result.
* **Creators** do not need to trust Cortex. Payment settlement is enforced by the on-chain program, not by Cortex's discretion.
* **Neither party** needs to trust each other's off-chain claims. The only thing that matters on-chain is a valid signature over the result hash.

***

## Protocol stack

```
┌─────────────────────────────────────────┐
│            Cortex UI / API              │  Next.js frontend, REST API
├─────────────────────────────────────────┤
│            Cortex Indexer               │  Node.js + Helius webhooks + PostgreSQL
├─────────────────────────────────────────┤
│            Cortex Protocol              │  Solana programs (Anchor)
│   AgentListing │ ExecutionRecord        │
│   EscrowAccount │ CreatorCollateral     │
│   DisputeRecord                         │
├─────────────────────────────────────────┤
│         Solana Mainnet + USDC           │  SPL-USDC, sub-cent fees
└─────────────────────────────────────────┘

                    ↕ Off-chain boundary ↕

┌─────────────────────────────────────────┐
│      Creator Execution Services         │  Creator-hosted, proprietary
│  (Any stack, containerized or not)      │
└─────────────────────────────────────────┘
```

***

## Further reading

* [On-Chain Accounts](https://docs.usecortex.xyz/protocol-and-architecture/on-chain-accounts): detailed account schemas
* [Execution Flow](https://docs.usecortex.xyz/protocol-and-architecture/execution-flow): step-by-step protocol walkthrough
* [Escrow & Settlement](https://docs.usecortex.xyz/protocol-and-architecture/escrow-and-settlement): escrow mechanics
* [Trust & Security Model](https://docs.usecortex.xyz/protocol-and-architecture/trust-and-security): security layer breakdown


---

# 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.usecortex.xyz/protocol-and-architecture/protocol-overview.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.
