Browse Source

spec: update DAO section with recent ElGamalEncryptedNote fixes.

zero 2 years ago
parent
commit
d87be16dd3
2 changed files with 94 additions and 60 deletions
  1. 33 56
      doc/src/spec/contract/dao/scheme.md
  2. 61 4
      doc/src/spec/crypto-schemes.md

+ 33 - 56
doc/src/spec/contract/dao/scheme.md

@@ -12,7 +12,9 @@ Let $\t{MerklePos}, \t{MerklePath}, \t{MerkleRoot}$ be defined as in the section
 
 
 Let $\t{Params}_\t{DAO}, \t{Bulla}_\t{DAO}, \t{Params}_\t{Proposal}, \t{Bulla}_\t{Proposal}$ be defined as in [DAO Model](model.md).
 Let $\t{Params}_\t{DAO}, \t{Bulla}_\t{DAO}, \t{Params}_\t{Proposal}, \t{Bulla}_\t{Proposal}$ be defined as in [DAO Model](model.md).
 
 
-Let $\t{EncNote}$ be defined as in [In-band Secret Distribution](../../crypto-schemes.md#in-band-secret-distribution).
+Let $\t{AeadEncNote}$ be defined as in [In-band Secret Distribution](../../crypto-schemes.md#in-band-secret-distribution).
+
+Let $\t{ElGamal.Encryptโ‚™}, \t{ElGamalEncNote}โ‚™$ be defined as in the section [Verifiable In-Band Secret Distribution](../../crypto-schemes.md#verifiable-in-band-secret-distribution).
 
 
 ## Mint
 ## Mint
 
 
@@ -97,7 +99,7 @@ $$ \begin{aligned}
   R_\t{DAO} &โˆˆ ๐”ฝโ‚š \\
   R_\t{DAO} &โˆˆ ๐”ฝโ‚š \\
   T &โˆˆ ๐”ฝโ‚š \\
   T &โˆˆ ๐”ฝโ‚š \\
   ๐’ซ &โˆˆ \t{im}(\t{Bulla}_\t{Proposal}) \\
   ๐’ซ &โˆˆ \t{im}(\t{Bulla}_\t{Proposal}) \\
-  \t{note} &โˆˆ \t{EncNote} \\
+  \t{note} &โˆˆ \t{AeadEncNote} \\
   ๐ข &โˆˆ \t{ProposeInput}^*
   ๐ข &โˆˆ \t{ProposeInput}^*
 \end{aligned} $$
 \end{aligned} $$
 
 
@@ -228,7 +230,7 @@ $$ \begin{aligned}
   ฯ„ &โˆˆ ๐”ฝโ‚š \\
   ฯ„ &โˆˆ ๐”ฝโ‚š \\
   ๐’ซ &โˆˆ \t{im}(\t{Bulla}_\t{Proposal}) \\
   ๐’ซ &โˆˆ \t{im}(\t{Bulla}_\t{Proposal}) \\
   V_\t{yes} &โˆˆ โ„™โ‚š \\
   V_\t{yes} &โˆˆ โ„™โ‚š \\
-  \t{note} &โˆˆ \t{EncNote} \\
+  \t{enc\_vote} &โˆˆ \t{ElGamalEncNote}โ‚„ \\
   ๐ข &โˆˆ \t{VoteInput}^*
   ๐ข &โˆˆ \t{VoteInput}^*
 \end{aligned} $$
 \end{aligned} $$
 
 
@@ -240,6 +242,14 @@ $$ \begin{aligned}
   \t{VoteInput}.\t{PK}_ฯƒ &โˆˆ โ„™โ‚š
   \t{VoteInput}.\t{PK}_ฯƒ &โˆˆ โ„™โ‚š
 \end{aligned} $$
 \end{aligned} $$
 
 
+**Note**: $\t{VoteInput}.V$ is a pedersen commitment, where the blinds are
+selected such that their sum is a valid field element in $๐”ฝโ‚š$ so the blind
+for $โˆ‘ V$ can be verifiably encrypted. Likewise we do the same for the blind
+used to calculate $V_\t{yes}$.
+
+This allows DAO members to securely receive all secrets for votes on a proposal.
+This is then used in the Exec phase when we work on the sum of DAO votes.
+
 ```rust
 ```rust
 {{#include ../../../../../src/contract/dao/src/model.rs:dao-vote-params}}
 {{#include ../../../../../src/contract/dao/src/model.rs:dao-vote-params}}
 ```
 ```
@@ -260,11 +270,12 @@ $$ \begin{aligned}
   d &โˆˆ \t{Params}_\t{DAO} \\
   d &โˆˆ \t{Params}_\t{DAO} \\
   b_d &โˆˆ ๐”ฝโ‚š \\
   b_d &โˆˆ ๐”ฝโ‚š \\
   o &โˆˆ ๐”ฝโ‚š \\
   o &โˆˆ ๐”ฝโ‚š \\
-  b_y &โˆˆ ๐”ฝแตฅ \\
+  b_y &โˆˆ ๐”ฝโ‚š \\
   v &โˆˆ ๐”ฝโ‚š \\
   v &โˆˆ ๐”ฝโ‚š \\
-  bแตฅ &โˆˆ ๐”ฝแตฅ \\
+  bแตฅ &โˆˆ ๐”ฝโ‚š \\
   b_ฯ„ &โˆˆ ๐”ฝโ‚š \\
   b_ฯ„ &โˆˆ ๐”ฝโ‚š \\
-  t_\t{now} &โˆˆ ๐”ฝโ‚š
+  t_\t{now} &โˆˆ ๐”ฝโ‚š \\
+  \t{esk} &โˆˆ ๐”ฝโ‚š \\
 \end{aligned} $$
 \end{aligned} $$
 Attach a proof $ฯ€_\mathcal{V}$ such that the following relations hold:
 Attach a proof $ฯ€_\mathcal{V}$ such that the following relations hold:
 
 
@@ -275,9 +286,9 @@ commit $T = \t{PedersenCommit}(d.ฯ„, b_ฯ„)$ where $T = โˆ‘_{i โˆˆ ๐ข} Tแตข$.
 
 
 **Proposal bulla integrity**   $๐’ซ = \t{Bulla}_\t{Proposal}(p, b_p)$
 **Proposal bulla integrity**   $๐’ซ = \t{Bulla}_\t{Proposal}(p, b_p)$
 
 
-**Yes vote commit**   $V_\t{yes} = \t{PedersenCommit}(ov, b_y)$
+**Yes vote commit**   $V_\t{yes} = \t{PedersenCommit}(ov, \t{Lift}แตฅ(b_y))$
 
 
-**Total vote value commit**   $V_\t{all} = \t{PedersenCommit}(v, bแตฅ)$ where
+**Total vote value commit**   $V_\t{all} = \t{PedersenCommit}(v, \t{Lift}แตฅ(bแตฅ))$ where
 $V_\t{all} = โˆ‘_{i โˆˆ ๐ข} i.V$ should also hold.
 $V_\t{all} = โˆ‘_{i โˆˆ ๐ข} i.V$ should also hold.
 
 
 **Vote option boolean**   enforce $o โˆˆ \{ 0, 1 \}$.
 **Vote option boolean**   enforce $o โˆˆ \{ 0, 1 \}$.
@@ -285,6 +296,10 @@ $V_\t{all} = โˆ‘_{i โˆˆ ๐ข} i.V$ should also hold.
 **Proposal not expired**   let $t_\t{end} = โ„•โ‚†โ‚„2๐”ฝโ‚š(p.tโ‚€) + โ„•โ‚†โ‚„2๐”ฝโ‚š(p.D)$,
 **Proposal not expired**   let $t_\t{end} = โ„•โ‚†โ‚„2๐”ฝโ‚š(p.tโ‚€) + โ„•โ‚†โ‚„2๐”ฝโ‚š(p.D)$,
 and then check $t_\t{now} < t_\t{end}$.
 and then check $t_\t{now} < t_\t{end}$.
 
 
+**Verifiable encryption of vote commit secrets** &emsp;
+let $๐ง = (o, b_y, v, bแตฅ)$, and verify
+$\t{enc\_vote} = \t{ElGamal}.\t{Encrypt}(๐ง, \t{esk}, d.\t{PK})$.
+
 For each input $i โˆˆ ๐ข$, perform the following checks:
 For each input $i โˆˆ ๐ข$, perform the following checks:
 
 
 &emsp; **Valid input merkle root** &emsp; check that $i.R_\t{coin}$ is the
 &emsp; **Valid input merkle root** &emsp; check that $i.R_\t{coin}$ is the
@@ -427,29 +442,11 @@ DAO treasury but be unspendable.
 
 
 Define the DAO AuthMoneyTransfer function params
 Define the DAO AuthMoneyTransfer function params
 $$ \begin{aligned}
 $$ \begin{aligned}
-  ๐’ž_\t{enc} &โˆˆ \t{AuthCoinAttrs}^* \\
-  \t{EPK}_\t{DAO} &โˆˆ โ„™โ‚š \\
-  v_\t{DAO}^\t{enc} &โˆˆ ๐”ฝโ‚š \\
-  ฯ„_\t{DAO}^\t{enc} &โˆˆ ๐”ฝโ‚š \\
-  ฮถ_\t{DAO}^\t{enc} &โˆˆ ๐”ฝโ‚š \\
+  ๐’ž_\t{enc} &โˆˆ \t{ElGamalEncNote}โ‚…^* \\
+  ๐’Ÿ_\t{enc} &โˆˆ \t{ElGamalEncNote}โ‚ƒ
 \end{aligned} $$
 \end{aligned} $$
 
 
-Define the DAO $\t{AuthCoinAttrs}$ as
-$$ \begin{aligned}
-  \t{AuthCoinAttrs}.\t{EPK} &โˆˆ โ„™โ‚š \\
-  \t{AuthCoinAttrs}.v^\t{enc} &โˆˆ ๐”ฝโ‚š \\
-  \t{AuthCoinAttrs}.ฯ„^\t{enc} &โˆˆ ๐”ฝโ‚š \\
-  \t{AuthCoinAttrs}.ฮถ^\t{enc} &โˆˆ ๐”ฝโ‚š \\
-  \t{AuthCoinAttrs}.\t{SH}^\t{enc} &โˆˆ ๐”ฝโ‚š \\
-  \t{AuthCoinAttrs}.\t{UD}^\t{enc} &โˆˆ ๐”ฝโ‚š \\
-\end{aligned} $$
-which corresponds to encrypted coin attributes.
-In both cases $\t{EPK}$ refers to the ephemeral key used to construct a
-diffie-hellman shared secret. We then derive further blinding factors from this
-shared secret which we use to encrypt the [coin attributes](../money/model.md#coin)
-$v, ฯ„, ฮถ, \t{SH}, \t{UD}$.
-
-This provides verifiable note encryption for all output coins in the sibling `Money::transfer()` call.
+This provides verifiable note encryption for all output coins in the sibling `Money::transfer()` call as well as the DAO change coin.
 
 
 ```rust
 ```rust
 {{#include ../../../../../src/contract/dao/src/model.rs:dao-auth_xfer-params}}
 {{#include ../../../../../src/contract/dao/src/model.rs:dao-auth_xfer-params}}
@@ -480,7 +477,7 @@ $$ \begin{aligned}
   v_\t{DAO} &โˆˆ ๐”ฝโ‚š \\
   v_\t{DAO} &โˆˆ ๐”ฝโ‚š \\
   ฯ„_\t{DAO} &โˆˆ ๐”ฝโ‚š \\
   ฯ„_\t{DAO} &โˆˆ ๐”ฝโ‚š \\
   ฮถ_\t{DAO} &โˆˆ ๐”ฝโ‚š \\
   ฮถ_\t{DAO} &โˆˆ ๐”ฝโ‚š \\
-  e &โˆˆ ๐”ฝโ‚š \\
+  \t{esk} &โˆˆ ๐”ฝโ‚š \\
 \end{aligned} $$
 \end{aligned} $$
 
 
 Attach a proof $ฯ€_\t{auth}$ such that the
 Attach a proof $ฯ€_\t{auth}$ such that the
@@ -499,19 +496,9 @@ where $๐’ซ $ matches the value in `DAO::exec()`, and $p.๐’œ  = ๐’œ $.
 $$ C_\t{DAO} = \t{Coin}(d.\t{PK}, v_\t{DAO}, ฯ„_\t{DAO}, ฮถ_\t{DAO},
 $$ C_\t{DAO} = \t{Coin}(d.\t{PK}, v_\t{DAO}, ฯ„_\t{DAO}, ฮถ_\t{DAO},
                         \t{CID}_\t{DAO}, ๐’Ÿ ) $$
                         \t{CID}_\t{DAO}, ๐’Ÿ ) $$
 
 
-**Diffie-Hellman shared secret** &emsp; $\t{EPK}_\t{DAO} = \t{DerivePubKey}(e)$.
-Now we create the shared secret with the DAO pubkey.
-$$ P = \t{Lift}แตฅ(e) d.\t{PK} $$
-$$ ฮฑ = \t{PoseidonHash}(\mathcal{X}(P), \mathcal{Y}(P)) $$
-This is then used in the following three checks.
-
-**Verifiable encryption for value** &emsp; $v_\t{DAO}^\t{enc} = v_\t{DAO} + ฮฑ$
-
-**Verifiable encryption for token ID** &emsp; let $ฮฑโ‚ = \t{PoseidonHash}(ฮฑ, 1_{๐”ฝโ‚š})$
-then $ฯ„_\t{DAO}^\t{enc} = ฯ„_\t{DAO} + ฮฑโ‚$.
-
-**Verifiable encryption for serial** &emsp; let $ฮฑโ‚‚ = \t{PoseidonHash}(ฮฑ, 2_{๐”ฝโ‚š})$
-then $ฮถ_\t{DAO}^\t{enc} = ฮถ_\t{DAO} + ฮฑโ‚‚$.
+**Verifiable DAO change coin note encryption** &emsp;
+let $๐ง = (v_\t{DAO}, ฯ„_\t{DAO}, ฮถ_\t{DAO})$, and verify
+$๐’Ÿ_\t{enc} = \t{ElGamal}.\t{Encrypt}(๐ง, \t{esk}, d.\t{PK})$.
 
 
 Then we do the same for each output coin of `Money::transfer()`.
 Then we do the same for each output coin of `Money::transfer()`.
 For $k โˆˆ [n]$, let $a = (๐’ž_\t{enc})โ‚–$ and $C$ be the $k$th output coin from
 For $k โˆˆ [n]$, let $a = (๐’ž_\t{enc})โ‚–$ and $C$ be the $k$th output coin from
@@ -525,19 +512,9 @@ Attach a proof $ฯ€โ‚–$ such that the following relations hold:
 
 
 &emsp; **Coin integrity** &emsp; $C = \t{Coin}(c)$
 &emsp; **Coin integrity** &emsp; $C = \t{Coin}(c)$
 
 
-&emsp; **Diffie-Hellman shared secret** &emsp; $a.\t{EPK} = \t{DerivePubKey}(e)$.
-Now we create the shared secret with the DAO pubkey.
-$$ P = \t{Lift}แตฅ(e) c.\t{PK} $$
-$$ ฮฑ = \t{PoseidonHash}(\mathcal{X}(P), \mathcal{Y}(P)) $$
-This is then used in the following three checks.
-
-&emsp; **Verifiable encryption for value** &emsp; $a.v^\t{enc} = c.v + ฮฑ$
-
-&emsp; **Verifiable encryption for token ID** &emsp; let $ฮฑโ‚ = \t{PoseidonHash}(ฮฑ, 1_{๐”ฝโ‚š})$
-then $a.ฯ„^\t{enc} = c.ฯ„ + ฮฑโ‚$.
-
-&emsp; **Verifiable encryption for serial** &emsp; let $ฮฑโ‚‚ = \t{PoseidonHash}(ฮฑ, 2_{๐”ฝโ‚š})$
-then $a.ฮถ^\t{enc} = c.ฮถ + ฮฑโ‚‚$.
+&emsp; **Verifiable output coin note encryption** &emsp;
+let $๐ง = (c.v, c.ฯ„, c.ฮถ, c.\t{SH}, c.\t{UD})$, and verify
+$a = \t{ElGamal}.\t{Encrypt}(๐ง, \t{esk}, d.\t{PK})$.
 
 
 ### Signatures
 ### Signatures
 
 

+ 61 - 4
doc/src/spec/crypto-schemes.md

@@ -233,7 +233,8 @@ To transmit secrets securely to a recipient *without* requiring an out-of-band
 communication channel, we use the [key derivation function](#key-derivation)
 communication channel, we use the [key derivation function](#key-derivation)
 together with [symmetric encryption](#symmetric-encryption).
 together with [symmetric encryption](#symmetric-encryption).
 
 
-Denote the ciphertext space $C = \t{im}(\t{Sym}.\t{Encrypt})$ by $\t{EncNote}$.
+Denote $\t{AeadEncNote}โ‚™ = (E, C)$ where $E$ is the space of *ephemeral
+public keys* and $C$ is the ciphertext space.
 
 
 ### Encryption
 ### Encryption
 
 
@@ -255,9 +256,8 @@ Return $c$
 
 
 ## Decryption
 ## Decryption
 
 
-We let $P โˆˆ โ„™โ‚š$ denote the recipient's public key with corresponding
-secret key $x โˆˆ ๐”ฝโ‚š$. And let $c โˆˆ C = ๐”น^*$ denote the ciphertext note to
-be decrypted.
+We denote the recipient's secret key with $x โˆˆ ๐”ฝโ‚š$.
+Let $c โˆˆ C = ๐”น^*$ denote the ciphertext note to be decrypted.
 
 
 The recipient receives the *ephemeral public key* $\t{EPK} โˆˆ โ„™โ‚š$ used to decrypt
 The recipient receives the *ephemeral public key* $\t{EPK} โˆˆ โ„™โ‚š$ used to decrypt
 the ciphertext note $c$.
 the ciphertext note $c$.
@@ -269,3 +269,60 @@ Let $k = \t{KDF}(\t{shared\_secret}, \t{EPK})$
 Let $\t{note} = \t{Sym}.\t{Decrypt}(k, c)$. If $\t{note} = โŸ‚$ then
 Let $\t{note} = \t{Sym}.\t{Decrypt}(k, c)$. If $\t{note} = โŸ‚$ then
 return $โŸ‚$, otherwise return $\t{note}$.
 return $โŸ‚$, otherwise return $\t{note}$.
 
 
+## Verifiable In-Band Secret Distribution
+
+Let $\t{PoseidonHash}$ be defined as in the section [PoseidonHash Function](#poseidonhash-function).
+
+This scheme is verifiable inside ZK using the [Pallas and Vesta](#pallas-and-vesta) curves.
+
+Let $n โˆˆ โ„•$.
+Denote the plaintext space $N$ and ciphertext $C$ with $N = C = ๐”ฝโ‚šโฟ$.
+$$ \t{ElGamal}.\t{Encrypt}โ‚™ : N ร— ๐”ฝโ‚š ร— โ„™โ‚š โ†’ C ร— โ„™โ‚š $$
+$$ \t{ElGamal}.\t{Decrypt}โ‚™ : C ร— ๐”ฝโ‚š ร— โ„™โ‚š โ†’ N $$
+
+Denote $\t{ElGamalEncNote}โ‚™ = (E, C)$ where $E$ is the space of *ephemeral
+public keys* and $C$ is the ciphertext space.
+
+See `ElGamalEncryptedNote` in `src/sdk/src/crypto/note.rs`.
+
+### Encryption
+
+We let $P โˆˆ โ„™โ‚š$ denote the recipient's public key.
+Let $\t{note} โˆˆ N = ๐”ฝโ‚šโฟ$ with $n โˆˆ โ„•$ denote the plaintext note to be encrypted.
+
+Let $\t{esk} โˆˆ ๐”ฝโ‚š$ be the randomly generated *ephemeral secret key*.
+
+Let $\t{EPK} = \t{DerivePubKey}(\t{esk}) โˆˆ โ„™โ‚š$
+
+Let $\t{shared\_secret} = \t{KeyAgree}(\t{esk}, P)$
+
+Let $k = \t{PoseidonHash}(\cX(\t{shared\_secret}), \cY(\t{shared\_secret}))$
+
+For $i โˆˆ [n]$ then compute:
+
+&emsp; Let $bแตข = \t{PoseidonHash}(k, i)$
+
+&emsp; Let $cแตข = \t{note}แตข + bแตข$
+
+Return $๐œ = (cแตข) โˆˆ C$ and $\t{EPK}$
+
+### Decryption
+
+We denote the recipient's secret key with $x โˆˆ ๐”ฝโ‚š$.
+Let $\t{note} โˆˆ N = ๐”ฝโ‚š^n$ with $n โˆˆ โ„•$ denote the plaintext note to be encrypted.
+
+The recipient receives the *ephemeral public key* $\t{EPK} โˆˆ โ„™โ‚š$ used to decrypt
+the ciphertext note $๐œ โˆˆ C = ๐”ฝโ‚šโฟ$.
+
+Let $\t{shared\_secret} = \t{KeyAgree}(x, \t{EPK})$
+
+Let $k = \t{PoseidonHash}(\cX(\t{shared\_secret}), \cY(\t{shared\_secret}))$
+
+For $i โˆˆ [n]$ then compute:
+
+&emsp; Let $bแตข = \t{PoseidonHash}(k, i)$
+
+&emsp; Let $\t{note}แตข = cแตข - bแตข$
+
+Return $\t{note} = (\t{note}แตข)$
+