From 5e1a2f9d3fd1004d0f7a54a0e755ff5526da9354 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Tue, 3 Mar 2020 18:05:14 -0700 Subject: [PATCH] Rename zcash_mmr to zcash_history. This crate will contain all chain history logic. --- Cargo.lock | 6 +++--- librustzcash/Cargo.toml | 2 +- librustzcash/src/rustzcash.rs | 18 +++++++++--------- librustzcash/src/tests/mmr.rs | 16 ++++++++-------- zcash_history/.travis.yml | 4 ---- zcash_history/COPYRIGHT | 14 ++++++++++++++ zcash_history/Cargo.toml | 4 ++-- zcash_history/README.md | 6 +++--- zcash_history/examples/lib/shared.rs | 2 +- zcash_history/examples/long.rs | 2 +- zcash_history/src/lib.rs | 2 +- 11 files changed, 43 insertions(+), 33 deletions(-) delete mode 100644 zcash_history/.travis.yml create mode 100644 zcash_history/COPYRIGHT diff --git a/Cargo.lock b/Cargo.lock index 63a8edd09..37967cf2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -426,7 +426,7 @@ dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "pairing 0.15.1", "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "zcash_mmr 0.1.0", + "zcash_history 0.0.1", "zcash_primitives 0.1.0", "zcash_proofs 0.1.0", ] @@ -866,8 +866,8 @@ dependencies = [ ] [[package]] -name = "zcash_mmr" -version = "0.1.0" +name = "zcash_history" +version = "0.0.1" dependencies = [ "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "bigint 4.4.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/librustzcash/Cargo.toml b/librustzcash/Cargo.toml index 8c7d4ff8b..304dbdfec 100644 --- a/librustzcash/Cargo.toml +++ b/librustzcash/Cargo.toml @@ -28,7 +28,7 @@ libc = "0.2" pairing = { version = "0.15.0", path = "../pairing" } lazy_static = "1" rand_core = "0.5.1" -zcash_mmr = { version = "0.1.0", path = "../zcash_history" } +zcash_history = { version = "0.0.1", path = "../zcash_history" } zcash_primitives = { version = "0.1.0", path = "../zcash_primitives" } zcash_proofs = { version = "0.1.0", path = "../zcash_proofs" } diff --git a/librustzcash/src/rustzcash.rs b/librustzcash/src/rustzcash.rs index 084d5b0ff..c60b1d55a 100644 --- a/librustzcash/src/rustzcash.rs +++ b/librustzcash/src/rustzcash.rs @@ -65,7 +65,7 @@ use zcash_proofs::{ sprout, }; -use zcash_mmr::{Entry as MMREntry, NodeData as MMRNodeData, Tree as MMRTree}; +use zcash_history::{Entry as MMREntry, NodeData as MMRNodeData, Tree as MMRTree}; #[cfg(test)] mod tests; @@ -1173,7 +1173,7 @@ fn construct_mmr_tree( // Indices of provided tree nodes, length of p_len+e_len ni_ptr: *const u32, // Provided tree nodes data, length of p_len+e_len - n_ptr: *const [c_uchar; zcash_mmr::MAX_ENTRY_SIZE], + n_ptr: *const [c_uchar; zcash_history::MAX_ENTRY_SIZE], // Peaks count p_len: size_t, @@ -1211,17 +1211,17 @@ pub extern "system" fn librustzcash_mmr_append( // Indices of provided tree nodes, length of p_len ni_ptr: *const u32, // Provided tree nodes data, length of p_len - n_ptr: *const [c_uchar; zcash_mmr::MAX_ENTRY_SIZE], + n_ptr: *const [c_uchar; zcash_history::MAX_ENTRY_SIZE], // Peaks count p_len: size_t, // New node pointer - nn_ptr: *const [u8; zcash_mmr::MAX_NODE_DATA_SIZE], + nn_ptr: *const [u8; zcash_history::MAX_NODE_DATA_SIZE], // Return of root commitment rt_ret: *mut [u8; 32], // Return buffer for appended leaves, should be pre-allocated of ceiling(log2(t_len)) length - buf_ret: *mut [c_uchar; zcash_mmr::MAX_NODE_DATA_SIZE], + buf_ret: *mut [c_uchar; zcash_history::MAX_NODE_DATA_SIZE], ) -> u32 { - let new_node_bytes: &[u8; zcash_mmr::MAX_NODE_DATA_SIZE] = unsafe { + let new_node_bytes: &[u8; zcash_history::MAX_NODE_DATA_SIZE] = unsafe { match nn_ptr.as_ref() { Some(r) => r, None => { @@ -1283,7 +1283,7 @@ pub extern "system" fn librustzcash_mmr_delete( // Indices of provided tree nodes, length of p_len+e_len ni_ptr: *const u32, // Provided tree nodes data, length of p_len+e_len - n_ptr: *const [c_uchar; zcash_mmr::MAX_ENTRY_SIZE], + n_ptr: *const [c_uchar; zcash_history::MAX_ENTRY_SIZE], // Peaks count p_len: size_t, // Extra nodes loaded (for deletion) count @@ -1319,10 +1319,10 @@ pub extern "system" fn librustzcash_mmr_delete( #[no_mangle] pub extern "system" fn librustzcash_mmr_hash_node( cbranch: u32, - n_ptr: *const [u8; zcash_mmr::MAX_NODE_DATA_SIZE], + n_ptr: *const [u8; zcash_history::MAX_NODE_DATA_SIZE], h_ret: *mut [u8; 32], ) -> u32 { - let node_bytes: &[u8; zcash_mmr::MAX_NODE_DATA_SIZE] = unsafe { + let node_bytes: &[u8; zcash_history::MAX_NODE_DATA_SIZE] = unsafe { match n_ptr.as_ref() { Some(r) => r, None => return 1, diff --git a/librustzcash/src/tests/mmr.rs b/librustzcash/src/tests/mmr.rs index 4107a75a5..d077f0738 100644 --- a/librustzcash/src/tests/mmr.rs +++ b/librustzcash/src/tests/mmr.rs @@ -1,4 +1,4 @@ -use zcash_mmr::{Entry, EntryLink, NodeData}; +use zcash_history::{Entry, EntryLink, NodeData}; use crate::{librustzcash_mmr_append, librustzcash_mmr_delete}; @@ -82,7 +82,7 @@ fn prepare_tree(nodes: &[NodeData]) -> TreeView { TreeView { peaks, extra } } -fn preload_tree_append(nodes: &[NodeData]) -> (Vec, Vec<[u8; zcash_mmr::MAX_ENTRY_SIZE]>) { +fn preload_tree_append(nodes: &[NodeData]) -> (Vec, Vec<[u8; zcash_history::MAX_ENTRY_SIZE]>) { assert!(!nodes.is_empty()); let tree_view = prepare_tree(nodes); @@ -91,7 +91,7 @@ fn preload_tree_append(nodes: &[NodeData]) -> (Vec, Vec<[u8; zcash_mmr::MAX let mut bytes = Vec::new(); for (idx, entry) in tree_view.peaks.into_iter() { - let mut buf = [0u8; zcash_mmr::MAX_ENTRY_SIZE]; + let mut buf = [0u8; zcash_history::MAX_ENTRY_SIZE]; entry .write(&mut &mut buf[..]) .expect("Cannot fail if enough buffer length"); @@ -105,7 +105,7 @@ fn preload_tree_append(nodes: &[NodeData]) -> (Vec, Vec<[u8; zcash_mmr::MAX // also returns number of peaks fn preload_tree_delete( nodes: &[NodeData], -) -> (Vec, Vec<[u8; zcash_mmr::MAX_ENTRY_SIZE]>, usize) { +) -> (Vec, Vec<[u8; zcash_history::MAX_ENTRY_SIZE]>, usize) { assert!(!nodes.is_empty()); let tree_view = prepare_tree(nodes); @@ -120,7 +120,7 @@ fn preload_tree_delete( .into_iter() .chain(tree_view.extra.into_iter()) { - let mut buf = [0u8; zcash_mmr::MAX_ENTRY_SIZE]; + let mut buf = [0u8; zcash_history::MAX_ENTRY_SIZE]; entry .write(&mut &mut buf[..]) .expect("Cannot fail if enough buffer length"); @@ -136,7 +136,7 @@ fn load_nodes(bytes: &'static [u8]) -> Vec { let mut cursor = std::io::Cursor::new(bytes); while (cursor.position() as usize) < bytes.len() { let node_data = - zcash_mmr::NodeData::read(0, &mut cursor).expect("Statically checked to be correct"); + zcash_history::NodeData::read(0, &mut cursor).expect("Statically checked to be correct"); res.push(node_data); } @@ -150,9 +150,9 @@ fn append() { let mut rt_ret = [0u8; 32]; - let mut buf_ret = Vec::<[u8; zcash_mmr::MAX_NODE_DATA_SIZE]>::with_capacity(32); + let mut buf_ret = Vec::<[u8; zcash_history::MAX_NODE_DATA_SIZE]>::with_capacity(32); - let mut new_node_data = [0u8; zcash_mmr::MAX_NODE_DATA_SIZE]; + let mut new_node_data = [0u8; zcash_history::MAX_NODE_DATA_SIZE]; let new_node = NodeData { consensus_branch_id: 0, subtree_commitment: [0u8; 32], diff --git a/zcash_history/.travis.yml b/zcash_history/.travis.yml deleted file mode 100644 index 00e7694a3..000000000 --- a/zcash_history/.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -language: rust -rust: -- nightly -- stable \ No newline at end of file diff --git a/zcash_history/COPYRIGHT b/zcash_history/COPYRIGHT new file mode 100644 index 000000000..bb8c4e7dd --- /dev/null +++ b/zcash_history/COPYRIGHT @@ -0,0 +1,14 @@ +Copyrights in the "zcash_history" library are retained by their contributors. No +copyright assignment is required to contribute to the "zcash_history" library. + +The "zcash_history" library is licensed under either of + + * Apache License, Version 2.0, (see ./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) + * MIT license (see ./LICENSE-MIT or http://opensource.org/licenses/MIT) + +at your option. + +Unless you explicitly state otherwise, any contribution intentionally +submitted for inclusion in the work by you, as defined in the Apache-2.0 +license, shall be dual licensed as above, without any additional terms or +conditions. diff --git a/zcash_history/Cargo.toml b/zcash_history/Cargo.toml index d527675e7..f397e3fde 100644 --- a/zcash_history/Cargo.toml +++ b/zcash_history/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "zcash_mmr" -version = "0.1.0" +name = "zcash_history" +version = "0.0.1" authors = ["NikVolf "] edition = "2018" diff --git a/zcash_history/README.md b/zcash_history/README.md index f034137ec..5658ec1bc 100644 --- a/zcash_history/README.md +++ b/zcash_history/README.md @@ -1,4 +1,4 @@ -# zcash_mmr +# zcash_history Special implementation of Merkle mountain ranges (MMR) for Zcash! @@ -14,7 +14,7 @@ The main design goals of this MMR implementation are # License -`zcash_mmr` is distributed under the terms of both the MIT +`zcash_history` is distributed under the terms of both the MIT license and the Apache License (Version 2.0), at your choice. See LICENSE-APACHE, and LICENSE-MIT for details. @@ -22,5 +22,5 @@ See LICENSE-APACHE, and LICENSE-MIT for details. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in `zcash_mmr` by you, as defined in the Apache-2.0 license, shall be +for inclusion in `zcash_history` by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/zcash_history/examples/lib/shared.rs b/zcash_history/examples/lib/shared.rs index 4cd926212..dc1b3f932 100644 --- a/zcash_history/examples/lib/shared.rs +++ b/zcash_history/examples/lib/shared.rs @@ -1,4 +1,4 @@ -use zcash_mmr:: {NodeData, Tree, Entry, EntryLink}; +use zcash_history:: {NodeData, Tree, Entry, EntryLink}; pub struct NodeDataIterator { return_stack: Vec, diff --git a/zcash_history/examples/long.rs b/zcash_history/examples/long.rs index 951d2262e..084497457 100644 --- a/zcash_history/examples/long.rs +++ b/zcash_history/examples/long.rs @@ -1,4 +1,4 @@ -use zcash_mmr::{Entry, EntryLink, NodeData, Tree}; +use zcash_history::{Entry, EntryLink, NodeData, Tree}; #[path= "lib/shared.rs"] mod share; diff --git a/zcash_history/src/lib.rs b/zcash_history/src/lib.rs index 0c26dfa94..d1a2ecfdc 100644 --- a/zcash_history/src/lib.rs +++ b/zcash_history/src/lib.rs @@ -1,4 +1,4 @@ -//! MMR library for Zcash +//! Chain history library for Zcash //! //! To be used in zebra and via FFI bindings in zcashd #![warn(missing_docs)]