feat(test): add upgrade test for app storage version 3
What changed, and why it matters
This commit only adds a new automated test to the Trezor firmware test suite. It checks that Cardano public keys and addresses stay the same before and after a firmware upgrade that migrates internal app storage from version 2 to the current version. There is no change to the actual firmware code, wallet logic, or security behavior.
No action required. This is a regression/upgrade test addition and does not alter firmware behavior. Reviewers may optionally verify the test covers the intended storage migration path.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds test_cardano_address_does_not_change_by_upgrade in tests/upgrade_tests/test_firmware_upgrades.py. The test initializes an emulator on an older firmware tag, sets up a BIP-39 or SLIP-39 wallet, derives a Cardano public key at m/44h/1815h/0h for both ICARUS and ICARUS_TREZOR derivation types, captures the emulator storage, then runs the current firmware with that storage and re-derives the key. It asserts that xpub, public key, and chain code remain identical across the upgrade. A skip is added for firmware v2.1.2 with SLIP-39 because Cardano did not support SLIP-39 then. No production code is modified.
Changed components
tests/upgrade_tests/test_firmware_upgrades.pyInspect captured patch +53 / −1
diff --git a/tests/upgrade_tests/test_firmware_upgrades.py b/tests/upgrade_tests/test_firmware_upgrades.py
index 40800844..ce55902b 100644
--- a/tests/upgrade_tests/test_firmware_upgrades.py
+++ b/tests/upgrade_tests/test_firmware_upgrades.py
@@ -22,15 +22,17 @@ import pytest
from shamir_mnemonic import shamir
from trezorlib import btc, debuglink, device, exceptions, fido, messages, models
+from trezorlib.cardano import get_public_key
from trezorlib.client import ProtocolVersion
from trezorlib.messages import (
ApplySettings,
BackupAvailability,
BackupType,
+ CardanoDerivationType,
RecoveryStatus,
Success,
)
-from trezorlib.tools import H_
+from trezorlib.tools import H_, parse_path
from ..click_tests import recovery
from ..common import MNEMONIC_SLIP39_BASIC_20_3of6, MNEMONIC_SLIP39_BASIC_20_3of6_SECRET
@@ -517,6 +519,56 @@ def test_upgrade_u2f(gen: str, tag: str):
assert counter == 12
+@for_all("core")
+@lower_models_minimum_version
+@pytest.mark.parametrize("backup_type", [BackupType.Bip39, BackupType.Slip39_Basic])
+@pytest.mark.parametrize(
+ "derivation_type",
+ [CardanoDerivationType.ICARUS, CardanoDerivationType.ICARUS_TREZOR],
+)
+def test_cardano_address_does_not_change_by_upgrade(
+ gen: str,
+ tag: Optional[str],
+ backup_type: BackupType,
+ derivation_type: CardanoDerivationType,
+):
+ """
+ Check that the Cardano address does not change after upgrading app storage from v2
+ to the current version.
+ """
+ ADDRESS_N = parse_path("m/44h/1815h/0h")
+
+ version_tag = version_from_tag(tag)
+ if (
+ version_tag is not None
+ and version_tag == (2, 1, 2)
+ and backup_type == BackupType.Slip39_Basic
+ ):
+ # SLIP-39 was not implemented for Cardano in v2.1.2
+ return
+
+ with EmulatorWrapper(gen, tag) as emu:
+ device.setup(
+ emu.client.get_seedless_session(),
+ pin_protection=False,
+ passphrase_protection=False,
+ skip_backup=True,
+ backup_type=backup_type,
+ entropy_check_count=0,
+ )
+ session = emu.client.get_session(derive_cardano=True)
+ old_key = get_public_key(session, ADDRESS_N, derivation_type, show_display=True)
+ storage = emu.get_storage()
+
+ with EmulatorWrapper(gen, storage=storage) as emu:
+ session = emu.client.get_session(derive_cardano=True)
+ new_key = get_public_key(session, ADDRESS_N, derivation_type, show_display=True)
+
+ assert old_key.xpub == new_key.xpub
+ assert old_key.node.public_key == new_key.node.public_key
+ assert old_key.node.chain_code == new_key.node.chain_code
+
+
if __name__ == "__main__":
if not ALL_TAGS:
print("No versions found. Remember to run download_emulators.sh")
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.