Closed Stu-Yang closed 1 week ago
Let me take a look. Thanks!
Hi, @wangxiao1254 After our investigation, we found that the issue is related to the length settings of Integer-type data a
, b
, and c
in emp-sh2pc/test/circuit_file.cpp. In the example file used for calculating the AES-128 circuit, the lengths are set as follows:
When I attempted to compute SHA-128 and SHA-256, I referred to Table 5 in the paper "Authenticated Garbling and Efficient Maliciously Secure Two-Party Computation", and set the lengths of a
, b
, and c
to 256, 256, 160 for SHA-128 and 256, 256, 256 for SHA-256. However, this caused the label inconsistency issue mentioned above.
Upon further investigation, I realized that the lengths of a
, b
, and c
should be set according to the values specified in the circuit files in the emp-tool/circuits/files/bristol_format directory, not the values in the table from the paper. Specifically, in the file sha-1.txt, the two inputs and one output are set to 512, 0, 160, and in the file sha-256-big.txt, the two inputs and one output are set to 512, 0, 256. Therefore, the correct approach is to set the values according to these input-output configurations. After applying these changes, the label inconsistency issue was resolved successfully.
To avoid the issue mentioned earlier, I suggest initializing the inputs as follows.
Integer a(cf.n1, 2, ALICE);
Integer b(cf.n2, 3, BOB);
Integer c(cf.n3, 1, PUBLIC);
I have encountered a further issue. In the solution mentioned above, where we set Integer b(128, 3, BOB);
, during the SHA circuit calculation, we instead set Integer b(0, 3, BOB);
. This means that Bob's input length is 0, indicating that he has no input. As a result, he does not need to receive the corresponding labels from Alice, the circuit generator. However, during testing, I found that Bob still incurs the same amount of communication as when performing the AES circuit calculation (as shown below), even though, theoretically, the communication should be different.
# terminal 1
(emp) root@ubuntu:~/emp-toolkit/emp-sh2pc# ./bin/test_circuit_file 1 12345
*************** Semi-Honest GC Protocol Starts! ***************
circuit file: /usr/local/include/emp-tool/circuits/files/bristol_format/AES-non-expanded.txt
*************** Protocol Ends! ***************
The number of iterations is: 100
Running Time:
running time: 393.185 ms
average running time: 3.932 ms
Communication:
comm. cost: 21258.688 KB
average comm. cost: 212.587 KB
(emp) root@ubuntu:~/emp-toolkit/emp-sh2pc# ./bin/test_circuit_file 1 12345
*************** Semi-Honest GC Protocol Starts! ***************
circuit file: /usr/local/include/emp-tool/circuits/files/bristol_format/sha-1.txt
*************** Protocol Ends! ***************
The number of iterations is: 100
Running Time:
running time: 2022.872 ms
average running time: 20.229 ms
Communication:
comm. cost: 116571.188 KB
average comm. cost: 1165.712 KB
(emp) root@ubuntu:~/emp-toolkit/emp-sh2pc# ./bin/test_circuit_file 1 12345
*************** Semi-Honest GC Protocol Starts! ***************
circuit file: /usr/local/include/emp-tool/circuits/files/bristol_format/sha-256-big.txt
*************** Protocol Ends! ***************
The number of iterations is: 100
Running Time:
running time: 4842.467 ms
average running time: 48.425 ms
Communication:
comm. cost: 283836.812 KB
average comm. cost: 2838.368 KB
# terminal 2
(emp) root@ubuntu:~/emp-toolkit/emp-sh2pc# ./bin/test_circuit_file 2 12345
*************** Semi-Honest GC Protocol Starts! ***************
circuit file: /usr/local/include/emp-tool/circuits/files/bristol_format/AES-non-expanded.txt
*************** Protocol Ends! ***************
The number of iterations is: 100
Running Time:
running time: 407.435 ms
average running time: 4.074 ms
Communication:
comm. cost: 264.255 KB
average comm. cost: 2.643 KB
(emp) root@ubuntu:~/emp-toolkit/emp-sh2pc# ./bin/test_circuit_file 2 12345
*************** Semi-Honest GC Protocol Starts! ***************
circuit file: /usr/local/include/emp-tool/circuits/files/bristol_format/sha-1.txt
*************** Protocol Ends! ***************
The number of iterations is: 100
Running Time:
running time: 2036.104 ms
average running time: 20.361 ms
Communication:
comm. cost: 264.130 KB
average comm. cost: 2.641 KB
(emp) root@ubuntu:~/emp-toolkit/emp-sh2pc# ./bin/test_circuit_file 2 12345
*************** Semi-Honest GC Protocol Starts! ***************
circuit file: /usr/local/include/emp-tool/circuits/files/bristol_format/sha-256-big.txt
*************** Protocol Ends! ***************
The number of iterations is: 100
Running Time:
running time: 4857.286 ms
average running time: 48.573 ms
Communication:
comm. cost: 264.130 KB
average comm. cost: 2.641 KB
Thus, my question is: How should we understand Bob's input length being set to 0 during the SHA circuit calculation? Why is the communication overhead not reflecting the absence of input from Bob?
By default, we always do a small number of OT to reduce the roundtrip complexity when initializing multiple inputs from Bob. https://github.com/emp-toolkit/emp-sh2pc/blob/master/emp-sh2pc/sh_eva.h#L15
You could comment out this part (also sh_gen) but then you cannot initialize anything from Bob.
Thank you for your response! It has resolved my issue, and I truly appreciate your help!
Hello, @wangxiao1254 , thank you very much to your team for providing such an excellent MPC library. During my development work using EMP-Toolkit, I encountered a few issues and would like to seek your advice and guidance on these matters.
Issue Description
I have successfully installed
emp-tool
,emp-ot
, andemp-sh2pc
, and I am able to run the provided test examples without issue. My current project involves designing a secure two-party computation protocol based onemp-sh2pc
. Specifically, I need to understand how output wire labels are computed in the half-gates-based garbled circuits used byemp-sh2pc
, and how the relationships between the output wire labels held by Alice (the circuit generator) and Bob (the circuit evaluator) are established.To investigate this, I modified
emp-sh2pc/test/circuit_file.cpp
to explicitly output:delta
from Alice (the circuit generator)result.reveal<string>(BOB)
) of the computationIn theory, following the secure computation protocol, Bob's output wire label should either match Alice's output wire label, or it should be the XOR of Alice's output wire label and the global key delta. This relationship holds true for the AES-128 circuit (
/bristol_format/AES-non-expanded.txt
) based on my testing. However, when testing with the SHA-1 circuit (/bristol_format/sha-1.txt
) and the SHA-256 circuit (/bristol_format/sha-256-big.txt
), the expected label relationships do not hold, and I am unable to reconcile the output labels between Alice and Bob.I have tried several approaches to investigate this issue, but so far, none have resolved the problem. Could you please provide guidance on how to address this inconsistency, or offer some insights into what might be causing the deviation in behavior for the SHA-1 and SHA-256 circuits?
1. Environment Setup
I am using the following setup to compile and test the project:
emp
)The specific versions of the repositories I am using are:
emp-tool
: commit@62ee03a94af3ef66607f460aac7ad2b1f10e3a26 (August 5, 2024)emp-ot
: commit@eb0daf2a7a88c44b419f6d1276dc19e66f80776f (August 5, 2024)emp-sh2pc
: commit@61589f52111a26015b2bb8ab359dc457f8a246eb (August 5, 2024)To compile the
emp-tool
,emp-ot
, andemp-sh2pc
projects, I used the following commands:I tested the code using two machines, with the following results:
These results matched the expected outcome.
2. Test Case Details
To better understand the half-gate garbled circuit computation process in
emp-sh2pc
, I tested emp-sh2pc/test/circuit_file.cpp. During the testing, I aimed to understand the behavior of the garbled circuit computation, specifically focusing on the output wire labels.I identified that the core computation occurs in the following lines of code:
The function
cf.compute((block*)c.bits.data(), (block*)a.bits.data(), (block*)b.bits.data())
handles the garbled circuit computation. Through my analysis, I found thatc.bits
corresponds to the output wire labels of the circuit. Specifically:0
.delta
.I modified the code to output the hexadecimal values of the following:
c.bits
(for both Alice and Bob in the two-machine mode).delta
(in hexadecimal).result
).Below is the modified version of the code:
I believe my analysis is correct, and the modified code seems fine, though a confirmation is needed.
3. Expected Behavior
With the computation iteration count set to 1, I ran the modified code in a LAN environment (configured using throttle.sh, with bandwidth set to 3GB/s and latency set to 0.32ms). The results are as follows:
Terminal 1
Terminal 2
To verify the correctness of the labels computed by Alice and Bob, I wrote a Python program that checks if Bob’s label is either equal to Alice’s label (corresponding to an output value of
0
), or equal to the XOR of Alice’s label and the global keydelta
(corresponding to an output value of1
).In the case of the AES-128 circuit, I observed that this relationship holds true, meaning the labels between Alice and Bob are consistent with the expected behavior. Furthermore, the output string computed based on the relationship between their labels matched the result produced by the original code.
The Python program I used for this validation is as follows:
The program compares the labels from Alice and Bob, checking if Bob's labels match either Alice's label or its XOR with the global key delta. In the AES-128 circuit computation, the program output was consistent with the expected relationship, and the resulting bit string generated by comparing the labels matched the result produced by the secure computation code.
4. Observed Behavior and Attempts to Resolve
However, when I switched the circuit file to
/bristol_format/sha-1.txt
or/bristol_format/sha-256-big.txt
, the output labels were entirely inconsistent. None of the labels matched between Alice and Bob, and using the Python program to validate these labels resulted in complete failure. This is very puzzling, as there should not be any fundamental difference between the AES-128 circuit computation and the SHA-1 or SHA-256 circuit computations.Terminal 1
Terminal 2
To investigate further, I used gdb to debug the above code but did not encounter any obvious anomalies. Additionally, we checked the example inputs and outputs provided for SHA-1 and SHA-256 on Nigel Smart’s MPC Circuits page. For instance, we tested the following input and output for SHA-256:
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
da5698be17b9b46962335799779fbeca8ce5d491c0d26243bafef9ea1837a9d8
We set the input values
a
,b
, andc
inemp-sh2pc/test/circuit_file.cpp
to0
,0
, and0
(256 bits), respectively. However, the output generated by the secure computation (71c84c0c7e571f2691638855e5c89a611a441fc203ed446ebc0204ec59a71f4f
) was not equal to the expected result. This further adds to the confusion, as we could not identify the reason for this discrepancy.At this point, I am unsure if the issue is with the SHA-1 or SHA-256 circuits themselves or with how the
emp-sh2pc
framework handles them.5. Request for Assistance
In summary, I would like to consult on the following questions:
Is there any issue with my analysis above, particularly with my understanding of the labels held by Alice (the circuit generator) and Bob (the circuit evaluator)? Additionally, does
c.bits
indeed correspond to the output wire labels as I expect?In the AES-128 example, does my analysis hold true and correctly reflect the label relationships between Alice and Bob? If so, why do inconsistencies arise when using the SHA-1 and SHA-256 examples? Is there any specific reason for these discrepancies that I may have overlooked?
Any guidance or insight into these questions would be highly appreciated. I am particularly interested in understanding whether this behavior stems from something specific to the SHA circuits or from a potential misunderstanding on my part. Any further discussions can take place under this issue, and feel free to contact me via email at stuyangpeng@gmail.com for any clarifications or additional information.