mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 23:08:14 +00:00
core/sign_tx: check if prev_tx has enough outputs to match prev_index
This commit is contained in:
parent
1bf08cbb97
commit
303c05aba7
@ -597,6 +597,11 @@ async def get_prevtx_output_value(
|
||||
# STAGE_REQUEST_2_PREV_META
|
||||
tx = await helpers.request_tx_meta(tx_req, prev_hash)
|
||||
|
||||
if tx.outputs_cnt <= prev_index:
|
||||
raise SigningError(
|
||||
FailureType.ProcessError, "Not enough outputs in previous transaction."
|
||||
)
|
||||
|
||||
if not utils.BITCOIN_ONLY and coin.decred:
|
||||
txh = utils.HashWriter(blake256())
|
||||
else:
|
||||
|
@ -17,6 +17,7 @@
|
||||
import pytest
|
||||
|
||||
from trezorlib import btc, messages as proto
|
||||
from trezorlib.exceptions import TrezorFailure
|
||||
from trezorlib.tools import H_, CallException, btc_hash, parse_path
|
||||
|
||||
from ..common import MNEMONIC12
|
||||
@ -864,3 +865,31 @@ class TestMsgSigntx:
|
||||
)
|
||||
|
||||
check_sign_tx(client, "Testnet", [inp1], [out1, out_change])
|
||||
|
||||
@pytest.mark.skip_ui
|
||||
def test_not_enough_vouts(self, client):
|
||||
cache = tx_cache("Bitcoin")
|
||||
prev_tx = cache[TXHASH_157041]
|
||||
|
||||
# tx has two vouts
|
||||
assert len(prev_tx.bin_outputs) == 2
|
||||
|
||||
# vout[0] and vout[1] exist
|
||||
inp0 = proto.TxInputType(address_n=[0], prev_hash=TXHASH_157041, prev_index=0)
|
||||
inp1 = proto.TxInputType(address_n=[0], prev_hash=TXHASH_157041, prev_index=1)
|
||||
# vout[2] does not exist
|
||||
inp2 = proto.TxInputType(address_n=[0], prev_hash=TXHASH_157041, prev_index=2)
|
||||
|
||||
# try to spend the sum of existing vouts
|
||||
out1 = proto.TxOutputType(
|
||||
address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1",
|
||||
amount=220160000,
|
||||
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
||||
)
|
||||
|
||||
with pytest.raises(TrezorFailure) as e:
|
||||
btc.sign_tx(client, "Bitcoin", [inp0, inp1, inp2], [out1], prev_txes=cache)
|
||||
|
||||
assert e.value.failure.message.endswith(
|
||||
"Not enough outputs in previous transaction."
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user