mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-02-11 17:55:46 +00:00
Rename zcash_mmr to zcash_history.
This crate will contain all chain history logic.
This commit is contained in:
parent
9379eec1b8
commit
5e1a2f9d3f
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -426,7 +426,7 @@ dependencies = [
|
|||||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pairing 0.15.1",
|
"pairing 0.15.1",
|
||||||
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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_primitives 0.1.0",
|
||||||
"zcash_proofs 0.1.0",
|
"zcash_proofs 0.1.0",
|
||||||
]
|
]
|
||||||
@ -866,8 +866,8 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zcash_mmr"
|
name = "zcash_history"
|
||||||
version = "0.1.0"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"bigint 4.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -28,7 +28,7 @@ libc = "0.2"
|
|||||||
pairing = { version = "0.15.0", path = "../pairing" }
|
pairing = { version = "0.15.0", path = "../pairing" }
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
rand_core = "0.5.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_primitives = { version = "0.1.0", path = "../zcash_primitives" }
|
||||||
zcash_proofs = { version = "0.1.0", path = "../zcash_proofs" }
|
zcash_proofs = { version = "0.1.0", path = "../zcash_proofs" }
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ use zcash_proofs::{
|
|||||||
sprout,
|
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)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
@ -1173,7 +1173,7 @@ fn construct_mmr_tree(
|
|||||||
// Indices of provided tree nodes, length of p_len+e_len
|
// Indices of provided tree nodes, length of p_len+e_len
|
||||||
ni_ptr: *const u32,
|
ni_ptr: *const u32,
|
||||||
// Provided tree nodes data, length of p_len+e_len
|
// 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
|
// Peaks count
|
||||||
p_len: size_t,
|
p_len: size_t,
|
||||||
@ -1211,17 +1211,17 @@ pub extern "system" fn librustzcash_mmr_append(
|
|||||||
// Indices of provided tree nodes, length of p_len
|
// Indices of provided tree nodes, length of p_len
|
||||||
ni_ptr: *const u32,
|
ni_ptr: *const u32,
|
||||||
// Provided tree nodes data, length of p_len
|
// 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
|
// Peaks count
|
||||||
p_len: size_t,
|
p_len: size_t,
|
||||||
// New node pointer
|
// 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
|
// Return of root commitment
|
||||||
rt_ret: *mut [u8; 32],
|
rt_ret: *mut [u8; 32],
|
||||||
// Return buffer for appended leaves, should be pre-allocated of ceiling(log2(t_len)) length
|
// 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 {
|
) -> 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() {
|
match nn_ptr.as_ref() {
|
||||||
Some(r) => r,
|
Some(r) => r,
|
||||||
None => {
|
None => {
|
||||||
@ -1283,7 +1283,7 @@ pub extern "system" fn librustzcash_mmr_delete(
|
|||||||
// Indices of provided tree nodes, length of p_len+e_len
|
// Indices of provided tree nodes, length of p_len+e_len
|
||||||
ni_ptr: *const u32,
|
ni_ptr: *const u32,
|
||||||
// Provided tree nodes data, length of p_len+e_len
|
// 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
|
// Peaks count
|
||||||
p_len: size_t,
|
p_len: size_t,
|
||||||
// Extra nodes loaded (for deletion) count
|
// Extra nodes loaded (for deletion) count
|
||||||
@ -1319,10 +1319,10 @@ pub extern "system" fn librustzcash_mmr_delete(
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "system" fn librustzcash_mmr_hash_node(
|
pub extern "system" fn librustzcash_mmr_hash_node(
|
||||||
cbranch: u32,
|
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],
|
h_ret: *mut [u8; 32],
|
||||||
) -> u32 {
|
) -> 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() {
|
match n_ptr.as_ref() {
|
||||||
Some(r) => r,
|
Some(r) => r,
|
||||||
None => return 1,
|
None => return 1,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use zcash_mmr::{Entry, EntryLink, NodeData};
|
use zcash_history::{Entry, EntryLink, NodeData};
|
||||||
|
|
||||||
use crate::{librustzcash_mmr_append, librustzcash_mmr_delete};
|
use crate::{librustzcash_mmr_append, librustzcash_mmr_delete};
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ fn prepare_tree(nodes: &[NodeData]) -> TreeView {
|
|||||||
TreeView { peaks, extra }
|
TreeView { peaks, extra }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn preload_tree_append(nodes: &[NodeData]) -> (Vec<u32>, Vec<[u8; zcash_mmr::MAX_ENTRY_SIZE]>) {
|
fn preload_tree_append(nodes: &[NodeData]) -> (Vec<u32>, Vec<[u8; zcash_history::MAX_ENTRY_SIZE]>) {
|
||||||
assert!(!nodes.is_empty());
|
assert!(!nodes.is_empty());
|
||||||
|
|
||||||
let tree_view = prepare_tree(nodes);
|
let tree_view = prepare_tree(nodes);
|
||||||
@ -91,7 +91,7 @@ fn preload_tree_append(nodes: &[NodeData]) -> (Vec<u32>, Vec<[u8; zcash_mmr::MAX
|
|||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
|
|
||||||
for (idx, entry) in tree_view.peaks.into_iter() {
|
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
|
entry
|
||||||
.write(&mut &mut buf[..])
|
.write(&mut &mut buf[..])
|
||||||
.expect("Cannot fail if enough buffer length");
|
.expect("Cannot fail if enough buffer length");
|
||||||
@ -105,7 +105,7 @@ fn preload_tree_append(nodes: &[NodeData]) -> (Vec<u32>, Vec<[u8; zcash_mmr::MAX
|
|||||||
// also returns number of peaks
|
// also returns number of peaks
|
||||||
fn preload_tree_delete(
|
fn preload_tree_delete(
|
||||||
nodes: &[NodeData],
|
nodes: &[NodeData],
|
||||||
) -> (Vec<u32>, Vec<[u8; zcash_mmr::MAX_ENTRY_SIZE]>, usize) {
|
) -> (Vec<u32>, Vec<[u8; zcash_history::MAX_ENTRY_SIZE]>, usize) {
|
||||||
assert!(!nodes.is_empty());
|
assert!(!nodes.is_empty());
|
||||||
|
|
||||||
let tree_view = prepare_tree(nodes);
|
let tree_view = prepare_tree(nodes);
|
||||||
@ -120,7 +120,7 @@ fn preload_tree_delete(
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(tree_view.extra.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
|
entry
|
||||||
.write(&mut &mut buf[..])
|
.write(&mut &mut buf[..])
|
||||||
.expect("Cannot fail if enough buffer length");
|
.expect("Cannot fail if enough buffer length");
|
||||||
@ -136,7 +136,7 @@ fn load_nodes(bytes: &'static [u8]) -> Vec<NodeData> {
|
|||||||
let mut cursor = std::io::Cursor::new(bytes);
|
let mut cursor = std::io::Cursor::new(bytes);
|
||||||
while (cursor.position() as usize) < bytes.len() {
|
while (cursor.position() as usize) < bytes.len() {
|
||||||
let node_data =
|
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);
|
res.push(node_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,9 +150,9 @@ fn append() {
|
|||||||
|
|
||||||
let mut rt_ret = [0u8; 32];
|
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 {
|
let new_node = NodeData {
|
||||||
consensus_branch_id: 0,
|
consensus_branch_id: 0,
|
||||||
subtree_commitment: [0u8; 32],
|
subtree_commitment: [0u8; 32],
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
language: rust
|
|
||||||
rust:
|
|
||||||
- nightly
|
|
||||||
- stable
|
|
14
zcash_history/COPYRIGHT
Normal file
14
zcash_history/COPYRIGHT
Normal file
@ -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.
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "zcash_mmr"
|
name = "zcash_history"
|
||||||
version = "0.1.0"
|
version = "0.0.1"
|
||||||
authors = ["NikVolf <nikvolf@gmail.com>"]
|
authors = ["NikVolf <nikvolf@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# zcash_mmr
|
# zcash_history
|
||||||
|
|
||||||
Special implementation of Merkle mountain ranges (MMR) for Zcash!
|
Special implementation of Merkle mountain ranges (MMR) for Zcash!
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ The main design goals of this MMR implementation are
|
|||||||
|
|
||||||
# License
|
# 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.
|
license and the Apache License (Version 2.0), at your choice.
|
||||||
|
|
||||||
See LICENSE-APACHE, and LICENSE-MIT for details.
|
See LICENSE-APACHE, and LICENSE-MIT for details.
|
||||||
@ -22,5 +22,5 @@ See LICENSE-APACHE, and LICENSE-MIT for details.
|
|||||||
### Contribution
|
### Contribution
|
||||||
|
|
||||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
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.
|
dual licensed as above, without any additional terms or conditions.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use zcash_mmr:: {NodeData, Tree, Entry, EntryLink};
|
use zcash_history:: {NodeData, Tree, Entry, EntryLink};
|
||||||
|
|
||||||
pub struct NodeDataIterator {
|
pub struct NodeDataIterator {
|
||||||
return_stack: Vec<NodeData>,
|
return_stack: Vec<NodeData>,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use zcash_mmr::{Entry, EntryLink, NodeData, Tree};
|
use zcash_history::{Entry, EntryLink, NodeData, Tree};
|
||||||
|
|
||||||
#[path= "lib/shared.rs"]
|
#[path= "lib/shared.rs"]
|
||||||
mod share;
|
mod share;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//! MMR library for Zcash
|
//! Chain history library for Zcash
|
||||||
//!
|
//!
|
||||||
//! To be used in zebra and via FFI bindings in zcashd
|
//! To be used in zebra and via FFI bindings in zcashd
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user