fix(deps): replace unmaintained rust-crypto with sha2, bump vulnerabl…#208
Open
EddieHouston wants to merge 2 commits intoBlockstream:new-indexfrom
Open
fix(deps): replace unmaintained rust-crypto with sha2, bump vulnerabl…#208EddieHouston wants to merge 2 commits intoBlockstream:new-indexfrom
EddieHouston wants to merge 2 commits intoBlockstream:new-indexfrom
Conversation
…e dependencies rust-crypto has known AES miscomputation (RUSTSEC-2022-0011) and its transitive dep rustc-serialize has a stack overflow (RUSTSEC-2022-0004). Both crates are unmaintained with no upgrade path. Replace with the sha2 crate (0.10), which provides hardware-accelerated SHA-256 via SHA-NI on x86_64 and ARMv8 intrinsics on aarch64. All three call sites (compute_script_hash, get_status_hash, hash_ip_with_salt) are updated to the sha2 Digest API. Also bumps tokio (1.49→1.52, RUSTSEC-2025-0023) and tar (0.4.44→0.4.45, RUSTSEC-2026-0068). Resolves 11 of 18 cargo-audit findings; the remaining 7 are pinned by upstream deps (electrum-client, electrumd, minreq) and require upstream releases.
Verify compute_script_hash produces correct SHA-256 output after the rust-crypto to sha2 migration. Tests against NIST vectors for empty string and abc, plus a real P2PKH scriptPubKey.
566076b to
45e3daa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rust-cryptowithsha20.10 for hardware-accelerated SHA-256 (SHA-NI on x86_64, ARMv8 crypto on aarch64)tokio1.49→1.52 andtar0.4.44→0.4.45 to resolve known vulnerabilitiescargo auditfindings; remaining 7 are pinned by upstream crates (electrum-client,electrumd,minreq)Motivation
cargo auditflagged 18 vulnerabilities and 15 warnings. The most actionable wasrust-crypto, a direct dependency used only for SHA-256 hashing in three places:compute_script_hashinsrc/new_index/schema.rsandsrc/new_index/precache.rsget_status_hashandhash_ip_with_saltinsrc/electrum/server.rsrust-cryptois unmaintained (last release 2016) and has a known AES miscomputation advisory (RUSTSEC-2022-0011). Its transitive dependencyrustc-serializehas a stack overflow advisory (RUSTSEC-2022-0004) and is also unmaintained.Prior art
mempool/electrs made the same
rust-crypto→sha2swap in06cf2ff. Our change follows the same approach with one minor improvement: we use.finalize().into()instead of.finalize().try_into().unwrap()for theGenericArray<u8, U32>→[u8; 32]conversion, sinceIntois implemented directly and avoids an unnecessary runtime panic path.Changes
Cargo.tomlrust-crypto = "0.2"→sha2 = "0.10"src/new_index/schema.rssha2::{Digest, Sha256}APIsrc/new_index/precache.rssha2::{Digest, Sha256}APIsrc/electrum/server.rssha2::{Digest, Sha256}APICargo.lockrust-crypto/rustc-serializetree, addsha2tree, bumptokioandtarAdvisories resolved
rust-cryptosha2rustc-serializerust-crypto)bytescrossbeam-channelh2hyper-utilprotobufrocksdburltokiotarRemaining (upstream-blocked)
The 7 remaining advisories cannot be resolved without upstream releases. Most are in dev-only dependencies that do not ship in the production binary;
electrum-clientis the exception — it ships when theelectrum-discoveryfeature isenabled.
ring0.16.20electrum-client,electrumdelectrum-discovery)rustls0.16.0electrum-clientelectrum-discovery)webpki0.21.4electrum-clientelectrum-discovery)rustls0.19.1electrumd→ureqidna0.2.3electrumd→ureqrustls-webpki0.101.7minreq→corepc-nodeTest plan
cargo checkpasses (default features)cargo check --features liquidpassescargo test new_index::schema::tests— 3 unit tests pass:test_sha256_empty_input— NIST test vector for SHA-256("")test_sha256_abc— NIST test vector for SHA-256("abc")test_p2pkh_script_hash— real P2PKH scriptPubKey verified against independent SHA-256 computation