mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-31 01:41:18 +00:00
core/sign_tx: Add further message sanitization checks.
This commit is contained in:
parent
7b94cbee54
commit
7db3e930d4
@ -242,6 +242,8 @@ def sanitize_tx_input(tx: TransactionType, coin: CoinInfo) -> TxInputType:
|
|||||||
txi.script_type = InputScriptType.SPENDADDRESS
|
txi.script_type = InputScriptType.SPENDADDRESS
|
||||||
if txi.sequence is None:
|
if txi.sequence is None:
|
||||||
txi.sequence = 0xFFFFFFFF
|
txi.sequence = 0xFFFFFFFF
|
||||||
|
if txi.prev_index is None:
|
||||||
|
raise wire.DataError("Missing prev_index field.")
|
||||||
if txi.prev_hash is None or len(txi.prev_hash) != TX_HASH_SIZE:
|
if txi.prev_hash is None or len(txi.prev_hash) != TX_HASH_SIZE:
|
||||||
raise wire.DataError("Provided prev_hash is invalid.")
|
raise wire.DataError("Provided prev_hash is invalid.")
|
||||||
if txi.multisig and txi.script_type not in MULTISIG_INPUT_SCRIPT_TYPES:
|
if txi.multisig and txi.script_type not in MULTISIG_INPUT_SCRIPT_TYPES:
|
||||||
@ -253,8 +255,6 @@ def sanitize_tx_input(tx: TransactionType, coin: CoinInfo) -> TxInputType:
|
|||||||
if txi.script_type in SEGWIT_INPUT_SCRIPT_TYPES:
|
if txi.script_type in SEGWIT_INPUT_SCRIPT_TYPES:
|
||||||
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.amount is None:
|
|
||||||
raise wire.DataError("Segwit input without amount")
|
|
||||||
return txi
|
return txi
|
||||||
|
|
||||||
|
|
||||||
@ -264,8 +264,12 @@ def sanitize_tx_output(tx: TransactionType, coin: CoinInfo) -> TxOutputType:
|
|||||||
raise wire.DataError("Multisig field provided but not expected.")
|
raise wire.DataError("Multisig field provided but not expected.")
|
||||||
if txo.address_n and txo.script_type not in CHANGE_OUTPUT_SCRIPT_TYPES:
|
if txo.address_n and txo.script_type not in CHANGE_OUTPUT_SCRIPT_TYPES:
|
||||||
raise wire.DataError("Output's address_n provided but not expected.")
|
raise wire.DataError("Output's address_n provided but not expected.")
|
||||||
|
if txo.amount is None:
|
||||||
|
raise wire.DataError("Missing amount field.")
|
||||||
if txo.script_type == OutputScriptType.PAYTOOPRETURN:
|
if txo.script_type == OutputScriptType.PAYTOOPRETURN:
|
||||||
# op_return output
|
# op_return output
|
||||||
|
if txo.op_return_data is None:
|
||||||
|
raise wire.DataError("OP_RETURN output without op_return_data")
|
||||||
if txo.amount != 0:
|
if txo.amount != 0:
|
||||||
raise wire.DataError("OP_RETURN output with non-zero amount")
|
raise wire.DataError("OP_RETURN output with non-zero amount")
|
||||||
if txo.address or txo.address_n or txo.multisig:
|
if txo.address or txo.address_n or txo.multisig:
|
||||||
@ -284,4 +288,8 @@ def sanitize_tx_output(tx: TransactionType, coin: CoinInfo) -> TxOutputType:
|
|||||||
|
|
||||||
def sanitize_tx_binoutput(tx: TransactionType, coin: CoinInfo) -> TxOutputBinType:
|
def sanitize_tx_binoutput(tx: TransactionType, coin: CoinInfo) -> TxOutputBinType:
|
||||||
txo_bin = tx.bin_outputs[0]
|
txo_bin = tx.bin_outputs[0]
|
||||||
|
if txo_bin.amount is None:
|
||||||
|
raise wire.DataError("Missing amount field.")
|
||||||
|
if txo_bin.script_pubkey is None:
|
||||||
|
raise wire.DataError("Missing script_pubkey field.")
|
||||||
return txo_bin
|
return txo_bin
|
||||||
|
Loading…
Reference in New Issue
Block a user