mirror of
https://github.com/pezkuwichain/merkle-mountain-range.git
synced 2026-04-22 10:17:55 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c0c9263122 | |||
| 0ab3dac108 | |||
| 25c5d823a0 | |||
| 5c70a2da40 | |||
| ea53d5cd45 | |||
| ac82e869e3 | |||
| 6099da18fa | |||
| ee499a9ef0 | |||
| 6e2e9450a2 | |||
| dcf3ff85db | |||
| e049986f9c | |||
| 29afe7ad15 | |||
| 5c33c7af57 | |||
| becf6e3430 | |||
| 20c1987d8d | |||
| 246da2661d |
+3
-2
@@ -1,8 +1,9 @@
|
||||
[package]
|
||||
name = "ckb-merkle-mountain-range"
|
||||
version = "0.6.0"
|
||||
version = "0.7.0"
|
||||
authors = ["Nervos Core Dev <dev@nervos.org>"]
|
||||
edition = "2018"
|
||||
edition = "2024"
|
||||
rust-version = "1.85.0"
|
||||
license = "MIT"
|
||||
description = "A generalized merkle mountain range implementation"
|
||||
repository = "https://github.com/nervosnetwork/merkle-mountain-range"
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 nervosnetwork
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -4,7 +4,7 @@ use criterion::Criterion;
|
||||
|
||||
use ckb_merkle_mountain_range::{leaf_index_to_mmr_size, leaf_index_to_pos};
|
||||
|
||||
use rand::{thread_rng, Rng};
|
||||
use rand::{Rng, thread_rng};
|
||||
|
||||
fn bench(c: &mut Criterion) {
|
||||
c.bench_function("left_index_to_pos", |b| {
|
||||
|
||||
@@ -4,7 +4,7 @@ extern crate criterion;
|
||||
use criterion::{BenchmarkId, Criterion};
|
||||
|
||||
use bytes::Bytes;
|
||||
use ckb_merkle_mountain_range::{util::MemStore, Error, MMRStoreReadOps, Merge, Result, MMR};
|
||||
use ckb_merkle_mountain_range::{Error, MMR, MMRStoreReadOps, Merge, Result, util::MemStore};
|
||||
use rand::{seq::SliceRandom, thread_rng};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ impl core::fmt::Display for Error {
|
||||
StoreError(msg) => write!(f, "Store error {}", msg)?,
|
||||
CorruptedProof => write!(f, "Corrupted proof")?,
|
||||
NodeProofsNotSupported => write!(f, "Tried to verify membership of a non-leaf")?,
|
||||
GenProofForInvalidLeaves => write!(f, "Generate proof ofr invalid leaves")?,
|
||||
GenProofForInvalidLeaves => write!(f, "Generate proof for invalid leaves")?,
|
||||
MergeError(msg) => write!(f, "Merge error {}", msg)?,
|
||||
}
|
||||
Ok(())
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ pub mod util;
|
||||
pub use error::{Error, Result};
|
||||
pub use helper::{leaf_index_to_mmr_size, leaf_index_to_pos};
|
||||
pub use merge::Merge;
|
||||
pub use mmr::{MerkleProof, MMR};
|
||||
pub use mmr::{MMR, MerkleProof};
|
||||
pub use mmr_store::{MMRStoreReadOps, MMRStoreWriteOps};
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@ use crate::vec::Vec;
|
||||
use crate::{Error, Merge, Result};
|
||||
use core::fmt::Debug;
|
||||
use core::marker::PhantomData;
|
||||
use core::mem;
|
||||
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
pub struct MMR<T, M, S> {
|
||||
@@ -498,5 +499,5 @@ fn take_while_vec<T, P: Fn(&T) -> bool>(v: &mut Vec<T>, p: P) -> Vec<T> {
|
||||
return v.drain(..i).collect();
|
||||
}
|
||||
}
|
||||
v.drain(..).collect()
|
||||
mem::take(v)
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
use crate::{vec::Vec, Result};
|
||||
use crate::{Result, vec::Vec};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct MMRBatch<Elem, Store> {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::new_blake2b;
|
||||
use crate::{leaf_index_to_pos, util::MemStore, MMRStoreReadOps, Merge, MerkleProof, Result, MMR};
|
||||
use crate::{MMR, MMRStoreReadOps, Merge, MerkleProof, Result, leaf_index_to_pos, util::MemStore};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use std::fmt;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use super::{MergeNumberHash, NumberHash};
|
||||
use crate::{
|
||||
MMR,
|
||||
helper::{get_peak_map, get_peaks, pos_height_in_tree},
|
||||
leaf_index_to_mmr_size, leaf_index_to_pos,
|
||||
util::MemStore,
|
||||
MMR,
|
||||
};
|
||||
use lazy_static::lazy_static;
|
||||
use proptest::prelude::*;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use super::{MergeNumberHash, NumberHash};
|
||||
use crate::{
|
||||
Error,
|
||||
helper::pos_height_in_tree,
|
||||
leaf_index_to_mmr_size,
|
||||
util::{MemMMR, MemStore},
|
||||
Error,
|
||||
};
|
||||
use faster_hex::hex_string;
|
||||
use proptest::prelude::*;
|
||||
@@ -234,9 +234,11 @@ fn test_invalid_proof_verification(
|
||||
}
|
||||
Err(Error::NodeProofsNotSupported) => {
|
||||
// if couldn't generate proof, then it contained a non-leaf
|
||||
assert!(positions_to_verify
|
||||
.iter()
|
||||
.any(|pos| pos_height_in_tree(*pos) > 0));
|
||||
assert!(
|
||||
positions_to_verify
|
||||
.iter()
|
||||
.any(|pos| pos_height_in_tree(*pos) > 0)
|
||||
);
|
||||
}
|
||||
Err(e) => panic!("Unexpected error: {}", e),
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::fmt;
|
||||
use proptest::proptest;
|
||||
use rand::{prelude::*, thread_rng};
|
||||
|
||||
use crate::{util::MemStore, Merge, Result, MMR};
|
||||
use crate::{MMR, Merge, Result, util::MemStore};
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Default)]
|
||||
struct NumberRange {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
use crate::collections::BTreeMap;
|
||||
use crate::{vec::Vec, MMRStoreReadOps, MMRStoreWriteOps, Result, MMR};
|
||||
use crate::{MMR, MMRStoreReadOps, MMRStoreWriteOps, Result, vec::Vec};
|
||||
use core::cell::RefCell;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
||||
Reference in New Issue
Block a user