Skip to content

Commit

Permalink
Issue #20 Oblivious Update
Browse files Browse the repository at this point in the history
  • Loading branch information
apanarun committed Nov 24, 2024
1 parent cd6d853 commit 320eb53
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nada-project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 31 additions & 0 deletions src/oblivious_update.py
Original file line number Diff line number Diff line change
@@ -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)
]

16 changes: 16 additions & 0 deletions tests/oblivious_update_test.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 320eb53

Please sign in to comment.