Преглед изворни кода

daod/example_contract: create example proof + empty contract frame with stub methods

ihateface пре 4 година
родитељ
комит
ace5a2706a

+ 14 - 0
bin/daod/proof/foo.zk

@@ -0,0 +1,14 @@
+constant "DaoMint" {
+}
+
+contract "DaoMint" {
+    Base a,
+    Base b,
+}
+
+circuit "DaoMint" {
+    c = base_add(a, b);
+    constrain_instance(c);
+}
+
+

+ 1 - 1
bin/daod/src/demo.rs

@@ -43,7 +43,7 @@ use darkfi::{
     zkas::decoder::ZkBinary,
 };
 
-use crate::{dao_contract, money_contract, util::poseidon_hash};
+use crate::{dao_contract, example_contract, money_contract, util::poseidon_hash};
 
 // TODO: Anonymity leaks in this proof of concept:
 //

+ 3 - 0
bin/daod/src/example_contract/foo/mod.rs

@@ -0,0 +1,3 @@
+#![allow(unused)]
+pub mod validate;
+pub mod wallet;

+ 46 - 0
bin/daod/src/example_contract/foo/validate.rs

@@ -0,0 +1,46 @@
+use darkfi::{crypto::types::DrkCircuitField, Error as DarkFiError};
+
+use std::any::Any;
+
+use crate::demo::{CallDataBase, StateRegistry, Transaction};
+
+type Result<T> = std::result::Result<T, Error>;
+
+#[derive(Debug, Clone, thiserror::Error)]
+pub enum Error {
+    #[error("DarkFi error: {0}")]
+    DarkFiError(String),
+}
+
+impl From<DarkFiError> for Error {
+    fn from(err: DarkFiError) -> Self {
+        Self::DarkFiError(err.to_string())
+    }
+}
+
+pub struct CallData {}
+
+impl CallDataBase for CallData {
+    fn zk_public_values(&self) -> Vec<Vec<DrkCircuitField>> {
+        vec![]
+    }
+    fn zk_proof_addrs(&self) -> Vec<String> {
+        vec![]
+    }
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+}
+
+pub fn state_transition(
+    states: &StateRegistry,
+    func_call_index: usize,
+    parent_tx: &Transaction,
+) -> Result<Update> {
+    Ok(Update {})
+}
+
+#[derive(Clone)]
+pub struct Update {}
+
+pub fn apply(states: &mut StateRegistry, mut update: Update) {}

+ 22 - 0
bin/daod/src/example_contract/foo/wallet.rs

@@ -0,0 +1,22 @@
+use std::any::Any;
+
+use crate::example_contract::foo::validate::CallData;
+
+use crate::demo::{/*CallDataBase, StateRegistry, ZkContractInfo, */ FuncCall, ZkContractTable,};
+
+pub struct Builder {}
+
+impl Builder {
+    pub fn build(self, zk_bins: &ZkContractTable) -> FuncCall {
+        let mut proofs = vec![];
+
+        let call_data = CallData {};
+
+        FuncCall {
+            contract_id: "EXAMPLE".to_string(),
+            func_id: "EXAMPLE::foo()".to_string(),
+            call_data: Box::new(call_data),
+            proofs,
+        }
+    }
+}

+ 5 - 0
bin/daod/src/example_contract/mod.rs

@@ -0,0 +1,5 @@
+#![allow(unused)]
+
+// foo()
+pub mod foo;
+pub mod state;

+ 9 - 0
bin/daod/src/example_contract/state.rs

@@ -0,0 +1,9 @@
+use std::any::Any;
+
+pub struct State {}
+
+impl State {
+    pub fn new() -> Box<dyn Any> {
+        Box::new(Self {})
+    }
+}

+ 4 - 1
bin/daod/src/main.rs

@@ -15,10 +15,13 @@ use darkfi::{
 };
 
 mod dao_contract;
-mod demo;
+mod example_contract;
 mod money_contract;
+
+mod demo;
 mod note;
 mod util;
+
 use crate::demo::demo;
 
 async fn _start() -> Result<()> {