refactor: flatten check_transparent_input with let-else + map_or
What changed, and why it matters
This commit is a pure code-style refactor in a Zcash transaction-checking function. It rewrites nested match statements into a flatter let-else and map_or pattern, but the commit message and diff show no change to the actual logic, error messages, or security behavior.
No security action needed; treat as normal code-quality refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change restructures check_transparent_input in rust/apps/zcash/src/pczt/check.rs. It replaces a nested match on TransparentAddress::from_script_from_chain and a nested match on bip32_derivation lookup with a let-else binding and an Option::map_or call. The same error variants, the same hash comparison, and the same derivation check are preserved. The commit explicitly states ‘No behavior change.’
Changed components
rust/apps/zcash/src/pczt/check.rsInspect captured patch +31 / −36
diff --git a/rust/apps/zcash/src/pczt/check.rs b/rust/apps/zcash/src/pczt/check.rs
index 375df9f..85dec60 100644
--- a/rust/apps/zcash/src/pczt/check.rs
+++ b/rust/apps/zcash/src/pczt/check.rs
@@ -145,43 +145,38 @@ fn check_transparent_input<P: consensus::Parameters>(
input: &transparent::pczt::Input,
) -> Result<bool, ZcashError> {
let script = input.script_pubkey().clone();
- //p2sh transparent input is not supported yet
- match TransparentAddress::from_script_from_chain(&script) {
- Some(TransparentAddress::PublicKeyHash(hash)) => {
- // 1: find my derivation
- let my_derivation = input
- .bip32_derivation()
- .iter()
- .find(|(_pubkey, derivation)| seed_fingerprint == derivation.seed_fingerprint());
- match my_derivation {
- None => {
- //not my input, pass
- Ok(false)
- }
- Some((pubkey, derivation)) => {
- // 2: derive my pubkey
- super::check_transparent_derivation(
- params,
- account_index,
- xpub,
- pubkey,
- derivation,
- "input",
- )?;
- // 3: check script pubkey
- if hash[..] != Ripemd160::digest(Sha256::digest(pubkey))[..] {
- return Err(ZcashError::InvalidPczt(
- "transparent input script pubkey mismatch".to_string(),
- ));
- }
- Ok(true)
- }
- }
- }
- _ => Err(ZcashError::InvalidPczt(
+ // p2sh transparent input is not supported yet
+ let Some(TransparentAddress::PublicKeyHash(hash)) =
+ TransparentAddress::from_script_from_chain(&script)
+ else {
+ return Err(ZcashError::InvalidPczt(
"transparent input script pubkey is not a public key hash".to_string(),
- )),
- }
+ ));
+ };
+
+ // 1: find my derivation (none means the input isn't ours, pass)
+ input
+ .bip32_derivation()
+ .iter()
+ .find(|(_pubkey, derivation)| seed_fingerprint == derivation.seed_fingerprint())
+ .map_or(Ok(false), |(pubkey, derivation)| {
+ // 2: derive my pubkey
+ super::check_transparent_derivation(
+ params,
+ account_index,
+ xpub,
+ pubkey,
+ derivation,
+ "input",
+ )?;
+ // 3: check script pubkey
+ if hash[..] != Ripemd160::digest(Sha256::digest(pubkey))[..] {
+ return Err(ZcashError::InvalidPczt(
+ "transparent input script pubkey mismatch".to_string(),
+ ));
+ }
+ Ok(true)
+ })
}
fn check_transparent_output<P: consensus::Parameters>(
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.