# 架构

Rome Protocol 将一个 EVM 字节码解释器嵌入到 Solana 链上程序中。本页将说明各组件如何协同工作。

## 系统概览

```
┌─────────────────────────────────────────────────────────────────┐
│                        用户层                                   │
│   MetaMask / ethers.js / Hardhat / Foundry                      │
│   （标准 Ethereum JSON-RPC）                                     │
└──────────────────────┬──────────────────────────────────────────┘
                       │
            ┌──────────┴──────────┐
            ▼                     ▼
   ┌────────────────┐    ┌────────────────┐
   │  Rome 代理     │    │   OP-Geth      │
   │  (:9090)       │    │   (:8545)      │
   │  JSON-RPC      │    │   EVM RPC      │
   └───────┬────────┘    └───────┬────────┘
           │                     │
           │              ┌──────┴──────┐
           │              │    Rhea     │  （将 geth 交易中继到 Solana）
           │              └──────┬──────┘
           │                     │
           └──────────┬──────────┘
                      ▼
   ┌──────────────────────────────────────────────────────────────┐
   │                    Solana 运行时                              │
   │                                                              │
   │   ┌──────────────────────────────────────────────────┐       │
   │   │              Rome EVM 程序                        │       │
   │   │                                                   │       │
   │   │   EVM 字节码解释器（SputnikVM 分支）               │       │
   │   │   账户映射：H160 → Solana PDA                     │       │
   │   │   预编译：ecrecover、BN254、SPL、CPI 等           │       │
   │   └───────────────────────┬───────────────────────────┘       │
   │                           │ CPI                               │
   │   ┌───────────┬───────────┼───────────┬───────────┐          │
   │   │SPL 代币   │ Jupiter   │ Kamino    │ Meteora   │  ...     │
   │   └───────────┴───────────┴───────────┴───────────┘          │
   └──────────────────────────────────────────────────────────────┘
                      ▲
                      │ 索引事件
               ┌──────┴──────┐
               │  Hercules   │  （区块索引器 → Engine API → OP-Geth）
               └─────────────┘
```

## 组件

### Rome EVM 程序（链上）

Rome 的核心——一个 Solana BPF 程序，内置完整的 EVM 字节码解释器（SputnikVM 分支）。它：

* 接收来自 Solana 指令的序列化 EVM 交易
* 在 Solana 运行时中执行 Solidity 字节码
* 将以太坊地址（H160）映射到 Solana PDA
* 为 CPI、SPL 代币、系统程序提供预编译接口
* 将 EVM 状态（合约存储、余额、nonce）作为 Solana 账户数据进行管理

### Rome 代理（JSON-RPC 服务器）

一个运行在 9090 端口的标准 Ethereum JSON-RPC 服务器，将 Ethereum API 调用转换为 Solana 交易：

* `eth_sendRawTransaction` → 序列化 EVM 交易 → 提交 Solana 指令
* `eth_call` → 在链下模拟 EVM 执行（通过 Mollusk SVM 模拟器）
* `eth_estimateGas` → 模拟执行以进行 gas 估算
* `eth_getBalance`, `eth_getCode`等 → 从 Solana 账户数据中读取

Rome 扩展： `rome_emulateTx`, `rome_emulateRegRollup`, `rome_mintId`, `rome_buildInfo`, `rome_getResources`.

### OP-Geth（可选 EVM RPC 层）

一个经过修改的 Go-Ethereum 客户端，提供完整的 Ethereum RPC 兼容性。在 op-geth 模式下：

1. 用户将交易发送到 OP-Geth（:8545）
2. Rhea 将交易中继到 Rome 代理 → Solana
3. Hercules 索引 Solana 事件，并通过 Engine API（:8551）将 EVM 区块馈送给 OP-Geth

在单状态模式下，用户直接连接到 Rome 代理（:9090），完全绕过 OP-Geth。

### Hercules（索引器）

监控 Solana 上的 Rome EVM 程序，并生成与 EVM 兼容的区块数据：

* 监听 Solana 上的 Rome 程序事件
* 重建包含交易收据、日志和状态变更的 EVM 区块
* 通过 Engine API 将区块馈送给 OP-Geth，以实现标准区块浏览器兼容性
* 由 PostgreSQL 提供支持

### Rhea（Mempool 桥接器）

将 OP-Geth 的 mempool 桥接到 Solana：

* 从 OP-Geth 的 mempool 中读取待处理交易
* 将其封装为指向 Rome EVM 程序的 Solana 指令
* 提交到 Solana 执行

## 执行模式

Rome 为 EVM 交易支持两种执行模式：

### 原子执行（VmAt）

单个 Solana 交易。整个 EVM 交易在一次 Solana 交易的计算预算内执行（约 140 万 compute units）。用于大多数操作——转账、简单合约调用、兑换。

### 迭代执行（VmIt）

适用于超出单笔交易预算的计算密集型操作。EVM 执行会拆分为多个 Solana 交易：

1. 每一步执行约 500 条 EVM 操作码
2. VM 状态会以 Borsh 序列化到一个 `StateHolder` 步骤之间的账户中
3. 执行期间账户会被 TTL 锁定 3–4 秒
4. 用于 BN254 配对等重型操作（ZK 证明验证）

## 账户映射

每个以太坊地址（20 字节）都会映射到由 Rome EVM 程序派生出的 Solana PDA（32 字节）：

```
Ethereum Address (H160) → PDA = findProgramAddress([address], ROME_EVM_PROGRAM)
```

该 PDA 拥有账户的：

* ETH/代币余额（作为 SPL 代币账户）
* 合约字节码（存储在 Solana 账户数据中）
* 合约存储槽（存储在 Solana 账户数据中）
* Nonce

## Holder 账户

Solana 交易限制为 1,232 字节。EVM 交易（尤其是合约部署）可能大得多。Rome 通过以下方式处理： **holder 账户**:

1. 大型 EVM 交易会被拆分为多个块
2. 这些块会按顺序暂存到 holder 账户中（最大 80 KB）
3. 当所有块都写入后，完整交易会被组装并执行
4. 这由 Rome SDK 透明地管理

## Gas 与定价

Rome 上的每个应用（链 ID）都有自己的 gas 代币——任意 SPL 代币。Gas 定价使用 Meteora DAMM V1 池，在 gas 代币与 SOL 之间转换，用于底层 Solana 交易费用。

## 部署模式

| 模式             | 数据流                                             | 使用场景                 |
| -------------- | ----------------------------------------------- | -------------------- |
| **OP-Geth 模式** | 用户 → OP-Geth → Rhea → 代理 → Solana；Hercules 反向索引 | 完整的 Ethereum RPC 兼容性 |
| **单状态模式**      | 用户 → 直接连接代理 → Solana                            | 部署更简单，延迟更低           |

## 下一步

* [快速开始](/zh/ru-men/quickstart.md) — 部署你的第一个合约
* [执行模型](/zh/he-xin-gai-nian/execution-model.md) — 深入了解原子执行与迭代执行
* [计算预算](/zh/he-xin-gai-nian/compute-budget.md) — 理解 CU 成本与优化


---

# 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.rome.builders/zh/ru-men/architecture.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.
