|
10 | 10 | from codex32.checksums import _CRC, _crc_pad |
11 | 11 | from codex32.correction import _best |
12 | 12 | from codex32.gf32 import _multiply as _gf32_multiply |
13 | | -from codex32.profiles.ms32 import ( |
14 | | - SEED_BYTE_LENGTHS, |
15 | | - _has_generation_padding, |
16 | | - _has_legacy_generation_padding, |
17 | | - _payload_padding, |
18 | | -) |
| 13 | +from codex32.profiles.ms32 import SEED_BYTE_LENGTHS, _has_generation_padding, _payload_padding |
19 | 14 |
|
20 | 15 |
|
21 | 16 | @pytest.mark.parametrize( |
@@ -65,19 +60,24 @@ def test_parsed_master_seed_validity_is_independent_of_crc() -> None: |
65 | 60 | assert generated.payload_symbols in {secret.payload_symbols for secret in parsed} |
66 | 61 |
|
67 | 62 |
|
68 | | -def test_tie_break_prefers_current_then_legacy_crc_padding() -> None: |
| 63 | +def test_tie_break_prefers_only_current_crc_padding() -> None: |
69 | 64 | parsed = [parse_codex32(VECTOR_4[f"secret_s_alternate_{padding}"]) for padding in range(16)] |
70 | 65 | assert all(isinstance(secret, MasterSeed) for secret in parsed) |
71 | 66 | current = next(secret for secret in parsed if _has_generation_padding(secret)) |
72 | | - legacy = next(secret for secret in parsed if _has_legacy_generation_padding(secret)) |
73 | | - other = next(secret for secret in parsed if secret not in (current, legacy)) |
74 | | - |
75 | | - def best(*secrets: MasterSeed) -> tuple[MasterSeed, ...]: |
76 | | - candidates = [CorrectionCandidate(s, (), 1, 0, 0, _has_generation_padding(s)) for s in secrets] |
77 | | - return tuple(candidate.artifact for candidate in _best(candidates)) |
78 | | - |
79 | | - assert best(other, legacy, current) == (current,) |
80 | | - assert best(other, legacy) == (legacy,) |
| 67 | + previous = parsed[8] # Pad suffix produced before the final XOR was added. |
| 68 | + other = parsed[0] |
| 69 | + assert current not in (previous, other) |
| 70 | + |
| 71 | + def candidates(*secrets: MasterSeed) -> list[CorrectionCandidate]: |
| 72 | + return [CorrectionCandidate(s, (), 1, 0, 0, _has_generation_padding(s)) for s in secrets] |
| 73 | + |
| 74 | + assert tuple(item.artifact for item in _best(candidates(other, previous, current))) == (current,) |
| 75 | + # Without a current CRC match, neither historical nor arbitrary padding wins. |
| 76 | + tied = tuple(item.artifact for item in _best(candidates(other, previous))) |
| 77 | + assert tied == tuple(sorted((other, previous), key=lambda secret: secret.text.lower())) |
| 78 | + # The wallet hint can decide the tie without being overridden by historical padding. |
| 79 | + hinted = _best(candidates(other, previous), fingerprint_match=lambda item: item.artifact == other) |
| 80 | + assert tuple(item.artifact for item in hinted) == (other,) |
81 | 81 |
|
82 | 82 |
|
83 | 83 | def test_padding_acceptance_is_balanced_for_every_nonzero_lagrange_weight() -> None: |
|
0 commit comments