diff --git a/.config/nextest.toml b/.config/nextest.toml index 513c7c728..2b60ad1bb 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -1,9 +1,9 @@ [profile.default] -failure-output = "immediate-final" -fail-fast = false default-filter = 'not test(merkle::smt::full::concurrent)' +fail-fast = false +failure-output = "immediate-final" [profile.smt-concurrent] -failure-output = "immediate-final" -fail-fast = false default-filter = 'test(merkle::smt::full::concurrent)' +fail-fast = false +failure-output = "immediate-final" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 67cbfef16..8bac04d22 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,35 +17,5 @@ permissions: contents: read jobs: - clippy: - name: clippy nightly on ubuntu-latest - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@main - - name: Clippy - run: | - rustup update --no-self-update nightly - rustup +nightly component add clippy - make clippy - - rustfmt: - name: rustfmt check nightly on ubuntu-latest - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@main - - name: Rustfmt - run: | - rustup update --no-self-update nightly - rustup default ${{ matrix.toolchain }} - rustup +nightly component add rustfmt - make format-check - - doc: - name: doc stable on ubuntu-latest - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@main - - name: Build docs - run: | - rustup update --no-self-update - make doc + lint: + uses: 0xMiden/.github/.github/workflows/lint.yml@main diff --git a/.taplo.toml b/.taplo.toml new file mode 100644 index 000000000..b735451f6 --- /dev/null +++ b/.taplo.toml @@ -0,0 +1,6 @@ +[formatting] +align_entries = true +column_width = 120 +reorder_arrays = true +reorder_inline_tables = true +reorder_keys = true diff --git a/Cargo.toml b/Cargo.toml index 8312f57f8..d9e411898 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,17 +1,17 @@ [workspace] -members = [ - "miden-crypto" -] -exclude = [ - "miden-crypto-fuzz" -] -resolver = "3" # Use the edition 2024 dependency resolver +exclude = ["miden-crypto-fuzz"] +members = ["miden-crypto"] +resolver = "3" # Use the edition 2024 dependency resolver [workspace.package] -authors = ["miden contributors"] -license = "MIT OR Apache-2.0" -repository = "https://github.com/0xMiden/crypto" -categories = ["cryptography", "no-std"] -keywords = ["miden", "crypto", "hash", "merkle"] -edition = "2024" +authors = ["miden contributors"] +categories = ["cryptography", "no-std"] +edition = "2024" +keywords = ["crypto", "hash", "merkle", "miden"] +license = "MIT OR Apache-2.0" +repository = "https://github.com/0xMiden/crypto" rust-version = "1.88" + +[workspace.lints.rust] +# Suppress warnings about `cfg(fuzzing)`, which is automatically set when using `cargo-fuzz`. +unexpected_cfgs = { check-cfg = ['cfg(fuzzing)'], level = "warn" } diff --git a/Makefile b/Makefile index b6ae0903d..4527b449d 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ DEBUG_OVERFLOW_INFO=RUSTFLAGS="-C debug-assertions -C overflow-checks -C debugin .PHONY: clippy clippy: ## Run Clippy with configs - $(WARNINGS) cargo +nightly clippy --workspace --all-targets --all-features + $(WARNINGS) cargo clippy --workspace --all-targets --all-features .PHONY: fix @@ -30,9 +30,28 @@ format: ## Run Format using nightly toolchain format-check: ## Run Format using nightly toolchain but only in check mode cargo +nightly fmt --all --check +.PHONY: machete +machete: ## Runs machete to find unused dependencies + cargo machete + +.PHONY: toml +toml: ## Runs Format for all TOML files + taplo fmt + +.PHONY: toml-check +toml-check: ## Runs Format for all TOML files but only in check mode + taplo fmt --check --verbose + +.PHONY: typos-check +typos-check: ## Runs spellchecker + typos + +.PHONY: workspace-check +workspace-check: ## Runs a check that all packages have `lints.workspace = true` + cargo workspace-lints .PHONY: lint -lint: format fix clippy ## Run all linting tasks at once (Clippy, fixing, formatting) +lint: format fix clippy toml typos-check machete ## Run all linting tasks at once (Clippy, fixing, formatting, machete) # --- docs ---------------------------------------------------------------------------------------- @@ -104,3 +123,22 @@ bench-smt-concurrent: ## Run SMT benchmarks with concurrent feature .PHONY: fuzz-smt fuzz-smt: ## Run fuzzing for SMT cargo +nightly fuzz run smt --release --fuzz-dir miden-crypto-fuzz -- -max_len=10485760 + +# --- installing ---------------------------------------------------------------------------------- + +.PHONY: check-tools +check-tools: ## Checks if development tools are installed + @echo "Checking development tools..." + @command -v typos >/dev/null 2>&1 && echo "[OK] typos is installed" || echo "[MISSING] typos is not installed (run: make install-tools)" + @command -v cargo nextest >/dev/null 2>&1 && echo "[OK] nextest is installed" || echo "[MISSING] nextest is not installed (run: make install-tools)" + @command -v taplo >/dev/null 2>&1 && echo "[OK] taplo is installed" || echo "[MISSING] taplo is not installed (run: make install-tools)" + @command -v cargo machete >/dev/null 2>&1 && echo "[OK] machete is installed" || echo "[MISSING] machete is not installed (run: make install-tools)" + +.PHONY: install-tools +install-tools: ## Installs development tools required by the Makefile (typos, nextest, taplo, machete) + @echo "Installing development tools..." + cargo install typos-cli --locked + cargo install cargo-nextest --locked + cargo install taplo-cli --locked + cargo install cargo-machete --locked + @echo "Development tools installation complete!" diff --git a/miden-crypto-fuzz/Cargo.toml b/miden-crypto-fuzz/Cargo.toml index 03912987d..520cd8935 100644 --- a/miden-crypto-fuzz/Cargo.toml +++ b/miden-crypto-fuzz/Cargo.toml @@ -1,20 +1,23 @@ [package] -name = "miden-crypto-fuzz" -version = "0.0.0" -publish = false edition = "2024" +name = "miden-crypto-fuzz" +publish = false +version = "0.0.0" [package.metadata] cargo-fuzz = true [dependencies] libfuzzer-sys = "0.4" -miden-crypto = { path = "../miden-crypto", features = ["concurrent"] } -rand = { version = "0.9", default-features = false } +miden-crypto = { features = ["concurrent"], path = "../miden-crypto" } +rand = { default-features = false, version = "0.9" } [[bin]] -name = "smt" -path = "fuzz_targets/smt.rs" -test = false -doc = false bench = false +doc = false +name = "smt" +path = "fuzz_targets/smt.rs" +test = false + +[lints] +workspace = true diff --git a/miden-crypto/Cargo.toml b/miden-crypto/Cargo.toml index ff95dd09e..844b9c58a 100644 --- a/miden-crypto/Cargo.toml +++ b/miden-crypto/Cargo.toml @@ -1,115 +1,117 @@ [package] -name = "miden-crypto" -version = "0.17.0" -description = "Miden Cryptographic primitives" -authors.workspace = true -readme = "../README.md" -license.workspace = true -repository.workspace = true -documentation = "https://docs.rs/miden-crypto/0.17.0" -categories.workspace = true -keywords.workspace = true -edition.workspace = true +authors.workspace = true +categories.workspace = true +description = "Miden Cryptographic primitives" +documentation = "https://docs.rs/miden-crypto/0.17.0" +edition.workspace = true +keywords.workspace = true +license.workspace = true +name = "miden-crypto" +readme = "../README.md" +repository.workspace = true rust-version.workspace = true +version = "0.17.0" [[bin]] -name = "miden-crypto" -path = "src/main.rs" -bench = false -doctest = false +bench = false +doctest = false +name = "miden-crypto" +path = "src/main.rs" required-features = ["executable"] [[bench]] -name = "hash" harness = false +name = "hash" [[bench]] -name = "smt" harness = false +name = "smt" [[bench]] -name = "smt-subtree" -harness = false +harness = false +name = "smt-subtree" required-features = ["internal"] [[bench]] -name = "merkle" harness = false +name = "merkle" [[bench]] -name = "smt-with-entries" harness = false +name = "smt-with-entries" [[bench]] -name = "store" harness = false +name = "store" [[bench]] -name = "dsa" harness = false +name = "dsa" [[bench]] -name = "word" harness = false +name = "word" [[bench]] -name = "rand" harness = false +name = "rand" [features] concurrent = ["dep:rayon", "hashbrown?/rayon"] -default = ["std", "concurrent"] +default = ["concurrent", "std"] executable = ["dep:clap", "dep:rand-utils", "std"] hashmaps = ["dep:hashbrown"] internal = [] serde = ["dep:serde", "serde?/alloc", "winter-math/serde"] std = [ - "blake3/std", - "dep:cc", - "rand/std", - "rand/thread_rng", - "winter-crypto/std", - "winter-math/std", - "winter-utils/std", + "blake3/std", + "dep:cc", + "rand/std", + "rand/thread_rng", + "winter-crypto/std", + "winter-math/std", + "winter-utils/std", ] [dependencies] -blake3 = { version = "1.8", default-features = false } -clap = { version = "4.5", optional = true, features = ["derive"] } -getrandom = { version = "0.2", features = ["js"] } -hashbrown = { version = "0.15", optional = true, features = ["serde"] } -hkdf = { version = "0.12", default-features = false } -k256 = { version = "0.13", features = ["ecdsa", "ecdh"] } -num = { version = "0.4", default-features = false, features = ["alloc", "libm"] } -num-complex = { version = "0.4", default-features = false } -rand = { version = "0.9", default-features = false } -rand_chacha = { version = "0.9", default-features = false } -rand_core = { version = "0.9", default-features = false } -rand_hc = { version = "0.3" } -rand-utils = { version = "0.13", package = "winter-rand-utils", optional = true } -rayon = { version = "1.10", optional = true } -serde = { version = "1.0", default-features = false, optional = true, features = ["derive"] } -sha3 = { version = "0.10", default-features = false } -thiserror = { version = "2.0", default-features = false } -winter-crypto = { version = "0.13", default-features = false } -winter-math = { version = "0.13", default-features = false } -winter-utils = { version = "0.13", default-features = false } +blake3 = { default-features = false, version = "1.8" } +clap = { features = ["derive"], optional = true, version = "4.5" } +getrandom = { features = ["js"], version = "0.2" } +hashbrown = { features = ["serde"], optional = true, version = "0.15" } +hkdf = { default-features = false, version = "0.12" } +k256 = { features = ["ecdh", "ecdsa"], version = "0.13" } +num = { default-features = false, features = ["alloc", "libm"], version = "0.4" } +num-complex = { default-features = false, version = "0.4" } +rand = { default-features = false, version = "0.9" } +rand-utils = { optional = true, package = "winter-rand-utils", version = "0.13" } +rand_chacha = { default-features = false, version = "0.9" } +rand_core = { default-features = false, version = "0.9" } +rand_hc = { version = "0.3" } +rayon = { optional = true, version = "1.10" } +serde = { default-features = false, features = ["derive"], optional = true, version = "1.0" } +sha3 = { default-features = false, version = "0.10" } +thiserror = { default-features = false, version = "2.0" } +winter-crypto = { default-features = false, version = "0.13" } +winter-math = { default-features = false, version = "0.13" } +winter-utils = { default-features = false, version = "0.13" } [dev-dependencies] -assert_matches = { version = "1.5", default-features = false } -criterion = { version = "0.7", features = ["html_reports"] } -hex = { version = "0.4", default-features = false, features = ["alloc"] } -itertools = { version = "0.14" } -proptest = { version = "1.7", default-features = false, features = ["alloc"] } -rand_chacha = { version = "0.9", default-features = false } -rand-utils = { version = "0.13", package = "winter-rand-utils" } -rstest = { version = "0.26" } -seq-macro = { version = "0.3" } +assert_matches = { default-features = false, version = "1.5" } +criterion = { features = ["html_reports"], version = "0.7" } +hex = { default-features = false, features = ["alloc"], version = "0.4" } +itertools = { version = "0.14" } +proptest = { default-features = false, features = ["alloc"], version = "1.7" } +rand-utils = { package = "winter-rand-utils", version = "0.13" } +rand_chacha = { default-features = false, version = "0.9" } +rstest = { version = "0.26" } +seq-macro = { version = "0.3" } [build-dependencies] -cc = { version = "1.2", optional = true, features = ["parallel"] } +cc = { features = ["parallel"], optional = true, version = "1.2" } glob = "0.3" -[lints.rust] -# Suppress warnings about `cfg(fuzzing)`, which is automatically set when using `cargo-fuzz`. -unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] } +[lints] +workspace = true + +[package.metadata.cargo-machete] +ignored = ["getrandom"] diff --git a/miden-crypto/src/dsa/rpo_falcon512/tests/data.rs b/miden-crypto/src/dsa/rpo_falcon512/tests/data.rs index bc5c69a70..fe49eee70 100644 --- a/miden-crypto/src/dsa/rpo_falcon512/tests/data.rs +++ b/miden-crypto/src/dsa/rpo_falcon512/tests/data.rs @@ -1753,7 +1753,7 @@ pub(crate) static SK_POLYS: [[[i16; 512]; 4]; NUM_TEST_VECTORS] = [ ]; /// Serialized deterministic RPO-Falcon-512 signature intended for use as a test vector -/// for the determinism in the signing procedure accros platforms. +/// for the determinism in the signing procedure across platforms. /// /// This was generated on an `Intel Core i5-8279U` running on Linux kernel `5.4.0-144-generic` and /// built with Rust `1.88.0`. diff --git a/miden-crypto/src/hash/algebraic_sponge/mod.rs b/miden-crypto/src/hash/algebraic_sponge/mod.rs index 84d89de65..d035a147c 100644 --- a/miden-crypto/src/hash/algebraic_sponge/mod.rs +++ b/miden-crypto/src/hash/algebraic_sponge/mod.rs @@ -9,7 +9,7 @@ //! `[AlgebraicSponge]` which boils down to implementing the `apply_permutation` method. //! //! There are currently three algebraic sponge-based hash functions implemented in the module, RPO -//! and RPX hash functions, both of which belong to the Rescue familly of hash functions, and +//! and RPX hash functions, both of which belong to the Rescue family of hash functions, and //! Poseidon2 hash function. use core::ops::Range; diff --git a/miden-crypto/src/hash/algebraic_sponge/poseidon2/mod.rs b/miden-crypto/src/hash/algebraic_sponge/poseidon2/mod.rs index f239b7d04..0180f831d 100644 --- a/miden-crypto/src/hash/algebraic_sponge/poseidon2/mod.rs +++ b/miden-crypto/src/hash/algebraic_sponge/poseidon2/mod.rs @@ -11,7 +11,7 @@ mod test; /// Implementation of the Poseidon2 hash function with 256-bit output. /// -/// The implementation follows the orignal [specification](https://eprint.iacr.org/2023/323) and +/// The implementation follows the original [specification](https://eprint.iacr.org/2023/323) and /// its accompanying reference [implementation](https://github.com/HorizenLabs/poseidon2). /// /// The parameters used to instantiate the function are: diff --git a/miden-crypto/src/merkle/mmr/tests.rs b/miden-crypto/src/merkle/mmr/tests.rs index 35677f60a..759ce9717 100644 --- a/miden-crypto/src/merkle/mmr/tests.rs +++ b/miden-crypto/src/merkle/mmr/tests.rs @@ -30,7 +30,7 @@ fn test_empty_partial_mmr() { } #[test] -fn test_position_equal_or_higher_than_leafs_is_never_contained() { +fn test_position_equal_or_higher_than_leaves_is_never_contained() { let empty_forest = 0; for pos in 1..1024 { // pos is index, 0 based diff --git a/miden-crypto/src/merkle/smt/mod.rs b/miden-crypto/src/merkle/smt/mod.rs index f26c5f70d..9764a0aa9 100644 --- a/miden-crypto/src/merkle/smt/mod.rs +++ b/miden-crypto/src/merkle/smt/mod.rs @@ -600,7 +600,7 @@ pub struct MutationSet { old_root: Word, /// The set of nodes that need to be removed or added. The "effective" node at an index is the /// Merkle tree's existing node at that index, with the [`NodeMutation`] in this map at that - /// index overlayed, if any. Each [`NodeMutation::Addition`] corresponds to a + /// index overlaid, if any. Each [`NodeMutation::Addition`] corresponds to a /// [`SparseMerkleTree::insert_inner_node()`] call, and each [`NodeMutation::Removal`] /// corresponds to a [`SparseMerkleTree::remove_inner_node()`] call. node_mutations: NodeMutations, diff --git a/miden-crypto/src/merkle/smt/partial.rs b/miden-crypto/src/merkle/smt/partial.rs index 8ae58019f..0da00c04a 100644 --- a/miden-crypto/src/merkle/smt/partial.rs +++ b/miden-crypto/src/merkle/smt/partial.rs @@ -248,7 +248,7 @@ impl PartialSmt { /// Returns an iterator over the [`InnerNode`] and the respective [`NodeIndex`] of the /// [`PartialSmt`]. - pub fn inner_node_indicies(&self) -> impl Iterator + '_ { + pub fn inner_node_indices(&self) -> impl Iterator + '_ { self.0.inner_node_indices() } diff --git a/miden-crypto/src/merkle/smt/simple/mod.rs b/miden-crypto/src/merkle/smt/simple/mod.rs index d831b24a4..b60863957 100644 --- a/miden-crypto/src/merkle/smt/simple/mod.rs +++ b/miden-crypto/src/merkle/smt/simple/mod.rs @@ -216,7 +216,7 @@ impl SimpleSmt { /// This also recomputes all hashes between the leaf (associated with the key) and the root, /// updating the root itself. pub fn insert(&mut self, key: LeafIndex, value: Word) -> Word { - // SAFETY: a SimpleSmt does not contain multi-value leaves. The underlaying + // SAFETY: a SimpleSmt does not contain multi-value leaves. The underlying // SimpleSmt::insert_value does not return any errors so it's safe to unwrap here. >::insert(self, key, value) .expect("inserting a value into a simple smt never returns an error") @@ -246,7 +246,7 @@ impl SimpleSmt { &self, kv_pairs: impl IntoIterator, Word)>, ) -> MutationSet, Word> { - // SAFETY: a SimpleSmt does not contain multi-value leaves. The underlaying + // SAFETY: a SimpleSmt does not contain multi-value leaves. The underlying // SimpleSmt::construct_prospective_leaf does not return any errors so it's safe to unwrap // here. >::compute_mutations(self, kv_pairs) diff --git a/miden-crypto/src/merkle/store/mod.rs b/miden-crypto/src/merkle/store/mod.rs index e52cb82cf..5a99b3e9b 100644 --- a/miden-crypto/src/merkle/store/mod.rs +++ b/miden-crypto/src/merkle/store/mod.rs @@ -72,7 +72,7 @@ pub struct StoreNode { /// assert_eq!(d0, d1, "Both trees have the same leaf at pos {i}"); /// } /// -/// // The leafs A-B-C-D are the same for both trees, so are their 2 immediate parents +/// // The leaves A-B-C-D are the same for both trees, so are their 2 immediate parents /// for i in 0..4 { /// let idx0 = NodeIndex::new(3, i).unwrap(); /// let d0 = store.get_path(ROOT0, idx0).unwrap(); @@ -442,7 +442,7 @@ impl MerkleStore { /// Merges two elements and adds the resulting node into the store. /// - /// Merges arbitrary values. They may be leafs, nodes, or a mixture of both. + /// Merges arbitrary values. They may be leaves, nodes, or a mixture of both. pub fn merge_roots(&mut self, left_root: Word, right_root: Word) -> Result { let parent = Rpo256::merge(&[left_root, right_root]); self.nodes.insert(parent, StoreNode { left: left_root, right: right_root }); diff --git a/miden-crypto/src/merkle/store/tests.rs b/miden-crypto/src/merkle/store/tests.rs index 5b44f1751..6bd5583f8 100644 --- a/miden-crypto/src/merkle/store/tests.rs +++ b/miden-crypto/src/merkle/store/tests.rs @@ -172,7 +172,7 @@ fn test_empty_roots() { fn test_leaf_paths_for_empty_trees() -> Result<(), MerkleError> { let store = MerkleStore::default(); - // Starts at 1 because leafs are not included in the store. + // Starts at 1 because leaves are not included in the store. // Ends at 64 because it is not possible to represent an index of a depth greater than 64, // because a u64 is used to index the leaf. seq!(DEPTH in 1_u8..64_u8 { diff --git a/rustfmt.toml b/rustfmt.toml index cebafc6ee..fd0298feb 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,23 +1,23 @@ -edition = "2024" -array_width = 80 -attr_fn_like_width = 80 -chain_width = 80 -comment_width = 100 -condense_wildcard_suffixes = true -fn_call_width = 80 -format_code_in_doc_comments = true -format_macro_matchers = true -group_imports = "StdExternalCrate" -hex_literal_case = "Lower" -imports_granularity = "Crate" -match_block_trailing_comma = true -newline_style = "Unix" -reorder_imports = true -reorder_modules = true -single_line_if_else_max_width = 60 +array_width = 80 +attr_fn_like_width = 80 +chain_width = 80 +comment_width = 100 +condense_wildcard_suffixes = true +edition = "2024" +fn_call_width = 80 +format_code_in_doc_comments = true +format_macro_matchers = true +group_imports = "StdExternalCrate" +hex_literal_case = "Lower" +imports_granularity = "Crate" +match_block_trailing_comma = true +newline_style = "Unix" +reorder_imports = true +reorder_modules = true +single_line_if_else_max_width = 60 single_line_let_else_max_width = 60 -struct_lit_width = 40 -struct_variant_width = 40 -use_field_init_shorthand = true -use_try_shorthand = true -wrap_comments = true +struct_lit_width = 40 +struct_variant_width = 40 +use_field_init_shorthand = true +use_try_shorthand = true +wrap_comments = true