bitcoin: disallow importing/sweeping segwit scripts with uncompressed pubkey
fixes #4638
This commit is contained in:
@@ -527,6 +527,9 @@ WIF_SCRIPT_TYPES = {
|
||||
WIF_SCRIPT_TYPES_INV = inv_dict(WIF_SCRIPT_TYPES)
|
||||
|
||||
|
||||
def is_segwit_script_type(txin_type: str) -> bool:
|
||||
return txin_type in ('p2wpkh', 'p2wpkh-p2sh', 'p2wsh', 'p2wsh-p2sh')
|
||||
|
||||
|
||||
def serialize_privkey(secret: bytes, compressed: bool, txin_type: str,
|
||||
internal_use: bool=False) -> str:
|
||||
@@ -576,6 +579,10 @@ def deserialize_privkey(key: str) -> Tuple[str, bytes, bool]:
|
||||
if len(vch) not in [33, 34]:
|
||||
raise BitcoinException('invalid vch len for WIF key: {}'.format(len(vch)))
|
||||
compressed = len(vch) == 34
|
||||
|
||||
if is_segwit_script_type(txin_type) and not compressed:
|
||||
raise BitcoinException('only compressed public keys can be used in segwit scripts')
|
||||
|
||||
secret_bytes = vch[1:33]
|
||||
# we accept secrets outside curve range; cast into range here:
|
||||
secret_bytes = ecc.ECPrivkey.normalize_secret_bytes(secret_bytes)
|
||||
|
||||
Reference in New Issue
Block a user