data61 / MP-SPDZ

Versatile framework for multi-party computation
Other
900 stars 278 forks source link

how to use shamir-party.x and prf_mimc.mpc #1372

Closed whoqz closed 4 months ago

whoqz commented 5 months ago

i got several nodes, every nodes got shares of secrets and plaintexts seperately(via shamir), i want to get the final mimc result through the nodes(in the distributed way),i found the prf_mimc.mpc and the shamir-party.x(don't konw right or not),how can i use prf_mimc.mpc and shamir-party.x to reach my purpose? i am a rookie in this field, please can anyone give me some tips or help?

mkskeller commented 5 months ago

The top of the following file has some instructions: https://github.com/data61/MP-SPDZ/blob/master/Programs/Source/htmac.mpc I suggest you start with local computation:

./compile.py htmac 1 1 1
Scripts/shamir.sh htmac-1-1-1

If that works, you can expand this by running the following on every node

./compile.py htmac 1 1 1
./shamir-party.x -p <node number> -N <total nodes> -h <hostname/IP of node 0> htmac-1-1-1
whoqz commented 5 months ago

thank you for your reply! but i can't access to this link for some how. can you explain something about htmac.mpc? i.e. the function of this file or something else. what is the connection between this mpc file and prf_mimc.mpc?

mkskeller commented 5 months ago

Apologies, I've used the wrong repository, the link should now work. htmac.mpc includes prf_mimc.mpc on line 53.

whoqz commented 5 months ago

oh! thank you so much! another question pls, can you explain those orders(command) you list above ? what's the meaning of those order? i can figure out part of some simple command, i would like to consult someone about those command lines, they are really confused for me. if i encounter some issues after, maybe i can count on myself to solve the problem. Besides, what does "shamir-party.x" actually do? i am a bit confused about the connection between mpc file and binary file like"shamir-party.x". how do they work together to reach my purpose?Could you please enlighten me?

mkskeller commented 5 months ago

shamir-party.x implements secure computation based on Shamir's secret sharing via a virtual machine, and compile.py produces the matching virtual machine code from the Python high-level code. The following section in the documentation goes deeper into this: https://mp-spdz.readthedocs.io/en/latest/journey.html

whoqz commented 5 months ago

htmac.mpc is a benchmark test file or not? but i want to reach such scene: there are several nodes, every nodes has shares of secret and plaintext(via shamir),i want them to do the mpc with MiMC(need a secret and a plaintext as input),i want to obtain the final PRF result those nodes return with original secret and plaintext. how can i get the actual result?

mkskeller commented 5 months ago

Most of MP-SPDZ is geared towards benchmarking. I'm not particularly familiar with MiMC because someone else wrote that code. For ways of getting data into and out of an MPC computation, see the documentation: https://mp-spdz.readthedocs.io/en/latest/io.html

whoqz commented 5 months ago

thank you! i just try those command you list before, ./compile.py htmac 1 1 1 Scripts/shamir.sh htmac-1-1-1 it told me "You can use Scripts/setup-ssl.sh <nparties> i set 2 parties ,but i got error message "terminate called after throwing an instance of 'boost::wrapexcept'", don't know what's next should i do

mkskeller commented 5 months ago

Shamir's secret sharing requires 3 parties.

whoqz commented 5 months ago

still wrong. i set Scripts/setup-ssl.sh 3 and then Scripts/shamir.sh htmac-1-1-1 receive "terminate called after throwing an instance of 'boost::wrapexcept' what(): handshake: certificate verify failed"

mkskeller commented 5 months ago

Are there any more messages? As there are several parties, it would say:

some errors...
=== Party 1
more errors....
=== Party 2
more errors...
whoqz commented 5 months ago

@localhost mp-spdz-0.3.8]$ Scripts/shamir.sh htmac-1-1-1
Running /home/hqz/mp-spdz-0.3.8/Scripts/../shamir-party.x 0 htmac-1-1-1 -pn 10077 -h localhost -N 3
Running /home/hqz/mp-spdz-0.3.8/Scripts/../shamir-party.x 1 htmac-1-1-1 -pn 10077 -h localhost -N 3
Running /home/hqz/mp-spdz-0.3.8/Scripts/../shamir-party.x 2 htmac-1-1-1 -pn 10077 -h localhost -N 3
Using statistical security parameter 40
Server-side handshake with P2 failed. Make sure both sides  have the necessary certificate (Player-Data/P0.pem in the default configuration on their side and Player-Data/P2.pem on ours), and run `c_rehash <directory>` on its location.
The certificates should be the same on every host. Also make sure that it's still valid. Certificates generated with `Scripts/setup-ssl.sh` expire after a month.
See also https://mp-spdz.readthedocs.io/en/latest/troubleshooting.html#handshake-failures
Signature (should match the other side): d2dd14e19d6e5a4b2dfbb1acb8f83439/945cffb2e097261ee7d1684cfdde5674
terminate called after throwing an instance of 'boost::wrapexcept<boost::system::system_error>'
  what():  handshake: stream truncated
