Skip to content
Permalink
Browse files

Prefer to return error rather than ? them,

avoid return when it cant be early (in a simple if-else)
  • Loading branch information
huitseeker authored and Pratyush committed Dec 2, 2019
1 parent 9fec4b1 commit 7228d0606b43f6329e7f226083ca52e48c1dc8ca
@@ -200,7 +200,7 @@ impl<P: MerkleTreeConfig> MerkleHashTree<P> {

// 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<P: MerkleTreeConfig> MerkleHashTree<P> {
}
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 })
}
@@ -100,7 +100,7 @@ where
for sn in transaction.old_serial_numbers() {
if sn != &self.genesis_sn {
if self.sn_to_index.contains_key(sn) {
Err(LedgerError::DuplicateSn)?;
return Err(LedgerError::DuplicateSn.into());
}
self.sn_to_index.insert(sn.clone(), cur_sn_index);
cur_sn_index += 1;
@@ -111,7 +111,7 @@ where
let mut cur_cm_index = self.cur_cm_index;
for cm in transaction.new_commitments() {
if cm == &self.genesis_cm || self.comm_to_index.contains_key(cm) {
Err(LedgerError::InvalidCm)?;
return Err(LedgerError::InvalidCm.into());
}
self.comm_to_index.insert(cm.clone(), cur_cm_index);
cur_cm_index += 1;
@@ -120,7 +120,7 @@ where

if transaction.memorandum() != &self.genesis_memo {
if self.memo_to_index.contains_key(transaction.memorandum()) {
Err(LedgerError::DuplicateMemo)?;
return Err(LedgerError::DuplicateMemo.into());
} else {
self.memo_to_index
.insert(transaction.memorandum().clone(), self.cur_memo_index);
@@ -66,7 +66,7 @@ impl<F: Field> LinearCombination<F> {
found_index += 1;
}
}
return Err(found_index);
Err(found_index)
} else {
self.0
.binary_search_by_key(search_var, |&(cur_var, _)| cur_var)
@@ -681,7 +681,7 @@ impl<ConstraintF: Field> ConditionalEqGadget<ConstraintF> 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()

0 comments on commit 7228d06

Please sign in to comment.
You can’t perform that action at this time.