Control flow in blockchain script
By emulating complex control flow in functionally constrained scripting languages, the method enhances blockchain transaction execution with secure and advanced functionality, addressing security and programmability limitations.
Patent Information
- Application Number
- JP2024122944
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2017-07-07
- Filing Date
- 2024-07-30
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2038-07-05
AI Technical Summary
Existing blockchain scripting languages, such as Bitcoin's Script, are functionally constrained and lack support for complex control flow mechanisms, which poses security risks while limiting programmability, and alternative platforms like Ethereum face security vulnerabilities despite being Turing-complete.
A method and system to emulate complex control flow mechanisms, like loops and switch-case statements, within functionally constrained scripting languages by inserting code portions dynamically into blockchain transaction scripts, using data items to control execution.
Enables sophisticated and secure execution of blockchain transactions with enhanced functionality without compromising security, allowing for automated processes and control over resource transfers.
Smart Images

Figure 2024153799000001_ABST
Abstract
Description
[Technical field]
[0001] The present invention relates generally to blockchain technology, and in particular to implementing complex functions via blockchain. Advantageously, the present invention provides a mechanism that allows blockchain transactions to include functionality that is normally provided by control flow structures. Thus, the present invention extends the capabilities and functionality of blockchain scripts, and thus the blockchain protocol itself, without the need to modify the underlying existing protocol. Transactions generated according to the present invention can be used as a control mechanism to enable, influence, and direct the activity of computer-implemented processes. The present invention is suitable for, but not limited to, implementing and controlling automated processes. [Background technology]
[0002] The term "blockchain" is used herein to encompass all forms of consensus-based electronic, computer-based distributed ledgers, including but not limited to blockchain and transaction chain technologies, permissioned and unpermissioned ledgers, shared ledgers, and variations thereof. The most widely known application of blockchain technology is the Bitcoin ledger, although other blockchain implementations have been proposed and developed. Although Bitcoin is referred to herein for convenience and illustrative purposes, it should be noted that the present invention is not limited to use with the Bitcoin blockchain, and alternative blockchain implementations and protocols are within the scope of the present invention.
[0003] A blockchain is a consensus-based electronic ledger implemented as a computer-based decentralized distributed system composed of blocks. Blocks are in turn composed of transactions. Each transaction is a data structure that encodes the transfer of control of digital assets between participants in the blockchain system and contains at least one input and at least one output. Each block contains a hash of the previous block, and blocks are chained together to create a permanent, immutable record of all transactions written to the blockchain since its inception. Transactions contain small programs, known as scripts, embedded in their inputs and outputs. Scripts specify how and by whom the output of a transaction can be accessed. On the Bitcoin platform, these scripts are written using a scripting language based on the stack.
[0004] In order for a transaction to be written to the blockchain, it must be "verified." Network nodes (miners) perform work to ensure that each transaction is valid, and invalid transactions are rejected from the network. A software client installed on the node performs this validation work on unspent transactions (UTXOs) 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 the transaction is written to the blockchain. Thus, for a transaction to be written to the blockchain, it must i) be verified by the first node that receives the transaction, and if the transaction is verified, the node relays the transaction to other nodes in the network, ii) be added to a new block constructed by miners, and iii) be mined, i.e., added to the public ledger of past transactions.
[0005] Although blockchain technology is most widely known for its use in implementing cryptocurrencies, digital entrepreneurs are beginning to explore the use of both the cryptocurrency security system on which Bitcoin is based, and the data that can be stored on the blockchain, to implement new systems. It would be highly advantageous if blockchain could be used for automating tasks and processes that are not limited to the cryptocurrency realm. Such solutions would be more diverse in their applications, while still being able to take advantage of the benefits of blockchain (e.g., permanent, tamper-resistant record of events, distributed processes, etc.). Summary of the Invention
[0006] According to the present invention there is provided a computer implemented system and / or method as defined in the accompanying claims.
[0007] The present invention may provide a computer-implemented method. The present invention may be described as a method configured to enable or accommodate the generation of blockchain transactions (Tx). Additionally or alternatively, the present invention may be described as a method for controlling execution of a transaction (Tx) script that controls or influences whether an output associated with a blockchain transaction can be unlocked (used). Thus, the present invention is a method for controlling or influencing a cryptographic process. The present invention may also be described as controlling the transfer or exchange of resources over a blockchain network. The present invention may also be described as providing security techniques that enable or enable Turing-complete functionality to be provided in or by a blockchain script without compromising resilience against security exploits. Thus, the present invention provides an improved blockchain, since transfers and exchanges can be performed across a blockchain network in a more functional and technically superior manner while retaining security and protection against security exploits of the protocol.
[0008] The method may include receiving or generating or deriving, with a software resource, at least one data item. The 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. The data item may thus be used to determine how many times code is copied or inserted into the script and may be determined and / or generated outside the script. It may be generated as a computational result by a computational resource. It may be generated by use of a random or pseudo-random number generator.
[0009] The invention may include inserting at least one code portion at least once into a script associated with or for a blockchain transaction, such that when the script is executed, the script provides the functionality of the control flow mechanism. The code portion may be pre-specified or pre-written. It may be stored in a computer-based resource and may be retrieved from storage prior to being inserted into the script.
[0010] The script may be associated with the transaction in that it forms part of the transaction and / or can be used to lock / unlock a portion of the cryptocurrency to be transferred using the transaction.
[0011] The method may include generating a blockchain transaction. The method may include submitting the transaction to a blockchain network. The method may include 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.
[0012] The operation / execution of the control flow mechanism may be controlled or influenced by at least one data item. Preferably, the script may not contain Turing complete constructs (e.g. loops, recursive jumps, high level control structures) following the insertion of at least one code portion. Preferably, following the insertion of at least one code portion at least once, the script is compatible for execution on a blockchain using a functionally constrained (Turing incomplete) language. This may be the Script language used by blockchains implementing the Bitcoin protocol or a variant thereof.
[0013] The script may be associated with an input or output of a blockchain transaction. The transaction may be generated according to a blockchain protocol, which may be the Bitcoin protocol. The script may be written in the Script programming language or a scripting language based on another stack. The script may be written in a functionally constrained (alternatively may be referred to as "Turing-incomplete") language. The language may be functionally constrained in the sense that the language does not natively support one or more control flow mechanisms such as loops and / or jump iterations.
[0014] The method may include inserting and / or copying the at least one code portion into the script more than once and / or in more than one location within the script.
[0015] The method may include using the at least one data item to determine how many times the at least one code portion is to be inserted / copied into the script.
[0016] The control flow mechanism may be a loop, such as a for or while loop, or a selection control mechanism, such as a switch / case statement.
[0017] The at least one data item may be derived from a compiler configured to convert code from a High Level Language (HLL) into a blockchain transaction script.
[0018] The code portion may include a counter or index that is incremented at least once by execution of the script, the counter or index being used to control or influence the execution of the script.
[0019] The counter or index may be incremented or otherwise manipulated using values stored in and / or read from a data structure based on the two stacks.
[0020] The present invention may also provide a computer-implemented system configured to perform the method of any embodiment described herein. Any aspect or feature described in relation to the method may also apply to the corresponding system. The system may include at least one computer-based resource. The system may include one or more blockchain nodes.
[0021] The present invention also provides a system comprising a processor and a memory containing executable instructions that, upon execution by the processor, cause the system to perform any embodiment of the computer-implemented method described herein.
[0022] The present invention also provides a non-transitory computer-readable storage medium having executable instructions stored thereon that, when executed by a processor of a computer system, cause the computer system to perform at least an embodiment of a computer-implemented method described herein.
[0023] These and other aspects of the invention will be apparent from and will be taught with reference to the embodiments described hereinafter, by way of example only, and with reference to the accompanying drawings, in which: [Brief description of the drawings]
[0024] [Figure 1] 1 provides a simplified diagram of a distributed blockchain network, as it is known in the art. [Diagram 2] 1 shows a flow chart illustrating one embodiment according to the present invention. [Diagram 3] 1 illustrates an exemplary network associated with a blockchain that may be used in accordance with the present invention. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0025] The Bitcoin network is an example of a blockchain implementation, as shown in Figure 1. Bitcoin utilizes a scripting language known as Script. Script is a Forth-like language that uses a set of primitive operators or commands known as op_codes for the creation of relatively simple programs. Script uses a data structure known as a stack for temporary storage of data items (variables and constants) during program execution. Items are pushed onto the stack, one on top of the other, and popped off in reverse order. Typically, items pushed onto the stack are later popped off in order to use them as operands of the next operation. When a Script program terminates, the value left on the top of the stack is the return value.
[0026] As is known in other stack-based languages such as Forth, it is sometimes useful to have access to an additional stack. In Script, this second stack is known as the alt stack, and the first stack is known as the main stack. The alt stack is typically used to temporarily store data during script execution.
[0027] However, in contrast to Forth, Script does not feature a built-in syntax for performing complex control flow statements such as loops. Control flow statements are programming mechanisms used to influence and direct (i.e., control) the way a program executes. Specific values are used to determine which path the logic will take when executing. These values may be hard-coded in the program or provided as dynamic inputs at runtime. The values may then be used in decision making (e.g., is a value less than or equal to value b?, is string x="Hello World!"?). Examples of control flow statements include while loops, for loops, and switch-case statements.
[0028] The prohibition of such mechanisms for scripting is an intentional security feature; it leaves the blockchain network potentially vulnerable to security weaknesses such as Denial-of-Service (DOS) attacks. However, the trade-off is that programmers are constrained as to how Script code can be written; for example, source code cannot contain loops. This has led some to describe Script as Turing-incomplete (though others dispute this definition). One known Bitcoin alternative, Ethereum, has attempted to overcome this constraint by incorporating a Turing-complete language as an inherent feature of its protocol. However, at the time of writing, Ethereum suffered from at least one serious security weakness.
[0029] There is therefore a need to provide a technical solution that resolves the trade-off between the security offered by a functionally constrained blockchain scripting language such as Script, and the desire to perform more complex functions by the blockchain platform. Ideally, this can be achieved in a way that expedites the encoding process, for example by automation with software resources.
[0030] The present invention provides a solution to at least this problem, thereby allowing the functionality of complex control flow mechanisms to be achieved or at least emulated using functionally constrained scripting languages on the blockchain. (Due to controversy in the field regarding the Turing completeness of Script, we may refer to such languages herein as "functionally constrained" rather than "Turing incomplete", although the terms may be used interchangeably.) The example we use here is merely for illustrative purposes and presents a solution that allows the emulation of both for loops and switch-case control sequences. Those skilled in the art will appreciate that other types of control flow mechanisms may be provided by the present invention.
[0031] A process that can be used according to the invention is shown in the flow chart of Figure 2. According to the invention, a decision is made as to how the logic should be controlled in the transaction (Tx) script. For example, this can be a pre-determination of the statements to be executed in the loop body for each iteration or the statements to be executed for each option (case) in a switch construct. These can be stored as code fragments for later retrieval during the generation of the script / transaction.
[0032] Once generated or received, the decision is then used to generate code for the script of the blockchain transaction, which may be an unlock script, a redeem script, or an unlock script language. In particular, the code portion is inserted into the script as many times as desired and in the appropriate locations within the script.
[0033] A code segment may be, for example, the code to execute an instance of a loop, or an option in a switch command sequence. Code segments are repeated within a script as necessary. As a result, 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 body of loop> Or if(i==2) Then<execute statement(s) and break out of switch> It is.
[0034] The generation of the script code can be performed manually, however, in a preferred embodiment of the invention, the code (and the entire transaction) is generated by an automated process, i.e. by a suitably configured software resource or agent running on a processor.
[0035] In such an embodiment, the software agent is configured 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 code portion needs to be provided in the script. The same or another data item can be used to control the execution of the script during evaluation, for example by use in a condition to control a loop or as a value against which a switch-case is tested.
[0036] Moreover, the code portions can be predetermined and stored in memory, and when the software agent needs to generate a script, the code portions can be accessed from memory and inserted into the script as many times as necessary, thus adapting it to test the associated control conditions using the above mentioned data items.
[0037] Thus, a software agent can receive the relevant data items and use them, when executed, to generate a transaction script that includes code to emulate complex control flow functions as needed. This script can be used in generating blockchain transactions that can then be submitted to the network for validation and propagation.
[0038] Thus, the present invention can be used to control how scripts associated with inputs / outputs of a blockchain transaction are executed. In effect, this controls whether the output associated with the transaction (Tx) can be used and whether cryptographic ownership of an asset (e.g., a portion of cryptocurrency, a token, etc.) on the blockchain can be transferred from one entity to another. In another sense, the present invention controls or influences cryptographic processes.
[0039] Below, examples are provided to analyze and explain the above-mentioned concepts and techniques.
[0040] <Example 1: Emulation of a for loop> In this example, we provide a Script-based operation sequence that emulates the behavior of a for loop as if it were natively supported by the language.
[0041] The loop has the following form:
number
[0042] Let K and N be the lower and upper bounds, respectively, of the interval I=[K:N]. The operation sequence has the following form:
number
[0043] Note that a frame representing an instance of a loop is provided multiple times, say P times, where P>N. Also, the code for the loop body is<EXECUTE STATEMENTS> should not modify the state of either the primary or alt stack.
[0044] <Loop example 1: Loop 0~2> In the following example, we assume that the code in the box is copied three times. In this example, we<EXECUTE STATEMENTS> Verify that is executed twice.
[0045] Consider the following code snippet:
number
[0046] Your stack should look something like this (the left column is the primary stack, and the right column is the alt stack).
number
[0047] <Example 2: Emulation of switch-case command sequence> In this example, we describe a Bitcoin Script emulation of a switch command sequence. We want to emulate the following kind of command sequence:
number
[0048] Let X be the value we want to check. Written using Bitcoin Script language syntax, the switch case code looks like this:
number
[0049] (Example 1) The input signal is OP_2. We have the code<EXECUTE STATEMENTS 2> Check that only one statement is executed, and assume that the code contains three statements:
number
[0050] <Blockchain network> Referring to FIG. 3, FIG. 3 illustrates in block diagram form an exemplary network associated with a blockchain. The network may be referred to herein as a blockchain network 100 and may be utilized for implementing the present invention. The blockchain network 100 is a peer-to-peer open membership network that anyone may join without invitation or approval from other members. The blockchain network 100 operates under a blockchain protocol, and distributed electronic devices running instances of the blockchain protocol 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, the Bitcoin protocol, or other cryptocurrency.
[0051] The electronic devices that execute the blockchain protocol and form the nodes 102 of the blockchain network 100 may be of various types, including, for example, computers such as desktop computers, laptop computers, tablet computers, servers, mobile devices such as smartphones, wearable computers such as smart watches, or other electronic devices.
[0052] The nodes 102 of the blockchain network 100 are coupled to one another 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 of the nodes 102 may be located in geographically dispersed locations.
[0053] Nodes 102 maintain a global ledger of all transactions on the blockchain. The transactions are grouped into blocks, with each block containing a hash of the previous block in the chain. The global ledger is a distributed ledger, and each node 102 may store a full or partial copy of the global ledger. Transactions by nodes 102 that affect the global ledger are verified by other nodes 102. As a result, the validity of the global ledger is maintained. The implementation and operation details of a blockchain network, such as using the Bitcoin protocol, are understood by those skilled in the art.
[0054] Each transaction typically has one or more inputs and one or more outputs. Script embedded in the inputs and outputs specifies how and by whom the transaction's outputs can be accessed. A transaction's output may be an address to which value is transferred as a result of the transaction. The value is then associated with that output address as an unspent transaction output (UTXO). Subsequent transactions may then reference that address as an input to use or disperse the value.
[0055] Nodes 102 can fulfill many different functions, from network routing to wallet services, and maintain a robust and secure distributed public ledger. "Full nodes" have a complete up-to-date copy of the blockchain and can therefore verify any transaction (spent or unspent) on the public ledger. "Lightweight nodes" (or SPVs) maintain a subset of the blockchain and can verify transactions using "simple payment verification" techniques. Lightweight nodes download only block headers, not the transactions within each block. These nodes therefore rely on peers to verify their transactions. "Mining nodes" are full or lightweight nodes, and are responsible for verifying transactions on the blockchain and generating new blocks. "Wallet nodes" are typically lightweight nodes, and handle wallet services for users. Nodes 102 communicate with each other using a connection-oriented protocol such as TCP / IP (Transmission Control Protocol).
[0056] It should be noted that the above-described embodiments do not limit the present invention, and that those skilled in the art can devise numerous alternative embodiments without departing from the scope of the present invention, which is defined by the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claims. The terms "comprising" and "comprises" and the like do not exclude the presence of elements or steps other than those listed in any claim and in the specification as a whole. In this specification, "comprises" means "includes" or "consists of", and "comprising" means "including" or "including of". The singular reference of an element does not exclude the presence of a plurality of such elements and vice versa. The invention can be implemented by means of hardware comprising several distinct elements, or by means of a suitably programmed computer. In a device claim enumerating several means, these several means may be implemented by one and the same hardware element. The fact that certain quantities are recited in mutually different dependent claims does not indicate that a combination of these quantities cannot be used to advantage. [Explanation of symbols]
[0057] 100 Blockchain Networks 102 nodes
Claims
1. 1. A computer-implemented method comprising: receiving, generating or deriving at least one data item; inserting at least one code portion at least once into a script associated with a blockchain transaction, such that when the script is executed, the script provides functionality for a control flow mechanism, the operation of the control flow mechanism being controlled or influenced by the at least one data item, the script being written in a functionally constrained, stack-based scripting language, and the code portion does not modify the state of the stack; The method includes:
2. The method of claim 1 , wherein the script is associated with an input or output of the blockchain transaction.
3. 3. The method of claim 1 or 2, wherein the transactions are generated in accordance with or for use with a blockchain protocol.
4. The method of claim 3 , wherein the protocol is the Bitcoin protocol or a variant of the Bitcoin protocol.
5. A method according to any preceding claim, comprising inserting and / or copying said at least one code portion into said script more than once and / or in more than one location within said script.
6. A method according to any preceding claim, comprising using said at least one data item to determine how many times said at least one code portion has been inserted / copied into said script.
7. The method of claim 1 , wherein the control flow mechanism is a loop, such as a for loop, or a selection control mechanism, such as a switch statement.
8. 8. The method of claim 1, 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. 9. A method according to claim 1, wherein the code portion comprises a counter or index which is incremented at least once by execution of the script, the counter or index being used to control or influence the execution of the script.
10. 10. The method of claim 9, wherein the counter or index is incremented or manipulated using values stored in and / or read from a data structure based on two stacks.
11. A computer-implemented system configured to perform the method of any of claims 1 to 10.
12. A computer-readable storage medium comprising computer-executable instructions which, when executed, configure a processor to perform the method of any one of claims 1 to 10.
13. 1. An electronic device comprising: An interface device; a processor coupled to the interface device; A memory coupled to the processor, the memory storing computer executable instructions that, when executed, configure the processor to perform the method of any one of claims 1 to 10; An electronic device comprising:
Citation Information
Patent Citations
Device, method and system for virtual asset transactions
US20160342977A1
System and method for decentralized autonomous healthcare economy platform
WO2017024071A1
