> 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/constraints.md).

# 约束

在 Rome EVM 上构建时的限制——Solana 交易大小、约 140 万 CU 预算、账户上限、存储布局，以及 Rome 如何逐一规避这些限制。

在 Rome EVM 上构建时的重要限制与边界。理解这些约束有助于您设计能够可靠运行的合约。

## Solana 交易限制

| 约束        | 值              | 影响                                             |
| --------- | -------------- | ---------------------------------------------- |
| 交易大小      | 4 KB（4,096 字节） | Rome 发送 Solana v1 交易；更大的 EVM 交易会暂存到持有账户中（透明）   |
| 每笔交易的计算单元 | 约 140 万 CU     | 超过此值的操作将使用迭代模式，其有自己的上限（见下）                     |
| 每笔交易的账户数  | 64 个地址         | v1 交易上限；EVM 交易及其 CPI 所触及的一切都计入其中，包括 Rome 自身的账户 |
| 最大持有账户大小  | 80 KB          | 单笔 EVM 交易的最大 RLP 大小                            |

## EVM 执行限制

| 约束                    | 值                         | 说明                                                                                                                                                         |
| --------------------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 合约存储槽                 | 每个存储账户 256 个              | 每个合约可创建多个存储账户                                                                                                                                              |
| 每轮迭代的操作码数             | 自适应                       | 按每笔 Solana 交易的 CU 预算进行打包（VmIt）                                                                                                                             |
| 账户锁定 TTL              | 3 秒（当会话触及超过 28 个账户时为 4 秒） | 在迭代执行期间；每一步都会续期                                                                                                                                            |
| 迭代会话长度                | 160 步                     | 超过上限后，下一步会释放会话锁并结束会话，不提交任何内容                                                                                                                               |
| 由 Rust Rome SDK 规划的分段 | 128                       | 迭代编排器的上限；实际调用通常远少于此                                                                                                                                        |
| 每个由钱包签名的计划中的交易数       | 64                        | 最多 `rome_submitSignedV1Plan` 一次调用中可接受；参见 [转发调用和长调用](https://docs.rome.builders/zh/kai-fa-zhe-zhi-nan/call-evm-from-solana.md#relayed-calls-and-long-calls) |
| 财务钱包                  | 64                        | 手续费池钱包                                                                                                                                                     |
| 合约大小限制                | 24 KB                     | 与 Ethereum 相同（EIP-170，24,576 字节）                                                                                                                           |

## CPI 约束

| 约束                     | 值                                                           | 说明                                                             |
| ---------------------- | ----------------------------------------------------------- | -------------------------------------------------------------- |
| CPI 深度                 | 最多 4 层                                                      | Solana 的 CPI 深度限制                                              |
| 每次 CPI 调用的账户数          | 在 64 地址的交易上限内                                               | 与交易触及的所有其他账户共享                                                 |
| CPI + Transfer Hook 深度 | 使用 CPI 层级                                                   | 在 CPI 内部触发的转移钩子可能会超过深度限制                                       |
| 每个合约仅限一条路径             | 传统（`0xff…07/08/09`, `0x42…16`) **或** 缓存（`0xff…04/05/06/0b`) | 在同一笔交易中混用两者的变更调用会被拒绝                                           |
| 迭代模式下的传统 CPI           | 不允许                                                         | 迭代交易中的传统路径 CPI 会失败并报错 `CpiProhibitedInIterativeTx`；缓存路径的效果是允许的 |

**CPI 深度是最关键的约束。** 当 Solana 调用 Rome 程序时，Rome EVM 会占用一层 CPI。若您的 Solidity 合约随后通过 CPI 调用另一个 Solana 程序，则为第 2 层。若该程序再调用另一个程序，则为第 3 层。总共最多只有 4 层。

```
第 0 层：Solana Runtime → Rome EVM 程序
第 1 层：Rome EVM 程序 → 您的 CPI 目标（例如 Jupiter）
第 2 层：Jupiter → 另一个程序（例如 Raydium）
第 3 层：Raydium → SPL Token（最大深度）
```

## Token-2022 转移钩子约束

| 约束                   | 影响                                                |
| -------------------- | ------------------------------------------------- |
| 每个 mint 仅一个钩子        | Token-2022 mint 只有一个 transfer-hook 插槽             |
| `transfer_checked` 仅 | 钩子不会在普通 `transfer`。Rome 桥接操作使用 `transfer_checked` |
| 铸造/销毁不受钩子控制          | 通过 mint 权限控制，而非钩子                                 |

## Gas 和定价约束

