Control flow in blockchain scripts

The method emulates complex control flow in functionally constrained blockchain scripts, enabling advanced automation and secure transaction execution, addressing the limitations of existing scripting languages.

JP7771289B2Active Publication Date: 2025-11-17NCHAIN LICENSING AG
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
JP2024122944
Authority / Receiving Office
JP · JP
Patent Type
Patents
Current Assignee / Owner
Priority Date
2017-07-07
Filing Date
2024-07-30
Publication Date
2025-11-17
Estimated Expiration
2038-07-05

AI Technical Summary

Technical Problem

Existing blockchain scripting languages, such as Bitcoin's Script, are functionally constrained to prevent security vulnerabilities but lack the ability to support complex control flow mechanisms, limiting their functionality in automating tasks beyond cryptocurrencies.

Method used

A method and system that emulate complex control flow mechanisms, like loops and switch-case statements, within functionally constrained blockchain scripts by inserting pre-determined code portions dynamically, allowing for more sophisticated transaction execution while maintaining security.

Benefits of technology

Enables advanced automation and control of blockchain transactions without compromising security, enhancing the functionality of blockchain platforms to handle diverse applications beyond cryptocurrencies.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 0007771289000008
    Figure 0007771289000008
  • Figure 0007771289000009
    Figure 0007771289000009
  • Figure 0007771289000010
    Figure 0007771289000010
Patent Text Reader

Abstract

To provide a computer-implemented method and a corresponding system for generating a blockchain transaction (Tx).SOLUTION: This method includes: using a software resource to receive, generate, or derive at least one data item; and then inserting, at least once, at least one portion of code into a script associated with a transaction. Upon execution of the script, the portion of code provides functionality of a control flow mechanism, the behaviour of the control flow mechanism being controlled or influenced by the at least one data item. The control flow mechanism is a loop, such as a while or for loop, or a selection control mechanism such as a switch statement.SELECTED DRAWING: Figure 2
Need to check novelty before this filing date? Find Prior Art

Description

[Technical Field]

[0001] The present invention relates generally to blockchain technology, and more particularly to implementing complex functions via blockchains. Advantageously, the present invention provides a mechanism that allows blockchain transactions to include functionality typically provided by control flow structures. Thus, the present invention extends the capabilities and functionality of blockchain scripts, and thus the blockchain protocol itself, without requiring modifications to the underlying existing protocol. Transactions generated in accordance with 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. While 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 decentralized, distributed, computer-based system composed of blocks. Blocks, in turn, are 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 chain 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 transaction's outputs can be accessed. On the Bitcoin platform, these scripts are written using a stack-based scripting language.

[0004] In order for a transaction to be written to the blockchain, it must be "verified." Network nodes (miners) perform work to ensure each transaction is valid; invalid transactions are rejected by the network. A software client installed on a node performs this validation work on unspent transactions (UTXOs) by running its locking and unlocking scripts. If the execution of the locking and unlocking scripts evaluates to true, 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; 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] While 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 upon 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, decentralized 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 creation of blockchain transactions (Tx). Additionally or alternatively, the present invention may be described as a method for controlling the execution of a transaction (Tx) script that controls or affects whether outputs associated with a blockchain transaction can be unlocked (spent). Thus, the present invention is a method for controlling or affecting a cryptographic process. The present invention may also be described as controlling the transfer or exchange of resources across a blockchain network. The present invention may also be described as providing security techniques that enable or enable Turing-complete functionality within or by a blockchain script without compromising resilience to security vulnerabilities. Thus, the present invention provides an improved blockchain because it is capable of performing transfers and exchanges across a blockchain network in a more sophisticated and technically superior manner while maintaining security and protection against protocol security vulnerabilities.

[0008] The method may include receiving, generating, or deriving, using 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. Thus, the data item may 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 result of a computation by a computational resource. It may be generated through the use of a random or pseudo-random number generator.

[0009] The present invention may include inserting, at least once, at least one code portion 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, 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] A 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 insertion of at least one code fragment. Preferably, following at least one insertion of at least one code fragment, 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 manipulated using values ​​stored in and / or read from two stack-based data structures.

[0020] The present invention may also provide a computer-implemented system configured to perform any embodiment of the method described herein. Any aspect or feature described in connection with 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 stored thereon executable instructions that, when executed by a processor of a computer system, cause the computer system to perform at least one 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 herein, which are described hereinafter, by way of example only, with reference to the accompanying drawings, in which: [Brief explanation of the drawings]

[0024] [Figure 1] Provides a simplified diagram of a distributed blockchain network, as known in the art. [Figure 2] 1 shows a flow chart illustrating one embodiment in accordance with the present invention. [Figure 3] 1 illustrates an exemplary network associated with a blockchain that may be used in accordance with the present invention. DETAILED DESCRIPTION OF THE INVENTION

