Purposes.
[BIP43] recommends to index of the first level of a BIP 32 key tree as an indication of ``purpose''. We introduce a fixtype for the possible values of this index.
[BIP43] uses an apostrophe to indicate that
the purpose key should be hardened.
Therefore, the purpose number should be below
[BIP43] also states that number 0 is already taken by BIP 32 to indicate a default account. Thus, it seems reasonable to exclude 0 from the set of acceptable purpose numbers.
Function:
(defun bip43-purposep (x) (declare (xargs :guard t)) (integer-range-p 1 (expt 2 31) x))
Theorem:
(defthm booleanp-of-bip43-purposep (b* ((yes/no (bip43-purposep x))) (booleanp yes/no)) :rule-classes :rewrite)
Function:
(defun bip43-purpose-fix (x) (declare (xargs :guard (bip43-purposep x))) (mbe :logic (if (bip43-purposep x) x 1) :exec x))
Theorem:
(defthm bip43-purposep-of-bip43-purpose-fix (b* ((fixed-x (bip43-purpose-fix x))) (bip43-purposep fixed-x)) :rule-classes :rewrite)
Theorem:
(defthm bip43-purpose-fix-when-bip43-purposep (implies (bip43-purposep x) (equal (bip43-purpose-fix x) x)))
Function:
(defun bip43-purpose-equiv$inline (acl2::x acl2::y) (declare (xargs :guard (and (bip43-purposep acl2::x) (bip43-purposep acl2::y)))) (equal (bip43-purpose-fix acl2::x) (bip43-purpose-fix acl2::y)))
Theorem:
(defthm bip43-purpose-equiv-is-an-equivalence (and (booleanp (bip43-purpose-equiv x y)) (bip43-purpose-equiv x x) (implies (bip43-purpose-equiv x y) (bip43-purpose-equiv y x)) (implies (and (bip43-purpose-equiv x y) (bip43-purpose-equiv y z)) (bip43-purpose-equiv x z))) :rule-classes (:equivalence))
Theorem:
(defthm bip43-purpose-equiv-implies-equal-bip43-purpose-fix-1 (implies (bip43-purpose-equiv acl2::x x-equiv) (equal (bip43-purpose-fix acl2::x) (bip43-purpose-fix x-equiv))) :rule-classes (:congruence))
Theorem:
(defthm bip43-purpose-fix-under-bip43-purpose-equiv (bip43-purpose-equiv (bip43-purpose-fix acl2::x) acl2::x) :rule-classes (:rewrite :rewrite-quoted-constant))
Theorem:
(defthm equal-of-bip43-purpose-fix-1-forward-to-bip43-purpose-equiv (implies (equal (bip43-purpose-fix acl2::x) acl2::y) (bip43-purpose-equiv acl2::x acl2::y)) :rule-classes :forward-chaining)
Theorem:
(defthm equal-of-bip43-purpose-fix-2-forward-to-bip43-purpose-equiv (implies (equal acl2::x (bip43-purpose-fix acl2::y)) (bip43-purpose-equiv acl2::x acl2::y)) :rule-classes :forward-chaining)
Theorem:
(defthm bip43-purpose-equiv-of-bip43-purpose-fix-1-forward (implies (bip43-purpose-equiv (bip43-purpose-fix acl2::x) acl2::y) (bip43-purpose-equiv acl2::x acl2::y)) :rule-classes :forward-chaining)
Theorem:
(defthm bip43-purpose-equiv-of-bip43-purpose-fix-2-forward (implies (bip43-purpose-equiv acl2::x (bip43-purpose-fix acl2::y)) (bip43-purpose-equiv acl2::x acl2::y)) :rule-classes :forward-chaining)