Stoffel Secret MPC Programming
Scope: AI-agent-agnostic playbook for building applications with the Stoffel framework. This is not a maintainer guide for compiler, VM, protocol, or release engineering work. Dependency assumption: use the public 0.1.0 install snippets from these docs. When developing against a local checkout, make that source-based workflow explicit.
Use when
Use this playbook when an app handles private values, secret shares, client-provided inputs, MPC output delivery, protocol/runtime metadata, or secure algorithm examples.Goal
Help developers write MPC-oriented Stoffel apps usingsecret types, Share.*, ClientStore.*, Mpc.*, MpcOutput.*, and related builtins, while preserving runnable local examples.
Current source of truth
crates/stoffel-lang/examples/README.mdcrates/stoffel-lang/examples/COVERAGE.mdcrates/stoffel-lang/examples/mpc_*crates/stoffel-lang/examples/bits/secret/*crates/stoffel-lang/examples/matrix/secret/*crates/stoffel-lang/examples/polynomials/secret/*crates/stoffel-lang/examples/number_theory/secret/*crates/stoffel-lang/examples/avss_*crates/stoffel-lang/examples/threshold_signatures/*
Minimal secret app
ClientStore:
ClientStore.take_share(client_slot, input_index) is the client slot. The second is that client’s ordered input index. Repeating --client-input 0=... appends inputs for slot 0 in order.
Secret values and shares
Common patterns:Client input shares
UseClientStore when the app receives private client inputs through the coordinator/client path:
Client outputs
Send share outputs to clients when the runtime advertises that capability:--expected-output-clients N in a first-line # run-args: header. Preserve that flag in local runs; without it, output-capable client slots may not be declared in the local runtime.
Runtime metadata
Useful app metadata:Mpc.party_id()Mpc.n_parties()Mpc.threshold()Mpc.instance_id()Mpc.protocol_name()Mpc.curve()/Mpc.field()Mpc.is_ready()Mpc.has_capability(name)Mpc.capabilities()Mpc.rand()/Mpc.rand_int()
Example families to inspect
MPC primitive examples:mpc_share_arithmeticmpc_boolean_circuitmpc_bitwise_sharempc_random_bitmpc_bit_decompositionmpc_secure_comparisonmpc_select_minmaxmpc_aes128_circuitmpc_client_private_scorempc_client_federated_averagempc_protocol_coordinationmpc_share_toolkit
- Comparison and bit algorithms:
mpc_range_check,mpc_clamp,mpc_compare_family,mpc_is_zero,mpc_popcount_secret,mpc_msb_log2,mpc_lowest_set_bit,mpc_parity,mpc_bit_reverse_rotate,mpc_sign_extend. - Oblivious data access/search:
mpc_oblivious_read,mpc_oblivious_write,mpc_mux_tree,mpc_linear_search,mpc_lookup_table,mpc_pattern_match. - Arithmetic/number theory:
mpc_secure_division,mpc_modulo_secret,mpc_mod_constant,mpc_gcd,mpc_lcm,mpc_reciprocal,mpc_sqrt,mpc_horner_eval,mpc_secret_base_power,mpc_secret_exponentiation,mpc_modexp,mpc_modinv,mpc_transcendental. - Sorting/ranking/arrays:
mpc_bitonic_sort,mpc_secure_shuffle,mpc_top_k,mpc_rank_order.
bits/secret/*: private bit/boolean circuits withClientStoreinputs.matrix/secret/*: private matrix/vector and fixed-point examples.polynomials/secret/*: polynomial, interpolation, coding, and private matching examples.number_theory/secret/*: private GCD, modular inverse, CRT, MAC, equality, and Diophantine examples.
avss_share_auditoravss_certificate/*threshold_signatures/*
Validation / done criteria
For a secret app source change:# run-args: header, use the exact flags from that header. Example:
Common pitfalls
- Do not use clear function arguments when the program expects
ClientStoreinputs. - Do not reorder repeated
--client-inputvalues for the same slot; order is the per-client input index. - Do not omit
--expected-output-clientsfor programs that callMpcOutput.send_to_clientorShare.send_to_client. - Do not reveal intermediate private values in examples unless the algorithm intentionally opens that result.
- Do not claim protocol behavior from static compilation alone; run local MPC or report the blocker.