What is the cheapest way to store a list of 1024 words for a mnemonic generator, and why?

These ideas had a gas cost of 165720 GAS for a string array, and 42300 GAS for storing all the words in a byte array, 6 byte per word.

contract mnemonicgenerator {

bytes public listBytes;

string[] public listString;

function storeString() {

function storeBytes() {
    bytes memory toBytes = new bytes(6*5);
    assembly {
      mstore(add(toBytes, 32), "about")
      mstore(add(toBytes, 38), "above")
      mstore(add(toBytes, 44), "abroad")
      mstore(add(toBytes, 50), "accept")
      mstore(add(toBytes, 56), "access")
    listBytes = toBytes;

and a bytes6 array costs 104258 GAS

bytes6[] public listBytes6;

function storeBytes() {
  • 1
    check out this answer ethereum.stackexchange.com/questions/47254/… – Badr Bellaj Jul 21 '18 at 11:52
  • the idea is that the mnemonic generator should be readable on-state, by other contracts – nim Jul 21 '18 at 11:58
  • A Trie is an efficent way of storing a dictionary of words: en.wikipedia.org/wiki/Trie – Shawn Tabrizi Jul 21 '18 at 22:37
  • @ShawnTabrizi feel free to write an answer – nim Jul 22 '18 at 9:36
  • What is the use of the word list? Do you want to validate a mnemonic? Since the word list does not change, I'd store them as constant in the contract if that is possible, the compiler can optimize them to minimize costs. – Ismael Jul 24 '18 at 2:10

Your Answer

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

Browse other questions tagged or ask your own question.