Method for controlling flow execution of generated scripts for blockchain transactions
By inserting the code of the control flow mechanism into the blockchain transaction script, the problem of restricted blockchain script language functions is solved, and the security and security of executing complex functions on the blockchain is realized, and the blockchain is expanded. Functional capabilities of the protocol.
Patent Information
- Application Number
- CN202411373079.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2017-07-07
- Filing Date
- 2018-07-05
- Publication Date
- 2025-01-17
AI Technical Summary
Blockchain scripting languages (such as Script) are limited in functionality and cannot support complex control flow structures, resulting in a trade-off between security and utilization risks when executing complex functions on the blockchain.
Simulating complex control flow functions by inserting code of control flow mechanisms into blockchain transaction scripts, such as looping and selecting control structures, ensure the security of performing complex functions on the blockchain network and preventing protocol utilization.
The ability to execute complex functions on the blockchain is realized, while maintaining security and preventing protocol utilization, expanding the functional capabilities of the blockchain protocol.
Smart Images

Figure CN119322611A_ABST
Abstract
Description
[0001] This application is a divisional application of the PCT national phase application with a filing date of July 5, 2018 and national application number 201880045599.7. Technical Field
[0002] The present invention relates generally to blockchain technology, and more specifically to enabling complex functionality through blockchain. Advantageously, the present invention provides a mechanism that enables blockchain transactions to include functionality typically provided by control flow structures. Thus, the present invention extends the capabilities and functionality of blockchain scripts, and thereby the blockchain protocol itself, without modifying the underlying existing protocol. Transactions generated in accordance with the present invention can be used as a control mechanism for implementing, influencing, and directing the actions of computer-implemented processes. The present invention is suitable for, but not limited to, implementing and controlling automated processes. Background Art
[0003] As used herein, the term "blockchain" is used to encompass all forms of consensus-based, computer-based electronic distributed ledgers, including but not limited to blockchain and transaction chain technologies, permissioned and unpermissioned ledgers, shared ledgers, and variants thereof. The most widely known application of blockchain technology is the cryptocurrency ledger, although other blockchain implementations have been proposed and developed. Although cryptocurrency may be referred to herein for convenience and purposes of illustration, it should be noted that the present invention is not limited to use with cryptocurrency blockchains, and alternative blockchain implementations and protocols fall within the scope of the present invention.
[0004] A blockchain is a consensus-based electronic ledger implemented as a decentralized, distributed computer-based system that consists of blocks, which in turn consist of transactions. Each transaction is a data structure that encodes the transfer of control of a digital asset between participants in the blockchain system and includes at least one input and at least one output. Each block contains a hash of the previous block, so that the blocks become linked together to create a permanent, unchangeable record of all transactions that have been written to the blockchain since its inception. Transactions contain small programs called scripts embedded in their inputs and outputs that specify how and by whom the outputs of the transaction can be accessed. On cryptocurrency platforms, these scripts are written using a stack-based scripting language.
[0005] In order for a transaction to be written to the blockchain, it must be "validated". Network nodes work to ensure that each transaction is valid, and invalid transactions are rejected from the network. The software client installed on the node does this validation work for unspent transactions (UTXO) by executing its locking and unlocking scripts. If the execution of the locking and unlocking scripts evaluates to TRUE, then the transaction is valid and is written to the blockchain. Therefore, in order for a transaction to be written to the blockchain, the transaction must i) be validated by the first node that receives the transaction - if the transaction is validated, the node relays it to other nodes in the network; ii) be included in a new block built by the network nodes; iii) be mined, i.e. added to the public ledger of past transactions.
[0006] While blockchain technology is best known for its use in cryptocurrency implementations, digital entrepreneurs have begun exploring the use of both the cryptographically secure systems that cryptocurrencies are based on and the data that can be stored on blockchains to implement new systems. It would be extremely advantageous if blockchains could be used to automate tasks and processes that are not limited to the cryptocurrency space. Such solutions would be able to leverage the benefits of blockchains (e.g., permanent, tamper-proof proof records of events, distributed processing, etc.) while being more versatile in its application. Summary of the invention
[0007] According to the present invention, there is provided a computer implemented system / method as defined in the accompanying claims.
[0008] The present invention may provide a computer-implemented method. It may be described as a method configured to enable or suitable for generating a blockchain transaction (Tx). Additionally or alternatively, it may be described as a method for controlling the execution of a transaction (Tx) script to control or influence whether an output associated with a blockchain transaction is unlocked (consumed). Therefore, it is a method for controlling or influencing an encryption process. The method may also be described as controlling the transfer or exchange of resources through a blockchain network. The present invention may also be described as providing a security technique that allows or enables Turing-complete functionality within or by a blockchain script without compromising adaptability to exploits. Therefore, the present invention provides an enhanced blockchain because transfers and exchanges can be performed on a blockchain network in a more complex and technically superior manner while maintaining security and preventing exploitation of the protocol.
[0009] The method may include the step of receiving or generating or deriving at least one data item using a software resource. A data item may also be referred to as a "signal", "value", "parameter" or "input". The data item may be received as a signal. It may be received from an off-chain source. Thus, the data item may be used to determine the number of times code is copied or inserted into a script, and may be determined and / or generated outside of the script. It may be generated by a computing resource as a result of a calculation. It may be generated by using a random or pseudo-random number generator.
[0010] The steps may include inserting at least a portion of the code at least once into a script associated with or for a blockchain transaction, such that when the script is executed, it provides the functionality of a control flow mechanism. The portion of the code may be pre-specified or pre-written. It may be stored in a computer-based resource and may be retrieved from storage prior to insertion into the script.
[0011] The script can be associated with a transaction in that it forms part of the transaction and / or can be used to lock / unlock a portion of cryptocurrency to be transferred using the transaction.
[0012] The method may include the step of generating a blockchain transaction. The method may include the step of submitting the transaction to the blockchain network. It may include the step of using the transaction to transfer a resource or control of a resource from one node or party to another node or party on the network.
[0013] The behavior / execution of the control flow mechanism may be controlled or influenced by at least one data item. Preferably, after insertion into at least a portion of the code, the script may not include any Turing complete control structures (e.g., loops, recursive jumps, high-level control structures). Preferably, after at least one insertion into at least a portion of the code, the script is compatible with execution on a blockchain using a limited-function (non-Turing complete) language. This may be a Script language used by a blockchain implementing a cryptocurrency protocol or a variant thereof.
[0014] The script may be associated with an input or output of a blockchain transaction. Transactions may be generated according to a blockchain protocol. This may be a cryptocurrency protocol. The script may be written in the Script programming language or other stack-based scripting language. The script may be written in a language that is limited in functionality (also referred to as "non-Turing complete"). The language is limited in functionality in the sense that it does not inherently support one or more control flow mechanisms such as loops and / or recursive jumps.
[0015] The method may comprise the step of inserting and / or copying at least a portion of the code into the script more than once and / or at more than one location within the script.
[0016] The method may comprise the step of using at least one data item to determine a number of times at least a portion of the code has been inserted / copied into the script.
[0017] The control flow mechanism can be a loop, such as a for or while loop, or a selection control mechanism such as a switch / Case statement.
[0018] The at least one data item may be derived from a compiler arranged to convert code from a high level language (HLL) into a blockchain transaction script.
[0019] The portion of the code may include a counter or index that is incremented at least once when the script is executed, the counter or index being used to control or influence the execution of the script.
[0020] Counters or indexes can be incremented or manipulated using values stored in and / or retrieved from both stack-based data structures.
[0021] The present invention may also include a computer-implemented system arranged to implement the method of any embodiment described herein. Any aspects or features described with respect to the method may also be applicable to a corresponding system. The system may include at least one computer-based resource. It may also include one or more blockchain nodes.
[0022] The present invention also provides a system, comprising:
[0023] Processor; and
[0024] A memory comprising executable instructions that, upon execution by the processor, cause the system to perform any embodiment of the computer-implemented method described herein.
[0025] The present invention also provides a non-transitory computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor of a computer system, causes the computer system to perform at least an embodiment of the computer-implemented method described herein. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] These and other aspects of the invention will become apparent from and will be elucidated with reference to the embodiments described herein. Embodiments of the invention will now be described by way of example only with reference to the accompanying drawings, in which:
[0027] FIG1 provides a simple illustration of a decentralized blockchain network known in the prior art.
[0028] Figure 2 A flow chart illustrating an embodiment according to the present invention is shown.
[0029] Figure 3 An exemplary network associated with a blockchain that may be used in accordance with the present invention is shown. DETAILED DESCRIPTION
[0030] A cryptocurrency network is an example of a blockchain implementation, as shown in Figure 1. Cryptocurrencies utilize a scripting language called Script. Script is a language similar to Forth that uses a set of primitive operators or commands (called opcodes) to create relatively simple programs. Script uses a data structure called a stack for temporary storage of data items (variables and constants) during program execution. Data items are pushed onto the stack, one on top of the other, and then popped off in reverse order. Typically, the item pushed onto the stack will be popped off later so that it can be used as an operand for the next operation. At the end of the Script program, the value left on the top of the stack is the return value.
[0031] As known in other stack-based languages such as Forth, it is often convenient to have access to another stack. In Script, the second stack is called the alt stack, while the first stack is called the main stack. The alt stack is often used to store temporary data during script execution.
[0032] However, in contrast to Forth, Script does not have a built-in syntax for executing complex control flow statements (such as loops). Control flow statements are programming mechanisms used to influence and direct (i.e., control) how a program executes. Specific values are used to determine the path that the logic takes at run time. These values can be hard-coded into the program or provided as dynamic input at run time. The value can then be used in the decision-making process (e.g., is value a less than or equal to value b? Does string x = "HelloWorld!"?). Examples of control flow statements include while loops, for loops, and switch-case statements.
[0033] Script's prohibition of this mechanism is an intentional security feature: complex control mechanisms can potentially make a blockchain network vulnerable to exploits such as denial of service (DOS or DDOS) attacks. However, the trade-off is that programmers are restricted in how they write Script code, for example not being able to include loops in the source code. This has led some to describe Script as non-Turing complete (although others refute that definition).
[0034] Therefore, there is a need to provide a technical solution to address the trade-off between the security provided by a limited-function blockchain scripting language (such as Script) and the desire to perform more complex functions through a blockchain platform. Ideally, this will be achieved in a way that facilitates the coding process through software resources, such as through automation.
[0035] The present invention provides a solution to at least this problem and implements a mechanism whereby the functionality of a complex control flow mechanism can be implemented, or at least simulated on a blockchain using a functionally limited scripting language. (Due to the debate in the field about the Turing completeness of Script, the language may be referred to herein as "functionally limited" rather than "non-Turing complete", although the terms are used interchangeably). The examples used herein for illustrative purposes only present solutions that allow simulation of for loops and switch-case control sequences. Those skilled in the art will appreciate that the present invention may provide other types of control flow mechanisms.
[0036] The treatments that can be used according to the invention are Figure 2 . According to the present invention, a determination is made as to how the logic is controlled within a transaction (Tx) script. For example, the determination may be a pre-determination of the statements that should be executed within the body per iteration of a loop, or a pre-determination of the statements that should be executed for each option (case) in a switch structure. These may be stored as (one or more) portions of code for subsequent retrieval during script / transaction generation.
[0037] Once generated or received, the determination is then used to generate code for the script of the blockchain transaction. This can be an unlocking script, a redeem script, or an unlocking script. In particular, a portion of the code is inserted into the script at the appropriate location within the script the desired number of times.
[0038] The portion of code may be, for example, code that executes an instance of a loop, or an option in a switch command sequence. Portions of code are repeated as needed within the script so that one or more statements may be executed based on the value of a data item and / or the evaluation of a condition. For example, if (i<3), then <execute the body of the loop>, or if (i==2), then <execute the statement and jump out of the switch>.
[0039] The generation of the script code may be performed manually. However, in a preferred embodiment of the invention, the code (and the entire transaction) is generated by an automated process, ie, executed by a suitably configured software resource or agent running on a processor.
[0040] In this embodiment, the software agent is arranged to receive or generate a data item. The data item is an input or signal that can be used to determine the number of times a portion of code needs to be set within a script. The same or another data item can be used to control the execution of the script during evaluation, for example by using it within a conditional of a control loop, or by using it as the value of a switch case for testing it.
[0041] Alternatively, portions of code may be predetermined and stored in memory. When the software agent needs to generate a script, it may access the portion of code from memory, insert it into the script as many times as needed, and adapt the portion of code accordingly, thereby testing the relevant control conditions using the above data items.
[0042] Thus, once the software agent receives the relevant data item, it can use the data item to generate a transaction script that includes code that emulates complex control flow functionality as needed at runtime. The script can be used in the generation of a blockchain transaction, which can then be submitted to the network for verification and propagation.
[0043] Thus, the present invention can be used to control the manner in which scripts associated with the inputs / outputs of blockchain transactions are executed. In practice, this controls whether the outputs associated with a transaction (Tx) can be spent, and in turn controls whether cryptographic ownership of an asset (i.e., a portion of a cryptocurrency, a token, etc.) on the blockchain can be transferred from one entity to another. In another sense, the present invention controls or influences the cryptographic process.
[0044] Examples are now provided to analyze and explain the concepts and techniques described above.
[0045] Use case 1: Simulating a for loop
[0046] In this example, a Script-based sequence of operations is provided that emulates the behavior of a for loop as if the for loop were natively supported by the language.
[0047] The loop is of the form:
[0048] for iin[K,N]
[0049] <execution statement> / / "body" of the loop
[0050] end
[0051] Let K and N be the lower and upper limits of the interval I = [K:N] respectively. The sequence of operations takes the following form:
[0052] OP_N OP_K OP_2DUP OP_SWAP OP_TOALTSTACK OP_TOALTSTACK
[0053]
[0054]
[0055]
[0056]
[0057] …
[0058] …
[0059]
[0060] OP_DROP OP_DROP
[0061] It should be noted that the box representing an instance of a loop is provided multiple times, say P times, and P > N. Furthermore, the code of the loop body <execute statement> should not modify the state of the main stack or the alt stack.
[0062] Loop Example 1: Loop from 0 to 2
[0063] In the following example, assume that the code in the box is copied 3 times. In this example, the verification <execute statement> is executed 2 times.
[0064] Consider the following code snippet:
[0065] OP_2OP_0OP_2DUP OP_SWAP OP_TOALTSTACK OP_TOALTSTACK
[0066] The stack should look like this (the left column is the main stack, the right column is the alt stack):
[0067]
[0068] OP_GREATERTHAN
[0069] OP_IF
[0070] OP_FROMALTSTACK OP_1ADD OP_TOALTSTACK
[0071] <Execute statement>
[0072] OP_ENDIF
[0073] OP_FROMALTSTACK OP_FROMALTSTACK OP_2DUP OP_TOALTSTACK OP_TOALTSTACKOP_SWAP
[0074]
[0075] OP_GREATERTHAN
[0076] OP_IF
[0077] OP_FROMALTSTACK OP_1ADD OP_TOALTSTACK
[0078] <Execute statement>
[0079] OP_ENDIF
[0080] OP_FROMALTSTACK OP_FROMALTSTACK OP_2DUP OP_TOALTSTACK OP_TOALTSTACKOP_SWAP
[0081]
[0082] OP_GREATERTHAN
[0083] OP_IF
[0084] OP_FROMALTSTACK OP_1ADD OP_TOALTSTACK
[0085] <Execute statement>
[0086] OP_ENDIF
[0087] OP_FROMALTSTACK OP_FROMALTSTACK OP_2DUP OP_TOALTSTACK OP_TOALTSTACKOP_SWAP
[0088]
[0089] OP_DROP OP_DROP
[0090]
[0091] Use case 2: Simulating a switch-case command sequence
[0092] In this example, a CryptoScript simulation of a switch command sequence is described. It is desirable to simulate the following types of command sequences:
[0093] (start up)
[0094] case i equals value1
[0095] Execute Statement
[0096] break
[0097] case i equals value2
[0098] Execute Statement
[0099] break
[0100] …
[0101] …
[0102] case i equals valueN
[0103] Execute Statement
[0104] break
[0105] (closure)
[0106] Now, let X be the value to be checked. When written using the syntax of the CryptoScript language, the switch-case code becomes:
[0107] OP_X OP_DUP OP_TOALTSTACK
[0108] OP_1OP_EQUAL
[0109] OP_IF
[0110] <Execute statement 1>
[0111] OP_ENDIF
[0112] OP_FROMALTSTACK OP_DUP OP_TOALTSTACK
[0113] OP_2OP_EQUAL
[0114] OP_IF
[0115] <Execute statement 2>
[0116] OP_ENDIF
[0117] OP_FROMALTSTACK OP_DUP OP_TOALTSTACK
[0118] …
[0119] …
[0120] OP_N OP_EQUAL
[0121] OP_IF
[0122] <Execute statement N>
[0123] OP_ENDIF
[0124] OP_FROMALTSTACK OP_DUP OP_TOALTSTACK OP_DROP
[0125] Example 1:
[0126] The input signal is OP_2. It is checked that the code only executes <Execute Statement 2> and it is assumed that the code contains three statements.
[0127] OP_2OP_DUP OP_TOALTSTACK
[0128]
[0129] OP_1OP_EQUAL
[0130]
[0131] OP_IF
[0132] <Execute statement 1>
[0133] OP_ENDIF
[0134] OP_FROMALTSTACK OP_DUP OP_TOALTSTACK
[0135]
[0136] OP_2OP_EQUAL
[0137]
[0138] OP_IF
[0139] <Execute statement 2>
[0140] OP_ENDIF
[0141] OP_FROMALTSTACK OP_DUP OP_TOALTSTACK
[0142]
[0143] OP_3OP_EQUAL
[0144]
[0145] OP_IF
[0146] <Execute statement 3>
[0147] OP_ENDIF
[0148] OP_FROMALTSTACK OP_DUP OP_TOALTSTACK
[0149]
[0150] OP_DROP
[0151]
[0152] Blockchain Network
[0153] Reference now Figure 3 , which shows in block diagram form an exemplary network associated with a blockchain, which may be referred to herein as a blockchain network 100 and may be used to implement the present invention. The blockchain network 100 is a peer-to-peer open member network that anyone can join without invitation or consent from other members. Distributed electronic devices running an instance of a blockchain protocol (under which the blockchain network 100 operates) may participate in the blockchain network 100. Such distributed electronic devices may be referred to as nodes 102. The blockchain protocol may be, for example, a cryptocurrency protocol.
[0154] The electronic devices that run the blockchain protocol and form the nodes 102 of the blockchain network 100 may be various types of devices, including, for example, computers (e.g., desktop computers, laptop computers, tablet computers), servers, mobile devices such as smart phones, wearable computers such as smart watches, or other electronic devices.
[0155] The nodes 102 of the blockchain network 100 are coupled to each other using suitable communication technologies, which may include wired and wireless communication technologies. In many cases, the blockchain network 100 is implemented at least in part on the Internet, and some nodes 102 may be located in geographically dispersed locations.
[0156] Nodes 102 maintain a global ledger of all transactions on the blockchain, which is divided into blocks, and each block contains a hash of the previous block in the chain. The global ledger is a distributed ledger, and each node 102 can store a complete copy or a partial copy of the global ledger. Transactions of nodes 102 that affect the global ledger are verified by other nodes 102, thereby maintaining the validity of the global ledger. The details of implementing and operating a blockchain network (such as a blockchain network using a cryptocurrency protocol) are understood by those skilled in the art.
[0157] Each transaction generally has one or more inputs and one or more outputs. Scripts embedded in the inputs and outputs specify how and by whom the outputs of the transaction are accessed. The output of a transaction may be an address to which the value is transferred as a result of the transaction. The value is then associated with the output address as an unspent transaction output (UTXO). Subsequent transactions may then refer to the address as an input, thereby consuming or dispersing the value.
[0158] Nodes 102 can perform many different functions from network routing to wallet services to maintain a robust and secure, decentralized public ledger. A "full node" contains a complete and up-to-date copy of the blockchain, and can therefore verify any transaction (consumed or unconsumed) on the public ledger. A "lightweight node" (or SPV) maintains a subset of the blockchain and can verify transactions using "simple payment verification" technology. Lightweight nodes only download the headers of the blocks, not the transactions within each block. These nodes therefore rely on peer nodes to verify their transactions. A "mining node" can be a full node or a lightweight node, responsible for verifying transactions and creating new blocks on the blockchain. A "wallet node" is typically a lightweight node that handles the wallet service for the user. Nodes 102 communicate with each other using a connection-oriented protocol, such as TCP / IP (Transmission Control Protocol).
[0159] It should be noted that the above embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design many alternative embodiments without departing from the scope of the invention as defined by the appended claims. In the claims, any reference signs in brackets shall not be construed as limiting the claims. The words "comprising, comprise" and the like do not exclude the presence of elements or steps in addition to those listed in any claim or in the entire specification. In this specification, "comprises" means "includes or consists of", and "comprising" means "including or consisting of". The singular reference of an element does not exclude the plural reference of the element, and vice versa. The present invention may be implemented by hardware comprising several different elements and by a suitably programmed computer. In a device claim enumerating several means, several of these means may be implemented by one and the same item of hardware. The fact that certain measures are recited in mutually different dependent claims does not mean that a combination of these measures cannot be used to advantage.
Claims
1. A computer-implemented method comprising the following steps: receiving, generating or deriving at least one data item; Inserting at least a portion of the code at least once into a script associated with a blockchain transaction so as to provide functionality of a control flow mechanism when the script is executed, the behavior of the control flow mechanism being controlled or affected by the at least one data item, wherein the script is written in a stack-based scripting language and the portion of the code does not modify a state of the stack.
2. The method according to claim 1, wherein: The script is associated with an input or an output of the blockchain transaction.
3. The method according to claim 1 or 2, wherein: The transaction is generated in accordance with a blockchain protocol, or is generated for use with a blockchain protocol.
4. The method according to claim 3, wherein: The protocol is a cryptocurrency protocol or a variation of a cryptocurrency protocol.
5. The method according to any one of the preceding claims, comprising the steps of: The at least a portion of the code is inserted and / or copied into the script more than once and / or at more than one location within the script.
6. The method according to any one of the preceding claims, comprising the steps of: The at least one data item is used to determine a number of times the at least a portion of the code was inserted / copied into the script.
7. A method according to any one of the preceding claims, wherein: The control flow mechanism is a loop, such as a for loop, or the control flow mechanism is a selection control mechanism, such as a switch statement.
8. A method according to any one of the preceding claims, wherein: The at least one data item is derived from a compiler configured to convert code from a high level language (HLL) into a blockchain transaction script.
9. A method according to any one of the preceding claims, wherein: The portion of code includes a counter or index that is incremented at least once when the script is executed, the counter or index being used to control or influence the execution of the script.
10. The method according to claim 9, wherein: The counter or index is incremented or manipulated using values stored in and / or retrieved from two stack-based data structures.
11. A method according to any one of the preceding claims, wherein: The scripts are written in a language with limited functionality.
12. A computer-implemented method comprising the steps of: Inserting at least a portion of the code at least once into a script associated with a blockchain transaction so as to provide a function, when the script is executed, whose behavior is controlled or affected by at least one data item.
13. The method according to claim 12, wherein: The script is associated with an input or an output of the blockchain transaction.
14. The method according to claim 12 or 13, wherein: The transaction is generated in accordance with a blockchain protocol, or is generated for use with a blockchain protocol.
15. The method according to claim 14, wherein: The protocol is a cryptocurrency protocol or a variation of a cryptocurrency protocol.
16. The method according to any one of claims 12 to 15, comprising the steps of: The at least a portion of the code is inserted and / or copied into the script more than once and / or at more than one location within the script.
17. The method according to any one of claims 12 to 16, comprising the steps of: The at least one data item is used to determine a number of times the at least a portion of the code was inserted / copied into the script.
18. A method according to any one of claims 12 to 17, wherein: The functions are functions of the control flow mechanism, and The control flow mechanism is a loop, such as a for loop, or the control flow mechanism is a selection control mechanism, such as a switch statement.
19. A method according to any one of claims 12 to 18, wherein: The at least one data item is derived from a compiler configured to convert code from a high level language (HLL) into a blockchain transaction script.
20. The method according to any one of claims 12 to 19, wherein: The portion of code includes a counter or index that is incremented at least once when the script is executed, the counter or index being used to control or influence the execution of the script.
21. The method according to claim 20, wherein: The counter or index is incremented or manipulated using values stored in and / or retrieved from two stack-based data structures.
22. The method according to any one of claims 12 to 21, wherein: The scripts are written in a language with limited functionality.