Patent Description:
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 peer-to-peer (P2P) network. The blockchain comprises a chain of blocks of data, wherein each block comprises one or more transactions. Each transaction may point back to a preceding transaction in a sequence which may span one or more blocks. Transactions can be submitted to the network to be included in new blocks. New blocks are created by a process known as "mining", which involves each of a plurality of mining nodes competing to perform "proof-of-work", i.e. solving a cryptographic puzzle based on a pool of the pending transactions waiting to be included in blocks.

Conventionally the transactions in the blockchain are used to convey a digital asset, i.e. data acting as a store of value. However, a blockchain can also be exploited in order to layer additional functionality on top of the blockchain. For instance, blockchain protocols may allow for storage of additional user data in an output of a transaction. Modern blockchains are increasing the maximum data capacity that can be stored within a single transaction, enabling more complex data to be incorporated. For instance this may be used to store an electronic document in the blockchain, or even audio or video data.

Each node in the network can have any one, two or all of three roles: forwarding, mining and storage. Forwarding nodes propagate transactions throughout the nodes of the network. Mining nodes perform the mining of transactions into blocks. Storage nodes each store their own copy of the mined blocks of the blockchain. In order to have a transaction recorded in the blockchain, a party sends the transaction to one of the nodes of the network to be propagated. Mining nodes which receive the transaction may race to mine the transaction into a new block. Each node is configured to respect the same node protocol, which will include one or more conditions for a transaction to be valid. Invalid transactions will not be propagated nor mined into blocks. Assuming the transaction is validated and thereby accepted onto the blockchain, then the transaction (including any user data) will thus remain stored at each of the nodes in the P2P network as an immutable public record.

The miner who successfully solved the proof-of-work puzzle to create the latest block is typically rewarded with a new transaction called a "generation transaction" which generates a new amount of the digital asset. The proof-of work incentivises miners not to cheat the system by including double-spending transactions in their blocks, since it requires a large amount of compute resource to mine a block, and a block that includes an attempt to double spend is likely not be accepted by other nodes.

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, sometimes referred to as a UTXO ("unspent transaction output"). The output may further comprise a locking script specifying a condition for redeeming the output. Each input comprises a pointer 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 P2P 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 nor include it for mining into a 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 miners separate to the blockchain and is updated constantly. The state is modified by running smart-contracts which are included in transactions and run when the transactions are validated by nodes of the blockchain network.

<CIT> discloses a method which uses a blockchain to control a process executing on a computing resource.

The locking and unlocking scripts used in output-based models typically employ a more limited scripting language than the smart contracts in an account-based model. For instance, output-based models typically employ a stack-based language such as the language simply named Script (capital S). Stack-based languages are not "Turing complete" which means they cannot implement certain types of algorithms such as loops.

For this or other reasons, it would be desirable to enable additional criteria for validation to be included in the locking scripts of transactions in an output-based model, not bound by the limitations of the scripting language recognized by the nodes of the blockchain network. For instance, it may be desirable to enable functionality akin to the smart contracts of an account-based model, but in an output-based model (e.g. UTXO-based model). As another example, it could be desirable to enable conditions written by a programmer proficient in a second language to be incorporated into the locking scripts of an output-based model that operates primarily based on a first language.

According to one aspect disclosed herein, there is provided a computer-implemented method performed by a node of a blockchain network, wherein copies of a blockchain are maintained across at least some of the nodes of the blockchain network, the blockchain comprising a chain of blocks each comprising one or more transactions, each transaction comprising one or more outputs, and each output comprising a locking script formulated in a first language. The first language is not Turing complete and is a stack-based language, such as Script, for placing values onto a stack (<NUM>) and reading values from the stack. The method comprises: a) accessing the locking script from at least a first output of a first of said transactions, the locking script of the first output specifying, in the first language, one or more conditions for unlocking said first output; b) receiving a second transaction not yet recorded on blockchain, wherein the second transaction comprises an input comprising an unlocking script formulated in the first language; and c) extracting, from the first transaction, a portion of code formulated in a second language other than the first language. The second language is Turing complete and is not stack-based. The method further comprises: d) running the extracted portion of code in the second language, wherein as a result thereof the code generates at least one first value; e) writing the first value to the stack, thereby being readable by the locking script in the first language; and f) running, in the first language, the locking script from the first output of the first transaction together with the unlocking script from the second transaction, thereby evaluating the one or more conditions, the method comprising validating the second transaction on condition of said one or more conditions being met. The unlocking script is configured to read the first value from the stack, and the second value is included in the second transaction (Txj), the method comprising extracting the second value from the second transaction. The unlocking script is configured to compare the first value as read from the stack with the second value as extracted from the second transaction, the one or more conditions comprising a condition that the first and second values match.

For each of a plurality of transactions including the target transaction, at least some nodes of the network are configured to propagate each transaction on condition of the transaction being valid and at least some nodes are configured to record each transaction in the copy of the blockchain at that node on condition of the transaction being valid. The validity of the target transaction is conditional on the outcome of the code in the second language. If this condition is not met, the transaction will not be propagated through the blockchain network, pooled for mining, nor recorded on the blockchain. Hence functionality written in the second language can be incorporated to set conditions for validity in a model that is otherwise based on validation using the first, scripting language.

<FIG> shows an example system <NUM> for implementing a blockchain <NUM>. The system <NUM> comprises a packet-switched network <NUM>, typically a wide-area internetwork such as the Internet. The packet-switched network <NUM> comprises a plurality of nodes <NUM> arranged to form a peer-to-peer (P2P) overlay network <NUM> within the packet-switched network <NUM>. Each node <NUM> comprises computer equipment of a peers, with different ones of the nodes <NUM> belonging to different peers. Each node <NUM> 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). 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 <NUM> comprises a chain of blocks of data <NUM>, wherein a respective copy of the blockchain <NUM> is maintained at each of a plurality of nodes in the P2P network <NUM>. Each block <NUM> in the chain comprises one or more transactions <NUM>, 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 typically use one particular transaction protocol throughout. In one common type of transaction protocol, the data structure of each transaction <NUM> comprises at least one input and at least one output. Each output specifies an amount representing a quantity of a digital asset belonging to a user <NUM> to whom the output is cryptographically locked (requiring a signature of that user in order to be unlocked and thereby redeemed or spent). Each input points back to the output of a preceding transaction <NUM>, thereby linking the transactions.

