Procházet zdrojové kódy

clear all warning messages

ghassmo před 5 roky
rodič
revize
40e79b2c1d

+ 2 - 2
lisp/core.rs

@@ -705,12 +705,12 @@ fn seq(a: MalArgs) -> MalRet {
     }
 }
 
-fn gen_rand(a: MalArgs) -> MalRet {
+fn gen_rand(_a: MalArgs) -> MalRet {
     let mut rng = rand::thread_rng();
     Ok(MalVal::Int(rng.gen::<i64>()))
 }
 
-fn scalar_rnd(a: MalArgs) -> MalRet {
+fn scalar_rnd(_a: MalArgs) -> MalRet {
     let randomness_value: jubjub::Fr = jubjub::Fr::random(&mut OsRng);
     let value = bls12_381::Scalar::from_bytes(&randomness_value.to_bytes());
     Ok(MalVal::ZKScalar(value.unwrap()))

+ 25 - 25
lisp/lisp.rs

@@ -138,22 +138,22 @@ fn eval_ast(ast: &MalVal, env: &Env) -> MalRet {
     }
 }
 
-fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
+fn eval(mut _ast: MalVal, mut env: Env) -> MalRet {
     let ret: MalRet;
 
     let start = Instant::now();
 
     'tco: loop {
         // TODO check DEBUG symbol on env
-        println!("debug eval \t {:?} \t {:?}", ast, start.elapsed());
-        ret = match ast.clone() {
+        println!("debug eval \t {:?} \t {:?}", _ast, start.elapsed());
+        ret = match _ast.clone() {
             List(l, _) => {
                 if l.len() == 0 {
-                    return Ok(ast);
+                    return Ok(_ast);
                 }
-                match macroexpand(ast.clone(), &env) {
+                match macroexpand(_ast.clone(), &env) {
                     (true, Ok(new_ast)) => {
-                        ast = new_ast;
+                        _ast = new_ast;
                         continue 'tco;
                     }
                     (_, Err(e)) => return Err(e),
@@ -161,7 +161,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                 }
 
                 if l.len() == 0 {
-                    return Ok(ast);
+                    return Ok(_ast);
                 }
                 let a0 = &l[0];
                 match a0 {
@@ -192,7 +192,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                                 return error("let* with non-List bindings");
                             }
                         };
-                        ast = a2;
+                        _ast = a2;
                         continue 'tco;
                     }
                     Sym(ref a0sym) if a0sym == "let*" => {
@@ -219,13 +219,13 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                                 return error("let* with non-List bindings");
                             }
                         };
-                        ast = a2;
+                        _ast = a2;
                         continue 'tco;
                     }
                     Sym(ref a0sym) if a0sym == "quote" => Ok(l[1].clone()),
                     Sym(ref a0sym) if a0sym == "quasiquoteexpand" => Ok(quasiquote(&l[1])),
                     Sym(ref a0sym) if a0sym == "quasiquote" => {
-                        ast = quasiquote(&l[1]);
+                        _ast = quasiquote(&l[1]);
                         continue 'tco;
                     }
                     Sym(ref a0sym) if a0sym == "defmacro!" => {
@@ -242,7 +242,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                                 &env,
                                 a1.clone(),
                                 MalFunc {
-                                    eval: eval,
+                                    eval,
                                     ast: ast.clone(),
                                     env: env.clone(),
                                     params: params.clone(),
@@ -282,7 +282,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                     Sym(ref a0sym) if a0sym == "do" => {
                         match eval_ast(&list!(l[1..l.len() - 1].to_vec()), &env)? {
                             List(_, _) => {
-                                ast = l.last().unwrap_or(&Nil).clone();
+                                _ast = l.last().unwrap_or(&Nil).clone();
                                 continue 'tco;
                             }
                             _ => error("invalid do form"),
@@ -292,7 +292,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                         match eval(l[1].clone(), env.clone())? {
                             MalVal::Int(v) => {
                                 for _i in 0..v {
-                                    ast = eval_ast(&l[2], &env)?;
+                                    _ast = eval_ast(&l[2], &env)?;
                                 }
                                 Ok(Nil)
                             }
@@ -303,12 +303,12 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                         let cond = eval(l[1].clone(), env.clone())?;
                         match cond {
                             Bool(false) | Nil if l.len() >= 4 => {
-                                ast = l[3].clone();
+                                _ast = l[3].clone();
                                 continue 'tco;
                             }
                             Bool(false) | Nil => Ok(Nil),
                             _ if l.len() >= 3 => {
-                                ast = l[2].clone();
+                                _ast = l[2].clone();
                                 continue 'tco;
                             }
                             _ => Ok(Nil),
@@ -318,16 +318,16 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                     Sym(ref a0sym) if a0sym == "fn*" => {
                         let (a1, a2) = (l[1].clone(), l[2].clone());
                         Ok(MalFunc {
-                            eval: eval,
+                            eval,
                             ast: Rc::new(a2),
-                            env: env,
+                            env,
                             params: Rc::new(a1),
                             is_macro: false,
                             meta: Rc::new(Nil),
                         })
                     }
                     Sym(ref a0sym) if a0sym == "eval" => {
-                        ast = eval(l[1].clone(), env.clone())?;
+                        _ast = eval(l[1].clone(), env.clone())?;
                         while let Some(ref e) = env.clone().outer {
                             env = e.clone();
                         }
@@ -336,7 +336,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                     Sym(ref a0sym) if a0sym == "setup" => {
                         let a1 = l[1].clone();
                         // todo
-                        ast = eval(a1.clone(), env.clone())?;
+                        _ast = eval(a1.clone(), env.clone())?;
                         //                        let _pvk = setup(a1.clone(), env.clone())?;
                         continue 'tco;
                     }
@@ -347,7 +347,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                         prove(a1.clone(), env.clone())
                     }
                     Sym(ref a0sym) if a0sym == "kill" => {
-                        error(&format!("KILL at: {:?}", ast).to_string())
+                        error(&format!("KILL at: {:?}", _ast).to_string())
                     }
                     Sym(ref a0sym) if a0sym == "alloc-const" => {
                         let start = Instant::now();
@@ -536,7 +536,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
 
                         Ok(MalVal::Str("enforce-eof".to_string()))
                     }
-                    _ => match eval_ast(&ast, &env)? {
+                    _ => match eval_ast(&_ast, &env)? {
                         List(ref el, _) => {
                             let ref f = el[0].clone();
                             let args = el[1..].to_vec();
@@ -551,7 +551,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                                     let a = &**mast;
                                     let p = &**params;
                                     env = env_bind(Some(menv.clone()), p.clone(), args)?;
-                                    ast = a.clone();
+                                    _ast = a.clone();
                                     continue 'tco;
                                 }
                                 _ => {
@@ -565,7 +565,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                     },
                 }
             }
-            _ => eval_ast(&ast, &env),
+            _ => eval_ast(&_ast, &env),
         };
 
         break;
@@ -628,7 +628,7 @@ pub fn get_allocations_nested(env: &Env, key: &str) -> RefCell<HashMap<String, M
     }
 }
 
-pub fn setup(_ast: MalVal, env: Env) -> Result<VerifyKeyParams, MalErr> {
+pub fn setup(_ast: MalVal, _env: Env) -> Result<VerifyKeyParams, MalErr> {
     let start = Instant::now();
     let c = LispCircuit {
         params: HashMap::default(),
@@ -674,7 +674,7 @@ pub fn prove(_ast: MalVal, env: Env) -> MalRet {
     };
     let proof = groth16::create_random_proof(circuit, params.as_ref().unwrap(), &mut OsRng)?;
     let mut vec_input = vec![];
-    for (k, val) in allocs_input.borrow_mut().iter() {
+    for (_k, val) in allocs_input.borrow_mut().iter() {
         match val {
             MalVal::Str(v) => {
                 vec_input.push(bls12_381::Scalar::from_string(&v.to_string()));

+ 1 - 1
lisp/types.rs

@@ -124,7 +124,7 @@ impl Circuit<bls12_381::Scalar> for LispCircuit {
         }
         println!("circuit alloc input \t {:?}", start.elapsed());
         let start = Instant::now();
-        let mut enforce_sorted = self.constraints.clone();
+        let enforce_sorted = self.constraints.clone();
         // enforce_sorted.sort_by(|a, b| a.idx.cmp(&b.idx));
         for alloc_value in enforce_sorted.iter() {
             // println!("Enforce -> {:?}", alloc_value);

+ 1 - 0
src/bin/darkfid.rs

@@ -26,6 +26,7 @@ use easy_parallel::Parallel;
 use ff::Field;
 use std::path::Path;
 
+#[allow(dead_code)]
 pub struct State {
     // The entire merkle tree state
     tree: CommitmentTree<MerkleNode>,

+ 1 - 0
src/bin/dfg.rs

@@ -192,6 +192,7 @@ const VERTICES: &[model::ModelVertex] = &[
 //const INDICES: &[u16] = &[0, 1, 4, 1, 2, 4, 2, 3, 4];
 const INDICES: &[u16] = &[0, 1, 2, 0, 2, 3];
 
+#[allow(dead_code)]
 struct State {
     surface: wgpu::Surface,
     device: wgpu::Device,

+ 1 - 1
src/bin/mint-classic.rs

@@ -18,7 +18,7 @@ fn main() {
 
     {
         let params = setup_mint_prover();
-        save_params("mint.params", &params);
+        save_params("mint.params", &params).unwrap();
     }
     let (params, pvk) = load_params("mint.params").expect("params should load");
 

+ 2 - 2
src/bin/mint.rs

@@ -25,7 +25,7 @@ fn unpack<F: PrimeField>(value: F) -> Vec<Scalar> {
 }
 
 // Unpack a u64 value in 64 Scalar binary digits
-fn unpack_u64(value: u64) -> Vec<Scalar> {
+fn _unpack_u64(value: u64) -> Vec<Scalar> {
     let mut result = Vec::with_capacity(64);
 
     for i in 0..64 {
@@ -56,7 +56,7 @@ fn main() -> Result<()> {
         visor.vm.constraints.len()
     );
 
-    visor.setup("mint.zts");
+    visor.setup("mint.zts")?;
 
     // We use the ExtendedPoint in calculations because it's faster
     let public_point = jubjub::ExtendedPoint::from(jubjub::SubgroupPoint::random(&mut OsRng));

+ 2 - 1
src/bin/spend-classic.rs

@@ -53,6 +53,7 @@ struct SpendRevealedValues {
     merkle_root: bls12_381::Scalar,
 }
 
+#[allow(dead_code)]
 impl SpendRevealedValues {
     fn compute(
         value: u64,
@@ -185,7 +186,7 @@ fn main() {
 
     {
         let params = setup_spend_prover();
-        save_params("spend.params", &params);
+        save_params("spend.params", &params).unwrap();
     }
     let (params, pvk) = load_params("spend.params").expect("params should load");
 

+ 12 - 15
src/bin/tx-test.rs

@@ -1,29 +1,25 @@
-use async_std::sync;
 use bellman::groth16;
 use bls12_381::Bls12;
-use drk::{Error, Result};
-use ff::{Field, PrimeField};
-use log::*;
-use rand::rngs::OsRng;
+
 //use rocksdb::DB;
-use rusqlite::{named_params, Connection};
+
 //use std::fs::File;
-use rocksdb::{IteratorMode, Options, DB};
+
 use std::path::Path;
 
 use drk::crypto::{
     coin::Coin,
     load_params,
     merkle::{CommitmentTree, IncrementalWitness},
-    merkle_node::{hash_coin, MerkleNode},
+    merkle_node::MerkleNode,
     note::{EncryptedNote, Note},
     nullifier::Nullifier,
     save_params, setup_mint_prover, setup_spend_prover,
 };
-use drk::serial::{Decodable, Encodable};
-use drk::state::{state_transition, ProgramState, StateUpdate};
-use drk::wallet::walletdb::WalletDB;
 
+use drk::state::{ProgramState, StateUpdate};
+
+#[allow(dead_code)]
 struct MemoryState {
     // The entire merkle tree state
     tree: CommitmentTree<MerkleNode>,
@@ -52,7 +48,7 @@ struct MemoryState {
 
 impl ProgramState for MemoryState {
     // Vec<u8> for keys
-    fn is_valid_cashier_public_key(&self, public: &jubjub::SubgroupPoint) -> bool {
+    fn is_valid_cashier_public_key(&self, _public: &jubjub::SubgroupPoint) -> bool {
         //let path = WalletDB::wallet_path();
         //let connect = Connection::open(&path).expect("Failed to connect to database.");
         //let mut stmt = connect.prepare("SELECT key_public FROM keys").unwrap();
@@ -93,6 +89,7 @@ impl ProgramState for MemoryState {
     }
 }
 
+#[allow(dead_code)]
 impl MemoryState {
     fn apply(&mut self, mut update: StateUpdate) {
         // Extend our list of nullifiers with the ones from the update
@@ -135,7 +132,7 @@ impl MemoryState {
     }
 
     // sql
-    fn try_decrypt_note(&self, ciphertext: EncryptedNote) -> Option<(Note, jubjub::Fr)> {
+    fn try_decrypt_note(&self, _ciphertext: EncryptedNote) -> Option<(Note, jubjub::Fr)> {
         //debug!(target: "adapter", "try_decrypt_note() [START]");
         //let path = WalletDB::wallet_path();
         //debug!(target: "adapter", "try_decrypt_note() [FOUND PATH]");
@@ -176,8 +173,8 @@ fn main() {
     }
 
     // Load trusted setup parameters
-    let (mint_params, mint_pvk) = load_params("mint.params").expect("params should load");
-    let (spend_params, spend_pvk) = load_params("spend.params").expect("params should load");
+    let (_mint_params, _mint_pvk) = load_params("mint.params").expect("params should load");
+    let (_spend_params, _spend_pvk) = load_params("spend.params").expect("params should load");
 
     // Where is cashier private key stored? Does node have its own wallet schema
     // Cashier creates a secret key

+ 8 - 8
src/bin/tx.rs

@@ -8,7 +8,7 @@ use drk::crypto::{
     coin::Coin,
     load_params,
     merkle::{CommitmentTree, IncrementalWitness},
-    merkle_node::{hash_coin, MerkleNode},
+    merkle_node::MerkleNode,
     note::{EncryptedNote, Note},
     nullifier::Nullifier,
     save_params, setup_mint_prover, setup_spend_prover,
@@ -119,11 +119,11 @@ fn main() {
     // Auto create trusted ceremony parameters if they don't exist
     if !Path::new("mint.params").exists() {
         let params = setup_mint_prover();
-        save_params("mint.params", &params);
+        save_params("mint.params", &params).unwrap();
     }
     if !Path::new("spend.params").exists() {
         let params = setup_spend_prover();
-        save_params("spend.params", &params);
+        save_params("spend.params", &params).unwrap();
     }
 
     // Load trusted setup parameters
@@ -183,11 +183,11 @@ fn main() {
     {
         // Here we simulate 5 fake random coins, adding them to our tree.
         let tree = &mut state.tree;
-        for i in 0..5 {
+        for _i in 0..5 {
             // Don't worry about any of the code in this block
             // We're just filling the tree with fake coins
             let cmu = MerkleNode::new(bls12_381::Scalar::random(&mut OsRng).to_repr());
-            tree.append(cmu);
+            tree.append(cmu).unwrap();
 
             let root = tree.root();
             state.merkle_roots.push(root.into());
@@ -218,12 +218,12 @@ fn main() {
         assert_eq!(tree.root(), witness.root());
 
         // Add some more random coins in
-        for i in 0..10 {
+        for _i in 0..10 {
             // Don't worry about any of the code in this block
             // We're just filling the tree with fake coins
             let cmu = MerkleNode::new(bls12_381::Scalar::random(&mut OsRng).to_repr());
-            tree.append(cmu);
-            witness.append(cmu);
+            tree.append(cmu).unwrap();
+            witness.append(cmu).unwrap();
             assert_eq!(tree.root(), witness.root());
 
             let root = tree.root();

+ 2 - 2
src/crypto/coin.rs

@@ -16,13 +16,13 @@ impl Coin {
 }
 
 impl Encodable for Coin {
-    fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
+    fn encode<S: io::Write>(&self, s: S) -> Result<usize> {
         Ok(self.repr.encode(s)?)
     }
 }
 
 impl Decodable for Coin {
-    fn decode<D: io::Read>(mut d: D) -> Result<Self> {
+    fn decode<D: io::Read>(d: D) -> Result<Self> {
         Ok(Self {
             repr: Decodable::decode(d)?,
         })

+ 2 - 2
src/crypto/merkle_node.rs

@@ -119,13 +119,13 @@ impl From<MerkleNode> for bls12_381::Scalar {
 }
 
 impl Encodable for MerkleNode {
-    fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
+    fn encode<S: io::Write>(&self, s: S) -> Result<usize> {
         Ok(self.repr.encode(s)?)
     }
 }
 
 impl Decodable for MerkleNode {
-    fn decode<D: io::Read>(mut d: D) -> Result<Self> {
+    fn decode<D: io::Read>(d: D) -> Result<Self> {
         Ok(Self {
             repr: Decodable::decode(d)?,
         })

+ 2 - 2
src/crypto/nullifier.rs

@@ -16,13 +16,13 @@ impl Nullifier {
 }
 
 impl Encodable for Nullifier {
-    fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
+    fn encode<S: io::Write>(&self, s: S) -> Result<usize> {
         Ok(self.repr.encode(s)?)
     }
 }
 
 impl Decodable for Nullifier {
-    fn decode<D: io::Read>(mut d: D) -> Result<Self> {
+    fn decode<D: io::Read>(d: D) -> Result<Self> {
         Ok(Self {
             repr: Decodable::decode(d)?,
         })

+ 13 - 13
src/old/mimc.rs

@@ -56,19 +56,19 @@ fn mimc<Scalar: PrimeField>(mut xl: Scalar, mut xr: Scalar, constants: &[Scalar]
     xl
 }
 
-macro_rules! from_slice {
-    ($data:expr, $len:literal) => {{
-        let mut array = [0; $len];
-        // panics if not enough data
-        let bytes = &$data[..array.len()];
-        assert_eq!(bytes.len(), array.len());
-        for (a, b) in array.iter_mut().rev().zip(bytes.iter()) {
-            *a = *b;
-        }
-        //array.copy_from_slice(bytes.iter().rev());
-        array
-    }};
-}
+//macro_rules! from_slice {
+//    ($data:expr, $len:literal) => {{
+//        let mut array = [0; $len];
+//        // panics if not enough data
+//        let bytes = &$data[..array.len()];
+//        assert_eq!(bytes.len(), array.len());
+//        for (a, b) in array.iter_mut().rev().zip(bytes.iter()) {
+//            *a = *b;
+//        }
+//        //array.copy_from_slice(bytes.iter().rev());
+//        array
+//    }};
+//}
 
 /// This is our demo circuit for proving knowledge of the
 /// preimage of a MiMC hash invocation.

+ 2 - 2
src/rpc/adapter.rs

@@ -1,7 +1,7 @@
 use crate::wallet::WalletDB;
-use crate::{Error, Result};
+use crate::Result;
 use log::*;
-use std::path::{Path, PathBuf};
+use std::path::PathBuf;
 use std::sync::Arc;
 
 // Dummy adapter for now

+ 1 - 0
src/rpc/jsonserver.rs

@@ -101,6 +101,7 @@ pub async fn start(
     Ok(())
 }
 // json RPC server goes here
+#[allow(dead_code)]
 pub struct RpcInterface {
     p2p: Arc<net::P2p>,
     pub started: Mutex<bool>,

+ 5 - 4
src/service/gateway.rs

@@ -17,8 +17,6 @@ enum GatewayError {
     IndexNotExist,
 }
 
-
-
 #[repr(u8)]
 enum GatewayCommand {
     PutSlab,
@@ -231,7 +229,11 @@ impl GatewayClient {
     pub async fn get_slab(&mut self, index: u64) -> Result<Option<Slab>> {
         let rep = self
             .protocol
-            .request(GatewayCommand::GetSlab as u8, serialize(&index), &handle_error)
+            .request(
+                GatewayCommand::GetSlab as u8,
+                serialize(&index),
+                &handle_error,
+            )
             .await?;
 
         if let Some(slab) = rep {
@@ -306,7 +308,6 @@ impl GatewayClient {
     }
 }
 
-
 fn handle_error(status_code: u32) {
     match status_code {
         1 => {

+ 6 - 1
src/service/reqrep.rs

@@ -144,7 +144,12 @@ impl ReqProtocol {
         Ok(())
     }
 
-    pub async fn request(&mut self, command: u8, data: Vec<u8>, handle_error: &dyn Fn(u32)) -> Result<Option<Vec<u8>>> {
+    pub async fn request(
+        &mut self,
+        command: u8,
+        data: Vec<u8>,
+        handle_error: &dyn Fn(u32),
+    ) -> Result<Option<Vec<u8>>> {
         let request = Request::new(command, data);
         let req = serialize(&request);
         let req = bytes::Bytes::from(req);

+ 7 - 4
src/wallet/walletdb.rs

@@ -34,7 +34,12 @@ impl WalletDB {
         Ok(path)
     }
 
-    pub async fn key_gen(path: PathBuf, id: i32, pubkey: Vec<u8>, privkey: Vec<u8>) -> Result<()> {
+    pub async fn key_gen(
+        path: PathBuf,
+        _id: i32,
+        _pubkey: Vec<u8>,
+        _privkey: Vec<u8>,
+    ) -> Result<()> {
         debug!(target: "key_gen", "Generating keys...");
         let connect = Connection::open(&path).expect("Failed to connect to database.");
         // TODO: ID should not be fixed
@@ -60,7 +65,7 @@ impl WalletDB {
     pub async fn get(path: PathBuf) -> Result<()> {
         debug!(target: "get_cash_public", "Returning cashier keys...");
         let connect = Connection::open(&path).expect("Failed to connect to database.");
-        let id = 0;
+        let _id = 0;
         let mut stmt = connect.prepare("SELECT key_public FROM keys").unwrap();
         let key_iter = stmt
             .query_map::<Vec<u8>, _, _>([], |row| row.get(0))
@@ -92,5 +97,3 @@ impl WalletDB {
         Ok(())
     }
 }
-
-fn main() {}