Skip to content

Commit 87df440

Browse files
VictorLuxclaude
andcommitted
fix: Resolve Rust 1.93.0 Clippy lints in zipherx-crypto
- Replace cloned_ref_to_slice_refs with std::slice::from_ref - Remove drop_non_drop calls on non-Drop types - Remove unnecessary u32-to-u32 casts - Use is_multiple_of() instead of manual modulo checks - Extract ParsedOutput type alias for complex tuple Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 893b052 commit 87df440

6 files changed

Lines changed: 16 additions & 16 deletions

File tree

crates/zipherx-crypto/src/boost_scan.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
99
use std::collections::{HashMap, HashSet};
1010

11+
/// Parsed output record: (array_idx, height, index_field, cmu, epk, ciphertext, received_txid)
12+
type ParsedOutput = (usize, u32, u32, [u8; 32], [u8; 32], [u8; 580], [u8; 32]);
13+
1114
use ff::PrimeField;
1215
use rayon::prelude::*;
1316
use serde::{Deserialize, Serialize};
@@ -198,7 +201,7 @@ pub fn scan_boost_outputs(
198201

199202
// Parse output at index i directly from raw bytes — avoids ~700MB intermediate allocation.
200203
// Returns: (array_idx, height, index_field, cmu, epk, ciphertext, received_txid)
201-
let parse_output = |i: usize| -> (usize, u32, u32, [u8; 32], [u8; 32], [u8; 580], [u8; 32]) {
204+
let parse_output = |i: usize| -> ParsedOutput {
202205
let offset = i * BOOST_OUTPUT_SIZE;
203206
let height = u32::from_le_bytes([
204207
outputs_data[offset],

crates/zipherx-crypto/src/keys.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ pub fn derive_spending_key(seed: &[u8], account: u32) -> Result<Zeroizing<Vec<u8
3636
.write(&mut buf)
3737
.map_err(|e| CryptoError::InvalidData(format!("SK serialize: {e}")))?;
3838

39-
// Note: explicit drop() ends the scope of these temporaries but does NOT
40-
// zero memory. The actual zeroization is provided by the Zeroizing<Vec<u8>>
41-
// return type, which zeros on drop via the zeroize crate.
42-
drop(account_key);
43-
drop(master);
39+
// Note: `account_key` and `master` are dropped here at scope end.
40+
// Their types do NOT implement Drop (no zeroization), but the actual
41+
// secret bytes are returned via Zeroizing<Vec<u8>>, which zeros on drop.
4442

4543
if buf.len() != SPENDING_KEY_LENGTH {
4644
return Err(CryptoError::InvalidData(format!(

crates/zipherx-crypto/src/prover.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,19 @@ pub(crate) fn get_verifying_keys(
121121
/// Get the total number of proofs to generate for the current TX.
122122
pub fn proof_total() -> u32 {
123123
zcash_primitives::transaction::components::sapling::builder::GROTH16_PROOFS_TOTAL
124-
.load(std::sync::atomic::Ordering::Relaxed) as u32
124+
.load(std::sync::atomic::Ordering::Relaxed)
125125
}
126126

127127
/// Get the number of proofs completed so far.
128128
pub fn proof_completed() -> u32 {
129129
zcash_primitives::transaction::components::sapling::builder::GROTH16_PROOFS_COMPLETED
130-
.load(std::sync::atomic::Ordering::Relaxed) as u32
130+
.load(std::sync::atomic::Ordering::Relaxed)
131131
}
132132

133133
/// Get the number of proof threads in use.
134134
pub fn proof_threads() -> u32 {
135135
zcash_primitives::transaction::components::sapling::builder::GROTH16_PROOF_THREADS
136-
.load(std::sync::atomic::Ordering::Relaxed) as u32
136+
.load(std::sync::atomic::Ordering::Relaxed)
137137
}
138138

139139
/// Cancel ongoing proof generation.

crates/zipherx-crypto/src/transaction.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub fn build_transaction(
103103
to_address,
104104
amount,
105105
memo,
106-
&[spend.clone()],
106+
std::slice::from_ref(spend),
107107
chain_height,
108108
)
109109
}
@@ -343,14 +343,13 @@ pub fn build_transaction_multi(
343343
)));
344344
}
345345

346-
// RCR-6: SECURITY — `extsk` is dropped here as defense-in-depth, but Rust's
347-
// default `Drop` does NOT zero memory. The `&[u8]` slice received here cannot
348-
// be zeroed by this function (immutable borrow).
346+
// RCR-6: SECURITY — `extsk` goes out of scope here, but Rust's default Drop
347+
// does NOT zero memory. The `&[u8]` slice received here cannot be zeroed by
348+
// this function (immutable borrow).
349349
//
350350
// IMPORTANT: Callers MUST wrap `sk_bytes` in `zeroize::Zeroizing<Vec<u8>>` to
351351
// ensure spending key material is securely zeroed on drop. Without `Zeroizing`,
352352
// key material may persist in freed memory.
353-
drop(extsk);
354353

355354
Ok(TransactionResult {
356355
tx_bytes,

crates/zipherx-crypto/src/tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub fn append(cmu: &[u8; 32]) -> Result<u64, CryptoError> {
160160
///
161161
/// Returns the new tree size.
162162
pub fn append_batch(cmus: &[u8]) -> Result<u64, CryptoError> {
163-
if cmus.len() % 32 != 0 {
163+
if !cmus.len().is_multiple_of(32) {
164164
return Err(CryptoError::InvalidData(format!(
165165
"CMU data length {} not a multiple of 32",
166166
cmus.len()

crates/zipherx-crypto/src/witness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub fn update_witness(witness_data: &[u8], cmu: &[u8; 32]) -> Result<Vec<u8>, Cr
8484
///
8585
/// Returns the updated witness bytes.
8686
pub fn update_witness_batch(witness_data: &[u8], cmus: &[u8]) -> Result<Vec<u8>, CryptoError> {
87-
if cmus.len() % 32 != 0 {
87+
if !cmus.len().is_multiple_of(32) {
8888
return Err(CryptoError::InvalidData(format!(
8989
"CMU data length {} not a multiple of 32",
9090
cmus.len()

0 commit comments

Comments
 (0)