Merkle path retrieval
Patent Information
- Application Number
- EP2024786011
- Authority / Receiving Office
- EP · EP
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-10-31
- Filing Date
- 2024-10-01
- Publication Date
- 2026-09-09
AI Technical Summary
Existing technologies face challenges in efficiently retrieving and storing Merkle paths for large Merkle trees, which are crucial for blockchain operations, due to the complexity of navigating and indexing the tree structure.
A computer-implemented method is introduced that uses an array representation of a Merkle tree to efficiently retrieve the Merkle path. This method determines the index of each hash in the verification path by calculating the position and index based on the target hash's position within its layer and the initial index of the layer, allowing for iterative extraction of hashes from the array.
The proposed method enables fast and optimized retrieval of Merkle proofs by leveraging the array representation of the Merkle tree, improving storage efficiency and reducing computational complexity, thus enhancing blockchain operations.
Smart Images

Figure EP2024077523_08052025_PF_FP_ABST
Abstract
Description
[0001]MERKLE PATH RETRIEVAL TECHNICAL FIELD The present disclosure relates to an efficient mechanism for retrieving a Merkle path, i.e. extracting, from storage, the required hashes of a Merkle path for performing a Merkle proof for a given target hash of a Merkle tree. BACKGROUND A tree is a connected graph without loops. A tree is rooted if a node of the tree is chosen as the root of the tree. A tree is labelled if each node is labelled by a value. Since trees are connected graphs, they inherit a natural concept of distance between nodes, i.e., the length of the minimal path between them. In a rooted tree, distance can be used to define levels in the tree, the level of a node is its distance from the root. In a rooted tree, the relation between adjacent nodes (nodes at distance 1) is often called parent-child relation. Let ^^^be a node at level and ^^ଶa node at level ^^ଶadjacent to ^^^, ^^^is a child of ^^ଶ(or ^^ଶis the parent of ^^^) if − ^^ଶ= 1. A node without children is called a leaf and the root node has no parent (since the distance cannot be negative), nodes with a parent and at least one child are called branches or inner nodes. A rooted tree where every node has at most two children is called a binary tree, and the two children are called siblings. Let ^^ be a hash function, a Merkle tree is a rooted labelled tree with the following additional properties: • Each leaf is labelled by an output of ^^. • If a node ^^ has a single child, labelled with a value ℎ, the label of ^^ is ^^( ^^(ℎ)), for some function ^^ (in Bitcoin, ^^(ℎ)= ℎ||ℎ, where || denotes the concatenation). • If a node ^^ has two children, labelled with ℎ^^^௧, and ℎ^^^^௧, the label of ^^ is ^^( ^^(ℎ^^^௧, ℎ^^^^௧)), for some function ^^ (in Bitcoin, ^^൫ℎ^^^௧, ℎ^^^^௧൯ = ℎ^^^௧||ℎ^^^^௧). • All leaves in the tree are at the same level. • All leaves are as far left as possible. • The number of levels is minimal. The Merkle proof of a node is a set of hashes that prove the node membership in the tree. The proof consists of the node sibling, and any additional hash that could not be computed without additional information. To prove membership the two siblings are hashed to create a parent hash and then repeatedly combined with each hash in the proof to calculate the root hash. If the computed root hash corresponds to the root label, the proof is correct. Figure 3 illustrates an example Merkle proof for the leaf ^^^. The Merkle path, i.e. the hashes need to perform the Merkle proof) are indicated using thick black boxes. In a Merkle tree with ^^ leaves, the leaves are all at level ⌈logଶ^^⌉. The number of nodes in a Merkle tree depends only on the number of leaves. If at level ^^ (with ^^ > 0) there are ^^^nodes, at level ^^ − 1 there will be nodes. Thus, the number of nodes in a Merkle tree with ^^ leaves is represented in recursive form as: A proof of this formula and an equivalent, non-recursive version can be found in Appendix 1.1. SUMMARY Merkle trees are one of the fundamental data structures of the blockchain. However, as the size of blocks increases, it is important to find optimal ways to store and access them. Merkle trees can be stored efficiently using arrays. This is possible because the number of leaves bounds the number of nodes at each level of the tree. The process of constructing the array representing a tree is called vectorization. Vectorizing a tree means constructing an array that represents the tree and that allows – without any additional information – for the reconstruction of the tree (i.e., which nodes are connected and what are their parent-child relationships). There are multiple techniques to create an array from a tree; however, without additional information, this process is not usually invertible. Merkle trees are among the family of trees that can be vectorized. The array is created as follows. 1. Start with an empty array. 2. Starting with the leftmost leaf and moving right, all leaves are appended to the array. 3. When there are no more leaves to append, move to the upper level and repeat Step 2 for that level. 4. Continue until the root of the tree is appended. The array created in this way has the root as last element of the array, but it is also possible to order the array so that the root is at index 0. The method described in the present disclosure can be adapted to recover the Merkle proof using the vectorized tree can be adapted to this inverse ordering. The present disclosure provides an algorithm that uses this array representation for fast retrieval of the Merkle proof from the index of the transaction in the array. This algorithm allows for optimized storage of Merkle trees and efficient Merkle proof retrieval. According to one aspect disclosed herein, there is provided a computer-implemented method of determining a verification path for a target hash of a hash tree, wherein the hash tree comprises a layer comprising a plurality of leaf hashes, one or more layers each comprising one or more inner hashes, and a layer comprising a root hash, wherein each hash is associated with a respective position within a respective layer of the hash tree, and wherein the hashes of the hash tree, or respective values for deriving said hashes of the hash tree, are stored as an array ordered based on the respective layer of the hash tree and the respective position of the respective hash within the respective layer, wherein each hash or respective value stored in the array is associated with a respective index representing its position within the array, and wherein the method comprises: determining a respective index of a respective next hash of the verification path by determining a respective position of the target hash within the respective layer comprising the target hash, a respective number of hashes within the respective layer comprising the target hash, and a respective index associated with a respective initial hash of the respective layer, wherein the respective index is based on the respective position of the target hash, the respective index associated with the respective initial hash, and the respective number of hashes within the respective layer comprising the target hash; and performing one or more iterations until a respective index of the root hash is determined, wherein each iteration comprises determining a respective index of a respective next hash of the verification path by determining a respective position of a respective parent hash of the respective next hash within the respective layer comprising the respective parent hash, a respective number of hashes within the respective layer comprising the respective parent hash, and a respective index associated with a respective initial hash of the respective layer comprising the respective parent hash, wherein the respective index of the respective next hash is based on the respective position of the respective parent hash and the respective index associated with the respective initial hash, and the respective number of hashes within the respective layer comprising the respective parent hash; and extracting, from the array and using the determined respective indexes, the respective next hashes or respective values for deriving the respective next hashes, of the verification path. Whilst embodiments of the present disclosure are described in terms of the hash tree being a Merkle tree, this is for illustrative purposes only. More generally the embodiments may apply to any type of hash tree, of which a Merkle tree is one example. Further examples of hash trees are described herein. Similarly, embodiments are primarily described in terms of determining a Merkle path. More generally the embodiments may be used to determine a verification path of a hash tree, wherein the verification path (of which a Merkle path is an example) can be used to determine whether a target hash belongs to the hash tree. Note also that whilst some examples are described in terms of the hash tree representing blockchain transactions, this is merely for illustrative purposes and in general the hash tree may represent (i.e. encode) any type of data. Note also that instead of storing the hashes of the hash tree, instead values for deriving those hashes may be stored. That is, each value may be transformed into a respective hash of the hash tree. The transformation may be as simple as removing a digit, applying a mathematical operation (e.g. subtract 1), etc. BRIEF DESCRIPTION OF THE DRAWINGS To assist understanding of embodiments of the present disclosure and to show how such embodiments may be put into effect, reference is made, by way of example only, to the accompanying drawings in which: Figure 1 is a schematic block diagram of a system for implementing a blockchain, Figure 2 schematically illustrates some examples of transactions which may be recorded in a blockchain, and Figure 3 illustrates an example Merkle proof for a leaf hash of a Merkle tree, and Figure 4 illustrates an Merkle tree stored as an array. DETAILED DESCRIPTION OF EMBODIMENTS 1. RETRIEVING A MERKLE PATH Embodiments of the present disclosure enable a party (call the party a “Merkle path retriever”, or simply “retriever”) to retrieve (i.e. determine, obtain, attain, etc.) a Merkle path from storage. The retriever may be a user (e.g. Alice 103a or Bob 103b, a node 104, or a different entity operating any of the example computing equipment described herein). A Merkle tree representing (i.e. encoding) a plurality of data items is stored as an array. The data items may be blockchain transactions, or other data, such as messages / communications, digital tokens, financial transactions, records, etc. A Merkle tree comprises a plurality of leaf hashes, a plurality of inner hashes, and a root hash (also known as a Merkle root). The hashes of the Merkle tree are stored as an array based on the respective position of the hash and the respective layer of the Merkle tree. For instance, the leaf hashes may be stored first (starting with the first leaf hash of the leaf layer), then the hashes of each inner layer (i.e. all hashes of a first inner layer, all hashes of a second inner layer, and so on, again starting with the first hash of the respective inner layer), then the root hash. Each hash stored in the array is associated with a respective index representing the position of the hash in the array. The array may be stored in the retriever’s local internal storage, in external storage, or in cloud storage. Figure 4 illustrates the storage of an example Merkle tree. In this example the Merkle tree comprises three leaf hashes (L1, L2 and L3), a single inner layer comprising two inner hashes (N1 and N2) and a root hash (R). The leaf hashes are stored first in the array starting with the first leaf hash (L1) and ending with the final leaf hash (L3), then the inner hashes starting with the first inner hash (N1) and ending with the final inner hash (N2), then the root hash. The retriever may itself generate the array based on the Merkle tree and store the array, e.g. in memory. Alternatively, the array may be generated by a different party and provided to the retriever. Additional information may be provided, e.g. the number of leaf hashes of the Merkle tree, the total number of hashes in the Merkle tree, or other such information for determining the number of leaf hashes or the total number of hashes in the Merkle tree. At some time after the Merkle tree has been stored as an array, a Merkle path for a hash of the Merkle tree is required. For simplicity the hash for which the Merkle path is required will be referred to as a target hash. The target hash may be a leaf hash or an inner hash. The target hash may be an inner hash of any inner layer. The retriever may be provided with an indication of the target hash (e.g. the target hash itself) and / or the index of the target hash in the array, and / or other information for determining the target hash. Each hash is associated with a respective position and a respective index. The position indicates where the hash is found within a layer of the Merkle tree. The index indicates where the hash if found in the array. The retriever first determines the position of the target hash within the respective layer of the Merkle tree that contains the target hash, and the number of hashes within (i.e. that form) the respective layer of the Merkle tree. The retriever may be provided with this information, or have access to this information. For example, the retriever may be provided with the target hash and look up the corresponding index of the target hash in the array, and use the index, along with a total number of hashes in the array (or a total number of leaf hashes in the Merkle tree), to determine the position of the target hash in its respective layer. The retriever may be required to determine the number of leaf hashes. Any suitable technique (e.g. mathematical relation) may be used to determine the number of leaf hashes. The retriever also determines an index of an initial hash in the respective layer of the Merkle tree that contains the target hash. For instance if the target hash is a leaf hash, the initial hash is the initial (i.e. first) leaf hash of the leaf layer, and the index of the initial leaf hash in the array is 0 (assuming the indexing system starts at 0 – other choices are possible too, e.g. the indexing system may be initialised at 1). The retriever then determines an index of the next hash of the Merkle path, i.e. the first hash of the Merkle path that will be used, together with the target hash, to perform a Merkle proof for the target hash. The index of the next hash is determined based on the position of the target hash in the respective layer of the Merkle tree, and the index of the initial hash in the respective layer of the Merkle tree. The retriever extracts, from the array, the hash located in the array associated with the determined index. Depending on which layer of the Merkle tree the target hash belongs to, and the number of layers in the Merkle tree, the retriever may need to determine one or more additional next hashes of the Merkle path. To determine the next hash, the retriever determines a position, within a respective layer of the Merkle tree, of the parent hash of the previous hash in the Merkle path (i.e. the “next hash” that the retriever has just determined). That is, the previously determined hash in the Merkle path has a parent hash, and the retriever determines the position of that parent hash within the layer of the Merkle tree that contains the parent hash. The retriever also determines the number of hashes in the layer of the Merkle tree containing the parent hash. The retriever also determines an index associated with the initial hash of the layer containing the parent hash. The index of the next hash in the Merkle path is then determined based on the determined position of the parent hash within its layer of the Merkle tree, and the index associated with the initial hash of the that layer. The retriever extracts, from the array, the hash located in the array associated with the determined index. This process is repeated one or more times until the respective index of the root hash is determined, i.e. until the parent hash of the determined next hash of the Merkle path is the root hash. The extracted hashes form the Merkle path. The Merkle path may then be used by the retriever to perform a Merkle proof, or provided to a party for performing a Merkle proof. 1.1 Specific Example of Merkle Proof Retrieval This section describes a specific example of the above described embodiments that recovers the Merkle proof for the node at index ^^ ^^ ^^ in the array corresponding to a Merkle tree with ^^ leaves. The input of this algorithm is ^^ and ^^ ^^ ^^. The first leaf of the tree is at index 0, so it corresponds to ^^ ^^ ^^ = 0. The algorithm works for both leaves and branches of the Merkle tree. 1. Initialization. Two temporary variables ^^ ^^ ^^ ^^ ^^ and ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ are introduced, they are initialized at ^^ and 0, respectively. The variable ^^ ^^ ^^ ^^ ^^ registers the number of nodes at the current level and the variable ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ registers the first index of the current level in the array. The initialization values correspond to the leaf level. 2. Determine the position of the node. If ^^ ^^ ^^ < ^^, then the node is a leaf, and the algorithm continues to Step 3. Otherwise, it is branch. If it is a branch, then its relative position and the number of other nodes at the same level are computed. While ^^ ^^ ^^ ≥ ^^ ^^ ^^ ^^ ^^, the values of ^^ ^^ ^^, ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^, and ^^ ^^ ^^ ^^ ^^ are updated as follows: 3. Find the next hash needed for the Merkle proof. If ^^ ^^ ^^ is odd, then the value needed for the Merkle proof is the value at index ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ + ^^ ^^ ^^ − 1. Otherwise, it is at index ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ + ^^ ^^ ^^ + 1. If the node is the last node in a level (i.e., ^^ ^^ ^^ + 1 = ^^ ^^ ^^ ^^ ^^), then it has no siblings, so the next value in the Merkle proof is at index ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ + ^^ ^^ ^^. 4. Determine the index of the parent of the node. Update the variables, ^^ ^^ ^^ ← , The parent of the current node is at index ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ + ^^ ^^ ^^. 5. Repeat Steps 2-4 until the root is returned. The algorithm ends once ^^ ^^ ^^ ^^ ^^ = 1, which means that the root of the Merkle tree has been reached. A more detailed description of the algorithm in Appendix 1.2, where a Python implementation is discussed. 1.2 Memory and time complexity This section discusses different aspects of the algorithm described above. More specifically, the amount of memory used for storage, the time complexity of retrieving a Merkle proof, and the amount of data nodes have to communicate. Let ^^ be the number of transactions in a block. Assuming only transaction IDs are stored, each transaction occupies 256 bits of storage, so the total storage space required for the vectorized Merkle tree is 32 ^^^bytes (where ^^^is the function that counts the number of nodes in a Merkle tree). Assuming blocks of size 1TB and average transaction size of 4kB, the memory requirement to store the Merkle tree is approximately 16GB. Retrieving a Merkle proof has worst-case time complexity of ^^(log ^^) and best-case time complexity of ^^(1). Knowing the transaction index in the block is enough to retrieve a Merkle proof, and in some cases, the Merkle proof may never be used for SPV. For this reason, nodes may prefer to send only the index of the transaction and send users the full Merkle proof only when it is explicitly requested. 1.3 Storage Since the hash length is a known and fixed value, the processor can efficiently store the array in memory. The Merkle trees of old blocks, whose Merkle proof are not requested often can be stored using cheaper and less efficient (with higher access latency) storage solutions. If data in the Merkle tree will be accessed frequently (which may be the case for recently generated blocks), it may be convenient to make hardware-specific optimization to reduce access latency as much as possible. More specifically, the described algorithm can be modified so that instead of using an array of integers, it uses arrays of Merkle subtrees. A solid-state drive (SSD) is a storage solution that has as smallest storage unit pages that have, usually, a size of 4096 bytes. When reading any subset of a page the entire page is accessed and stored momentarily in cache. If the storage solution is an SSD, its properties can be exploited to reduce access latency by grouping values that appears together in multiple Merkle proofs. A Merkle tree can be split in multiple subtrees of a size that can be stored in a single page. Since a page can store 128 different hashes, the largest Merkle subtree that can be saved in a single page has 64 leaves. This can be further refined by using the remaining free 256 bits in a page to store additional values, for instance, the sibling of the root of the subtree. Thus, the elements at index 0 in the array corresponds to the subtree containing the leaves between position 0 and 63, the one in position 1 to the subtree containing the leaves from 64 to 127, and so on. Once all the leaves are added, the next value in the array follows the same structure and contains the subtree containing nodes in the first level that has not been stored yet. Retrieval of Merkle proofs work similarly to the case of array of integers, with the main difference being that at each index of the array corresponds multiple elements in the Merkle proof. 1.4 Applications to Merkle Path Servers A beneficiary of the invention described in this disclosure are servers interested in storing and communicating transaction information, like the Merkle path servers described in international (PCT) patent application PCT / EP2021 / 078206. The embodiments described herein can be used to improve Merkle proof retrieval performance and storage efficiency of such servers. The Merkle tree can be stored as described in Subsection 1.3, and any additional transaction information (e.g., the transaction ID) can be stored in a database. Storing in the database also the array index of the transaction link the database with the array storing the Merkle tree. Since Merkle proofs can be retrieved efficiently from the array, they do not need to be stored explicitly in the database, this reduces the overall storage requirement. 1.5 Hash Tree Structures A hash tree can take different forms. By way of example, the Ethereum blockchain uses a type of hash tree known as a “Transaction Trie” to store transactions. Because the overall structure of the Ethereum Transaction Trie is or is similar to a Merkle tree, a person skilled in the art would appreciate that the methods described herein can also be applied to said Transaction Tries. Similarly, the methods described herein may apply hash trees of different structures. For instance, each parent hash of the hash tree may have only two children (a so-called “binary hash tree”), or each parent of the hash tree may have n children, where n is greater than two (a so-called “n-ary hash tree”). In some examples, some parent hashes of the hash tree may have a different number of children compared to other parent hashes. The methods provided herein apply to any Merkle tree-like structure. Moreover, with a relationship (explicitly or implicitly obtained) that indicates how the number of nodes at a given level depends on the number of total leaves in the tree, the methods are applicable to said tree. While it is important that there is a bound for the size of the label of a node, it is not necessary for it to be a strict bound, nor that such label is a hash. 2. EXAMPLE SYSTEM OVERVIEW A blockchain refers to a form of distributed data structure, wherein a duplicate copy of the blockchain is maintained at each of a plurality of nodes in a distributed peer-to-peer (P2P) network (referred to below as a “blockchain network”) and widely publicised. The blockchain comprises a chain of blocks of data, wherein each block comprises one or more transactions. Each transaction, other than so-called “coinbase transactions”, points back to a preceding transaction in a sequence which may span one or more blocks going back to one or more coinbase transactions. Coinbase transactions are discussed further below. Transactions that are submitted to the blockchain network are included in new blocks. New blocks are created by a process often referred to as “mining”, which involves each of a plurality of the nodes competing to perform “proof-of-work”, i.e. solving a cryptographic puzzle based on a representation of a defined set of ordered and validated pending transactions waiting to be included in a new block of the blockchain. It should be noted that the blockchain may be pruned at some nodes, and the publication of blocks can be achieved through the publication of mere block headers. The transactions in the blockchain may be used for one or more of the following purposes: to convey a digital asset (i.e. a number of digital tokens), to order a set of entries in a virtualised ledger or registry, to receive and process timestamp entries, and / or to time- order index pointers. A blockchain can also be exploited in order to layer additional functionality on top of the blockchain. For example, blockchain protocols may allow for storage of additional user data or indexes to data in a transaction. There is no pre-specified limit to the maximum data capacity that can be stored within a single transaction, and therefore increasingly more complex data can be incorporated. For instance this may be used to store an electronic document in the blockchain, or audio or video data. In an “output-based” model (sometimes referred to as a UTXO-based model), the data structure of a given transaction comprises one or more inputs and one or more outputs. Any spendable output comprises an element specifying an amount of the digital asset that is derivable from the proceeding sequence of transactions. The spendable output is sometimes referred to as a UTXO (“unspent transaction output”). The output may further comprise a locking script specifying a condition for the future redemption of the output. A locking script is a predicate defining the conditions necessary to validate and transfer digital tokens or assets. Each input of a transaction (other than a coinbase transaction) comprises a pointer (i.e. a reference) to such an output in a preceding transaction, and may further comprise an unlocking script for unlocking the locking script of the pointed-to output. So consider a pair of transactions, call them a first and a second transaction (or “target” transaction). The first transaction comprises at least one output specifying an amount of the digital asset, and comprising a locking script defining one or more conditions of unlocking the output. The second, target transaction comprises at least one input, comprising a pointer to the output of the first transaction, and an unlocking script for unlocking the output of the first transaction. In such a model, when the second, target transaction is sent to the blockchain network to be propagated and recorded in the blockchain, one of the criteria for validity applied at each node will be that the unlocking script meets all of the one or more conditions defined in the locking script of the first transaction. Another will be that the output of the first transaction has not already been redeemed by another, earlier valid transaction. Any node that finds the target transaction invalid according to any of these conditions will not propagate it (as a valid transaction, but possibly to register an invalid transaction) nor include it in a new block to be recorded in the blockchain. An alternative type of transaction model is an account-based model. In this case each transaction does not define the amount to be transferred by referring back to the UTXO of a preceding transaction in a sequence of past transactions, but rather by reference to an absolute account balance. The current state of all accounts is stored by the nodes separate to the blockchain and is updated constantly. Figure 1 shows an example system 100 for implementing a blockchain 150. The system 100 may comprise a packet-switched network 101, typically a wide-area internetwork such as the Internet. The packet-switched network 101 comprises a plurality of blockchain nodes 104 (often referred to as “miners”) that may be arranged to form a peer-to-peer (P2P) network 106 within the packet-switched network 101. Whilst not illustrated, the blockchain nodes 104 may be arranged as a near-complete graph. Each blockchain node 104 is therefore highly connected to other blockchain nodes 104. Each blockchain node 104 comprises computer equipment of a peer, with different ones of the nodes 104 belonging to different peers. Each blockchain node 104 comprises processing apparatus comprising one or more processors, e.g. one or more central processing units (CPUs), accelerator processors, application specific processors and / or field programmable gate arrays (FPGAs), and other equipment such as application specific integrated circuits (ASICs). Each node also comprises memory, i.e. computer-readable storage in the form of a non-transitory computer-readable medium or media. The memory may comprise one or more memory units employing one or more memory media, e.g. a magnetic medium such as a hard disk; an electronic medium such as a solid-state drive (SSD), flash memory or EEPROM; and / or an optical medium such as an optical disk drive. The blockchain 150 comprises a chain of blocks of data 151, wherein a respective copy of the blockchain 150 is maintained at each of a plurality of blockchain nodes 104 in the distributed or blockchain network 106. As mentioned above, maintaining a copy of the blockchain 150 does not necessarily mean storing the blockchain 150 in full. Instead, the blockchain 150 may be pruned of data so long as each blockchain node 150 stores the block header (discussed below) of each block 151. Each block 151 in the chain comprises one or more transactions 152, wherein a transaction in this context refers to a kind of data structure. The nature of the data structure will depend on the type of transaction protocol used as part of a transaction model or scheme. A given blockchain will use one particular transaction protocol throughout. A blockchain node 104 may be configured to forward transactions 152 to other blockchain nodes 104, and thereby cause transactions 152 to be propagated throughout the network 106. A blockchain node 104 may be configured to create blocks 151 and to store a respective copy of the same blockchain 150 in their respective memory. A blockchain node 104 may also maintain an ordered set (or “pool”) 154 of transactions 152 waiting to be incorporated into blocks 151. The ordered pool 154 is often referred to as a “mempool”. This term herein is not intended to limit to any particular blockchain, protocol or model. It refers to the ordered set of transactions which a node 104 has accepted as valid and for which the node 104 is obliged not to accept any other transactions attempting to spend the same output. In a given present transaction 152j, the (or each) input comprises a pointer referencing the output of a preceding transaction 152i in the sequence of transactions, specifying that this output is to be redeemed or “spent” in the present transaction 152j. Spending or redeeming does not necessarily imply transfer of a financial asset, though that is certainly one common application. More generally spending could be described as consuming the output, or assigning it to one or more outputs in another, onward transaction. In general, the preceding transaction could be any transaction in the ordered set 154 or any block 151. The preceding transaction 152i need not necessarily exist at the time the present transaction 152j is created or even sent to the network 106, though the preceding transaction 152i will need to exist and be validated in order for the present transaction to be valid. Hence “preceding” herein refers to a predecessor in a logical sequence linked by pointers, not necessarily the time of creation or sending in a temporal sequence, and hence it does not necessarily exclude that the transactions 152i, 152j be created or sent out-of-order (see discussion below on orphan transactions). The preceding transaction 152i could equally be called the antecedent or predecessor transaction. Due to the resources involved in transaction validation and publication, typically at least each of the blockchain nodes 104 takes the form of a server comprising one or more physical server units, or even whole a data centre. However in principle any given blockchain node 104 could take the form of a user terminal or a group of user terminals networked together. The memory of each blockchain node 104 stores software configured to run on the processing apparatus of the blockchain node 104 in order to perform its respective role or roles and handle transactions 152 in accordance with the blockchain node protocol. It will be understood that any action attributed herein to a blockchain node 104 may be performed by the software run on the processing apparatus of the respective computer equipment. The node software may be implemented in one or more applications at the application layer, or a lower layer such as the operating system layer or a protocol layer, or any combination of these. Any given blockchain node may be configured to perform one or more of the following operations: validating transactions, storing transactions, propagating transactions to other peers, performing consensus (e.g. proof-of-work) / mining operations. In some examples, each type of operation is performed by a different node 104. That is, nodes may specialise in particular operation. For example, a nodes 104 may focus on transaction validation and propagation, or on block mining. In some examples, a blockchain node 104 may perform more than one of these operations in parallel. Any reference to a blockchain node 104 may refer to an entity that is configured to perform at least one of these operations. Also connected to the network 101 is the computer equipment 102 of each of a plurality of parties 103 in the role of consuming users. These users may interact with the blockchain network 106 but do not participate in validating transactions or constructing blocks. Some of these users or agents 103 may act as senders and recipients in transactions. Other users may interact with the blockchain 150 without necessarily acting as senders or recipients. For instance, some parties may act as storage entities that store a copy of the blockchain 150 (e.g. having obtained a copy of the blockchain from a blockchain node 104). Some or all of the parties 103 may be connected as part of a different network, e.g. a network overlaid on top of the blockchain network 106. Users of the blockchain network (often referred to as “clients”) may be said to be part of a system that includes the blockchain network 106; however, these users are not blockchain nodes 104 as they do not perform the roles required of the blockchain nodes. Instead, each party 103 may interact with the blockchain network 106 and thereby utilize the blockchain 150 by connecting to (i.e. communicating with) a blockchain node 106. Two parties 103 and their respective equipment 102 are shown for illustrative purposes: a first party 103a and his / her respective computer equipment 102a, and a second party 103b and his / her respective computer equipment 102b. It will be understood that many more such parties 103 and their respective computer equipment 102 may be present and participating in the system 100, but for convenience they are not illustrated. Each party 103 may be an individual or an organization. Purely by way of illustration the first party 103a is referred to herein as Alice and the second party 103b is referred to as Bob, but it will be appreciated that this is not limiting and any reference herein to Alice or Bob may be replaced with “first party” and “second “party” respectively. The computer equipment 102 of each party 103 comprises respective processing apparatus comprising one or more processors, e.g. one or more CPUs, GPUs, other accelerator processors, application specific processors, and / or FPGAs. The computer equipment 102 of each party 103 further comprises memory, i.e. computer-readable storage in the form of a non-transitory computer-readable medium or media. This memory may comprise one or more memory units employing one or more memory media, e.g. a magnetic medium such as hard disk; an electronic medium such as an SSD, flash memory or EEPROM; and / or an optical medium such as an optical disc drive. The memory on the computer equipment 102 of each party 103 stores software comprising a respective instance of at least one client application 105 arranged to run on the processing apparatus. It will be understood that any action attributed herein to a given party 103 may be performed using the software run on the processing apparatus of the respective computer equipment 102. The computer equipment 102 of each party 103 comprises at least one user terminal, e.g. a desktop or laptop computer, a tablet, a smartphone, or a wearable device such as a smartwatch. The computer equipment 102 of a given party 103 may also comprise one or more other networked resources, such as cloud computing resources accessed via the user terminal. The client application 105 may be initially provided to the computer equipment 102 of any given party 103 on suitable computer-readable storage medium or media, e.g. downloaded from a server, or provided on a removable storage device such as a removable SSD, flash memory key, removable EEPROM, removable magnetic disk drive, magnetic floppy disk or tape, optical disk such as a CD or DVD ROM, or a removable optical drive, etc. The client application 105 comprises at least a “wallet” function. This has two main functionalities. One of these is to enable the respective party 103 to create, authorise (for example sign) and send transactions 152 to one or more bitcoin nodes 104 to then be propagated throughout the network of blockchain nodes 104 and thereby included in the blockchain 150. The other is to report back to the respective party the amount of the digital asset that he or she currently owns. In an output-based system, this second functionality comprises collating the amounts defined in the outputs of the various 152 transactions scattered throughout the blockchain 150 that belong to the party in question. Note: whilst the various client functionality may be described as being integrated into a given client application 105, this is not necessarily limiting and instead any client functionality described herein may instead be implemented in a suite of two or more distinct applications, e.g. interfacing via an API, or one being a plug-in to the other. More generally the client functionality could be implemented at the application layer or a lower layer such as the operating system, or any combination of these. The following will be described in terms of a client application 105 but it will be appreciated that this is not limiting. The instance of the client application or software 105 on each computer equipment 102 is operatively coupled to at least one of the blockchain nodes 104 of the network 106. This enables the wallet function of the client 105 to send transactions 152 to the network 106. The client 105 is also able to contact blockchain nodes 104 in order to query the blockchain 150 for any transactions of which the respective party 103 is the recipient (or indeed inspect other parties’ transactions in the blockchain 150, since in embodiments the blockchain 150 is a public facility which provides trust in transactions in part through its public visibility). The wallet function on each computer equipment 102 is configured to formulate and send transactions 152 according to a transaction protocol. As set out above, each blockchain node 104 runs software configured to validate transactions 152 according to the blockchain node protocol, and to forward transactions 152 in order to propagate them throughout the blockchain network 106. The transaction protocol and the node protocol correspond to one another, and a given transaction protocol goes with a given node protocol, together implementing a given transaction model. The same transaction protocol is used for all transactions 152 in the blockchain 150. The same node protocol is used by all the nodes 104 in the network 106. An alternative type of transaction protocol operated by some blockchain networks may be referred to as an “account-based” protocol, as part of an account-based transaction model. In the account-based case, each transaction does not define the amount to be transferred by referring back to the UTXO of a preceding transaction in a sequence of past transactions, but rather by reference to an absolute account balance. The current state of all accounts is stored, by the nodes of that network, separate to the blockchain and is updated constantly. In such a system, transactions are ordered using a running transaction tally of the account (also called the “position” or “nonce”). This value is signed by the sender as part of their cryptographic signature and is hashed as part of the transaction reference calculation. In addition, an optional data field may also be signed the transaction. This data field may point back to a previous transaction, for example if the previous transaction ID is included in the data field. Some account-based transaction models share several similarities with the output-based transaction model described herein. For example, as mentioned above, the data field of an account-based transaction may point back to a previous transaction, which is equivalent to the input of an output-based transaction which references an outpoint a previous transaction. Thus both models enable linking between transactions. As another example, an account-based transaction contains a “recipient” field (in which a receiving address of an account is specified) and a “value” field (in which an amount of digital asset may be specified). Together the recipient and value fields are equivalent to the output of an output- based transaction which may be used to assign an amount of digital asset to a blockchain address. Similarly, an account-based transaction has a “signature” field which includes a signature for the transaction. The signature is generated using the sender's private key and confirms the sender has authorized this transaction. This is equivalent to an input / unlocking script of an output-based transaction which, typically, includes a signature for the transaction. When both types of transaction are submitted to their respective blockchain networks, the signatures are checked to determine whether the transaction is valid and can be recorded on the blockchain. On an account-based blockchain, a “smart contact” refers to a transaction that contains a script configured to perform one or more actions (e.g. send or “release” a digital asset to a recipient address) in response to one or more inputs (provided by a transaction) meeting one or more conditions defined by the smart contact’s script. The smart contract exists as a transaction on the blockchain, and can be called (or triggered) by subsequent transactions. Thus, in some examples, a smart contract may be considered equivalent to a locking script of an output-based transaction, which can be triggered by a subsequent transaction, and checks whether one or more conditions defined by the locking script are met by the input of the subsequent transaction. 3. UTXO-BASED MODEL Figure 2 illustrates an example transaction protocol. This is an example of a UTXO-based protocol. A transaction 152 (abbreviated “Tx”) is the fundamental data structure of the blockchain 150 (each block 151 comprising one or more transactions 152). The following will be described by reference to an output-based or “UTXO” based protocol. However, this is not limiting to all possible embodiments. Note that while the example UTXO-based protocol is described with reference to bitcoin, it may equally be implemented on other example blockchain networks. In a UTXO-based model, each transaction (“Tx”) 152 comprises a data structure comprising one or more inputs 202, and one or more outputs 203. Each output 203 may comprise an unspent transaction output (UTXO), which can be used as the source for the input 202 of another new transaction (if the UTXO has not already been redeemed). The UTXO includes a value specifying an amount of a digital asset. This represents a set number of tokens on the distributed ledger. The UTXO may also contain the transaction ID of the transaction from which it came, amongst other information. The transaction data structure may also comprise a header 201, which may comprise an indicator of the size of the input field(s) 202 and output field(s) 203. The header 201 may also include an ID of the transaction. In embodiments the transaction ID is the hash of the transaction data (excluding the transaction ID itself) and stored in the header 201 of the raw transaction 152 submitted to the nodes 104. Say Alice 103a wishes to create a transaction 152j transferring an amount of the digital asset in question to Bob 103b. In Figure 2 Alice’s new transaction 152j is labelled “Tx1”. It takes an amount of the digital asset that is locked to Alice in the output 203 of a preceding transaction 152i in the sequence, and transfers at least some of this to Bob. The preceding transaction 152i is labelled “Tx0” in Figure 2. Tx0 and Tx1 are just arbitrary labels. They do not necessarily mean that Tx0 is the first transaction in the blockchain 151, nor that Tx1 is the immediate next transaction in the pool 154. Tx1 could point back to any preceding (i.e. antecedent) transaction that still has an unspent output 203 locked to Alice. The terms “preceding” and “subsequent” as used herein in the context of the sequence of transactions refer to the order of the transactions in the sequence as defined by the transaction pointers specified in the transactions (which transaction points back to which other transaction, and so forth). They could equally be replaced with “predecessor” and “successor”, or “antecedent” and “descendant”, “parent” and “child”, or such like. It does not necessarily imply an order in which they are created, sent to the network 106, or arrive at any given blockchain node 104. Nevertheless, a subsequent transaction (the descendent transaction or “child”) which points to a preceding transaction (the antecedent transaction or “parent”) will not be validated until and unless the parent transaction is validated. A child that arrives at a blockchain node 104 before its parent is considered an orphan. It may be discarded or buffered for a certain time to wait for the parent, depending on the node protocol and / or node behaviour. One of the one or more outputs 203 of the preceding transaction Tx0comprises a particular UTXO, labelled here UTXO0. Each UTXO comprises a value specifying an amount of the digital asset represented by the UTXO, and a locking script which defines a condition which must be met by an unlocking script in the input 202 of a subsequent transaction in order for the subsequent transaction to be validated, and therefore for the UTXO to be successfully redeemed. The locking script (aka scriptPubKey) is a piece of code written in the domain specific language recognized by the node protocol. A particular example of such a language is called “Script” (capital S) which is used by the blockchain network. The locking script specifies what information is required to spend a transaction output 203, for example the requirement of Alice’s signature. Locking scripts appear in the outputs of transactions. The unlocking script (aka scriptSig) is a piece of code written the domain specific language that provides the information required to satisfy the locking script criteria. For example, it may contain Bob’s signature. Unlocking scripts appear in the input 202 of transactions. So in the example illustrated, UTXO0 in the output 203 of Tx0 comprises a locking script [Checksig PA] which requires a signature Sig PA of Alice in order for UTXO0to be redeemed (strictly, in order for a subsequent transaction attempting to redeem UTXO0to be valid). [Checksig PA] contains a representation (i.e. a hash) of the public key PA from a public- private key pair of Alice. The input 202 of Tx1 comprises a pointer pointing back to Tx1 (e.g. by means of its transaction ID, TxID0, which in embodiments is the hash of the whole transaction Tx0). The input 202 of Tx1 comprises an index identifying UTXO0 within Tx0, to identify it amongst any other possible outputs of Tx0. The input 202 of Tx1 further comprises an unlocking script <Sig PA> which comprises a cryptographic signature of Alice, created by Alice applying her private key from the key pair to a predefined portion of data (sometimes called the “message” in cryptography). The data (or “message”) that needs to be signed by Alice to provide a valid signature may be defined by the locking script, or by the node protocol, or by a combination of these. When the new transaction Tx1arrives at a blockchain node 104, the node applies the node protocol. This comprises running the locking script and unlocking script together to check whether the unlocking script meets the condition defined in the locking script (where this condition may comprise one or more criteria). Note that the script code is often represented schematically (i.e. not using the exact language). For example, one may use operation codes (opcodes) to represent a particular function. “OP_...” refers to a particular opcode of the Script language. As an example, OP_RETURN is an opcode of the Script language that when preceded by OP_FALSE at the beginning of a locking script creates an unspendable output of a transaction that can store data within the transaction, and thereby record the data immutably in the blockchain 150. E.g. the data could comprise a document which it is desired to store in the blockchain. Typically an input of a transaction contains a digital signature corresponding to a public key PA. In embodiments this is based on the ECDSA using the elliptic curve secp256k1. A digital signature signs a particular piece of data. In some embodiments, for a given transaction the signature will sign part of the transaction input, and some or all of the transaction outputs. The particular parts of the outputs it signs depends on the SIGHASH flag. The SIGHASH flag is usually a 4-byte code included at the end of a signature to select which outputs are signed (and thus fixed at the time of signing). The locking script is sometimes called “scriptPubKey” referring to the fact that it typically comprises the public key of the party to whom the respective transaction is locked. The unlocking script is sometimes called “scriptSig” referring to the fact that it typically supplies the corresponding signature. However, more generally it is not essential in all applications of a blockchain 150 that the condition for a UTXO to be redeemed comprises authenticating a signature. More generally the scripting language could be used to define any one or more conditions. Hence the more general terms “locking script” and “unlocking script” may be preferred. 3. FURTHER REMARKS Other variants or use cases of the disclosed techniques may become apparent to the person skilled in the art once given the disclosure herein. The scope of the disclosure is not limited by the described embodiments but only by the accompanying claims. For instance, some embodiments above have been described in terms of a bitcoin network 106, bitcoin blockchain 150 and bitcoin nodes 104. However it will be appreciated that the bitcoin blockchain is one particular example of a blockchain 150 and the above description may apply generally to any blockchain. That is, the present invention is in by no way limited to the bitcoin blockchain. More generally, any reference above to bitcoin network 106, bitcoin blockchain 150 and bitcoin nodes 104 may be replaced with reference to a blockchain network 106, blockchain 150 and blockchain node 104 respectively. The blockchain, blockchain network and / or blockchain nodes may share some or all of the described properties of the bitcoin blockchain 150, bitcoin network 106 and bitcoin nodes 104 as described above. In preferred embodiments of the invention, the blockchain network 106 is the bitcoin network and bitcoin nodes 104 perform at least all of the described functions of creating, publishing, propagating and storing blocks 151 of the blockchain 150. It is not excluded that there may be other network entities (or network elements) that only perform one or some but not all of these functions. That is, a network entity may perform the function of propagating and / or storing blocks without creating and publishing blocks (recall that these entities are not considered nodes of the preferred bitcoin network 106). In other embodiments of the invention, the blockchain network 106 may not be the bitcoin network. In these embodiments, it is not excluded that a node may perform at least one or some but not all of the functions of creating, publishing, propagating and storing blocks 151 of the blockchain 150. For instance, on those other blockchain networks a “node” may be used to refer to a network entity that is configured to create and publish blocks 151 but not store and / or propagate those blocks 151 to other nodes. Even more generally, any reference to the term “bitcoin node” 104 above may be replaced with the term “network entity” or “network element”, wherein such an entity / element is configured to perform some or all of the roles of creating, publishing, propagating and storing blocks. The functions of such a network entity / element may be implemented in hardware in the same way described above with reference to a blockchain node 104. Some embodiments have been described in terms of the blockchain network implementing a proof-of-work consensus mechanism to secure the underlying blockchain. However proof- of-work is just one type of consensus mechanism and in general embodiments may use any type of suitable consensus mechanism such as, for example, proof-of-stake, delegated proof-of-stake, proof-of-capacity, or proof-of-elapsed time. As a particular example, proof- of-stake uses a randomized process to determine which blockchain node 104 is given the opportunity to produce the next block 151. The chosen node is often referred to as a validator. Blockchain nodes can lock up their tokens for a certain time in order to have the chance of becoming a validator. Generally, the node who locks the biggest stake for the longest period of time has the best chance of becoming the next validator. It will be appreciated that the above embodiments have been described by way of example only. More generally there may be provided a method, apparatus or program in accordance with any one or more of the following Statements. Statement 1. A computer-implemented method of determining a verification path for a target hash of a hash tree, wherein the hash tree comprises a layer comprising a plurality of leaf hashes, one or more layers each comprising one or more inner hashes, and a layer comprising a root hash, wherein each hash is associated with a respective position within a respective layer of the hash tree, and wherein the hashes of the hash tree, or respective values for deriving said hashes of the hash tree, are stored as an array ordered based on the respective layer of the hash tree and the respective position of the respective hash within the respective layer, wherein each hash or respective value stored in the array is associated with a respective index representing its position within the array, and wherein the method comprises: determining a respective index of a respective next hash of the verification path by determining a respective position of the target hash within the respective layer comprising the target hash, a respective number of hashes within the respective layer comprising the target hash, and a respective index associated with a respective initial hash of the respective layer, wherein the respective index is based on the respective position of the target hash, the respective index associated with the respective initial hash, and the respective number of hashes within the respective layer comprising the target hash; and performing one or more iterations until a respective index of the root hash is determined, wherein each iteration comprises determining a respective index of a respective next hash of the verification path by determining a respective position of a respective parent hash of the respective next hash within the respective layer comprising the respective parent hash, a respective number of hashes within the respective layer comprising the respective parent hash, and a respective index associated with a respective initial hash of the respective layer comprising the respective parent hash, wherein the respective index of the respective next hash is based on the respective position of the respective parent hash and the respective index associated with the respective initial hash, and the respective number of hashes within the respective layer comprising the respective parent hash; and extracting, from the array and using the determined respective indexes, the respective next hashes or respective values for deriving the respective next hashes, of the verification path. Statement 2. The method of statement 1, comprising using the extracted hashes or respective values to perform a verification proof for the target hash and / or providing the extracted hashes or respective values to a party for performing the verification proof for the target hash. Statement 3. The method of statement 1 or statement 2, comprising receiving any one or more of: an indication of a number of leaf hashes of the hash tree, a respective index of the target hash, information for determining the number of leaf hashes of the hash tree, information for determining the respective index of the target hash. Statement 4. The method of statement 3, comprising determining whether the target hash is a leaf hash based on the respective index of the target hash. Statement 5. The method of statement 4, comprising: if the target hash is a leaf hash, determining the respective position of the target hash within the respective layer comprising the target hash based on the respective index of the target hash, and determining the respective index associated with the respective initial hash of the respective layer as an initial index associated with an initial hash of the array; and if the target hash is not a leaf hash, determining the respective position of the target hash within the respective layer comprising the target hash based on the respective position of the respective index of the target hash and a respective number of hashes within the respective layer comprising the target hash, and determining the respective index associated with the respective initial hash of the respective layer based on the initial index associated with an initial hash of the array and the respective number if hashes within the respective layer comprising the target hash. Statement 6. The method of any preceding statement, wherein for each iteration, the respective position of the respective parent hash is based on i) a first variable determined based on the respective position of the respective next hash of a respective previous iteration, and ii) a second variable determined based on a respective index associated with a respective initial hash of the respective layer comprising the respective next hash of the respective previous iteration. Statement 7. The method of any preceding statement, comprising: for each iteration, determining a respective number of hashes within the respective layer comprising the parent hash of the respective next hash, and determining that the respective index of the root hash has been determined when the respective number of hashes within the respective layer comprising the parent hash is equal to one. Statement 8. The method of any preceding statement, wherein the hash tree encodes a plurality of blockchain transactions. Statement 9. The method of statement 8, wherein the plurality of blockchain transactions together form a block of blockchain transactions. Statement 10. The method of any preceding statement, comprising generating the array. Statement 11. The method of any preceding statement, comprising receiving the array. Statement 12. The method of any preceding statement, wherein the hash tree is a Merkle tree, the verification path is a Merkle path and the verification proof is a Merkle proof. Statement 13. Computer equipment comprising: memory comprising one or more memory units; and processing apparatus comprising one or more processing units, wherein the memory stores code arranged to run on the processing apparatus, the code being configured so as when on the processing apparatus to perform the method of any of statements 1 to 12. Statement 14. A computer program embodied on computer-readable storage and configured so as, when run on one or more processors, to perform the method of any of statements to 12. In embodiments, the method may be used in the context of blockchain transactions, wherein some or all of the leaf nodes of the hash tree are based on (e.g. a hash or double hash of) a respective blockchain transactions. For instance, the leaf hashes of the hash tree may be respective transaction identifiers. In embodiments, the method is performed by a blockchain node. In embodiments, the method comprises making the verification (e.g. Merkle) path available to a simplified payment verification (SPV) client. According to one aspect disclosed herein, there is provided a method of receiving a verification (e.g. Merkle) path generated according to any of the preceding statements and embodiments described herein. According to another aspect disclosed herein, there is provided a method of validating a transaction’s inclusion in a blockchain block based on the received verification (e.g. Merkle) path and a block header of the blockchain block. 4. APPENDIX 4.1 Number of nodes in a Merkle tree Lemma. The number of nodes in a Merkle tree with ^^ leaves is: Proof. If ^^ = 1, it is trivially true. For ^^ bigger than 1, there are ^^ leaves, and nodes connected to the leaves, these nodes can be interpreted as the leaves of a Merkle tree with leaves. Lemma. The number of nodes in a Merkle tree with ^^ leaves is: Where: • ^^^is the number of zeros in the binary representation of ^^. • ^^^is the number of trailing zeros (the number of continuous zeros at the end of the binary representation of ^^). • ^^^is 1 if ^^ is a power of 2 and 0 otherwise. Proof. The proof works by induction. If ^^ = 1 then the formula is correct since there is only one node. For ^^ > 1, there are 3 cases: • If ^^ = 2 ^^, then ^^^− ^^^= ^^^− ^^^, and ^^^= ^^^. Thus: ^^^= ^^^+ ^^ = ^^ + 2 ^^ + ^^^− ^^^− ^^^= 2 ^^ + ^^^− ^^^+ ^^^. • If ^^ = 2^− 1, ^^ > 1, then the number of nodes is 2^ା^− 2. In this case, ^^^, ^^^and ^^^are all equal to 0, thus the formula reduces to ^^^= 2(2^− 1). • If ^^ = 2 ^^ + 1, but ^^ + 1 is not a power of 2, then also = ^^ + 1 is not a power of 2, thus ^^^ା^= ^^^= 0. Moreover, since ^^ + 1 is not a power of 2, then ^^^− ^^^= 1 + ^^^ା^− ^^^ା^. Indeed, the parts to the left of the rightmost zero of ^^ and ^^ + 1 are identical, while the others have the form of 01 … 1 for ^^ and of 10 … 0 for ^^ + 1. Thus: ^^^= 2 ^^ + 1 + ^^^ା^= 2(2 ^^ + 1) + 1 + ^^^ା^− ^^^ା^= 2 ^^ + ^^^− ^^^− ^^^4.2 Code implementation and examples This appendix shows an example Python implementation of the algorithms described herein by creating the class MerkleArray. The class MerkleArray collects the ordered set of transactions in the Merkle tree, generates the values of the nodes of the tree, and converts the tree in an array. Once the Merkle tree has been converted into an array, it is possible to recover the Merkle proof of any node providing its index in the array. If the index corresponds to a leaf, the Merkle proof of the associated transaction is returned. If the index corresponds to an inner node, the Merkle proof of that branch of the tree is returned. The hash function The hash function used is the double SHA256. from hashlib import sha256 def hash(x): return sha256(sha256(x.encode()).hexdigest().encode()).hexdigest() Class initialization The MerkleArray class can be initialized with any list which is interpreted as the values of the leaves (i.e., the elements of this list should be transaction IDs). class MerkleArray: def __init__(self, l = []): # the class can be initialized with any list of transaction IDs. # txLList: a list of lists that describes the Merkle tree structure. # isPerfect: flag set to true if the number of transactions is a power of two. # isFinished: flag that determines whether additional transactions can be added. # nTx: the number of transactions in the tree. # array: the flattened representation of the tree. It is initialized once the Merkle tree is finalized. self.txLList = [l] self.isPerfect = (len(l) & (len(l) - 1) == 0) self.isFinished = False self.nTx = len(l) self.array = [] # construct the upper levels in txLList. If isPerfect is True, then txLList corresponds to a perfect tree. while len(l) > 1: l = [hash (x[0] + x[1]) for x in zip(l[::2], l[1::2])] self.txLList.append(l) Example 1 Assume l = [], then self.txLList = [[]], self.isPerfect = False, self.isFinished = False, self.nTx = 0 and self.array = []. Example 2 Assume l = [‘0’, ‘1’], then self.txLList = [[‘0’, ‘1’], [hash(‘01’)]], self.isPerfect = True, self.isFinished = False, self.nTx = 2 and self.array = []. Example 3 Assume l = [‘0’, ‘1’, ‘2’, ‘3’, ‘4’], then self.txLList = [[‘0’, ‘1’, ‘2’, ‘3’, ‘4’], [hash(‘01’), hash(‘23’)], [hash(hash(‘01’) + hash(‘23’))]], self.isPerfect = False, self.isFinished = False, self.nTx = 5 and self.array = []. Append transactions to the tree The class supports the addition of new transactions to the list of leaves. When a new leaf is added to the tree, its parents are added as well. Adding new transactions is possible only if the tree has not been finalized yet. def append(self, tx : str): # add a new transaction to the tree, only possible if the tree is not finalized if not self.isFinished: #add the transaction, and update the values nTx, txLList and isPerfect self.txLList[0].append(tx) self.nTx = len(self.txLList[0]) self.isPerfect = (self.nTx & (self.nTx - 1) == 0) level = 0 n = self.nTx # if the transaction can be paired with a transaction already in the tree, it is done. while n % 2 == 0: nodeL = self.txLList[level][-2] nodeR = self.txLList[level][-1] newNode = hash(nodeL + nodeR) # if it reached the current root, it creates a new level. if level + 1 < len(self.txLList): self.txLList[level + 1].append(newNode) else: self.txLList.append([newNode]) # repeat the process for the upper layers, if possible n / / = 2 level += 1 Example 1 Assume self.txLList = [[]], appending ‘1’ causes the following changes self.txLList = [[‘1’]], self.isPerfect = True, self.isFinished = False, self.nTx = 1 and self.array = []. Example 2 Assume self.txLList = [[‘0’, ‘1’]], appending ‘2’ causes the following changes self.txLList = [[‘0’, ‘1’, ‘2’], [hash(‘01’)]], self.isPerfect = False, self.isFinished = False, self.nTx = 3 and self.array = []. Example 3 Assume self.txLList = [[‘0’, ‘1’, ‘2’],[hash(‘01’)]], appending ‘3’ causes the following changes self.txLList = [[‘0’, ‘1’, ‘2’, ‘3’], [hash(‘01’), hash(‘23’)], [hash(hash(‘01’) + hash(‘23’))]], self.isPerfect = True, self.isFinished = False, self.nTx = 4 and self.array = []. Tree finalization and array creation Once the list of transactions is completed, the tree is finished, and the array is generated. def close(self): # finalize the tree in case isPerfect is false and the tree is not empty if not self.isPerfect and self.txLList[0]: # nodes are added from the first level that has not even numbers of elements. toComplete keeps track of this. toComplete = False for level, levelList in enumerate(self.txLList): # determine the first level that requires some new node. if len(levelList) % 2 == 1: toComplete = True if toComplete: # if the number of elements is odd, hash it with itself, otherwise with the previous if len(levelList) % 2 == 1: lastNode = levelList[-1] newNode = hash(lastNode + lastNode) else: lastNode = levelList[-1] lastLastNode = levelList[-2] newNode = hash(lastLastNode + lastNode) # if the root is generated, add its level and then stop. if level != len(self.txLList) - 1: self.txLList[level + 1].append(newNode) else: self.txLList.append([newNode]) break # the tree is now completed and cannot be changed, it can be vectorized. self.isFinished = True self.array = [hash for level in self.txLList for hash in level] Example 1 Assume self.txLList = [[‘1’]], the presented function only changes self.isFinished = True, and self.array = [‘1’]. Example 2 Assume self.txLList = [[‘0’, ‘1’, ‘2’], [hash(‘01’)]], the presented function changes the following: 1. self.txLList = [[‘0’, ‘1’, ‘2’], [hash(‘01’), hash(‘22’)], [hash(hash(‘01’) + hash(‘22’))]]; 2. self.isFinished = True, 3. self.txLList = [‘0’, ‘1’, ‘2’, hash(‘01’), hash(‘22’), hash(hash(‘01’) + hash(‘22’))]. Reconstructing the Merkle proof Given the finalized tree, the array can recover efficiently the Merkle proofs. Notice that to reconstruct the Merkle proof it is required to know if the nodes are left of right children. This can be deduced from the binary representation of the position in the tree. def recoverMerkleProof(self, pos): # recover the Merkle proof of the node at index pos in the array. The function is not restricted to recover the Merkle proof of leaves of the tree. # ans contains the value of the hashes needed for the Merkle proof, while ansLoc is the indices of the hashes in the array. ans = [] ansLoc = [] # the Merkle proof is produced only if array is not empty, which implies that that the tree has been closed. if self.array: # the first element in the Merkle proof is the one at the desired position. ans.append(self.array[pos]) ansLoc.append(pos) # startingPoint keeps track of the initial element at each level. # limit tracks the number of elements in a level. startingPoint = 0 limit = self.nTx # in case the position is referring to a branch of the tree, update the startingPoint, the limit and the position to start from the correct level. while pos >= limit: startingPoint += limit pos -= limit limit = limit / / 2 + limit%2 # iterate until the root is reached. while startingPoint + pos < len(self.array): # stop if the root is reached. if limit == 1: ans.append(self.array[startingPoint]) ansLoc.append(startingPoint) break # if the pos is even, it may be the last node in the level or not. if pos % 2 == 0: if pos == limit - 1: ans.append(self.array[startingPoint + pos]) ansLoc.append(startingPoint + pos) else: ans.append(self.array[startingPoint + pos + 1]) ansLoc.append(startingPoint + pos + 1) # if the pos is odd, it is hashed with the next value (it cannot be the root since it was already checked). else: ans.append(self.array[startingPoint + pos - 1]) ansLoc.append(startingPoint + pos - 1) # update startingPoint, limit and pos. startingPoint += limit limit = limit / / 2 + limit%2 pos = pos / / 2 return ans, ansLoc
Claims
CLAIMS 1. A computer-implemented method of determining a verification path for a target hash of a hash tree, wherein the hash tree comprises a layer comprising a plurality of leaf hashes, one or more layers each comprising one or more inner hashes, and a layer comprising a root hash, wherein each hash is associated with a respective position within a respective layer of the hash tree, and wherein the hashes of the hash tree, or respective values for deriving said hashes of the hash tree, are stored as an array ordered based on the respective layer of the hash tree and the respective position of the respective hash within the respective layer, wherein each hash or respective value stored in the array is associated with a respective index representing its position within the array, and wherein the method comprises: determining a respective index of a respective next hash of the verification path by determining a respective position of the target hash within the respective layer comprising the target hash, a respective number of hashes within the respective layer comprising the target hash, and a respective index associated with a respective initial hash of the respective layer, wherein the respective index is based on the respective position of the target hash, the respective index associated with the respective initial hash, and the respective number of hashes within the respective layer comprising the target hash; and performing one or more iterations until a respective index of the root hash is determined, wherein each iteration comprises determining a respective index of a respective next hash of the verification path by determining a respective position of a respective parent hash of the respective next hash within the respective layer comprising the respective parent hash, a respective number of hashes within the respective layer comprising the respective parent hash, and a respective index associated with a respective initial hash of the respective layer comprising the respective parent hash, wherein the respective index of the respective next hash is based on the respective position of the respective parent hash and the respective index associated with the respective initial hash, and the respective number of hashes within the respective layer comprising the respective parent hash; andextracting, from the array and using the determined respective indexes, the respective next hashes or respective values for deriving the respective next hashes, of the verification path.
2. The method of claim 1, comprising using the extracted hashes or respective values to perform a verification proof for the target hash and / or providing the extracted hashes or respective values to a party for performing the verification proof for the target hash.
3. The method of claim 1 or claim 2, comprising receiving any one or more of: an indication of a number of leaf hashes of the hash tree, a respective index of the target hash, information for determining the number of leaf hashes of the hash tree, information for determining the respective index of the target hash.
4. The method of claim 3, comprising determining whether the target hash is a leaf hash based on the respective index of the target hash.
5. The method of claim 4, comprising: if the target hash is a leaf hash, determining the respective position of the target hash within the respective layer comprising the target hash based on the respective index of the target hash, and determining the respective index associated with the respective initial hash of the respective layer as an initial index associated with an initial hash of the array; and if the target hash is not a leaf hash, determining the respective position of the target hash within the respective layer comprising the target hash based on the respective position of the respective index of the target hash and a respective number of hashes within the respective layer comprising the target hash, and determining the respective index associated with the respective initial hash of the respective layer based on the initial index associated with an initial hash of the array and the respective number if hashes within the respective layer comprising the target hash.
6. The method of any preceding claim, wherein for each iteration, the respective position of the respective parent hash is based on i) a first variable determined based on therespective position of the respective next hash of a respective previous iteration, and ii) a second variable determined based on a respective index associated with a respective initial hash of the respective layer comprising the respective next hash of the respective previous iteration.
7. The method of any preceding claim, comprising: for each iteration, determining a respective number of hashes within the respective layer comprising the parent hash of the respective next hash, and determining that the respective index of the root hash has been determined when the respective number of hashes within the respective layer comprising the parent hash is equal to one.
8. The method of any preceding claim, wherein the hash tree encodes a plurality of blockchain transactions.
9. The method of claim 8, wherein the plurality of blockchain transactions together form a block of blockchain transactions.
10. The method of any preceding claim, comprising generating the array.
11. The method of any preceding claim, comprising receiving the array.
12. The method of any preceding claim, wherein the hash tree is a Merkle tree, the verification path is a Merkle path and the verification proof is a Merkle proof.
13. Computer equipment comprising: memory comprising one or more memory units; and processing apparatus comprising one or more processing units, wherein the memory stores code arranged to run on the processing apparatus, the code being configured so as when on the processing apparatus to perform the method of any of claims 1 to 12.
14. A computer program embodied on computer-readable storage and configured so as, when run on one or more processors, to perform the method of any of claims 1 to 12.