summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--examples/proofer_blake3.rs13
-rw-r--r--src/merkletree.rs9
-rw-r--r--src/node.rs16
-rw-r--r--src/proof.rs7
5 files changed, 14 insertions, 33 deletions
diff --git a/README.md b/README.md
index b16fa15..4f1e734 100644
--- a/README.md
+++ b/README.md
@@ -58,7 +58,7 @@ fn main() {
let proof = proofer.generate(0).expect("Couldn't generate proof");
assert!(tree.root().hash() == root_hash);
- assert!(proofer.verify(&proof, tree.leaves()[0].data(), tree.root().hash(), &hasher));
+ assert!(proofer.verify(&proof, std::fs::read(&filenames[0]).unwrap(), tree.root().hash(), &hasher));
}
```
diff --git a/examples/proofer_blake3.rs b/examples/proofer_blake3.rs
index 154b51c..62d1429 100644
--- a/examples/proofer_blake3.rs
+++ b/examples/proofer_blake3.rs
@@ -24,10 +24,7 @@ fn main() {
let mut nodes: Vec<Node> = Vec::new();
for filename in &filenames {
match std::fs::read(filename) {
- Ok(contents) => {
- let hash = Blake3Hasher::new().hash(&contents);
- nodes.push(Node::new_leaf(&contents, hash));
- }
+ Ok(contents) => nodes.push(Node::new_leaf(Blake3Hasher::new().hash(&contents))),
Err(e) => {
eprintln!("Failed to read file '{}': {}", filename, e);
std::process::exit(1);
@@ -35,13 +32,17 @@ fn main() {
}
}
- let first_node = nodes[0].clone();
let hasher = Blake3Hasher::new();
let proofer = DefaultProofer::new(&hasher, nodes);
let proof = proofer.generate(0).expect("Couldn't generate proof");
println!(
"{}",
- proofer.verify(&proof, first_node.data(), &root_hash[..], &hasher)
+ proofer.verify(
+ &proof,
+ std::fs::read(&filenames[0]).unwrap(),
+ &root_hash[..],
+ &hasher
+ )
);
}
diff --git a/src/merkletree.rs b/src/merkletree.rs
index 362077e..c8962f4 100644
--- a/src/merkletree.rs
+++ b/src/merkletree.rs
@@ -49,7 +49,7 @@ impl MerkleTree {
let mut leaves: Vec<Node> = data_slices
.iter()
- .map(|data| Node::new_leaf(data, hasher.hash(data)))
+ .map(|data| Node::new_leaf(hasher.hash(data)))
.collect();
if leaves.len() % 2 != 0 {
@@ -87,12 +87,7 @@ impl MerkleTree {
buffer.extend_from_slice(right_hash);
let hash = hasher.hash(&buffer);
- next_level.push(Node::new_internal(
- &buffer,
- hash,
- left.clone(),
- right.clone(),
- ));
+ next_level.push(Node::new_internal(hash, left.clone(), right.clone()));
}
std::mem::swap(&mut current_level, &mut next_level);
diff --git a/src/node.rs b/src/node.rs
index e7e6b0f..e784a69 100644
--- a/src/node.rs
+++ b/src/node.rs
@@ -43,8 +43,6 @@ pub struct Node {
hash: String,
/// Type of the node: leaf or internal.
status: NodeStatus,
- /// Data in bytes.
- data: Vec<u8>,
}
impl Node {
@@ -53,11 +51,9 @@ impl Node {
/// # Arguments
///
/// * `hasher` - A reference to a hashing strategy.
- /// * `data` - The data to be hashed and stored as a leaf.
- pub fn new_leaf(data: &[u8], hash: String) -> Self {
+ pub fn new_leaf(hash: String) -> Self {
Self {
hash,
- data: data.to_vec(),
status: NodeStatus::Leaf,
}
}
@@ -66,17 +62,16 @@ impl Node {
///
/// # Arguments
///
- /// * `hasher` - A reference to a hashing strategy.
+ /// * `hash` - An hash value for the following node.
/// * `left` - Left child node.
/// * `right` - Right child node.
///
/// # Behavior
///
/// The internal node hash is computed as the hash of the concatenated children's hashes.
- pub fn new_internal(data: &[u8], hash: String, left: Node, right: Node) -> Self {
+ pub fn new_internal(hash: String, left: Node, right: Node) -> Self {
Self {
hash,
- data: data.to_vec(),
status: NodeStatus::Internal(Box::new(left), Box::new(right)),
}
}
@@ -86,11 +81,6 @@ impl Node {
&self.hash
}
- /// Returns the data value in bytes format.
- pub fn data(&self) -> &[u8] {
- &self.data
- }
-
/// Returns a reference to the node's type (leaf or internal).
pub fn status(&self) -> &NodeStatus {
&self.status
diff --git a/src/proof.rs b/src/proof.rs
index 4c42841..c893b08 100644
--- a/src/proof.rs
+++ b/src/proof.rs
@@ -110,12 +110,7 @@ impl Proofer for DefaultProofer<'_> {
buffer.extend_from_slice(right_hash);
let hash = self.hasher.hash(&buffer);
- next_level.push(Node::new_internal(
- &buffer,
- hash,
- left.clone(),
- right.clone(),
- ));
+ next_level.push(Node::new_internal(hash, left.clone(), right.clone()));
}
current_level = next_level;
current_index /= 2;