• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Debugging
    • Projects
    • 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-byte-list

    Parse a string into a list of bytes.

    Signature
    (string-to-byte-list string) → (mv error? bytes)
    Arguments
    string — Guard (stringp string).
    Returns
    error? — Type (booleanp error?).
    bytes — Type (byte-listp bytes).

    Certain wallet commands take byte lists as inputs, which are supplied by the wallet's user as strings. These must be an even-length strings of hexadecimal digits, where the letters may be uppercase or lowercase. Each pair of hexadecimal digits is turned into a byte, with the first digit becoming the most significant nibble of the byte. If the string cannot be converted to a byte list, the error result is t.

    Definitions and Theorems

    Function: string-to-byte-list

    (defun string-to-byte-list (string)
           (declare (xargs :guard (stringp string)))
           (if (and (stringp string)
                    (hex-digit-string-p string)
                    (evenp (length string)))
               (mv nil (hexstring=>ubyte8s string))
               (mv t nil)))

    Theorem: booleanp-of-string-to-byte-list.error?

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

    Theorem: byte-listp-of-string-to-byte-list.bytes

    (defthm byte-listp-of-string-to-byte-list.bytes
            (b* (((mv ?error? ?bytes)
                  (string-to-byte-list string)))
                (byte-listp bytes))
            :rule-classes :rewrite)