Explorar o código

Merge branch 'master' of github.com:darkrenaissance/darkfi

ghassmo %!s(int64=4) %!d(string=hai) anos
pai
achega
9f8444d699
Modificáronse 6 ficheiros con 17 adicións e 217 borrados
  1. 0 4
      Cargo.toml
  2. 14 12
      README.md
  3. 0 166
      src/bin/zkvm.rs
  4. 1 24
      src/cli/cli_config.rs
  5. 2 2
      todo.md
  6. 0 9
      zkvm.md

+ 0 - 4
Cargo.toml

@@ -104,10 +104,6 @@ sol = ["solana-sdk", "solana-client", "tokio-tungstenite", "tokio"]
 name = "lisp"
 name = "lisp"
 path = "lisp/lisp.rs"
 path = "lisp/lisp.rs"
 
 
-[[bin]]
-name = "zkvm"
-path = "src/bin/zkvm.rs"
-
 [[bin]]
 [[bin]]
 name = "mimc"
 name = "mimc"
 path = "src/old/mimc.rs"
 path = "src/old/mimc.rs"

+ 14 - 12
README.md

@@ -1,6 +1,8 @@
-# First time running the demo:
+## First time running the demo:
 
 
-1. Configure gatewayd, cashierd, darkfid and drk TOML files. Copy paste the following defaults to .config/darkfi:
+1. Install [sqlcipher] (https://github.com/sqlcipher/sqlcipher).
+
+2. Configure gatewayd, cashierd, darkfid and drk TOML files. Copy paste the following defaults to .config/darkfi:
 
 
 **gatewayd.toml**
 **gatewayd.toml**
 
 
@@ -46,45 +48,45 @@ rpc_url = "http://127.0.0.1:8000"
 log_path = "/tmp/drk_cli.log"
 log_path = "/tmp/drk_cli.log"
 ```
 ```
 
 
-2. Configure the password field on all TOML files.
+3. Configure the password field on all TOML files.
 
 
-3. Compile the project:
+4. Compile the project:
 
 
 ```console
 ```console
 $ cargo build --release
 $ cargo build --release
 ```
 ```
 
 
-4. Run the gateway daemon:
+5. Run the gateway daemon:
 
 
 ```console
 ```console
 $ cargo run --bin gatewayd -- -v
 $ cargo run --bin gatewayd -- -v
 ```
 ```
 
 
-5. Run cashierd:
+6. Run cashierd:
 
 
 ```console
 ```console
 $ cargo run --bin cashierd -- -v
 $ cargo run --bin cashierd -- -v
 ```
 ```
 
 
-6. Run darkfid:
+7. Run darkfid:
 
 
 ```console
 ```console
 $ cargo run --bin darkfid -- -v
 $ cargo run --bin darkfid -- -v
 ```
 ```
 
 
-7. Initialize drk wallet and generate a key pair:
+8. Initialize drk wallet and generate a key pair:
 
 
 ```console
 ```console
 $ cargo run --bin drk -- -wk 
 $ cargo run --bin drk -- -wk 
 ```
 ```
 
 
-8. Play.
+9. Play.
 
 
 ```console
 ```console
 $ cargo run --bin drk -- -help
 $ cargo run --bin drk -- -help
 ```
 ```
 
 
-# Every time running the demo:
+## Every time running the demo:
 
 
 Run gateway daemon:
 Run gateway daemon:
 
 
@@ -110,11 +112,11 @@ Show drk usage manual:
 $ cargo run --bin drk -- -help
 $ cargo run --bin drk -- -help
 ```
 ```
 
 
-# darkfid & drk configurations:
+## darkfid & drk configurations:
 
 
 Darkfid and drk can be configured using the TOML files in the .config/darkfid directory. Make sure to recompile darkfid and drk after customizing the TOML.
 Darkfid and drk can be configured using the TOML files in the .config/darkfid directory. Make sure to recompile darkfid and drk after customizing the TOML.
 
 
-# Go dark
+## Go dark
 
 
 Let's liberate people from the claws of big tech and create the democratic paradigm of technology.
 Let's liberate people from the claws of big tech and create the democratic paradigm of technology.
 
 

+ 0 - 166
src/bin/zkvm.rs

@@ -1,166 +0,0 @@
-#[macro_use]
-extern crate clap;
-use bls12_381::Scalar;
-use drk::{BlsStringConversion, Decodable, Encodable, ZkContract, ZkProof};
-use simplelog::*;
-use std::fs;
-use std::fs::File;
-use std::time::Instant;
-//use log::*;
-
-type Result<T> = std::result::Result<T, failure::Error>;
-
-// do the setup for mint.zcd, save the params in mint.setup
-fn trusted_setup(contract_data: String, setup_file: String) -> Result<()> {
-    let start = Instant::now();
-    let file = File::open(contract_data)?;
-    let mut contract = ZkContract::decode(file)?;
-    println!(
-        "loaded contract '{}': [{:?}]",
-        contract.name,
-        start.elapsed()
-    );
-    println!("Stats:");
-    println!("    Constants: {}", contract.vm.constants.len());
-    println!("    Alloc: {}", contract.vm.alloc.len());
-    println!("    Operations: {}", contract.vm.ops.len());
-    println!(
-        "    Constraint Instructions: {}",
-        contract.vm.constraints.len()
-    );
-    contract.setup(&setup_file)?;
-    Ok(())
-}
-
-// make the proof
-fn create_proof(
-    contract_data: String,
-    setup_file: String,
-    params: String,
-    zk_proof: String,
-) -> Result<()> {
-    let start = Instant::now();
-    let file = File::open(contract_data)?;
-    let mut contract = ZkContract::decode(file)?;
-    contract.load_setup(&setup_file)?;
-    println!(
-        "Loaded contract '{}': [{:?}]",
-        contract.name,
-        start.elapsed()
-    );
-    let param_content = fs::read_to_string(params).expect("something went wrong reading the file");
-    let lines: Vec<&str> = param_content.lines().collect();
-    for line in lines {
-        let name = line.split_whitespace().next().unwrap_or("");
-        let value = line.trim_start_matches(name).trim_start();
-        contract.set_param(name, Scalar::from_string(value))?;
-        println!("Set parameter: {}", name);
-        println!("      Value: {}", value);
-    }
-    let proof = contract.prove()?;
-    let mut file = File::create(zk_proof)?;
-    proof.encode(&mut file)?;
-    Ok(())
-}
-
-//verify the proof
-fn verify_proof(contract_data: String, setup_file: String, zk_proof: String) -> Result<()> {
-    let contract_file = File::open(contract_data)?;
-    let mut contract = ZkContract::decode(contract_file)?;
-    contract.load_setup(&setup_file)?;
-    let proof_file = File::open(zk_proof)?;
-    let proof = ZkProof::decode(proof_file)?;
-    if contract.verify(&proof) {
-        println!("Zero-knowledge proof verified correctly.")
-    } else {
-        eprintln!("Verification failed.")
-    }
-    Ok(())
-}
-
-// show public values in proof
-fn show_public(zk_proof: String) -> Result<()> {
-    let file = File::open(zk_proof)?;
-    let proof = ZkProof::decode(file)?;
-    //assert_eq!(proof.public.len(), 2);
-    println!("Public values: {:?}", proof.public);
-    Ok(())
-}
-
-fn main() -> Result<()> {
-    let matches = clap_app!(zkvm =>
-        (version: "0.1.0")
-        (author: "Rose O'Leary <rrose@tuta.io>")
-        (about: "Zero Knowledge Virtual Machine Command Line Interface")
-        (@subcommand init =>
-            (about: "Trusted setup phase")
-            (@arg CONTRACT_DATA: +required "Input zero-knowledge contract data (.zcd)")
-            (@arg SETUP_FILE: +required "Output setup parameters")
-        )
-        (@subcommand prove =>
-            (about: "Create zero-knowledge proof")
-            (@arg CONTRACT_DATA: +required "Input zero-knowledge contract data (.zcd)")
-            (@arg SETUP_FILE: +required "Input setup parameters")
-            (@arg PARAMS: +required "Input parameters json file")
-            (@arg ZK_PROOF: +required "Output zero-knowledge proof")
-        )
-        (@subcommand verify =>
-            (about: "Verify zero-knowledge proof")
-            (@arg CONTRACT_DATA: +required "Input zero-knowledge contract data (.zcd)")
-            (@arg SETUP_FILE: +required "Input setup parameters")
-            (@arg ZK_PROOF: +required "Input zero-knowledge proof")
-        )
-        (@subcommand show =>
-            (about: "Show public values in proof")
-            (@arg ZK_PROOF: +required "Input zero-knowledge proof")
-        )
-    )
-    .get_matches();
-
-    CombinedLogger::init(vec![TermLogger::new(
-        LevelFilter::Debug,
-        Config::default(),
-        TerminalMode::Mixed,
-    )
-    .unwrap()])
-    .unwrap();
-
-    match matches.subcommand() {
-        ("init", matches) => {
-            if let Some(matches) = matches {
-                let contract_data: String = matches.value_of("CONTRACT_DATA").unwrap().parse()?;
-                let setup_file: String = matches.value_of("SETUP_FILE").unwrap().parse()?;
-                trusted_setup(contract_data, setup_file)?;
-            }
-        }
-        ("prove", matches) => {
-            if let Some(matches) = matches {
-                let contract_data: String = matches.value_of("CONTRACT_DATA").unwrap().parse()?;
-                let setup_file: String = matches.value_of("SETUP_FILE").unwrap().parse()?;
-                let params: String = matches.value_of("PARAMS").unwrap().parse()?;
-                let zk_proof: String = matches.value_of("ZK_PROOF").unwrap().parse()?;
-                create_proof(contract_data, setup_file, params, zk_proof)?;
-            }
-        }
-        ("verify", matches) => {
-            if let Some(matches) = matches {
-                let contract_data: String = matches.value_of("CONTRACT_DATA").unwrap().parse()?;
-                let setup_file: String = matches.value_of("SETUP_FILE").unwrap().parse()?;
-                let zk_proof: String = matches.value_of("ZK_PROOF").unwrap().parse()?;
-                verify_proof(contract_data, setup_file, zk_proof)?;
-            }
-        }
-        ("show", matches) => {
-            if let Some(matches) = matches {
-                let zk_proof: String = matches.value_of("ZK_PROOF").unwrap().parse()?;
-                show_public(zk_proof)?;
-            }
-        }
-        _ => {
-            eprintln!("error: Invalid subcommand invoked");
-            std::process::exit(-1);
-        }
-    }
-
-    Ok(())
-}

+ 1 - 24
src/cli/cli_config.rs

@@ -21,6 +21,7 @@ impl<T: Serialize + DeserializeOwned> Config<T> {
             let config: T = toml::from_str(str_buff.clone())?;
             let config: T = toml::from_str(str_buff.clone())?;
             Ok(config)
             Ok(config)
         } else {
         } else {
+            println!("No config files were found in .config/darkfi. Please follow the instructions in the README and add default configs.");
             Err(Error::ConfigNotFound)
             Err(Error::ConfigNotFound)
         }
         }
     }
     }
