mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 12:28:09 +00:00
fix(cardano): add input validation
This commit is contained in:
parent
48587d83fe
commit
143af80aea
@ -4,6 +4,39 @@
|
|||||||
"passphrase": ""
|
"passphrase": ""
|
||||||
},
|
},
|
||||||
"tests": [
|
"tests": [
|
||||||
|
{
|
||||||
|
"description": "Input prev hash has incorrect length",
|
||||||
|
"parameters": {
|
||||||
|
"protocol_magic": 764824073,
|
||||||
|
"network_id": 1,
|
||||||
|
"fee": 42,
|
||||||
|
"ttl": 10,
|
||||||
|
"certificates": [],
|
||||||
|
"withdrawals": [],
|
||||||
|
"auxiliary_data": null,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"path": "m/1852'/1815'/0'/0/0",
|
||||||
|
"prev_hash": "3b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3",
|
||||||
|
"prev_index": 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"address": "Ae2tdPwUPEZCanmBz5g2GEwFqKTKpNJcGYPKfDxoNeKZ8bRHr8366kseiK2",
|
||||||
|
"amount": "3003112"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"mint": [],
|
||||||
|
"script_data_hash": null,
|
||||||
|
"signing_mode": "ORDINARY_TRANSACTION",
|
||||||
|
"additional_witness_requests": [],
|
||||||
|
"include_network_id": false
|
||||||
|
},
|
||||||
|
"result": {
|
||||||
|
"error_message": "Invalid input"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"description": "Output address is a valid CBOR but invalid Cardano address",
|
"description": "Output address is a valid CBOR but invalid Cardano address",
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
@ -4,6 +4,7 @@ INVALID_ADDRESS = wire.ProcessError("Invalid address")
|
|||||||
INVALID_ADDRESS_PARAMETERS = wire.ProcessError("Invalid address parameters")
|
INVALID_ADDRESS_PARAMETERS = wire.ProcessError("Invalid address parameters")
|
||||||
NETWORK_MISMATCH = wire.ProcessError("Output address network mismatch")
|
NETWORK_MISMATCH = wire.ProcessError("Output address network mismatch")
|
||||||
INVALID_TX_SIGNING_REQUEST = wire.ProcessError("Invalid tx signing request")
|
INVALID_TX_SIGNING_REQUEST = wire.ProcessError("Invalid tx signing request")
|
||||||
|
INVALID_INPUT = wire.ProcessError("Invalid input")
|
||||||
INVALID_OUTPUT = wire.ProcessError("Invalid output")
|
INVALID_OUTPUT = wire.ProcessError("Invalid output")
|
||||||
INVALID_CERTIFICATE = wire.ProcessError("Invalid certificate")
|
INVALID_CERTIFICATE = wire.ProcessError("Invalid certificate")
|
||||||
INVALID_WITHDRAWAL = wire.ProcessError("Invalid withdrawal")
|
INVALID_WITHDRAWAL = wire.ProcessError("Invalid withdrawal")
|
||||||
@ -22,6 +23,7 @@ INVALID_OUTPUT_DATUM_HASH = wire.ProcessError("Invalid output datum hash")
|
|||||||
INVALID_SCRIPT_DATA_HASH = wire.ProcessError("Invalid script data hash")
|
INVALID_SCRIPT_DATA_HASH = wire.ProcessError("Invalid script data hash")
|
||||||
|
|
||||||
LOVELACE_MAX_SUPPLY = 45_000_000_000 * 1_000_000
|
LOVELACE_MAX_SUPPLY = 45_000_000_000 * 1_000_000
|
||||||
|
INPUT_PREV_HASH_SIZE = 32
|
||||||
ADDRESS_KEY_HASH_SIZE = 28
|
ADDRESS_KEY_HASH_SIZE = 28
|
||||||
SCRIPT_HASH_SIZE = 28
|
SCRIPT_HASH_SIZE = 28
|
||||||
OUTPUT_DATUM_HASH_SIZE = 32
|
OUTPUT_DATUM_HASH_SIZE = 32
|
||||||
|
@ -60,6 +60,8 @@ from .certificates import (
|
|||||||
validate_pool_relay,
|
validate_pool_relay,
|
||||||
)
|
)
|
||||||
from .helpers import (
|
from .helpers import (
|
||||||
|
INPUT_PREV_HASH_SIZE,
|
||||||
|
INVALID_INPUT,
|
||||||
INVALID_OUTPUT,
|
INVALID_OUTPUT,
|
||||||
INVALID_OUTPUT_DATUM_HASH,
|
INVALID_OUTPUT_DATUM_HASH,
|
||||||
INVALID_SCRIPT_DATA_HASH,
|
INVALID_SCRIPT_DATA_HASH,
|
||||||
@ -341,6 +343,7 @@ async def _process_inputs(
|
|||||||
"""Read, validate and serialize the inputs."""
|
"""Read, validate and serialize the inputs."""
|
||||||
for _ in range(inputs_count):
|
for _ in range(inputs_count):
|
||||||
input: CardanoTxInput = await ctx.call(CardanoTxItemAck(), CardanoTxInput)
|
input: CardanoTxInput = await ctx.call(CardanoTxItemAck(), CardanoTxInput)
|
||||||
|
_validate_input(input)
|
||||||
inputs_list.append((input.prev_hash, input.prev_index))
|
inputs_list.append((input.prev_hash, input.prev_index))
|
||||||
|
|
||||||
|
|
||||||
@ -778,6 +781,11 @@ def _validate_stake_pool_registration_tx_structure(msg: CardanoSignTxInit) -> No
|
|||||||
raise INVALID_STAKE_POOL_REGISTRATION_TX_STRUCTURE
|
raise INVALID_STAKE_POOL_REGISTRATION_TX_STRUCTURE
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_input(input: CardanoTxInput) -> None:
|
||||||
|
if len(input.prev_hash) != INPUT_PREV_HASH_SIZE:
|
||||||
|
raise INVALID_INPUT
|
||||||
|
|
||||||
|
|
||||||
def _validate_output(
|
def _validate_output(
|
||||||
output: CardanoTxOutput,
|
output: CardanoTxOutput,
|
||||||
signing_mode: CardanoTxSigningMode,
|
signing_mode: CardanoTxSigningMode,
|
||||||
|
Loading…
Reference in New Issue
Block a user