Skip to main content

Linear Scan

The linear scan example scans a list of secret values from multiple parties, checking for the existence of specific values. The example uses a reusable helper function for the logic for determining whether a given value is present or isn't present in the list.

src/list_scan_linear.py
from nada_dsl import *
import nada_numpy as na

def is_number_present_in_list(array: List[SecretInteger], value: Integer) -> SecretBoolean:
result = Integer(0)
for element in array:
# If the element is equal to the value, add 1 to the result.
result += (value == element).if_else(Integer(1), Integer(0))
return (result > Integer(0))

def nada_main():
num_parties = 10
parties = na.parties(num_parties)

secrets_list = []
for i in range(num_parties):
secrets_list.append(
SecretInteger(Input(name="num_" + str(i), party=parties[i]))
)

# Check if 100 is a secret value in the list
is_present_1 = is_number_present_in_list(secrets_list, Integer(100))

# Check if 99 is a secret value in the list
is_present_2 = is_number_present_in_list(secrets_list, Integer(99))

return [
Output(is_present_1, "is_present_1", party=parties[0]),
Output(is_present_2, "is_present_2", party=parties[0]),
]

Run and test the list_scan_linear program

1. Open "Nada by Example"

Open in Gitpod

2. Run the program with inputs from the test file

nada run list_scan_linear_test

3. Test the program with inputs from the test file against the expected_outputs from the test file

nada test list_scan_linear_test
Feedback