(DRAFT) Garbled Circuits for Three-Party Computation
Imagine a group of people have some private data, and they want to jointly compute a function of their private data, without sharing any of the data. Maybe they want to know the median of their salaries, without anyone revealing their own. Maybe a group of doctors wants to collaborate on a statistical study, without sharing any data about individual patients. This is the problem that multiparty computation solves.
If you haven’t thought about this before, you’ll want to start with the special case of two-party computation, which rests on Yao’s garbled circuits protocol and a technique called oblivious transfer. This post by Gubsheep walks you through understanding how you would discover the protocol on your own. If you just want to see the protocol, Vitalik’s post is also very good.
In this post I’m going to explain how to upgrade two-party computation to handle computations between three (or more) people, still using the basic idea of garbled circuits.
For this post, we’re going to assume that all three parties carry out the protocol honestly… One could ask for stronger security guarantees. There are lots of different 3PC protocols, with different tradeoffs among security and complexity. There are also lots of good ideas that we won’t get into in this blog post – for example, “cut-and-choose”.
A three-party version of oblivious transfer
Alice has 4 messages: . Bob and Carol each have a private bit – call them and . Alice wants to transmit to Carol, in such a way that:
- Alice learns neither nor
- Bob learns neither nor any information about the messages, and
- Carol learns neither nor any information about the other three messages.
If you’ve seen plain vanilla two-party oblivious transfer, it’s not hard to come up with a protocol. Here’s one:
- Alice randomly generates four symmetric encryption keys – two for Bob ( and ) and two for Carol ( and ).
- Alice performs a classical (two-party) oblivious transfer with Bob, sending him ; Alice performs another OT with Carol, sending her .
- Alice sends Bob this table.
(b, c) | |
---|---|
(0, 0) | |
(0, 1) | |
(1, 0) | |
(1, 1) |
- Bob uses to decrypt the two messages and , and sends them both to Carol.
- Carol uses to decrypt the one message .
Why is this secure?
- Alice doesn’t learn anything about and because nobody sends her any messages (except as part of the original OT protocol, which we know is secure).
- Bob doesn’t learn anything about because Carol never sends him any messages. He doesn’t learn anything about any of the encrypted messages because he doesn’t know or .
- Carol doesn’t learn anything about because she only sees and . She doesn’t learn anything about the two messages and for because she never sees them, even in encrypted form; she doesn’t learn the third message for because she doesn’t have the key to decrypt it.
Toward a 3PC Protocol
Let’s make a couple of observations.
- What if Bob and Carol each have 2 bits (), Alice has messages (), and Alice wants to send Carol only the single message determined by Bob’s 2 bits and Carol’s 2 bits?
To make this work, Alice needs to give Bob (and Carol, but we’ll focus on Bob for now) a for each of his two bits. So Alice chooses at random 4 symmetric keys, . Using two OTs, Alice transfers to Bob the key corresponding to his first bit and the key corresponding to his second bit. Now Bob computes a symmetric key . Alice does the same with Carol.
Now there are four possibilities for and four possibilities for , and Alice knows all of them. So Alice can publish a table – just like the table above, but with 16 rows – and at the end of the protocol, Carol learns only the one value she’s supposed to.
In the actual protocol, Bob has 3 bits , Carol has 2 bits , and Alice’s table has rows.
Secret shares
Just like in the 2PC protocol, each bit – each “wire” in the circuit – will be jointly held by Alice, Bob, and Carol, in the form of “secret shares”. In other words: Alice will hold a bit , Bob , and Carol , with the property that .
In our protocol, Alice and Bob will choose her bit at random. We might as well as choose Bob’s shares of gate output bits by simply setting them all equal to , Bob’s first input bit. (This lets Alice send Bob his keys without using extra oblivious transfers.) And then will be determined from the inputs to the gate, and , by the rule .
The Protocol
Just as in the usual 2PC garbled circuits protocol, Alice sets up the initial “garbling” of the circuit.
We set up some notation first. Number Bob’s inputs and . Number the gates , in some order (so that the inputs to each are either inputs to the circuit, or outputs of previous gates).
Let’s call all the bits (wires) in the circuit . So is just another name for Bob’s inputs , and similarly for Carol’s inputs. We’ll call the three parties’ shares of the bit .
- For each gate , Alice chooses at random her share of the output bit .
- For each bit to be held by either Bob or Carol (this includes both their input bits to the circuit, and their shares of intermediate bits ), Alice chooses at random two keys, one for each value of the bit. So: for each , Alice chooses and . Similarly for Carol’s bits .
- For Bob’s shares of output bits, since we know , we’ll just use the same keys for Bob. So .
- For each gate , Alice makes a 32-row table. Let and be the inputs to gate . Then the table has the form:
(b_i, b_j, b_k, c_j, c_k) | |
---|---|
- For each of Bob’s and Carol’s inputs and , Alice sends Bob and Carol the keys and by oblivious transfer – this is one OT per input bit to the circuit. (Note that Bob knows his keys for the whole circuit now, since they are all the same as his key .)
- Bob goes through each gate in order and uses his known key to decrypt the 4 rows of the table with his known values . Bob then sends to Carol the 4 encrypted values
- Carol goes through the gates in order. For each gate , she uses the known keys to decrypt both and .
- In the end, Carol computes her output bit . She, Alice and Bob share their three bits to determine the final output .
Security
First of all, notice that until the very last step information only ever travels from Alice –> Bob –> Carol. So (if the three parties don’t communicate outside the protocol) Alice can’t learn anything about Bob’s or Carol’s inputs, and Bob can’t learn anything about Carol’s.
Bob doesn’t learn anything about Alice’s inputs, either, since he only ever sees encrypted messages. And Carol only ever learns the bits , which are guaranteed to be uniformly random, because they are computed by , and is chosen uniformly at random.
But there’s a more interesting question: If two of Alice, Bob and Carol team up, can they learn the third person’s inputs?
Alice and Bob can’t learn anything about Carol’s inputs, because Carol never sends them any messages.
What can Bob and Carol learn? Even if they collaborate, they can’t possibly learn more than the one row from each table. So they can learn and for each , but again that tells them nothing they didn’t already know, because Bob chose and is random.
Alice and Carol can learn something, though. If Carol tells Alice which row of the table Bob sent her, Alice can work out Bob’s bit . But was the same as Bob’s input bit . Even worse, once they know , they can figure out for every .
Things get even worse if the players don’t carry out the protocol honestly. Bob and Carol are constrained by the encryption: they only ever find out one key per bit, so they can only read the “correct” row of the table. But our protocol relies on Alice to garble the circuit correctly in the first place. Nothing stops a malicious Alice from writing any circuit she pleases.
We’ll leave this as an example of a 3PC protocol and the level of security it affords – but if you want to know more, read about the “cut and choose” method.