# Daml Programming Challenge : Privacy-preserving statistics

**URL:** <https://forum.canton.network/t/daml-programming-challenge-privacy-preserving-statistics/3595>\
**Category:** App Development\
**Tags:** daml, privacy\
**Created:** [December 17, 2021, 11:08am UTC](https://forum.canton.network/t/daml-programming-challenge-privacy-preserving-statistics/3595 "2021-12-17T11:08:28Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luciano](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/luciano/32/319_2.png) [@Luciano](https://forum.canton.network/u/Luciano)\
**Post date:** [December 17, 2021, 11:08am UTC](https://forum.canton.network/t/daml-programming-challenge-privacy-preserving-statistics/3595/1 "2021-12-17T11:08:29Z")

</div>

Here’s a problem I’ve been working on for a while and am interested to see if anyone can implement a working solution:

1. Create a list of integers where each element is private to a single party
2. Extract the biggest integer from the list

Some more requirements:

- When calculating the `max` value, avoid disclosing the entire list to participants
- The `max` operation should be atomic i.e. run in a single `Update`

Caveat emptor: I’ve not been able to do this myself, especially the last point. I’m not convinced it’s even possible!

---

<div class="post-metadata">

**Author:** ![Luciano](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/luciano/32/319_2.png) [@Luciano](https://forum.canton.network/u/Luciano)\
**Post date:** [December 17, 2021, 11:20am UTC](https://forum.canton.network/t/daml-programming-challenge-privacy-preserving-statistics/3595/2 "2021-12-17T11:20:44Z")

</div>

I should add that the trick here is also to avoid participants becoming aware of other participants. In an ordered list, I don’t think it’s possible to do this without disclosing at least the identity of the adjacent participant.

---

<div class="post-metadata">

**Author:** ![Leonid\_Rozenberg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/leonid_rozenberg/32/48_2.png) [@Leonid\_Rozenberg](https://forum.canton.network/u/Leonid_Rozenberg)\
**Post date:** [December 17, 2021, 5:06pm UTC](https://forum.canton.network/t/daml-programming-challenge-privacy-preserving-statistics/3595/3 "2021-12-17T17:06:11Z")

</div>

> [@Luciano](#):
>
> run in a single `Update`

Who runs this? A party with access to all the elements?

---

<div class="post-metadata">

**Author:** ![Luciano](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/luciano/32/319_2.png) [@Luciano](https://forum.canton.network/u/Luciano)\
**Post date:** [December 17, 2021, 5:08pm UTC](https://forum.canton.network/t/daml-programming-challenge-privacy-preserving-statistics/3595/4 "2021-12-17T17:08:39Z")

</div>

> [@Leonid\_Rozenberg](#):
>
> A party with access to all the elements?

The way I’ve implemented this is to use the stakeholder of the head of the list. So they don’t have visibility to all the elements necessarily.

---

<div class="post-metadata">

**Author:** ![Shaul](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/shaul/32/117_2.png) [@Shaul](https://forum.canton.network/u/Shaul)\
**Post date:** [December 21, 2021, 1:32pm UTC](https://forum.canton.network/t/daml-programming-challenge-privacy-preserving-statistics/3595/5 "2021-12-21T13:32:35Z")

</div>

I’m not sure I understand the use case, but from my understanding

1. You’re requiring a single Update → the submitter will necessarily see all contracts which are part of the update
2. You’re looking for the `max` of the whole list → the Update must include the whole list → the submitter will see all integers

So I don’t see a trivial way to do this.

If you’re willing to use things like trusted hardware, I believe @georg has used Intel SGX in the past for something similar. A single party runs the `max` function on the list in the enclave, but only the trusted enclave sees the entire list, protecting the list’s privacy from any single human.

---

<div class="post-metadata">

**Author:** ![Luciano](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/luciano/32/319_2.png) [@Luciano](https://forum.canton.network/u/Luciano)\
**Post date:** [December 21, 2021, 3:03pm UTC](https://forum.canton.network/t/daml-programming-challenge-privacy-preserving-statistics/3595/6 "2021-12-21T15:03:09Z")

</div>

Yes, in retrospect I don’t think this was very well thought out.

Basically what I was trying to see if it was possible to stage multi-party ‘blind’ transactions atomically. So for instance, an auction (without a central agent) where participants can’t see each other’s identities, or subcustodial structures where settlement occurs atomically across multiple parties, but they only know the identity of their adjacent ‘link’ in the settlement chain.

I think in it’s current form this question isn’t very helpful. Will remove it.

---

<div class="post-metadata">

**Author:** ![Leonid\_Rozenberg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/leonid_rozenberg/32/48_2.png) [@Leonid\_Rozenberg](https://forum.canton.network/u/Leonid_Rozenberg)\
**Post date:** [December 22, 2021, 1:34am UTC](https://forum.canton.network/t/daml-programming-challenge-privacy-preserving-statistics/3595/7 "2021-12-22T01:34:02Z")

</div>

One addition that I’ve thought about before is adding `hidden` effect (or `Action`) to Daml. So one could write

```haskell
do
  step1 <- ...
  hiddden {
    step2 <- f step1
  } 
  step3 <- g step2

```

And no one who would ordinarily be notified of what happens in `f` is actually notified. If you have access to the code, one is delegating the truth of `f` to it and the node that you’re running on. Bernhard will chime in with other concerns, but this is just an idea…

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [December 22, 2021, 6:11am UTC](https://forum.canton.network/t/daml-programming-challenge-privacy-preserving-statistics/3595/8 "2021-12-22T06:11:35Z")

</div>

If they’re not notified they also cannot validate it. So you have to make some fairly fundamental changes to Daml’s ledger model to handle something like that.

---

<div class="post-metadata">

**Author:** ![Shaul](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/shaul/32/117_2.png) [@Shaul](https://forum.canton.network/u/Shaul)\
**Post date:** [December 22, 2021, 6:31pm UTC](https://forum.canton.network/t/daml-programming-challenge-privacy-preserving-statistics/3595/9 "2021-12-22T18:31:27Z")

</div>

As @cocreature points out, `hidden` changes the fundamental trust assumptions in the system. That said, we could implement something like this that delegates trust to an enclave or ZKP proof system, so anything in a `hidden` block still holds under modified trust assumptions. Example assumptions could be:

1. `hidden` executes in an enclave on all nodes, protecting data from the node operator. You trust that a malicious party can’t extract data from the enclave.
2. `hidden` executes in the submitting node’s enclave, and the enclave sends an attestation to all other nodes. You trust that a malicious party can’t forge an attestation.
3. `hidden` executes in a ZKP prover, sending proof to all other nodes. You trust that a malicious party can’t forge a ZKP proof.

At the moment, I think this puts too much onus on app developers to think about trust properties. Furthermore, there are still too many security vulnerabilities being found regularly with both enclaves and ZKP implementations. Security researchers in recent years have broken the three trust assumptions I wrote above.

---

<div class="post-metadata">

**Author:** ![Luciano](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/luciano/32/319_2.png) [@Luciano](https://forum.canton.network/u/Luciano)\
**Post date:** [May 12, 2022, 9:46am UTC](https://forum.canton.network/t/daml-programming-challenge-privacy-preserving-statistics/3595/10 "2022-05-12T09:46:18Z")

</div>

So doing some more reading on this, I’ve found that what I’m looking for actually has a name:

> **[Secure multi-party computation | Definition and overview](https://en.wikipedia.org/wiki/Secure_multi-party_computation#Definition_and_overview)**
>
> In an MPC, a given number of participants, p1, p2, ..., pN, each have private data, respectively d1, d2, ..., dN. Participants want to compute the value of a public function on that private data: F(d1, d2, ..., dN) while keeping their own inputs secret.
> For example, suppose we have three parties Alice, Bob and Charlie, with respective inputs x, y and z denoting their salaries. They want to find out the highest of the three salaries, without revealing to each other how much each of them makes. M...

Is this something that we’ve explored, in the context of daml or Canton?

---

<div class="post-metadata">

**Author:** ![Shaul](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/shaul/32/117_2.png) [@Shaul](https://forum.canton.network/u/Shaul)\
**Post date:** [May 26, 2022, 8:24pm UTC](https://forum.canton.network/t/daml-programming-challenge-privacy-preserving-statistics/3595/11 "2022-05-26T20:24:10Z")

</div>

We haven’t considered adding MPC directly to Daml. It would look very similar to the use of enclaves that I described.  
The difference is in the trust model - MPC relies on cryptographic assumptions and enclaves rely on different security assumptions.
