Analyzing the seed logic here;

Can someone please explain this expression:

w[0]= w[1] + word_list_length * (((word_list_length - w[1]) + w[2]) % word_list_length) +
word_list_length * word_list_length * (((word_list_length - w[2]) + w[3]) % word_list_length);

Source: https://github.com/monero-project/monero/blob/b60078d1b3b85caca1936f9f22894ced6ee2e88d/src/mnemonics/electrum-words.cpp#L328

Once I understand, I would like to PR a comment for it. Are such PR's welcome?


Each 3 words gets converted to 4 bytes of the secret key.

This particular line is calculating those 4 bytes (the unsigned integer at w[0]) in the loop which is taking 3 words at a time. It's essentially the reverse of the 4 bytes to 3 words in the function bytes_to_words.

  • Oh I understand the concept (the "what"), but I'm looking for guidance on the logic (the "how"). (I am open to draw it out and understand it by analyzing, but tackling all such snippets in this manner adds up quickly and is highly inefficient for diving into the project.) – hokkjoy Nov 14 '18 at 23:13
  • But the line is a simple expression using the indexes of the three words in the word list. Apologies, but I'm not sure what the confusion is with this. – jtgrassie Nov 15 '18 at 3:47
  • For example, what does (((word_list_length - w[1]) + w[2]) % word_list_length) represent? If you'd assign it to a variable with meaningful name, what would that name be? Why do we subtract the first word's index from the total of indexes, then add the second word's index (and then run modulo on it)? – hokkjoy Dec 7 '18 at 19:54
  • It's not important to assign to "meaningful name". What is important is that the math is reversible (i.e. you can take a set of words to produce a key and given a key produce the same words) and deterministic (the same set of words always produces the same key and vice versa). There is no need for a PR to change variable names for such simple to understand expressions / math. – jtgrassie Dec 8 '18 at 21:35
  • I wrote my initial question "just to save time". Since then I went through the calculation manually with several example values in order to find a pattern. Result: I am still unable to extract the original reasoning behind the math and why it was chosen exactly the way it was. Your comment makes me think that I am lacking mental capacity, which may be true. So I'll just shut up until it develops. – hokkjoy Dec 10 '18 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.