From eae8bcf676f13d26366d3eb0cabb44ac64965fc5 Mon Sep 17 00:00:00 2001
From: Kirill Fomichev <fanatid@ya.ru>
Date: Thu, 1 Oct 2015 23:12:38 +0300
Subject: [PATCH] fix isMultisigOutput

---
 src/script.js             | 4 +---
 test/fixtures/script.json | 4 ++++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/script.js b/src/script.js
index 56c75e9..d6d5c31 100644
--- a/src/script.js
+++ b/src/script.js
@@ -225,12 +225,10 @@ function isMultisigOutput (script) {
   if (chunks[chunks.length - 1] !== OPS.OP_CHECKMULTISIG) return false
 
   var mOp = chunks[0]
-  if (mOp === OPS.OP_0) return false
   if (mOp < OPS.OP_1) return false
   if (mOp > OPS.OP_16) return false
 
   var nOp = chunks[chunks.length - 2]
-  if (nOp === OPS.OP_0) return false
   if (nOp < OPS.OP_1) return false
   if (nOp > OPS.OP_16) return false
 
@@ -239,7 +237,7 @@ function isMultisigOutput (script) {
   if (n < m) return false
 
   var pubKeys = chunks.slice(1, -2)
-  if (n < pubKeys.length) return false
+  if (n !== pubKeys.length) return false
 
   return pubKeys.every(isCanonicalPubKey)
 }
diff --git a/test/fixtures/script.json b/test/fixtures/script.json
index 59bb6e8..81f905d 100644
--- a/test/fixtures/script.json
+++ b/test/fixtures/script.json
@@ -241,6 +241,10 @@
         "description": "n < len(pubKeys)",
         "scriptPubKey": "OP_2 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34 OP_2 OP_CHECKMULTISIG"
       },
+      {
+        "description": "n > len(pubKeys)",
+        "scriptPubKey": "OP_1 024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34 OP_2 OP_CHECKMULTISIG"
+      },
       {
         "description": "non-canonical pubKey (bad length)",
         "scriptPubKey": "OP_1 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ffff OP_1 OP_CHECKMULTISIG"