// Multiple separate encryptions have overheadlet enc_a = owner.from_arcis(x);let enc_b = owner.from_arcis(y);// If you need both values encrypted together, use a tuple typelet enc_tuple: Enc<Shared, (u64, u64)> = owner.from_arcis((x, y));// ✗ Won't compile - Enc<T> wraps the entire value,// so destructuring patterns don't work on Enc types// let (enc_a, enc_b) = owner.from_arcis((x, y));
Reuse comparison results:
Copy
Ask AI
// ✗ Redundant - same comparison computed twiceif x > 1000 { do_something();}if x > 1000 { // Expensive comparison done AGAIN do_another_thing();}// ✓ Compute once, reuse the resultlet is_large = x > 1000;if is_large { do_something();}if is_large { // Reuses the boolean, no recomputation do_another_thing();}
Prefer public constants over secret-dependent values:
Copy
Ask AI
// ✓ Constant multiplier - compiler can optimizefn double(x: u64) -> u64 { x * 2 // Multiplication by constant is efficient}// ✓ Pass known values as public inputsfn apply_rate(amount: u64, rate_percent: u64) -> u64 { // If rate is known ahead of time, pass it as a public input // rather than computing it inside the secure computation amount * rate_percent / 100}
In MPC, values known before the computation (public inputs and constants) can be handled more efficiently than values computed during secure execution.
Use assertions to verify invariants during development:
Copy
Ask AI
#[instruction]fn with_assertions(x: u32, y: u32) -> u32 { debug_assert!(x > 0, "x must be positive"); debug_assert_eq!(x, x, "sanity check"); debug_assert_ne!(x, y, "x and y should differ"); x + y}
debug_assert macros are for development verification only. They do not enforce constraints in production—use explicit conditionals for actual validation logic.
#[instruction] functions cannot be unit-tested in isolation—they require the full MPC runtime. For end-to-end testing, use the TypeScript SDK to invoke deployed circuits on a test cluster.See the JavaScript Client documentation and the Hello World tutorial for integration testing setup.
When a condition is not a compile-time constant, both branches execute. The condition selects which result to keep, but ARX nodes perform work for both paths.See Thinking in MPC for the full explanation.
Copy
Ask AI
// Problematic: assumes the indexing won't happen when found_match is falseif found_match { data[secret_idx] = new_value; // Executes regardless of found_match}// Safe: constant-index loop with conditional assignmentfor i in 0..DATA_SIZE { let should_update = found_match && (i == secret_idx); if should_update { data[i] = new_value; }}