> 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/ko/core-concepts/compute-budget.md).

# 컴퓨트 예산

Rome EVM 작업의 Solana 컴퓨트 유닛(CU) 비용 — 원자적 예산과 반복적 예산, 그리고 CU 효율적인 Solidity 계약을 설계하는 방법.

모든 Solana 트랜잭션에는 Compute Units(CU)로 측정되는 컴퓨트 예산이 있습니다. CU 비용을 이해하면 효율적인 Rome 계약을 설계하는 데 도움이 됩니다.

## 예산 개요

| 모드        | 최대 CU                                 | 참고                                                             |
| --------- | ------------------------------------- | -------------------------------------------------------------- |
| 원자적(VmAt) | \~1,400,000 CU                        | 단일 Solana 트랜잭션                                                 |
| 반복적(VmIt) | 레그당 최대 약 1,400,000 CU; 세션당 최대 160회 반복 | 각 레그는 자체 Solana 트랜잭션이며, 적응형 opcode/step는 각 tx의 CU 예산에 맞춰 패킹됩니다 |

각 Solana 트랜잭션의 기본 예산은 200,000 CU이며, 컴퓨트 예산 지시문( Rome SDK가 자동으로 추가함)을 통해 약 140만 CU까지 확장할 수 있습니다.

반복 실행은 무제한이 아닙니다. 한 세션은 160회 반복 후 종료되며, Rust Rome SDK의 반복 composer는 최대 128개 레그를 계획합니다. 지갑이 직접 서명하는 계획은 `rome_submitSignedV1Plan`한 호출당 최대 64개 트랜잭션만 허용합니다. 대부분의 호출은 훨씬 적게 필요합니다. 반복 세션에서는 legacy-track CPI가 거부되므로, 이를 사용하는 호출은 원자적 예산 안에 들어와야 합니다. 참고 [릴레이된 호출과 긴 호출](https://docs.rome.builders/ko/developer-guides/call-evm-from-solana.md#relayed-calls-and-long-calls) 그리고 [제약 사항](https://docs.rome.builders/ko/core-concepts/constraints.md).

## CU 비용 추정치

### EVM 작업

| 작업                   | 대략적인 CU              | 참고                                                                     |
| -------------------- | -------------------- | ---------------------------------------------------------------------- |
| 트랜잭션 서명 확인(EVM 키 경로) | \~25,000 CU          | 위의 `secp256k1_recover` syscall, 아래와 동일한 비용의 `ecrecover` 아래의 precompile |
| 단순 전송                | \~50,000-100,000 CU  | 잔액 업데이트만                                                               |
| ERC-20 전송            | \~100,000-150,000 CU | SPL precompile 호출 포함                                                   |
| 계약 배포(소형)            | \~200,000-400,000 CU | 바이트코드 크기에 따라 다름                                                        |
| 저장소 쓰기(SSTORE)       | \~5,000-20,000 CU    | 콜드 접근 vs 웜 접근                                                          |

### Precompile 작업

| 사전 컴파일          | 대략적인 CU                      | 참고                                                                                                                                                                                           |
| --------------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ecrecover       | \~25,700 CU                  |                                                                                                                                                                                              |
| SHA-256         | 측정 기준 32바이트 워드당 약 257 CU     | 작은 고정 비용이 추가됩니다. 이 프로그램은 SHA-256, RIPEMD-160 및 identity precompile을 공통으로 사용하는 워드당 약 2,200 CU의 단일 가격 기준으로 책정하며, 세 가지 중 가장 비용이 큰 RIPEMD-160에 맞춰 산정되어 있으므로 SHA-256 호출에는 실제 사용량보다 더 많은 비용이 청구됩니다 |
| BN254 ecAdd     | CU 0에 가깝습니다                  | 32바이트를 복사하는 것보다 저렴함                                                                                                                                                                          |
| BN254 ecMul     | \~4,200 CU                   |                                                                                                                                                                                              |
| BN254 ecPairing | \~22,000 CU + 쌍당 약 12,800 CU | 4쌍 검사는 약 73,000 CU로, 하나의 원자적 트랜잭션 안에 충분히 들어갑니다                                                                                                                                               |

이 수치는 프로그램 자체 보정에서 나온 것으로, 테스트넷 배포에서 Solana 노드로부터 읽어온 compute units를 사용했습니다. 이 페이지를 위해 다시 측정한 값은 아니며, 다음으로 자신의 호출을 측정하십시오 `computeUnitsConsumed`.

## 최적화 기법

### 1. 핫 패스에는 Yul 사용

Solidity의 최적화기는 괜찮은 코드를 생성하지만, Yul(인라인 어셈블리)을 사용하면 중요한 연산의 CU를 크게 줄일 수 있습니다:

```solidity
// Before: ~600K CU
function createPairAccount(bytes32 token0, bytes32 token1) external {
    // Solidity 수준 연산
}

// After: ~150K CU (Yul optimization)
function createPairAccount(bytes32 token0, bytes32 token1) external {
    assembly {
        // 직접 메모리 조작, ABI 인코딩 오버헤드 건너뜀
    }
}
```

### 2. PDA 파생값 캐시

를 통한 PDA 파생은 `find_program_address` 비용이 많이 듭니다. 매 호출마다 계산하지 말고 파생된 PDA를 계약 저장소에 저장하십시오:

```solidity
mapping(address => bytes32) private cachedPdas;

function getPda(address user) internal returns (bytes32) {
    bytes32 cached = cachedPdas[user];
    if (cached != bytes32(0)) return cached;

    bytes32 pda = RomeEVMAccount.pda(user);
    cachedPdas[user] = pda;
    return pda;
}
```

### 3. 알려진 프로그램 ID를 하드코딩

저장소에서 프로그램 ID를 불러오지 말고, 상수를 사용하십시오:

```solidity
// 비용이 큼: 저장소에서 읽음
bytes32 splTokenProgram = storage_program_id;

// 저렴함: 컴파일 시 상수
bytes32 constant SPL_TOKEN_PROGRAM = 0x06ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a9;
```

### 4. 계정 수 최소화

Solana 트랜잭션의 각 계정은 CU 오버헤드를 추가합니다. 다음과 같이 계정 수를 줄이십시오:

* 계정을 공유하는 작업을 일괄 처리
* 중간 계정 수를 줄이기
* 불필요한 ATA 생성 검사를 피하기

### 5. 최적화기 설정 사용

```typescript
// hardhat.config.ts — 빌드 프로필에서 최적화기 활성화
solidity: {
  profiles: {
    default: { version: "0.8.28" },
    production: {
      version: "0.8.28",
      settings: { optimizer: { enabled: true, runs: 200 } },
    },
  },
}
```

다음으로 빌드 `npx hardhat compile --build-profile production`.

## CU 소비 측정

`eth_estimateGas` Rome에서 1 gas unit은 1 lamport의 비용이므로 compute units를 측정하지 않습니다. 이는 가스 한도를 정합니다. EVM 해시 뒤에 있는 Solana 트랜잭션에서 compute를 읽으십시오: 다음으로 서명을 가져오십시오 `rome_solanaTxForEvmTx`를 사용해 각각을 Solana의 `getTransaction` 그리고 `maxSupportedTransactionVersion: 1`로 가져오고, `computeUnitsConsumed`, 또는 탐색기에서 호출을 여십시오. 반복 호출은 레그마다 트랜잭션 하나를 가집니다. 제출하기 전에 가스 한도를 정하려면:

```bash
cast estimate --rpc-url https://hadrian.testnet.romeprotocol.xyz/ \
  0xCONTRACT "myFunction(uint256)" 42
```

또는 ethers.js를 통해:

```javascript
const gas = await contract.myFunction.estimateGas(42);
console.log("Estimated gas:", gas.toString());
```

## 다음은 무엇인가

* [제약 사항](https://docs.rome.builders/ko/core-concepts/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/ko/core-concepts/compute-budget.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.
