GB2618766A - Optimizing blockchain transaction size - Google Patents

Optimizing blockchain transaction size Download PDF

Info

Publication number
GB2618766A
GB2618766A GB2206032.1A GB202206032A GB2618766A GB 2618766 A GB2618766 A GB 2618766A GB 202206032 A GB202206032 A GB 202206032A GB 2618766 A GB2618766 A GB 2618766A
Authority
GB
United Kingdom
Prior art keywords
transaction
fee
value
input
output
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
GB2206032.1A
Other versions
GB202206032D0 (en
Inventor
Pagani Alessio
Paunoiu Alexandru
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nchain Licensing AG
Original Assignee
Nchain Licensing AG
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nchain Licensing AG filed Critical Nchain Licensing AG
Priority to GB2206032.1A priority Critical patent/GB2618766A/en
Publication of GB202206032D0 publication Critical patent/GB202206032D0/en
Priority to PCT/EP2023/058489 priority patent/WO2023208517A1/en
Publication of GB2618766A publication Critical patent/GB2618766A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q10/00Administration; Management
    • G06Q10/04Forecasting or optimisation specially adapted for administrative or management purposes, e.g. linear programming or "cutting stock problem"
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/50Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols using hash chains, e.g. blockchains or hash trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/04Payment circuits
    • G06Q20/06Private payment circuits, e.g. involving electronic currency used among participants of a common payment scheme
    • G06Q20/065Private payment circuits, e.g. involving electronic currency used among participants of a common payment scheme using e-cash
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/32Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
    • H04L9/3247Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials involving digital signatures
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L2209/00Additional information or applications relating to cryptographic mechanisms or cryptographic arrangements for secret or secure communication H04L9/00
    • H04L2209/56Financial cryptography, e.g. electronic payment or e-cash

Landscapes

  • Engineering & Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Computer Security & Cryptography (AREA)
  • Strategic Management (AREA)
  • Theoretical Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Economics (AREA)
  • Accounting & Taxation (AREA)
  • Human Resources & Organizations (AREA)
  • Signal Processing (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • General Business, Economics & Management (AREA)
  • Physics & Mathematics (AREA)
  • Quality & Reliability (AREA)
  • Tourism & Hospitality (AREA)
  • Operations Research (AREA)
  • Marketing (AREA)
  • Development Economics (AREA)
  • Entrepreneurship & Innovation (AREA)
  • Game Theory and Decision Science (AREA)
  • Finance (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Financial Or Insurance-Related Operations Such As Payment And Settlement (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

A method of optimizing a size of a blockchain transaction by minimising a number of inputs and/or outputs of the transaction. An optimizer 502 has access to unspent transaction outputs (UTXOs) that are available as inputs. The method involves determining a number of each UTXO having a value to be used as an input to the transaction and a number of each output of the transaction having a value, by minimising, for each different value of the UTXOs and for each different value of each output, a sum of a) a number of each UTXO having a value multiplied by the associated input fee, and b) a sum of bi) a number of each output having a value multiplied by the associated output fee, and bii) a leftover fee. The minimising is subject to constraints to ensure the transaction is fully funded.

Description

