Skip to content

Commit b4ca705

Browse files
Version bump, small cleanups, README
1 parent 879a827 commit b4ca705

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "nmt-rs"
3-
version = "0.2.1"
3+
version = "0.2.3"
44
edition = "2021"
55
description = "A namespaced merkle tree compatible with Celestia"
66
license = "MIT OR Apache-2.0"
@@ -21,7 +21,7 @@ nmt-rs = { path = ".", features = ["borsh", "serde"] }
2121
borsh = { version = "1" }
2222
serde_json = "1.0.96"
2323
postcard = { version = "1.0.4", features = ["use-std"] }
24-
tendermint = { version = "0.35.0" }
24+
tendermint = { version = "0.39.1" }
2525

2626
[features]
2727
default = ["std"]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This code has not been audited, and may contain critical vulnerabilities. Do not
2020

2121
- [x] Verify namespace range proofs
2222

23+
- [x] Narrow namespace range proofs: supply part of the range to generate a proof for the remaining sub-range
2324

2425
## License
2526

src/nmt_proof.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! - A range of leaves forms a complete namespace
44
//! - A range of leaves all exists in the same namespace
55
use crate::maybestd::{mem, vec::Vec};
6-
use crate::simple_merkle::db::MemDb;
76
use crate::{
87
namespaced_hash::{NamespaceId, NamespaceMerkleHasher, NamespacedHash},
98
simple_merkle::{
@@ -118,23 +117,18 @@ where
118117
return Err(RangeProofError::WrongAmountOfLeavesProvided);
119118
}
120119

121-
// TODO: make this more concise
122-
let left_extra_hashes: Vec<_> = left_extra_raw_leaves
123-
.iter()
124-
.map(|data| {
125-
M::with_ignore_max_ns(self.ignores_max_ns())
126-
.hash_leaf_with_namespace(data.as_ref(), leaf_namespace)
127-
})
128-
.collect();
129-
let right_extra_hashes: Vec<_> = right_extra_raw_leaves
130-
.iter()
131-
.map(|data| {
132-
M::with_ignore_max_ns(self.ignores_max_ns())
133-
.hash_leaf_with_namespace(data.as_ref(), leaf_namespace)
134-
})
135-
.collect();
120+
let leaves_to_hashes = |l: &[L]| -> Vec<NamespacedHash<NS_ID_SIZE>> {
121+
l.iter()
122+
.map(|data| {
123+
M::with_ignore_max_ns(self.ignores_max_ns())
124+
.hash_leaf_with_namespace(data.as_ref(), leaf_namespace)
125+
})
126+
.collect()
127+
};
128+
let left_extra_hashes = leaves_to_hashes(left_extra_raw_leaves);
129+
let right_extra_hashes = leaves_to_hashes(right_extra_raw_leaves);
136130

137-
let mut tree = NamespaceMerkleTree::<MemDb<M::Output>, M, NS_ID_SIZE>::with_hasher(
131+
let mut tree = NamespaceMerkleTree::<NoopDb, M, NS_ID_SIZE>::with_hasher(
138132
M::with_ignore_max_ns(self.ignores_max_ns()),
139133
);
140134

src/simple_merkle/proof.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::ops::Range;
22

33
use super::{
4-
db::{MemDb, NoopDb},
4+
db::NoopDb,
55
error::RangeProofError,
66
tree::{MerkleHash, MerkleTree},
77
utils::compute_num_left_siblings,
@@ -100,9 +100,12 @@ where
100100
let new_start_idx = (self.start_idx() as usize)
101101
.checked_add(left_extra_leaves.len())
102102
.ok_or(RangeProofError::TreeTooLarge)?;
103-
let new_end_idx = new_start_idx + self.range_len() - new_leaf_len as usize; // TODO safe arithmetic
103+
let new_end_idx = new_start_idx
104+
.checked_add(self.range_len())
105+
.and_then(|i| i.checked_sub(new_leaf_len))
106+
.ok_or(RangeProofError::TreeTooLarge)?;
104107

105-
let mut tree = MerkleTree::<MemDb<M::Output>, M>::with_hasher(hasher);
108+
let mut tree = MerkleTree::<NoopDb, M>::with_hasher(hasher);
106109
tree.narrow_range_proof(
107110
left_extra_leaves,
108111
new_start_idx..new_end_idx,

0 commit comments

Comments
 (0)