From 320eb535f180b5411b942dd185104347111e6e9b Mon Sep 17 00:00:00 2001 From: Arun Date: Sat, 23 Nov 2024 19:12:32 -0500 Subject: [PATCH] Issue #20 Oblivious Update --- nada-project.toml | 5 +++++ src/oblivious_update.py | 31 +++++++++++++++++++++++++++++++ tests/oblivious_update_test.yaml | 16 ++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 src/oblivious_update.py create mode 100644 tests/oblivious_update_test.yaml diff --git a/nada-project.toml b/nada-project.toml index e79ceb2..6d8d429 100644 --- a/nada-project.toml +++ b/nada-project.toml @@ -263,3 +263,8 @@ prime_size = 128 path = "src/auction_can_tie.py" name = "auction_can_tie" prime_size = 128 + +[[programs]] +path = "src/oblivious_update.py" +name = "oblivious_update" +prime_size = 128 diff --git a/src/oblivious_update.py b/src/oblivious_update.py new file mode 100644 index 0000000..b1eb843 --- /dev/null +++ b/src/oblivious_update.py @@ -0,0 +1,31 @@ +from nada_dsl import * +import nada_numpy as na + +### Updates the elements of the list which matches the old_value to a new_value +def nada_main(): + party_alice = Party(name="Party_Alice") + party_bob = Party(name="Party_Bob") + + # Getting the old and new value to update the list + old_value = SecretInteger(Input(name="old_value", party=party_alice)) + new_value = SecretInteger(Input(name="new_value", party=party_bob)) + + size_of_list = 5 + parties = na.parties(size_of_list) + + # Get the values of the list + secrets_list = [] + for i in range(size_of_list): + secrets_list.append( + SecretInteger(Input(name="num_" + str(i), party=parties[i])) + ) + + # Update the list + for i in range(size_of_list): + secrets_list[i] = (secrets_list[i] == old_value).if_else(new_value, secrets_list[i]) + + return [ + Output(secrets_list[i], "modified_num_" + str(i + 1), party=parties[i]) + for i in range(size_of_list) + ] + diff --git a/tests/oblivious_update_test.yaml b/tests/oblivious_update_test.yaml new file mode 100644 index 0000000..49b57a6 --- /dev/null +++ b/tests/oblivious_update_test.yaml @@ -0,0 +1,16 @@ +--- +program: oblivious_update +inputs: + new_value: 6 + num_0: 1 + num_1: 2 + num_2: 3 + num_3: 4 + num_4: 5 + old_value: 2 +expected_outputs: + modified_num_1: 1 + modified_num_2: 6 + modified_num_3: 3 + modified_num_4: 4 + modified_num_5: 5