Why Computation Definitions Exist
When you write an encrypted instruction using Arcis, it gets compiled into an MPC circuit - essentially a program that the MPC nodes can execute securely on encrypted data. But here’s the challenge: how do the MPC nodes know what circuit to run when your Solana program calls for a computation? That’s where Computation Definition Accounts come in. They serve as the bridge between your Solana program and the MPC network, storing both the circuit itself and metadata about how to execute it. Think of it as uploading your encrypted instruction to the blockchain so the MPC nodes can access it when needed.Computation Definition Accounts
When we define an encrypted instruction using Arcis, we need the MPC cluster that will execute this confidential instruction to have access to the confidential instruction itself, its interface, and some more metadata. This is done by defining aComputationDefinitionAccount
struct, which consists of two parts:
- The confidential instruction metadata and interface.
- The raw MPC bytecode.
b"ComputationDefinitionAccount", mxe_program_id, comp_def_offset
. The first is exported as a constant by the Arcium Anchor SDK, the second is just the program id of our MXE program, and the third is a confidential-instruction-specific offset. It is computed with comp_def_offset = sha256(<confidential_instruction_name>).slice(0,4)
and then interpreted as a little-endian u32. Theoretically, you shouldn’t need to know this, but it’s good to know what’s going on under the hood. We abstract this with derive_comp_def_pda
macro which takes in the comp_def_offset
as a parameter, and computes the ComputationDefinitionAccount
address for you.
The MPC bytecode is stored inside account(s) with the seeds b"ComputationDefinitionRaw", comp_def_acc, i
. Like above, the first is exported as a constant by the Arcium Anchor SDK, the second is the computation definition account we defined above, and the third is an index starting from 0 up to however many accounts we need to store the full MPC bytecode.
Usage
When working locally, you theoretically don’t need to care about the MPC bytecode accounts, as the Arcium CLI will handle the creation and management of these accounts for you. You do however need to create the interface ComputationDefinitionAccount, which can easily be done with the Arcium Anchor tooling. Let’s say we want to deploy a confidential instruction calledadd_together
: