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.
- Nada program
- Test file
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]),
]
tests/list_scan_linear_test.yaml
---
program: list_scan_linear
inputs:
num_0: 10
num_2: 20
num_1: 30
num_4: 40
num_9: 50
num_6: 60
num_7: 70
num_8: 80
num_5: 90
num_3: 100
expected_outputs:
is_present_1: true
is_present_2: false
Run and test the list_scan_linear program
1. Open "Nada by Example"
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