Check if a byte array is an RLP encoding of a byte array.
This is analogous to rlp-tree-encoding-p.
The encoding of a byte array is also the encoding of the tree consisting of a single leaf with that byte array. The encoding of a leaf tree is also the encoding of the byte array in the tree.
By definition, the witness function is right inverse of the encoding function, over the valid encodings.
Theorem:
(defthm rlp-bytes-encoding-p-suff (implies (and (byte-listp bytes) (b* (((mv error? encoding1) (rlp-encode-bytes bytes))) (and (not error?) (equal encoding1 (byte-list-fix encoding))))) (rlp-bytes-encoding-p encoding)))
Theorem:
(defthm booleanp-of-rlp-bytes-encoding-p (b* ((yes/no (rlp-bytes-encoding-p encoding))) (booleanp yes/no)) :rule-classes :rewrite)
Theorem:
(defthm rlp-bytes-encoding-p-of-byte-list-fix-encoding (equal (rlp-bytes-encoding-p (byte-list-fix encoding)) (rlp-bytes-encoding-p encoding)))
Theorem:
(defthm rlp-bytes-encoding-p-byte-list-equiv-congruence-on-encoding (implies (byte-list-equiv encoding encoding-equiv) (equal (rlp-bytes-encoding-p encoding) (rlp-bytes-encoding-p encoding-equiv))) :rule-classes :congruence)
Theorem:
(defthm byte-listp-of-rlp-bytes-encoding-witness (implies (rlp-bytes-encoding-p encoding) (byte-listp (rlp-bytes-encoding-witness encoding))))
Theorem:
(defthm rlp-encode-bytes-of-rlp-bytes-encoding-witness (implies (rlp-bytes-encoding-p encoding) (b* (((mv error? encoding1) (rlp-encode-bytes (rlp-bytes-encoding-witness encoding)))) (and (not error?) (equal encoding1 (byte-list-fix encoding))))))
Theorem:
(defthm rlp-bytes-encoding-p-of-rlp-bytes-encode-when-no-error (implies (not (mv-nth 0 (rlp-encode-bytes bytes))) (rlp-bytes-encoding-p (mv-nth 1 (rlp-encode-bytes bytes)))))
Theorem:
(defthm rlp-tree-encoding-p-when-rlp-bytes-encoding-p (implies (rlp-bytes-encoding-p encoding) (rlp-tree-encoding-p encoding)))
Theorem:
(defthm rlp-bytes-encoding-p-when-rlp-tree-encoding-p-and-leaf (implies (and (rlp-tree-encoding-p encoding) (rlp-tree-case (rlp-tree-encoding-witness encoding) :leaf)) (rlp-bytes-encoding-p encoding)))