• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
        • Bv
        • Imp-language
        • Event-macros
        • Java
        • Bitcoin
        • Ethereum
        • Yul
          • Transformations
          • Language
            • Abstract-syntax
            • Dynamic-semantics
            • Concrete-syntax
            • Static-soundness
            • Static-semantics
              • Static-safety-checking
              • Static-shadowing-checking
              • Mode-set-result
              • Literal-evaluation
                • Eval-literal
                • Eval-hex-string-literal
                  • Eval-plain-string-literal
                  • Ubyte16-to-utf8
                  • Eval-escape
                  • Eval-string-element
                  • Eval-hex-string-rest-element-list
                  • Eval-hex-string-rest-element
                  • Eval-hex-string-content
                  • Eval-string-element-list
                  • Eval-hex-quad
                  • Eval-hex-pair
                • Static-identifier-checking
                • Static-safety-checking-evm
                • Mode-set
                • Modes
              • Errors
            • Yul-json
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Literal-evaluation

    Eval-hex-string-literal

    Evaluate a hex string literal to a value.

    Signature
    (eval-hex-string-literal hstring) → val
    Arguments
    hstring — Guard (hex-stringp hstring).
    Returns
    val — Type (value-resultp val).

    We convert the hex pairs to a list of bytes, empty if the hex string is empty. If the resulting bytes exceed 32 in number, it is an error. Otherwise, we pad the list with zeros (bytes of value 0) on the right to reach 32 bytes, and we turn the resulting list of 32 bytes to a 256-bit word, interpreting the bytes in big endian form, i.e. the first byte contains the most significant bits of the word. This evaluation is not described in detail in [Yul], but it was explained via discussions on Gitter, and [Yul] is being extended with these explanations.

    Definitions and Theorems

    Function: eval-hex-string-literal

    (defun eval-hex-string-literal (hstring)
     (declare (xargs :guard (hex-stringp hstring)))
     (let ((__function__ 'eval-hex-string-literal))
       (declare (ignorable __function__))
       (b*
        (((hex-string hstring) hstring)
         (bytes (hex-string-content-option-case
                     hstring.content
                     :some (eval-hex-string-content hstring.content.val)
                     :none nil))
         ((unless (<= (len bytes) 32))
          (reserrf (list :hex-string-too-long bytes)))
         (bytes (append bytes (repeat (- 32 (len bytes)) 0))))
        (value (bebytes=>nat bytes)))))

    Theorem: value-resultp-of-eval-hex-string-literal

    (defthm value-resultp-of-eval-hex-string-literal
      (b* ((val (eval-hex-string-literal hstring)))
        (value-resultp val))
      :rule-classes :rewrite)

    Theorem: error-info-wfp-of-eval-hex-string-literal

    (defthm error-info-wfp-of-eval-hex-string-literal
      (b* ((?val (eval-hex-string-literal hstring)))
        (implies (reserrp val)
                 (error-info-wfp val))))

    Theorem: eval-hex-string-literal-of-hex-string-fix-hstring

    (defthm eval-hex-string-literal-of-hex-string-fix-hstring
      (equal (eval-hex-string-literal (hex-string-fix hstring))
             (eval-hex-string-literal hstring)))

    Theorem: eval-hex-string-literal-hex-string-equiv-congruence-on-hstring

    (defthm
         eval-hex-string-literal-hex-string-equiv-congruence-on-hstring
      (implies (hex-string-equiv hstring hstring-equiv)
               (equal (eval-hex-string-literal hstring)
                      (eval-hex-string-literal hstring-equiv)))
      :rule-classes :congruence)