> For the complete documentation index, see [llms.txt](https://docs.rome.builders/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rome.builders/zh/he-xin-gai-nian/execution-model.md).

# 执行模型

Rome EVM 如何在 Solana 上处理以太坊交易——代理仿真、原子模式（VmAt）与迭代模式（VmIt），以及完整的交易生命周期。

Rome EVM 在 Solana 链上程序中执行 Solidity 字节码。本页说明 EVM 交易如何处理。

## 交易生命周期

```
1. 用户签署 EVM 交易（MetaMask / ethers.js）
                    ↓
2. Rome Proxy 通过 eth_sendRawTransaction 接收
                    ↓
3. Proxy 在链下模拟交易（Mollusk SVM 模拟器）
   → 估算 gas、检查原子性、识别所需账户
                    ↓
4. Proxy 将 EVM 交易封装为 Solana 指令
   → 如果交易可放入一笔 Solana 交易中 → 原子模式（VmAt）
   → 如果交易超出 CU 预算 → 迭代模式（VmIt）
                    ↓
5. Solana 验证者执行这些指令
   → Rome EVM 程序解释 EVM 字节码
   → 对其他 Solana 程序的 CPI 调用（如有）
                    ↓
6. 状态更改提交到 Solana 账户
                    ↓
7. Hercules 索引该事件 → 生成 EVM 区块
```

## 原子执行（VmAt）

默认模式。整个 EVM 交易在单笔 Solana 交易内执行。

**状态机：** `Lock → Init → Execute → Commit → GasTransfer → Exit`

**特性：**

* 全有或全无执行——如果任何步骤失败，整个交易回滚
* 每笔 Solana 交易约可用 140 万计算单元
* 适用于转账、简单合约调用、交换以及大多数 DeFi 操作
* 亚秒级最终确认（Solana 区块时间）

**何时使用：** 当模拟器判断交易可在单笔 Solana 交易的计算预算内完成时自动选择。

## 迭代执行（VmIt）

用于超出单笔交易预算的计算密集型操作。EVM 执行将拆分到多笔 Solana 交易中。

**工作原理：**

1. 每一步（一个 Solana 交易）执行 **尽可能多的 EVM 操作码，直至达到其计算预算** ——这是自适应步长，而非固定数量
2. 每一步后，VM 状态会以 Borsh 格式序列化到一个 `StateHolder` 账户
3. 下一步会反序列化状态并继续执行
4. 涉及的账户会被 TTL 锁定 **3-4 秒** 在多步执行期间；一个会话上限为 **160 步**；超过该时间后，下一步会释放会话锁并结束，不提交任何内容

**状态机：** `FromStateHolder → Lock → Init → Execute → Serialize → NextIteration → ... → Completed`

**账户锁定：**

* 一个 **独占锁** 每个受管理账户（余额和存储账户）各有一把独占锁——同一时间只能有一个迭代会话持有某个账户；写入已锁定账户的原子交易会被拒绝，返回 `AccountLocked` 直到锁过期，客户端重新发送
* **TTL：** 3 秒，每一步续期一次（当会话触及超过 28 个账户时为 4 秒）
* **Legacy 路径的 CPI 会被拒绝** 在迭代交易中（`CpiProhibitedInIterativeTx`）；cached 路径的效果会先暂存，并在最后提交

**何时使用：** 大型合约部署、深层调用栈，以及任何超过约 140 万 CU 的操作。单独的 BN254 配对检查不需要它；见 [计算预算](https://docs.rome.builders/zh/he-xin-gai-nian/compute-budget.md).

## 模拟

在将交易提交到 Solana 之前，Proxy 会使用 **Mollusk SVM 模拟器**在链下模拟它。这会：

1. 估算 gas 消耗
2. 判断需要原子模式还是迭代模式
3. 识别交易将触及的所有 Solana 账户
4. 验证交易不会在链上失败

模拟器执行与链上程序相同的 EVM 逻辑—— `entrypoint!` 宏确保程序和模拟器代码库中的分发表完全一致。

**Mollusk SVM** 在模拟期间还可以执行任意 Solana BPF 程序，这意味着 `eth_call` 和 `eth_estimateGas` 能够正确处理对 SPL Token、Jupiter、Kamino 等的 CPI 调用。

## 账户映射

每个以太坊地址映射到一个 Solana PDA：

```
以太坊地址（H160，20 字节）
    ↓
PDA = findProgramAddress(
    [chain_id, "ACCOUN_SEED", H160, bump],
    ROME_EVM_PROGRAM_ID
)
    ↓
Solana 账户（Pubkey，32 字节）
```

**链上存储的账户类型：**

| 类型          | 种子                                           | 用途                 |
| ----------- | -------------------------------------------- | ------------------ |
| 余额          | `[chain, "ACCOUN_SEED", H160, bump]`         | Nonce、余额、合约代码      |
| 存储          | `[chain, "STORAGE", H160, slot_index, bump]` | 合约存储（每个账户 256 个槽位） |
| TxHolder    | `[signer, "TX_HOLDER_SEED", index, bump]`    | 暂存的交易数据（最大 80 KB）  |
| StateHolder | `[signer, "STATE_HOLDER_SEED", index, bump]` | 迭代之间序列化的 VM 状态     |

## Holder 账户

Rome 向 Solana 发送 **v1 交易**，其限制为 4 KB（4,096 字节）和 64 个地址。EVM 交易——尤其是合约部署——可能要大得多。

**拆分机制：**

1. SDK 将 RLP 编码的交易拆分为多个块
2. 每个块都会写入一个 `TxHolder` 账户，通过 `TransmitTx` 指令
3. 当所有块都暂存后，一个 `DoTxHolder` 指令会组装并执行完整交易
4. Holder 最大大小： **80 KB** 每个 TxHolder

这对开发者完全透明——Rome SDK 会自动处理拆分与重组。

## 支持的交易类型

| 类型            | EIP      | 描述                                                                                                                                                                  |
| ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Legacy        | ——       | 传统以太坊交易                                                                                                                                                             |
| 访问列表          | EIP-2930 | 优化的状态访问模式                                                                                                                                                           |
| 动态费用          | EIP-1559 | 基础费用 + 优先费                                                                                                                                                          |
| 未签名的 EIP-1559 | ——       | 一个 `0x02`类型的负载，没有 secp256k1 签名，而是由 Solana 钱包的 Ed25519 签名授权（Solana 通道；见 [从 Solana 调用 EVM](https://docs.rome.builders/zh/kai-fa-zhe-zhi-nan/call-evm-from-solana.md)) |
| 存款            | 类型 0x7E  | 存款交易，例如桥入站结算                                                                                                                                                        |

## 日志化状态

Rome EVM 在执行期间使用日志化状态模型管理状态变更：

* 所有更改（nonce、余额、存储、代码）都记录在一个 `日志`
* 嵌套的 CALL/CREATE 操作会压入快照帧
* 回滚时：日志条目回滚到快照
* 成功时：更改提交到 Solana 账户
* 非 EVM 的 CPI 指令会立即执行（Solana 自身的原子性保证正确性）

## 下一步

* [计算预算](https://docs.rome.builders/zh/he-xin-gai-nian/compute-budget.md) —— CU 成本和优化策略
* [约束](https://docs.rome.builders/zh/he-xin-gai-nian/constraints.md) —— 重要限制和边界


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rome.builders/zh/he-xin-gai-nian/execution-model.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
