Skip to content

Commit

Permalink
feat: Add example of using Python builtin sum() for secret integers
Browse files Browse the repository at this point in the history
  • Loading branch information
navasvarela committed Nov 22, 2024
1 parent 203298a commit e918da3
Show file tree
Hide file tree
Showing 3 changed files with 31 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]]
name = "sum_list"
path = "src/sum_list.py"
prime_size = 128
18 changes: 18 additions & 0 deletions src/sum_list.py
Original file line number Diff line number Diff line change
@@ -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)]
8 changes: 8 additions & 0 deletions tests/sum_list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
program: sum_list
inputs:
secret1: 3
secret2: 3
secret3: 3
expected_outputs:
sum_list: 9

0 comments on commit e918da3

Please sign in to comment.