• 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

    Valid-key-path-p

    Check if a key path is valid for the wallet.

    Signature
    (valid-key-path-p path addresses) → yes/no
    Arguments
    path — Guard (ubyte32-listp path).
    addresses — Guard (natp addresses).
    Returns
    yes/no — Type (booleanp yes/no).

    All the key paths in the wallet must have the form

    m / 44' / 60' / 0' / 0 / address_index

    where address_index is less than the addresses state component, or they may be prefixes of that; BIP 32 key trees are always required to be closed under prefixes.

    This predicate checks if a path has one of these forms.

    Definitions and Theorems

    Function: valid-key-path-p

    (defun valid-key-path-p (path addresses)
           (declare (xargs :guard (and (ubyte32-listp path)
                                       (natp addresses))))
           (b* (((when (atom path)) t)
                ((unless (= (car path) *purpose-index*))
                 nil)
                (path (cdr path))
                ((when (atom path)) t)
                ((unless (= (car path) *coin-type-index*))
                 nil)
                (path (cdr path))
                ((when (atom path)) t)
                ((unless (= (car path) *account-index*))
                 nil)
                (path (cdr path))
                ((when (atom path)) t)
                ((unless (= (car path) *external-chain-index*))
                 nil)
                (path (cdr path))
                ((when (atom path)) t)
                ((unless (< (car path) addresses)) nil)
                (path (cdr path)))
               (atom path)))

    Theorem: booleanp-of-valid-key-path-p

    (defthm booleanp-of-valid-key-path-p
            (b* ((yes/no (valid-key-path-p path addresses)))
                (booleanp yes/no))
            :rule-classes :rewrite)

    Theorem: valid-key-path-p-of-next-key-path-under-1+-addresses

    (defthm valid-key-path-p-of-next-key-path-under-1+-addresses
            (valid-key-path-p (rcons addresses *key-path-prefix*)
                              (1+ addresses)))

    Theorem: valid-key-path-p-of-1+-addresses

    (defthm valid-key-path-p-of-1+-addresses
            (implies (valid-key-path-p path addresses)
                     (valid-key-path-p path (1+ addresses))))