Skip to main content

Half Gate

The Half-Gate optimization further reduces the number of ciphertexts from 33 to 22. This is also the protocol used in zkOracles, and more details of this algorithm will be given in this subsection. The algorithm is presented in the ZRE15 paper.

We first describe the basic idea behind half-gate garbling. Let's say we want to compute the gate ab=ca\wedge b = c. With the Free-XOR optimization, let (Xa,XaΔ)(X_a,X_a\oplus \Delta) and (Xb,XbΔ)(X_b,X_b\oplus\Delta) denote the input wire labels to this gate, and (Xc,XcΔ)(X_c,X_c\oplus \Delta) denote the output wire labels, with Xa,Xb,XcX_a,X_b,X_c each encoding 00.

Half-gate garbling contains two case: when the garbler knows one of the inputs, and when the evaluator knows one of the inputs.

Garbler half-gate. Considering the case of an AND\and gate ab=ca\wedge b = c, where a,ba,b are intermediate wires in the circuit and the garbler somehow knows in advance what the value aa will be.

When a=0a = 0, the garbler will garble a unary gate that always outputs 00. The label table is as follows.

bbcc
XbX_bXcX_c
XbΔX_b\oplus \DeltaXcX_c

Then the garbler generates two ciphertexts: H(Xb)Xc\sH(X_b)\oplus X_c H(XbΔ)Xc\sH(X_b\oplus\Delta)\oplus X_c

When a=1a = 1, the garbler will garble a unary identity gate. The label table is as follows.

bbcc
XbX_bXcX_c
XbΔX_b\oplus \DeltaXcΔX_c\oplus \Delta

Then the garbler generates two ciphertexts:

H(Xb)Xc\sH(X_b)\oplus X_c H(XbΔ)XcΔ\sH(X_b\oplus\Delta)\oplus X_c\oplus \Delta

Since aa is known to the garbler, the two cases shown above could be unified as follows:

H(Xb)Xc\sH(X_b)\oplus X_c H(XbΔ)XcaΔ\sH(X_b\oplus\Delta)\oplus X_c\oplus a\cdot\Delta

These two ciphertexts are then suitably permuted according to the color bits of XbX_b. The evaluator takes a hash of its wire label for XbX_b and decrypts the appropriate ciphertext. If a=0a = 0, he/she obtains output wire label XcX_c in both values of bb. If a=1a = 1 the evaluator obtains either XcX_c or XcΔX_c\oplus \Delta, depending on the bit bb. Intuitively, the evaluator will never know both XbX_b and XbΔX_b\oplus\Delta, hence the other ciphertext appears completely random.

By applying the row-reduction optimization, we reduce the number of ciphertexts from 22 to 11 as follows. H(XbΔ)H(Xb)aΔ\sH(X_b\oplus\Delta)\oplus \sH(X_b)\oplus a\cdot\Delta

Evaluator half-gate. Considering the case of an AND\and gate ab=ca\wedge b = c, where a,ba,b are intermediate wires in the circuit and the evaluator somehow knows the value aa at the time of evaluation. The evaluator can behave differently based on the value of aa.

When a=0a = 0, the evaluator should always obtain output wire label XcX_c, then the garbled circuit should contains the ciphertext: H(Xa)Xc\sH(X_a)\oplus X_c

When a=1a = 1, it is enough for the evaluator to obtain R=XcXbR= X_c\oplus X_b. He/she can then XOR\xor RR with the other wire label (either XbX_b or XbΔX_b\oplus \Delta) to obtain either XcX_c or XcΔX_c\oplus \Delta. Hence the garbler should provide the ciphertext: H(XaΔ)XcXb\sH(X_a\oplus\Delta)\oplus X_c\oplus X_b

Combining the above two case together, the garbler should provide two ciphertexts: H(Xa)Xc\sH(X_a)\oplus X_c H(XaΔ)XcXb\sH(X_a\oplus\Delta)\oplus X_c\oplus X_b

Note that these two ciphertext do NOT have to be permuted according to the color bit of XaX_a, because the evaluator already knows aa. If a=0a = 0, the evaluator uses the wire label XaX_a to decrypt the first ciphertext. If a=1a = 1, the evaluator uses the wire label XaΔX_a\oplus \Delta to decrypt the second ciphertext and XOR\xors the result with the wire label for bb.

By applying the row-reduction optimization, we reduce the number of ciphertexts from 22 to 11 as follows. H(XaΔ)H(Xa)Xb\sH(X_a\oplus\Delta)\oplus \sH(X_a)\oplus X_b

Two halves make a whole. Considering the case to garble an AND\and gate ab=ca\wedge b = c, where both inputs are secret. Consider: c=ab=a(rrb)=(ar)(a(rb))c = a \wedge b = a\wedge (r\oplus r\oplus b) = (a\wedge r)\oplus (a\wedge(r\oplus b))

Suppose the garbler chooses uniformly random bit rr. In this case, the first AND\and gate (ar)(a\wedge r) can be garbled with a garbler-half-gate. If we further arrange for the evaluator to learn the value rbr\oplus b, then the second AND\and gate (a(rb))(a\wedge(r\oplus b)) can be garbled with an evaluator-half-gate. Leaking this extra bit rbr\oplus b to the evaluator is safe, as it carries no information about the sensitive value bb. The remaining XOR\xor gate is free and the total cost is 22 ciphertexts.

Actually the evaluator could learn rbr\oplus b without any overhead. The garbler choose the color bit of the 0 label XbX_b on wire bb. Since that color bit is chosen uniformly, it is secure to use it. Then when a particular value bb is on that wire, the evaluator will hold a wire label whose color bit is brb\oplus r.

Let Xb0,Xb1=Xb0ΔX_b^0,X_b^1 = X_b^0\oplus \Delta be the labels for bb, let p=LSB(Xb0)p = \lsb(X_b^0). pp is the color bit of the wire, is a secret known only to the garbler. When the evaluator holds a wire label for bb whose color bit is ss, the label is XbspX_b^{s\oplus p}, corresponding to truth value sps\oplus p.