Răsfoiți Sursa

add more comments for DAO::exec(), and make a constant for DAO::exec::FUNC_ID

x 4 ani în urmă
părinte
comite
10b793c7d6

+ 3 - 2
Cargo.lock

@@ -1166,6 +1166,7 @@ dependencies = [
  "incrementalmerkletree",
  "incrementalmerkletree",
  "log",
  "log",
  "num_cpus",
  "num_cpus",
+ "once_cell",
  "pasta_curves",
  "pasta_curves",
  "rand",
  "rand",
  "serde_json",
  "serde_json",
@@ -2721,9 +2722,9 @@ dependencies = [
 
 
 [[package]]
 [[package]]
 name = "once_cell"
 name = "once_cell"
-version = "1.13.0"
+version = "1.13.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
+checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e"
 
 
 [[package]]
 [[package]]
 name = "opaque-debug"
 name = "opaque-debug"

+ 1 - 0
bin/daod/Cargo.toml

@@ -23,6 +23,7 @@ num_cpus = "1.13.1"
 simplelog = "0.12.0"
 simplelog = "0.12.0"
 url = "2.2.2"
 url = "2.2.2"
 thiserror = "1.0.32"
 thiserror = "1.0.32"
+once_cell = "1.13.1"
 
 
 # Crypto
 # Crypto
 incrementalmerkletree = "0.3.0"
 incrementalmerkletree = "0.3.0"

+ 6 - 0
bin/daod/src/dao_contract/exec/mod.rs

@@ -1,2 +1,8 @@
+use pasta_curves::pallas;
+use once_cell::sync::Lazy;
+
+pub static FUNC_ID: Lazy<pallas::Base> = Lazy::new(|| pallas::Base::from(110));
+
 pub mod validate;
 pub mod validate;
 pub mod wallet;
 pub mod wallet;
+

+ 23 - 8
bin/daod/src/dao_contract/exec/validate.rs

@@ -34,12 +34,17 @@ pub struct CallData {
     pub proposal: pallas::Base,
     pub proposal: pallas::Base,
     pub coin_0: pallas::Base,
     pub coin_0: pallas::Base,
     pub coin_1: pallas::Base,
     pub coin_1: pallas::Base,
+    // TODO: don't store the x, y like this
+    // store the actual point
     pub win_votes_commit_x: pallas::Base,
     pub win_votes_commit_x: pallas::Base,
     pub win_votes_commit_y: pallas::Base,
     pub win_votes_commit_y: pallas::Base,
     pub total_votes_commit_x: pallas::Base,
     pub total_votes_commit_x: pallas::Base,
     pub total_votes_commit_y: pallas::Base,
     pub total_votes_commit_y: pallas::Base,
     pub input_value_commit_x: pallas::Base,
     pub input_value_commit_x: pallas::Base,
     pub input_value_commit_y: pallas::Base,
     pub input_value_commit_y: pallas::Base,
+    /////
+
+    // Delete these values
     pub dao_spend_hook: pallas::Base,
     pub dao_spend_hook: pallas::Base,
     pub user_spend_hook: pallas::Base,
     pub user_spend_hook: pallas::Base,
     pub user_data: pallas::Base,
     pub user_data: pallas::Base,
@@ -59,9 +64,9 @@ impl CallDataBase for CallData {
                 self.total_votes_commit_y,
                 self.total_votes_commit_y,
                 self.input_value_commit_x,
                 self.input_value_commit_x,
                 self.input_value_commit_y,
                 self.input_value_commit_y,
-                self.dao_spend_hook,
-                self.user_spend_hook,
-                self.user_data,
+                *super::FUNC_ID,
+                pallas::Base::from(0),
+                pallas::Base::from(0),
             ],
             ],
         )]
         )]
     }
     }
@@ -85,12 +90,20 @@ pub fn state_transition(
     // This will be inside wasm so unwrap is fine.
     // This will be inside wasm so unwrap is fine.
     let call_data = call_data.unwrap();
     let call_data = call_data.unwrap();
 
 
-    //let example_state = states.lookup::<State>(&"Example".to_string()).unwrap();
+    // Enforce tx has correct format:
+    // 1. There should only be 2 calldata's
+    // 2. func_call_index == 1
+    // 3. First item should be a Money::transfer() calldata
+    // 4. Money::transfer() has exactly 2 outputs
+
+    // Checks:
 
 
-    //if example_state.public_exists(&call_data.header.public_c) {
-    //    return Err(Error::ValueExists)
-    //}
+    // 1. Check both coins in Money::transfer() are equal to our coin_0, coin_1
+    // 2. sum of Money::transfer() calldata input_value_commits == our input value commit
+    // 3. get the ProposalVote from DAO::State
+    // 4. check win/total_vote_commit is the same as in ProposalVote
 
 
+    // We need the proposal in here
     Ok(Box::new(Update {}))
     Ok(Box::new(Update {}))
 }
 }
 
 
