Use let-else to flatten nested optionals in is_multisig
What changed, and why it matters
This commit is a pure code-style refactor. It rewrites the same multisignature-pattern check using a newer Rust syntax (let-else) that flattens nested if-let blocks. The author explicitly states there are no behavioral changes, and the diff shows the same checks in the same order with the same early returns.
No security action needed. Treat as a normal readability refactor during code review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change replaces nested if-let/else blocks in Script::is_multisig with let-else statements. The control flow and conditions are identical: require a first push-number instruction, count subsequent push instructions, require the count to match the required signatures, require a final OP_CHECKMULTISIG, and ensure no trailing instructions. No logic, ordering, or return values changed.
Changed components
bitcoin/src/blockdata/script/borrowed.rsScript::is_multisigInspect captured patch +7 / −16
diff --git a/bitcoin/src/blockdata/script/borrowed.rs b/bitcoin/src/blockdata/script/borrowed.rs
index 5da05cc5..3f261218 100644
--- a/bitcoin/src/blockdata/script/borrowed.rs
+++ b/bitcoin/src/blockdata/script/borrowed.rs
@@ -321,18 +321,13 @@ internal_macros::define_extension_trait! {
/// `2 <pubkey1> <pubkey2> <pubkey3> 3 OP_CHECKMULTISIG`
#[inline]
fn is_multisig(&self) -> bool {
- let required_sigs;
-
let mut instructions = self.instructions();
- if let Some(Ok(Instruction::Op(op))) = instructions.next() {
- if let Some(pushnum) = op.decode_pushnum() {
- required_sigs = pushnum;
- } else {
- return false;
- }
- } else {
+ let Some(Ok(Instruction::Op(op))) = instructions.next() else {
return false;
- }
+ };
+ let Some(required_sigs) = op.decode_pushnum() else {
+ return false;
+ };
let mut num_pubkeys: u8 = 0;
while let Some(Ok(instruction)) = instructions.next() {
@@ -351,13 +346,9 @@ internal_macros::define_extension_trait! {
return false;
}
- if let Some(Ok(Instruction::Op(op))) = instructions.next() {
- if op != OP_CHECKMULTISIG {
- return false;
- }
- } else {
+ let Some(Ok(Instruction::Op(OP_CHECKMULTISIG))) = instructions.next() else {
return false;
- }
+ };
instructions.next().is_none()
}
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.