diff --git a/src/apps/wallet/sign_tx/helpers.py b/src/apps/wallet/sign_tx/helpers.py index 3574e09733..f5effa51dd 100644 --- a/src/apps/wallet/sign_tx/helpers.py +++ b/src/apps/wallet/sign_tx/helpers.py @@ -5,7 +5,7 @@ from trezor.messages.TxInputType import TxInputType from trezor.messages.SignTx import SignTx from trezor.messages.TxRequest import TxRequest from trezor.messages.TransactionType import TransactionType -from trezor.messages.RequestType import TXINPUT, TXOUTPUT, TXMETA, TXFINISHED +from trezor.messages.RequestType import TXINPUT, TXOUTPUT, TXMETA, TXEXTRADATA, TXFINISHED from trezor.messages import InputScriptType # Machine instructions @@ -55,6 +55,17 @@ def request_tx_meta(tx_req: TxRequest, tx_hash: bytes=None): return sanitize_tx_meta(ack.tx) +def request_tx_extra_data(tx_req: TxRequest, offset: int, size: int, tx_hash: bytes=None): + tx_req.request_type = TXEXTRADATA + tx_req.details.extra_data_offset = offset + tx_req.details.extra_data_len = size + tx_req.details.tx_hash = tx_hash + tx_req.details.request_index = None + ack = yield tx_req + tx_req.serialized = None + return ack.tx.extra_data + + def request_tx_input(tx_req: TxRequest, i: int, tx_hash: bytes=None): tx_req.request_type = TXINPUT tx_req.details.request_index = i @@ -101,6 +112,7 @@ def sanitize_tx_meta(tx: TransactionType) -> TransactionType: tx.lock_time = tx.lock_time if tx.lock_time is not None else 0 tx.inputs_cnt = tx.inputs_cnt if tx.inputs_cnt is not None else 0 tx.outputs_cnt = tx.outputs_cnt if tx.outputs_cnt is not None else 0 + tx.extra_data_len = tx.extra_data_len if tx.extra_data_len is not None else 0 return tx diff --git a/src/apps/wallet/sign_tx/signing.py b/src/apps/wallet/sign_tx/signing.py index fcc51897f2..64cfec8be8 100644 --- a/src/apps/wallet/sign_tx/signing.py +++ b/src/apps/wallet/sign_tx/signing.py @@ -319,6 +319,13 @@ async def get_prevtx_output_value(tx_req: TxRequest, prev_hash: bytes, prev_inde write_uint32(txh, tx.lock_time) + ofs = 0 + while ofs < tx.extra_data_len: + size = min(1024, tx.extra_data_len - ofs) + data = await request_tx_extra_data(tx_req, ofs, size, prev_hash) + write_bytes(txh, data) + ofs += len(data) + if get_tx_hash(txh, True, True) != prev_hash: raise SigningError(FailureType.ProcessError, 'Encountered invalid prev_hash') diff --git a/tests/test_apps.wallet.signtx.fee_threshold.py b/tests/test_apps.wallet.signtx.fee_threshold.py index 511ba6ed86..3c8190d55b 100644 --- a/tests/test_apps.wallet.signtx.fee_threshold.py +++ b/tests/test_apps.wallet.signtx.fee_threshold.py @@ -23,7 +23,7 @@ class TestSignTxFeeThreshold(unittest.TestCase): def test_over_fee_threshold(self): coin_bitcoin = coins.by_name('Bitcoin') - ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=2, outputs_cnt=1) + ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=2, outputs_cnt=1, extra_data_len=0) pinp1 = TxInputType(script_sig=unhexlify('483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503'), prev_hash=unhexlify('c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf'), prev_index=1, @@ -85,7 +85,7 @@ class TestSignTxFeeThreshold(unittest.TestCase): def test_under_threshold(self): coin_bitcoin = coins.by_name('Bitcoin') - ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=2, outputs_cnt=1) + ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=2, outputs_cnt=1, extra_data_len=0) pinp1 = TxInputType(script_sig=unhexlify('483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503'), prev_hash=unhexlify('c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf'), prev_index=1, diff --git a/tests/test_apps.wallet.signtx.py b/tests/test_apps.wallet.signtx.py index 4f080ea425..e792018336 100644 --- a/tests/test_apps.wallet.signtx.py +++ b/tests/test_apps.wallet.signtx.py @@ -26,7 +26,7 @@ class TestSignTx(unittest.TestCase): coin_bitcoin = coins.by_name('Bitcoin') - ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=2, outputs_cnt=1) + ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=2, outputs_cnt=1, extra_data_len=0) pinp1 = TxInputType(script_sig=unhexlify('483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503'), prev_hash=unhexlify('c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf'), prev_index=1,