Skip to content

Commit

Permalink
Test that only paths for which a key is present are indeed signed
Browse files Browse the repository at this point in the history
  • Loading branch information
bigspider committed Nov 19, 2024
1 parent 633ccef commit 1f8e204
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/test_sign_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,3 +987,44 @@ def test_sign_psbt_multiple_derivation_paths(navigator: Navigator, firmware: Fir
testname=test_name)

assert len(result) == 2


def test_sign_psbt_multiple_derivation_paths(navigator: Navigator, firmware: Firmware, client: RaggerClient, test_name: str):
# A previous implementation of the app incompletely checked the derivation paths of keys in certain
# transactions when multiple internal in the policy; that wasn't detected in other tests, so this
# was added in order to avoid regressions.
wallet = WalletPolicy(
name="Cold storage",
descriptor_template="wsh(or_d(multi(4,@0/<0;1>/*,@1/<0;1>/*,@2/<0;1>/*,@3/<0;1>/*),and_v(v:thresh(3,pkh(@0/<2;3>/*),a:pkh(@1/<2;3>/*),a:pkh(@2/<2;3>/*),a:pkh(@3/<2;3>/*)),older(65535))))",
keys_info=["[f5acc2fd/48'/1'/0'/2']tpubDFAqEGNyad35aBCKUAXbQGDjdVhNueno5ZZVEn3sQbW5ci457gLR7HyTmHBg93oourBssgUxuWz1jX5uhc1qaqFo9VsybY1J5FuedLfm4dK", 'tpubDE7NQymr4AFtewpAsWtnreyq9ghkzQBXpCZjWLFVRAvnbf7vya2eMTvT2fPapNqL8SuVvLQdbUbMfWLVDCZKnsEBqp6UK93QEzL8Ck23AwF',
'tpubDF4kujkh5dAhC1pFgBToZybXdvJFXXGX4BWdDxWqP7EUpG8gxkfMQeDjGPDnTr9e4NrkFmDM1ocav3Jz6x79CRZbxGr9dzFokJLuvDDnyRh', 'tpubDD3ULTdBbyuMMMs8BCsJKgZgEnZjjbsbtV6ig3xtkQnaSc1gu9kNhmDDEW49HoLzDNA4y2TMqRzj4BugrrtcpXkjoHSoMVhJwfZLUFmv6yn']
)
wallet_hmac = bytes.fromhex(
"8a0e67be3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gAMAAAA2IAAAIgIDJ1HzCxSlPAsnEPz/7BEzGQp/cDWxHrGzIyfoq3QCelIc9azC/TAAAIABAACAAAAAgAIAAIABAAAANiAAAAA="
psbt = PSBT()
psbt.deserialize(psbt_b64)

assert len(psbt.inputs) == 1

result = client.sign_psbt(psbt, wallet, wallet_hmac, navigator,
instructions=sign_psbt_instruction_approve(
firmware, has_spend_from_wallet=True, save_screenshot=False),
testname=test_name)

assert len(result) == 2

# Removing all the PSBT_IN_BIP32_DERIVATION fields for that don't end in /<0;1>/*, the app should
# no longer sign for those keys (therefore we only expect one signature)
for input in psbt.inputs:
for pk, key_orig in list(input.hd_keypaths.items()):
if key_orig.path[-2] not in [0, 1]:
del input.hd_keypaths[pk]

result = client.sign_psbt(psbt, wallet, wallet_hmac, navigator,
instructions=sign_psbt_instruction_approve(
firmware, has_spend_from_wallet=True, save_screenshot=False),
testname=test_name)

assert len(result) == 1

0 comments on commit 1f8e204

Please sign in to comment.