| 约束        | 说明                                 |
| --------- | ---------------------------------- |
| Gas 定价来源  | Meteora DAMM 池，v1 或 v2（SPL gas 代币） |
| Gas 价格倍率  | 可按代理配置（`gas_price_mul`)            |
| 最低 gas 价格 | 由代理配置设置                            |
| Gas 估算    | 提交前通过 Mollusk 模拟器在链下执行             |

## 特定网络约束

| 环境           | 链 ID   | rome-evm 程序 ID                                |
| ------------ | ------ | --------------------------------------------- |
| Hadrian（测试网） | 200010 | `RPTWwELXAY4KC9ZPHhaxp7Sq1hHtU3HNEgLbSegCcWf` |
| Rubicon（主网）  | 7531   | `RomePq9X3iAoTr813HR7uRarafFDUJty6GdiEceYpzX` |

## 预编译约束

| 预编译                   | 约束                                                                        |
| --------------------- | ------------------------------------------------------------------------- |
| Modexp（0x05）          | **已禁用** — 调用会回退并返回 `big_mod_exp 调用已禁用` 直到 Solana 启用 `big_mod_exp` syscall |
| BN254 ecPairing（0x08） | 按程序定价，大约需要 22K CU，外加每对 12.8K CU；四对检查可放入一笔原子交易                             |
| CPI 预编译（0xFF...08）    | 账户必须在 Solana 交易中预先声明                                                      |

## 交易验证

| 规则           | 影响                                                                                        |
| ------------ | ----------------------------------------------------------------------------------------- |
| 签名可塑性（EIP-2） | 一笔已签名交易，其 `s` 大于曲线阶一半时将被拒绝                                                                |
| RLP 结构       | 若交易的 RLP 列表在最后一项之后仍包含尾随字节，则会被拒绝                                                           |
| 未实现的操作码      | 中止整笔交易（`IncompatibleVersionEVM(opcode)`）；不会提交任何内容，调用合约也无法吞掉该错误                            |
| Gas 计量       | Rome 没有按操作码划分的 gas 计价表：传递给 `CALL`/`CREATE` 的 gas 不会被强制执行，也没有 2300 gas 预付补贴——不要依赖基于补贴的重入保护 |

## 预言机约束

| 约束              | 值                                           |
| --------------- | ------------------------------------------- |
| 默认最大陈旧时间        | 60 秒                                        |
| 历史轮次数据          | 不支持 — `getRoundData(roundId)` 回退            |
| Switchboard EMA | 不支持 — `latestEMAData()` 在 SwitchboardV3 上回退 |
| 解析器偏移量          | 已通过实证验证——在重新部署前必须重新验证                       |

## 设计建议

1. **保持 CPI 深度较浅。** 设计合约时应尽量减少嵌套。如果您调用 Jupiter，而 Jupiter 再调用 Raydium，Raydium 再调用 SPL Token，那么就已经达到 3 层——距离上限非常接近，存在风险。
2. **优先使用原子模式。** 设计操作时应控制在约 140 万 CU 以内。迭代模式会增加延迟（3–4 秒锁定）、每个会话最多 160 次迭代，并且当钱包自行签署各分段时，Solana 通道上的每个分段都需要一次钱包提示。任何发起传统路径 CPI 的调用都完全不能以迭代方式运行。
3. **预先声明账户。** CPI 触及的所有 Solana 账户必须在交易创建时就已知（代理的模拟会发现它们）。在 CPI 调用中无法动态发现账户，且总数必须符合 64 地址上限。
4. **每个合约只选一种预编译路径。** 调用自定义的 Solana 程序（`invoke_signed`）属于传统路径且仅限原子模式；参见 [集成 Solana 程序](https://docs.rome.builders/zh/kai-fa-zhe-zhi-nan/integrate-solana-program.md).
5. **使用 `transfer_checked`.** 如果您构建的内容会接触 Token-2022 代币，请始终使用 `transfer_checked` 以确保钩子触发。
6. **测试 CU 消耗。** 从交易收据中测量真实的 Solana 计算单元（`computeUnitsConsumed`）— EVM `gasUsed` 不是 Solana CU 的真实代理。对于热点路径，请使用 Yul 优化。

## 下一步

* [计算预算](https://docs.rome.builders/zh/he-xin-gai-nian/compute-budget.md) — 每个操作的详细 CU 成本
* [代币互操作](https://docs.rome.builders/zh/he-xin-gai-nian/token-interop.md) — ERC-20 ↔ SPL 桥接模型
* [预编译参考](https://docs.rome.builders/zh/can-kao/precompiles.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/constraints.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.
