From d71bc5a675a534dccdb72d2ec4fb3f2fea71c91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Mon, 2 Dec 2019 07:21:10 -0800 Subject: [PATCH] Prefer to return error rather than ? them, avoid return when it cant be early (in a simple if-else) --- crypto-primitives/src/merkle_tree/mod.rs | 4 ++-- r1cs-std/src/bits/boolean.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crypto-primitives/src/merkle_tree/mod.rs b/crypto-primitives/src/merkle_tree/mod.rs index 96eeeb4..df65dd0 100644 --- a/crypto-primitives/src/merkle_tree/mod.rs +++ b/crypto-primitives/src/merkle_tree/mod.rs @@ -200,7 +200,7 @@ impl MerkleHashTree

{ // Check that the given index corresponds to the correct leaf. if leaf_hash != self.tree[tree_index] { - Err(MerkleTreeError::IncorrectLeafIndex(tree_index))? + return Err(MerkleTreeError::IncorrectLeafIndex(tree_index).into()) } // Iterate from the leaf up to the root, storing all intermediate hash values. @@ -230,7 +230,7 @@ impl MerkleHashTree

{ } end_timer!(prove_time); if path.len() != (Self::HEIGHT - 1) as usize { - Err(MerkleTreeError::IncorrectPathLength(path.len()))? + return Err(MerkleTreeError::IncorrectPathLength(path.len()).into()) } else { Ok(MerkleTreePath { path }) } diff --git a/r1cs-std/src/bits/boolean.rs b/r1cs-std/src/bits/boolean.rs index 7395dc5..5d2edac 100644 --- a/r1cs-std/src/bits/boolean.rs +++ b/r1cs-std/src/bits/boolean.rs @@ -681,7 +681,7 @@ impl ConditionalEqGadget for Boolean { // 1 - 1 = 0 - 0 = 0 (Constant(true), Constant(true)) | (Constant(false), Constant(false)) => return Ok(()), // false != true - (Constant(_), Constant(_)) => Err(SynthesisError::AssignmentMissing)?, + (Constant(_), Constant(_)) => return Err(SynthesisError::AssignmentMissing), // 1 - a (Constant(true), Is(a)) | (Is(a), Constant(true)) => { LinearCombination::zero() + one - a.get_variable()