At least some of the nodes <NUM> take on the role of forwarding nodes 104F which forward and thereby propagate transactions <NUM>. At least some of the nodes <NUM> take on the role of miners <NUM> which mine blocks <NUM>. At least some of the nodes <NUM> take on the role of storage nodes <NUM> (sometimes also called "full-copy" nodes), each of which stores a respective copy of the same blockchain <NUM> in their respective memory. Each miner node <NUM> also maintains a pool <NUM> of transactions <NUM> waiting to be mined into blocks <NUM>. A given node <NUM> may be a forwarding node <NUM>, miner <NUM>, storage node <NUM> or any combination of two or all of these.

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. In general, the preceding transaction could be any transaction in the pool <NUM> or any block <NUM>. The preceding transaction 152i need not necessarily exist at the time the present transaction 152j is created or even sent to the network <NUM>, 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 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 103b. The present transaction 152j can thus transfer the amount defined in the input of the preceding transaction 152i to the new user 103b as defined in the output of the present transaction 152j. In some cases a transaction <NUM> may have multiple outputs to split the input amount between multiple users (one of whom could be the original user 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.

The above may be referred to as an "output-based" transaction protocol, sometimes also referred to as an unspent transaction output (UTXO) type protocol (where the outputs are referred to as UTXOs). A user's total balance is not defined in any one number stored in the blockchain, and instead the user needs a special "wallet" application <NUM> to collate the values of all the UTXOs of that user which are scattered throughout many different transactions <NUM> in the blockchain <NUM>.

An alternative type of transaction protocol 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 miners 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.

With either type of transaction protocol, when a user <NUM> wishes to enact a new transaction 152j, then he/she sends the new transaction from his/her computer terminal <NUM> to one of the nodes <NUM> of the P2P network <NUM> (which nowadays are typically servers or data centres, but could in principle be other user terminals). This node <NUM> checks whether the transaction is valid according to a node protocol which is applied at each of the nodes <NUM>. The details of the node protocol will correspond to the type of transaction protocol being used in the blockchain <NUM> in question, together forming the overall transaction model. The node protocol typically requires the node <NUM> to check that the cryptographic signature in the new transaction 152j matches the expected signature, which depends on the previous transaction 152i in an ordered sequence of transactions <NUM>. In an output-based case, this may comprise checking that the cryptographic signature of the user 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, wherein this condition typically comprises at least checking that the cryptographic signature in the input of the new transaction 152j unlocks the output of the previous transaction 152i to which the input of the new transaction points. In some transaction protocols the condition may be at least partially defined by a custom script included in the input and/or output. Alternatively it could simply be a fixed by the node protocol alone, or it could be due to a combination of these. Either way, if the new transaction 152j is valid, the current node forwards it to one or more others of the nodes <NUM> in the P2P network <NUM>. At least some of these nodes <NUM> also act as forwarding nodes 104F, applying the same test according to the same node protocol, and so forward the new transaction 152j on to one or more further nodes <NUM>, and so forth. In this way the new transaction is propagated throughout the network of nodes <NUM>.

In an output-based model, the definition of whether a given output (e.g. UTXO) is spent is whether it has yet been validly redeemed by the input of another, onward transaction 152j according to the node protocol. Another condition for a transaction to be valid is that the output of the preceding transaction 152i which it attempts to spend or redeem has not already been spent/redeemed by another valid transaction. Again if not valid, the transaction 152j will not be propagated or recorded in the blockchain. This guards against double-spending whereby the spender tries to spend 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 validation, at least some of the nodes <NUM> also race to be the first to create blocks of transactions in a process known as mining, which is underpinned by "proof of work". At a mining node <NUM>, new transactions are added to a pool of valid transactions that have not yet appeared in a block. The miners then race to assemble a new valid block <NUM> of transactions <NUM> from the pool of transactions <NUM> by attempting to solve a cryptographic puzzle. Typically this comprises searching for a "nonce" value such that when the nonce is concatenated with the pool of transactions <NUM> and hashed, then the output of the hash meets a predetermined condition. the predetermined condition may be that the output of the hash has a certain predefined number of leading zeros. 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 node <NUM> that is trying to solve the puzzle.

The first miner node <NUM> to solve the puzzle announces this to the network <NUM>, providing the solution as proof which can then be easily checked by the other nodes <NUM> 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 pool of transactions <NUM> for which the winner solved the puzzle then becomes recorded as a new block <NUM> in the blockchain <NUM> by at least some of the nodes <NUM> acting as storage nodes <NUM>, based on having checked the winner's announced solution at each such node. A block pointer <NUM> is also assigned to the new block 151n pointing back to the previously created block 151n-<NUM> in the chain. The proof-of-work helps reduce the risk of double spending since it takes a large amount of effort to create a new block <NUM>, and as any block containing a double spend is likely to be rejected by other nodes <NUM>, mining nodes <NUM> are incentivised not to allow double spends to be included in their blocks. Once created, the block <NUM> cannot be modified since it is recognized and maintained at each of the storing nodes <NUM> in the P2P network <NUM> according to the same protocol. The block pointer <NUM> also imposes a sequential order to the blocks <NUM>. Since the transactions <NUM> are recorded in the ordered blocks at each storage node <NUM> in a P2P network <NUM>, this therefore provides an immutable public ledger of the transactions.

Note that different miners <NUM> racing to solve the puzzle at any given time may be doing so based on different snapshots of the unmined transaction pool <NUM> at any given time, depending on when they started searching for a solution. Whoever solves their respective puzzle first defines which transactions <NUM> are included in the next new block 151n, and the current pool <NUM> of unmined transactions is updated. The miners <NUM> then continue to race to create a block from the newly defined outstanding pool <NUM>, and so forth. A protocol also exists for resolving any "fork" that may arise, which is where two miners <NUM> solve their puzzle within a very short time of one another such that a conflicting view of the blockchain gets propagated. In short, whichever prong of the fork grows the longest becomes the definitive blockchain <NUM>.

In most blockchains the winning miner <NUM> is automatically rewarded with a special kind of new transaction which creates a new quantity of the digital asset out of nowhere (as opposed to normal transactions which transfer an amount of the digital asset from one user to another). Hence the winning node is said to have "mined" a quantity of the digital asset. This special type of transaction is sometime referred to as a "generation" transaction. It automatically forms part of the new block 151n. This reward gives an incentive for the miners <NUM> to participate in the proof-of-work race. Often a regular (non-generation) transaction <NUM> will also specify an additional transaction fee in one of its outputs, to further reward the winning miner <NUM> that created the block 151n in which that transaction was included.

Due to the computational resource involved in mining, typically at least each of the miner nodes <NUM> takes the form of a server comprising one or more physical server units, or even whole a data centre. Each forwarding node <NUM> and/or storage node <NUM> may also take the form of a server or data centre. However in principle any given node <NUM> could take the form of a user terminal or a group of user terminals networked together.

The memory of each node <NUM> stores software configured to run on the processing apparatus of the node <NUM> in order to perform its respective role or roles and handle transactions <NUM> in accordance with the node protocol. It will be understood that any action attributed herein to a node <NUM> 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, the term "blockchain" as used herein is a generic term that refers to the kind of technology in general, and does not limit to any particular proprietary blockchain, protocol or service.

Also connected to the network <NUM> is the computer equipment <NUM> of each of a plurality of parties <NUM> in the role of consuming users. These act as payers and payees in transactions but do not necessarily participate in mining or propagating transactions on behalf of other parties. They do not necessarily run the mining protocol. Two parties <NUM> and their respective equipment <NUM> 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 <NUM> and their respective computer equipment <NUM> may be present and participating in the system, but for convenience they are not illustrated. Each party <NUM> 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 <NUM> of each party <NUM> comprises respective processing apparatus comprising one or more processors, e.g. one or more CPUs, GPUs, other accelerator processors, application specific processors, and/or FPGAs. The computer equipment <NUM> of each party <NUM> further comprises memory, i.e. computer-readable storage in the form of a non-transitory computer-readable medium or media. This memory may comprise one or more memory units employing one or more memory media, e.g. a magnetic medium such as hard disk; an electronic medium such as an SSD, flash memory or EEPROM; and/or an optical medium such as an optical disc drive. The memory on the computer equipment <NUM> of each party <NUM> stores software comprising a respective instance of at least one client application <NUM> arranged to run on the processing apparatus. It will be understood that any action attributed herein to a given party <NUM> may be performed using the software run on the processing apparatus of the respective computer equipment <NUM>. The computer equipment <NUM> of each party <NUM> 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 <NUM> of a given party <NUM> may also comprise one or more other networked resources, such as cloud computing resources accessed via the user terminal.

The client application <NUM> may be initially provided to the computer equipment <NUM> of any given party <NUM> 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 <NUM> comprises at least a "wallet" function. This has two main functionalities. One of these is to enable the respective user party <NUM> to create, sign and send transactions <NUM> to be propagated throughout the network of nodes <NUM> and thereby included in the blockchain <NUM>. 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 <NUM> transactions scattered throughout the blockchain <NUM> that belong to the party in question.

Note: whilst the various client functionality may be described as being integrated into a given client application <NUM>, 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 <NUM> but it will be appreciated that this is not limiting.

The instance of the client application or software <NUM> on each computer equipment <NUM> is operatively coupled to at least one of the forwarding nodes 104F of the P2P network <NUM>. This enables the wallet function of the client <NUM> to send transactions <NUM> to the network <NUM>. The client <NUM> is also able to contact one, some or all of the storage nodes <NUM> in order to query the blockchain <NUM> for any transactions of which the respective party <NUM> is the recipient (or indeed inspect other parties' transactions in the blockchain <NUM>, since in embodiments the blockchain <NUM> is a public facility which provides trust in transactions in part through its public visibility). The wallet function on each computer equipment <NUM> is configured to formulate and send transactions <NUM> according to a transaction protocol. Each node <NUM> runs software configured to validate transactions <NUM> according to a node protocol, and in the case of the forwarding nodes 104F to forward transactions <NUM> in order to propagate them throughout the network <NUM>. The transaction protocol and 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 <NUM> in the blockchain <NUM> (though the transaction protocol may allow different subtypes of transaction within it). The same node protocol is used by all the nodes <NUM> in the network <NUM> (though it many handle different subtypes of transaction differently in accordance with the rules defined for that subtype, and also different nodes may take on different roles and hence implement different corresponding aspects of the protocol).

As mentioned, the blockchain <NUM> comprises a chain of blocks <NUM>, wherein each block <NUM> comprises a set of one or more transactions <NUM> that have been created by a proof-of-work process as discussed previously. Each block <NUM> also comprises a block pointer <NUM> pointing back to the previously created block <NUM> in the chain so as to define a sequential order to the blocks <NUM>. The blockchain <NUM> also comprises a pool of valid transactions <NUM> waiting to be included in a new block by the proof-of-work process. Each transaction <NUM> (other than a generation transaction) comprises a pointer back to a previous transaction so as to define an order to sequences of transactions (N. sequences of transactions <NUM> are allowed to branch). The chain of blocks <NUM> goes all the way back to a genesis block (Gb) <NUM> which was the first block in the chain. One or more original transactions <NUM> early on in the chain <NUM> pointed to the genesis block <NUM> rather than a preceding transaction.

When a given party <NUM>, say Alice, wishes to send a new transaction 152j to be included in the blockchain <NUM>, then she formulates the new transaction in accordance with the relevant transaction protocol (using the wallet function in her client application <NUM>). She then sends the transaction <NUM> from the client application <NUM> to one of the one or more forwarding nodes 104F to which she is connected. this could be the forwarding node 104F that is nearest or best connected to Alice's computer <NUM>. When any given node <NUM> receives a new transaction 152j, it handles it in accordance with the 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 <NUM>. 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 storage node <NUM> that receives the transaction 152j will add the new validated transaction <NUM> to the pool <NUM> in the copy of the blockchain <NUM> maintained at that node <NUM>. Further, any forwarding node 104F that receives the transaction 152j will propagate the validated transaction <NUM> onward to one or more other nodes <NUM> in the P2P network <NUM>. Since each forwarding node 104F applies the same protocol, then assuming the transaction 152j is valid, this means it will soon be propagated throughout the whole P2P network <NUM>.

Once admitted to the pool <NUM> in the copy of the blockchain <NUM> maintained at one or more storage nodes <NUM>, then miner nodes <NUM> will start competing to solve the proof-of-work puzzle on the latest version of the pool <NUM> including the new transaction <NUM> (other miners <NUM> may still be trying to solve the puzzle based on the old view of the pool <NUM>, but whoever gets there first will define where the next new block <NUM> ends and the new pool <NUM> starts, and eventually someone will solve the puzzle for a part of the pool <NUM> which includes Alice's transaction 152j). Once the proof-of-work has been done for the pool <NUM> including the new transaction 152j, it immutably becomes part of one of the blocks <NUM> in the blockchain <NUM>. Each transaction <NUM> comprises a pointer back to an earlier transaction, so the order of the transactions is also immutably recorded.

Different nodes <NUM> may receive different instances of a given transaction first and therefore have conflicting views of which instance is 'valid' before one instance is mined into a block <NUM>, at which point all nodes <NUM> agree that the mined instance is the only valid instance. If a node <NUM> accepts one instance as valid, and then discovers that a second instance has been recorded in the blockchain <NUM> then that node <NUM> must accept this and will discard (i.e. treat as invalid) the unmined instance which it had initially accepted.

<FIG> illustrates an example transaction protocol. This is an example of an UTXO-based protocol. A transaction <NUM> (abbreviated "Tx") is the fundamental data structure of the blockchain <NUM> (each block <NUM> comprising one or more transactions <NUM>). The following will be described by reference to an output-based or "UTXO" based protocol. However, this not limiting to all possible embodiments.

In a UTXO-based model, each transaction ("Tx") <NUM> comprises a data structure comprising one or more inputs <NUM>, and one or more outputs <NUM>. Each output <NUM> may comprise an unspent transaction output (UTXO), which can be used as the source for the input <NUM> of another new transaction (if the UTXO has not already been redeemed). The UTXO specifies an amount of a digital asset (a store of value). It 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 <NUM>, which may comprise an indicator of the size of the input field(s) <NUM> and output field(s) <NUM>. The header <NUM> 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 <NUM> of the raw transaction <NUM> submitted to the miners <NUM>.

Say Alice 103a wishes to create a transaction 152j transferring an amount of the digital asset in question to Bob 103b. In <FIG> Alice's new transaction 152j is labelled "Tx<NUM>". It takes an amount of the digital asset that is locked to Alice in the output <NUM> of a preceding transaction 152i in the sequence, and transfers at least some of this to Bob. The preceding transaction 152i is labelled "Tx<NUM>" in <FIG>. Tx<NUM> and Tx<NUM> are just an arbitrary labels. They do not necessarily mean that Tx<NUM> is the first transaction in the blockchain <NUM>, nor that Tx<NUM> is the immediate next transaction in the pool <NUM>. Tx<NUM> could point back to any preceding (i.e. antecedent) transaction that still has an unspent output <NUM> locked to Alice.

The preceding transaction Tx<NUM> may already have been validated and included in the blockchain <NUM> at the time when Alice creates her new transaction Tx<NUM>, or at least by the time she sends it to the network <NUM>. It may already have been included in one of the blocks <NUM> at that time, or it may be still waiting in the pool <NUM> in which case it will soon be included in a new block <NUM>. Alternatively Tx<NUM> and Tx<NUM> could be created and sent to the network <NUM> together, or Tx<NUM> could even be sent after Tx<NUM> 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 <NUM>, or arrive at any given node <NUM>. 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 node <NUM> 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 miner behaviour.

One of the one or more outputs <NUM> of the preceding transaction Tx<NUM> comprises a particular UTXO, labelled here UTXO<NUM>. 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 <NUM> 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). 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). The locking script specifies what information is required to spend a transaction output <NUM>, 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 <NUM> of transactions.

So in the example illustrated, UTXO<NUM> in the output <NUM> of Txocomprises a locking script [Checksig PA] which requires a signature Sig PA of Alice in order for UTXO<NUM> to be redeemed (strictly, in order for a subsequent transaction attempting to redeem UTXO<NUM> to be valid). [Checksig PA] contains the public key PA from a public-private key pair of Alice. The input <NUM> of Tx<NUM> comprises a pointer pointing back to Tx<NUM> (e.g. by means of its transaction ID, TxID<NUM>, which in embodiments is the hash of the whole transaction Tx<NUM>). The input <NUM> of Tx<NUM> comprises an index identifying UTXO<NUM> within Tx<NUM>, to identify it amongst any other possible outputs of Tx<NUM>. The input <NUM> of Tx<NUM> 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). What data (or "message") 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 Tx<NUM> arrives at a node <NUM>, 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> ∥[Checksig PA]
where "∥" represents a concatenation and "<. >" means place the data on the stack, and "[. ]" is a function comprised by the unlocking 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 Tx<NUM>, to authenticate that the locking script in the input of Tx<NUM> 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 Tx<NUM> order to perform this authentication. In embodiments the signed data comprises the whole of Tx<NUM> (so a separate element does to 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 by encrypting it with her private key, then given Alice's public key and the message in the clear (the unencrypted message), another entity such as a node <NUM> is able to authenticate that the encrypted version of the message must have been signed by Alice. Signing typically comprises hashing the message, signing the hash, and tagging this onto the clear version of 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.

If the unlocking script in Tx<NUM> meets the one or more conditions specified in the locking script of Tx<NUM> (so in the example shown, if Alice's signature is provided in Tx<NUM> and authenticated), then the node <NUM> deems Tx<NUM> valid. If it is a mining node <NUM>, this means it will add it to the pool of transactions <NUM> awaiting proof-of-work. If it is a forwarding node 104F, it will forward the transaction Tx<NUM> to one or more other nodes <NUM> in the network <NUM>, so that it will be propagated throughout the network. Once Tx<NUM> has been validated and included in the blockchain <NUM>, this defines UTXO<NUM> from Tx<NUM> as spent. Note that Tx<NUM> can only be valid if it spends an unspent transaction output <NUM>. If it attempts to spend an output that has already been spent by another transaction <NUM>, then Tx<NUM> will be invalid even if all the other conditions are met. Hence the node <NUM> also needs to check whether the referenced UTXO in the preceding transaction Tx<NUM> is already spent (has already formed a valid input to another valid transaction). This is one reason why it is important for the blockchain <NUM> to impose a defined order on the transactions <NUM>. In practice a given node <NUM> may maintain a separate database marking which UTXOs <NUM> in which transactions <NUM> 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 <NUM>.

If the total amount specified in all the outputs <NUM> of a given transaction <NUM> is greater than the total amount pointed to by all its inputs <NUM>, this is another basis for invalidity in most transaction models. Therefore such transactions will not be propagated nor mined into blocks <NUM>.

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. the amount defined in UTXO<NUM> in Tx<NUM> can be split between multiple UTXOs in Tx<NUM>. Hence if Alice does not want to give Bob all of the amount defined in UTXO<NUM>, she can use the remainder to give herself change in a second output of Tx<NUM>, or pay another party.

In practice Alice will also usually need to include a fee for the winning miner, because nowadays the reward of the generation transaction alone is not typically sufficient to motivate mining. If Alice does not include a fee for the miner, Txowill likely be rejected by the miner nodes <NUM>, and hence although technically valid, it will still not be propagated and included in the blockchain <NUM> (the miner protocol does not force miners <NUM> to accept transactions <NUM> if they don't want). In some protocols, the mining fee does not require its own separate output <NUM> (i.e. does not need a separate UTXO). Instead any different between the total amount pointed to by the input(s) <NUM> and the total amount of specified in the output(s) <NUM> of a given transaction <NUM> is automatically given to the winning miner <NUM>. say a pointer to UTXO<NUM> is the only input to Tx<NUM>, and Tx<NUM> has only one output UTXO<NUM>. If the amount of the digital asset specified in UTXO<NUM> is greater than the amount specified in UTXO<NUM>, then the difference automatically goes to the winning miner <NUM>. Alternatively or additionally however, it is not necessarily excluded that a miner fee could be specified explicitly in its own one of the UTXOs <NUM> of the transaction <NUM>.

Alice and Bob's digital assets consist of the unspent UTXOs locked to them in any transactions <NUM> anywhere in the blockchain <NUM>. Hence typically, the assets of a given party <NUM> are scattered throughout the UTXOs of various transactions <NUM> throughout the blockchain <NUM>. There is no one number stored anywhere in the blockchain <NUM> that defines the total balance of a given party <NUM>. It is the role of the wallet function in the client application <NUM> to collate together the values of all the various UTXOs 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 <NUM> as stored at any of the storage nodes <NUM>, e.g. the storage node <NUM> that is closest or best connected to the respective party's computer equipment <NUM>.

Note that the script code is often represented schematically (i.e. not the exact language). For example, one may write [Checksig PA] to mean [Checksig PA] = OP_DUP OP_HASH160 <H(PA)> OP_EQUALVERIFY OP_CHECKSIG. " refers to a particular opcode of the Script language. OP_CHECKSIG (also called "Checksig") is a Script opcode that takes two inputs (signature and public key) and verifies the signature's validity using the Elliptic Curve Digital Signature Algorithm (ECDSA). At runtime, any occurrences of signature ('sig') are removed from the script but additional requirements, such as a hash puzzle, remain in the transaction verified by the 'sig' input. As another example, OP_RETURN is an opcode of the Script language for creating an unspendable output of a transaction that can store metadata within the transaction, and thereby record the metadata immutably in the blockchain <NUM>. the metadata could comprise a document which it is desired to store in the blockchain.

The signature PA is a digital signature. In embodiments this is based on the ECDSA using the elliptic curve secp256k1. A digital signature signs a particular piece of data. In embodiments, for a given transaction the signature will sign part of the transaction input, and all or part of the transaction output. The particular parts of the outputs it signs depends on the SIGHASH flag. The SIGHASH flag is a <NUM>-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 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 supplies the corresponding signature. However, more generally it is not essential in all applications of a blockchain <NUM> 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.

<FIG> illustrates an example of the node software <NUM> that is run on each node <NUM> of the P2P network <NUM>, in the example of a UTXO- or output-based model. The node software <NUM> comprises a protocol engine <NUM>, a script engine <NUM>, a stack <NUM>, an application-level decision engine <NUM>, and a set of one or more blockchain-related functional modules <NUM>. At any given node <NUM>, these may include any one, two or all three of: a mining module <NUM>, a forwarding module 455F and a storing module <NUM> (depending on the role or roles of the node). The protocol engine <NUM> is configured to recognize the different fields of a transaction <NUM> and process them in accordance with the node protocol. When a transaction 152j (Txj) is received having an input pointing to an output (e.g. UTXO) of another, preceding transaction 152i (Txi), then the protocol engine <NUM> identifies the unlocking script in Txj and passes it to the script engine <NUM>. The protocol engine <NUM> also identifies and retrieves Txi based on the pointer in the input of Txj. It may retrieve Txi from the respective node's own pool <NUM> of pending transactions if Txi is not already on the blockchain <NUM>, or from a copy of a block <NUM> in the blockchain <NUM> stored at the respective node or another node <NUM> if Txi is already on the blockchain <NUM>. Either way, the script engine <NUM> identifies the locking script in the pointed-to output of Txi and passes this to the script engine <NUM>.

The script engine <NUM> thus has the locking script of Txi and the unlocking script from the corresponding input of Txj. For example, transactions labelled Tx<NUM> and Tx<NUM> are illustrated in <FIG>, but the same could apply for any pair of transactions. The script engine <NUM> runs the two scripts together as discussed previously, which will include placing data onto and retrieving data from the stack <NUM> in accordance with the stack-based scripting language being used (e.g. Script).

By running the scripts together, the script engine <NUM> determines whether or not the unlocking script meets the one or more criteria defined in the locking script - i.e. does it "unlock" the output in which the locking script is included? The script engine <NUM> returns a result of this determination to the protocol engine <NUM>. If the script engine <NUM> determines that the unlocking script does meet the one or more criteria specified in the corresponding locking script, then it returns the result "true". Otherwise it returns the result "false".

In an output-based model, the result "true" from the script engine <NUM> is one of the conditions for validity of the transaction. Typically there are also one or more further, protocol-level conditions evaluated by the protocol engine <NUM> that must be met as well; such as that the total amount of digital asset specified in the output(s) of Txj does not exceed the total amount pointed to by its inputs, and that the pointed-to output of Txi has not already been spent by another valid transaction. The protocol engine <NUM> evaluates the result from the script engine <NUM> together with the one or more protocol-level conditions, and only if they are all true does it validate the transaction Txj. The protocol engine <NUM> outputs an indication of whether the transaction is valid to the application-level decision engine <NUM>. Only on condition that Txj is indeed validated, the decision engine <NUM> may select to control one or both of the mining module <NUM> and the forwarding module 455F to perform their respective blockchain-related function in respect of Txj. This may comprise the mining module <NUM> adding Txj to the node's respective pool <NUM> for mining into a block <NUM>, and/or the forwarding module 455F forwarding Txj to another node <NUM> in the P2P network <NUM>. Note however that in embodiments, while the decision engine <NUM> will not select to forward or mine an invalid transaction, this does not necessarily mean that, conversely, it is obliged to trigger the mining or the forwarding of a valid transaction simply because it is valid. Optionally, in embodiments the application-level decision engine <NUM> may apply one or more additional conditions before triggering either or both of these functions. if the node is a mining node <NUM>, the decision engine may only select to mine the transaction on condition that the transaction is both valid and leaves enough of a mining fee.

Note also that the terms "true" and "false" herein do not necessarily limit to returning a result represented in the form of only a single binary digit (bit), though that is certainly one possible implementation. More generally, "true" can refer to any state indicative of a successful or affirmative outcome, and "false" can refer to any state indicative of an unsuccessful or non-affirmative outcome. For instance in an account-based model (not illustrated in <FIG>), a result of "true" could be indicated by a combination of an implicit, protocol-level) validation of a signature by the node <NUM> and an additional affirmative output of a smart contract (the overall result being deemed to signal true if both individual outcomes are true).

An increasing amount of data is being stored on the blockchain, leveraging the security and immutability the blockchain provides. Going forward this may include the possibility of programming languages adopting objects that reference TXIDs, as well as executable files being stored on-chain and available to the public. As the mining services begin to emerge, it would be desirable to provide a way for miners to provide a means of decentralised computation, e.g. to eliminate the need for consumers to have large amounts of processing power in their personal devices. In this section, there is disclosed a method to enable such aims or similar through the inclusion of non-Script code within Script codes, to be evaluated off-chain, but whereby inputs and outputs are stored immutably on-chain. This parallels the virtual machines available on certain software such as account-based models.

Note: embodiments herein are exemplified in terms of the Script scripting language being used in the locking and unlocking scripts, and the second language being a non-Script language. However more generally, in other blockchain implementations, the techniques disclosed anywhere herein could be extended to any first and second language, where the first language is any stack-based, non-Turing-complete language used in the locking and unlocking scripts which is recognized by the nodes <NUM> of the blockchain network <NUM> according to the standard node protocol employed across the blockchain network <NUM>. The second language may be any Turing-complete, non-stack-based language. Embodiments are described below, and elsewhere herein, in terms of an example in which the first language is Script and the second language is a non-Script language. However it will be appreciated that this is not limiting, and any mention of Script and non-Script languages anywhere herein could be replaced more generally with the terms "first language" and "second language" respectively. Note also that term "language" as referred to herein means a computer language (i.e. programming language). This could be any form of code (software) recognizable by computer equipment to implement a set of rules, instructions or steps for operating the computer equipment. It could refer to a scripting language, a high-level language to be compiled, a high-level language to be interpreted, an assembly language to be assembled, or a low-level machine code language to be directly executed. Further, note that the term "execute" as referred to herein can refer generally to any such means of running any such program in any kind of language, and is not necessarily meant in a narrower sense of executing machine code instructions for example.

A native extension in software typically describes the process of embedding some code of one programming language in a script of another programming language (e.g. including a C code in a Ruby script). More generally, it is a means to connect one software to another. The embedded script may be compiled and linked locally so the resulting executable file can set a conditional depending on the returned value of the native extension. In this section, script (lower-case) refers to a set of code-based instructions and Script (upper-case) refers to the programming language recognized by the nodes <NUM> of the blockchain network <NUM> for use in locking and unlocking scripts to validate transactions <NUM> according to the node protocol recognized by the nodes <NUM> of the network <NUM>.

According to embodiments disclosed herein, a script can be defined that uses an external code embedded inside Script code. This script links to an external non-Script library, executes and returns a value into the Script code that can be verified or analysed using, e.g., the standard OP codes. This method can analyse a value using inputs from the blockchain <NUM> or user as well as be used to select a variety of transaction options. An example schematic of the process is shown in <FIG>.

<FIG> shows an example schematic of the execution of non-Script code <NUM>. The wallet or node software uses a program launcher such as an integrated virtual machine to evaluate the non-Script code <NUM> with external non-Script libraries <NUM>. In embodiments the results can then be pushed to the stack <NUM> and evaluated using Script OP codes.

Use of non-Script code can allow for more complex control data and verification steps embedded within a compressed executable file. If the virtual machine that can execute the embedded script is integrated within the wallet or node software, then the blockchain's security and identity verification also can be provided to the software. This can be used to directly target the existing issue of software piracy, for example, as redistributing software would require exposing one's private key in a blockchain-based scenario.

In the script, the control data and/or key verification can be included as a set of conditional statements (e.g. if, else, while) in the non-script code <NUM>. An extractor included in a branch of the script engine <NUM> can then read the compressed executable file stored in an OP_RETURN, OP_PUSHDATA and/or OP_DROP, and then decompress and run the code on the integrated virtual machine. This process allows data outside the transaction to be accessed by transaction scripts, increasing the versatility of scripts while adhering to the base protocol.

<FIG> shows an extension to the node software <NUM> in accordance with embodiments disclosed herein. The script engine <NUM> additionally comprises an extractor <NUM>, and the node software <NUM> additionally comprises a program launcher <NUM> for running non-Script code <NUM>. The node software <NUM> may also comprise one or more non-Script libraries <NUM>. The extractor is configured to extract non-Script code <NUM> from a transaction <NUM> and pass this to the program launcher <NUM> to run. In embodiments this may include using one or more of the non-Script libraries <NUM> to run the non-Script code <NUM>.

The described process is run by the node software <NUM> on at least one node <NUM> of the blockchain network. In general this could be any type of node <NUM> that validates transactions <NUM>: a mining node <NUM>, a storage node <NUM> and/or a forwarding node 104F. However in particularly preferred embodiments the process is implemented at least by one or more of the mining nodes <NUM>. This way the miner is paid to run the non-Script software <NUM>, at least by the inherent mining fee and also by any additional mining fee left explicitly by the payer, e.g. Alice 103a. As will be discussed in more detail shortly, the present disclosure provides a mechanism whereby the non-Script code <NUM> has to be run in order to validate the relevant transaction, and hence the miner has to run the non-Script code <NUM> in order to obtain the fee.

The script engine <NUM> is arranged to receive a first transaction 152i (Txi) which is already recorded in a block <NUM> on the blockchain <NUM>. It does this either by accessing its own node's local record of the transactions <NUM> on the blockchain <NUM>, or by accessing the record on another node <NUM> (e.g. a storage node <NUM>). The first transaction Txi comprises a spendable output <NUM> comprising a locking script, i.e. the Script code <NUM>.

The script engine <NUM> is also arranged to receive a second transaction 152j (Txj), which is not yet recorded in a block <NUM> on the blockchain <NUM>. Rather, the second transaction is going to be validated for propagation and/or mining based on the presently disclosed mechanism. The second transaction Txj may be received from an end-user's user equipment <NUM>, e.g. from Alice's equipment 102b. Alternatively the second transaction Txj may be received from another node <NUM> acting as a forwarding node 104F. As another possibility, the second transaction Txj could be formulated at the node <NUM> performing the validation, in which case it is received from another internal process of the local node <NUM>. From wherever it is received, the second transaction Txj comprises an input <NUM> pointing to the output <NUM> of the first transaction Txi. The input <NUM> of the second transaction Txj also comprises an unlocking script for unlocking the output of the first transaction Txi, and thereby having the second transaction Txj validated for propagation and/or mining (and therefore ultimately recordal in a block <NUM> on the blockchain <NUM>). The unlocking script is formulated in the same scripting language as the locking script, i.e. Script in this example.

The extractor <NUM> is configured to automatically extract the non-Script code <NUM> from the first transaction Txi and pass the extracted non-Script code <NUM> to the non-Script program launcher <NUM> to execute (run).

Where the non-Script code <NUM> is embedded in the same transaction as the locking script <NUM>, i.e. the first transaction Txi, there are a number of options for this. Since the inclusion of the non-Script code <NUM> is a non-standard element, then in principle it can be included anywhere in the first transaction Txi (either in the same spendable output as the respective locking script <NUM>, or in another output such as an unspendable output, or elsewhere such as appended to the transaction) as long as the extractor <NUM> is configured to know where to look for it or how to find it in the transaction data structure. This could be achieved by including the non-Script code <NUM> at a predetermined position or in a predetermined field of the transaction <NUM> (Txi in this example). In this case the extractor <NUM> is pre-configured to extract the non-Script code <NUM> from the predetermined field or position. Alternatively the position of the non-Script code <NUM> in the transaction data structure could be indicated with a code marker. For instance, in some embodiments a non-standard (non-Script) code marker could be used, such as NSC_{. }, where the portion between the curly braces comprises the non-script code <NUM>. As another option however, the non-Script code <NUM> could be embedded in one of the outputs <NUM> of the first transaction Txi (e.g. embedded in the locking script <NUM> itself) by using an opcode of the scripting language of the locking script <NUM>, i.e. in this example using a Script OP code.

The Script OP code used for this could be an OP_RETURN. In this case the non-Script code <NUM> is included in a separate output <NUM> than the locking script <NUM>. An OP_RETURN has the effect of terminating the script of any output <NUM> in which it is included when run by the script engine <NUM> of a node <NUM>. Hence OP_RETURN renders the output in which it included unspendable. This enables the output in question to be used instead to carry any arbitrary payload data.

As another example, a Script OP code such as OP_DROP or OP_PUSHDATA could be used to embed the non-Script code in the locking script <NUM> itself, in the same output <NUM>. For instance, OP_DROP tells the script engine <NUM> to ignore whatever comes before the OP_DROP during execution of the unlocking script. This can be used to include the non-Script code <NUM> in the locking script <NUM> without causing an error when the locking script <NUM> is run by the script engine <NUM>. OP_PUSHDATA tells the script engine <NUM> to push the next N bytes to the stack <NUM> e.g. OP_PUSHDATA4 say pus the next <NUM> bytes to the stack). This could be used to push non-Script code onto the stack <NUM>, and the extractor <NUM> would then read the non-Script code from the stack <NUM>.

Whatever extraction means are employed, the extractor <NUM> passes the extracted non-Script code <NUM> to the program launcher <NUM> to run. In embodiments the extractor <NUM> may also remove the non-Script code <NUM> (and any non-Script code marker), leaving only the standard transaction format comprising only standard Script <NUM> in the output(s) <NUM> to be run by the script engine <NUM>. However in other embodiments such as those using OP_RETURN, OP_DROP or OP_PUSHDATA, this is not necessary, as the locking Script <NUM> is already written so as to ignore or render ineffectual the non-Script code <NUM> when encountered by the script engine <NUM>.

The program launcher <NUM> is configured to run the non-Script code <NUM> received from the extractor <NUM>. The non-Script code <NUM> could comprise any high or low level language. It may comprise for example any scripting language, language requiring compilation, language requiring linking, language requiring assembly, and/or an interpreted language. The running of the non-Script code <NUM> by the code launcher <NUM> may comprise any one or more of: compiling, linking, assembling and/or interpreting, depending on the language. For instance the non-Script code <NUM> could be C, C++, Python, Java script, BASIC, etc., or even a combination of languages. In embodiments the non-Script code launcher <NUM> may take the form of a virtual machine. It may refer to one or more libraries <NUM> to run the non-Script code <NUM>, e.g. by linking to the library or libraries <NUM>.

When run by the code launcher <NUM>, the non-Script code <NUM> performs one or more operations which result in one or more first values being output to a storage location readable by the first language recognized by the standard script engine <NUM>. Physically this storage location could be any non-volatile memory, RAM, or even one or more registers. As the first language is a stack-based language such as Script, then the storage location is the stack <NUM>. the destination storage location for the value(s) output by the non-Script code <NUM> is the stack <NUM>, making it accessible to the stack-based scripting language (e.g. Script) recognised by the script engine <NUM>.

The locking script <NUM> of the first transaction Txi is configured such that outputting "true", and thereby enabling validation, is dependent on at least one of the values written to the stack <NUM> by the non-Script code <NUM>. Hence validation of the second transaction Txj is forced to be conditional on running the non-Script code <NUM> at the respective node <NUM>.

Beyond this, the specific condition placed by the locking script <NUM> on the value(s) written to the stack <NUM> by the non-Script code <NUM> could be virtually anything that a user or developer desires. According to the present disclosure, the condition comprises at least that a value written to the stack by the non-Script code matches a value specified in the second transaction Txj. In the example given where the payer is Alice, i.e. the output <NUM> of the first transaction Txi is locked to Alice, then the non-Script code <NUM> may be some code that Alice wishes to pay a miner to execute for her, e.g. to perform some computational analysis or machine learning task on the network <NUM> instead of Alice's own equipment 103a. The expected output value of the non-Script code <NUM> could for example be a desired outcome, or evidence that the non-Script code <NUM> has been properly executed.

For instance, in embodiments Bob 103b may be miner (so his computer equipment 102b comprises a mining node <NUM> rather than just end-user equipment). The input <NUM> of the second transaction Txj points to the output <NUM> of the first transaction Txi which is locked to Alice, and the second transaction Txj has an output <NUM> locked to miner Bob or another party. So in this scenario Alice is paying Bob at least the mining fee, and possibly also an explicit fee, in order to run her desired software. The output of the non-Script code <NUM> can be pushed to the stack <NUM> running in the Script code allowing for OP_CODES to be applied. The value returned (the "first" value) can then be used to unlock other scripts or to unlock and complete the same script that the loader was in. Bob has to run the non-Script software <NUM> or else the second transaction Txj won't be validated and he won't receive his fee. The output <NUM> containing the locking script <NUM> could specify a dust (negligible) amount of the digital asset, whereas the input <NUM> of the first transaction Txi is a non-negligible amount, so that in effect only the miner is being paid. Alternatively another party could be being paid by the output <NUM> (or another output) as well.

To check the condition placed on the output value (the "first" value) of the non-Script code <NUM>, the script engine <NUM> is configured to receive a second value, compare the second value to the first value (the value output by the non-Script code <NUM>), and output a result of true on condition that the first and second values match. The second value is received from the input <NUM> of the second transaction Txj. It will be appreciated that "first" and "second" in this context are again just arbitrary labels and do not necessarily imply anything about the order in which the values are generated.

For instance, the locking script <NUM> in the output <NUM> of the first transaction Txi could be:
{Non Script Code <NUM>} (Expected Output) OP_EQUALVERIFY.

In which case, in order to have a valid second transaction Txj, the unlocking script in the input <NUM> of the second transaction Txj would be:
{Non Script Code <NUM> Input}.

Here, 〈 〉 denotes pushing to the stack and { } denotes non-Script code executed externally with output pushed to the stack. The Expected Output is the first value (the value output by the non-Script code <NUM> to the stack <NUM>), and Non Script Code <NUM> Input is the second value, i.e. that being compared to the output of the non-Script code <NUM>.

In this example it is required that the first value is identical to the second value in order to validate the second transaction. However more generally, a match could be require identical values or could allow some other criterion for a match, e.g. the first and second values being within a margin of error in the case where the values are numbers, or being synonyms of the values are words, etc..

In further examples, the locking script <NUM> could be conditional on more than one value to be output by the non-Script code.

For example the locking script <NUM> in the output <NUM> of the first transaction Txi could be:
{Non Script Code <NUM>} (Expected Output) OP_EQUALVERIFY {Non Script Code <NUM>}.

And the corresponding unlocking script in the input <NUM> of the second transaction Txj would be:
{Non Script Code <NUM> Input} {Non Script Code <NUM> Input}.

The execution of the example script above is shown in <FIG>.

In this example it is required that each of two first values (expected values) output by the non-Script code <NUM> is equal to a respective one of two corresponding second values (in this case both specified in the input of the second transaction Txj). In other examples the locking script <NUM> could specify that the condition is met if, e.g., either one of the two values matches its respective second value (i.e. a logical OR, such that both matches are not necessarily required). Another example would be an XOR. These ideas could also be extended to more than two first values and their corresponding second values.

The evaluation of the script is done using a hybrid on-chain/off-chain mechanism where the inputs and outputs are recorded on-chain, verification of conditions is performed on-chain but complex conditions are evaluated off-chain. This provides a method for miners to perform paid decentralized computations should they choose to specialize in this.

In the above examples, as no signature is required to redeem the transaction, anyone can submit inputs by attempting to spend the transaction and any verification conditions can be implemented in (Non Script Code <NUM>). Alternatively however, one or more further conditions for validation (not dependent on the non-Script code <NUM>) could additionally be imposed by the locking script <NUM> of the first transaction Txi. These could comprise one or more conventional conditions, such as authenticating a signature of Bob included in the unlocking script of the second transaction Txj, or that the unlocking script of the second transaction Txj provides the solution to a hash puzzle set in the locking script <NUM> of the first transaction Txi.

Claim 1:
A computer-implemented method performed by a node (<NUM>) of a blockchain network (<NUM>), wherein copies of a blockchain (<NUM>) are maintained across at least some of the nodes (<NUM>) of the blockchain network, the blockchain comprising a chain of blocks (<NUM>) each comprising one or more transactions (<NUM>), each transaction comprising one or more outputs (<NUM>), and each output comprising a locking script formulated in a first language, wherein the first language is not Turing complete and is a stack-based language for placing values onto a stack (<NUM>) and reading values from the stack; wherein the method comprises:
accessing the locking script (<NUM>) from at least a first output of a first of said transactions (Txi), the locking script of the first output specifying, in the first language, one or more conditions for unlocking said first output; and
receiving a second transaction (Txj) not yet recorded on the blockchain, wherein the second transaction comprises an input comprising an unlocking script formulated in the first language;
the method further comprises:
extracting, from the first transaction, a portion of code (<NUM>) formulated in a second language other than the first language, wherein the second language is Turing complete and is not stack-based;
running the extracted portion of code in the second language, wherein as a result thereof the code generates at least one first value;
writing the first value to the stack (<NUM>), the stack being readable by the locking script in the first language; and
running, in the first language, the locking script from the first output of the first transaction together with the unlocking script from the second transaction, thereby evaluating the one or more conditions, the method comprising validating the second transaction on condition of said one or more conditions being met;
wherein the unlocking script is configured to read the first value from the stack;
wherein the second value is included in the second transaction (Txj), the method comprising extracting the second value from the second transaction; and
wherein the unlocking script is configured to compare the first value as read from the stack with the second value as extracted from the second transaction, the one or more conditions comprising a condition that the first value matches the second value.