OPTIMIZING BLOCKCHAIN TRANSACTION SIZE
TECHNICAL FIELD
The present disclosure relates to a method of optimizing a size of a blockchain transaction by minimising a number of inputs and/or outputs of the transaction.
BACKGROUND
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.
Nodes of the blockchain network (which are often referred to as "miners") perform a distributed transaction registration and verification process, which will be described in more detail later. In summary, during this process a node validates transactions and inserts them into a block template for which they attempt to identify a valid proof-of-work solution. Once a valid solution is found, a new block is propagated to other nodes of the network, thus enabling each node to record the new block on the blockchain. In order to have a transaction recorded in the blockchain, a user (e.g. a blockchain client application) sends the transaction to one of the nodes of the network to be propagated. Nodes which receive the transaction may race to find a proof-of-work solution incorporating the validated transaction into a new block. Each node is configured to enforce the same node protocol, which will include one or more conditions for a transaction to be valid. Invalid transactions will not be propagated nor incorporated into blocks. Assuming the transaction is validated and thereby accepted onto the blockchain, then the transaction (including any user data) will thus remain registered and indexed at each of the nodes in the blockchain network as an immutable public record.
The node who successfully solved the proof-of-work puzzle to create the latest block is typically rewarded with a new transaction called the "coinbase transaction" which distributes an amount of the digital asset, i.e. a number of tokens. The detection and rejection of invalid transactions is enforced by the actions of competing nodes who act as agents of the network and are incentivised to report and block malfeasance. The widespread publication of information allows users to continuously audit the performance of nodes. The publication of the mere block headers allows participants to ensure the ongoing integrity of the blockchain.
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.
SUMMARY
It is a feature of most blockchains that a transaction has an associated transaction fee based on the size of the transaction. Each input to a transaction is an unspent transaction output (UTXO) from a previous transaction and has an associated value. Similarly, each spendable output of a transaction itself is a UTXO with an associated value. The sum of the value(s) associated with the one or more inputs must be at least equal to the sum of the value(s) associated with the one or more outputs and the transaction fee. One option for meeting this condition is to add more inputs until the condition is met. However, adding more inputs increases the transaction size, and hence the transaction fee. Moreover, adding more inputs may necessitate the need for more outputs, which also increase the transaction size, and hence the transaction fee.
The present disclosure provides techniques for optimising the transaction size by minimising the number of inputs and/or or outputs of a transaction whilst still satisfying the fee-based condition, given a particular set of UTX05 available for serving as inputs to the transaction. Minimising the transaction size provides storage savings (e.g. for the blockchain nodes) and bandwidth benefits (e.g. when initially sending the transaction to the blockchain nodes, and when those blockchain nodes distribute to the transaction to other nodes). Minimizing the transaction size also has the additional benefit in reducing the transaction fee for the sending party.
The present disclosure also provides techniques for identifying the optimal value (i.e. the denomination) of the inputs for a given funding scenario. This allows the creation of predefined UTX0s, spendable when needed for a particular scenario. This pre-processing allows faster transaction creation (therefore faster transaction throughput) when needed.
According to one aspect disclosed herein, there is provided a computer-implemented method of optimizing a size of a blockchain transaction by minimising a number of inputs and/or outputs of the transaction, wherein the transaction has at least one input and at least one output, wherein an optimizer has access to a plurality of unspent transaction outputs, UTX0s, that are available for being respective inputs to the transaction, each respective UTXO having a respective value, wherein the transaction comprises target data having an associated data fee, each input to the transaction has associated input fee and each output of the transaction has an associated output fee, and wherein a total amount of respective values of the respective UTX05 input to the transaction is required to be at least equal to the total amount of fees of the transaction, and wherein the method comprises: determining a respective number of each respective UTXO having a respective value to be used as a respective input to the transaction and a respective number of each output of the transaction having a respective value, by minimising, for each different respective value of the respective UTX05 and for each different respective value of each output, a sum of a) a number of each respective UTXO having a respective value multiplied by the associated input fee, and b) a sum of bi) a number of each respective output having a respective value multiplied by the associated output fee, and bii) a leftover fee, wherein said minimising is subject to the following constraints: i) a total amount of the respective values of the respective UTX05 must be at least equal to the data fees and a leftover amount, wherein the leftover amount is based on based on a total amount of respective values of one or more respective UTX05 input to the transaction, a total amount of respective values of one or more respective outputs of the transaction, and a total amount of fees of the transaction, ii) the determined respective number of each UTXO must be non-negative, iii) the determined respective number of each output must be non-negative, and iv) the leftover amount must be between zero and a maximum of a predetermined upper bound and a sum of the associated input fee and the associated output fee. 20 An optimizer (e.g. a user, service provider, etc.) has access to (e.g. control of) a plurality of UTX0s. For instance, the optimizer may control the private keys necessary for spending the UTX0s, or at least have awareness of which UTX0s are available for funding the transaction.
As mentioned, each input has an associated input fee and each output has an associated output fee. Each spendable output (i.e. an output having a respective value) may be required to have a predetermined minimum value. This is sometimes referred to as a dust limit. The transaction contains target data having an associated data fee. The target data is generally any data of the transaction other than the data associated with the input(s) and output(s), which have their own associated fees. The target data may therefore include components of the transaction which are inherent to the transaction (e.g. a version number). The target data may also include user-defined data, e.g. an image, text, etc. Some techniques for funding a transaction may rely on simply adding enough UTX0s to the transaction until the data fees are covered. However this would not necessarily result in the an optimal transaction size. In contrast, according to embodiments, the optimizer is configured to determine, from the available UTX05, the minimum number of inputs and outputs of the transaction, and the associated values of those inputs and outputs, that satisfy the fee requirements of the transaction. That is, given a set of UTX0s of certain values, and target data having an associated fee, the optimizer determines how to optimally fund the transaction (by adding one or more input UTX05) whilst minimising the size of the transaction (in terms of number of inputs and outputs).
In some embodiments the optimizer is configured to apply a dynamic programming approach to solve the problem of how to optimally fund the transaction. One approach described herein makes use of a modified change-making-problem algorithm that is modified according to the specific requirements of blockchain transaction funding.
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, Figure 3 schematically illustrates an example service for building and submitting transactions to the blockchain, Figure 4 is a visualisation of a simulated annealing algorithm, Figure 5 is a schematic block diagram of a system for implementing the described embodiments and Figure 6 shows a transaction fees graph with respect to the leftover fee.
S
DETAILED DESCRIPTION OF EMBODIMENTS
1. EXAMPLE SYSTEM OVERVIEW 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 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. In one common type of transaction protocol, the data structure of each transaction 152 comprises at least one input and at least one output. Each output specifies an amount representing a quantity of a digital asset as property, an example of which is a user 103 to whom the output is cryptographically locked (requiring a signature or other solution of that user in order to be unlocked and thereby redeemed or spent). Each input points back to the output of a preceding transaction 152, thereby linking the transactions.
Each block 151 also comprises a block pointer 155 pointing back to the previously created block 151 in the chain so as to define a sequential order to the blocks 151. Each transaction 152 (other than a coinbase transaction) comprises a pointer back to a previous transaction so as to define an order to sequences of transactions (N.B. sequences of transactions 152 are allowed to branch). The chain of blocks 151 goes all the way back to a genesis block (Gb) 153 which was the first block in the chain. One or more original transactions 152 early on in the chain 150 pointed to the genesis block 153 rather than a preceding transaction.
Each of the blockchain nodes 104 is configured to forward transactions 152 to other blockchain nodes 104, and thereby cause transactions 152 to be propagated throughout the network 106. Each blockchain node 104 is configured to create blocks 151 and to store a respective copy of the same blockchain 150 in their respective memory. Each blockchain node 104 also maintains 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.
The input of the present transaction 152j also comprises the input authorisation, for example the signature of the user 103a to whom the output of the preceding transaction 152i is locked. In turn, the output of the present transaction 152j can be cryptographically locked to a new user or entity 103b. The present transaction 152j can thus transfer the amount defined in the input of the preceding transaction 152i to the new user or entity 103b as defined in the output of the present transaction 152j. In some cases a transaction 152 may have multiple outputs to split the input amount between multiple users or entities (one of whom could be the original user or entity 103a in order to give change). In some cases a transaction can also have multiple inputs to gather together the amounts from multiple outputs of one or more preceding transactions, and redistribute to one or more outputs of the current transaction.
According to an output-based transaction protocol such as bitcoin, when a party 103, such as an individual user or an organization, wishes to enact a new transaction 152j (either manually or by an automated process employed by the party), then the enacting party sends the new transaction from its computer terminal 102 to a recipient. The enacting party or the recipient will eventually send this transaction to one or more of the blockchain nodes 104 of the network 106 (which nowadays are typically servers or data centres, but could in principle be other user terminals). It is also not excluded that the party 103 enacting the new transaction 152j could send the transaction directly to one or more of the blockchain nodes 104 and, in some examples, not to the recipient. A blockchain node 104 that receives a transaction checks whether the transaction is valid according to a blockchain node protocol which is applied at each of the blockchain nodes 104. The blockchain node protocol typically requires the blockchain node 104 to check that a cryptographic signature in the new transaction 152j matches the expected signature, which depends on the previous transaction 152i in an ordered sequence of transactions 152. In such an output-based transaction protocol, this may comprise checking that the cryptographic signature or other authorisation of the party 103 included in the input of the new transaction 152j matches a condition defined in the output of the preceding transaction 152i which the new transaction spends (or "assigns"), wherein this condition typically comprises at least checking that the cryptographic signature or other authorisation in the input of the new transaction 152j unlocks the output of the previous transaction 152i to which the input of the new transaction is linked to. The condition may be at least partially defined by a script included in the output of the preceding transaction 152i. Alternatively it could simply be fixed by the blockchain node protocol alone, or it could be due to a combination of these. Either way, if the new transaction 152j is valid, the blockchain node 104 forwards it to one or more other blockchain nodes 104 in the blockchain network 106. These other blockchain nodes 104 apply the same test according to the same blockchain node protocol, and so forward the new transaction 152j on to one or more further nodes 104, and so forth. In this way the new transaction is propagated throughout the network of blockchain nodes 104.
In an output-based model, the definition of whether a given output (e.g. UTXO) is assigned (or "spent") is whether it has yet been validly redeemed by the input of another, onward transaction 152j according to the blockchain node protocol. Another condition for a transaction to be valid is that the output of the preceding transaction 152i which it attempts to redeem has not already been redeemed by another transaction. Again if not valid, the transaction 1521 will not be propagated (unless flagged as invalid and propagated for alerting) or recorded in the blockchain 150. This guards against double-spending whereby the transactor tries to assign the output of the same transaction more than once. An account-based model on the other hand guards against double-spending by maintaining an account balance. Because again there is a defined order of transactions, the account balance has a single defined state at any one time.
In addition to validating transactions, blockchain nodes 104 also race to be the first to create blocks of transactions in a process commonly referred to as mining, which is supported by "proof-of-work". At a blockchain node 104, new transactions are added to an ordered pool 154 of valid transactions that have not yet appeared in a block 151 recorded on the blockchain 150. The blockchain nodes then race to assemble a new valid block 151 of transactions 152 from the ordered set of transactions 154 by attempting to solve a cryptographic puzzle. Typically this comprises searching for a "nonce" value such that when the nonce is concatenated with a representation of the ordered pool of pending transactions 154 and hashed, then the output of the hash meets a predetermined condition.
E.g. the predetermined condition may be that the output of the hash has a certain predefined number of leading zeros. Note that this is just one particular type of proof-ofwork puzzle, and other types are not excluded. A property of a hash function is that it has an unpredictable output with respect to its input. Therefore this search can only be performed by brute force, thus consuming a substantive amount of processing resource at each blockchain node 104 that is trying to solve the puzzle.
The first blockchain node 104 to solve the puzzle announces this to the network 106, providing the solution as proof which can then be easily checked by the other blockchain nodes 104 in the network (once given the solution to a hash it is straightforward to check that it causes the output of the hash to meet the condition). The first blockchain node 104 propagates a block to a threshold consensus of other nodes that accept the block and thus enforce the protocol rules. The ordered set of transactions 154 then becomes recorded as a new block 151 in the blockchain 150 by each of the blockchain nodes 104. A block pointer is also assigned to the new block 151n pointing back to the previously created block 151n-1 in the chain. The significant amount of effort, for example in the form of hash, required to create a proof-of-work solution signals the intent of the first node 104 to follow the rules of the blockchain protocol. Such rules include not accepting a transaction as valid if it spends or assigns the same output as a previously validated transaction, otherwise known as double-spending. Once created, the block 151 cannot be modified since it is recognized and maintained at each of the blockchain nodes 104 in the blockchain network 106. The block pointer 155 also imposes a sequential order to the blocks 151. Since the transactions 152 are recorded in the ordered blocks at each blockchain node 104 in a network 106, this therefore provides an immutable public ledger of the transactions.
Note that different blockchain nodes 104 racing to solve the puzzle at any given time may be doing so based on different snapshots of the pool of yet-to-be published transactions 154 at any given time, depending on when they started searching for a solution or the order in which the transactions were received. Whoever solves their respective puzzle first defines which transactions 152 are included in the next new block 151n and in which order, and the current pool 154 of unpublished transactions is updated. The blockchain nodes 104 then continue to race to create a block from the newly-defined ordered pool of unpublished transactions 154, and so forth. A protocol also exists for resolving any "fork" that may arise, which is where two blockchain nodes104 solve their puzzle within a very short time of one another such that a conflicting view of the blockchain gets propagated between nodes 104. In short, whichever prong of the fork grows the longest becomes the definitive blockchain 150. Note this should not affect the users or agents of the network as the same transactions will appear in both forks.
According to the bitcoin blockchain (and most other blockchains) a node that successfully constructs a new block 104 is granted the ability to newly assign an additional, accepted amount of the digital asset in a new special kind of transaction which distributes an additional defined quantity of the digital asset (as opposed to an inter-agent, or inter-user transaction which transfers an amount of the digital asset from one agent or user to another). This special type of transaction is usually referred to as a "coinbase transaction", but may also be termed an "initiation transaction" or "generation transaction". It typically forms the first transaction of the new block 151n. The proof-of-work signals the intent of the node that constructs the new block to follow the protocol rules allowing this special transaction to be redeemed later. The blockchain protocol rules may require a maturity period, for example 100 blocks, before this special transaction may be redeemed. Often a regular (non-generation) transaction 152 will also specify an additional transaction fee in one of its outputs, to further reward the blockchain node 104 that created the block 151n in which that transaction was published. This fee is normally referred to as the "transaction fee", and is discussed blow.
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.
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, CPUs, 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 [EPROM; 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.
When a given party 103, say Alice, wishes to send a new transaction 152j to be included in the blockchain 150, then she formulates the new transaction in accordance with the relevant transaction protocol (using the wallet function in her client application 105). She then sends the transaction 152 from the client application 105 to one or more blockchain nodes 104 to which she is connected. E.g. this could be the blockchain node 104 that is best connected to Alice's computer 102. When any given blockchain node 104 receives a new transaction 152j, it handles it in accordance with the blockchain node protocol and its respective role. This comprises first checking whether the newly received transaction 152j meets a certain condition for being "valid", examples of which will be discussed in more detail shortly. In some transaction protocols, the condition for validation may be configurable on a per-transaction basis by scripts included in the transactions 152. Alternatively the condition could simply be a built-in feature of the node protocol, or be defined by a combination of the script and the node protocol.
On condition that the newly received transaction 152j passes the test for being deemed valid (i.e. on condition that it is "validated"), any blockchain node 104 that receives the transaction 152j will add the new validated transaction 152 to the ordered set of transactions 154 maintained at that blockchain node 104. Further, any blockchain node 104 that receives the transaction 152j will propagate the validated transaction 152 onward to one or more other blockchain nodes 104 in the network 106. Since each blockchain node 104 applies the same protocol, then assuming the transaction 152j is valid, this means it will soon be propagated throughout the whole network 106.
Once admitted to the ordered pool of pending transactions 154 maintained at a given blockchain node 104, that blockchain node 104 will start competing to solve the proof-of-work puzzle on the latest version of their respective pool of 154 including the new transaction 152 (recall that other blockchain nodes 104 may be trying to solve the puzzle based on a different pool of transactions154, but whoever gets there first will define the set of transactions that are included in the latest block 151. Eventually a blockchain node 104 will solve the puzzle for a part of the ordered pool 154 which includes Alice's transaction 152j). Once the proof-of-work has been done for the pool 154 including the new transaction 152j, it immutably becomes part of one of the blocks 151 in the blockchain 150. Each transaction 152 comprises a pointer back to an earlier transaction, so the order of the transactions is also immutably recorded.
Different blockchain nodes 104 may receive different instances of a given transaction first and therefore have conflicting views of which instance is 'valid' before one instance is published in a new block 151, at which point all blockchain nodes 104 agree that the published instance is the only valid instance. If a blockchain node 104 accepts one instance as valid, and then discovers that a second instance has been recorded in the blockchain 150 then that blockchain node 104 must accept this and will discard (i.e. treat as invalid) the instance which it had initially accepted (i.e. the one that has not been published in a block 151).
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"). 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.
2. 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 "Tx/". 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. Tx0and Txi are just arbitrary labels. They do not necessarily mean that Txois the first transaction in the blockchain 151, nor that Tx/ 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 preceding transaction Txo may already have been validated and included in a block 151 of the blockchain 150 at the time when Alice creates her new transaction Tx], or at least by the time she sends it to the network 106. It may already have been included in one of the blocks 151 at that time, or it may be still waiting in the ordered set 154 in which case it will soon be included in a new block 151. Alternatively Lto and Tv' could be created and sent to the network 106 together, or Tx° could even be sent after DO if the node protocol allows for buffering "orphan" transactions. 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 Txo comprises a particular UTXO, labelled here UTX00. 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. Typically the locking script locks the amount to a particular party (the beneficiary of the transaction in which it is included). 1.e. the locking script defines an unlocking condition, typically comprising a condition that the unlocking script in the input of the subsequent transaction comprises the cryptographic signature of the party to whom the preceding transaction is locked.
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. Unlocking 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, UTX00 in the output 203 of Txo comprises a locking script [Checksig PA] which requires a signature Sig PA of Alice in order for UTX00 to be redeemed (strictly, in order for a subsequent transaction attempting to redeem UTX00 to 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 Txt comprises a pointer pointing back to Txt (e.g. by means of its transaction ID, TxID0, which in embodiments is the hash of the whole transaction Txo). The input 202 of at comprises an index identifying UTX00 within Txo, to identify it amongst any other possible outputs of Txo. The input 202 of Txr 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 Tn arrives 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). In embodiments this involves concatenating the two scripts: <Sig PA> <PA> I [Checksig PA] where "I I" represents a concatenation and "<...>" means place the data on the stack, and "[...]" is a function comprised by the locking script (in this example a stack-based language). Equivalently the scripts may be run one after the other, with a common stack, rather than concatenating the scripts. Either way, when run together, the scripts use the public key PA of Alice, as included in the locking script in the output of Txo, to authenticate that the unlocking script in the input of Tx, contains the signature of Alice signing the expected portion of data. The expected portion of data itself (the "message") also needs to be included in order to perform this authentication. In embodiments the signed data comprises the whole of Tx1 (so a separate element does not need to be included specifying the signed portion of data in the clear, as it is already inherently present).
The details of authentication by public-private cryptography will be familiar to a person skilled in the art. Basically, if Alice has signed a message using her private key, then given Alice's public key and the message in the clear, another entity such as a node 104 is able to authenticate that the message must have been signed by Alice. Signing typically comprises hashing the message, signing the hash, and tagging this onto the message as a signature, thus enabling any holder of the public key to authenticate the signature. Note therefore that any reference herein to signing a particular piece of data or part of a transaction, or such like, can in embodiments mean signing a hash of that piece of data or part of the transaction.
lithe unlocking script in Do meets the one or more conditions specified in the locking script of Tx° (so in the example shown, if Alice's signature is provided in Tx/ and authenticated), then the blockchain node 104 deems Tx/ valid. This means that the blockchain node 104 will add Tx/ to the ordered pool of pending transactions 154. The blockchain node 104 will also forward the transaction Tx/to one or more other blockchain nodes 104 in the network 106, so that it will be propagated throughout the network 106. Once Tx/ has been validated and included in the blockchain 150, this defines UTX00 from Troas spent. Note that Tx1 can only be valid if it spends an unspent transaction output 203. If it attempts to spend an output that has already been spent by another transaction 152, then Txi will be invalid even if all the other conditions are met. Hence the blockchain node 104 also needs to check whether the referenced UTXO in the preceding transaction Tx° is already spent (i.e. whether it has already formed a valid input to another valid transaction). This is one reason why it is important for the blockchain 150 to impose a defined order on the transactions 152. In practice a given blockchain node 104 may maintain a separate database marking which UTX05 203 in which transactions 152 have been spent, but ultimately what defines whether a UTXO has been spent is whether it has already formed a valid input to another valid transaction in the blockchain 150.
If the total amount specified in all the outputs 203 of a given transaction 152 is greater than the total amount pointed to by all its inputs 202, this is another basis for invalidity in most transaction models. Therefore such transactions will not be propagated nor included in a block 151.
Note that in UTXO-based transaction models, a given UTXO needs to be spent as a whole. It cannot "leave behind" a fraction of the amount defined in the UTXO as spent while another fraction is spent. However the amount from the UTXO can be split between multiple outputs of the next transaction. E.g. the amount defined in UTX00 in Txocan be split between multiple UTX0s in Tx/. Hence if Alice does not want to give Bob all of the amount defined in UTX0o, she can use the remainder to give herself change in a second output of Txl, or pay another party.
In practice Alice will also usually need to include a fee for the bitcoin node 104 that successfully includes her transaction 104 in a block 151. If Alice does not include such a fee, Tiro may be rejected by the blockchain nodes 104, and hence although technically valid, may not be propagated and included in the blockchain 150 (the node protocol does not force blockchain nodes 104 to accept transactions 152 if they don't want). In some protocols, the transaction fee does not require its own separate output 203 (i.e. does not need a separate UTXO). Instead any difference between the total amount pointed to by the input(s) 202 and the total amount of specified in the output(s) 203 of a given transaction 152 is automatically given to the blockchain node 104 publishing the transaction. E.g. say a pointer to UTX0o is the only input to Txl, and Tx/ has only one output UTX01. If the amount of the digital asset specified in UTX00 is greater than the amount specified in UTX01, then the difference may be assigned (or spent) by the node 104 that wins the proof-of-work race to create the block containing UTX0/. Alternatively or additionally however, it is not necessarily excluded that a transaction fee could be specified explicitly in its own one of the UTX0s 203 of the transaction 152.
Alice and Bob's digital assets consist of the UTX05 locked to them in any transactions 152 anywhere in the blockchain 150. Hence typically, the assets of a given party 103 are scattered throughout the UTX05 of various transactions 152 throughout the blockchain 150.
There is no one number stored anywhere in the blockchain 150 that defines the total balance of a given party 103. It is the role of the wallet function in the client application 105 to collate together the values of all the various UTX0s which are locked to the respective party and have not yet been spent in another onward transaction. It can do this by querying the copy of the blockchain 150 as stored at any of the bitcoin nodes 104.
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. SIDE CHANNEL As shown in Figure 1, the client application on each of Alice and Bob's computer equipment 102a, 120b, respectively, may comprise additional communication functionality. This additional functionality enables Alice 103a to establish a separate side channel 107 with Bob 103b (at the instigation of either party or a third party). The side channel 107 enables exchange of data separately from the blockchain network. Such communication is sometimes referred to as "off-chain" communication. For instance this may be used to exchange a transaction 152 between Alice and Bob without the transaction (yet) being registered onto the blockchain network 106 or making its way onto the chain 150, until one of the parties chooses to broadcast it to the network 106. Sharing a transaction in this way is sometimes referred to as sharing a "transaction template". A transaction template may lack one or more inputs and/or outputs that are required in order to form a complete transaction. Alternatively or additionally, the side channel 107 may be used to exchange any other transaction related data, such as keys, negotiated amounts or terms, data content, etc. The side channel 107 may be established via the same packet-switched network 101 as the blockchain network 106. Alternatively or additionally, the side channel 301 may be established via a different network such as a mobile cellular network, or a local area network such as a local wireless network, or even a direct wired or wireless link between Alice and Bob's devices 102a, 102b. Generally, the side channel 107 as referred to anywhere herein may comprise any one or more links via one or more networking technologies or communication media for exchanging data "off-chain", i.e. separately from the blockchain network 106. Where more than one link is used, then the bundle or collection of off-chain links as a whole may be referred to as the side channel 107. Note therefore that if it is said that Alice and Bob exchange certain pieces of information or data, or such like, over the side channel 107, then this does not necessarily imply all these pieces of data have to be send over exactly the same link or even the same type of network.
4. TRANSACTION FUNDING 4.1 Data funding Generally speaking, UTXO-based blockchains can be seen as a cash system, where each unspent transaction outputs (UTXO) is a coin that can be spent only once. Each payment transaction consumes one or more UTX0s and creates one or more new UTX0s.
Figure 3 illustrates an example system 300 which may be used to increase scalability. The system comprises a funding service 301 that manages UTX05 using a service called a transaction builder (TxBuilder) 302 which holds a cache of several unspent transaction outputs (UTX0s). Given some data, the purpose of the TxBuilder 302 is to embed the data in a transaction that can be then published on the blockchain 150.
The TxBuilder 302 receives funds (i.e., (JTX05) from the funding service 301 split into fixed values el, ek. These UTX05 are cached by the TxBuilder 302 into k buckets according to their values el, ek, each bucket having a maximum capacity of Q UTX05. Herein, el, ...,ek are referred to as denominations. Assume a client 303 (e.g. user application 105) requires storage of data D, the executed protocol steps are shown in Figure 3 and are detailed below: 1. The client 303 calls the TxBuilder 302, requesting storage of data D. 2. The TxBuilder 302 creates a transaction that embeds the data D: a. The TxBuilder 302 funds the transaction using the cached UTX05 from the Funding Service 301 and adds the required change outputs.
b. If it does not have enough UTX0s of a certain denomination type in the cache, the TxBuilder 302 requests more denominations from the Funding Service 301.
3. The TxBuilder 302 sends the transaction to the funding service 301.
4. The funding service 301 sends the transaction to the broadcaster service 304.
5. The transaction is broadcast to the Bitcoin SV blockchain using the mAPI service.
6. The client 303 is notified that the data has been stored together with an inclusion proof (e.g. transaction ID containing the data together with a Merkle inclusion proof).
Each of the funding service 301, transaction builder 302, client 303 and broadcaster service 304 are components that may be implemented in hardware or software.
4.2 Dust limit Some blockchains have a dust limit. The dust limit prevents transactions with very low value from being published. The reason for having a dust limit is that under the standard fee policies, a very low value output would require a higher fee to spend than the value of the output itself, making these transactions uneconomical to spend (the cost of the unlocking script would be higher than the UTXO value).
Another reason for setting a dust limit is to prevent dusting attacks. Dusting attacks are used by scammers to deanonymize transactions, revealing individuals or organizations behind a wallet. Scammers can "dust" a large number of addresses, wait for wallets to spend these dust outputs and then perform analysis to reveal which of these addresses belong to the same wallet.
4.3 Consolidation transactions A consolidation transaction is a transaction that reduces the number of UTX05 by a margin that is more valuable for the network than the corresponding transaction fee. From a node's point of view the size of the UTXO database matters because the larger it is the higher the cost of maintaining it, for this reason it is in a node's economic interest to trim the UTXO where possible. Consolidation transactions, which have many inputs and few outputs, result in a shrinking of the UTXO database.
In general, a transaction is considered a consolidation transaction if: * The input/output ratio is at least 1 to 100 (at least 100 inputs for each output).
* It only uses standard P2131(FI inputs or bare multi-sig outputs with no more than two signatures.
* It only uses inputs confirmed for at least 6 blocks.
5. OPTIMISATION ALGORITHMS 5.1 Change-Making Problem (CMP) The change-making problem (CMP) addresses the question of minimising the number of coins of certain denominations that sum up to an amount S. The question can be formulated as a minimisation problem. Given a set of denominations el, e k and an amount S, solve: Ic subject to Wtei = S, Wt E N>o 1=1 where w1 is the number of denominations of value e1. This problem can be solved with dynamic programming in a similar manner as the 0-1 Knapsack problem. Let amp[8,E] be the minimum number of coins used to fund the amount E using the first S denominations.
We define cmp[S,E] as follows: co, 8=0 1, es = E cmp[5 -1,E], es > E min(cmp [8 -1, E], 1 + cmp[6,E -e5]), otherwise We discuss each case: * The first case is trivial, and says that we cannot solve the minimisation problem without any denominations. We use infinity co to denote this.
* In the second case, if the 6th denomination es equals the amount E, then E is paid for using es. Thus, the minimum number of coins we use is 1.
* In the third case the 6th denomination is too large to pay for E. Then the minimum number of coins is attained using the first 8 objects is equal to the maximum value attained using the first -1 objects.
cmp[8,X] = 1 * Finally, in the fourth case either the minimum value is attained using the first 8 -1 denominations or by including the 8th denomination ea.
5.2 Simulated Annealing Many problems are computationally intractable (NP-hard) through a deterministic algorithm. To approximate the solution of such difficult problems we can use heuristic algorithms such as Simulated Annealing, Tabu Search or Genetic algorithms that have proven to give reliable results to optimisation problems.
Simulated Annealing (SA) results in a fast convergence to an answer. This is a heuristic algorithm designed to approximate the global minimum of a function f (x) that has a large domain D of values x. In order to heuristically search for values f (x) close to the global minimum we start with an initial approximator x0 E D and parameters To, limb, and 0 < p < 1. T0 and Tint?, are called temperatures and p is the percentage at which the temperature decreases from T0 to Tinto,. The search for the global minimum also depends on a function neighbour that outputs a value the function f is evaluated on.
The pseudocode of the algorithm is the following: 1. Define Xbest X0, T e To.
2. While T > Ttntn execute: a. Find an approximator in the neighbourhood of xh"t: x"w ne ig hbour (xb"t).
b. Compute f (x"w).
c. Compute Af =f -f (xb"t).
i. If af C 0, then the value x"w improves on the output of the function f and it becomes the current best approximator Xbest Xnew * _af ii. If Af > 0, then we define the exponential value p = e. If p is larger or equal than a value c randomly sampled from the uniform distribution U(0,1), then we assign the new approximator to xbest: xbest Xnew* d. T T (1-p). 3. Output f (xb"t).
We expand on the steps above to give the intuition of this algorithm. If we want to improve on the value f (xb"t), we derive a new approximator x", from the current best approximator xb"t in Step 3.a. If the neighbouring approximator x", improves on the value f(xb"t), we update the approximator)(best in Step 3.c.i.
The idea of this algorithm is that if x"w does not improve on the value flie 1 then we bestn may still accept it as long as p > c in Step 3.c.ii. This condition allows for the algorithm to escape local minima of f at the cost of temporarily increasing the value of f in order to approximate the global minimum. This is shown in Figure 4.
The value T starts at a positive value To and is decreased by multiplication with the drop rate p in Step 3.d, until it reaches a value Tmtb close to 0. This ensures that at the start of the algorithm we escape local minima more frequently in Step 3.c.ii. As T decreases and approaches 0, the value of p approaches 0 and accepting non-optimal approximators xnew becomes less likely. In this case the algorithm focuses on improving the global minimum approximator using Step 3.c.i. When implementing the algorithm, we may define the function neighbour. This is problem dependent.
6. OPTIMISING TRANSACTION SIZE Embodiments of the present disclosure relate to optimizing a size of a transaction, and determining a set of precomputed denominations that provides the best trade-off between transaction size and time to identify and retrieve UTX0s. This is useful for high-throughput applications or applications that need parallelisable transaction creation. Figure 5 illustrates an example system 500 for implementing the described embodiments. As shown, the system 500 includes an optimizer 502 that has access to a store of UTXOS 501. The optimizer 502 is configured to connect directly or indirectly to the blockchain network 106.
In an example implementation, the optimizer 502 may take the form of, or comprise, the transaction builder 302 of Figure 3. In this implementation, the optimizer 502 may additionally comprise one or both of the funding service 301 and the broadcaster service 304. The optimizer may be operated by a user such as Alice 103a or Bob 103b. In general, the optimizer may be implemented in hardware or software, or a combination.
The optimizer 502 obtains a transaction template. The optimizer 502 may generate the transaction template or receive the transaction template from a different entity, e.g. a client application 303, a user 103, etc. The transaction template may have a structure similar to that shown in Figure 2. The transaction template includes at least one input and at least one output. Each input to the transaction has an associated value. Each output of the transaction may be a spendable output or an unspendable output. An unspendable output has no associated value, whereas a spendable output does. The transaction template includes target data. Each input has an associated input fee that contributes to a total transaction fee. Each output also has an associated output fee that contributes to the total transaction fee. Similarly, the target data has an associated data fee that contributes to the total transaction fee. The fees are typically based on the size of the relevant field, e.g. a fee per byte. The total amount of the value(s) of the input(s) must be at least equal to a sum of the total amount of the value(s) of the output(s) and the transaction fee. If not, the transaction may (or will) be rejected when submitted to the network 106.
The UTXO store 501 contains a plurality of UTX05 which are available for being input to the transaction. The UTXO store 501 may be operated by the optimizer 502. The optimizer 502 is configured to communicate with the UTXO store to determine which UTX05 are available. In some examples, the UTXO store contains UTX05 of only certain values, e.g. of only a single value. That is, the UTXO store contains UTX0s of predetermined values and only UTXO of those predetermined values are added to the UTXO store. In other examples, the UTXO store contains UTX0s of varying values. In other words, the UTXO store contains UTXO of any value and there is no processing involved in adding or removing UTX05 of certain values. In some examples, the UTX0s are ordered from smallest value to highest value (or vice versa) in order to make searching of the UTXO store 501 more efficient.
The optimizer 502 determines the number of inputs of each particular value that are required to fund the transaction. The optimizer 502 also determines the number of additional outputs of each particular value (i.e. other than the output containing the target data) that are required. One or more additional outputs may be required so as to prevent excess fee leakage and/or create UTX05 of certain values for future use. In other words, the optimizer 502 determines a number of inputs and outputs having a first value, a number of inputs and outputs having a second value, and so on, for each value of UTXO available to the optimizer 502. Note that the number of inputs and outputs of a certain value may be zero. Similarly, the number of inputs having a certain value may be different to the number of outputs having the same value.
Moreover, rather than just determining any number of inputs and outputs of particular values, the optimizer 502 determines the minimum number of inputs of each value and the minimum number of outputs of each value that satisfies a set of funding criteria. This is done by minimising, for each different UTXO value, a sum of a) the number of each different input UTXO value multiplied by the associated input fee, and b) a sum of bi) the number of each different output UTXO value multiplied by the associated output fee, and bii) a leftover fee. The minimization is subject to several constraints, discussed below.
Once the optimizer 502 has determined the optimal number of inputs and outputs of different values, the optimizer 502 causes the completed transaction to be sent to the blockchain network 106. For example, the optimizer may submit the transaction to the network 106. Or, the optimizer may send the transaction to a different entity or component (e.g. broadcaster service 304) to be sent to the network 106.
Described in mathematical terms, the optimizer 502 may determine which UTX0s to use to fund the transaction by minimizing the following equation: min ( 1 wi feet?, +1w; fee,", + fee, where wi is the number of UTX0s input to the transaction having a respective value corresponding to the index i, leen, is the input fee, wi is the number of UTX05 of the transaction (i.e. the outputs) having a respective value corresponding to index i, fee,,,, is the output fee, and fee, is the leftover fee. The leftover fee is discussed below.
The equation is minimised subject to the following conditions: i) a total value of the UTX0s input to the transaction must be at least equal to the data fees and the leftover amount, the number of each input UTXO must be zero or more, the number of each output UTXO must be zero or more, and the leftover amount must be between zero and a maximum of a predetermined upper bound and a sum of the input fee and the output fee.
Minimizing the equation thus outputs a respective number of input UTX0s at each value and a respective number of output UTX0s at each value (where the number of a UTXO at a given value may be zero). It is particular advantageous to use a set of predetermined UTXO values to fund the transaction.
The leftover fee is calculated based on a leftover amount. For each possible solution to the equation, the respective values of the transaction's input(s) are summed to give a total input value. The respective values of the transaction's output(s) are summed to give a total output value. The total transaction fee is determined based on the input fees, the output fees and the data fees. The leftover amount is then determined as the difference between the total input value and the sum of the total output value and the total transaction fee.
The optimizer 502 may then determine the leftover fee by inputting the leftover amount into a fee decision algorithm.
The fee decision algorithm outputs one of three leftover amounts. If the leftover amount is less that the total of a single input fee and a single output fee, then the fee decision algorithm outputs the leftover amount as the leftover fee. If the leftover amount is instead more than the total of a single output fee and the dust limit, then the fee decision algorithm outputs the sum of a single output fee and a single input fee as the leftover fee. If the leftover amount takes any other value, the fee decision algorithm outputs infinity as the leftover fee. This signals that there are not enough inputs, and that the equation can minimised further. In other words, the minimisation of the equation requires a different number of inputs and outputs.
The above equation may be solved using a dynamic programming approach, as described in section 7.4 below. For instance, a modified change-making problem algorithm may be used to solve the equation. The change-making problem algorithm per se is well-known. However in its original form it is not suitable for solving the equation above. This is because it does not take into account the specific features of the blockchain, including fees for adding inputs and outputs to a transaction, and the dust limit. The present disclosure thus recognises how the change-making problem algorithm is to be adapted in order to solve the equation and optimise transaction funding.
In some examples, the UTXO store comprises UTX05 of varying values. In other examples, the UTXO store comprises UTX05 of set values. That is, each UTXO has a value equal to one of a predefined set of values. For example, the UTXO store may comprise UTX0s that have one of two predefined values, or three predefined values, etc. In other words, the UTXO values are not random.
The optimizer 502 may use the embodiments above to optimize a plurality of transactions. In some examples, each transaction has the same type and size of target data and therefore has the same associated data fee. Therefore the same number and value of the input UTX0s and output UTX05 may be used for each of the plurality of transactions.
As stated above, embodiments relate to determining the optimal set of denominations (UTXO values) for a given funding scenario, i.e. for a transaction with target data up to a maximum data size! maximum data fee. This optimal set of denominations may then be used as the UTXO pool accessible by the optimizer 502, as described above. That is, given the optimal set of denominations, the optimizer may determine the number of, and the value of, the inputs and outputs of a given transaction so as to minimise the size of that transaction.
The optimizer 502 may determine the optimal set of denominations (also referred to as UTXO values or input values) by minimizing a function. The function may be referred to as a "denomination function". The denomination function is evaluated based on a plurality (likely many) different sets of denominations. Each pair of sets of denominations differs in at least one denomination. For illustrative purposes, one set may contain denominations 1, 2 and 3, another set may contain denominations, 1, 3 and 5, another set may contain denominations 9, 17, and 100, and so on. That is, two or more sets may contain one or more denominations of the same value. Similarly, two or more sets may contain no denominations of the same value. In some examples, the smallest denomination is at least equal to the dust limit.
The denomination function is based on the following variables: i) the total amount of fees of the respective transaction (taking into account all input fees, output fees, and data fees); ii) the maximum fee data fee that any given transaction fee will have due to the target data included in that transaction; iii) the total value of all denominations required to fund a set of transactions; iv) a total number of spendable (i.e. change outputs) of across the set of transactions; v) an initial number of instances of each denomination available to the optimizer; and vi) a total number of transactions that are to be funded using the set of denominations.
In some examples, the optimizer 502 obtains the UTX05 used to fund a transaction from a separate pool of UTX0s (e.g. maintained by the funding service 301). In these examples, the denomination function may also be dependent upon the number of communications between the optimizer and the UTXO pool (or host of the UTXO pool), where each communication is a request for the initial number of instances of each denomination.
The denomination function is evaluated using a plurality of different sets of denominations. The set of denominations that results in the minimum value of the function is the optimal set of denominations. The optimal set of denominations may be used by the optimizer 502 when funding one or more transactions, e.g. using one of the algorithms described above or below in section 7.4 and 7.5.
The denomination function is first evaluated with an initial set of denominations, then a second set of denominations (which differs from the initial set), then a third set (which differs from the first and second sets), and so on. In some examples, a "neighbour function" may be used to determine each next set of denominations to be evaluated. Each denomination is assigned an index, e.g. from 1 to k (where k is the total number of denominations). The neighbour function works by sampling an index from 1 to k, then selecting the corresponding denomination to form part of the next set.
In general any suitable heuristic technique may be used to minimise the denomination function. For instance, a genetic algorithm may be used. Alternatively, a simulated annealing algorithm may be used, as described in section 7.5 below.
7. EXAMPLE IMPLEMENTATIONS The section shows how some example transactions can be optimally funded using the described embodiments. We assume throughout that we want to create a transaction that contains the data payload D. The length of the data can be variable in size, encrypted or not. We define the optimal funding of such a transaction as finding the set of UTX05 that minimises transaction fees. This task is two layered: 1. Given a set of UTX05, which UTX05 should be spent to minimise the transaction fees? 2. Which is the best set of UTX05 that on average minimises transaction fees (as given in Question 1) for many funding requests of data payloads with varying sizes? 7.1 Setup We define an example scenario with reference to Figure 3. Assume a client service 303 calls the TxBuilder 302 requiring funding for data D. The TxBuilder 302 then constructs a transaction with the necessary inputs and change outputs. For example, the transaction may take the following form: Tx Inputs Outputs Value Unlocking Script Value Locking Script ini <5191> <P1> anti [P2PKH Pont] in2 <Si92> <P2> 0 OP FALSE OP RETURN <D> inn <Sign> <Pn> Fees: n * f ee * + f eeont + f eeD where are amounts controlled by the Funding service 301, and the first output is the change returning outi Satoshis to the service 301. Each unlocking script (i.e., each input) has an associated transaction fee feein and similarly the P2PKH locking script (i.e., output 0) has an associated fee f eeont. Furthermore, the UTX0s unlocked by the inputs need to cover the data fees f eeD associated with data D (i.e., output 1). More concretely, we have: + in2 + *** + inn = outi + feeont + n * f eau,. + feeD + The column "Value" shown as being part of the Input is not part of the transaction, but is shown to illustrate the amount of Satoshis to unlock. The row "Fee"s is not part of the transaction, but is shown to illustrate the amount of transaction fees.
As it is very unlikely that the sum of the available input values ini equals the required fees (f eeont + n * f ee + f eeD), we usually provide a higher amount of 36atoshis than required. We use the notation E to denote any remaining amount of 36atoshis that can be used to cover fees for a change output), or it can be left to the miner as additional fees. We call E an excess term or leftover amount.
E = in -(Mai feennt + n * fee + feeD) We consider the following example: * in1 = 300 SAT, in2 = 448 SAT; 5 * feeD, = 74 SAT, feennt = 17 SAT; * data D has size 800 bytes, the fee rate is 0.5 SAT/byte, and consequently feeD = 400 SAT.
We can pay for feeD using int and in2. We derive the value of the change output outi from the formula: + in2 = outi + feennt + 2 fee," + feeD + e Then E = 183 SAT. E can be left as additional fee to the miner or returned to the payer as change. Paying an additional feeent to create the new output, we can create an additional change output worth 164 SAT (C -feemit).
Hereinafter, the following assumptions are made: * feeD also includes the fees necessary to pay for the transaction header and auxiliary information (nVersion, locktime, number of inputs, number of outputs).
* We consider the specific case of data funding, but the techniques are generalisable to fund transactions that have several spendable outputs.
* recant fee in < Id, where /d is the dust limit. The inequalities hold when using P2PKH unlocking scripts and locking scripts where at a rate of 0.5 SAT/byte we have: of e co = 17 SAT, corresponding to a standard P2PKH output: lic * 25 bytes for P2PKH locking script (20 bytes for public key hash + opcodes) * 8 bytes to encode the value (in satoshis) * 1 byte for variable-length script size of eein = 74 SAT, corresponding to a P2PKH unlocking script which is at most 148 bytes: * 40 bytes for spending UTXO reference (32 bytes TxID + sequence number) * up to 108 bytes for P2PKH unlocking script (up to 73 bytes ECDSA signature + 33 bytes public key + opcodes) * 1 byte for variable-length script size o The dust limit in Bitcoin is currently set at ld = 135 SAT for P2PKI-Iscripts.
* fee", feet?, and Id are fixed constants because we fix the script type, whereas fees can vary.
7.2 Variable UTXO values One option to create a transaction that funds storing data D on-chain is to spend the required outputs from a UTXO pool containing UTX05 of variable amounts. We show four example funding scenarios. For the purpose of simplifying computations, we assume the data transaction fees fees = 226 SAT.
7.2.1 Example 1
The UTXO pool contains 3 UTX05 with values 200 SAT, 310 SAT and 430 SAT.
The funding of data D that minimises transaction fees is to select in1 = 310 SAT, which covers feein, fees and an additional E = 10 SAT fee is left to the miner. The transaction is: Tx Inputs Outputs Value Script Value Script int = 310 SAT [unlocking script] 0 SAT OP FALSE OP RETURN <D> Fees: 300 SAT = fee i -F fees E = 10,S'Ali (left to miner) In this example we cannot add a change because feemit > E. It is worth noting that using the higher UTXO, worth 430 SAT, would allow to create a change output and collect the change. However, the cost of the new output (f eema = 17 SAT) would be higher than leaving the currents to the miner.
7.2.2 Example 2
The UTXO pool contains 3 UTX05 with values 200 SAT, 500 SAT and 800 SAT.
The funding of data D that minimises transaction fees is in1 = 500 SAT, which covers feein, feeD and the output fee feennt for a change output. The transaction is: Tx Inputs Outputs Value Script Value Script ini = 500 SAT [unlocking script] 183 SAT [locking script] 0 SAT OP FALSE OP RETURN <D> Fees: 300 SAT = feei + feennt + feeD e = 200 SAT (feeont + change) An alternative (more expensive) solution would be to only have the data output and omit the change. This would lead to an additional 200 SAT fee left to the miner (change + feeout).
7.2.3 Example 3
The UTXO pool contains 3 UTX05 with values 200 SAT, 250 SAT and 350 SAT.
The funding of data D that minimises transaction fees is to select in1 = 350 SAT which covers feet,/ feeD and an additional E = 50 SAT fee is left to the miner. The transaction is: Tx Inputs Outputs Value Script Value Script [unlocking = 350 SAT 0 SAT OP FALSE OP RETURN <D> script] Fees: 300 SAT = fee, + feeD E = 50 SAT (left to miner) In this example feeout < E, so we can add a change output, but doing so would result in an output that is less than the dust limit /d which is not allowed by policy.
7.2.4 Example 4
The UTXO pool contains 3 UTX05 with values 250 SAT, 280 SAT and 290 SAT.
The funding of data D that minimises transaction fees is to select ind = 250 SAT and in2 = 280 SAT which cover 2f eein, feeD and the output fee feecrut for a change output. The transaction is: Tx Inputs Outputs Value Script Value Script ind = 250 SAT [unlocking script] 139 SAT [locking script] in2 = 280 SAT [unlocking script] 0 SAT OP FALSE OP RETURN <D> Fees: 300 SAT = feel + feeaut + teen E = 230 SAT (f.Th+ feeout + change) In this example we needed to combine two inputs to cover all required transaction fees. This scenario is more expensive in comparison to the above examples as we have to pay a fee fee,,, for each input.
7.3 Implementation The examples discussed can be generalised according the following formula: = fee,fl + feeD + E, where the value of the input in1 is used to cover the fees for the input f eeD, and the fees for the data feeD. As already mentioned, any remaining amount of satoshis is called excess term a The excess term e can be left to the miner as additional reward or it can be returned to the transaction funder in the form of change output. As the choice of the funding a UTXO (ini) determines the value of e, choosing the optimal in1 is important in this process. The reason is that this determines what can be done with e: leave it to the miner or return it to the funding service 301 as change output.
Assuming a dust limit ld > feein we identify four scenarios (see Figure 5), depending on the value of e: 1. e < feema (solid line) In this case we cannot add a change output since e is not enough to cover the additional transaction fee fee"t to create the output locking script for the change transaction. a is left to the miner as additional reward.
2. feeput < f eetn+ fee", (small dashed line) Also in this case we cannot add a change output, a would be enough to cover the additional transaction fee feema but the resulting output is below the dust limit 1. a is left to the miner as additional reward.
3. feet?, + fee"t a < fee"t + Id (double line) In this case is favourable to create a change output and collect E. As the resulting change would still be below the dust limit Id, an additional input in2 is required to increase a above the threshold ld. With the addition of another input, the total transaction fee becomes 2 * feeiii+ feectit + feeD, and the remaining E is returned as output change.
4. E feenitt + ld (large dashed line) Also in this case is favourable to create a change output and collect a Differently from the previous case, here the change is already above the dust limit and there is no need to add an additional input. The total transaction fees therefore are feein+ fee"t + feeD and the remaining e is output change.
The 4 scenarios determine if the excess term can be collected in a change output or has to be left to the miner as additional fee. They can be summarised in a function as follows: fee_decision Input: E Output: additional transaction fees 1. If e < feein + fee"t then output E. 2. Otherwise if feeD, + fee"t E < feectit + ld then output fee"t + feet,.
3. Otherwise, output f eeout* 20 fee_decision is a specific example of the fee decision algorithm described in section 6.
Based on the four scenarios described in Figure 5, the funding protocol chooses the funding UTXO ini, among the ones available in the pool, that reduces the fees to be paid to the miner. Given teeth. + feeD (the minimum amount to be paid to publish a transaction embedding data D) we build the transaction with minimum fees. This is done by ordering the strategies from the best (lowest additional transaction fee) to the worst (highest additional transaction fee) that should be used when selecting from the available UTX0s for funding the transaction: 7.4 Dynamic programming approach The approach presented in this section is based on the CMP algorithm presented in Section 5.1 above. CMP has two limitations. Firstly, it assumes that there are no transaction fees and secondly it does not take advantage of change. These limitations may lead to non-optimal transaction funding by not minimising fees. This is particularly relevant in blockchain transactions, as inputs and outputs have an associated fee.
Define the weights wi to be the number of inputs spending UTX0s of denomination et, and the weights w; to be the number of outputs of the denomination e1. The spent UTX05 pay for fees, input fees, output values, output fees and the excess term. This is captured by the following relation: wiei+ *** + wkek = fees + ei + *** + wk' ek +1w, feetn+ w; fee", + £ We subtract the term wit + *** + wek + Ei wi feet + Et w; feeout from both sides of the equation: wiei+ *** + wkek -wje, -*** -wk' ek - ees + E Furthermore, we rewrite the equation as follows: wi(ei -f ee in) + *** + wk(ek -f eetn)-wl(ei + fee") -*** - (ek + feeout) = fees + e This is the equation that the inputs, outputs and the excess term have to satisfy. Then the minimisation problem we solve is the following: min ( wi fee-+ w fee0ut + fees subject to w1 (e1 f eein) * ± wk(ek -wit (el feeout) -(ek + fee") = fees + E, w, w[ E 1k1=°, 0 < E < max{E,feeout + Rein} where fee, = fee_decision(e) fore < feeDi+ feemit and E > Ld feeout, otherwise fee, = co. The value E is an upper bound for the excess term which has to be chosen as input to the problem. We detail this later.
We discuss the minimisation problem: * The first line of the problem says that we want to minimise transaction fees by reducing the values of wi, wl or * The second line introduces the first constraint of the minimisation: we can minimise fees subject to covering the data fees feeD and any excess term E. * The second and third constraints bound the values of wi, w: and a When the upper bound E is very high (e.g. E = 2 * ek + fee.), then w = *** = wr; = 0 and consequently if a change output is created, it values a This choice can be made if in practice splitting the output into denominations is too expensive in terms of transaction fees. This can be the case if too many UTX05 of small denomination values have to be created. Then it is better to create an additional transaction that spends multiple UTX05 of value E and turns them into denominations.
On the other hand, if E < fee"", + feel, then E < fee., + tee1. and the minimisation will create outputs using the value of the denominations. The value E is left to the miner as additional transaction fees.
The minimisation introduces two problems that require us to change the CMP algorithm: * the terms w:(ek + fee.,) are deducted (so increasing w: decreases the total value) and * the excess term E is variable.
One option is to use the minimisation algorithm described below.
Step 1: Deducting values The function below shows how to minimise transaction fees for each transaction that covers data fees >: < fees,. We assume E = 0 and discuss the excess term in Step 2.
compute_cmp_negative Inputs: ..., ek, f eeD 1. Execute the CMP algorithm defined in Section 5.1 on the denominations fel -f ee...,ek -f eethl with S = (ek -teem) * feet,.
This outputs a matrix cmp1i[6,E], 6 < k, E < S. Each element of the matrix at position (6,E) represents the minimum number UTX05 we have to spend to cover a fee < S using the first 6 denominations. We discuss the value S below.
2. Execute the CMP algorithm in Section 5.1 on the denominations {e, + ek + ee0} with S = (ek_,+ feemit) * f eeD.
This outputs a matrix cmp"t[6,C], 6 < k, C < S. Each element of the matrix at position (6, C) represents the minimum number UTX0s we have to spend to cover a fee C < S using the first cl denominations. We discuss the value S below.
We use the following notation: Eiji = CMPin [kfr (C E)2 = CMPin[k, C E] and Cout = cmpoiark,C1.
3. Define the one-dimensional array cm/Linea computing the minimum transaction fees as follows: 4.
cmpneg [E] = min (E in * fee, min (C + X) eep, + Cant * feeout), E feeD c>o where C = vi4(ei + f ee "t) + * ** + (ek + fee") and C + X = wi(ei - + *** + wk(ek -f eetn)-Then either the fee E is covered with no change and then ED, * feein is the minimum transaction fee, or the fee E is covered by deducting C from the amount C +E. In the latter case, the minimum transaction fee required to cover E is given by (C + E)* * f ee * + Cnnt * feennt.
5. Output the array cmp"a.
Then the transaction that covers the data fees feeD has the minimum transaction fee crinPneg [f ee D].
The amounts (ek -fee) * fees and (ek_i + f eeont) * fees represent the worst case scenario where to cover f eeD we need to spend wk f eeD UTX05 of value ek and create wkr_i fees outputs of value ek_i such that ek -feein-(ek_i + feet:) = 1.
This means we only cover 1 SAT unit with each input, output pair. By creating the transaction with f eeD inputs, subtracting the outputs and associated input and output fees, we then cover f eeD. We have wk(e k -feein)-wk_Jek_i + feeont) = fees.
The transaction below illustrates the values C and C + E: Tx Inputs Outputs Value Script Value Script ini [unlocking script] 0 SAT OP FALSE OP RETURN <D> in2 [unlocking script] outi [locking script] - ...
outcout [locking script] in(c+z)tn [unlocking script] Fees: (C + E)in * f eesu+ cots * feeout + E SAT The inputs spend C + E input fees. The total change outputs cover C -output fees.
Step 2: Excess term Finally, we solve the minimisation problem for variable excess terms 0 < e < max{E,f eeout + feein1 using the following function: compute_cmp_final Inputs: el, e2, ...,ek, f eeD, E 1. Execute compute_neg_final with inputs e1, ...,ek and f eeD + max{E,f ee", + feeD}. This outputs the array cm/3,2,g.
2. Define the one-dimensional array cmp at computing the minimum transaction fees as follows: cmP finat [E] = Ci.E<max t+feeinj cmPneg [E + e] + fees, E f eeD tEnl[ein em, 3. Output the array cmp Then the minimum transaction fee to cover the data fees feed for variable excess E is crriP f inal[f ee Di-Once cmp f buil has been computed, for each data fee E < feed we can create a transaction in worst case time 0(f eed lei). Furthermore, each transaction has minimum fees and its construction is faster than the Greedy approach describe above if f ee /el is lower than k. The CMP algorithm requires 0(kS) space. We can further optimise this by rewriting the recurrence as: / 00, = 0 1, e5 =E cmp [6 mod 2,E] cmp[(6 -1) mod 2,E], es > E min(cmp[(6 -1) mod 2,E], 1 + cmp[6 mod 2,E -es]), otherwise This gives a space complexity of only 0(S) requiring the allocation of a matrix of size 2 X S. We discuss the optimisation and refer to Section 5.1 for the CMP algorithm. In Section 2.2.1 the computation of cmp[6, X] depends only on the value cmp[6 -1,E] and cmp[6,E -es].
Thus, to compute the (5 row of the matrix cmp we only need the current row 6 and the previous row 8 -1. Using this observation, we only need two rows in the matrix, the (6 mod 2)th row acting like the 5 row and the (6 -1 mod 2)th row acting like the 6 -1 row.
If we do not want the change output to be split into denominations, it is sufficient to set E = 2 * ek + feemit. In this case the solution is to fund f cep only with denominations of value e k * The advantage of splitting the output into denominations is that the UTX0s can then be directly stored in the funding service UTXO pool. If we choose not to split the change output into denominations, then an additional transaction has to be created in order to split the funds into denominations. Whereas both options require additional transaction fees (either because we have more outputs, or because we create another transaction), it requires less fees to split the output into denominations and avoid creating another transaction.
7.5 Finding denominations This section describes a technique for finding the set of denominations that minimise the size of transactions and consequently minimise the transaction fees feeD.
S
7.5.1 Methodology We define a function [that measures the fitness of a set of denominations el, ... Jek when used to fund a large number of transactions N of different sizes. In genetic algorithms, the fitness measures how close a given solution is to the optimum solution of the desired problem. The output of the function [aggregates several measurements of the set to fund each of the N transactions. We want to find the set of denominations that gives the minimum value of the function f. Because there are infinitely many sets of denominations ek that can be used, finding the set that minimises the function f is intractable to solve using a deterministic algorithm. Thus, to find the set we use the heuristic Simulated Annealing (SA) algorithm introduced in Section 5.2.
7.5.2 Setup To run SA, we need to define the function f we wish to minimise and the function neighbour that selects at each iteration the next evaluation point for f.
We assume that the TxBuilder 302 is initially loaded with Q instances of each denomination Depending on which denominations are used in transactions, our experimental results show how many instances Q should the TxBuilder 302 load for each denomination ei. We fund a collection of N transactions each with different data fees feeD and define: * M the maximum value [CCD can take, * F the total transaction fees paid, * S the total value of all unlocked UTX05 used to fund all N transactions, and * 0 the total number of change outputs. The change outputs will have to be split into denominations.
Every time the TxBuilder 302 terminates to supply of UTX05 of denomination ei, it communicates with the funding service 301 asking for Q UTX05 of denomination ei. We define C as the number of communications between the funding service 301 and the TxBuilder 302 needed to fund all N transactions.
The function f is evaluated on the set el, ..., ek and returns a positive number: l(F+SM±o±c, /14 We discuss the definition of the function: * The first term of this equation computes the expected transaction fees normalised by the maximum size of a transaction fee M. * The second term measures how many funds need to be allocated to fund a transaction normalised by the maximum size of a transaction fee M. * The third term adds a penalisation term for the change outputs, since they will have to be split into denominations. This adds computational overhead.
* The last term measures the impact of the number of communications C, each requiring Q instances of a denomination to be transferred to the Tx Builder from the Funding Service.
* We divide the sum of all four terms by the number of transactions N to obtain to obtain a value that indicates the fitness of the set el, ..., ek per transaction.
Finally, the function neighbour takes as input a set of denominations el, ek and derives a new set. It executes the following three steps: 1. Sample with equal probability an integer i E {1, k} 2. Sample with equal probability an integer e E {/d,/d + 1, ...,M} 3. Return the set of denominations {el__ e, ei+1, ek) 7.5.3 Parameters 15 20 25 To run the SA algorithm using the optimal decomposition in Section 7.4.3, we choose the following parameters. These can be changed depending on specifications, without requiring any change of the algorithms.
* Set the maximum excess value to E = 2 * ek + fee". Since f increases in value with the number of communications, it will not be optimal to use only one denomination ek as we will see in the results below.
* Set the number of transactions to N = 3000 and the quantity Q = N lk for each denomination. This number is chosen based on the number of UTX0s we expect to load in the TxBuilder N = Q k.
* Assume the fee per byte is set to 0.5 SAT/byte, the dust limit /d is set to 135 SAT, and the transaction fees for the unlocking and locking scripts are -fees = 74 SAT and fee"t = 17 SAT respectively, corresponding to P2PKH scripts.
* The data fees are normally distributed with mean fees = 191 SAT.
We analyse two examples: when the standard deviation of the set of fees fees is 1 and when it is 30.
7.5.4 Experimental Results 7.5.4.1 Standard deviation 1 In this case 99.7% of data have fees tees between 189 and 193 SAT. This applies when the data fees are expected to mostly stay constant for all data transactions. The table below shows the results we have obtained by running the SA algorithm depending on the number of denominations k = 1, 3, 5 and 7.
k f (el, ... , ek) Set of Observed Qt. per et S (total funds required) F (total transaction fees) Initial Q denominations C1, ..., ek 1 1.54 272 3000 816000 SAT 816000 SAT 3000 3 1.25 280, 442, 461 2940, 60, 0 849720 SAT 839934 SAT 1000 1.33 151, 235, 262, 0, 0, 74, 2926, 0 806482 SAT 806482 SAT 600 269, 991 7 1.39 231, 267, 272, 0, 2993, 7, 0, 0, 0, 801035 SAT 801035 SAT 428 435, 449, 553, 0 We make some observations: * Since the standard deviation is only 1 the data fees feeD do not vary significantly and hence the simulation algorithm correctly identified that even if we choose 3,5 or 7 denominations, the optimal strategy is to use a single denomination based on the usage column.
* The best denomination to choose is 267 SAT (as used in the set of 7 denominations). This is because it minimises S and F and moreover is used 2993 times. Furthermore, if we rerun the simulation using the single denomination 267, we obtain S = 802335 and F = 801460 and a usage of 3005. The values of S and Pare lower than for the denomination of value 272 SAT.
* The 267 SAT denomination is exactly covering the data fee feeD in the case it reaches 193 SAT and one locking script fee feein = 74 SAT.
Based on the observations, we can USE a single denomination el = 267 SAT in all N = 3000 transactions. Then Q1 = 3000 = N/1.
7.5.4.2 Standard deviation 30 In this case 99.7% of data have fees feeD between 101 and 281 SAT. This setting applies when the data fees can vary considerably, and a better diversification of denominations is appropriate. The table below shows the results we have obtained by running the SA algorithm depending on the number of denominations k = 1, 3, 5 and 7.
k f(ei,...,ek) Set of Observed Qi per et S (total funds required) F (total transaction fees) Q denominations 1 1.75 309 3305 1021245 SAT 948212 SAT 3000 3 0.91 277, 314, 359 1983, 903, 119 875554 SAT 874792 SAT 1000 0.96 239, 253, 270, 306, 542, 477, 700, 843355 SAT 842655 SAT 600 351 1050, 236 7 0.84 173, 230, 240, 262, 36, 290, 269, 836487 SAT 835806 SAT 428 271, 296, 330 850, 371, 838, We make the following observations: * In our testing, out of 3000 transactions, only a maximum of 5 change outputs were created using the 3, Sand 7 denominations.
* Furthermore the sets of 3, 5, and 7 denominations yield a significant improvement of the value of the function f in comparison to using only one denomination.
* The sets of 3, 5, and 7 denominations, reduce the total required funding S and the total transaction fees F. In particular, the sets of 5 and 7 denominations perform best.
The set of 7 denominations gives an overall lower value of the function f, optimising the total required funds and transactions fees. This is due to a good diversification of denominations.
8. EXAMPLE USE CASES
This section shows how the algorithms of the previous sections can be used in two funding examples using single denominations. We assume a data payload of constant size, hence why single denominations are appropriate. Furthermore, because the data payload has constant size, we can compute the value of the single denomination with precision.
8.1 Use case 1 As reference we use the transaction published here: https://test.whatsonchain. com/tx/817a3b51d7923e0a25978737473f80970c3268f1337750c 6d3c8c0edf7a6960f The total number of bytes of the hex codes relating to the transaction's data is 382 bytes requiring a fee of 191 SAT using a 0.5 SAT/byte fee rate. Using the notation introduced above, the data fee feeD is 191 SAT.
Any P2PKH input using a compressed public key contains: the previous hash TxId (32 bytes), the outpoint value (4 bytes), the script length (1 byte), the locking script (at most 107 bytes [10]) and the nSequence value (4 bytes). Thus, a P2PKH input requires at most 148 bytes.
The input fee is feet is 74 SAT computed at a 0.5 SAT/byte fee rate.
Furthermore, any P2PKH output contains: the nValue field (8 bytes), the script length (1 byte), and the unlocking script (25 bytes). Thus, a P2PKH output requires 34 bytes. The output fee fee"t is 17 SAT.
To cover the data fee f eeD it is then enough to fix a single denomination el of value 191+74 SAT, i.e. 265 SAT. Thus, using el of value 265 SAT we cover all necessary fees (f eeD and fee) and we do not require any change outputs.
8.2 Example 2
This example builds upon Example 1, and additional to funding data, we also require the funding of a P2PKH input and output. The P2PKH input and output are used to deterministically chain the transactions. The input unlocks a fixed dust amount d of 135 SAT and similarly the output has a value d.
Thus, the single denomination el needs to account for!CCD of 191 SAT, one P2PKH input fee feetn of 74 SAT and one P2PKH output fee fee", of 17 SAT. Furthermore, the single denomination needs to also cover its own input fee fee in of 74 SAT. Thus, el= 191 + 2 74 + 17 SAT, i.e. el = 356 SAT. An example transaction is given below: Tx Inputs Outputs Value Script Value Script d = 135 SAT ini unlocking script 135 SAT outi locking script el = 356 SAT in2 unlocking script 0 SAT OP FALSE OP RETURN cD> Fees: 356 SAT By using el as the single denomination, we cover all necessary fees and do not require any change outputs.
9. 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.
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 optimizing a size of a blockchain transaction by minimising a number of inputs and/or outputs of the transaction, wherein the transaction has at least one input and at least one output, wherein an optimizer has access to a plurality of unspent transaction outputs, UTX0s, that are available for being respective inputs to the transaction, each respective UTXO having a respective value, wherein the transaction comprises target data having an associated data fee, each input to the transaction has associated input fee and each output of the transaction has an associated output fee, and wherein a total amount of respective values of the respective UTX05 input to the transaction is required to be at least equal to the total amount of fees of the transaction, and wherein the method comprises: determining a respective number of each respective UTXO having a respective value to be used as a respective input to the transaction and a respective number of each output of the transaction having a respective value, by minimising, for each different respective value of the respective UTX05 and for each different respective value of each output, a sum of a) a number of each respective UTXO having a respective value multiplied by the associated input fee, and b) a sum of bi) a number of each respective output having a respective value multiplied by the associated output fee, and bii) a leftover fee, wherein said minimising is subject to the following constraints: i) a total amount of the respective values of the respective UTX05 must be at least equal to the data fees and a leftover amount, wherein the leftover amount is based on based on a total amount of respective values of one or more respective UTX0s input to the transaction, a total amount of respective values of one or more respective outputs of the transaction, and a total amount of fees of the transaction, ii) the determined respective number of each UTXO must be non-negative, iii) the determined respective number of each output must be non-negative, and iv) the leftover amount must be between zero and a maximum of a predetermined upper bound and a sum of the associated input fee and the associated output fee.
Statement 2. The method of statement 1, wherein said determining comprises minimizing the following equation: min 1 in 1; ( wi fee + w feeout + tee, i i wherein each respective value is associated with a respective index i based on the respective value, and where vitt is the respective number of each respective UTXO having a respective value corresponding to the index i, f eeit, is the associated input fee, wit is the respective number of each output of the transaction having a respective value corresponding to index i, f eeout is the associated output fee, and fee( is the leftover fee.
Statement 3. The method of statement 2, wherein:
constraint 1)15 defined by wi(ei -fee) + * * * + wk(ek -feebi) -w(ei + f ee out) -* ** - (ek + fee.) = f eeD + E, where e1 is the respective value corresponding to index i, f eeD is the associated data fee, and £ is the leftover amount; constraint ii) and constraint iii) are defined by tivi, iv; E constraint iv) is defined by 0 E < max[E, f ee"t + feeinl, where E is the predetermined upper bound.
Statement 4. The method of any preceding statement, comprising calculating the leftover fee based on the leftover amount, wherein: lithe leftover amount is less than a sum of the associated input fee and the associated output fee, the leftover fee is the leftover amount; otherwise, if the leftover amount is less than a sum of the associated output fee and a predetermined minimum value, the leftover fee is the sum of the associated input fee and the associated output fee; otherwise, the leftover fee is equal to infinity, or a representation thereof.
Statement S. The method of any preceding statement, wherein said determining is performed using a dynamic programming approach.
Statement 6. The method of statement 5, wherein a change-making problem algorithm, onp[8, E], is defined as follows: cmp [45, X] = 1 0 D, 5 = 0 1, es = E cmp[6 -1, Et es > E min(cmp[S -1,1],l+ cmp[5, -e5]), otherwise where S is an index representing a respective position of a respective UTXO in a sequence ordered based on the respective value of the respective UTXO, E is the total amount of fees of the transaction, and es is the respective value at position 6 in the sequence, and wherein said determining comprises determining a minimum total transaction fee to cover the data fee by: calculating a first matrix, cmp1n[6,1], for a set of first input values {e} -feetn, ...,ek -fee}, where k is the respective index corresponding to a highest respective value of the respective UTX05; calculating a second matrix, cmp"t [5, n, for a set of second input fel + f eeout, ek + feeoutl; calculating an array, cmp".q[E] = min (Ein * feet, min (C E) in * feet, + Cout * c>o f eeout), where Ein = cmpin[k,E], (C + X) = cmpin[k,C + E] and cut = cmpout[k,C], and where C = (el + feeout) + * * * + wk(e k + fee") and C + = wi(ei -feein) + * ** + w k(e k -f ee tn), and calculating the array cmp ftnat[X] = min EmPneg + El + 05e<max(E,fee0"t+feeitj fee,, where cmp f i[f eeD] is the minimum transaction fee to cover the data fee.
Statement 7. The method of statement 5, wherein a change-making problem algorithm, cmp[5,E], is defined as follows: 100, = 0 1, es = E cmp[8 mod 2, E] cmp[(6 -1) mod 2,E1, es > E min(cmp[(8 -1) mod 2,E],1 crnp[6 mod 2,E -es]), otherwise where 6 is an index representing a respective position of a respective UTXO in a sequence ordered based on the respective value of the respective UTXO, E is the total amount of fees of the transaction, and es is the respective value at position 6 in the sequence, and wherein said determining comprises determining a minimum total transaction fee to cover the data fee by: calculating a first matrix, cmpin[6, EL for a set of first input values fel - -feein}, where k is the respective index corresponding to a highest respective value of the respective UTX05; calculating a second matrix, cmp0t[5, E], for a set of second input fel + f eeout, ek + f eeoutb ± Cola calculating an array, cmpmen[E] = min (Et, * fee, min (C + E),:n * fee c>o f eeout), where Ein = cmpin[k,E], (C + E) = cmpb,[k,C + E] and C011 = cmpout[k,C], 5 and where C = u.4(e1 + fee")+ * * * + wk(ek + f eeout) and C + E = wi(ei -f ee in) + * ** + wk(ek -feet), and calculating the array cmprinca[E] = min i:1E<niaxte,feeour+f eein1 cmp",[E + El + fee,, where cmp final[f cep] is the minimum transaction fee to cover the data fee.
Statement 8. The method of any preceding statement, wherein the predetermined minimum value is set by the blockchain protocol.
Statement 9. The method of any preceding statement, wherein the plurality of UTX05 are ordered monotonically by respective value.
Statement 10. The method of any preceding statement, comprising using the method to optimize a respective size of a plurality of respective blockchain transactions, each respective blockchain transaction having respective target data having the same associated data fee.
Statement 11. The method of any preceding statement, wherein the plurality of UTX05 accessible to the optimizer are determined by determining an optimal set of input values for use as funding a set of respective blockchain transactions so as to optimise a size of each transaction, wherein the method comprises: for a plurality of different respective sets of input values, determining the respective set of input values that minimises a function when evaluated based on the respective set of input values, wherein the function is based on i) the total amount of fees of the respective transaction, ii) the associated data fee, iii) is a total value of all input values used for respective inputs to the set of transactions, iv) a total number of spendable outputs of the respective transaction, v) a total number of instances of each input value needed to fund the set of transactions, and vi) a total number of transactions in the set of transactions.
Statement 12. The method of statement 11, wherein the optimizer is configured to obtain each UTXO form a pool of UTX05, and wherein the function is also based on vii) a number of communications between the optimizer and the pool of UTX05 required to obtain the total number of instances of each input value needed to fund the set of transactions.
Statement 13. The method of statement 11 or statement 12, wherein said determining 10 comprises: a) evaluating the function based on an initial set of input values; b) determining a respective next set of input values by changing one or more of the input values in the initial set of input values; c) evaluating the function based on the respective next set of input values; and repeating steps b and c until the function is minimised, wherein the respective next set of inputs values used in step c is used as the initial set of input values in step b.
Statement 14. The method of any of statement 11 to 13, wherein the function is minimised using a heuristic function.
Statement 15. The method of statement 14, wherein the heuristic function is a simulated annealing algorithm.
Statement 16. The method of statement 12 or any claim dependent thereon, wherein the function is of the following form: fF S Ut7+7+0+C *Q) ek) where F is the total amount of fees of the respective transaction, M is the associated data fee, S is the total value of all input values used for respective inputs to the set of transactions, 0 is the total number of spendable outputs of the respective transaction, Q is the total number of instances of each input value needed to fund the set of transactions, N is the total number of transactions in the set of transactions, C is the number of communications between the optimizer and the pool of UTX05 required to obtain the total number of instances of each input value needed to fund the set of transactions, and ei is a respective input value associated with index i.
Statement 17. 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 statement 1 to 16.
Statement 18. 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 statement 1 to 16.

