data61 / MP-SPDZ

Versatile framework for multi-party computation
Other
953 stars 279 forks source link

Intermittent Floating Point Exception in Hemi-Party.x during MPC Computation #1547

Open fqliao opened 1 day ago

fqliao commented 1 day ago

Hello,

I'm experiencing intermittent issues with the hemi-party.x tool when running a two-party computation task. Here's the algorithm from the demo.mpc file:

n_threads = 8
value_type = sfix

sfix.set_precision(16, 47)

SOURCE0 = 0
source0_record_count = 5
source0_column_count = 1
source0_record = Matrix(source0_record_count, source0_column_count, value_type)

SOURCE1 = 1
source1_record_count = 5
source1_column_count = 1
source1_record = Matrix(source1_record_count, source1_column_count, value_type)

result_record = 5
results = Matrix(result_record, 1, value_type)

def read_data_collection(data_collection, party_id):
    if data_collection.sizes[0] > 0:
        data_collection.input_from(party_id)

def calculate_result_0():
    @for_range_opt_multithread(n_threads, result_record)
    def _(i):
        results[i][0] = 2*source0_record[i][0]*source1_record[i][0]

def print_results():
    result_fields = ['result0']
    set_display_field_names(result_fields)

    @for_range_opt(result_record)
    def _(i):
        result_values = [results[i][0].reveal()]
        display_data(result_values)

def set_display_field_names(name_list):
    for name in name_list:
        if " " in name:
            raise TypeError(
                'Space cannot be in title list, found type error', name)
    println("result_fields = %s", ' '.join(name_list))

def display_data(field_values):
    printfmt("result_values =")
    for value in field_values:
        printfmt(" %s", value)
    println()

def do_main():
    read_data_collection(source0_record, SOURCE0)
    read_data_collection(source1_record, SOURCE1)
    calculate_result_0()

    print_results()

do_main()

The datasets are as follows: Dataset for Input-P0-0:

1
2
3
4
5
6

Dataset for Input-P1-0:

10
20
30
40
50
60

The commands for running and compiling are:

python ./compile.py -F 128 demo && ./hemi-party.x 0 demo -h 192.168.0.18 -pn 5899 -N 2
python ./compile.py -F 128 demo && ./hemi-party.x 1 demo -h 192.168.0.18 -pn 5899 -N 2

The correct output should look like this:

Default bit length: 128
Default security parameter: 40
Compiling file Programs/Source/demo.mpc
WARNING: Order of memory instructions not preserved, errors possible
Writing to Programs/Bytecode/demo-multithread1-1.bc
Writing to Programs/Schedules/demo.sch
Writing to Programs/Bytecode/demo-0.bc
Hash: 3660d1e58f65a134475fd06465b646c490689185f5a254e3281427f22e646ce9
Program requires at most:
           5 integer inputs from player 0
           5 integer inputs from player 1
          10 integer opens
           5 integer triples
         515 integer bits
          12 virtual machine rounds
Using security parameter 40
result_fields = result0
result_values = 20
result_values = 80
result_values = 180
result_values = 320
result_values = 500

However, when running multiple times, I occasionally encounter a floating point exception error and fail to obtain the correct results. The error message is as follows:

Default bit length: 128
Default security parameter: 40
Compiling file Programs/Source/9899936497281030-SQL.mpc
WARNING: Order of memory instructions not preserved, errors possible
Writing to Programs/Bytecode/9899936497281030-SQL-multithread1-1.bc
Writing to Programs/Schedules/9899936497281030-SQL.sch
Writing to Programs/Bytecode/9899936497281030-SQL-0.bc
Hash: 3660d1e58f65a134475fd06465b646c490689185f5a254e3281427f22e646ce9
Program requires at most:
           5 integer inputs from player 0
           5 integer inputs from player 1
          10 integer opens
           5 integer triples
         515 integer bits
          12 virtual machine rounds
Using security parameter 40
[1]    14603 floating point exception  /root/sit/code/MP-SPDZ-SGD/hemi-party.x 1 9899936497281030-SQL -h 192.168.0.1

The code commit I am using is:

commit 640b1a988edef3c3498f79e56389525593cf08f4
Author: Marcel Keller <mks.keller@gmail.com>
Date:   Wed Apr 26 11:24:51 2023 +1000

    Fix bug in updating binary values.

Could you please advise on how to resolve this issue?

mkskeller commented 1 day ago

I can think of two things:

  1. Run . Scripts/common.sh; ./hemi-party.x .... This should give you a stack trace for further analysis.
  2. Update to the latest version because the issue might have been fixed, and your commit is five versions behind the current one.