@@ -28,106 +29,82 @@ impl<T: Serialize + DeserializeOwned> Config<T> {
 
 
 #[derive(Serialize, Deserialize, Debug)]
 #[derive(Serialize, Deserialize, Debug)]
 pub struct DrkConfig {
 pub struct DrkConfig {
-    #[serde(default)]
     pub rpc_url: String,
     pub rpc_url: String,
 
 
-    #[serde(default)]
     pub log_path: String,
     pub log_path: String,
 }
 }
 
 
 #[derive(Serialize, Deserialize, Debug)]
 #[derive(Serialize, Deserialize, Debug)]
 pub struct DarkfidConfig {
 pub struct DarkfidConfig {
-    #[serde(default)]
     #[serde(rename = "connect_url")]
     #[serde(rename = "connect_url")]
     pub connect_url: String,
     pub connect_url: String,
 
 
-    #[serde(default)]
     #[serde(rename = "subscriber_url")]
     #[serde(rename = "subscriber_url")]
     pub subscriber_url: String,
     pub subscriber_url: String,
 
 
-    #[serde(default)]
     #[serde(rename = "cashier_url")]
     #[serde(rename = "cashier_url")]
     pub cashier_url: String,
     pub cashier_url: String,
 
 
-    #[serde(default)]
     #[serde(rename = "rpc_url")]
     #[serde(rename = "rpc_url")]
     pub rpc_url: String,
     pub rpc_url: String,
 
 
-    #[serde(default)]
     #[serde(rename = "database_path")]
     #[serde(rename = "database_path")]
     pub database_path: String,
     pub database_path: String,
 
 
-    #[serde(default)]
     #[serde(rename = "walletdb_path")]
     #[serde(rename = "walletdb_path")]
     pub walletdb_path: String,
     pub walletdb_path: String,
 
 
-    #[serde(default)]
     #[serde(rename = "log_path")]
     #[serde(rename = "log_path")]
     pub log_path: String,
     pub log_path: String,
 
 
-    #[serde(default)]
     #[serde(rename = "password")]
     #[serde(rename = "password")]
     pub password: String,
     pub password: String,
 }
 }
 
 
 #[derive(Serialize, Deserialize, Debug)]
 #[derive(Serialize, Deserialize, Debug)]
 pub struct GatewaydConfig {
 pub struct GatewaydConfig {
-    #[serde(default)]
     #[serde(rename = "connect_url")]
     #[serde(rename = "connect_url")]
     pub accept_url: String,
     pub accept_url: String,
 
 
-    #[serde(default)]
     #[serde(rename = "publisher_url")]
     #[serde(rename = "publisher_url")]
     pub publisher_url: String,
     pub publisher_url: String,
 
 
-    #[serde(default)]
     #[serde(rename = "database_path")]
     #[serde(rename = "database_path")]
     pub database_path: String,
     pub database_path: String,
 
 
-    #[serde(default)]
     #[serde(rename = "log_path")]
     #[serde(rename = "log_path")]
     pub log_path: String,
     pub log_path: String,
 }
 }
 
 
 #[derive(Serialize, Deserialize, Debug)]
 #[derive(Serialize, Deserialize, Debug)]
 pub struct CashierdConfig {
 pub struct CashierdConfig {
-    #[serde(default)]
     #[serde(rename = "accept_url")]
     #[serde(rename = "accept_url")]
     pub accept_url: String,
     pub accept_url: String,
 
 
-    #[serde(default)]
     #[serde(rename = "rpc_url")]
     #[serde(rename = "rpc_url")]
     pub rpc_url: String,
     pub rpc_url: String,
 
 
-    #[serde(default)]
     #[serde(rename = "client_database_path")]
     #[serde(rename = "client_database_path")]
     pub client_database_path: String,
     pub client_database_path: String,
 
 
-    #[serde(default)]
     #[serde(rename = "btc_endpoint")]
     #[serde(rename = "btc_endpoint")]
     pub btc_endpoint: String,
     pub btc_endpoint: String,
 
 
-    #[serde(default)]
     #[serde(rename = "gateway_url")]
     #[serde(rename = "gateway_url")]
     pub gateway_url: String,
     pub gateway_url: String,
 
 
-    #[serde(default)]
     #[serde(rename = "log_path")]
     #[serde(rename = "log_path")]
     pub log_path: String,
     pub log_path: String,
 
 
-    #[serde(default)]
     #[serde(rename = "cashierdb_path")]
     #[serde(rename = "cashierdb_path")]
     pub cashierdb_path: String,
     pub cashierdb_path: String,
 
 
-    #[serde(default)]
     #[serde(rename = "client_walletdb_path")]
     #[serde(rename = "client_walletdb_path")]
     pub client_walletdb_path: String,
     pub client_walletdb_path: String,
 
 
-    #[serde(default)]
     #[serde(rename = "password")]
     #[serde(rename = "password")]
     pub password: String,
     pub password: String,
 
 
-    #[serde(default)]
     #[serde(rename = "client_password")]
     #[serde(rename = "client_password")]
     pub client_password: String,
     pub client_password: String,
 }
 }

+ 2 - 2
todo.md

@@ -5,9 +5,9 @@
 - [x] random ID param for jsonrpc requests (bin/drk.rs)
 - [x] random ID param for jsonrpc requests (bin/drk.rs)
 - [x] merge cashier branch
 - [x] merge cashier branch
 - [x] update cashierd.rs to new config handling. note: password param in toml
 - [x] update cashierd.rs to new config handling. note: password param in toml
-- [ ] sqlcipher: document install process or otherwise remove friction of using bundled version
+- [ ] sqlcipher: better document install process or otherwise remove friction of using bundled version
 - [X] remove default config from binaries and add to the readme
 - [X] remove default config from binaries and add to the readme
-- [ ] delete zkvm
+- [X] delete zkvm
 - [X] SOL bridge poc
 - [X] SOL bridge poc
 - [ ] Optional Cargo "features" for cashierd/darkfid, to {en,dis}able different chains
 - [ ] Optional Cargo "features" for cashierd/darkfid, to {en,dis}able different chains
 
 

+ 0 - 9
zkvm.md

@@ -1,9 +0,0 @@
-# do the setup for mint.zcd, save the params in mint.params
-zkvm setup mint.zcd mint.setup
-# make the proof
-zkvm prove mint.zcd mint.setup mint-params.json proof.dat
-# verify the proof
-zkvm verify mint.zcd mint.setup proof.dat
-# show public values in proof
-zkvm public proof.dat
-