diff options
| author | Santo Cariotti <santo@dcariotti.me> | 2025-06-23 12:27:51 +0000 |
|---|---|---|
| committer | Santo Cariotti <santo@dcariotti.me> | 2025-06-23 12:27:51 +0000 |
| commit | e27cfcb046758fd15e48b98bcdba34e34ae2d3bd (patch) | |
| tree | 08fa792e5ea99d82528f045e43ea43077b60d6b4 | |
| parent | 6e2fe64170ca7dc49b42d7db1e73bd36f149f206 (diff) | |
Add proofer example
| -rw-r--r-- | examples/proofer_blake3.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/examples/proofer_blake3.rs b/examples/proofer_blake3.rs new file mode 100644 index 0000000..154b51c --- /dev/null +++ b/examples/proofer_blake3.rs @@ -0,0 +1,47 @@ +use mt_rs::{ + hasher::{Blake3Hasher, Hasher}, + node::Node, + proof::{DefaultProofer, Proofer}, +}; + +fn main() { + let root_hash = match std::env::args().nth(1) { + Some(hash) => hash, + None => { + eprintln!( + "Usage: cargo run --example proofer_blake3 -- <root_hash> <file1> <file2> ..." + ); + std::process::exit(1); + } + }; + + let filenames: Vec<String> = std::env::args().skip(2).collect(); + if filenames.is_empty() { + eprintln!("Usage: cargo run --example proofer_blake3 -- <root_hash> <file1> <file2> ..."); + std::process::exit(1); + } + + 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)); + } + Err(e) => { + eprintln!("Failed to read file '{}': {}", filename, e); + std::process::exit(1); + } + } + } + + 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) + ); +} |
