Path: blob/main/frontier/12-mpc/sage/12e-spdz-protocol.ipynb
483 views
Notebook 12e: The SPDZ Protocol
Module 12: Multi-Party Computation
Motivating Question. Additive secret sharing lets parties compute on shared values, and Beaver triples handle multiplication. But what if a party cheats, sending a wrong share to bias the output? Can we detect (and abort) when any party deviates from the protocol?
Prerequisites. You should be comfortable with:
Additive secret sharing and Beaver triples (Notebook 12b)
Oblivious transfer (Notebook 12d)
Message authentication codes (basic concept)
Learning objectives. By the end of this notebook you will be able to:
Explain the offline/online paradigm of SPDZ.
Implement SPDZ shares: a value share paired with a MAC share.
Perform addition and multiplication on SPDZ shares.
Open a shared value with a MAC check that detects cheating.
Demonstrate that a malicious party cannot cheat undetected.
1. From Semi-Honest to Malicious Security
Bridge from Notebooks 12a–12d. So far, our secret sharing protocols assumed all parties follow the protocol honestly ("semi-honest" model). In the real world, a party might send incorrect shares to learn extra information or corrupt the output. SPDZ (Damgård, Pastro, Smart, Zakarias, 2012) upgrades to malicious security: any cheating is detected.
The Offline/Online Paradigm
SPDZ splits computation into two phases:
| Phase | What happens | Uses |
|---|---|---|
| Offline (preprocessing) | Generate Beaver triples + MAC material | Heavy crypto (OT, HE) |
| Online (computation) | Compute on shares using preprocessed material | Only field operations |
The offline phase is expensive but input-independent, it can run before parties even know what they want to compute.
2. SPDZ Shares: Values + MACs
The key idea in SPDZ: every shared value carries a Message Authentication Code (MAC).
Setup: All parties share a global MAC key . Party holds with . No party knows itself.
SPDZ share of : Party holds a pair where:
(additive shares of the value)
(additive shares of the MAC)
We write for a SPDZ-shared value (brackets denote "authenticated sharing").
Checkpoint 1. Each SPDZ share is a pair: a value share and a MAC share. The MAC shares sum to , where is a key that no single party knows. This is what makes cheating detectable.
3. Operations on SPDZ Shares
Addition (Local, No Communication)
To compute from and : each party locally adds their pairs.
This works because and .
Checkpoint 2. Notice that addition and scalar operations are free, no communication needed, and the MAC stays valid. This is just like plain additive sharing from Notebook 12b, but now with authentication.
Multiplication via Beaver Triples
Bridge from Notebook 12b. We saw that multiplying shared values requires Beaver triples with . In SPDZ, the triple is also authenticated: all carry MACs.
To compute :
Open and (these are random-looking, so they leak nothing)
Compute
4. Detecting Cheating
Here's the key question: what happens if a party lies during the opening phase?
Suppose Party 0 sends instead of their real share . The reconstructed value becomes . But the MAC check computes:
Since Party 0 doesn't know , they can't adjust their MAC share to compensate. The check catches the cheat!
Misconception alert. "Can't the cheater just also adjust their MAC share?" They could try, but they'd need to subtract from their MAC share. Computing requires knowing , but the cheater only knows their own share , not the full MAC key.
5. Complete Computation:
Let's put it all together. Three parties compute where:
Party 0 inputs
Party 1 inputs
Expected result:
Checkpoint 3. Count the communication rounds in the computation above: opening and (one round), then opening the final result (one round). That's two rounds for the online phase, regardless of how complex the additions are.
6. The Offline Phase
We've been using a trusted dealer to generate Beaver triples. In real SPDZ, the offline phase uses cryptographic protocols to generate authenticated triples without any trusted party:
| Method | Idea | Performance |
|---|---|---|
| Somewhat HE (original SPDZ) | Encrypt shares with homomorphic encryption; multiply under encryption | Moderate |
| OT-based (MASCOT, 2016) | Use oblivious transfer to create correlated randomness | Faster |
| Overdrive (2018) | Optimized HE-based preprocessing | Fastest for large batches |
Bridge from Notebook 12d. OT extension (millions of OTs from 128 base OTs) makes the OT-based approach practical. The MASCOT protocol generates one authenticated triple using roughly OTs per party, where is the security parameter.
The beauty of the offline/online split: all the expensive crypto happens before the inputs are known. The online phase is blazingly fast, just field arithmetic.
7. Semi-Honest vs. Malicious Security
| Property | Plain Additive Sharing (12b) | SPDZ |
|---|---|---|
| Shares | Value only: | Value + MAC: |
| Addition | Local (free) | Local (free) |
| Multiplication | Beaver triple | Beaver triple + MAC |
| Opening | Just sum shares | Sum shares + MAC check |
| Security model | Semi-honest | Malicious (with abort) |
| Cheating detection | None | MAC fails with prob |
| Offline cost | Trusted dealer | OT / HE protocols |
"Malicious with abort" means: if any party cheats, honest parties detect it and abort. The cheater doesn't learn the output either. This is the strongest practical security notion for MPC.
Crypto foreshadowing. SPDZ and its variants (SPDZ2k, Overdrive, MP-SPDZ) are the backbone of real-world MPC deployments: private machine learning (training on combined datasets without sharing data), secure auctions (computing the winning bid without revealing losing bids), and threshold cryptography (distributed key generation for blockchain wallets).
8. Exercises
Exercise 1 (Worked): Cheating During Multiplication
Problem. Show that if a party cheats when opening during a multiplication, the MAC check catches it.
Solution:
Exercise 2 (Guided): Compute
Problem. Three parties each provide one input. Compute using SPDZ.
Hint: you need one Beaver triple (for ) and one addition (adding ).
Exercise 3 (Independent): How Many Triples?
Problem.
How many Beaver triples are needed to compute using SPDZ? Can you reduce this by rewriting the expression?
Implement the computation using SPDZ and verify your answer.
In general, if a function has multiplications, how many Beaver triples and communication rounds does the online phase need?
Summary
| Concept | Key Fact |
|---|---|
| SPDZ shares | Each value has paired MAC shares: with |
| MAC key | Global shared additively, no single party knows it |
| Addition | Local, free, MAC stays valid automatically |
| Multiplication | Beaver triple + open (all MAC-checked) |
| Opening | Reveal shares, verify |
| Cheating detection | Tampering breaks MAC with probability |
| Offline/online split | Expensive triple generation before inputs; cheap online phase |
SPDZ achieves malicious security with abort: any cheating party is caught, and the protocol halts before producing an incorrect output. Combined with secret sharing (12a–12b), garbled circuits (12c), and oblivious transfer (12d), this completes our tour of the fundamental building blocks of secure multi-party computation.
This is the final notebook in the series. Congratulations on completing all 12 modules, from modular arithmetic to multi-party computation!