/home/hqz/mp-spdz-0.3.8/Scripts/run-common.sh: line 90: 48933 Aborted                 (core dumped) $my_prefix $SPDZROOT/$bin $i $params 2>&1
     48934 Done                    | { if test "$BENCH"; then
    if test $i = $front_player; then
        tee -a $log;
    else
        cat >> $log;
    fi;
else
    if test $i = $front_player; then
        tee $log;
    else
        cat > $log;
    fi;
fi; }
/home/hqz/mp-spdz-0.3.8/Scripts/run-common.sh: line 90: 48935 Aborted                 (core dumped) $my_prefix $SPDZROOT/$bin $i $params 2>&1
     48936 Done                    | { if test "$BENCH"; then
    if test $i = $front_player; then
        tee -a $log;
    else
        cat >> $log;
    fi;
else
    if test $i = $front_player; then
        tee $log;
    else
        cat > $log;
    fi;
fi; }
/home/hqz/mp-spdz-0.3.8/Scripts/run-common.sh: line 90: 48937 Aborted                 (core dumped) $my_prefix $SPDZROOT/$bin $i $params 2>&1
     48938 Done                    | { if test "$BENCH"; then
    if test $i = $front_player; then
        tee -a $log;
    else
        cat >> $log;
    fi;
else
    if test $i = $front_player; then
        tee $log;
    else
        cat > $log;
    fi;
fi; }
=== Party 1
Signature (should match the other side): d2dd14e19d6e5a4b2dfbb1acb8f83439/4dd1a79eec2faa69d678dc11c410253f
terminate called after throwing an instance of 'boost::wrapexcept<boost::system::system_error>'
  what():  handshake: tlsv1 alert unknown ca
=== Party 2
Signature (should match the other side): d2dd14e19d6e5a4b2dfbb1acb8f83439/4dd1a79eec2faa69d678dc11c410253f
terminate called after throwing an instance of 'boost::wrapexcept<boost::system::system_error>'
  what():  handshake: certificate verify failed
whoqz commented 5 months ago

after i exec the

Scripts/setup-ssl.sh 3
Scripts/shamir.sh htmac-1-1-1

i got those erro message

mkskeller commented 5 months ago

What is the output of Scripts/setup-ssl.sh?

whoqz commented 5 months ago
@localhost mp-spdz-0.3.8]$ Scripts/setup-ssl.sh 3
Setting up SSL for 3 parties
Generating a 2048 bit RSA private key
....+++
......................+++
writing new private key to 'Player-Data/P0.key'
-----
Generating a 2048 bit RSA private key
................................................................................................................................................+++
...............................+++
writing new private key to 'Player-Data/P1.key'
-----
Generating a 2048 bit RSA private key
..............................................+++
............................+++
writing new private key to 'Player-Data/P2.key'
-----
Scripts/setup-ssl.sh: line 17: c_rehash: command not found

maybe c_rehash's cause?

mkskeller commented 5 months ago

Almost certainly. Which system are you using?

whoqz commented 5 months ago

centos 7 in VMware

mkskeller commented 5 months ago

You should be able to install c_rehash with yum install openssl-perl.

whoqz commented 5 months ago

finally, i got those command

Scripts/setup-ssl.sh 3
Scripts/shamir.sh htmac-1-1-1

work ! but i didn't set threshold value and give the original secret key value or anything else(seems like time_private_mac use some random data to do the test). what does shamir.sh do then? besides if i use

