Skip to content

Commit bd75235

Browse files
committed
test(taproot): prove tampered prevout rejection
1 parent b6e8f01 commit bd75235

2 files changed

Lines changed: 46 additions & 8 deletions

File tree

scripts/generate-test-report.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -793,26 +793,32 @@ def _arg_shown(a):
793793
'Fails closed when any input amount is absent, preventing the device from producing '
794794
'a valid Schnorr signature over an incomplete BIP-341 commitment.',
795795
[]),
796-
('B25', 'test_msg_getaddress_taproot', 'test_show_taproot_address',
796+
('B25', 'test_msg_signtx_taproot',
797+
'test_mixed_p2tr_rejects_wrong_legacy_amount',
798+
'Reject a tampered legacy prevout amount',
799+
'Fetches the actual legacy prevout and rejects a host-provided amount that differs by '
800+
'one satoshi, preventing a false BIP-341 commitment in a mixed-input transaction.',
801+
[]),
802+
('B26', 'test_msg_getaddress_taproot', 'test_show_taproot_address',
797803
'Show BIP-86 address on OLED',
798804
'Displays the complete bech32m Taproot receive address and QR code on the trusted '
799805
'device screen for host-independent verification.',
800806
['Taproot address + QR code']),
801-
('B26', 'test_msg_signmessage', 'test_sign',
807+
('B27', 'test_msg_signmessage', 'test_sign',
802808
'Sign message with BTC key',
803809
'Signs arbitrary text with a BTC address key. Used for proof-of-ownership and login.',
804810
['Sign message on OLED']),
805-
('B27', 'test_msg_signmessage_segwit', 'test_sign',
811+
('B28', 'test_msg_signmessage_segwit', 'test_sign',
806812
'Sign message with SegWit key', 'Message signing with P2SH-SegWit address key.', []),
807-
('B28', 'test_msg_signmessage_segwit_native', 'test_sign',
813+
('B29', 'test_msg_signmessage_segwit_native', 'test_sign',
808814
'Sign message with bech32 key', 'Message signing with native SegWit address key.', []),
809-
('B29', 'test_msg_verifymessage', 'test_message_verify',
815+
('B30', 'test_msg_verifymessage', 'test_message_verify',
810816
'Verify signed message', 'Device verifies a message signature against a BTC address.', []),
811-
('B30', 'test_msg_signtx_bgold', 'test_send_bitcoin_gold_nochange',
817+
('B31', 'test_msg_signtx_bgold', 'test_send_bitcoin_gold_nochange',
812818
'Sign Bitcoin Gold tx', 'BTG fork uses same signing code with different chain parameters.', []),
813-
('B31', 'test_msg_signtx_dash', 'test_send_dash',
819+
('B32', 'test_msg_signtx_dash', 'test_send_dash',
814820
'Sign Dash transaction', 'Dash special transaction types (InstantSend-compatible).', []),
815-
('B32', 'test_msg_signtx_grs', 'test_one_one_fee',
821+
('B33', 'test_msg_signtx_grs', 'test_one_one_fee',
816822
'Sign Groestlcoin tx', 'GRS uses Groestl hash instead of SHA-256d for tx hashing.', []),
817823
# Zcash transparent signing moved to its own section Y (Zcash Transparent).
818824
]),

tests/test_msg_signtx_taproot.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,38 @@ def test_mixed_p2tr_requires_every_input_amount(self):
188188
self.client.sign_tx(
189189
"Bitcoin", [taproot, incomplete_legacy], [recipient])
190190

191+
def test_mixed_p2tr_rejects_wrong_legacy_amount(self):
192+
"""Reject a host amount that disagrees with the actual legacy prevout."""
193+
self.requires_taproot()
194+
self.setup_mnemonic_abandon()
195+
self.client.set_tx_api(TxApiBitcoin)
196+
197+
taproot = proto_types.TxInputType(
198+
address_n=parse_path("86'/0'/0'/0/0"),
199+
amount=100000,
200+
prev_hash=unhexlify(MIXED_PREV_TXID),
201+
prev_index=0,
202+
script_type=proto_types.SPENDTAPROOT,
203+
)
204+
tampered_legacy = proto_types.TxInputType(
205+
address_n=parse_path("44'/0'/0'/0/0"),
206+
amount=50001,
207+
prev_hash=unhexlify(MIXED_PREV_TXID),
208+
prev_index=1,
209+
script_type=proto_types.SPENDADDRESS,
210+
)
211+
recipient = proto_types.TxOutputType(
212+
address=OUT_ADDRESS,
213+
amount=140000,
214+
script_type=proto_types.PAYTOADDRESS,
215+
)
216+
217+
with self.assertRaisesRegex(
218+
CallException,
219+
"Input amount or script does not match prevout"):
220+
self.client.sign_tx(
221+
"Bitcoin", [taproot, tampered_legacy], [recipient])
222+
191223

192224
if __name__ == '__main__':
193225
unittest.main()

0 commit comments

Comments
 (0)