@@ -98,5 +111,7 @@ pub fn state_transition(
 pub struct Update {}
 pub struct Update {}
 
 
 impl UpdateBase for Update {
 impl UpdateBase for Update {
-    fn apply(mut self: Box<Self>, states: &mut StateRegistry) {}
+    fn apply(mut self: Box<Self>, states: &mut StateRegistry) {
+        // Delete the ProposalVotes from DAO::State hashmap
+    }
 }
 }

+ 6 - 7
bin/daod/src/demo.rs

@@ -384,7 +384,7 @@ pub async fn demo() -> Result<()> {
 
 
     //// Wallet
     //// Wallet
 
 
-    // Address of deployed contract in our example is hook_dao_exec
+    // Address of deployed contract in our example is dao_contract::exec::FUNC_ID
     // This field is public, you can see it's being sent to a DAO
     // This field is public, you can see it's being sent to a DAO
     // but nothing else is visible.
     // but nothing else is visible.
     //
     //
@@ -392,8 +392,7 @@ pub async fn demo() -> Result<()> {
     //
     //
     //   spend_hook = b"0xdao_ruleset"
     //   spend_hook = b"0xdao_ruleset"
     //
     //
-    let hook_dao_exec = DrkSpendHook::random(&mut OsRng);
-    let spend_hook = hook_dao_exec;
+    let spend_hook = *dao_contract::exec::FUNC_ID;
     // The user_data can be a simple hash of the items passed into the ZK proof
     // The user_data can be a simple hash of the items passed into the ZK proof
     // up to corresponding linked ZK proof to interpret however they need.
     // up to corresponding linked ZK proof to interpret however they need.
     // In out case, it's the bulla for the DAO
     // In out case, it's the bulla for the DAO
@@ -461,7 +460,7 @@ pub async fn demo() -> Result<()> {
     ]);
     ]);
     assert_eq!(coin, dao_recv_coin.coin.0);
     assert_eq!(coin, dao_recv_coin.coin.0);
 
 
-    assert_eq!(treasury_note.spend_hook, hook_dao_exec);
+    assert_eq!(treasury_note.spend_hook, *dao_contract::exec::FUNC_ID);
     assert_eq!(treasury_note.user_data, dao_bulla.0);
     assert_eq!(treasury_note.user_data, dao_bulla.0);
 
 
     debug!("DAO received a coin worth {} xDRK", treasury_note.value);
     debug!("DAO received a coin worth {} xDRK", treasury_note.value);
@@ -1080,7 +1079,7 @@ pub async fn demo() -> Result<()> {
                 public: dao_keypair.public,
                 public: dao_keypair.public,
                 serial: dao_serial,
                 serial: dao_serial,
                 coin_blind: dao_coin_blind,
                 coin_blind: dao_coin_blind,
-                spend_hook: hook_dao_exec,
+                spend_hook: *dao_contract::exec::FUNC_ID,
                 user_data: dao_bulla.0,
                 user_data: dao_bulla.0,
             },
             },
         ],
         ],
@@ -1101,7 +1100,7 @@ pub async fn demo() -> Result<()> {
         dao_coin_blind,
         dao_coin_blind,
         input_value,
         input_value,
         input_value_blind,
         input_value_blind,
-        hook_dao_exec,
+        hook_dao_exec: *dao_contract::exec::FUNC_ID,
     };
     };
     let exec_func_call = builder.build(&zk_bins);
     let exec_func_call = builder.build(&zk_bins);
 
 
@@ -1125,7 +1124,7 @@ pub async fn demo() -> Result<()> {
         // At least one input has this field value which means DAO::exec() is invoked.
         // At least one input has this field value which means DAO::exec() is invoked.
         assert_eq!(transfer_call_data.inputs.len(), 1);
         assert_eq!(transfer_call_data.inputs.len(), 1);
         let input = &transfer_call_data.inputs[0];
         let input = &transfer_call_data.inputs[0];
-        assert_eq!(input.revealed.spend_hook, hook_dao_exec);
+        assert_eq!(input.revealed.spend_hook, *dao_contract::exec::FUNC_ID);
         let user_data_enc = poseidon_hash::<2>([dao_bulla.0, user_data_blind]);
         let user_data_enc = poseidon_hash::<2>([dao_bulla.0, user_data_blind]);
         assert_eq!(input.revealed.user_data_enc, user_data_enc);
         assert_eq!(input.revealed.user_data_enc, user_data_enc);
     }
     }