Skip to content

Commit

Permalink
fix InvalidNumEntries error condition
Browse files Browse the repository at this point in the history
  • Loading branch information
plafer committed Nov 27, 2023
1 parent 244204b commit ed2efb7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/merkle/simple_smt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ impl SimpleSmt {
// append leaves to the tree returning an error if a duplicate entry for the same key
// is found
let mut empty_entries = BTreeSet::new();
for (key, value) in entries {
let old_value = tree
.update_leaf(key, value)
.map_err(|_| MerkleError::InvalidNumEntries(max_num_entries))?;
for (idx, (key, value)) in entries.into_iter().enumerate() {
if idx >= max_num_entries {
return Err(MerkleError::InvalidNumEntries(max_num_entries));
}

let old_value = tree.update_leaf(key, value)?;

if old_value != Self::EMPTY_VALUE || empty_entries.contains(&key) {
return Err(MerkleError::DuplicateValuesForIndex(key));
Expand Down

0 comments on commit ed2efb7

Please sign in to comment.