Closed AliceNCsyuk closed 2 months ago
This is the topk protocol and it is from https://eprint.iacr.org/2023/1147.pdf
You can debug memory allocation and overflow errors using valgrind with prefix=valgrind Scripts/<protocol>.sh
.
Also note there is now more documentation on adding instructions: https://mp-spdz.readthedocs.io/en/latest/add-instruction.html
I implemented a TOP-K protocol in a virtual machine by adding an topk instruction. However, after I ran the protocol and successfully obtained the result, the program reported an error and did not show the total communication overhead. It seems that this is caused by resource recycling, but I don't know where to fix this error. Secure_top_k.mpc batch_size=6 topk_rate=0.9
k=int(topk_rate*batch_size)
k=4 v=sfix.get_input_from(0, size=6) ans=cint(size=k) secure_topk(ans,v.pre_mul(),k,batch_size) print_ln("%s",ans) print_ln("%s",ans) print_ln("%s",ans) ans1=cint(size=k) secure_topk(ans1,v.pre_mul(),k,batch_size) print_ln("%s",ans1) print_ln("%s",ans1) print_ln("%s",ans1)
library.py def secure_topk(ans,v,k,batch_size): secure_top_k(ans,v,k,batch_size)
instruction.py class secure_top_k(base.VarArgsInstruction): slots = [] code = base.opcodes['TOPK'] arg_format = tools.cycle(['cw','s','int','int'])
Input-P0-0 10.1 3.2 2.3 10.4 4.5 6.6
The output: P0: Using security parameter 40 Trying to run 64-bit computation [0, 3, 5, 4] [0, 3, 5, 4] [0, 3, 5, 4] [0, 3, 5, 4] [0, 3, 5, 4] [0, 3, 5, 4] free(): invalid next size (fast) Aborted (core dumped) P1: Using security parameter 40 Trying to run 64-bit computation The following benchmarks are including preprocessing (offline phase). Time = 0.00978447 seconds Data sent = 0.006804 MB in ~36 rounds (party 1) terminate called after throwing an instance of 'boost::wrapexcept'
what(): read_some: stream truncated [asio.ssl.stream:1]
Aborted (core dumped)
P2:
Using security parameter 40
Trying to run 64-bit computation
The following benchmarks are including preprocessing (offline phase).
Time = 0.00951865 seconds
Data sent = 0.000216 MB in ~73 rounds (party 2)
terminate called after throwing an instance of 'boost::wrapexcept'
what(): read_some: stream truncated [asio.ssl.stream:1]
Aborted (core dumped)