• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • ACL2
    • Macro-libraries
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
        • Bv
        • Imp-language
        • Event-macros
        • Java
        • Bitcoin
          • Bip32
          • Bech32
          • Bip39
            • *bip39-english-words*
            • Bip39-mnemonic-to-seed
            • Bip39-entropy-to-word-indexes
            • Bip39-entropy
            • Bip39-word-indexes-to-words
            • Bip39-words-to-mnemonic
              • Bip39-entropy-to-seed
              • Bip39-entropy-to-mnemonic
              • Bip39-english-words-bound-p
              • Bip39-entropy-size-p
            • Bip44
            • Base58
            • Bip43
            • Bytes
            • Base58check
            • Cryptography
            • Bip-350
            • Bip-173
          • Ethereum
          • Yul
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Bip39

    Bip39-words-to-mnemonic

    Turn a list of mnemonic words into a single string, i.e. the mnemonic.

    Signature
    (bip39-words-to-mnemonic words) → mnemonic
    Arguments
    words — Guard (string-listp words).
    Returns
    mnemonic — Type (stringp mnemonic).

    If the words come from the English wordlist (as they do), whose maximum word length is 8, then we can calculate an upper bound on the length of the mnemonic that is a function of the number of words. Given that one extra character (the space) is added after each word (except the last one), the upper bound is 9 multiplied by the number of words. Since there is no ending space, a tighter bound is one unit smaller, but that holds only if there is at least one word (if there is no word, the total length is 0). So it's just simpler to use the slightly looser, but simpler, bound.

    Definitions and Theorems

    Function: bip39-words-to-mnemonic

    (defun bip39-words-to-mnemonic (words)
      (declare (xargs :guard (string-listp words)))
      (str::join (str::string-list-fix words)
                 " "))

    Theorem: stringp-of-bip39-words-to-mnemonic

    (defthm stringp-of-bip39-words-to-mnemonic
      (b* ((mnemonic (bip39-words-to-mnemonic words)))
        (stringp mnemonic))
      :rule-classes :rewrite)

    Theorem: bip39-words-to-mnemonic-upper-bound

    (defthm bip39-words-to-mnemonic-upper-bound
      (implies (bip39-english-words-bound-p words)
               (<= (length (bip39-words-to-mnemonic words))
                   (* 9 (len words))))
      :rule-classes :linear)

    Theorem: bip39-words-to-mnemonic-of-string-list-fix-words

    (defthm bip39-words-to-mnemonic-of-string-list-fix-words
      (equal (bip39-words-to-mnemonic (str::string-list-fix words))
             (bip39-words-to-mnemonic words)))

    Theorem: bip39-words-to-mnemonic-string-list-equiv-congruence-on-words

    (defthm
          bip39-words-to-mnemonic-string-list-equiv-congruence-on-words
      (implies (str::string-list-equiv words words-equiv)
               (equal (bip39-words-to-mnemonic words)
                      (bip39-words-to-mnemonic words-equiv)))
      :rule-classes :congruence)