From 920c5db5bc1f064ae08a25ea1cdf09a87b81307e Mon Sep 17 00:00:00 2001 From: Jan Ferdinand Sauer Date: Mon, 19 Aug 2024 11:10:24 +0200 Subject: [PATCH] chore: Canonicalize `use` statements --- twenty-first/benches/coset_extrapolation.rs | 1 - twenty-first/benches/evaluation.rs | 1 - twenty-first/benches/extrapolation.rs | 1 - .../benches/formal_power_series_inverse.rs | 1 - twenty-first/benches/interpolation.rs | 1 - twenty-first/benches/inverses.rs | 5 ++- twenty-first/benches/merkle_tree.rs | 1 - .../merkle_tree_auth_structure_size.rs | 1 - .../benches/merkle_tree_authenticate.rs | 1 - twenty-first/benches/ntt_forward.rs | 9 ++++-- twenty-first/benches/poly_clean_div.rs | 1 - twenty-first/benches/poly_mod_reduce.rs | 1 - twenty-first/benches/poly_mul.rs | 1 - twenty-first/benches/poly_scalar_mul.rs | 1 - twenty-first/benches/poly_scale.rs | 1 - twenty-first/benches/polynomial_coset.rs | 1 - twenty-first/benches/tip5.rs | 1 - twenty-first/benches/various_muls.rs | 1 - twenty-first/benches/zerofier.rs | 1 - twenty-first/src/amount/u32s.rs | 3 +- twenty-first/src/math/b_field_element.rs | 7 ++--- twenty-first/src/math/bfield_codec.rs | 9 ++---- twenty-first/src/math/digest.rs | 3 +- twenty-first/src/math/lattice.rs | 10 +++--- twenty-first/src/math/mds.rs | 3 +- twenty-first/src/math/ntt.rs | 3 +- twenty-first/src/math/polynomial.rs | 8 ++--- twenty-first/src/math/tip5.rs | 3 +- twenty-first/src/math/x_field_element.rs | 3 +- twenty-first/src/mock/mmr/mock_mmr.rs | 10 ++---- twenty-first/src/mock/mmr/mod.rs | 8 ++--- .../src/util_types/algebraic_hasher.rs | 3 +- twenty-first/src/util_types/merkle_tree.rs | 3 +- .../src/util_types/mmr/mmr_accumulator.rs | 15 ++++----- .../util_types/mmr/mmr_membership_proof.rs | 31 ++++++++++++------- .../src/util_types/mmr/mmr_successor_proof.rs | 22 +++++++------ twenty-first/tests/bfield_codec_derive.rs | 1 - 37 files changed, 77 insertions(+), 99 deletions(-) diff --git a/twenty-first/benches/coset_extrapolation.rs b/twenty-first/benches/coset_extrapolation.rs index 74f6fdd14..e6977ccb7 100644 --- a/twenty-first/benches/coset_extrapolation.rs +++ b/twenty-first/benches/coset_extrapolation.rs @@ -2,7 +2,6 @@ use criterion::criterion_group; use criterion::criterion_main; use criterion::BenchmarkId; use criterion::Criterion; - use twenty_first::math::other::random_elements; use twenty_first::prelude::*; diff --git a/twenty-first/benches/evaluation.rs b/twenty-first/benches/evaluation.rs index 93ae826db..994efa0b1 100644 --- a/twenty-first/benches/evaluation.rs +++ b/twenty-first/benches/evaluation.rs @@ -2,7 +2,6 @@ use criterion::criterion_group; use criterion::criterion_main; use criterion::BenchmarkId; use criterion::Criterion; - use twenty_first::math::other::random_elements; use twenty_first::math::zerofier_tree::ZerofierTree; use twenty_first::prelude::*; diff --git a/twenty-first/benches/extrapolation.rs b/twenty-first/benches/extrapolation.rs index 0577b2d02..0a30366f2 100644 --- a/twenty-first/benches/extrapolation.rs +++ b/twenty-first/benches/extrapolation.rs @@ -2,7 +2,6 @@ use criterion::criterion_group; use criterion::criterion_main; use criterion::BenchmarkId; use criterion::Criterion; - use twenty_first::math::ntt::intt; use twenty_first::math::other::random_elements; use twenty_first::math::traits::PrimitiveRootOfUnity; diff --git a/twenty-first/benches/formal_power_series_inverse.rs b/twenty-first/benches/formal_power_series_inverse.rs index b68935af2..4f79ed37f 100644 --- a/twenty-first/benches/formal_power_series_inverse.rs +++ b/twenty-first/benches/formal_power_series_inverse.rs @@ -2,7 +2,6 @@ use criterion::criterion_group; use criterion::criterion_main; use criterion::BenchmarkId; use criterion::Criterion; - use twenty_first::math::other::random_elements; use twenty_first::prelude::*; diff --git a/twenty-first/benches/interpolation.rs b/twenty-first/benches/interpolation.rs index 18a6f7eff..d85348ddc 100644 --- a/twenty-first/benches/interpolation.rs +++ b/twenty-first/benches/interpolation.rs @@ -3,7 +3,6 @@ use criterion::criterion_main; use criterion::BenchmarkId; use criterion::Criterion; use criterion::Throughput; - use twenty_first::math::other::random_elements; use twenty_first::prelude::*; diff --git a/twenty-first/benches/inverses.rs b/twenty-first/benches/inverses.rs index b355b08ff..276af1fd8 100644 --- a/twenty-first/benches/inverses.rs +++ b/twenty-first/benches/inverses.rs @@ -1,4 +1,7 @@ -use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; +use criterion::criterion_group; +use criterion::criterion_main; +use criterion::BenchmarkId; +use criterion::Criterion; use itertools::Itertools; use twenty_first::math::b_field_element::BFieldElement; use twenty_first::math::other::random_elements; diff --git a/twenty-first/benches/merkle_tree.rs b/twenty-first/benches/merkle_tree.rs index e2325a8c1..2fcfdd9b6 100644 --- a/twenty-first/benches/merkle_tree.rs +++ b/twenty-first/benches/merkle_tree.rs @@ -4,7 +4,6 @@ use criterion::criterion_group; use criterion::criterion_main; use criterion::BenchmarkId; use criterion::Criterion; - use twenty_first::math::digest::Digest; use twenty_first::math::other::random_elements; use twenty_first::util_types::merkle_tree::CpuParallel; diff --git a/twenty-first/benches/merkle_tree_auth_structure_size.rs b/twenty-first/benches/merkle_tree_auth_structure_size.rs index 3316dd4e5..3a5f25491 100644 --- a/twenty-first/benches/merkle_tree_auth_structure_size.rs +++ b/twenty-first/benches/merkle_tree_auth_structure_size.rs @@ -11,7 +11,6 @@ use rand::Rng; use rand::RngCore; use rand::SeedableRng; use twenty_first::math::bfield_codec::BFieldCodec; - use twenty_first::math::tip5::Tip5; use twenty_first::util_types::algebraic_hasher::AlgebraicHasher; use twenty_first::util_types::merkle_tree::CpuParallel; diff --git a/twenty-first/benches/merkle_tree_authenticate.rs b/twenty-first/benches/merkle_tree_authenticate.rs index 8dcbbcaba..0061db01e 100644 --- a/twenty-first/benches/merkle_tree_authenticate.rs +++ b/twenty-first/benches/merkle_tree_authenticate.rs @@ -1,7 +1,6 @@ use criterion::*; use rand::rngs::StdRng; use rand::*; - use twenty_first::math::digest::Digest; use twenty_first::math::tip5::Tip5; use twenty_first::util_types::algebraic_hasher::AlgebraicHasher; diff --git a/twenty-first/benches/ntt_forward.rs b/twenty-first/benches/ntt_forward.rs index b7883db73..6289822bc 100644 --- a/twenty-first/benches/ntt_forward.rs +++ b/twenty-first/benches/ntt_forward.rs @@ -1,7 +1,10 @@ +use criterion::criterion_group; +use criterion::criterion_main; use criterion::measurement::WallTime; -use criterion::{ - criterion_group, criterion_main, BenchmarkGroup, BenchmarkId, Criterion, Throughput, -}; +use criterion::BenchmarkGroup; +use criterion::BenchmarkId; +use criterion::Criterion; +use criterion::Throughput; use twenty_first::math::b_field_element::BFieldElement; use twenty_first::math::ntt::ntt; use twenty_first::math::other::random_elements; diff --git a/twenty-first/benches/poly_clean_div.rs b/twenty-first/benches/poly_clean_div.rs index d0d80bf58..178ae878c 100644 --- a/twenty-first/benches/poly_clean_div.rs +++ b/twenty-first/benches/poly_clean_div.rs @@ -2,7 +2,6 @@ use criterion::criterion_group; use criterion::criterion_main; use criterion::BenchmarkId; use criterion::Criterion; - use twenty_first::math::other::random_elements; use twenty_first::prelude::*; diff --git a/twenty-first/benches/poly_mod_reduce.rs b/twenty-first/benches/poly_mod_reduce.rs index b7dc60e0c..d8d0f4a6b 100644 --- a/twenty-first/benches/poly_mod_reduce.rs +++ b/twenty-first/benches/poly_mod_reduce.rs @@ -2,7 +2,6 @@ use criterion::criterion_group; use criterion::criterion_main; use criterion::BenchmarkId; use criterion::Criterion; - use twenty_first::math::other::random_elements; use twenty_first::prelude::*; diff --git a/twenty-first/benches/poly_mul.rs b/twenty-first/benches/poly_mul.rs index 044141890..3181f14e1 100644 --- a/twenty-first/benches/poly_mul.rs +++ b/twenty-first/benches/poly_mul.rs @@ -2,7 +2,6 @@ use criterion::criterion_group; use criterion::criterion_main; use criterion::BenchmarkId; use criterion::Criterion; - use twenty_first::math::other::random_elements; use twenty_first::prelude::*; diff --git a/twenty-first/benches/poly_scalar_mul.rs b/twenty-first/benches/poly_scalar_mul.rs index e1296cd41..c737fea77 100644 --- a/twenty-first/benches/poly_scalar_mul.rs +++ b/twenty-first/benches/poly_scalar_mul.rs @@ -3,7 +3,6 @@ use criterion::criterion_main; use criterion::BenchmarkId; use criterion::Criterion; use rand::random; - use twenty_first::math::other::random_elements; use twenty_first::prelude::*; diff --git a/twenty-first/benches/poly_scale.rs b/twenty-first/benches/poly_scale.rs index a956356e3..2cd8413bb 100644 --- a/twenty-first/benches/poly_scale.rs +++ b/twenty-first/benches/poly_scale.rs @@ -3,7 +3,6 @@ use criterion::criterion_main; use criterion::BenchmarkId; use criterion::Criterion; use rand::random; - use twenty_first::math::other::random_elements; use twenty_first::prelude::*; diff --git a/twenty-first/benches/polynomial_coset.rs b/twenty-first/benches/polynomial_coset.rs index 908da980b..11bcca1a0 100644 --- a/twenty-first/benches/polynomial_coset.rs +++ b/twenty-first/benches/polynomial_coset.rs @@ -3,7 +3,6 @@ use criterion::criterion_main; use criterion::BenchmarkId; use criterion::Criterion; use criterion::Throughput; - use twenty_first::math::b_field_element::BFieldElement; use twenty_first::math::other::random_elements; use twenty_first::math::polynomial::Polynomial; diff --git a/twenty-first/benches/tip5.rs b/twenty-first/benches/tip5.rs index 705f308b8..5401d1b5a 100644 --- a/twenty-first/benches/tip5.rs +++ b/twenty-first/benches/tip5.rs @@ -4,7 +4,6 @@ use criterion::BenchmarkId; use criterion::Criterion; use rand::random; use rayon::prelude::*; - use twenty_first::math::other::random_elements; use twenty_first::prelude::*; diff --git a/twenty-first/benches/various_muls.rs b/twenty-first/benches/various_muls.rs index ce7c676ad..1bba2c3e7 100644 --- a/twenty-first/benches/various_muls.rs +++ b/twenty-first/benches/various_muls.rs @@ -7,7 +7,6 @@ use criterion::BenchmarkGroup; use criterion::BenchmarkId; use criterion::Criterion; use criterion::Throughput; - use twenty_first::math::b_field_element::BFieldElement; use twenty_first::math::other::random_elements; use twenty_first::math::x_field_element::XFieldElement; diff --git a/twenty-first/benches/zerofier.rs b/twenty-first/benches/zerofier.rs index c7ce85a2d..52ba933c9 100644 --- a/twenty-first/benches/zerofier.rs +++ b/twenty-first/benches/zerofier.rs @@ -2,7 +2,6 @@ use criterion::criterion_group; use criterion::criterion_main; use criterion::BenchmarkId; use criterion::Criterion; - use twenty_first::math::b_field_element::BFieldElement; use twenty_first::math::other::random_elements; use twenty_first::math::polynomial::Polynomial; diff --git a/twenty-first/src/amount/u32s.rs b/twenty-first/src/amount/u32s.rs index 35d945f38..a04355281 100644 --- a/twenty-first/src/amount/u32s.rs +++ b/twenty-first/src/amount/u32s.rs @@ -390,9 +390,8 @@ mod u32s_tests { use rand::Rng; use rand::RngCore; - use crate::math::other::random_elements; - use super::*; + use crate::math::other::random_elements; #[test] fn get_size_test() { diff --git a/twenty-first/src/math/b_field_element.rs b/twenty-first/src/math/b_field_element.rs index 3339e4f2f..ad46ffaec 100644 --- a/twenty-first/src/math/b_field_element.rs +++ b/twenty-first/src/math/b_field_element.rs @@ -29,16 +29,15 @@ use serde::Deserializer; use serde::Serialize; use serde::Serializer; +use super::traits::Inverse; +use super::traits::PrimitiveRootOfUnity; +use super::x_field_element::XFieldElement; use crate::error::ParseBFieldElementError; use crate::math::traits::CyclicGroupGenerator; use crate::math::traits::FiniteField; use crate::math::traits::ModPowU32; use crate::math::traits::ModPowU64; -use super::traits::Inverse; -use super::traits::PrimitiveRootOfUnity; -use super::x_field_element::XFieldElement; - const PRIMITIVE_ROOTS: phf::Map = phf_map! { 0u64 => 1, 1u64 => 1, diff --git a/twenty-first/src/math/bfield_codec.rs b/twenty-first/src/math/bfield_codec.rs index d3213655e..6574dedcd 100644 --- a/twenty-first/src/math/bfield_codec.rs +++ b/twenty-first/src/math/bfield_codec.rs @@ -13,11 +13,10 @@ use num_traits::ConstOne; use num_traits::ConstZero; use thiserror::Error; -use crate::bfe_vec; - use super::b_field_element::BFieldElement; use super::polynomial::Polynomial; use super::traits::FiniteField; +use crate::bfe_vec; /// This trait provides functions for encoding to and decoding from a Vec of [BFieldElement]s. /// This encoding does not record the size of objects nor their type information; this is @@ -547,9 +546,8 @@ mod tests { use proptest_arbitrary_interop::arb; use test_strategy::proptest; - use crate::prelude::*; - use super::*; + use crate::prelude::*; #[derive(Debug, PartialEq, Eq, test_strategy::Arbitrary)] struct BFieldCodecPropertyTestData @@ -834,6 +832,7 @@ mod tests { use arbitrary::Arbitrary; use num_traits::Zero; + use super::*; use crate::math::digest::Digest; use crate::math::tip5::Tip5; use crate::math::x_field_element::XFieldElement; @@ -841,8 +840,6 @@ mod tests { use crate::util_types::mmr::mmr_accumulator::MmrAccumulator; use crate::util_types::mmr::mmr_membership_proof::MmrMembershipProof; - use super::*; - #[derive(Debug, Clone, PartialEq, Eq, BFieldCodec, Arbitrary)] struct UnitStruct; diff --git a/twenty-first/src/math/digest.rs b/twenty-first/src/math/digest.rs index 5e48160b2..f1aa122fe 100644 --- a/twenty-first/src/math/digest.rs +++ b/twenty-first/src/math/digest.rs @@ -325,9 +325,8 @@ pub(crate) mod digest_tests { use proptest_arbitrary_interop::arb; use test_strategy::proptest; - use crate::prelude::*; - use super::*; + use crate::prelude::*; impl ProptestArbitrary for Digest { type Parameters = (); diff --git a/twenty-first/src/math/lattice.rs b/twenty-first/src/math/lattice.rs index d2071a4da..dcc4d8923 100644 --- a/twenty-first/src/math/lattice.rs +++ b/twenty-first/src/math/lattice.rs @@ -639,13 +639,12 @@ pub mod kem { use sha3::Sha3_256; use sha3::Shake256; - use crate::math::b_field_element::BFieldElement; - use super::embed_msg; use super::extract_msg; use super::CyclotomicRingElement; use super::ModuleElement; use super::CYCLOTOMIC_RING_ELEMENT_SIZE_IN_BFES; + use crate::math::b_field_element::BFieldElement; #[derive(PartialEq, Eq, Copy, Clone, Debug, Serialize, Deserialize)] pub struct SecretKey { @@ -824,15 +823,14 @@ mod lattice_test { use sha3::Digest as Sha3Digest; use sha3::Sha3_256; + use super::kem::shake256; + use super::kem::SecretKey; + use super::kem::CIPHERTEXT_SIZE_IN_BFES; use crate::math::b_field_element::BFieldElement; use crate::math::lattice::kem::Ciphertext; use crate::math::lattice::kem::PublicKey; use crate::math::lattice::*; - use super::kem::shake256; - use super::kem::SecretKey; - use super::kem::CIPHERTEXT_SIZE_IN_BFES; - #[test] fn test_kats() { // KATs lifted from diff --git a/twenty-first/src/math/mds.rs b/twenty-first/src/math/mds.rs index 27ce4eae7..563fc1552 100644 --- a/twenty-first/src/math/mds.rs +++ b/twenty-first/src/math/mds.rs @@ -498,7 +498,8 @@ pub fn generated_function(input: &[u64]) -> [u64; 16] { #[cfg(test)] mod tests { use itertools::Itertools; - use rand::{thread_rng, RngCore}; + use rand::thread_rng; + use rand::RngCore; use super::*; diff --git a/twenty-first/src/math/ntt.rs b/twenty-first/src/math/ntt.rs index fc17a715d..6e241f528 100644 --- a/twenty-first/src/math/ntt.rs +++ b/twenty-first/src/math/ntt.rs @@ -273,14 +273,13 @@ mod fast_ntt_attempt_tests { use proptest_arbitrary_interop::arb; use test_strategy::proptest; + use super::*; use crate::math::other::random_elements; use crate::math::traits::PrimitiveRootOfUnity; use crate::math::x_field_element::EXTENSION_DEGREE; use crate::prelude::*; use crate::xfe; - use super::*; - #[test] fn chu_ntt_b_field_prop_test() { for log_2_n in 1..10 { diff --git a/twenty-first/src/math/polynomial.rs b/twenty-first/src/math/polynomial.rs index 27cbd9945..05c6b6e51 100644 --- a/twenty-first/src/math/polynomial.rs +++ b/twenty-first/src/math/polynomial.rs @@ -23,6 +23,8 @@ use num_traits::One; use num_traits::Zero; use rayon::prelude::*; +use super::traits::PrimitiveRootOfUnity; +use super::zerofier_tree::ZerofierTree; use crate::math::ntt::intt; use crate::math::ntt::ntt; use crate::math::traits::FiniteField; @@ -31,9 +33,6 @@ use crate::prelude::BFieldElement; use crate::prelude::Inverse; use crate::prelude::XFieldElement; -use super::traits::PrimitiveRootOfUnity; -use super::zerofier_tree::ZerofierTree; - impl Zero for Polynomial { fn zero() -> Self { Self { @@ -2408,9 +2407,8 @@ mod test_polynomials { use proptest_arbitrary_interop::arb; use test_strategy::proptest; - use crate::prelude::*; - use super::*; + use crate::prelude::*; impl proptest::arbitrary::Arbitrary for Polynomial { type Parameters = (); diff --git a/twenty-first/src/math/tip5.rs b/twenty-first/src/math/tip5.rs index f8391a311..7d3ce5182 100644 --- a/twenty-first/src/math/tip5.rs +++ b/twenty-first/src/math/tip5.rs @@ -624,11 +624,10 @@ pub(crate) mod tip5_tests { use rayon::prelude::ParallelIterator; use test_strategy::proptest; + use super::*; use crate::math::other::random_elements; use crate::math::x_field_element::XFieldElement; - use super::*; - impl Tip5 { pub(crate) fn randomly_seeded() -> Self { let mut sponge = Self::init(); diff --git a/twenty-first/src/math/x_field_element.rs b/twenty-first/src/math/x_field_element.rs index cbce727f3..4c55c29dd 100644 --- a/twenty-first/src/math/x_field_element.rs +++ b/twenty-first/src/math/x_field_element.rs @@ -21,6 +21,7 @@ use rand_distr::Standard; use serde::Deserialize; use serde::Serialize; +use super::digest::Digest; use crate::bfe_vec; use crate::error::TryFromXFieldElementError; use crate::math::b_field_element::BFieldElement; @@ -32,8 +33,6 @@ use crate::math::traits::ModPowU32; use crate::math::traits::ModPowU64; use crate::math::traits::PrimitiveRootOfUnity; -use super::digest::Digest; - pub const EXTENSION_DEGREE: usize = 3; #[derive( diff --git a/twenty-first/src/mock/mmr/mock_mmr.rs b/twenty-first/src/mock/mmr/mock_mmr.rs index 1dd9a2ed6..140f8a997 100644 --- a/twenty-first/src/mock/mmr/mock_mmr.rs +++ b/twenty-first/src/mock/mmr/mock_mmr.rs @@ -3,14 +3,13 @@ use itertools::Itertools; use crate::math::digest::Digest; use crate::prelude::Tip5; use crate::util_types::algebraic_hasher::AlgebraicHasher; -use crate::util_types::mmr::mmr_trait::LeafMutation; -use crate::util_types::shared::bag_peaks; - use crate::util_types::mmr::mmr_accumulator::MmrAccumulator; use crate::util_types::mmr::mmr_membership_proof::MmrMembershipProof; +use crate::util_types::mmr::mmr_trait::LeafMutation; use crate::util_types::mmr::mmr_trait::Mmr; use crate::util_types::mmr::shared_advanced; use crate::util_types::mmr::shared_basic; +use crate::util_types::shared::bag_peaks; /// MockMmr is available for feature `mock` and for unit tests. /// @@ -367,14 +366,13 @@ impl MyVec { #[cfg(test)] mod mmr_test { use itertools::*; - use rand::random; use test_strategy::proptest; + use super::*; use crate::math::b_field_element::BFieldElement; use crate::math::other::*; use crate::math::tip5::Tip5; - use crate::mock::mmr::*; use crate::util_types::merkle_tree::merkle_tree_test::MerkleTreeToTest; use crate::util_types::merkle_tree::*; @@ -382,8 +380,6 @@ mod mmr_test { use crate::util_types::mmr::shared_advanced::get_peak_heights; use crate::util_types::mmr::shared_advanced::get_peak_heights_and_peak_node_indices; - use super::*; - impl MockMmr { /// Return the number of nodes in all the trees in the MMR fn count_nodes(&mut self) -> u64 { diff --git a/twenty-first/src/mock/mmr/mod.rs b/twenty-first/src/mock/mmr/mod.rs index b272d6517..0ef67be6d 100644 --- a/twenty-first/src/mock/mmr/mod.rs +++ b/twenty-first/src/mock/mmr/mod.rs @@ -24,14 +24,14 @@ pub fn get_mock_ammr_from_digests(digests: Vec) -> MockMmr { #[cfg(test)] mod shared_tests_tests { use hashbrown::HashSet; - use rand::{random, Rng}; + use itertools::Itertools; + use rand::random; + use rand::Rng; + use super::*; use crate::math::other::random_elements; use crate::util_types::mmr::mmr_accumulator::util::mmra_with_mps; use crate::util_types::mmr::mmr_trait::Mmr; - use itertools::Itertools; - - use super::*; #[should_panic] #[test] diff --git a/twenty-first/src/util_types/algebraic_hasher.rs b/twenty-first/src/util_types/algebraic_hasher.rs index bc8c874a0..8f0103574 100644 --- a/twenty-first/src/util_types/algebraic_hasher.rs +++ b/twenty-first/src/util_types/algebraic_hasher.rs @@ -135,12 +135,11 @@ mod algebraic_hasher_tests { use rand_distr::Distribution; use rand_distr::Standard; + use super::*; use crate::math::digest::Digest; use crate::math::tip5::Tip5; use crate::math::x_field_element::EXTENSION_DEGREE; - use super::*; - fn encode_prop(smallest: T, largest: T) where T: Eq + BFieldCodec, diff --git a/twenty-first/src/util_types/merkle_tree.rs b/twenty-first/src/util_types/merkle_tree.rs index 13bc56ce2..f102a1824 100644 --- a/twenty-first/src/util_types/merkle_tree.rs +++ b/twenty-first/src/util_types/merkle_tree.rs @@ -606,12 +606,11 @@ pub mod merkle_tree_test { use proptest_arbitrary_interop::arb; use test_strategy::proptest; + use super::*; use crate::math::b_field_element::BFieldElement; use crate::math::digest::digest_tests::DigestCorruptor; use crate::math::tip5::Tip5; - use super::*; - impl MerkleTree { fn test_tree_of_height(tree_height: usize) -> Self { let num_leafs = 1 << tree_height; diff --git a/twenty-first/src/util_types/mmr/mmr_accumulator.rs b/twenty-first/src/util_types/mmr/mmr_accumulator.rs index 8999f6c4c..452e0b0c0 100644 --- a/twenty-first/src/util_types/mmr/mmr_accumulator.rs +++ b/twenty-first/src/util_types/mmr/mmr_accumulator.rs @@ -7,6 +7,10 @@ use itertools::Itertools; use serde::Deserialize; use serde::Serialize; +use super::mmr_membership_proof::MmrMembershipProof; +use super::mmr_trait::LeafMutation; +use super::mmr_trait::Mmr; +use super::shared_basic; use crate::math::bfield_codec::BFieldCodec; use crate::math::digest::Digest; use crate::prelude::Tip5; @@ -14,11 +18,6 @@ use crate::util_types::algebraic_hasher::AlgebraicHasher; use crate::util_types::mmr::shared_advanced; use crate::util_types::shared::bag_peaks; -use super::mmr_membership_proof::MmrMembershipProof; -use super::mmr_trait::LeafMutation; -use super::mmr_trait::Mmr; -use super::shared_basic; - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, GetSize, BFieldCodec)] pub struct MmrAccumulator { leaf_count: u64, @@ -318,12 +317,11 @@ impl Mmr for MmrAccumulator { pub mod util { use itertools::Itertools; + use super::*; use crate::math::other::random_elements; use crate::util_types::mmr::shared_advanced::right_lineage_length_from_node_index; use crate::util_types::mmr::shared_basic::leaf_index_to_mt_index_and_peak_index; - use super::*; - /// Get an MMR accumulator with a requested number of leafs, and requested leaf digests at specified indices /// Also returns the MMR membership proofs for the specified leafs. pub fn mmra_with_mps( @@ -492,14 +490,13 @@ mod accumulator_mmr_tests { use rand::RngCore; use test_strategy::proptest; + use super::*; use crate::math::b_field_element::BFieldElement; use crate::math::other::random_elements; use crate::math::tip5::Tip5; use crate::mock::mmr::get_mock_ammr_from_digests; use crate::mock::mmr::MockMmr; - use super::*; - impl From for MmrAccumulator { fn from(ammr: MockMmr) -> Self { MmrAccumulator { diff --git a/twenty-first/src/util_types/mmr/mmr_membership_proof.rs b/twenty-first/src/util_types/mmr/mmr_membership_proof.rs index 22bd5ad7e..774ee2316 100644 --- a/twenty-first/src/util_types/mmr/mmr_membership_proof.rs +++ b/twenty-first/src/util_types/mmr/mmr_membership_proof.rs @@ -1,17 +1,23 @@ +use std::collections::hash_map::RandomState; +use std::collections::hash_set::Intersection; +use std::collections::HashMap; +use std::collections::HashSet; +use std::fmt::Debug; +use std::iter::FromIterator; + use arbitrary::Arbitrary; use get_size::GetSize; use itertools::Itertools; -use serde::{Deserialize, Serialize}; -use std::collections::hash_map::RandomState; -use std::collections::hash_set::Intersection; -use std::collections::{HashMap, HashSet}; -use std::{fmt::Debug, iter::FromIterator}; +use serde::Deserialize; +use serde::Serialize; use super::mmr_trait::LeafMutation; -use super::{shared_advanced, shared_basic}; +use super::shared_advanced; +use super::shared_basic; use crate::math::bfield_codec::BFieldCodec; use crate::math::digest::Digest; -use crate::prelude::{AlgebraicHasher, Tip5}; +use crate::prelude::AlgebraicHasher; +use crate::prelude::Tip5; #[derive(Debug, Clone, Serialize, Deserialize, GetSize, BFieldCodec, Arbitrary)] pub struct MmrMembershipProof { @@ -634,20 +640,23 @@ impl MmrMembershipProof { mod mmr_membership_proof_test { use itertools::Itertools; use proptest_arbitrary_interop::arb; - use rand::{random, thread_rng, Rng, RngCore}; + use rand::random; + use rand::thread_rng; + use rand::Rng; + use rand::RngCore; use test_strategy::proptest; + use super::*; use crate::math::b_field_element::BFieldElement; use crate::math::digest::Digest; use crate::math::other::random_elements; use crate::math::tip5::Tip5; - use crate::mock::mmr::{get_mock_ammr_from_digests, MockMmr}; + use crate::mock::mmr::get_mock_ammr_from_digests; + use crate::mock::mmr::MockMmr; use crate::util_types::mmr::mmr_accumulator::util::mmra_with_mps; use crate::util_types::mmr::mmr_accumulator::MmrAccumulator; use crate::util_types::mmr::mmr_trait::Mmr; - use super::*; - #[test] fn equality_and_hash_test() { type H = Tip5; diff --git a/twenty-first/src/util_types/mmr/mmr_successor_proof.rs b/twenty-first/src/util_types/mmr/mmr_successor_proof.rs index 534692333..3b677c35f 100644 --- a/twenty-first/src/util_types/mmr/mmr_successor_proof.rs +++ b/twenty-first/src/util_types/mmr/mmr_successor_proof.rs @@ -1,16 +1,18 @@ use bfieldcodec_derive::BFieldCodec; use itertools::Itertools; -use crate::{ - prelude::{AlgebraicHasher, Digest, Mmr, Tip5}, - util_types::mmr::shared_advanced::{left_sibling, node_indices_added_by_append}, -}; - -use super::{ - mmr_accumulator::MmrAccumulator, - shared_advanced::{get_peak_heights_and_peak_node_indices, parent, right_sibling}, - shared_basic::{calculate_new_peaks_from_append, leaf_index_to_mt_index_and_peak_index}, -}; +use super::mmr_accumulator::MmrAccumulator; +use super::shared_advanced::get_peak_heights_and_peak_node_indices; +use super::shared_advanced::parent; +use super::shared_advanced::right_sibling; +use super::shared_basic::calculate_new_peaks_from_append; +use super::shared_basic::leaf_index_to_mt_index_and_peak_index; +use crate::prelude::AlgebraicHasher; +use crate::prelude::Digest; +use crate::prelude::Mmr; +use crate::prelude::Tip5; +use crate::util_types::mmr::shared_advanced::left_sibling; +use crate::util_types::mmr::shared_advanced::node_indices_added_by_append; /// An MmrSuccessorProof asserts that one MMR Accumulator is the descendant of /// another, *i.e.*, that the second can be obtained by appending a set of leafs diff --git a/twenty-first/tests/bfield_codec_derive.rs b/twenty-first/tests/bfield_codec_derive.rs index 71debcf26..ce499dcf1 100644 --- a/twenty-first/tests/bfield_codec_derive.rs +++ b/twenty-first/tests/bfield_codec_derive.rs @@ -2,7 +2,6 @@ use arbitrary::Arbitrary; use proptest::prelude::*; use proptest_arbitrary_interop::arb; use test_strategy::proptest; - // Required by the `BFieldCodec` derive macro. This is generally only needed once per crate, at the top-level `lib.rs`. #[allow(clippy::single_component_path_imports)] use twenty_first;