• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • Vwsim
      • Isar
      • Wp-gen
      • Dimacs-reader
      • Pfcs
      • Legacy-defrstobj
      • Proof-checker-array
      • Soft
      • C
      • Farray
      • Rp-rewriter
      • Instant-runoff-voting
      • Imp-language
      • Sidekick
      • Leftist-trees
      • Java
      • Taspi
      • Bitcoin
      • Riscv
      • Des
      • Ethereum
        • Mmp-trees
        • Semaphore
        • Database
        • Cryptography
        • Rlp
        • Transactions
          • Make-signed-transaction
          • Transaction
          • Maybe-byte-list20
          • Rlp-decode-transaction
          • Rlp-encode-transaction
            • Rlp-transaction-encoding-p
          • Hex-prefix
          • Basics
          • Addresses
        • X86isa
        • Sha-2
        • Yul
        • Zcash
        • Proof-checker-itp13
        • Regex
        • ACL2-programming-language
        • Json
        • Jfkr
        • Equational
        • Cryptography
        • Poseidon
        • Where-do-i-place-my-book
        • Axe
        • Bigmems
        • Builtins
        • Execloader
        • Aleo
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Transactions

    Rlp-encode-transaction

    RLP encoding of a transaction.

    Signature
    (rlp-encode-transaction trans) → (mv error? encoding)
    Arguments
    trans — Guard (transactionp trans).
    Returns
    error? — Type (booleanp error?).
    encoding — Type (byte-listp encoding).

    The first step towards RLP-encoding a transaction is to turn it into an RLP tree. This is implied by [YP:4.2], which in fact uses a tuple notation for transactions.

    Each scalar component is turned into its big-endian byte array representation, consistently with rlp-encode-scalar. Note that here we are just constructing the RLP tree, not encoding it yet; RLP trees cannot contain scalars. The other components are byte arrays that are left unchanged.

    We put all nine components under a branching tree, which we RLP-encode. Encoding may fail, if the \mathbf{v} signature component is unreasonably large, or if the initialization or data array is unreasonably long.

    Definitions and Theorems

    Function: rlp-encode-transaction

    (defun rlp-encode-transaction (trans)
     (declare (xargs :guard (transactionp trans)))
     (b*
      (((transaction trans) trans)
       (tree (rlp-tree-branch
                  (list (rlp-tree-leaf (nat=>bebytes* trans.nonce))
                        (rlp-tree-leaf (nat=>bebytes* trans.gas-price))
                        (rlp-tree-leaf (nat=>bebytes* trans.gas-limit))
                        (rlp-tree-leaf trans.to)
                        (rlp-tree-leaf (nat=>bebytes* trans.value))
                        (rlp-tree-leaf trans.init/data)
                        (rlp-tree-leaf (nat=>bebytes* trans.sign-v))
                        (rlp-tree-leaf (nat=>bebytes* trans.sign-r))
                        (rlp-tree-leaf (nat=>bebytes* trans.sign-s))))))
      (rlp-encode-tree tree)))

    Theorem: booleanp-of-rlp-encode-transaction.error?

    (defthm booleanp-of-rlp-encode-transaction.error?
      (b* (((mv ?error? ?encoding)
            (rlp-encode-transaction trans)))
        (booleanp error?))
      :rule-classes :rewrite)

    Theorem: byte-listp-of-rlp-encode-transaction.encoding

    (defthm byte-listp-of-rlp-encode-transaction.encoding
      (b* (((mv ?error? ?encoding)
            (rlp-encode-transaction trans)))
        (byte-listp encoding))
      :rule-classes :rewrite)

    Theorem: rlp-encode-transaction-of-transaction-fix-trans

    (defthm rlp-encode-transaction-of-transaction-fix-trans
      (equal (rlp-encode-transaction (transaction-fix trans))
             (rlp-encode-transaction trans)))

    Theorem: rlp-encode-transaction-transaction-equiv-congruence-on-trans

    (defthm rlp-encode-transaction-transaction-equiv-congruence-on-trans
      (implies (transaction-equiv trans trans-equiv)
               (equal (rlp-encode-transaction trans)
                      (rlp-encode-transaction trans-equiv)))
      :rule-classes :congruence)