Browse Source

daod/ exec: create pederson commitments for win_votes, total_votes, and input_value and make them public

lunar-mining 4 years ago
parent
commit
8d196d14a7

+ 30 - 0
bin/daod/proof/dao-exec.zk

@@ -96,6 +96,36 @@ circuit "DaoExec" {
     );
     constrain_instance(coin_1);
 
+    win_votes_v = ec_mul_short(win_votes, VALUE_COMMIT_VALUE);
+    win_votes_r = ec_mul(win_votes_blind, VALUE_COMMIT_RANDOM);
+    win_votes_commit = ec_add(win_votes_v, win_votes_r);
+
+    # get curve points and constrain
+	win_votes_commit_x = ec_get_x(win_votes_commit);
+	win_votes_commit_y = ec_get_y(win_votes_commit);
+	constrain_instance(win_votes_commit_x);
+	constrain_instance(win_votes_commit_y);
+
+    total_votes_v = ec_mul_short(total_votes, VALUE_COMMIT_VALUE);
+    total_votes_r = ec_mul(total_votes_blind, VALUE_COMMIT_RANDOM);
+    total_votes_commit = ec_add(total_votes_v, total_votes_r);
+
+    # get curve points and constrain
+	total_votes_commit_x = ec_get_x(total_votes_commit);
+	total_votes_commit_y = ec_get_y(total_votes_commit);
+	constrain_instance(total_votes_commit_x);
+	constrain_instance(total_votes_commit_y);
+
+    input_value_v = ec_mul_short(input_value, VALUE_COMMIT_VALUE);
+    input_value_r = ec_mul(input_value_blind, VALUE_COMMIT_RANDOM);
+    input_value_commit = ec_add(input_value_v, input_value_r);
+
+    # get curve points and constrain
+	input_value_x = ec_get_x(input_value_commit);
+	input_value_y = ec_get_y(input_value_commit);
+	constrain_instance(input_value_x);
+	constrain_instance(input_value_y);
+
     # Create pedersen commits for win_votes, and total_votes
     # and make public
 

+ 20 - 1
bin/daod/src/dao_contract/exec/validate.rs

@@ -34,11 +34,30 @@ pub struct CallData {
     pub proposal: pallas::Base,
     pub coin_0: pallas::Base,
     pub coin_1: pallas::Base,
+    pub win_votes_commit_x: pallas::Base,
+    pub win_votes_commit_y: pallas::Base,
+    pub total_votes_commit_x: pallas::Base,
+    pub total_votes_commit_y: pallas::Base,
+    pub input_value_commit_x: pallas::Base,
+    pub input_value_commit_y: pallas::Base,
 }
 
 impl CallDataBase for CallData {
     fn zk_public_values(&self) -> Vec<(String, Vec<DrkCircuitField>)> {
-        vec![("dao-exec".to_string(), vec![self.proposal, self.coin_0, self.coin_1])]
+        vec![(
+            "dao-exec".to_string(),
+            vec![
+                self.proposal,
+                self.coin_0,
+                self.coin_1,
+                self.win_votes_commit_x,
+                self.win_votes_commit_y,
+                self.total_votes_commit_x,
+                self.total_votes_commit_y,
+                self.input_value_commit_x,
+                self.input_value_commit_y,
+            ],
+        )]
     }
 
     fn as_any(&self) -> &dyn Any {

+ 38 - 3
bin/daod/src/dao_contract/exec/wallet.rs

@@ -9,7 +9,7 @@ use pasta_curves::{
 };
 
 use darkfi::{
-    crypto::Proof,
+    crypto::{util::pedersen_commitment_u64, Proof},
     zk::vm::{Witness, ZkCircuit},
 };
 
@@ -108,6 +108,21 @@ impl Builder {
             self.dao_coin_blind,
         ]);
 
+        let win_votes_commit = pedersen_commitment_u64(self.win_votes, self.win_votes_blind);
+        let win_votes_coords = win_votes_commit.to_affine().coordinates().unwrap();
+        let win_votes_commit_x = *win_votes_coords.x();
+        let win_votes_commit_y = *win_votes_coords.y();
+
+        let total_votes_commit = pedersen_commitment_u64(self.total_votes, self.total_votes_blind);
+        let total_votes_coords = total_votes_commit.to_affine().coordinates().unwrap();
+        let total_votes_commit_x = *total_votes_coords.x();
+        let total_votes_commit_y = *total_votes_coords.y();
+
+        let input_value_commit = pedersen_commitment_u64(self.input_value, self.input_value_blind);
+        let input_value_coords = input_value_commit.to_affine().coordinates().unwrap();
+        let input_value_commit_x = *input_value_coords.x();
+        let input_value_commit_y = *input_value_coords.y();
+
         let zk_info = zk_bins.lookup(&"dao-exec".to_string()).unwrap();
         let zk_info = if let ZkContractInfo::Binary(info) = zk_info {
             info
@@ -151,7 +166,17 @@ impl Builder {
             Witness::Base(Value::known(user_data)),
         ];
 
-        let public_inputs = vec![proposal_bulla, coin_0, coin_1];
+        let public_inputs = vec![
+            proposal_bulla,
+            coin_0,
+            coin_1,
+            win_votes_commit_x,
+            win_votes_commit_y,
+            total_votes_commit_x,
+            total_votes_commit_y,
+            input_value_commit_x,
+            input_value_commit_y,
+        ];
 
         let circuit = ZkCircuit::new(prover_witnesses, zk_bin);
         debug!(target: "example_contract::foo::wallet::Builder", "input_proof Proof::create()");
@@ -160,7 +185,17 @@ impl Builder {
             .expect("DAO::exec() proving error!)");
         proofs.push(input_proof);
 
-        let call_data = CallData { proposal: proposal_bulla, coin_0, coin_1 };
+        let call_data = CallData {
+            proposal: proposal_bulla,
+            coin_0,
+            coin_1,
+            win_votes_commit_x,
+            win_votes_commit_y,
+            total_votes_commit_x,
+            total_votes_commit_y,
+            input_value_commit_x,
+            input_value_commit_y,
+        };
 
         FuncCall {
             contract_id: "DAO".to_string(),