waves_logo Docs
  • Why Waves
    Why Waves
  • Waves Basics
    Waves Basics
  • Account
    • Creating Account
      Creating Account
    • Address
      Address
    • Account Balance
      Account Balance
    • Account Data Storage
      Account Data Storage
    • Alias
      Alias
    • dApp and Smart Account
      dApp and Smart Account
    Account
  • Token (Asset)
    • Non-Fungible Token
      Non-Fungible Token
    • Smart Asset
      Smart Asset
    • Token ID
      Token ID
    • WAVES
      WAVES
    Token (Asset)
  • Transaction
    • Transaction Fee
      • Sponsored Fee
        Sponsored Fee
      Transaction Fee
    • Signature and Proofs
      Signature and Proofs
    • Transaction Types
      • Burn Transaction
        Burn Transaction
      • Create Alias Transaction
        Create Alias Transaction
      • Data Transaction
        Data Transaction
      • Exchange Transaction
        • Order
          Order
        Exchange Transaction
      • Genesis Transaction
        Genesis Transaction
      • Invoke Script Transaction
        Invoke Script Transaction
      • Issue Transaction
        Issue Transaction
      • Lease Cancel Transaction
        Lease Cancel Transaction
      • Lease Transaction
        Lease Transaction
      • Mass Transfer Transaction
        Mass Transfer Transaction
      • Reissue Transaction
        Reissue Transaction
      • Set Asset Script Transaction
        Set Asset Script Transaction
      • Set Script Transaction
        Set Script Transaction
      • Sponsor Fee Transaction
        Sponsor Fee Transaction
      • Transfer Transaction
        Transfer Transaction
      • Update Asset Info Transaction
        Update Asset Info Transaction
      • Ethereum-like Transaction
        Ethereum-like Transaction
      Transaction Types
    • Transaction Validation
      Transaction Validation
    Transaction
  • Block
    • Transactions Root Hash
      Transactions Root Hash
    • Genesis Block
      Genesis Block
    Block
  • Node
    • Leasing
      Leasing
    • Generator’s Income
      Generator’s Income
    • Monetary Policy
      Monetary Policy
    Node
  • Mainnet, Testnet, Stagenet
    Mainnet, Testnet, Stagenet
  • Unit Zero
    Unit Zero
  • Oracle
    Oracle
  • Protocols & Data formats
    • Cryptographic Practical Details
      Cryptographic Practical Details
    • Leased Proof of Stake
      Leased Proof of Stake
    • Waves-NG Solution
      Waves-NG Solution
    • Waves-NG Protocol
      Waves-NG Protocol
    • Waves 1.5
      Waves 1.5
    • Blockchain Data Types
      Blockchain Data Types
    • Binary Format
      • Address Binary Format
        Address Binary Format
      • Alias Binary Format
        Alias Binary Format
      • Block Binary Format
        Block Binary Format
      • Network Message Binary Format
        • Block Message Binary Format
          Block Message Binary Format
        • Checkpoint Message Binary Format
          Checkpoint Message Binary Format
        • Get Block Message Binary Format
          Get Block Message Binary Format
        • Get Peers Message Binary Format
          Get Peers Message Binary Format
        • Get Signatures Message Binary Format
          Get Signatures Message Binary Format
        • Handshake Message Binary Format
          Handshake Message Binary Format
        • Peers Message Binary Format
          Peers Message Binary Format
        • Score Message Binary Format
          Score Message Binary Format
        • Signatures Message Binary Format
          Signatures Message Binary Format
        • Transaction Message Message Binary Format
          Transaction Message Message Binary Format
        Network Message Binary Format
      • Order Binary Format
        Order Binary Format
      • Transaction Binary Format
        • Burn Transaction Binary Format
          Burn Transaction Binary Format
        • Create Alias Transaction Binary Format
          Create Alias Transaction Binary Format
        • Data Transaction Binary Format
          Data Transaction Binary Format
        • Exchange Transaction Binary Format
          Exchange Transaction Binary Format
        • Genesis Transaction Binary Format
          Genesis Transaction Binary Format
        • Invoke Script Transaction Binary Format
          Invoke Script Transaction Binary Format
        • Issue Transaction Binary Format
          Issue Transaction Binary Format
        • Lease Cancel Transaction Binary Format
          Lease Cancel Transaction Binary Format
        • Lease Transaction Binary Format
          Lease Transaction Binary Format
        • Mass Transfer Transaction Binary Format
          Mass Transfer Transaction Binary Format
        • Reissue Transaction Binary Format
          Reissue Transaction Binary Format
        • Set Asset Script Transaction Binary Format
          Set Asset Script Transaction Binary Format
        • Set Script Transaction Binary Format
          Set Script Transaction Binary Format
        • Sponsor Fee Transaction Binary Format
          Sponsor Fee Transaction Binary Format
        • Transfer Transaction Binary Format
          Transfer Transaction Binary Format
        • Update Asset Info Transaction Binary Format
          Update Asset Info Transaction Binary Format
        • Ethereum-like Transaction Binary Format
          Ethereum-like Transaction Binary Format
        Transaction Binary Format
      • Transaction Proof Binary Format
        Transaction Proof Binary Format
      Binary Format
    • Validation Rules
      Validation Rules
    Protocols & Data formats
  • Glossary
    Glossary
      • English
      • Русский
      On this page
        • transactionsRoot Calculation
        • Proof of Transaction in Block
        • Tools
      waves_logo Docs

          # Transactions Root Hash

          The transactionsRoot field in the block header contains the root hash of the Merkle tree of transactions of the block. The root hash is the proof that the block contains all the transactions in the proper order.

          The transactions root hash in the block header has the following purposes:

          • To prove the integrity of transactions in the block without presenting all transactions.
          • To sign the block header only, separately from its transactions.

          ⚠️ transactionsRoot is enabled by feature #15 “Ride V4, VRF, Protobuf, Failed transactions”.

          # transactionsRoot Calculation

          1. The hash of each transaction in the block is calculated. For example:

            HA = hash(TA)

            HB = hash(TB)

            etc.

          2. Each pair of adjacent hashes is concatenated, and the hash is calculated for each resulting concatenation:

            HAB = hash(HA + HB)

            If the last hash does not have a pair, it is concatenated with the zero byte hash:

            HGH = hash(HG + hash(0))

          3. Step 2 is repeated until the root hash is obtained:

            HABCDEFGH

            The root hash is written in the transactionsRoot field.

          If the block is empty, then transactionsRoot = hash(0).

          Waves blockchain uses BLAKE2b-256 hashing function.

          # Proof of Transaction in Block

          Let's suppose that side 1 stores the full blockchain data and side 2 stores the block headers only.

          To prove that the block contains a given transaction, side 1 provides the following data:

          • T: Transaction to check.
          • merkleProofs: Array of sibling hashes of the Merkle tree, bottom-to-top.
          • index: Index of the transaction in the block.

          For example, for the TD transaction:

          • merkleProofs = [ HC, HAB, HEFGH ]
          • index = 3

          Side 2 checks the proof:

          1. It calculates the hash of the transaction being checked (all the transaction data is hashed, including the signature):

            HD = hash(TD)

          2. It concatenates the current hash with the corresponding hash of the merkleProofs array and calculates the hash of concatenation.

            index determines in which order to concatenate the hashes:

            • If the nth bit of index from the end is 0, then the order is: the current hash + the nth hash of the merkleProofsarray (proof hash is on the right). • If the nth bit is 1, the order is: the nth hash of the merkleProofsarray + the current hash (proof hash is on the left).

            For example, index = 310 = 112 , thus:

            • merkleProofs[0] = HC is on the left, • merkleProofs[1] = HAB is on the left, • merkleProofs[2] = HEFGH is on the right.

          3. It repeates Step 2 until the root hash is obtained:

            HABCDEFGH

          4. It compares the root hash obtained with the already known transactionsRoot from the block header. If the hashes match, then the transaction exists in the block.

          # Tools

          The following Node API methods accept transaction IDs and provide the proof that the transaction is in a block for each transaction:

          • GET /transactions/merkleProof
          • POST /transactions/merkleProof

          The methods are described in the Transaction article.

          You can check a transaction on the same blockchain without using a root hash, since the Waves node stores the full blockchain data, including all transactions. Use the following built-in Ride function:

          transactionHeightById(id: ByteVector): Int|Unit
          

          The function returns the block height if the transaction with the specified id exists. Otherwise, it returns unit. See the function description in the Blockchain functions article.

          To check a transaction in a block on the external blockchain you can use the following built-in Ride function:

          createMerkleRoot(merkleProofs: List[ByteVector], valueBytes: ByteVector, index: Int): ByteVector
          

          This function is applicable if the external blockchain uses the same algorithm for calculating the root hash of transactions (for instance, external blockchain is Waves-based). The createMerkleRoot function calculates the root hash from the transaction hash and sibling hashes of the Merkle tree (see Steps 1–3). To check a transaction in a block, compare the calculated root hash with the transactionsRoot value in the block header. See the function description in the Verification functions article.

          Block
          Genesis Block
          Block
          Genesis Block