[0025] The Bitcoin network, as shown in Figure 1, is an example of a blockchain implementation. 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, placed one on top of the other, and popped off in reverse order. Typically, items pushed onto the stack are later popped off to use them as operands for 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 from 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 ​​can be hard-coded in the program or provided as dynamic input at runtime. The values ​​can then be used in decision-making processes (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 complex control mechanisms potentially vulnerable to security exploits such as denial-of-service (DOS) attacks. However, the tradeoff is that programmers are constrained regarding 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, attempted to overcome this constraint by incorporating a Turing-complete language as an inherent feature of its protocol. However, at the time of its writing, Ethereum suffered from at least one serious security exploit.

[0029] Therefore, there is a need to provide a technical solution that resolves the trade-off between the security offered by functionally constrained blockchain scripting languages ​​such as Script and the desire to perform more complex functions with blockchain platforms. 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 enabling the functionality of complex control flow mechanisms to be achieved, or at least emulated, using functionally constrained scripting languages ​​on the blockchain. (Due to debates in the field regarding the Turing completeness of scripts, we sometimes refer to such languages ​​herein as "functionally constrained" rather than "Turing incomplete," although the terms are sometimes used interchangeably.) The example we use here is purely 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 understand that other types of control flow mechanisms can be provided by the present invention.

[0031] A process usable in accordance with the present invention is shown in the flowchart of Figure 2. According to the present invention, a decision is made as to how the logic should be controlled within a transaction (Tx) script. For example, this can be a pre-determination of the statements to be executed within a 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 script / transaction generation.

[0032] Once generated or received, the decision is then used to generate code for the blockchain transaction script, 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 that executes an instance of a loop, or an option in a switch command sequence. Code segments are repeated within a script as needed. 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> is.

[0034] The generation of the script code can be performed manually, however, in a preferred embodiment of the present 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. A 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 a 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 that controls a loop or by use as a value that a switch-case is tested against.

[0036] Furthermore, 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 data items mentioned above.

[0037] Thus, a software agent can receive the relevant data items and use them, when executed, to generate a transaction script containing code to emulate complex control flow functions as needed. This script can be used in generating blockchain transactions, which 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 blockchain transactions are executed. In effect, this controls whether outputs associated with a transaction (Tx) can be used, and whether cryptographic ownership of assets (e.g., portions of cryptocurrency, tokens, etc.) on the blockchain can be transferred from one entity to another. In other words, the present invention controls or influences cryptographic processes.

[0039] Below, examples are provided to analyze and explain the above-described concepts and techniques.

[0040] <Example 1: Emulating 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 is of the 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 the loop instance is provided multiple times, P times, where P>N.<EXECUTE STATEMENTS> should not change 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.<EXECUTE STATEMENTS> Verify that is executed twice.

[0045] Consider the following code fragment:

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 assume that the code is<EXECUTE STATEMENTS 2> We check that only the following statements are executed, and assume the code contains three statements:

number

[0050] <Blockchain network> Referring to Figure 3, Figure 3 illustrates in block diagram form an exemplary network associated with a blockchain. The network may be referred to herein as blockchain network 100 and may be utilized to implement the present invention. Blockchain network 100 is a peer-to-peer, open membership network that anyone may join without invitation or approval from other members. Blockchain network 100 operates under a blockchain protocol, and distributed electronic devices running instances of the blockchain protocol may participate in 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. Often, the blockchain network 100 is implemented at least in part over 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, and each block contains 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, thereby maintaining the validity of the global ledger. The implementation and operation details of blockchain networks, 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 (spend or not) 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 that are responsible for verifying transactions on the blockchain and generating new blocks. "Wallet nodes" are typically lightweight nodes that 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 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 claim. The word "comprising" or "comprises", and the like, does not exclude the presence of elements or steps other than those listed in any claim or 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 can be embodied 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; Using the at least one data item, determining the number of times at least one code portion is inserted / copied into a script associated with a blockchain transaction; inserting the at least one code portion into the script at least once based on the number of times, the script providing functionality of a control flow mechanism when executed, 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 not modifying the state of the stack; A method comprising:

2. The method of claim 1 , wherein the script is associated with an input or an output of the blockchain transaction.

3. 3. The method of claim 1 or 2, wherein the transaction is 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. 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. 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.

7. 7. 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.

8. 8. A method according to claim 1, wherein the code portion includes 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.

9. 9. The method of claim 8, wherein the counter or index is incremented or manipulated using values ​​stored in and / or read from a two stack-based data structure.

10. A computer-implemented system configured to perform the method of any of claims 1 to 9.

11. A computer-readable storage medium comprising computer-executable instructions that, when executed, configure a processor to perform the method of any one of claims 1 to 9.

12. 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 9; 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