Claims (18)

  1. CLAIMS1. A computer-implemented method of optimizing a size of a blockchain transaction by minimising a number of inputs and/or outputs of the transaction, wherein the transaction has at least one input and at least one output, wherein an optimizer has access to a plurality of unspent transaction outputs, UTX05, that are available for being respective inputs to the transaction, each respective UTXO having a respective value, wherein the transaction comprises target data having an associated data fee, each input to the transaction has associated input fee and each output of the transaction has an associated output fee, and wherein a total amount of respective values of the respective UTX05 input to the transaction is required to be at least equal to the total amount of fees of the transaction, and wherein the method comprises: determining a respective number of each respective UTXO having a respective value to be used as a respective input to the transaction and a respective number of each output of the transaction having a respective value, by minimising, for each different respective value of the respective UTX05 and for each different respective value of each output, a sum of a) a number of each respective UTXO having a respective value multiplied by the associated input fee, and b) a sum of bi) a number of each respective output having a respective value multiplied by the associated output fee, and bii) a leftover fee, wherein said minimising is subject to the following constraints: i) a total amount of the respective values of the respective UTX0s must be at least equal to the data fees and a leftover amount, wherein the leftover amount is based on based on a total amount of respective values of one or more respective UTX05 input to the transaction, a total amount of respective values of one or more respective outputs of the transaction, and a total amount of fees of the transaction, ii) the determined respective number of each UTXO must be non-negative, iii) the determined respective number of each output must be non-negative, and iv) the leftover amount must be between zero and a maximum of a predetermined upper bound and a sum of the associated input fee and the associated output fee.
  2. 2. The method of claim 1, wherein said determining comprises minimizing the following equation: min (w1 feein + i feeout + fee() wherein each respective value is associated with a respective index i based on the respective value, and where wi is the respective number of each respective UTXO having a respective value corresponding to the index i, f eein is the associated input fee, wi is the respective number of each output of the transaction having a respective value corresponding to index i, feeont is the associated output fee, and fee is the leftover fee.
  3. 3. The method of claim 2, wherein: constraint i) is defined by w1 (e1 -fee) + * * * + wk(ek -feet)-w(ei + f e e out) -- (e,, + feeout) = fees + E, where ei is the respective value corresponding to index i, feeD is the associated data fee, and E is the leftover amount; constraint ii) and constraint iii) are defined by wi, E N"; constraint iv) is defined by 0 e < maxtE,f ee"t + feein}, where E is the predetermined upper bound.
  4. 4. The method of any preceding claim, comprising calculating the leftover fee based on the leftover amount, wherein: If the leftover amount is less than a sum of the associated input fee and the associated output fee, the leftover fee is the leftover amount; otherwise, if the leftover amount is less than a sum of the associated output fee and a predetermined minimum value, the leftover fee is the sum of the associated input fee and the associated output fee; otherwise, the leftover fee is equal to infinity, or a representation thereof.
  5. 5. The method of any preceding claim, wherein said determining is performed using a dynamic programming approach.
  6. 6. The method of claims, wherein a change-making problem algorithm, cmp[8, E], is defined as follows: cmp [6, E] = 1 co, 8 = 0 1, e8= E cmp[o -1, Et es > E min (cmp [S -1, E], 1 + cmp[S, E -e5]), otherwise where S is an index representing a respective position of a respective UTX0 in a sequence ordered based on the respective value of the respective UTXO, I is the total amount of fees of the transaction, and ets is the respective value at position S in the sequence, and wherein said determining comprises determining a minimum total transaction fee to cover the data fee by: calculating a first matrix, cmptn [8,E], for a set of first input values fel -feei",...,ek -feetn}, where k is the respective index corresponding to a highest respective value of the respective UTX05; calculating a second matrix, cmpokt[S, I], for a set of second input fel + f eeokt, ek + f eeoktl; calculating an array, cm/2,6RM = min (Et, * fee, min + I)t, * feeik + Cokt * c?o f eeokt), where Ein = cmpi[k,E], (C + E)in = cmpik[k,C + I] and Gnu = cmpokt[k,C], and where C = + feeokt) + * * * + (ek + f eeokt) and C + E = wi(ei - + *** + wk(ek -feet,), and calculating the array cmp fikoi[E] = min cmp"g[E + el + 0.sE<max(Efeeout+feeinj fee,, where cmp f t[feen] is the minimum transaction fee to cover the data fee.
  7. 7. The method of claims, wherein a change-making problem algorithm, cmp[S, E], is defined as follows: / co, = 0 1, = E cmp[ii mod 2,E] cmp[(5 -1) mod 2,E], es > min(cmp[(8 -1) mod 2,11,1 + cmp[6' mod 2,E -e5]), otherwise where S is an index representing a respective position of a respective UTXO in a sequence ordered based on the respective value of the respective UTXO, I is the total amount of fees of the transaction, and e8 is the respective value at position 6' in the sequence, and wherein said determining comprises determining a minimum total transaction fee to cover the data fee by: calculating a first matrix, cmp111[8,1], for a set of first input values fel -f eei", , e k -f ee in}, where k is the respective index corresponding to a highest respective value of the respective UTX05; calculating a second matrix, cmp011t[6, I], for a set of second input + f eec,"t, ek + f eeoutl; calculating an array, cmp".q[E] = min (Iin * feein, min (C + I) in * feet, + cut * f eema), where IL, = cmpin[k,E], (C + = cmpin[k,C + I] and Cout = cmp 0[k, C], and where C = w( e1 f e eo"t) + * * * + wjek + f e emu) and C + I = wi(ei -feein) + * ** + wk(ek-feein), and calculating the array cmprinat[E] = min cmp"g[E + el + 0.sE<max1E,fee,"t+feein} fee,, where cmprinal[feen] is the minimum transaction fee to cover the data fee.
  8. 8. The method of any preceding claim, wherein the predetermined minimum value is set by the blockchain protocol.
  9. 9. The method of any preceding claim, wherein the plurality of UTX0s are ordered monotonically by respective value.
  10. 10. The method of any preceding claim, comprising using the method to optimize a respective size of a plurality of respective blockchain transactions, each respective blockchain transaction having respective target data having the same associated data fee.
  11. 11. The method of any preceding claim, wherein the plurality of UTX0s accessible to the optimizer are determined by determining an optimal set of input values for use as funding a set of respective blockchain transactions so as to optimise a size of each transaction, wherein the method comprises: for a plurality of different respective sets of input values, determining the respective set of input values that minimises a function when evaluated based on the respective set of input values, wherein the function is based on i) the total amount of fees of the respective transaction, ii) the associated data fee, iii) is a total value of all input values used for respective inputs to the set of transactions, iv) a total number of spendable outputs of the respective transaction, v) a total number of instances of each input value needed to fund the set of transactions, and vi) a total number of transactions in the set of transactions.
  12. 12. The method of claim 11, wherein the optimizer is configured to obtain each UTXO form a pool of UTX05, and wherein the function is also based on vii) a number of communications between the optimizer and the pool of UTX05 required to obtain the total number of instances of each input value needed to fund the set of transactions.
  13. 13. The method of claim 11 or claim 12, wherein said determining comprises: a) evaluating the function based on an initial set of input values; b) determining a respective next set of input values by changing one or more of the input values in the initial set of input values; c) evaluating the function based on the respective next set of input values; and repeating steps b and c until the function is minimised, wherein the respective next set of inputs values used in step c is used as the initial set of input values in step b.
  14. 14. The method of any of claims 11 to 13, wherein the function is minimised using a heuristic function.
  15. 15. The method of claim 14, wherein the heuristic function is a simulated annealing algorithm.
  16. 16. The method of claim 12 or any claim dependent thereon, wherein the function is of the following form: (F s 7+7+0+c *Q) f(eu..-ek)-where F is the total amount of fees of the respective transaction, M is the associated data fee, S is the total value of all input values used for respective inputs to the set of transactions, (9 is the total number of spendable outputs of the respective transaction, Q is the total number of instances of each input value needed to fund the set of transactions, N is the total number of transactions in the set of transactions, C is the number of communications between the optimizer and the pool of UTX0s required to obtain the total number of instances of each input value needed to fund the set of transactions, and ei is a respective input value associated with index i.
  17. 17. 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 16.
  18. 18. 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 16.
GB2206032.1A 2022-04-26 2022-04-26 Optimizing blockchain transaction size Pending GB2618766A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
GB2206032.1A GB2618766A (en) 2022-04-26 2022-04-26 Optimizing blockchain transaction size
PCT/EP2023/058489 WO2023208517A1 (en) 2022-04-26 2023-03-31 Optimizing blockchain transaction size

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
GB2206032.1A GB2618766A (en) 2022-04-26 2022-04-26 Optimizing blockchain transaction size

Publications (2)

Publication Number Publication Date
GB202206032D0 GB202206032D0 (en) 2022-06-08
GB2618766A true GB2618766A (en) 2023-11-22

Family

ID=81851819

Family Applications (1)

Application Number Title Priority Date Filing Date
GB2206032.1A Pending GB2618766A (en) 2022-04-26 2022-04-26 Optimizing blockchain transaction size

Country Status (2)

Country Link
GB (1) GB2618766A (en)
WO (1) WO2023208517A1 (en)

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
None *

Also Published As

Publication number Publication date
GB202206032D0 (en) 2022-06-08
WO2023208517A1 (en) 2023-11-02

Similar Documents

Publication Publication Date Title
US20220337427A1 (en) Cryptographically linked identities
US20220309504A1 (en) Multi-criteria blockchain protocol
WO2023052019A1 (en) Propagating locking scripts
WO2023072959A1 (en) Methods and systems for distributed blockchain functionalities
US20230230078A1 (en) Custom transaction scripts
GB2618766A (en) Optimizing blockchain transaction size
JP2024525196A (en) Multi-level Blockchain
GB2618767A (en) Optimizing blockchain transaction size
GB2614295A (en) Methods and systems for recipient-facilitated blockchain transactions
GB2618765A (en) Optimizing blockchain transaction size
US20230196373A1 (en) Probabilistic membership test for blockchain transaction outputs
WO2024110153A1 (en) Payment channel aggregator
WO2024110166A1 (en) Payment channel aggregator
WO2024052065A1 (en) Determining shared secrets using a blockchain
WO2024041866A1 (en) Blockchain transaction
WO2023156101A1 (en) Blockchain transaction
GB2621858A (en) Blockchain transaction
WO2023072778A1 (en) Sharded merkle tree
WO2024052047A1 (en) Blockchain-based token protocol
Rahimpour Designing Efficient and Secure Algorithms for Payment Channel Networks
WO2024052052A1 (en) Blockchain-based token protocol
WO2023227381A1 (en) Coordinating peer-to-peer data transfer using blockchain
WO2023227529A1 (en) Hash masks
GB2614077A (en) Signature-based atomic swap
GB2619038A (en) Coordinating peer-to-peer data transfer using blockchain