From e918da3e669b4c88f71f20fd13c1f1ce023a16f1 Mon Sep 17 00:00:00 2001 From: Juan M Salamanca Date: Fri, 22 Nov 2024 11:25:56 +0000 Subject: [PATCH] feat: Add example of using Python builtin `sum()` for secret integers --- nada-project.toml | 5 +++++ src/sum_list.py | 18 ++++++++++++++++++ tests/sum_list.yaml | 8 ++++++++ 3 files changed, 31 insertions(+) create mode 100644 src/sum_list.py create mode 100644 tests/sum_list.yaml diff --git a/nada-project.toml b/nada-project.toml index e79ceb2..4f1896d 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]] +name = "sum_list" +path = "src/sum_list.py" +prime_size = 128 diff --git a/src/sum_list.py b/src/sum_list.py new file mode 100644 index 0000000..3e42f88 --- /dev/null +++ b/src/sum_list.py @@ -0,0 +1,18 @@ +from nada_dsl import * + + +def nada_main(): + party_alice = Party(name="Alice") + party_bob = Party(name="Bob") + party_charlie = Party(name="Charlie") + + # Inputs from each party + secret1 = SecretInteger(Input(name="secret1", party=party_alice)) + secret2 = SecretInteger(Input(name="secret2", party=party_bob)) + secret3 = SecretInteger(Input(name="secret3", party=party_charlie)) + + # List of secrets + secrets_list = [secret1, secret2, secret3] + + # Return the sum to party_alice + return [Output(sum(secrets_list), "sum_list", party_alice) for i in range(3)] diff --git a/tests/sum_list.yaml b/tests/sum_list.yaml new file mode 100644 index 0000000..4f9c8c0 --- /dev/null +++ b/tests/sum_list.yaml @@ -0,0 +1,8 @@ +--- +program: sum_list +inputs: + secret1: 3 + secret2: 3 + secret3: 3 +expected_outputs: + sum_list: 9