> 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 交易限制

| 约束                | 值         | 影响                         |
| ----------------- | --------- | -------------------------- |
| 交易大小              | 1,232 字节  | 较大的 EVM 交易会拆分到持有者账户中（透明处理） |
| 每笔交易的计算单元         | 约 1.4M CU | 超过此限制的操作将使用迭代模式            |
| 每笔交易的账户数（不使用 ALT） | 28        | 如需更多，请使用地址查找表              |
| 每笔交易的账户数（使用 ALT）  | 64+       | 当账户数 > 28 时自动使用 ALT        |
| 最大持有者大小           | 80 KB     | 单笔 EVM 交易的最大 RLP 大小        |

## EVM 执行限制

| 约束       | 值            | 说明                           |
| -------- | ------------ | ---------------------------- |
| 合约存储槽    | 每个存储账户 256 个 | 每个合约可创建多个存储账户                |
| 每次迭代的操作码 | 自适应          | 按每笔 Solana 交易的 CU 预算打包（VmIt） |
| 账户锁定 TTL | 3-4 秒        | 在迭代执行期间                      |
| 国库钱包     | 64           | 费用池钱包                        |
| 合约大小限制   | 24 KB        | 与以太坊相同（EIP-170，24,576 字节）    |

## CPI 约束

| 约束            | 值               | 说明                      |
| ------------- | --------------- | ----------------------- |
| CPI 深度        | 最多 4 层          | Solana 的 CPI 深度限制       |
| 每次 CPI 调用的账户数 | 受 Solana 交易大小限制 | 实际上每次 CPI 约可容纳 20 个账户   |
| CPI + 转账钩子深度  | 会使用 CPI 层级      | 来自 CPI 内部的转账钩子可能会超出深度限制 |

**CPI 深度是最关键的约束。** 当 Solana 调用 Rome 程序时，Rome EVM 会消耗 1 个 CPI 层级。如果你的 Solidity 合约随后通过 CPI 调用另一个 Solana 程序，那就是第 2 层。如果该程序再调用另一个程序，那就是第 3 层。你总共最多只有 4 层。

```
第 0 层：Solana 运行时 → 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` |
| 铸造/销毁不受钩子影响          | 通过铸币权限控制，而非通过钩子                                     |

## Gas 和定价约束

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

## 特定网络约束

| 环境               | 链 ID   | rome-evm 程序 ID                                |
| ---------------- | ------ | --------------------------------------------- |
| 本地               | 1001   | 本地开发栈                                         |
| Hadrian（devnet）  | 200010 | `RPTWwELXAY4KC9ZPHhaxp7Sq1hHtU3HNEgLbSegCcWf` |
| Martius（testnet） | 121214 | `RomeTaTNPJNBxtB3Wong9geVTtkEFJfUqgktQVq3iSX` |

## 预编译约束

| 预编译                    | 约束                           |
| ---------------------- | ---------------------------- |
| Modexp (0x05)          | **已禁用** — 可通过功能标志启用          |
| BN254 ecPairing (0x08) | CU 成本很高——通常需要迭代模式（约 200K CU） |
| CPI 预编译 (0xFF...08)    | 必须在 Solana 交易中预先声明账户         |

## 预言机约束

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

## 设计建议

1. **保持 CPI 深度较浅。** 设计合约时应尽量减少嵌套。如果你调用 Jupiter，Jupiter 再调用 Raydium，而 Raydium 再调用 SPL Token，那么你已经达到了 3 层——距离限制非常危险。
2. **优先使用原子模式。** 将操作设计在约 1.4M CU 以内。迭代模式会增加延迟（3-4 秒锁定）和复杂性。
3. **提前声明账户。** CPI 涉及的所有 Solana 账户都必须在交易创建时已知。无法在 CPI 调用内动态发现账户。
4. **使用 `transfer_checked`.** 如果你构建的任何内容会接触 Token-2022 代币，请始终使用 `transfer_checked` 以确保钩子触发。
5. **测试 CU 消耗。** 从交易回执中测量真实的 Solana 计算单元（`computeUnitsConsumed`）— EVM `gasUsed` 并不能真实反映 Solana CU。对热点路径使用 Yul 进行优化。

## 下一步

* [计算预算](/zh/he-xin-gai-nian/compute-budget.md) — 每个操作的详细 CU 成本
* [代币互操作](/zh/he-xin-gai-nian/token-interop.md) — ERC-20 ↔ SPL 桥接模型


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
