mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-11 05:36:09 +00:00
core/bitcoin: Check ownership proofs using the provided commitment data.
This commit is contained in:
parent
5d745d5d04
commit
295710c37d
@ -66,7 +66,7 @@ def generate_proof(
|
|||||||
def verify_nonownership(
|
def verify_nonownership(
|
||||||
proof: bytes,
|
proof: bytes,
|
||||||
script_pubkey: bytes,
|
script_pubkey: bytes,
|
||||||
commitment_data: bytes,
|
commitment_data: Optional[bytes],
|
||||||
keychain: Keychain,
|
keychain: Keychain,
|
||||||
coin: CoinInfo,
|
coin: CoinInfo,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
@ -92,6 +92,7 @@ def verify_nonownership(
|
|||||||
proof_body = proof[: r.offset]
|
proof_body = proof[: r.offset]
|
||||||
sighash = hashlib.sha256(proof_body)
|
sighash = hashlib.sha256(proof_body)
|
||||||
sighash.update(script_pubkey)
|
sighash.update(script_pubkey)
|
||||||
|
if commitment_data:
|
||||||
sighash.update(commitment_data)
|
sighash.update(commitment_data)
|
||||||
script_sig, witness = read_bip322_signature_proof(r)
|
script_sig, witness = read_bip322_signature_proof(r)
|
||||||
|
|
||||||
|
@ -245,7 +245,11 @@ class Bitcoin:
|
|||||||
) -> None:
|
) -> None:
|
||||||
if txi.ownership_proof:
|
if txi.ownership_proof:
|
||||||
if not verify_nonownership(
|
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")
|
raise wire.DataError("Invalid external input")
|
||||||
else:
|
else:
|
||||||
|
@ -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 txi.script_type in common.SEGWIT_INPUT_SCRIPT_TYPES or txi.witness is not None:
|
||||||
if not coin.segwit:
|
if not coin.segwit:
|
||||||
raise wire.DataError("Segwit not enabled on this coin")
|
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
|
return txi
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user