Skip to main content

Why computation definitions exist

When you write an encrypted instruction with Arcis, it compiles into an MPC circuit: a program that MPC nodes can execute securely on encrypted data. Computation definitions tell the nodes which circuit to run when your Solana program queues a computation. Computation Definition Accounts bridge your Solana program and the MPC network. They store the circuit metadata and, for onchain circuit sources, the circuit bytecode needed for execution.

Computation definition accounts

When you define an encrypted instruction using Arcis, the MPC cluster that executes it needs access to the instruction interface, metadata, and circuit source. A ComputationDefinitionAccount contains two parts:
  1. The encrypted instruction metadata and interface.
  2. The circuit source. For onchain sources, this references separate accounts that hold the raw MPC bytecode.
The interface stores expected inputs, outputs, required accounts, and execution metadata. This data lives in an account with the seeds b"ComputationDefinitionAccount", mxe_program_id, comp_def_offset. The first seed is exported by the Arcium Anchor SDK, the second is your MXE program ID, and the third is an encrypted-instruction-specific offset. comp_def_offset is sha256(<encrypted_instruction_name>).slice(0,4) interpreted as a little-endian u32. The derive_comp_def_pda! macro computes the ComputationDefinitionAccount address for you. For onchain circuit sources, the MPC bytecode is stored in accounts with the seeds b"ComputationDefinitionRaw", comp_def_acc, i. The first seed is exported by the Arcium Anchor SDK, the second is the computation definition account, and the third is an index from 0 through the number of accounts needed to store the full bytecode.

Usage

When working locally, the Arcium CLI creates and manages MPC bytecode accounts for you. You still need to create the interface ComputationDefinitionAccount, which the Arcium Anchor tooling handles. For an encrypted instruction called add_together, define:
pub fn init_add_together_comp_def(ctx: Context<InitAddTogetherCompDef>) -> Result<()> {
    init_computation_def(ctx.accounts, None)?;
    Ok(())
}

#[init_computation_definition_accounts("add_together", payer)]
#[derive(Accounts)]
pub struct InitAddTogetherCompDef<'info> {
    #[account(mut)]
    pub payer: Signer<'info>,
    #[account(
        mut,
        address = derive_mxe_pda!()
    )]
    pub mxe_account: Box<Account<'info, MXEAccount>>,
    #[account(mut)]
    /// CHECK: comp_def_account, checked by arcium program.
    pub comp_def_account: UncheckedAccount<'info>,
    #[account(mut, address = derive_mxe_lut_pda!(mxe_account.lut_offset_slot))]
    /// CHECK: address_lookup_table, checked by arcium program.
    pub address_lookup_table: UncheckedAccount<'info>,
    #[account(address = LUT_PROGRAM_ID)]
    /// CHECK: lut_program is the Address Lookup Table program.
    pub lut_program: UncheckedAccount<'info>,
    pub arcium_program: Program<'info, Arcium>,
    pub system_program: Program<'info, System>,
}
Call this instruction once before using the encrypted instruction. When you no longer need the computation definition, follow the account lifecycle to deactivate and close it.

Offchain circuit sources

For larger circuits, you can store the compiled circuit offchain and pass an OffChainCircuitSource as the second argument to init_computation_def:
use arcium_client::idl::arcium::types::{CircuitSource, OffChainCircuitSource};
use arcium_macros::circuit_hash;

pub fn init_add_together_comp_def(ctx: Context<InitAddTogetherCompDef>) -> Result<()> {
    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(())
}
The circuit_hash! macro embeds the SHA-256 hash from build/{circuit_name}.hash at compile time; Arx nodes verify it when fetching the circuit. For the full offchain workflow, see Deployment.