tevador/polyseed

Valid seed can theoretically decode incorrectly

j-berman opened this issue · 2 comments

Similar to monero-project/monero#9089, because there are duplicate words across language dictionaries, it is theoretically possible for a generated seed to decode incorrectly.

Example

Consider the following Spanish seed: imponer sorteo usuario cabina venus nobleza olivo clima contar barro marco autor producto vaca torneo fatiga

If you trim each word to the prefix length: impo sort usua cabi venu nobl oliv clim cont barr marc auto prod vaca torn fati

It should still validly decode as a Spanish seed, but it decodes as English and then fails the polycode check.

Note: there are also duplicate full words across languages (e.g. science and puzzle are both English and French), which means it's theoretically possible to generate a valid seed that decodes in the wrong language without trimming the words.

Potential solution

As proposed for classic seeds in monero-project/monero#9089, require specifying the language alongside the seed, rather than search for the seed lang.

Note: technically I believe it should be theoretically possible to generate a valid seed in one language that when trimmed is also a valid seed in another. This means including logic that checks if the seed is valid inside the language search technically wouldn't be a valid solution.

The lib could also expose a lang_search function that can plausibly return multiple languages for a single seed, which enables wallets to abstract the UX of specifying the language to the rare edge case it is as @kayabaNerve proposed:

Wallets can also try to abstract it, by decoding with all languages, and only asking the user if/when multiple valid options show up ("Is this seed Spanish or Italian?").

@j-berman can you please review #12?