./shamir-party.x -p 0 -N 3 htmac 1-1-1
 ./shamir-party.x -p 1 -N 3 htmac 1-1-1
./shamir-party.x -p 2 -N 3 htmac 1-1-1

what actually do i set? in the htmac.mpc the node 0,node 1, node 2 seems like to play no roles. total messages in mpc file is message = [sint(2*i+1) for i in range(nmessages)] and the key is key = sint.get_random_int(128) then node 0,1,2 that i set play what roles in the mpc or the bechmarking test? have them(shamir.sh and those shamir-party.x command) or not play any differences?those nodes i set seems like to obtain no data and don't execute the mpc progress. i can not tell the actual process and still feel confused! thank you so much for your patience!

whoqz commented 5 months ago

I still have some questions, looking forward to your further replies if you are free!

mkskeller commented 5 months ago

Indeed, the code uses some constants for the message and a fresh random key. See the documentation on input/output to learn about the ways of creating sint values from external data and outputting: https://mp-spdz.readthedocs.io/en/latest/io.html

whoqz commented 5 months ago

for example

./shamir-party.x 0 htmac-1-1-1 -pn 12168 -h localhost -N 3
./shamir-party.x 1 htmac-1-1-1 -pn 12168 -h localhost -N 3
./shamir-party.x 2 htmac-1-1-1 -pn 12168 -h localhost -N 3

So does this mean that the three commands above have already implemented the collaborative computation to obtain the PRF result? I noticed that in htmac.mpc, there doesn't seem to be a process for allocating shares to each participant. Is this process implemented by shamir-party.x? If I want to see the share information of each participant, what should I do? i have already checked the I/O document and found few useful information, the private outputs parts reveals few info.

mkskeller commented 5 months ago

So does this mean that the three commands above have already implemented the collaborative computation to obtain the PRF result?

Yes

I noticed that in htmac.mpc, there doesn't seem to be a process for allocating shares to each participant. Is this process implemented by shamir-party.x?

Yes

If I want to see the share information of each participant, what should I do? i have already checked the I/O document and found few useful information, the private outputs parts reveals few info.

You can use print_ln('%s', x, print_secrets=True) to output secret shares.

mkskeller commented 5 months ago

What do you mean?

whoqz commented 5 months ago

oh!sorry,i just find you have already answer my question before,perhaps it's network's delay, Thank you, i will check your answer above first. sorry

whoqz commented 5 months ago

Much appreciated!, now i understand much better, Thank you!

whoqz commented 5 months ago

@mkskeller another issue

You can use print_ln('%s', x, print_secrets=True) to output secret shares.

./shamir-party.x 0 htmac-1-1-1 -pn 12168 -h localhost -N 3
./shamir-party.x 1 htmac-1-1-1 -pn 12168 -h localhost -N 3
./shamir-party.x 2 htmac-1-1-1 -pn 12168 -h localhost -N 3

Considering situation above, what does x present? party 0, 1 or 2? In the mpc file, how can i get or set the x which contains the share information about every party? use get_input_from()(seems to be not ok) or something else?

mkskeller commented 5 months ago

x would be an instance of sint to see the secret sharing, but it can also be a cleartext value.

whoqz commented 5 months ago

I know that, but where does x come from? how do i get the secret sharing of party 0,1 and 2?(i.e. how do i get access to the x? i want to get sharings of party 0, 1 and 2. )

mkskeller commented 5 months ago

x can be any sint representing a secret value, see the tutorial for some examples: https://github.com/data61/MP-SPDZ/blob/master/Programs/Source/tutorial.mpc If you use print_ln as above (and -OF . when calling the virtual machine), every party will output their own share.

whoqz commented 5 months ago

If you use print_ln as above (and -OF . when calling the virtual machine), every party will output their own share.

Can you explain this more detailed or give some examples?

mkskeller commented 5 months ago

Consider the following program:

x = sint(0) * sint(0)
print_ln('%s', x, print_secrets=True)

If you put that into Programs/Source/test.py and then run

./compile.py test
./shamir-party.x 0 -OF . test &
./shamir-party.x 1 -OF . test &
./shamir-party.x 2 -OF . test

You should see three random-looking numbers, which corresponds to the shares. You can run the last three commands in three separate terminals for a less messy output.