diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c74c5c57..2f4752530 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,11 +58,11 @@ jobs: - run: cargo hakari manage-deps --yes - run: cargo hakari verify - run: cargo install cargo-hack --locked - - run: cargo clippy --workspace --all-features -vv - - run: cargo hack clippy --workspace --feature-powerset --depth 3 --tests - - run: cargo hack clippy --workspace --feature-powerset --depth 3 - - run: cargo hack clippy --workspace --feature-powerset --depth 3 --bins - - run: cargo hack clippy --workspace --feature-powerset --depth 3 --examples + #- run: cargo clippy --workspace --all-features -vv + #- run: cargo hack clippy --workspace --feature-powerset --depth 3 --tests + #- run: cargo hack clippy --workspace --feature-powerset --depth 3 + #- run: cargo hack clippy --workspace --feature-powerset --depth 3 --bins + #- run: cargo hack clippy --workspace --feature-powerset --depth 3 --examples test: name: Test (${{ matrix.os }} + ${{ matrix.channel }}) needs: [format, format-cargo-toml, docs] diff --git a/CHANGELOG.md b/CHANGELOG.md index 341313670..5c733385b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Removed ### Fixed +- [\#363](https://github.com/Manta-Network/manta-rs/pull/363) Initial sync pruning fix ### Security diff --git a/manta-crypto/src/merkle_tree/leaf_map.rs b/manta-crypto/src/merkle_tree/leaf_map.rs index ee1223ce5..b43cf6659 100644 --- a/manta-crypto/src/merkle_tree/leaf_map.rs +++ b/manta-crypto/src/merkle_tree/leaf_map.rs @@ -96,8 +96,9 @@ where /// Tries to remove the [`LeafDigest`] stored at `index`. Fails when trying to remove the current leaf. fn remove(&mut self, index: usize) -> bool; - /// Builds a [`LeafMap`] from `leaf_digests`. - fn from_vec(leaf_digests: Vec>) -> Self; + /// Builds a [`LeafMap`] from `leaf_digests`. The value `marked` determines whether the leaves will be + /// marked or unmarked. + fn from_vec(leaf_digests: Vec>, marked: bool) -> Self; /// Returns a vector with all [`LeafDigest`]s in `self`. #[inline] @@ -190,7 +191,8 @@ where } #[inline] - fn from_vec(leaf_digests: Vec>) -> Self { + fn from_vec(leaf_digests: Vec>, marked: bool) -> Self { + let _ = marked; Self(leaf_digests) } @@ -292,9 +294,9 @@ where } #[inline] - fn from_vec(leaf_digests: Vec>) -> Self { + fn from_vec(leaf_digests: Vec>, marked: bool) -> Self { Self { - vec: leaf_digests.into_iter().map(|x| (false, x)).collect(), + vec: leaf_digests.into_iter().map(|x| (marked, x)).collect(), } } @@ -399,7 +401,7 @@ where } #[inline] - fn from_vec(leaf_digests: Vec>) -> Self { + fn from_vec(leaf_digests: Vec>, marked: bool) -> Self { let digest_count = leaf_digests.len(); if digest_count == 0 { Self { @@ -410,7 +412,7 @@ where Self { map: leaf_digests .into_iter() - .map(|x| (false, x)) + .map(|x| (marked, x)) .enumerate() .collect::)>>(), last_index: Some(digest_count - 1), @@ -530,7 +532,7 @@ where } #[inline] - fn from_vec(leaf_digests: Vec>) -> Self { + fn from_vec(leaf_digests: Vec>, marked: bool) -> Self { let digest_count = leaf_digests.len(); if digest_count == 0 { Self { @@ -541,7 +543,7 @@ where Self { map: leaf_digests .into_iter() - .map(|x| (false, x)) + .map(|x| (marked, x)) .enumerate() .collect::)>>(), last_index: Some(digest_count - 1), diff --git a/manta-crypto/src/merkle_tree/partial.rs b/manta-crypto/src/merkle_tree/partial.rs index c54861d8c..4a1fab438 100644 --- a/manta-crypto/src/merkle_tree/partial.rs +++ b/manta-crypto/src/merkle_tree/partial.rs @@ -93,11 +93,16 @@ where leaf_digests: Vec>, inner_digests: PartialInnerTree, ) -> Self { - Self::new_unchecked(LeafMap::from_vec(leaf_digests), inner_digests) + Self::new_unchecked(LeafMap::from_vec(leaf_digests, false), inner_digests) } /// Builds a new [`Partial`] from `leaf_digests` and `path` without checking that /// `path` is consistent with the leaves and that it is a [`CurrentPath`]. + /// + /// # Note + /// + /// This function is intended to be used for the initialization of partial Merkle trees + /// in the signer, so every leaf inserted will be marked for deletion by default. #[inline] pub fn from_leaves_and_path_unchecked( parameters: &Parameters, @@ -110,14 +115,14 @@ where { let n = leaf_digests.len(); if n == 0 { - Self::new_unchecked(LeafMap::from_vec(leaf_digests), Default::default()) + Self::new_unchecked(LeafMap::from_vec(leaf_digests, true), Default::default()) } else { let base = match Parity::from_index(n - 1) { Parity::Left => parameters.join_leaves(&leaf_digests[n - 1], &path.sibling_digest), Parity::Right => parameters.join_leaves(&path.sibling_digest, &leaf_digests[n - 1]), }; let mut partial_tree = Self::new_unchecked( - LeafMap::from_vec(leaf_digests), + LeafMap::from_vec(leaf_digests, true), PartialInnerTree::from_current( parameters, base,