16 Commits

Author SHA1 Message Date
Quake Wang c0c9263122 Merge pull request #45 from eval-exec/exec/bump-0.7.0
bump version to 0.7.0
2025-03-11 13:43:10 +09:00
Eval EXEC 0ab3dac108 bump version to 0.7.0 2025-03-11 12:23:05 +08:00
zhangsoledad 25c5d823a0 Merge pull request #42 from eval-exec/exec/upgrade-rust-2024
Rust Toolchain: Upgrade to rust edition 2024
2025-03-11 04:01:34 +00:00
Eval EXEC 5c70a2da40 cargo: set MSRV to 1.85.0, since we use rust 2024 edition 2025-03-11 11:05:32 +08:00
Quake Wang ea53d5cd45 Merge pull request #44 from eval-exec/exec/bump-0.6.1
bump version to 0.6.1
2025-03-11 12:02:53 +09:00
Eval EXEC ac82e869e3 execute cargo fmt --all 2025-03-11 10:56:54 +08:00
Eval EXEC 6099da18fa rust-toolchain: upgrade rust 2024 2025-03-11 10:56:53 +08:00
Eval EXEC ee499a9ef0 clippy: Using mem::take is faster as it avoids the allocation: https://rust-lang.github.io/rust-clippy/master/index.html#drain_collect
cargo clippy  --all --all-features --all-targets
warning: you seem to be trying to move all elements into a new `Vec`
   --> src/mmr.rs:501:5
    |
501 |     v.drain(..).collect()
    |     ^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(v)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#drain_collect
    = note: `#[warn(clippy::drain_collect)]` on by default

Signed-off-by: Eval EXEC <execvy@gmail.com>
2025-03-11 10:55:43 +08:00
Eval EXEC 6e2e9450a2 rust-toolchain: upgrade rust edition to 2021
Signed-off-by: Eval EXEC <execvy@gmail.com>
2025-03-11 10:55:42 +08:00
Eval EXEC dcf3ff85db bump version to 0.6.1 2025-03-11 10:48:30 +08:00
Quake Wang e049986f9c Merge pull request #43 from eval-exec/exec/msrv
cargo: set MSRV to 1.60.0
2025-03-11 11:41:26 +09:00
Eval EXEC 29afe7ad15 cargo: set MSRV to 1.60.0 2025-03-10 16:29:41 +08:00
Quake Wang 5c33c7af57 Merge pull request #41 from dlachaume/fix-typo
fix: typo in error message for invalid leaves
2025-03-04 11:26:47 +09:00
Damien Lachaume becf6e3430 fix: typo in error message for invalid leaves 2025-03-03 15:11:25 +01:00
Quake Wang 20c1987d8d Merge pull request #40 from Lederstrumpf/Lederstrumpf-add-license
Add explicit MIT license
2024-12-11 18:29:13 +09:00
Robert Hambrock 246da2661d Create LICENSE 2024-09-11 11:23:07 +02:00
13 changed files with 41 additions and 16 deletions
+3 -2
View File
@@ -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"
+21
View File
@@ -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.
+1 -1
View File
@@ -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| {
+1 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -1,4 +1,4 @@
use crate::{vec::Vec, Result};
use crate::{Result, vec::Vec};
#[derive(Default)]
pub struct MMRBatch<Elem, Store> {
+1 -1
View File
@@ -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 -1
View File
@@ -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::*;
+6 -4
View File
@@ -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),
}
+1 -1
View File
@@ -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
View File
@@ -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)]