AddTogetherOutput are automatically generated from encrypted instructions.
The basics
Let’s say we have the following encrypted instruction and want to invoke it from our MXE.InputValues which contains two encrypted u8s, then build the computation arguments using ArgBuilder, and finally queue the computation for execution. Additionally, we need to define a callback instruction that will be invoked when the computation is complete. Callback instructions have a few requirements:
- They must be defined with the
#[arcium_callback(encrypted_ix = "encrypted_ix_name")]macro. - They must have exactly two arguments:
ctx: Context<...>andoutput: SignedComputationOutputs<T>whereTis named as{encrypted_ix_name}Output.
ArgBuilder API. If the corresponding argument is Enc<Shared, T>, then we need to pass the x25519_pubkey(pub_key) and plaintext_u128(nonce), before the ciphertext. If the corresponding argument is Enc<Mxe, T>, then we only need to pass the nonce as plaintext_u128(nonce) and the ciphertext. Ciphertexts are passed using methods like encrypted_u8, encrypted_u16, encrypted_u32, encrypted_u64, encrypted_u128, or encrypted_bool.
Accounts structs for each of these instructions:
mxe_account: Your MXE’s metadata and configurationmempool_account: Queue where computations wait to be processedexecuting_pool: Tracks computations currently being executedcomputation_account: Stores individual computation data and resultscomp_def_account: Definition of your encrypted instruction (circuit)
cluster_account: The MPC cluster that will process your computationpool_account: Arcium’s fee collection accountclock_account: Network timing information
payer: Pays transaction fees and rentsign_pda_account: PDA signer for the computationsystem_program: Solana’s system program for account creationarcium_program: Arcium’s core program that orchestrates MPC
COMP_DEF_OFFSET_ADD_TOGETHERto match your instruction name- The instruction name in the
queue_computation_accountsmacro
AddTogether struct, we need to change the parameter for the derive_comp_def_pda macro and in the callback_accounts macro depending on the encrypted instruction we’re invoking.
The callback_ix() method is a convenient helper generated by the #[callback_accounts] macro that automatically creates the proper callback instruction with all required accounts.
To return more than a raw value, check out input/outputs for how to handle encrypted data and callback accounts for returning additional accounts in the callback.
What’s next?
Callback Accounts
Pass additional accounts to your callback for storing results.
JavaScript Client
Encrypt inputs and invoke computations from TypeScript.
Deployment
Deploy your MXE to Solana devnet.
Design Constraints
Output size limits and language constraints to keep in mind.