• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
          • Command-error
          • Sign
          • Init-from-mnemonic
          • Command-error-message
          • Stat
          • Next-key
          • Init-from-entropy
          • Process-command
          • Transaction-message
          • Maybe-command-error
          • Maybe-stat
          • Check-stat-file-present
          • Valid-key-path-p
          • String-to-byte-list
          • Load-stat
          • Mnemonic-message
          • All-valid-key-paths-p
          • Process-sign
          • Process-init-from-entropy
          • String-to-word
            • String-to-nat
            • Process-next-key
            • Wallet
            • Process-init-from-mnemonic
            • Check-stat-file-absent
            • Stat-wfp
            • Save-stat
            • Stat-addresses-bounded-p
            • Stat-all-valid-key-paths-p
            • Stat-priv-keys-p
            • Stat-root-depth-zero-p
            • Stat-path-prefix-in-tree-p
            • Crypto-hdwallet-executable
            • *stat-filepath*
            • *key-path-prefix*
            • *coin-type-index*
            • *purpose-index*
            • *external-chain-index*
            • *command-name-init-from-mnemonic*
            • *command-name-init-from-entropy*
            • *account-index*
            • *command-name-sign*
            • *command-name-next-key*
          • Error-checking
          • Apt
          • Abnf
          • Fty-extensions
          • Isar
          • Kestrel-utilities
          • Prime-field-constraint-systems
          • Soft
          • Bv
          • Imp-language
          • Event-macros
          • Bitcoin
          • Ethereum
          • Yul
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Java
          • C
          • Syntheto
          • Number-theory
          • Cryptography
          • Lists-light
          • File-io-light
          • Json
          • Built-ins
          • Solidity
          • Axe
          • Std-extensions
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Execloader
        • Axe
      • Testing-utilities
      • Math
    • Crypto-hdwallet

    String-to-word

    Parse a string into a word.

    Signature
    (string-to-word string) → (mv error? word)
    Arguments
    string — Guard (stringp string).
    Returns
    error? — Type (booleanp error?).
    word — Type (wordp word).

    Certain wallet commands take words (in the Ethereum sense) as inputs, which are supplied by the wallet's user as strings. These must be non-empty sequences of decimal digits, which are turned into their big-endian value. If the string cannot be converted to a word, the error result is t.

    Definitions and Theorems

    Function: string-to-word

    (defun string-to-word (string)
           (declare (xargs :guard (stringp string)))
           (b* (((mv error? val) (string-to-nat string))
                ((when error?) (mv error? 0))
                ((unless (wordp val)) (mv t 0)))
               (mv nil val)))

    Theorem: booleanp-of-string-to-word.error?

    (defthm booleanp-of-string-to-word.error?
            (b* (((mv ?error? ?word)
                  (string-to-word string)))
                (booleanp error?))
            :rule-classes :rewrite)

    Theorem: wordp-of-string-to-word.word

    (defthm wordp-of-string-to-word.word
            (b* (((mv ?error? ?word)
                  (string-to-word string)))
                (wordp word))
            :rule-classes :rewrite)