> 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 交易内执行。

**状态机：** `锁定 → 初始化 → 执行 → 提交 → Gas 转移 → 退出`

**特性：**

* 要么全部执行，要么全部回滚——如果任一步失败，整笔交易都会回滚
* 每笔 Solana 交易约可用 140 万计算单元
* 适用于转账、简单合约调用、兑换以及大多数 DeFi 操作
* 亚秒级最终确认（Solana 出块时间）

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

## 迭代执行（VmIt）

适用于超出单笔交易预算的高计算量操作。EVM 执行会拆分到多笔 Solana 交易中。

**工作原理：**

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

**状态机：** `从 StateHolder → 锁定 → 初始化 → 执行 → 序列化 → 下一次迭代 → ... → 完成`

**账户锁定：**

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

**何时使用：** 大型合约部署、深层调用栈，以及任何超过约 140 万 CU 的操作。单独的 BN254 pairing 检查并不需要它；参见 [计算预算](/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 调用。

## 账户映射

每个 Ethereum 地址都会映射到一个 Solana PDA：

```
Ethereum 地址（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      | 说明                                                                                                                                        |
| ------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| 传统            | —        | 传统 Ethereum 交易                                                                                                                            |
| 访问列表          | EIP-2930 | 优化的状态访问模式                                                                                                                                 |
| 动态费用          | EIP-1559 | 基础费用 + 优先费用                                                                                                                               |
| 未签名的 EIP-1559 | —        | 一个 `0x02`类型正文，不含 secp256k1 签名，而是由 Solana 钱包的 Ed25519 签名授权（Solana 通道；参见 [从 Solana 调用 EVM](/zh/kai-fa-zhe-zhi-nan/call-evm-from-solana.md)) |
| 存入            | 类型 0x7E  | 存款交易，例如跨链桥入站结算                                                                                                                            |

## 日志化状态

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

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

## 接下来

* [计算预算](/zh/he-xin-gai-nian/compute-budget.md) —— CU 成本与优化策略
* [约束](/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.
