1616class ScriptPubKey extends Script
1717{
1818 /**
19+ * ScriptPubKey: OP_RETURN ...
1920 * @return bool
2021 */
2122 public function isReturn (): bool
@@ -24,6 +25,7 @@ public function isReturn(): bool
2425 }
2526
2627 /**
28+ * ScriptPubKey: (empty)
2729 * @return bool
2830 */
2931 public function isEmpty (): bool
@@ -53,6 +55,9 @@ protected function isPubKey(int $size, string $prefix): bool
5355 }
5456
5557 /**
58+ * ScriptPubKey: OP_PUSHDATA(33) [0x02] [pubkey compressed] OP_CHECKSIG
59+ * ScriptPubKey: OP_PUSHDATA(33) [0x03] [pubkey compressed] OP_CHECKSIG
60+ * ScriptPubKey: OP_PUSHDATA(65) [0x04] [pubkey] OP_CHECKSIG
5661 * @return bool
5762 */
5863 public function isPayToPubKey (): bool
@@ -64,6 +69,7 @@ public function isPayToPubKey(): bool
6469 }
6570
6671 /**
72+ * ScriptPubKey: OP_DUP OP_HASH160 OP_PUSHDATA(20) [pubkey hash] OP_EQUALVERIFY OP_CHECKSIG
6773 * @return bool
6874 */
6975 public function isPayToPubKeyHash (): bool
@@ -77,7 +83,8 @@ public function isPayToPubKeyHash(): bool
7783 }
7884
7985 /**
80- * handle output of TX 059787f0673ab2c00b8f2f9810fdd14b0cd6a3034cc44dc30de124f606d3670a
86+ * Handle output of TX 059787f0673ab2c00b8f2f9810fdd14b0cd6a3034cc44dc30de124f606d3670a
87+ * ScriptPubKey: OP_DUP OP_HASH160 OP_PUSHDATA1 [pubkey hash] OP_EQUALVERIFY OP_CHECKSIG
8188 * @return bool
8289 */
8390 public function isPayToPubKeyHashAlt (): bool
@@ -92,6 +99,7 @@ public function isPayToPubKeyHashAlt(): bool
9299 }
93100
94101 /**
102+ * ScriptPubKey: OP_HASH160 PUSHDATA(20) [script hash] OP_EQUAL
95103 * @return bool
96104 */
97105 public function isPayToScriptHash (): bool
@@ -103,13 +111,15 @@ public function isPayToScriptHash(): bool
103111 }
104112
105113 /**
114+ * ScriptPubKey: [num sigs] [...pub keys..] [num pub keys] OP_CHECKMULTISIG
106115 * @return bool
107116 */
108117 public function isMultisig (): bool
109118 {
110119 $ sigs = ord ($ this ->data [0 ]);
111120 $ keys = ord ($ this ->data [-2 ]);
112121
122+ // check pattern
113123 if (!($ this ->size >= 37 &&
114124 $ sigs >= Opcodes::OP_1 && $ sigs <= Opcodes::OP_16 &&
115125 $ keys >= Opcodes::OP_1 && $ keys <= Opcodes::OP_16 &&
@@ -118,20 +128,18 @@ public function isMultisig(): bool
118128 return false ;
119129 }
120130
121- for ($ i = 1 , $ k = 0 ; $ i < $ this ->size - 2 ; $ k ++) {
131+ // check valid keys
132+ for ($ i = 1 , $ j = $ k = 0 ; $ i < $ this ->size - 2 ; $ j ++) {
122133 $ size = ord ($ this ->data [$ i ]);
123-
124- if (!$ this ->isPubKey ($ size , $ this ->data [$ i + 1 ])) {
125- return false ;
126- }
127-
134+ $ k += $ this ->isPubKey ($ size , $ this ->data [$ i + 1 ]);
128135 $ i += $ size + 1 ;
129136 }
130137
131- return $ keys - Opcodes::OP_1 + 1 == $ k ;
138+ return $ k > 0 && $ keys - Opcodes::OP_1 + 1 == $ j ;
132139 }
133140
134141 /**
142+ * ScriptPubKey: [version] OP_PUSHDATA(20) [pubkey hash]
135143 * @return bool
136144 */
137145 public function isPayToWitnessPubKeyHash (): bool
@@ -144,6 +152,7 @@ public function isPayToWitnessPubKeyHash(): bool
144152 }
145153
146154 /**
155+ * ScriptPubKey: [version] OP_PUSHDATA(32) [script hash]
147156 * @return bool
148157 */
149158 public function isPayToWitnessScriptHash (): bool
0 commit comments