Arcium 백서

Arcium

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 17쪽 중 7쪽

nfigure the inputs | Input | Required | Default | Notes | | -------------------- | -------- | --------- | ----------------------------------------------------------------------------------------- | | `runner-arch-os` | yes | None | Use `x86_64_linux` for `ubuntu-latest` or `aarch64_macos` for Apple Silicon macOS runners | | `arcium-version` | no | `0.15.0` | Match the Arcium dependencies in your project | | `anchor-version` | no | `1.0.2` | Match the version your project pins | | `solana-cli-version` | no | `3.1.10` | Use Solana CLI 2.x or newer | | `node-version` | no | `24.10.0` | Match your project's Node.js version | ## Raise the Linux file limit `arcium test` starts validator and node processes that can exhaust the default open-file limit on Linux runners. The workflow raises the limit with `prlimit` in the test step. GitHub Actions starts a new shell for each step, so running `prlimit` in an earlier step does not affect the test process. ## What's next? <CardGroup> <Card title="Deployment" icon="rocket" href="/developers/deployment"> Deploy your MXE to devnet or mainnet after CI passes. </Card> <Card title="Installation" icon="download" href="/developers/installation"> Local-machine setup for the same toolchain. </Card> </CardGroup> # Core concepts Source: https://docs.arcium.com/developers/core-concepts Key terminology for Arcium development: MXE, Clusters, Encrypted Instructions, Computation Definitions, offsets, and how they connect Key terms you'll encounter throughout Arcium development. <CardGroup> <Card title="MXE (MPC eXecution Environment)" href="/multi-party-execution-environments-mxes/overview"> Your complete encrypted application composed of three parts: * A **Solana program** that receives inputs and queues computations * **Encrypted instructions** with encrypted logic written in Arcis * An **MXE account** storing onchain metadata like cluster selection and the MXE's public key When no longer needed, MXE accounts can be closed through the [account lifecycle](/developers/program/account-lifecycle). </Card> <Card title="Cluster" href="/clusters/overview"> A group of Multi-Party Computation (MPC) nodes that execute your encrypted instructions. You choose which cluster when deploying your MXE. The selection is made at deployment time but can be changed later via [`arcium migrate-cluster`](/developers/deployment#cluster-migration). Each cluster has a numeric `cluster_offset` identifier (e.g., `456` on devnet) that you specify during [deployment](/developers/deployment). </Card> <Card title="Encrypted instruction" href="/developers/arcis"> Your encrypted business logic written in **Arcis** (Rust framework) that executes on encrypted data via MPC. Mark functions with the `#[instruction]` macro to designate them as encrypted instructions. Examples: vote counting, order matching, sealed-bid auctions. </Card> <Card title="Arcium program" href="/developers/program"> The onchain coordinator on Solana that orchestrates MPC computations, routes work to clusters, and manages callbacks and finalization. You interact with it via **CPI** (Cross-Program Invocation) from your Solana program. </Card> <Card title="Computation definition" href="/developers/program/computation-def-accs"> An onchain account storing compiled MPC bytecode. Created once per encrypted instruction, it contains the compiled circuit from your Arcis code and must be initialized via `init_computation_def()` before first use. When no longer needed, a computation definition has its own [close lifecycle](/developers/program/account-lifecycle). </Card> <Card title="Computation" href="/developers/computation-lifecycle"> A single execution instance of an encrypted instruction. You generate a random `computation_offset` (u64) per invocation to uniquely identify it. The computation tracks execution status and stores encrypted results until callback. </Card> <Card title="Arx node" href="/arx-nodes/overview"> An MPC execution node that participates in cluster computations. Each node holds secret shares and collaborates via the MPC protocol. Clusters contain multiple Arx nodes. The dishonest majority model means privacy holds even if all but one node are compromised. </Card> </CardGroup> <Frame> ```mermaid theme={null} graph TD A[MXE Program] -->|queues computation| B[Arcium Program] A -->|references| C[MXE Account] B -->|routes to| D[Cluster] D -->|executes| E[Encrypted Instructions] D -->|returns result via callback| A ``` </Frame> ## Offset identifiers Arcium uses numeric offsets to identify onchain resources. You'll encounter these throughout the SDK: | Offset | Type | Purpose | How it's set | | -------------------- | ----- | ------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | | `cluster_offset` | `u32` | Identifies which cluster your MXE connects to | Chosen at [deployment](/developers/deployment) (e.g., `456` on devnet) | | `computation_offset` | `u64` | Uniquely identifies a single computation invocation | Generated randomly per invocation (`randomBytes(8)`) | | `comp_def_offset` | `u32` | Identifies a computation definition (circuit) within your MXE | Via `comp_def_offset("instruction_name")`, which computes `sha256(name)` truncated to LE u32 | ## What's next? <CardGroup> <Card title="Computation Lifecycle" icon="rotate" href="/developers/computation-lifecycle"> Understand how computations flow from queue to callback </Card> <Card title="Write Encrypted Instructions" icon="code" href="/developers/arcis"> Learn Arcis and write encrypted business logic </Card> </CardGroup> # Deployment Source: https://docs.arcium.com/developers/deployment Deploy your MXE to Solana with cluster configuration and RPC setup ## Getting started with deployment Deploy after `arcium build` and `arcium test` pass locally. Use the [continuous integration guide](/developers/continuous-integration) to run both checks on each change. This guide covers program preparation, cluster offsets, RPC setup, migration, and closing accounts. <Note> This guide walks you through deploying to **devnet** first. Once you've validated your MXE on devnet, see [Deploying to Mainnet](#deploying-to-mainnet) for mainnet-specific configuration. </Note> ## What you'll need Before deploying, make sure you have: * Your MXE built successfully with `arcium build` * Tests passing locally with `arcium test` * A Solana keypair with around 2-5 SOL for deployment costs (program deployment and account initialization) * Access to a reliable RPC endpoint <Warning> **RPC reliability is critical for deployment.** Default Solana RPC endpoints can be unreliable and drop transactions, causing deployment failures. Get an API key from [Helius](https://helius.dev), [Triton](https://triton.one), or [QuickNode](https://quicknode.com) before attempting deployment. </Warning> ## Preparing your program Before deploying, decide how your program stores computation definitions. ### Handling large circuits with offchain storage Arcis compiled circuits can be several MB. Uploading the full bytecode onchain can require many transactions and high rent. For larger circuits, upload the compiled `.arcis` file to public storage and initialize the computation definition with its URL and hash. **Standard approach (works for small circuits):** ```rust theme={null} pub fn init_add_together_comp_def(ctx: Context<InitAddTogetherCompDef>) -> Result<()> { // This initializes the computation definition account init_computation_def(ctx.accounts, None)?; Ok(()) } ``` **Offchain approach (recommended for larger circuits):** ```rust theme={null} // First, import the types you'll need use arcium_client::idl::arcium::types::{CircuitSource, OffChainCircuitSource}; use arcium_macros::circuit_hash; pub fn init_add_together_comp_def(ctx: Context<InitAddTogetherCompDef>) -> Result<()> { // Point to your uploaded circuit file init_computation_def( ctx.accounts, Some(CircuitSource::OffChain(OffChainCircuitSource { source: "https://your-storage.com/path/to/add_together.arcis".to_string(), hash: circuit_hash!("add_together"), })), )?; Ok(()) } ``` <Note> The `circuit_hash!` macro embeds the SHA-256 hash of your compiled circuit at compile time. The hash is read from `build/{circuit_name}.hash`, which is generated automatically during `arcium build`. Arx nodes verify this hash when fetching your circuit to ensure the circuit hasn't been tampered with. **Important:** Always use `circuit_hash!` for offchain circuits. Don't use a placeholder like `[0u8; 32]` - this will cause verification to fail on Arx nodes. </Note> Offchain circuit flow: 1. Build your project with `arcium build` to generate the circuit files and hashes 2. Upload the `.arcis` files from `build/` folder to your preferred storage service 3. Update your init functions with the public URLs and `circuit_hash!` macro calls Circuit files must be publicly readable without authentication. ### Note on cluster configuration When testing locally, you've been using `arciumEnv.arciumClusterOffset` with `getClusterAccAddress()` in your test code. For devnet deployment, you'll use the same pattern with your chosen cluster offset - we'll show you exactly how in the post-deployment section. ## Basic deployment The `arcium deploy` command handles both deploying your program and initializing the MXE account. Here's the basic command structure: ```bash theme={null} arcium deploy --cluster-offset <cluster-offset> --recovery-set-size <size> --keypair-path <path-to-your-keypair> --rpc-url <your-rpc-url> ``` <Warning> For a fresh MXE initialization, `--keypair-path` must point to the deployed program's current upgrade authority, including when you use `--skip-deploy`. An immutable program has no upgrade authority and can never initialize a fresh MXE. Deploy a new program that retains its upgrade authority instead. </Warning> Let's break down what each parameter does: ### Understanding cluster offsets The `--cluster-offset` tells your MXE which Arcium cluster it should connect to. Think of clusters as groups of nodes that will perform your encrypted computations. Available offsets: **Devnet cluster:** * `456` **Mainnet cluster:** * `2026` ### Recovery set size The `--recovery-set-size` parameter specifies how many nodes form the recovery set that holds encrypted key shares of your MXE's key. This enables key reconstruction when needed, whether due to node failure or cluster migration. This is required. The absolute minimum is `4`; larger clusters may require a larger recovery set, and the CLI prints the required value if the one you pass is too small. ### Choosing your RPC provider Always pass `--rpc-url <your-rpc-url>`. Solana's default RPC endpoints (`-u d`, `-u m`) can drop transactions during deployment. **Recommended approach with a reliable RPC:** ```bash theme={null} arcium deploy --cluster-offset 456 \ --recovery-set-size 4 \ --keypair-path ~/.config/solana/id.json \ --rpc-url <your-devnet-rpc-url> ``` **If you must use the default RPC:** ```bash theme={null} arcium deploy --cluster-offset 456 \ --recovery-set-size 4 \ --keypair-path ~/.config/solana/id.json \ -u d # 'd' for devnet, 'm' for mainnet, 'l' for localnet ``` Just be prepared for potential transaction failures with the default RPC. ## Advanced deployment options Once you're comfortable with basic deployment, you might want to customize things further. ### Using a custom program address If you need your program at a specific address (maybe for consistency across deployments), you can provide a program keypair: ```bash theme={null} arcium deploy --cluster-offset 456 \ --recovery-set-size 4 \ --keypair-path ~/.config/solana/id.json \ --rpc-url <your-rpc-url> \ --program-keypair ./program-keypair.json ``` ### Partial deployments Sometimes you might need to run just part of the deployment process. For instance, if you've already deployed the program but need to reinitialize the MXE account: ```bash theme={null} # Skip program deployment, only initialize MXE account arcium deploy --cluster-offset 456 \ --recovery-set-size 4 \ --keypair-path ~/.config/solana/id.json \ --rpc-url <your-rpc-url> \ --skip-deploy ``` Or if you only want to deploy the program without initialization: ```bash theme={null} # Deploy program only, skip MXE initialization arcium deploy --cluster-offset 456 \ --recovery-set-size 4 \ --keypair-path ~/.config/solana/id.json \ --rpc-url <your-rpc-url> \ --skip-init ``` ## After deployment ### Initialize your computation definitions Your MXE is deployed, but you still need to initialize the computation definitions. This tells the Arcium Network what encrypted operations your MXE can perform. Computation definitions only need to be initialized once - they persist onchain and don't need to be re-initialized unless you're deploying to a new program address. You can initialize them anytime after deployment completes successfully. Remember how we mentioned you'd need to update your cluster configuration? Now's the time! You'll need to update your test or client code to derive the cluster account (and the related PDAs) from the cluster offset you selected during deployment. **Local testing pattern:** ```typescript theme={null} const arciumEnv = getArciumEnv(); // In your transaction... .accountsPartial({ computationAccount: getComputationAccAddress( arciumEnv.arciumClusterOffset, computationOffset ), clusterAccount: getClusterAccAddress(arciumEnv.arciumClusterOffset), mxeAccount: getMXEAccAddress(program.programId), mempoolAccount: getMempoolAccAddress(arciumEnv.arciumClusterOffset), executingPool: getExecutingPoolAccAddress(arciumEnv.arciumClusterOffset), // ... other accounts }) ``` **For devnet deployment:** ```typescript theme={null} // Use the cluster offset from your deployment (e.g., 456) const clusterOffset = 456; // In your transaction... .accountsPartial({ computationAccount: getComputationAccAddress(clusterOffset, computationOffset), clusterAccount: getClusterAccAddress(clusterOffset), mxeAccount: getMXEAccAddress(program.programId), mempoolAccount: getMempoolAccAddress(clusterOffset), executingPool: getExecutingPoolAccAddress(clusterOffset), // ... other accounts }) ``` Make sure to use the same `cluster_offset` value that you used during deployment! This ensures your program talks to the right cluster. Once you've updated the cluster configuration, you can run the initialization: ```typescript theme={null} // Now with the correct cluster configured await initAddTogetherCompDef(program, owner); ``` ### Verify everything's working Let's make sure your deployment succeeded: ```bash theme={null} solana program show <your-program-id> --url <your-rpc-url> ``` To run your tests against the deployed program, configure the cluster offset in your `Arcium.toml`: ```toml theme={null} [clusters.devnet] offset = <your-cluster-offset> ``` Then run: ```bash theme={null} arcium test --cluster devnet ``` The CLI reads the cluster offset from `Arcium.toml` and configures the test environment automatically. For RPC configuration, set the cluster and wallet in your `Anchor.toml`: ```toml theme={null} [provider] cluster = "devnet" wallet = "~/.config/solana/id.json" ``` ## Deploying to mainnet Once you've validated your MXE on devnet, you can deploy to Arcium mainnet. The deployment process is the same, with a few key differences: ### Mainnet cluster offset Use the mainnet cluster offset from the [Understanding Cluster Offsets](#understanding-cluster-offsets) section: ```bash theme={null} arcium deploy --cluster-offset <mainnet-cluster-offset> \ --recovery-set-size 4 \ --keypair-path ~/.config/solana/id.json \ --rpc-url <your-mainnet-rpc-url> ``` ### Mainnet configuration Configure the mainnet cluster offset in your `Arcium.toml` (see [Understanding Cluster Offsets](#understanding-cluster-offsets) for the current value): ```toml theme={null} [clusters.mainnet] offset = <your-cluster-offset> ``` To test against your mainnet deployment: ```bash theme={null} arcium test --cluster mainnet ``` <Warning> Mainnet deployments require real SOL. There are no airdrops. Ensure your wallet is funded before deploying. </Warning> ## Common issues and solutions <Note> The examples below use devnet. For mainnet, replace `-u d` with `-u m` and use a mainnet RPC URL. </Note> ### Dealing with dropped transactions If your deployment fails with transaction errors, it's almost always the RPC. Switch to a dedicated provider: ```bash theme={null} # Instead of this (unreliable): arcium deploy --cluster-offset 456 \ --recovery-set-size <recovery-set-size> \ --keypair-path ~/.config/solana/id.json \ -u d # Use this (reliable): arcium deploy --cluster-offset 456 \ --recovery-set-size <recovery-set-size> \ --keypair-path ~/.config/solana/id.json \ --rpc-url <your-devnet-rpc-url> ``` ### Running out of SOL Check your balance before deploying: ```bash theme={null} solana balance <your-keypair-pubkey> -u devnet ``` If you need more SOL on devnet, request it via airdrop: ```bash theme={null} solana airdrop 2 <your-keypair-pubkey> -u devnet ``` ### Deployment partially failed? If your deployment was interrupted (e.g., due to a dropped transaction or network issue), use the `--resume` flag to pick up where it left off: ```bash theme={null} arcium deploy --cluster-offset 456 \ --recovery-set-size 4 \ --keypair-path ~/.config/solana/id.json \ --rpc-url <your-rpc-url> \ --resume ``` This skips already-completed steps and retries from the point of failure. The `--resume` flag is also available on `init-mxe` and `migrate-cluster` for the same purpose. For finer control, you can also skip specific phases: `--skip-deploy` (skip program deployment, only initialize MXE) or `--skip-init` (deploy program only, skip MXE initialization). ## Managing your MXE ### Cluster migration If you need to move your MXE from one cluster to another, use the `migrate-cluster` command: ```bash theme={null} arcium migrate-cluster <mxe-program-id> \ --keypair-path <path-to-your-keypair> \ --cluster-offset <new-cluster-offset> \ --rpc-url <your-rpc-url> ``` This reconstructs your MXE's keys on the new cluster using the recovery set configured during deployment. Your MXE will be temporarily unavailable during migration. <Note> MXEs deployed with v0.9.x already have the recovery material needed for `migrate-cluster`; no separate remediation command is required before migrating them. </Note> If a migration is interrupted, resume it with `--resume`: ```bash theme={null} arcium migrate-cluster <mxe-program-id> \ --keypair-path <path-to-your-keypair> \ --rpc-url <your-rpc-url> \ --resume ``` To abort an in-progress migration: ```bash theme={null} arcium migrate-cluster <mxe-program-id> \ --keypair-path <path-to-your-keypair> \ --rpc-url <your-rpc-url> \ --abort ``` With `--resume`/`--abort` the CLI infers the cluster offset from onchain state; `--cluster-offset` is required only on the initial call. <Warning> Do not abort and then re-initialize a migration back to the same target cluster. That opens a denial-of-service surface. If you need to retry, resume instead. </Warning> ### Transferring MXE authority Hand an MXE to a new authority, such as a multisig vault, with `arcium set-mxe-authority`. The transaction must be signed by the **current** MXE authority. ```bash theme={null} arcium set-mxe-authority <mxe-program-id> \ -k <current-authority-keypair> \ -a <new-authority-pubkey> \ --rpc-url <url> ``` <Warning> The transfer takes effect immediately and only the new authority can transfer it back. Verify the new authority pubkey before running this, and confirm the new signer works before retiring the old one. </Warning> ### Closing an MXE
프로젝트로 돌아가기