From ba7d3c41bf1f5531990850b31d00fb7026fc1b69 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 28 Mar 2022 19:46:47 +0000 Subject: [PATCH] rust: Improve `PrecomputedTransactionData` construction errors We now log separate errors for "provided inputs when signing a coinbase transaction" and "provided the wrong number of inputs to a transaction". --- src/rust/src/transaction_ffi.rs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/rust/src/transaction_ffi.rs b/src/rust/src/transaction_ffi.rs index 29bb48c20..517567a73 100644 --- a/src/rust/src/transaction_ffi.rs +++ b/src/rust/src/transaction_ffi.rs @@ -207,21 +207,32 @@ pub extern "C" fn zcash_transaction_precomputed_init( return ptr::null_mut(); } Ok(all_prev_outputs) - if !tx + if tx.transparent_bundle().map_or(false, |t| { + // Coinbase txs have one fake input. + t.is_coinbase() && !all_prev_outputs.is_empty() + }) => + { + error!( + "all_prev_outputs should be empty for a coinbase tx but has length {}", + all_prev_outputs.len() + ); + return ptr::null_mut(); + } + Ok(all_prev_outputs) + if tx .transparent_bundle() .map(|t| { - if t.is_coinbase() { - // Coinbase txs have one fake input. - all_prev_outputs.is_empty() - } else { - // For non-coinbase txs, every input is real. - t.vin.len() == all_prev_outputs.len() - } + // For non-coinbase txs, every input is real. + !t.is_coinbase() && t.vin.len() != all_prev_outputs.len() }) // If we have no transparent part, we should have no prev outputs. - .unwrap_or_else(|| all_prev_outputs.is_empty()) => + .unwrap_or_else(|| !all_prev_outputs.is_empty()) => { - error!("all_prev_outputs is incorrect length"); + error!( + "all_prev_outputs is incorrect length {} (should be {})", + all_prev_outputs.len(), + tx.transparent_bundle().map(|t| t.vin.len()).unwrap_or(0), + ); return ptr::null_mut(); } Ok(all_prev_outputs) => MapTransparent {