Secure Multi-Party Computation for ML
Computing a joint result without sharing inputs
Imagine two hospitals that want to jointly train a model on their combined patient data, but neither is legally or ethically permitted to share raw patient records with the other. Secure multi-party computation (MPC) solves exactly this class of problem: it allows several parties, each holding private input, to jointly compute an agreed-upon function of their combined inputs such that no party learns anything about the others' inputs beyond what the output itself necessarily reveals. Unlike homomorphic encryption (one party computes on another's encrypted data), MPC is fundamentally about multiple mutually distrusting parties computing together.
Secret sharing: the core building block
The most common MPC construction technique is secret sharing: a party splits its private value into multiple random-looking 'shares,' distributed among the computing parties, such that no individual share (or any subset below a threshold) reveals anything about the original value, but combining enough shares reconstructs it exactly. Computations (addition, multiplication) can be performed directly on the shares, producing shares of the *result* without ever reconstructing any intermediate private value. Shamir's Secret Sharing is the classic scheme: a secret is encoded as a point on a polynomial, and any $k$ of $n$ shares reconstruct it via polynomial interpolation, while fewer than $k$ shares reveal nothing.
import random
MODULUS = 2**31 - 1 # a large prime, for modular arithmetic
def split_secret(value: int, n_parties: int) -> list[int]:
"""Additive secret sharing: shares sum to the original value mod MODULUS."""
shares = [random.randrange(MODULUS) for _ in range(n_parties - 1)]
last_share = (value - sum(shares)) % MODULUS
shares.append(last_share)
return shares # no individual share reveals 'value'
def reconstruct(shares: list[int]) -> int:
return sum(shares) % MODULUS
def add_shares(shares_a: list[int], shares_b: list[int]) -> list[int]:
"""Addition on shared secrets, with NO party ever seeing the plaintext inputs."""
return [(a + b) % MODULUS for a, b in zip(shares_a, shares_b)]
secret_x = split_secret(42, n_parties=3)
secret_y = split_secret(17, n_parties=3)
result_shares = add_shares(secret_x, secret_y)
print(reconstruct(result_shares)) # 59, with no party ever learning 42 or 17 individuallyMPC protocol approaches
| Approach | Mechanism | Typical trade-off |
|---|---|---|
| Secret sharing (e.g. Shamir) | Split values into shares, compute on shares | Efficient for addition; multiplication needs extra communication rounds |
| Garbled circuits | Represent computation as an encrypted boolean circuit | Good for arbitrary functions; circuit size can be large |
| Oblivious transfer | Receiver gets one of several values without sender knowing which | Core primitive used inside other MPC protocols |
MPC for ML is mostly about the training or inference step, not storage
Communication cost: the main practical bottleneck
Unlike a single party running local computation, MPC protocols require multiple rounds of communication between parties for most operations beyond simple addition — multiplication in secret-sharing-based MPC, for instance, typically requires parties to exchange intermediate values to avoid introducing correlated randomness that could leak information. This communication overhead, not raw computation, is usually the dominant cost of MPC at scale, and it grows with network latency between parties — making MPC considerably more practical when the participating parties have reasonably fast, reliable connections to each other, and considerably harder when they're geographically distributed with high latency links.
Real deployments
MPC has moved from purely academic to real production use in specific niches: private set intersection (two parties discovering which records they have in common without revealing the rest of their datasets) is used in advertising measurement and contact-discovery features; joint fraud-detection consortiums among banks use MPC to compare signals without sharing customer data directly; and secure aggregation is a standard component in several federated learning frameworks, including deployments used for mobile keyboard prediction. It remains most viable for a small, fixed number of parties — protocols with dozens or more participants face steep communication overhead that limits practical scale.
What's Next?
MPC and homomorphic encryption both defend against a cooperative but curious computing party; a different and more adversarial threat model asks what happens when an attacker actively tries to extract a trained model's parameters or training data through its outputs alone — the subject of model stealing and extraction attacks.
I build these systems professionally.
Whether it's a RAG pipeline, analytics migration, or AI workflow — let's talk.