bristolcrypto/SPDZ-2

if_then/else_then/end-if misbehavior

Closed this issue · 1 comments

test_if_else.mpc.txt

In the above file, we are trying a simple case of looping through 100 sint values in a list. We have a function that helps to compare and return the lesser of two values along with the index of the lesser value.
Within the scope of the if-else-end block the index value seems to be correct, but once control returns outside the block, the index value is changed.
Output.txt
Please refer to the sample output in the above file.

Hi,

The problem is that the compiler unrolls the main loop, which basically converts the function min_val_with_index to a set of instructions known at compile time.

Since x <= y is a value which is known only at runtime (when running the online phase) and you want to process further on that, you should have ret_indx as a MemValue rather as an integer - that's how you properly play with run-time values in SPDZ.

The solution would be to replace the assignments of ret_ndx = val with ret_indx.write(val) and you should see the correct results in the end.