فهرست منبع

daod: further simplify vote pederson commitment naming

lunar-mining 3 سال پیش
والد
کامیت
e1cfc5f897

+ 18 - 18
bin/daod/proof/dao-exec.zk

@@ -22,10 +22,10 @@ contract "DaoExec" {
     Base dao_bulla_blind,
 
     # votes
-    Base yes_vote_values,
-    Base all_vote_values,
-    Scalar all_vote_blinds,
-    Scalar all_vote_value_blinds,
+    Base yes_votes_value,
+    Base all_votes_value,
+    Scalar yes_votes_blind,
+    Scalar all_votes_blind,
     
     # outputs + inputs
     Base user_serial,
@@ -98,25 +98,25 @@ circuit "DaoExec" {
 
     # Create pedersen commits for win_votes, and total_votes
     # and make public
-    yes_vote_values_c = ec_mul_short(yes_vote_values, VALUE_COMMIT_VALUE);
-    all_vote_blinds_c = ec_mul(all_vote_blinds, VALUE_COMMIT_RANDOM);
-    weighted_votes_commit = ec_add(yes_vote_values_c, all_vote_blinds_c);
+    yes_votes_value_c = ec_mul_short(yes_votes_value, VALUE_COMMIT_VALUE);
+    yes_votes_blind_c = ec_mul(yes_votes_blind, VALUE_COMMIT_RANDOM);
+    yes_votes_commit = ec_add(yes_votes_value_c, yes_votes_blind_c);
 
     # get curve points and constrain
-	weighted_votes_commit_x = ec_get_x(weighted_votes_commit);
-	weighted_votes_commit_y = ec_get_y(weighted_votes_commit);
-	constrain_instance(weighted_votes_commit_x);
-	constrain_instance(weighted_votes_commit_y);
+	yes_votes_commit_x = ec_get_x(yes_votes_commit);
+	yes_votes_commit_y = ec_get_y(yes_votes_commit);
+	constrain_instance(yes_votes_commit_x);
+	constrain_instance(yes_votes_commit_y);
 
-    all_vote_values_c = ec_mul_short(all_vote_values, VALUE_COMMIT_VALUE);
-    all_vote_value_blinds_c = ec_mul(all_vote_value_blinds, VALUE_COMMIT_RANDOM);
-    all_vote_values_commit = ec_add(all_vote_values_c, all_vote_value_blinds_c);
+    all_votes_c = ec_mul_short(all_votes_value, VALUE_COMMIT_VALUE);
+    all_votes_blind_c = ec_mul(all_votes_blind, VALUE_COMMIT_RANDOM);
+    all_votes_commit = ec_add(all_votes_c, all_votes_blind_c);
 
     # get curve points and constrain
-	all_vote_values_commit_x = ec_get_x(all_vote_values_commit);
-	all_vote_values_commit_y = ec_get_y(all_vote_values_commit);
-	constrain_instance(all_vote_values_commit_x);
-	constrain_instance(all_vote_values_commit_y);
+	all_votes_commit_x = ec_get_x(all_votes_commit);
+	all_votes_commit_y = ec_get_y(all_votes_commit);
+	constrain_instance(all_votes_commit_x);
+	constrain_instance(all_votes_commit_y);
 
     # Create pedersen commit for input_value and make public
     

+ 23 - 22
bin/daod/proof/dao-vote-main.zk

@@ -23,11 +23,11 @@ contract "DaoVoteMain" {
 
     # Is the vote yes or no
     Base vote_option,
-    Scalar vote_option_blind,
+    Scalar yes_vote_blind,
 
     # Total amount of capital allocated to vote
-    Base value,
-    Scalar value_blind,
+    Base all_votes_value,
+    Scalar all_votes_blind,
 
     # Check the inputs and this proof are for the same token
     Base gov_token_blind,
@@ -67,28 +67,29 @@ circuit "DaoVoteMain" {
     # TODO: we need to check the proposal isn't invalidated
     # that is expired or already executed.
 
+    # normally we call this yes vote
 	# Pedersen commitment for vote option
-    weighted_vote = base_mul(vote_option, value);
-	vote_co = ec_mul_short(weighted_vote, VALUE_COMMIT_VALUE);
-	vote_cr = ec_mul(vote_option_blind, VALUE_COMMIT_RANDOM);
-	vote_commit = ec_add(vote_co, vote_cr);
-	# Since vote_commit is a curve point, we fetch its coordinates
-	# and constrain them:
-	vote_commit_x = ec_get_x(vote_commit);
-	vote_commit_y = ec_get_y(vote_commit);
-	constrain_instance(vote_commit_x);
-	constrain_instance(vote_commit_y);
+    yes_votes_value = base_mul(vote_option, all_votes_value);
+	yes_votes_value_c = ec_mul_short(yes_votes_value, VALUE_COMMIT_VALUE);
+	yes_votes_blind_c = ec_mul(yes_vote_blind, VALUE_COMMIT_RANDOM);
+	yes_votes_commit = ec_add(yes_votes_value_c, yes_votes_blind_c);
+
+    # get curve points and constrain
+	yes_votes_commit_x = ec_get_x(yes_votes_commit);
+	yes_votes_commit_y = ec_get_y(yes_votes_commit);
+	constrain_instance(yes_votes_commit_x);
+	constrain_instance(yes_votes_commit_y);
 
 	# Pedersen commitment for vote value
-	vcv = ec_mul_short(value, VALUE_COMMIT_VALUE);
-	vcr = ec_mul(value_blind, VALUE_COMMIT_RANDOM);
-	value_commit = ec_add(vcv, vcr);
-	# Since value_commit is a curve point, we fetch its coordinates
-	# and constrain them:
-	value_commit_x = ec_get_x(value_commit);
-	value_commit_y = ec_get_y(value_commit);
-	constrain_instance(value_commit_x);
-	constrain_instance(value_commit_y);
+	all_votes_c = ec_mul_short(all_votes_value, VALUE_COMMIT_VALUE);
+	all_votes_blind_c = ec_mul(all_votes_blind, VALUE_COMMIT_RANDOM);
+	all_votes_commit = ec_add(all_votes_c, all_votes_blind_c);
+
+    # get curve points and constrain
+	all_votes_commit_x = ec_get_x(all_votes_commit);
+	all_votes_commit_y = ec_get_y(all_votes_commit);
+	constrain_instance(all_votes_commit_x);
+	constrain_instance(all_votes_commit_y);
 
     # This is the main check
     # TODO: vote option should be 0 or 1

+ 12 - 14
bin/daod/src/dao_contract/exec/validate.rs

@@ -59,18 +59,16 @@ pub struct CallData {
     pub proposal: pallas::Base,
     pub coin_0: pallas::Base,
     pub coin_1: pallas::Base,
-    pub weighted_votes_commit: pallas::Point,
-    pub all_vote_values_commit: pallas::Point,
+    pub yes_votes_commit: pallas::Point,
+    pub all_votes_commit: pallas::Point,
     pub input_value_commit: pallas::Point,
 }
 
 impl CallDataBase for CallData {
     fn zk_public_values(&self) -> Vec<(String, Vec<DrkCircuitField>)> {
-        let weighted_votes_commit_coords =
-            self.weighted_votes_commit.to_affine().coordinates().unwrap();
+        let yes_votes_commit_coords = self.yes_votes_commit.to_affine().coordinates().unwrap();
 
-        let all_vote_values_commit_coords =
-            self.all_vote_values_commit.to_affine().coordinates().unwrap();
+        let all_votes_commit_coords = self.all_votes_commit.to_affine().coordinates().unwrap();
 
         let input_value_commit_coords = self.input_value_commit.to_affine().coordinates().unwrap();
 
@@ -80,10 +78,10 @@ impl CallDataBase for CallData {
                 self.proposal,
                 self.coin_0,
                 self.coin_1,
-                *weighted_votes_commit_coords.x(),
-                *weighted_votes_commit_coords.y(),
-                *all_vote_values_commit_coords.x(),
-                *all_vote_values_commit_coords.y(),
+                *yes_votes_commit_coords.x(),
+                *yes_votes_commit_coords.y(),
+                *all_votes_commit_coords.x(),
+                *all_votes_commit_coords.y(),
                 *input_value_commit_coords.x(),
                 *input_value_commit_coords.y(),
                 *super::FUNC_ID,
@@ -177,12 +175,12 @@ pub fn state_transition(
         .expect("Return type is not of type State");
     let proposal_votes = state.proposal_votes.get(&HashableBase(call_data.proposal)).unwrap();
 
-    // 4. check win/total_vote_commit is the same as in ProposalVote
-    if proposal_votes.weighted_vote_commits != call_data.weighted_votes_commit {
+    // 4. check yes_votes_commit is the same as in ProposalVote
+    if proposal_votes.yes_votes_commit != call_data.yes_votes_commit {
         return Err(Error::InvalidVoteCommit)
     }
-    // 5. also check total_vote_commit
-    if proposal_votes.all_vote_value_commits != call_data.all_vote_values_commit {
+    // 5. also check all_votes_commit
+    if proposal_votes.all_votes_commit != call_data.all_votes_commit {
         return Err(Error::InvalidVoteCommit)
     }
 

+ 18 - 21
bin/daod/src/dao_contract/exec/wallet.rs

@@ -23,10 +23,10 @@ use crate::{
 pub struct Builder {
     pub proposal: Proposal,
     pub dao: DaoParams,
-    pub yes_vote_values: u64,
-    pub all_vote_values: u64,
-    pub all_vote_blinds: pallas::Scalar,
-    pub all_vote_value_blinds: pallas::Scalar,
+    pub yes_votes_value: u64,
+    pub all_votes_value: u64,
+    pub yes_votes_blind: pallas::Scalar,
+    pub all_votes_blind: pallas::Scalar,
     pub user_serial: pallas::Base,
     pub user_coin_blind: pallas::Base,
     pub dao_serial: pallas::Base,
@@ -104,14 +104,11 @@ impl Builder {
             self.dao_coin_blind,
         ]);
 
-        let weighted_votes_commit =
-            pedersen_commitment_u64(self.yes_vote_values, self.all_vote_blinds);
-        let weighted_votes_commit_coords = weighted_votes_commit.to_affine().coordinates().unwrap();
+        let yes_votes_commit = pedersen_commitment_u64(self.yes_votes_value, self.yes_votes_blind);
+        let yes_votes_commit_coords = yes_votes_commit.to_affine().coordinates().unwrap();
 
-        let all_vote_values_commit =
-            pedersen_commitment_u64(self.all_vote_values, self.all_vote_value_blinds);
-        let all_vote_values_commit_coords =
-            all_vote_values_commit.to_affine().coordinates().unwrap();
+        let all_votes_commit = pedersen_commitment_u64(self.all_votes_value, self.all_votes_blind);
+        let all_votes_commit_coords = all_votes_commit.to_affine().coordinates().unwrap();
 
         let input_value_commit = pedersen_commitment_u64(self.input_value, self.input_value_blind);
         let input_value_commit_coords = input_value_commit.to_affine().coordinates().unwrap();
@@ -142,10 +139,10 @@ impl Builder {
             Witness::Base(Value::known(*dao_pubkey_coords.y())),
             Witness::Base(Value::known(self.dao.bulla_blind)),
             // votes
-            Witness::Base(Value::known(pallas::Base::from(self.yes_vote_values))),
-            Witness::Base(Value::known(pallas::Base::from(self.all_vote_values))),
-            Witness::Scalar(Value::known(self.all_vote_blinds)),
-            Witness::Scalar(Value::known(self.all_vote_value_blinds)),
+            Witness::Base(Value::known(pallas::Base::from(self.yes_votes_value))),
+            Witness::Base(Value::known(pallas::Base::from(self.all_votes_value))),
+            Witness::Scalar(Value::known(self.yes_votes_blind)),
+            Witness::Scalar(Value::known(self.all_votes_blind)),
             // outputs + inputs
             Witness::Base(Value::known(self.user_serial)),
             Witness::Base(Value::known(self.user_coin_blind)),
@@ -163,10 +160,10 @@ impl Builder {
             proposal_bulla,
             coin_0,
             coin_1,
-            *weighted_votes_commit_coords.x(),
-            *weighted_votes_commit_coords.y(),
-            *all_vote_values_commit_coords.x(),
-            *all_vote_values_commit_coords.y(),
+            *yes_votes_commit_coords.x(),
+            *yes_votes_commit_coords.y(),
+            *all_votes_commit_coords.x(),
+            *all_votes_commit_coords.y(),
             *input_value_commit_coords.x(),
             *input_value_commit_coords.y(),
             self.hook_dao_exec,
@@ -185,8 +182,8 @@ impl Builder {
             proposal: proposal_bulla,
             coin_0,
             coin_1,
-            weighted_votes_commit,
-            all_vote_values_commit,
+            yes_votes_commit,
+            all_votes_commit,
             input_value_commit,
         };
 

+ 6 - 6
bin/daod/src/dao_contract/state.rs

@@ -14,11 +14,11 @@ pub struct DaoBulla(pub pallas::Base);
 type MerkleTree = BridgeTree<MerkleNode, MERKLE_DEPTH>;
 
 pub struct ProposalVotes {
-    // TODO: might be more logical to have 'yes_vote_commits' and 'no_vote_commits'
-    /// Weighted vote commits
-    pub weighted_vote_commits: pallas::Point,
+    // TODO: might be more logical to have 'yes_votes_commit' and 'no_votes_commit'
+    /// Weighted vote commit
+    pub yes_votes_commit: pallas::Point,
     /// All value staked in the vote
-    pub all_vote_value_commits: pallas::Point,
+    pub all_votes_commit: pallas::Point,
     /// Vote nullifiers
     pub vote_nulls: Vec<Nullifier>,
 }
@@ -69,8 +69,8 @@ impl State {
         self.proposal_votes.insert(
             HashableBase(bulla),
             ProposalVotes {
-                weighted_vote_commits: pallas::Point::identity(),
-                all_vote_value_commits: pallas::Point::identity(),
+                yes_votes_commit: pallas::Point::identity(),
+                all_votes_commit: pallas::Point::identity(),
                 vote_nulls: Vec::new(),
             },
         );

+ 19 - 20
bin/daod/src/dao_contract/vote/validate.rs

@@ -56,12 +56,12 @@ pub struct CallData {
 impl CallDataBase for CallData {
     fn zk_public_values(&self) -> Vec<(String, Vec<DrkCircuitField>)> {
         let mut zk_publics = Vec::new();
-        let mut total_value_commit = pallas::Point::identity();
+        let mut all_votes_commit = pallas::Point::identity();
 
         assert!(self.inputs.len() > 0, "inputs length cannot be zero");
         for input in &self.inputs {
-            total_value_commit += input.value_commit;
-            let value_coords = input.value_commit.to_affine().coordinates().unwrap();
+            all_votes_commit += input.vote_commit;
+            let value_coords = input.vote_commit.to_affine().coordinates().unwrap();
 
             let sigpub_coords = input.signature_public.0.to_affine().coordinates().unwrap();
 
@@ -79,20 +79,19 @@ impl CallDataBase for CallData {
             ));
         }
 
-        let weighted_vote_commit_coords =
-            self.header.weighted_vote_commit.to_affine().coordinates().unwrap();
+        let yes_vote_commit_coords = self.header.yes_vote_commit.to_affine().coordinates().unwrap();
 
-        let value_commit_coords = total_value_commit.to_affine().coordinates().unwrap();
+        let vote_commit_coords = all_votes_commit.to_affine().coordinates().unwrap();
 
         zk_publics.push((
             "dao-vote-main".to_string(),
             vec![
                 self.header.token_commit,
                 self.header.proposal_bulla,
-                *weighted_vote_commit_coords.x(),
-                *weighted_vote_commit_coords.y(),
-                *value_commit_coords.x(),
-                *value_commit_coords.y(),
+                *yes_vote_commit_coords.x(),
+                *yes_vote_commit_coords.y(),
+                *vote_commit_coords.x(),
+                *vote_commit_coords.y(),
             ],
         ));
 
@@ -123,14 +122,14 @@ impl CallDataBase for CallData {
 pub struct Header {
     pub token_commit: pallas::Base,
     pub proposal_bulla: pallas::Base,
-    pub weighted_vote_commit: pallas::Point,
+    pub yes_vote_commit: pallas::Point,
     pub enc_note: EncryptedNote2,
 }
 
 #[derive(Clone, SerialEncodable, SerialDecodable)]
 pub struct Input {
     pub nullifier: Nullifier,
-    pub value_commit: pallas::Point,
+    pub vote_commit: pallas::Point,
     pub merkle_root: MerkleNode,
     pub signature_public: PublicKey,
 }
@@ -160,7 +159,7 @@ pub fn state_transition(
 
     // Check the merkle roots for the input coins are valid
     let mut vote_nulls = Vec::new();
-    let mut total_value_commit = pallas::Point::identity();
+    let mut all_vote_commit = pallas::Point::identity();
     for input in &call_data.inputs {
         let money_state = states.lookup::<MoneyState>(*money_contract::CONTRACT_ID).unwrap();
         if !money_state.is_valid_merkle(&input.merkle_root) {
@@ -175,7 +174,7 @@ pub fn state_transition(
             return Err(Error::DoubleVote)
         }
 
-        total_value_commit += input.value_commit;
+        all_vote_commit += input.vote_commit;
 
         vote_nulls.push(input.nullifier);
     }
@@ -183,8 +182,8 @@ pub fn state_transition(
     Ok(Box::new(Update {
         proposal_bulla: call_data.header.proposal_bulla,
         vote_nulls,
-        weighted_vote_commit: call_data.header.weighted_vote_commit,
-        value_commit: total_value_commit,
+        yes_vote_commit: call_data.header.yes_vote_commit,
+        all_vote_commit,
     }))
 }
 
@@ -192,16 +191,16 @@ pub fn state_transition(
 pub struct Update {
     proposal_bulla: pallas::Base,
     vote_nulls: Vec<Nullifier>,
-    pub weighted_vote_commit: pallas::Point,
-    pub value_commit: pallas::Point,
+    pub yes_vote_commit: pallas::Point,
+    pub all_vote_commit: pallas::Point,
 }
 
 impl UpdateBase for Update {
     fn apply(mut self: Box<Self>, states: &mut StateRegistry) {
         let state = states.lookup_mut::<DaoState>(*dao_contract::CONTRACT_ID).unwrap();
         let votes_info = state.lookup_proposal_votes_mut(self.proposal_bulla).unwrap();
-        votes_info.weighted_vote_commits += self.weighted_vote_commit;
-        votes_info.all_vote_value_commits += self.value_commit;
+        votes_info.yes_votes_commit += self.yes_vote_commit;
+        votes_info.all_votes_commit += self.all_vote_commit;
         votes_info.vote_nulls.append(&mut self.vote_nulls);
     }
 }

+ 32 - 43
bin/daod/src/dao_contract/vote/wallet.rs

@@ -34,12 +34,11 @@ use log::debug;
 #[derive(SerialEncodable, SerialDecodable)]
 pub struct Note {
     pub vote: Vote,
-    pub value: u64,
-    pub value_blind: pallas::Scalar,
+    pub vote_value: u64,
+    pub vote_value_blind: pallas::Scalar,
 }
 
 #[derive(SerialEncodable, SerialDecodable)]
-// All info needed for vote and value commits
 pub struct Vote {
     pub vote_option: bool,
     pub vote_option_blind: pallas::Scalar,
@@ -71,14 +70,14 @@ impl Builder {
         let gov_token_blind = pallas::Base::random(&mut OsRng);
 
         let mut inputs = vec![];
-        let mut value = 0;
-        let mut value_blind = pallas::Scalar::from(0);
+        let mut vote_value = 0;
+        let mut vote_value_blind = pallas::Scalar::from(0);
 
         for input in self.inputs {
-            let input_value_blind = pallas::Scalar::random(&mut OsRng);
+            let value_blind = pallas::Scalar::random(&mut OsRng);
 
-            value += input.note.value;
-            value_blind += input_value_blind;
+            vote_value += input.note.value;
+            vote_value_blind += value_blind;
 
             let signature_public = PublicKey::from_secret(input.signature_secret);
 
@@ -103,7 +102,7 @@ impl Builder {
                 Witness::Base(Value::known(pallas::Base::from(note.value))),
                 Witness::Base(Value::known(note.token_id)),
                 Witness::Base(Value::known(note.coin_blind)),
-                Witness::Scalar(Value::known(input_value_blind)),
+                Witness::Scalar(Value::known(vote_value_blind)),
                 Witness::Base(Value::known(gov_token_blind)),
                 Witness::Uint32(Value::known(leaf_pos.try_into().unwrap())),
                 Witness::MerklePath(Value::known(input.merkle_path.clone().try_into().unwrap())),
@@ -143,23 +142,19 @@ impl Builder {
 
             let nullifier = poseidon_hash::<2>([input.secret.0, note.serial]);
 
-            let value_commit = pedersen_commitment_u64(note.value, value_blind);
-            let value_coords = value_commit.to_affine().coordinates().unwrap();
-            let value_commit_x = *value_coords.x();
-            let value_commit_y = *value_coords.y();
+            let vote_commit = pedersen_commitment_u64(note.value, vote_value_blind);
+            let vote_commit_coords = vote_commit.to_affine().coordinates().unwrap();
 
             let sigpub_coords = signature_public.0.to_affine().coordinates().unwrap();
-            let sigpub_x = *sigpub_coords.x();
-            let sigpub_y = *sigpub_coords.y();
 
             let public_inputs = vec![
                 nullifier,
-                value_commit_x,
-                value_commit_y,
+                *vote_commit_coords.x(),
+                *vote_commit_coords.y(),
                 token_commit,
                 merkle_root.0,
-                sigpub_x,
-                sigpub_y,
+                *sigpub_coords.x(),
+                *sigpub_coords.y(),
             ];
 
             let circuit = ZkCircuit::new(prover_witnesses, zk_bin);
@@ -171,7 +166,7 @@ impl Builder {
 
             let input = Input {
                 nullifier: Nullifier(nullifier),
-                value_commit,
+                vote_commit,
                 merkle_root,
                 signature_public,
             };
@@ -205,8 +200,6 @@ impl Builder {
         let proposal_bulla = poseidon_hash::<8>([
             *proposal_dest_coords.x(),
             *proposal_dest_coords.y(),
-            //proposal_dest_x,
-            //proposal_dest_y,
             proposal_amount,
             self.proposal.serial,
             self.proposal.token_id,
@@ -216,20 +209,15 @@ impl Builder {
             self.proposal.blind,
         ]);
 
-        let vote = self.vote.vote_option as u64;
-        assert!(vote == 0 || vote == 1);
+        let vote_option = self.vote.vote_option as u64;
+        assert!(vote_option == 0 || vote_option == 1);
 
-        let weighted_vote = vote * value;
+        let yes_vote_commit =
+            pedersen_commitment_u64(vote_option * vote_value, self.vote.vote_option_blind);
+        let yes_vote_commit_coords = yes_vote_commit.to_affine().coordinates().unwrap();
 
-        let weighted_vote_commit =
-            pedersen_commitment_u64(weighted_vote, self.vote.vote_option_blind);
-        debug!(target: "demo::dao_contract::vote::wallet::Builder", "weighted vote commit: {:?}", weighted_vote_commit);
-        let vote_coords = weighted_vote_commit.to_affine().coordinates().unwrap();
-        let vote = pallas::Base::from(vote);
-
-        let value_commit = pedersen_commitment_u64(value, value_blind);
-        let value_coords = value_commit.to_affine().coordinates().unwrap();
-        let value_base = pallas::Base::from(value);
+        let all_vote_commit = pedersen_commitment_u64(vote_value, vote_value_blind);
+        let all_vote_commit_coords = all_vote_commit.to_affine().coordinates().unwrap();
 
         let zk_info = zk_bins.lookup(&"dao-vote-main".to_string()).unwrap();
         let zk_info = if let ZkContractInfo::Binary(info) = zk_info {
@@ -256,11 +244,11 @@ impl Builder {
             Witness::Base(Value::known(*dao_pubkey_coords.y())),
             Witness::Base(Value::known(self.dao.bulla_blind)),
             // Vote
-            Witness::Base(Value::known(vote)),
+            Witness::Base(Value::known(pallas::Base::from(vote_option))),
             Witness::Scalar(Value::known(self.vote.vote_option_blind)),
             // Total number of gov tokens allocated
-            Witness::Base(Value::known(value_base)),
-            Witness::Scalar(Value::known(value_blind)),
+            Witness::Base(Value::known(pallas::Base::from(vote_value))),
+            Witness::Scalar(Value::known(vote_value_blind)),
             // gov token
             Witness::Base(Value::known(gov_token_blind)),
         ];
@@ -268,10 +256,11 @@ impl Builder {
         let public_inputs = vec![
             token_commit,
             proposal_bulla,
-            *vote_coords.x(),
-            *vote_coords.y(),
-            *value_coords.x(),
-            *value_coords.y(),
+            // this should be a value commit??
+            *yes_vote_commit_coords.x(),
+            *yes_vote_commit_coords.y(),
+            *all_vote_commit_coords.x(),
+            *all_vote_commit_coords.y(),
         ];
 
         let circuit = ZkCircuit::new(prover_witnesses, zk_bin);
@@ -282,10 +271,10 @@ impl Builder {
             .expect("DAO::vote() proving error!");
         proofs.push(main_proof);
 
-        let note = Note { vote: self.vote, value, value_blind };
+        let note = Note { vote: self.vote, vote_value, vote_value_blind };
         let enc_note = note::encrypt(&note, &self.vote_keypair.public).unwrap();
 
-        let header = Header { token_commit, proposal_bulla, weighted_vote_commit, enc_note };
+        let header = Header { token_commit, proposal_bulla, yes_vote_commit, enc_note };
 
         let call_data = CallData { header, inputs };
 

+ 31 - 30
bin/daod/src/demo.rs

@@ -821,6 +821,9 @@ pub async fn demo() -> Result<()> {
         let header = &call_data.header;
         let note: dao_contract::propose::wallet::Note =
             header.enc_note.decrypt(&dao_keypair.secret).unwrap();
+
+        // TODO: check it belongs to DAO bulla
+
         // Return the proposal info
         (note.proposal, call_data.header.proposal_bulla)
     };
@@ -885,6 +888,7 @@ pub async fn demo() -> Result<()> {
     assert!(vote_option == true || vote_option == false);
 
     // We create a new keypair to encrypt the vote.
+    // For the demo MVP, you can just use the dao_keypair secret
     let vote_keypair_1 = Keypair::random(&mut OsRng);
 
     let builder = dao_contract::vote::wallet::Builder {
@@ -945,7 +949,7 @@ pub async fn demo() -> Result<()> {
     };
     debug!(target: "demo", "User 1 voted!");
     debug!(target: "demo", "  vote_option: {}", vote_note_1.vote.vote_option);
-    debug!(target: "demo", "  value: {}", vote_note_1.value);
+    debug!(target: "demo", "  value: {}", vote_note_1.vote_value);
 
     // User 2: NO
 
@@ -1032,7 +1036,7 @@ pub async fn demo() -> Result<()> {
     };
     debug!(target: "demo", "User 2 voted!");
     debug!(target: "demo", "  vote_option: {}", vote_note_2.vote.vote_option);
-    debug!(target: "demo", "  value: {}", vote_note_2.value);
+    debug!(target: "demo", "  value: {}", vote_note_2.vote_value);
 
     // User 3: YES
 
@@ -1119,7 +1123,7 @@ pub async fn demo() -> Result<()> {
     };
     debug!(target: "demo", "User 3 voted!");
     debug!(target: "demo", "  vote_option: {}", vote_note_3.vote.vote_option);
-    debug!(target: "demo", "  value: {}", vote_note_3.value);
+    debug!(target: "demo", "  value: {}", vote_note_3.vote_value);
 
     // Every votes produces a semi-homomorphic encryption of their vote.
     // Which is either yes or no
@@ -1130,12 +1134,13 @@ pub async fn demo() -> Result<()> {
     // voting period.
     // (that's if we want votes to be hidden during voting)
 
-    let mut yes_vote_values = 0;
-    let mut all_vote_values = 0;
-    let mut all_vote_blinds = pallas::Scalar::from(0);
-    let mut all_vote_value_blinds = pallas::Scalar::from(0);
-    let mut all_vote_value_commits = pallas::Point::identity();
-    let mut weighted_vote_commits = pallas::Point::identity();
+    let mut yes_votes_value = 0;
+    let mut yes_votes_blind = pallas::Scalar::from(0);
+    let mut yes_votes_commit = pallas::Point::identity();
+
+    let mut all_votes_value = 0;
+    let mut all_votes_blind = pallas::Scalar::from(0);
+    let mut all_votes_commit = pallas::Point::identity();
 
     // We were previously saving votes to a Vec<Update> for testing.
     // However since Update is now UpdateBase it gets moved into update.apply().
@@ -1146,37 +1151,35 @@ pub async fn demo() -> Result<()> {
         .iter() /*.zip(updates)*/
         .enumerate()
     {
-        let all_vote_value_commit = pedersen_commitment_u64(note.value, note.value_blind);
+        let vote_commit = pedersen_commitment_u64(note.vote_value, note.vote_value_blind);
         //assert!(update.value_commit == all_vote_value_commit);
-        all_vote_value_commits += all_vote_value_commit;
-        all_vote_value_blinds += note.value_blind;
+        all_votes_commit += vote_commit;
+        all_votes_blind += note.vote_value_blind;
 
-        let weighted_vote_commit = pedersen_commitment_u64(
-            note.vote.vote_option as u64 * note.value,
+        let yes_vote_commit = pedersen_commitment_u64(
+            note.vote.vote_option as u64 * note.vote_value,
             note.vote.vote_option_blind,
         );
-        //assert!(update.weighted_vote_commit == weighted_vote_commit);
+        //assert!(update.yes_vote_commit == yes_vote_commit);
 
-        weighted_vote_commits += weighted_vote_commit;
-        all_vote_blinds += note.vote.vote_option_blind;
+        yes_votes_commit += yes_vote_commit;
+        yes_votes_blind += note.vote.vote_option_blind;
 
         let vote_option = note.vote.vote_option;
 
         if vote_option {
-            yes_vote_values += note.value;
+            yes_votes_value += note.vote_value;
         }
-        all_vote_values += note.value;
+        all_votes_value += note.vote_value;
         let vote_result: String = if vote_option { "yes".to_string() } else { "no".to_string() };
 
         debug!("Voter {} voted {}", i, vote_result);
     }
 
-    debug!("Outcome = {} / {}", yes_vote_values, all_vote_values);
+    debug!("Outcome = {} / {}", yes_votes_value, all_votes_value);
 
-    assert!(
-        all_vote_value_commits == pedersen_commitment_u64(all_vote_values, all_vote_value_blinds)
-    );
-    assert!(weighted_vote_commits == pedersen_commitment_u64(yes_vote_values, all_vote_blinds));
+    assert!(all_votes_commit == pedersen_commitment_u64(all_votes_value, all_votes_blind));
+    assert!(yes_votes_commit == pedersen_commitment_u64(yes_votes_value, yes_votes_blind));
 
     ///////////////////////////////////////////////////
     // Execute the vote
@@ -1247,12 +1250,10 @@ pub async fn demo() -> Result<()> {
     let builder = dao_contract::exec::wallet::Builder {
         proposal,
         dao: dao_params,
-        yes_vote_values,
-        all_vote_values,
-        //win_votes_blind: total_vote_blinds,
-        all_vote_blinds,
-        //total_votes_blind: total_value_blinds,
-        all_vote_value_blinds,
+        yes_votes_value,
+        all_votes_value,
+        yes_votes_blind,
+        all_votes_blind,
         user_serial,
         user_coin_blind,
         dao_serial,