1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

core/bitcoin: Check ownership proofs using the provided commitment data.

This commit is contained in:
Andrew Kozlik 2020-09-07 17:48:42 +02:00 committed by Andrew Kozlik
parent 5d745d5d04
commit 295710c37d
3 changed files with 10 additions and 3 deletions

View File

@ -66,7 +66,7 @@ def generate_proof(
def verify_nonownership(
proof: bytes,
script_pubkey: bytes,
commitment_data: bytes,
commitment_data: Optional[bytes],
keychain: Keychain,
coin: CoinInfo,
) -> bool:
@ -92,6 +92,7 @@ def verify_nonownership(
proof_body = proof[: r.offset]
sighash = hashlib.sha256(proof_body)
sighash.update(script_pubkey)
if commitment_data:
sighash.update(commitment_data)
script_sig, witness = read_bip322_signature_proof(r)

View File

@ -245,7 +245,11 @@ class Bitcoin:
) -> None:
if txi.ownership_proof:
if not verify_nonownership(
txi.ownership_proof, script_pubkey, bytes(), self.keychain, self.coin
txi.ownership_proof,
script_pubkey,
txi.commitment_data,
self.keychain,
self.coin,
):
raise wire.DataError("Invalid external input")
else:

View File

@ -276,6 +276,8 @@ def sanitize_tx_input(tx: TransactionType, coin: CoinInfo) -> TxInputType:
if txi.script_type in common.SEGWIT_INPUT_SCRIPT_TYPES or txi.witness is not None:
if not coin.segwit:
raise wire.DataError("Segwit not enabled on this coin")
if txi.commitment_data and not txi.ownership_proof:
raise wire.DataError("commitment_data field provided but not expected.")
return txi