MCPcopy
hub / github.com/petertodd/python-bitcoinlib / _CheckMultiSig

Function _CheckMultiSig

bitcoin/core/scripteval.py:149–224  ·  view source on GitHub ↗
(opcode, script, stack, txTo, inIdx, flags, err_raiser, nOpCount)

Source from the content-addressed store, hash-verified

147
148
149def _CheckMultiSig(opcode, script, stack, txTo, inIdx, flags, err_raiser, nOpCount):
150 i = 1
151 if len(stack) < i:
152 err_raiser(MissingOpArgumentsError, opcode, stack, i)
153
154 keys_count = _CastToBigNum(stack[-i], err_raiser)
155 if keys_count < 0 or keys_count > 20:
156 err_raiser(ArgumentsInvalidError, opcode, "keys count invalid")
157 i += 1
158 ikey = i
159 i += keys_count
160 nOpCount[0] += keys_count
161 if nOpCount[0] > MAX_SCRIPT_OPCODES:
162 err_raiser(MaxOpCountError)
163 if len(stack) < i:
164 err_raiser(ArgumentsInvalidError, opcode, "not enough keys on stack")
165
166 sigs_count = _CastToBigNum(stack[-i], err_raiser)
167 if sigs_count < 0 or sigs_count > keys_count:
168 err_raiser(ArgumentsInvalidError, opcode, "sigs count invalid")
169
170 i += 1
171 isig = i
172 i += sigs_count
173 if len(stack) < i-1:
174 raise err_raiser(ArgumentsInvalidError, opcode, "not enough sigs on stack")
175 elif len(stack) < i:
176 raise err_raiser(ArgumentsInvalidError, opcode, "missing dummy value")
177
178 # Drop the signature, since there's no way for a signature to sign itself
179 #
180 # Of course, this can only come up in very contrived cases now that
181 # scriptSig and scriptPubKey are processed separately.
182 for k in range(sigs_count):
183 sig = stack[-isig - k]
184 script = FindAndDelete(script, CScript([sig]))
185
186 success = True
187
188 while success and sigs_count > 0:
189 sig = stack[-isig]
190 pubkey = stack[-ikey]
191
192 if _CheckSig(sig, pubkey, script, txTo, inIdx, err_raiser):
193 isig += 1
194 sigs_count -= 1
195
196 ikey += 1
197 keys_count -= 1
198
199 if sigs_count > keys_count:
200 success = False
201
202 # with VERIFY bail now before we modify the stack
203 if opcode == OP_CHECKMULTISIGVERIFY:
204 err_raiser(VerifyOpFailedError, opcode)
205
206 while i > 1:

Callers 1

_EvalScriptFunction · 0.85

Calls 5

err_raiserFunction · 0.85
_CastToBigNumFunction · 0.85
FindAndDeleteFunction · 0.85
CScriptClass · 0.85
_CheckSigFunction · 0.85

Tested by

no test coverage detected