# Universal PSBT Engine

Atomic Execution Architecture

Partially Signed Bitcoin Transactions (PSBTs) provide the cryptographic foundation for atomic execution within the Nexus Protocol. Whether clearing trades on the L1 Settlement layer or updating balances via State Channel Rollups, PSBTs ensure that a transaction either executes entirely or fails completely.

This mechanism eliminates counterparty risk by leveraging Bitcoin's native consensus, enabling complex multi-party coordination without exposing asset private keys.

> ‼️ Nexus does not store user funds or private keys. All activity is coordinated cryptographically.

#### The Coordinated Signing Flow

The PSBT orchestration follows a strict, multi-party verification process. No party can execute an incomplete transaction, nor can any party alter the transaction post-signature.

{% stepper %}
{% step %}
Step 1: Draft Construction & Intent Matching

The Nexus Composer receives an [off-chain trading intent](/trading-and-routing-strategies/intent-execution.md). It queries available liquidity, computes the mathematics (AMM slippage, routing paths), and drafts a raw, unsigned PSBT containing the necessary inputs and output states.
{% endstep %}

{% step %}
Step 2: Taker Signature (Commitment)

The Taker reviews the drafted PSBT, confirming the final output amounts and fee allocations. To commit to the execution, the Taker applies their cryptographic signature to their specific inputs first.
{% endstep %}

{% step %}
Step 3: Maker Verification (Last Look)

The participating Maker (or [Institutional MPC Node](/deployment-and-integration/institutional-mpc.md)) receives the Taker-signed PSBT. The Maker evaluates the order against real-time oracle pricing and internal risk models to ensure it is not toxic flow (e.g., latency arbitrage). This "Last Look" privilege is essential to shelter Makers from impermanent loss.
{% endstep %}

{% step %}
Step 4: Final Maker Signature

Upon passing validation, the Maker applies the final cryptographic signatures required to unlock their liquidity. The PSBT is now fully formed and valid under Bitcoin consensus rules.
{% endstep %}

{% step %}
Step 5: Network Broadcast / Rollup Settlement

Depending on the routing strategy, the resulting transaction is either propagated to the Bitcoin L1 mempool for direct settlement, or ingested into the [HTLC State Channel](/protocol-architecture/fast-execution-accounts.md) for dynamic, multi-trade deferred settlement.
{% endstep %}
{% endstepper %}

#### Cryptographic Protections

The Universal PSBT Engine enforces zero-trust security using natively supported Bitcoin script mechanisms rather than smart contracts:

* Slippage Guard Outputs: Using strict UTXO mappings, the PSBT intrinsically fails if the output to the Taker falls below their defined tolerance.
* Replace-By-Fee (RBF): Full compatibility allows latency-sensitive trades to aggressively compete for blockspace without reinventing priority logic.
* Time-Lock Mechanisms: Output branches utilize `nLockTime` to auto-cancel stale PSBT drafts, preventing indefinite capital lockups.

***

#### 📚 Concept Guide

<details>

<summary><strong>PSBT (Partially Signed Bitcoin Transactions)</strong></summary>

A native Bitcoin standard (BIP 174) allowing multiple, entirely mutually distrusting parties to contribute inputs and outputs into a single transaction without exposing their private keys. Nexus utilizes this to ensure atomic swaps—the trade either executes perfectly as agreed, or mathematically fails to exist.

</details>

<details>

<summary><strong>Intent-Based Execution</strong></summary>

A structural pivot away from contract-driven DeFi. Rather than broadcasting specific execution commands (e.g., "Use Route A to swap X"), Takers only cryptographically sign their *desired outcome* (e.g., "I will output X only if I receive Y"). This closes the vulnerability to front-running and MEV since the strategy is never exposed.

</details>


---

# 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.on.nexus/protocol-architecture/psbt-engine.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.
