• 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

    Check-stat-file-present

    Ensure that the wallet state file exists.

    Signature
    (check-stat-file-present state) → (mv error? state)
    Returns
    error? — Type (maybe-command-error-p error?).

    Except for the initialization commands, the other wallet commands need to first read the wallet state from the file. Those commands call this function for that purpose.

    This function returns nil as first result if the file exists (i.e. no error); otherwise, it returns an error indicating the absence of the file. A different error is returned if the ACL2 function to test whether the file exists fails (that is, the file's existence cannot be tested); this should be a rare event.

    If the file exists, we also check that it is a regular file.

    Definitions and Theorems

    Function: check-stat-file-present

    (defun check-stat-file-present (state)
           (declare (xargs :stobjs (state)))
           (declare (xargs :guard t))
           (b* (((mv errmsg? file-existsp state)
                 (path-exists-p *stat-filepath*))
                ((when errmsg?)
                 (mv (command-error-state-file-untestable)
                     state))
                ((unless file-existsp)
                 (mv (command-error-state-file-absent)
                     state))
                ((mv err kind state)
                 (file-kind *stat-filepath*
                            :follow-symlinks t))
                ((when (or err (not (eq kind :regular-file))))
                 (mv (command-error-state-file-not-regular)
                     state)))
               (mv nil state)))

    Theorem: maybe-command-error-p-of-check-stat-file-present.error?

    (defthm maybe-command-error-p-of-check-stat-file-present.error?
            (b* (((mv ?error? acl2::?state)
                  (check-stat-file-present state)))
                (maybe-command-error-p error?))
            :rule-classes :rewrite)