0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

test: fix keys_to_multisig_script (P2MS) helper for n/k > 16

The helper assumes that the n and k values have to be provided as a
single byte push operation, which is only possible for values up to 16.
Fix that by passing the numbers directly to the CScript list, where it's
automatically converted to minimally-encoded pushes (see class
method `CScript.__coerce_instance`, branch `isinstance(other, int)`).

In case of 17..20, this means that the data-pushes are done with two
bytes using OP_PUSH1 (0x01), e.g. for n=20: 0x01,0x14
This commit is contained in:
Sebastian Falbesoner 2023-08-22 03:06:15 +02:00
parent ff7d2054c4
commit 0c41fc3fa5

View file

@ -5,7 +5,6 @@
"""Useful Script constants and utils."""
from test_framework.script import (
CScript,
CScriptOp,
OP_0,
OP_CHECKMULTISIG,
OP_CHECKSIG,
@ -49,10 +48,8 @@ def keys_to_multisig_script(keys, *, k=None):
if k is None: # n-of-n multisig by default
k = n
assert k <= n
op_k = CScriptOp.encode_op_n(k)
op_n = CScriptOp.encode_op_n(n)
checked_keys = [check_key(key) for key in keys]
return CScript([op_k] + checked_keys + [op_n, OP_CHECKMULTISIG])
return CScript([k] + checked_keys + [n, OP_CHECKMULTISIG])
def keyhash_to_p2pkh_script(hash):