Elliptic curve arithmetic in scripts

By executing modular inversion operation scripts in blockchain transactions, the problem of lack of elliptic curve arithmetic capabilities in the blockchain is solved, the execution of elliptic curve arithmetic on the blockchain is realized, and the computing power and security of the blockchain are improved. .

CN118633259AInactive Publication Date: 2024-09-10NCHAIN LICENSING AG
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202380018848.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2022-01-26
Filing Date
2023-01-20
Publication Date
2024-09-10
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The lack of the ability to perform elliptic curve arithmetic in blockchain limits the computational power and security of blockchain transactions.

Method used

By generating a blockchain transaction containing a modular inverse operation script, the script engine is used to perform elliptic curve arithmetic, including obtaining the target integer and modular value, generating the modular inverse value, calculating the modular inverse value using the square value sequence and the reduced modular value, and converting it Output to the blockchain transaction.

Benefits of technology

It realizes the execution of immutable elliptic curve arithmetic on the blockchain, improves the computing power and security of the blockchain, reduces the cost of high-cost computing tasks to be borne by script generators, and improves the functionality and performance of the blockchain.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118633259A
    Figure CN118633259A
Patent Text Reader

Abstract

A computer-implemented method for enabling elliptic curve arithmetic to be performed using blockchain transactions. A first script of the first block chain transaction is generated, the first script comprises a modular inverse operation script, and the modular inverse operation script is configured to obtain a target integer and a modular value and output modular inverse of the target integer. The modular inversion is generated by the following steps: generating a square value sequence; for each set bit of the reduced modulus value in binary representation, including a corresponding squared value in the sequence of squared values in the result; multiplying the squared values of the results to generate a result value; and calculating a modulo of the result value relative to the modulo value, wherein the modulo of the result value is output as the modulo inverse; and outputting the first script, so that the first script is included in the first block chain transaction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to a computer-implemented method for enabling execution of elliptic curve arithmetic in scripts using blockchain transactions. Background Art

[0002] Blockchain refers to a distributed data structure in which a copy of the blockchain is maintained at each of a plurality of nodes in a distributed peer-to-peer (P2P) network (hereinafter referred to as a "blockchain network") and is widely disclosed. The blockchain includes a series of data blocks, each of which includes one or more transactions. Except for the so-called "coinbase transaction", each transaction points to a previous transaction in a sequence, which can span one or more blocks back to one or more coinbase transactions. The coinbase transaction will be discussed further below. Transactions submitted to the blockchain network are included in new blocks. The process of creating a new block is generally referred to as "mining", which involves each of a plurality of nodes competing to perform "proof of work", i.e., solving a cryptographic puzzle based on a representation of a defined set of ordered and verified valid pending transactions waiting to be included in a new block of the blockchain. It should be noted that the blockchain can be pruned at some nodes, and the publication of blocks can be achieved by publishing only the block header.

[0003] Transactions in a blockchain can be used for one or more of the following purposes: transferring digital assets (i.e., a certain number of digital tokens); sorting a set of entries in a virtualized ledger or registry; receiving and processing time-stamped entries; and / or sorting index pointers by time. Blockchains can also be used to implement hierarchical additional functions on blockchains. For example, a blockchain protocol may allow additional user data or data indexes to be stored in a transaction. There is no pre-specified limit on the maximum data capacity that can be stored in a single transaction, so increasingly complex data can be incorporated. For example, this can be used to store electronic documents, audio, or video data in a blockchain.

[0004] The nodes of the blockchain network (commonly referred to as "miners") perform a distributed transaction registration and verification process, which will be described in more detail later. In summary, in this process, nodes verify transactions and insert them into block templates, which attempt to identify a valid proof-of-work solution for the block template. Once a valid solution is found, the new block is propagated to other nodes of the network, so that each node can record the new block on the blockchain. In order to record a transaction in the blockchain, a user (e.g., a blockchain client application) sends the transaction to one of the nodes in the network for propagation. The nodes receiving the transaction can compete to find a proof-of-work solution that incorporates the verified valid transaction into the new block. Each node is configured to execute the same node protocol, which will include one or more conditions for confirming that the transaction is valid. Invalid transactions will not be propagated or incorporated into the block. Assuming that the transaction has been verified to be valid and thus accepted on the blockchain, the transaction (including any user data) will therefore be registered and indexed as an immutable public record on each node in the blockchain network.

[0005] The node that successfully solves the proof-of-work puzzle to create the latest block is usually rewarded with a new transaction called a "coinbase transaction" that distributes the amount of digital assets, i.e. the number of tokens. The detection and rejection of invalid transactions is performed by the actions of competing nodes, which act as agents of the network and are incentivized to report and prevent improper behavior. The widespread publication of information allows users to continuously audit the performance of nodes. Publishing only block headers allows participants to ensure the continued integrity of the blockchain.

[0006] In the "output-based" model (sometimes referred to as the UTXO-based model), the data structure of a given transaction includes one or more inputs and one or more outputs. Any spendable output includes an element that specifies the amount of a digital asset, which can be derived from the ongoing transaction sequence. Spendable outputs are sometimes called UTXOs ("unspent transaction outputs"). Outputs may also include a locking script that specifies future redemption conditions for the output. A locking script is a predicate that defines the conditions necessary to verify and transfer a digital token or asset. Each input of a transaction (except for a coinbase transaction) includes a pointer (i.e., a reference) to such an output in a previous transaction, and may also include an unlocking script for unlocking the locking script pointing to the output. Thus, consider a pair of transactions, referred to as a first transaction and a second transaction (or "target" transaction). The first transaction includes at least one output that specifies the amount of a digital asset, and includes a locking script that defines one or more conditions for unlocking the output. The second target transaction includes at least one input and an unlocking script, the at least one input including a pointer to the output of the first transaction; the unlocking script is used to unlock the output of the first transaction.

[0007] In such a model, when the second target transaction is sent to the blockchain network for propagation and recording in the blockchain, one of the validity conditions applied at each node will be that the unlocking script satisfies all of the one or more conditions defined in the locking script of the first transaction. Another condition will be that the output of the first transaction has not been redeemed by another earlier valid transaction. Any node that finds the target transaction invalid according to any of these conditions will not propagate the transaction (as a valid transaction, but may register an invalid transaction) nor include the transaction in a new block to be recorded in the blockchain.

[0008] Another transaction model is the account-based model. In this case, each transaction is defined not by reference to the UTXO of the previous transaction in the past transaction sequence, but by reference to the absolute account balance. The current state of all accounts is stored individually by the node in the blockchain and is constantly updated. Summary of the invention

[0009] Blockchain transactions include scripts: unlocking scripts and locking scripts. These scripts allow data (e.g., public keys) and functions (e.g., opcodes) to be recorded on the chain, and when the script is executed (e.g., during transaction verification), the function operates on the data. For example, a function can be used to hash a public key to generate a public key hash.

[0010] Elliptic curves are used in many applications, such as elliptic curve cryptography (ECC), elliptic curve digital signature algorithm (ECDSA), elliptic curve Diffie-Hellman key exchange, etc. Some of these applications (e.g., ECDSA) are fundamentally related to some blockchain protocols. For example, most blockchain protocols use ECDSA signatures to sign transactions, which in turn rely on private-public key pairs generated using elliptic curve points.

[0011] Elliptic curve arithmetic refers to performing mathematical operations on elliptic curve points, such as adding two elliptic curve points, or multiplying an elliptic curve point by a scalar. A fundamental requirement of elliptic curve arithmetic is the ability to compute the modular inverse of an elliptic curve point, or more generally the modular inverse of an integer, such as the x-coordinate of an elliptic curve point. This document recognizes that it would be advantageous to be able to perform elliptic curve arithmetic in script. Therefore, there is a need to be able to compute the modular inverse of an integer in script.

[0012] According to one aspect disclosed herein, a computer-implemented method is provided for enabling elliptic curve arithmetic to be performed using blockchain transactions, wherein the method is performed by a script generator and includes: generating a first script for a first blockchain transaction, wherein the first script includes a modular inversion script, and wherein the modular inversion script is configured to perform the following steps when executed by a script engine: obtaining a target integer (x) and a modulus value (p), wherein the target integer and the modulus value are relatively prime, and the modulus value is a prime number; and, outputting a modular inversion (y) of the target integer, wherein the modular inversion is generated by: generating a sequence of square values, wherein a first square value is equal to the target integer (x), and wherein each subsequent square value in the sequence of square values ​​is generated by multiplying the immediately preceding square value by itself; for a reduced modulus value (p), For each set bit of a reduced modulus value (p-2), wherein the reduced modulus value is an integer less than the modulus value by 2 and represented in binary, including the corresponding square value in the sequence of square values ​​in a result; multiplying the square values ​​of the results to generate a result value; and calculating the modulus of the result value relative to the modulus value (p), wherein the modulus of the result value is output as the modular inverse (y); and outputting the first script to be included in the first blockchain transaction.

[0013] The script generator generates a first script (e.g., a lock script) for the second transaction. The script includes at least a modular inverse operation script, which is configured to use the modular value (n) to take the modular inverse of the target integer (x), that is, x -1 When the modulus is a prime number (n=p), the modular inverse of the target integer can be written as x p-2 Given a reduced modulus value (p-2), which has i bits when represented in binary, the modular inverse is calculated by computing all square values and multiplying only those square values ​​corresponding to the set bits of the reduced modulus value. The target integer and the modulus value may be included as part of the first script (e.g., the locking script) or provided as input to a different script (e.g., the unlocking script of the second transaction). The first transaction is recorded on the blockchain. When the first script is executed (e.g., during transaction verification), the modular inverse of the target integer is calculated and output (e.g., output to a memory such as a stack). The present disclosure improves the functionality of the blockchain by enabling the modular inverse of integers to be implemented in a script.

[0014] The modular inverse of an integer can be used as part of one or more additional arithmetic operations. For example, the modular inverse operation script can be included as part of (or output to) a point addition script configured to add two elliptic curve points. For another example, the modular inverse operation script can be used as part of a scalar multiplication script configured to multiply an elliptic curve point by a scalar.

[0015] One advantage of performing elliptic curve arithmetic in script is that the computations are immutably stored on-chain, meaning that the computations and results cannot be altered and can be verified in the future. Another advantage is that computations that are expensive in terms of processing power are performed by the script engine that executes the script rather than by the script generator. The script engine is typically implemented by an entity (e.g., a blockchain node) that has more computing resources than the script engine (e.g., a user).

[0016] The first script is written in a scripting language. For example, a specific blockchain protocol uses a specific language called "Script" (capital S), which is a stack-based scripting language that consists of predefined functions called opcodes. In this language, a given opcode is mapped to one or more of the following operations: (a) placing an element on a stack; (b) extracting an element from the stack; (c) operating on an element on the stack; and (d) removing an element from the stack. Some stack-based languages ​​may allow data to be stored on two stacks (e.g., a main stack and an alternate (alt) stack). Embodiments of the present disclosure enable the use of the existing Script language of the blockchain to perform elliptic curve arithmetic, and thus maintain the security of the blockchain by avoiding the introduction of new opcodes that may increase the attack surface of attackers. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] To facilitate an understanding of the embodiments of the present disclosure and to show how such embodiments may be implemented, reference will now be made, by way of example only, to the accompanying drawings, in which:

[0018] Figure 1 is a schematic block diagram of a system for implementing a blockchain;

[0019] Figure 2 Some examples of transactions that may be recorded in a blockchain are schematically shown;

[0020] Figure 3 A schematic block diagram of some node software for processing transactions is shown;

[0021] Figure 4 is a schematic block diagram of an exemplary system for generating and executing scripts. DETAILED DESCRIPTION

[0022] 1. Exemplary System Overview

[0023] Figure 1 An exemplary system 100 for implementing a blockchain 150 is shown. The system 100 may include a packet-switched network 101, typically a wide area internet such as the Internet. The packet-switched network 101 includes a plurality of blockchain nodes 104, which may be arranged to form a peer-to-peer (P2P) network 106 within the packet-switched network 101. Although not shown, the blockchain nodes 104 may be arranged as a nearly complete graph. Thus, each blockchain node 104 is highly connected to other blockchain nodes 104.

[0024] Each blockchain node 104 includes a computer device of a peer, and different nodes 104 belong to different peers. Each blockchain node 104 includes a processing device, which includes one or more processors, such as one or more central processing units (CPUs), accelerator processors, special processors and / or field programmable gate arrays (FPGAs), and other devices, such as application-specific integrated circuits (ASICs). Each node also includes a memory, that is, a computer-readable memory in the form of a non-transitory computer-readable medium. The memory may include one or more memory units, which use one or more memory media, such as magnetic media such as hard disks, electronic media such as solid-state drives (SSDs), flash memory, or electrically erasable programmable read-only memories (EEPROMs), and / or optical media such as optical disk drives.

[0025] The blockchain 150 includes a series of data blocks 151, wherein a respective copy of the blockchain 150 is maintained at each of the plurality of blockchain nodes 104 in the distributed or blockchain network 106. As described above, maintaining a copy of the blockchain 150 does not necessarily mean storing the blockchain 150 in its entirety. Instead, the blockchain 150 can be pruned as long as each blockchain node 150 stores a block header (discussed below) for each block 151. Each block 151 in the blockchain includes one or more transactions 152, wherein a transaction in this context refers to a data structure. The nature of the data structure will depend on the type of transaction protocol used as part of the transaction model or plan. A given blockchain uses a particular transaction protocol throughout. In a common transaction protocol, the data structure of each transaction 152 includes at least one input and at least one output. Each output specifies an amount of a digital asset represented as a property, an example of which is an output that is cryptographically locked to a user 103 (requiring the user's signature or other solution to unlock, thereby redeeming or spending). Each input points to the output of a previous transaction 152, thereby linking these transactions.

[0026] Each block 151 also includes a block pointer 155, which points to a previously created block 151 in the blockchain to define the order of blocks 151. Each transaction 152 (except for the coinbase transaction) includes a pointer to a previous transaction to define the order of the transaction sequence (Note: the sequence of transactions 152 can branch). The blockchain of blocks 151 is traced back to the genesis block (Gb) 153, which is the first block in the blockchain. One or more original transactions 152 earlier in the blockchain 150 point to the genesis block 153, not to the previous transaction.

[0027] Each blockchain node 104 is configured to forward transactions 152 to other blockchain nodes 104, so that transactions 152 are propagated throughout the network 106. Each blockchain node 104 is configured to create blocks 151 and store corresponding copies of the same blockchain 150 in its corresponding memory. Each blockchain node 104 also maintains an ordered set (or "pool") 154 of transactions 152 waiting to be incorporated into block 151. Ordered pools 154 are often referred to as "memory pools". In this article, the term is not intended to be limited to any particular blockchain, protocol, or model. The term refers to a set of ordered transactions that a node 104 has accepted as valid, and for which the node 104 is forced to not accept any other transaction that attempts to spend the same output.

[0028] In a given current transaction 152j, an input (or each input) includes a pointer that references an output of a previous transaction 152i in the transaction sequence, specifying that the output is to be redeemed or "spent" in the current transaction 152j. Spending or redeeming does not necessarily mean transferring a financial asset, although this is certainly a common application. More generally, spending can be described as consuming an output, or allocating it to one or more outputs in another subsequent transaction. In general, a previous transaction can be any transaction in an ordered set 154 or any block 151. Although a previous transaction 152i will need to exist and be verified to be valid in order to ensure that the current transaction is valid, it is not necessary for a previous transaction 152i to exist when the current transaction 152j is created or even sent to the network 106. Therefore, in this article, "previous" refers to the predecessor in a logical sequence linked by a pointer, and not necessarily the creation time or sending time in a time sequence, and therefore, does not necessarily exclude the situation where transactions 152i, 152j are created or sent out of order (see the discussion of isolated transactions below). A previous transaction 152i can also be called a predecessor transaction or a predecessor transaction.

[0029] The inputs of the current transaction 152j also include input authorizations, such as the signature of the user 103a to whom the outputs of the previous transaction 152i are locked. In turn, the outputs of the current transaction 152j may be cryptographically locked to the new user or entity 103b. Thus, the current transaction 152j may transfer the amounts defined in the inputs of the previous transaction 152i to the new user or entity 103b defined in the outputs of the current transaction 152j. In some cases, a transaction 152 may have multiple outputs to split the input amounts among multiple users or entities (one of which may be the original user or entity 103a for changes). In some cases, a transaction may also have multiple inputs to aggregate the amounts from multiple outputs of one or more previous transactions and reallocate them to one or more outputs of the current transaction.

[0030] According to an output-based transaction protocol, such as Bitcoin, when a party 103, such as an individual user or an organization, wishes to issue a new transaction 152j (either by an automated program employed by the party or manually), the issuing party sends the new transaction from its computer terminal 102 to a recipient. The issuing party or recipient will ultimately send the transaction to one or more blockchain nodes 104 of the network 106 (now typically a server or data center, but in principle it can also be other user terminals). It is also not excluded that the party 103 issuing the new transaction 152j can send the transaction directly to one or more blockchain nodes 104, and in some examples, the transaction may not be sent to the recipient. The blockchain node 104 receiving the transaction checks whether the transaction is valid according to the blockchain node protocol applied at each blockchain node 104. The blockchain node protocol typically requires the blockchain node 104 to check whether the cryptographic signature in the new transaction 152j matches the expected signature, which depends on the previous transaction 152i in the ordered sequence of transactions 152. In such an output-based transaction protocol, this may include checking whether the cryptographic signature or other authorization of the party 103 included in the input of the new transaction 152j matches the condition defined in the output of the previous transaction 152i that the new transaction spends (or "allocates"), where the condition typically includes at least checking whether the cryptographic signature or other authorization in the input of the new transaction 152j unlocks the output of the previous transaction 152i to which the input of the new transaction is linked. The condition may be defined at least in part by a script included in the output of the previous transaction 152i. Alternatively, this may be determined solely by the blockchain node protocol, or may be determined by a combination thereof. In either case, if the new transaction 152j is valid, the blockchain node 104 forwards it to one or more other blockchain nodes 104 in the blockchain network 106. These other blockchain nodes 104 apply the same test according to the same blockchain node protocol, and therefore forward the new transaction 152j to one or more other nodes 104, and so on. In this way, the new transaction is propagated throughout the network of blockchain nodes 104.

[0031] In the output-based model, the definition of whether a given output (e.g., UTXO) is allocated (or "spent") is whether it is validly redeemed by the input of another subsequent transaction 152j according to the blockchain node protocol. Another condition for a transaction to be valid is that the output of the previous transaction 152i that it attempts to redeem has not been redeemed by another transaction. Similarly, if invalid, transaction 152j will not be propagated (unless marked as invalid and propagated for reminder) or recorded in the blockchain 150. This prevents double spending, that is, the transaction processor allocates the output of the same transaction more than once. On the other hand, the account-based model prevents double spending by maintaining account balances. Because there is also a defined transaction order, the account balance has a single defined state at all times.

[0032] In addition to verifying that transactions are valid, blockchain nodes 104 compete to be the first node to create a block of transactions in a process generally referred to as mining, which is supported by "proof of work". At a blockchain node 104, a new transaction is added to an ordered pool 154 of valid transactions that have not yet appeared in a block 151 recorded on the blockchain 150. The blockchain nodes then compete to assemble a new valid transaction block 151 of transactions 152 in the ordered transaction set 154 by attempting to solve a cryptographic puzzle. Typically, this involves searching for a "nonce" value such that when the nonce is juxtaposed with a representation of the ordered pool 154 of pending transactions and hashed, the output of the hash value satisfies a predetermined condition. For example, the predetermined condition may be that the output of the hash value has a certain predefined number of leading zeros. Note that this is only one specific type of proof of work puzzle, and other types are not excluded. A property of a hash function is that it has an unpredictable output relative to its input. Therefore, this search can only be performed by brute force, consuming a large amount of processing resources at each blockchain node 104 that attempts to solve the puzzle.

[0033] The first blockchain node 104 that solves the puzzle announces the puzzle solution on the network 106, providing the solution as proof, which can then be easily checked by other blockchain nodes 104 in the network (once a solution to the hash value is given, it is directly possible to check whether the solution satisfies the output of the hash value). The first blockchain node 104 propagates a block to other nodes that accept the block to reach a threshold consensus, thereby enforcing the protocol rules. The ordered set of transactions 154 is then recorded by each blockchain node 104 as a new block 151 in the blockchain 150. A block pointer 155 is also assigned to the new block 151n pointing to the previously created block 151n-1 in the blockchain. The large amount of work required to create a proof-of-work solution (e.g., in the form of a hash) signals the intention of the first node 104 to follow the blockchain protocol. These rules include not accepting a transaction as valid if it spends or allocates the same output as a previously verified valid transaction, otherwise it is called a double spend. Once created, the block 151 cannot be modified because it is identified and maintained at each blockchain node 104 in the blockchain network 106. The block pointers 155 also impose order on the blocks 151. Because transactions 152 are recorded in ordered blocks at each blockchain node 104 in the network 106, an immutable public ledger of transactions is provided.

[0034] It should be noted that the different blockchain nodes 104 competing to solve a puzzle at any given time may do so based on different snapshots of the pool 154 of transactions that have not yet been published at any given time, depending on when they began searching for a solution or the order in which they received the transactions. The person solving the corresponding puzzle first defines the transactions 152 included in the new block 151n and their order, and updates the current pool of unpublished transactions 154. The blockchain nodes 104 then continue to compete to create blocks from the newly defined ordered pool of unpublished transactions 154, and so on. In addition, there is a protocol to resolve any "forks" that may occur, where two blockchain nodes 104 solve puzzles within a short time of each other, thereby propagating conflicting views of the blockchain between the nodes 104. In short, the fork direction that is the longest becomes the final blockchain 150. It should be noted that this does not affect users or agents of the network, as the same transaction will appear in both forks.

[0035] According to the Bitcoin blockchain (and most other blockchains), a node that successfully constructs a new block 104 is granted the ability to newly allocate an additional, accepted amount of digital assets in a new special type of transaction that allocates an additional limited amount of digital assets (as opposed to an inter-agent or inter-user transaction, which transfers a certain amount of digital assets from one agent or user to another). This special type of transaction is often called a "coinbase transaction", but may also be called a "starting transaction" or "generating transaction". It usually forms the first transaction of a new block 151n. The proof of work signals the intention of the node that constructs the new block to follow the protocol rules, thereby allowing the particular transaction to be redeemed later. The blockchain protocol rules may require a maturation period, such as 100 blocks, before the special transaction can be redeemed. Typically, a regular (non-generating) transaction 152 will also specify an additional transaction fee in one of its outputs to further reward the blockchain node 104 that created the block 151n in which the transaction was published. This fee is often called a "transaction fee" and is discussed below.

[0036] Due to the resources involved in transaction verification and publication, typically at least each blockchain node 104 takes the form of a server comprising one or more physical server units, or even an entire data center. However, in principle, any given blockchain node 104 may take the form of a user terminal or a group of user terminals networked together.

[0037] The memory of each blockchain node 104 stores software configured to run on the processing device of the blockchain node 104 to perform its corresponding role according to the blockchain node protocol and process transactions 152. It should be understood that any action attributed to the blockchain node 104 herein can be performed by software running on the processing device of the corresponding computer device. The node software can be implemented in one or more applications at the application layer or a lower layer such as an operating system layer or a protocol layer, or any combination of these layers.

[0038] Computer devices 102 of each of the parties 103 acting as consuming users are also connected to the network 101. These users can interact with the blockchain network 106 but do not participate in verifying transactions or constructing blocks. Some of these users or agents 103 can act as senders and receivers in transactions. Other users can interact with the blockchain 150 without acting as senders or receivers. For example, some parties can act as storage entities that store a copy of the blockchain 150 (e.g., having obtained a copy of the blockchain from the blockchain node 104).

[0039] Some or all of the parties 103 may be connected as part of a different network, such as a network overlaid on the blockchain network 106. Users of the blockchain network (often referred to as "clients") may be referred to as being part of a system that includes the blockchain network 106; however, these users are not blockchain nodes 104 because they do not perform the roles required of blockchain nodes. Instead, each party 103 may interact with the blockchain network 106, thereby utilizing the blockchain 150 by connecting to (i.e., communicating with) the blockchain node 106. For illustrative purposes, two parties 103 and their corresponding devices 102 are shown: a first party 103a and its corresponding computer device 102a, and a second party 103b and its corresponding computer device 102b. It should be understood that more such parties 103 and their corresponding computer devices 102 may exist and participate in the system 100, but for convenience, they are not illustrated. Each party 103 may be an individual or an organization. For illustrative purposes only, in this document, the first party 103a is referred to as Alice and the second party 103b is referred to as Bob, but it should be understood that this is not limited to Alice or Bob, and any reference to Alice or Bob in this document can be replaced with "first party" and "second party" respectively.

[0040] The computer device 102 of each party 103 includes a corresponding processing device, which includes one or more processors, such as one or more CPUs, graphics processing units (GPUs), other accelerator processors, specific application processors and / or FPGAs. The computer device 102 of each party 103 also includes a memory, that is, a computer-readable memory in the form of a non-temporary computer-readable medium. The memory may include one or more memory units, which use one or more memory media, such as magnetic media such as hard disks, electronic media such as SSDs, flash memory or EEPROMs, and / or optical media such as optical disk drives. The memory on the computer device 102 of each party 103 stores software, which includes a corresponding instance of at least one client application 105 that is set to run on the processing device. It should be understood that any action attributed to a given party 103 in this article can be executed by software running on the processing device of the corresponding computer device 102. The computer device 102 of each party 103 includes at least one user terminal, such as a desktop or laptop computer, a tablet computer, a smart phone, or a wearable device such as a smart watch. The computer device 102 of a given party 103 may also include one or more other network resources, such as cloud computing resources accessed through a user terminal.

[0041] The client application 105 may initially be provided to the computer device 102 of any given party 103 via a suitable computer-readable storage medium downloaded from a server, for example, or via a removable storage device such as a removable SSD, flash memory key, removable EEPROM, removable disk drive, floppy disk or tape, an optical disk such as a CD or DVD ROM, or a removable optical drive, etc.

[0042] The client application 105 includes at least a "wallet" function. This has two main functions. One of the functions is to enable the corresponding party 103 to create, authorize (e.g., sign) and send transactions 152 to one or more Bitcoin nodes 104, which are then propagated in the network of blockchain nodes 104 and included in the blockchain 150. Another function is to report to the corresponding party the amount of digital assets it currently owns. In an output-based system, this second function includes collating the amounts defined in the outputs of various transactions 152 belonging to the relevant parties scattered in the blockchain 150.

[0043] Note: While various client functions may be described as being integrated into a given client application 105, this is not necessarily limiting, and rather, any client function described herein may be implemented in a suite consisting of two or more different applications, such as interfacing via an API or one application as a plug-in to another application. More generally, the client functions may be implemented at the application layer or at a lower layer such as an operating system, or any combination of these layers. The following description will be based on the client application 105, but it should be understood that this is not limiting.

[0044] An instance of a client application or software 105 on each computer device 102 is operably coupled to at least one of the blockchain nodes 104 of the network 106. This can enable a wallet function of the client 105 to send transactions 152 to the network 106. The client 105 can also contact the blockchain node 104 to query the blockchain 150 for any transactions to which the corresponding party 103 is a recipient (or indeed to check other parties' transactions in the blockchain 150, because in an embodiment, the blockchain 150 is a public facility that provides transaction trust to some extent through its public visibility). The wallet function on each computer device 102 is configured to formulate and send transactions 152 according to a transaction protocol. As described above, each blockchain node 104 runs software that is configured to verify transactions 152 according to the blockchain node protocol and forward transactions 152 for propagation in the blockchain network 106. The transaction protocol and the node protocol correspond to each other, and a given transaction protocol and a given node protocol together implement a given transaction model. The same transaction protocol is used for all transactions 152 in the blockchain 150. All nodes 104 in the network 106 use the same node protocol.

[0045] When a given party 103 (say Alice) wishes to send a new transaction 152j to be included in the blockchain 150, she will formulate the new transaction according to the relevant transaction protocol (using the wallet function in her client application 105). She will then send the transaction 152 from the client application 105 to one or more blockchain nodes 104 to which she is connected. For example, this may be the blockchain node 104 that Alice's computer 102 is best connected to. When any given blockchain node 104 receives the new transaction 152j, it will process it according to the blockchain node protocol and its corresponding role. This includes first checking whether the newly received transaction 152j meets certain conditions for becoming "valid", specific examples of which will be discussed in detail later. In some transaction protocols, the validity conditions may be configurable on a per-transaction basis through a script included in the transaction 152. Alternatively, the conditions may simply be a built-in function of the node protocol, or defined by a combination of script and node protocol.

[0046] If the newly received transaction 152j passes the validity test (i.e., under the “valid” condition), any blockchain node 104 that receives the transaction 152j will add the new verified valid transaction 152 to the ordered transaction set 154 maintained at the blockchain node 104. Further, any blockchain node 104 that receives the transaction 152j will then propagate the verified valid transaction 152 to one or more other blockchain nodes 104 in the network 106. Since each blockchain node 104 applies the same protocol, it is assumed that the transaction 152j is valid, which means that the transaction will soon be propagated throughout the network 106.

[0047] Once in the ordered pool 154 of pending transactions maintained at a given blockchain node 104, that blockchain node 104 will begin racing to solve the proof-of-work puzzle on the latest version of its respective pool 154 containing the new transaction 152 (keep in mind that other blockchain nodes 104 can attempt to solve the puzzle based on different transaction pools 154. However, whoever solves the puzzle first will define the set of transactions included in the latest block 151. Ultimately, the blockchain node 104 will solve the puzzle for a portion of the ordered pool 154, which includes Alice's transaction 152j). Once the pool 154 including the new transaction 152j completes the proof-of-work, it will immutably become part of one of the blocks 151 in the blockchain 150. Each transaction 152 includes a pointer to an earlier transaction, so the order of transactions is also immutably recorded.

[0048] Different blockchain nodes 104 may initially receive different instances of a given transaction and therefore have conflicting views about which instance is “valid” before one instance is published in a new block 151, at which point all blockchain nodes 104 agree that the published instance is the only valid instance. If a blockchain node 104 accepts one instance as valid and then discovers that a second instance has been recorded in the blockchain 150, the blockchain node 104 must accept this and will discard (i.e., treat as invalid) the instance it originally accepted (i.e., the instance that has not yet been published in block 151).

[0049] Another type of transaction protocol operated by some blockchain networks as part of the account-based transaction model can be called an "account-based" protocol. In the account-based case, each transaction is defined not by reference to the UTXO of a previous transaction in the past sequence of transactions, but by reference to an absolute account balance. The current state of all accounts is stored individually in the blockchain by the nodes of the network and is continuously updated. In such systems, transactions are ordered using an account's running transaction record (also called a "position"). This value is signed by the sender as part of their cryptographic signature and hashed as part of the transaction reference calculation. In addition, optional data fields can also be signed in the transaction. For example, a data field can point to a previous transaction if it contains the ID of the previous transaction.

[0050] 2. UTXO-based model

[0051] Figure 2 An exemplary transaction protocol is shown. This is an example of a UTXO-based protocol. A transaction 152 ("Tx" for short) is the basic data structure of the blockchain 150 (each block 151 includes one or more transactions 152). The following will be described with reference to an output-based or "UTXO"-based protocol. However, this is not limited to all possible embodiments. It should be noted that although the exemplary UTXO-based protocol is described with reference to Bitcoin, it can also be implemented on other exemplary blockchain networks.

[0052] In the UTXO-based model, each transaction ("Tx") 152 includes a data structure that includes one or more inputs 202 and one or more outputs 203. Each output 203 may include an unspent transaction output (UTXO), which can be used as a source of input 202 for another new transaction (if the UTXO has not been redeemed). The UTXO includes a value that specifies the amount of a digital asset. This represents a set of tokens on a distributed ledger. The UTXO may also include a transaction ID of its source transaction and other information. The transaction data structure may also include a header 201, which may include an indicator of the size of the input field 202 and the output field 203. The header 201 may also include an ID for the transaction. In an embodiment, the transaction ID is a hash value of the transaction data (excluding the transaction ID itself) and is stored in the header 201 of the original transaction 152 submitted to the node 104.

[0053] Let's say Alice 103a wishes to create a transaction 152j that transfers the relevant amount of digital assets to Bob 103b. Figure 2 In , Alice's new transaction 152j is labeled "Tx1". This new transaction takes the amount of digital assets locked to Alice in output 203 of the previous transaction 152i in the sequence and transfers at least a portion of such amount to Bob. Figure 2 , the previous transaction 152i is labeled "Tx0". Tx0 and Tx1 are just arbitrary labels that do not necessarily mean that Tx0 refers to the first transaction in blockchain 151 and Tx1 refers to a subsequent transaction in pool 154. Tx1 can point to any previous (i.e., preceding) transaction that still has unspent output 203 locked to Alice.

[0054] When Alice creates her new transaction Tx1, or at least when she sends it to the network 106, the previous transaction Tx0 may already be valid and included in block 151 of the blockchain 150. The transaction may have been included in one of the blocks 151 at this time, or it may still be waiting in the ordered set 154, in which case it will be included in the new block 151 soon. Alternatively, Tx0 and Tx1 may be created and sent to the network 106 together; or, if the node protocol allows buffering of "orphan" transactions, Tx0 may even be sent after Tx1. The terms "previous" and "successor" as used herein in the context of transaction sequences refer to the order of transactions in the sequence defined by the transaction pointers specified in the transactions (which transaction points to which other transaction, etc.). They may equally be replaced by "predecessors" and "successors", "predecessors" and "descendants", or "parents" and "children", etc. This does not necessarily refer to the order in which they are created, sent to the network 106, or arrive at any given blockchain node 104. However, subsequent transactions (descendant transactions or "child transactions") pointing to a previous transaction (predecessor transaction or "parent transaction") will not be valid unless the parent transaction is valid. A child transaction that arrives at the blockchain node 104 before the parent transaction is considered an orphan transaction. Depending on the node protocol and / or node behavior, it may be discarded or buffered for a period of time to wait for the parent transaction.

[0055] One of the one or more outputs 203 of the previous transaction Tx0 includes a specific UTXO, labeled UTXO0. Each UTXO includes a value specifying the amount of digital assets represented by the UTXO and a locking script that defines the conditions that the unlocking script in the input 202 of the subsequent transaction must satisfy in order for the subsequent transaction to be valid and thus successfully redeem the UTXO. Typically, the locking script locks the amount to a specific party (the beneficiary of the transaction for that amount). That is, the locking script defines the unlocking condition, which typically includes the following conditions: the unlocking script in the input of the subsequent transaction includes the cryptographic signature of the party to which the previous transaction was locked.

[0056] The locking script (also known as scriptPubKey) is a piece of code written in a domain-specific language recognized by the node protocol. A specific example of such a language is called a "Script" (with a capital S), which can be used by the blockchain network. The locking script specifies the information required to spend the transaction output 203, such as the requirement for Alice's signature. The unlocking script appears in the output of the transaction. The unlocking script (also known as scriptSig) is a piece of code written in a domain-specific language that provides the information required to meet the locking script criteria. For example, it can contain Bob's signature. The unlocking script appears in the input 202 of the transaction.

[0057] Thus in the example shown, UTXO0 in output 203 of Tx0 includes a locking script [Checksig P A], the locking script requires Alice’s signature Sig P A , in order to redeem UTXO0 (strictly speaking, to make subsequent transactions that attempt to redeem UTXO0 valid). A ] contains Alice's public key P from her public-private key pair A The input 202 of Tx1 includes a pointer to Tx1 (e.g., by its transaction ID (TxID0), which in the embodiment is the hash value of the entire transaction Tx0). The input 202 of Tx1 includes an index identifying UTXO0 in Tx0 to identify it among any other possible outputs of Tx0. The input 202 of Tx1 further includes an unlocking script <Sig P A >, the unlocking script includes Alice's cryptographic signature, which is created by Alice by applying the private key of her key pair to a predetermined portion of data (sometimes called a "message" in cryptography). The data (or "message") that Alice needs to sign to provide a valid signature can be defined by the locking script, the node protocol, or a combination thereof.

[0058] When a new transaction Tx1 arrives at a blockchain node 104, the node applies the node protocol. This includes running the locking script and the unlocking script together to check whether the unlocking script satisfies the conditions defined in the locking script (where the conditions may include one or more criteria). In an embodiment, this involves juxtaposing two scripts:

[0059] <Sig PA> <pa>||[Checksig PA]

[0060] Where "||" means concatenation, "<…>" means putting data on the stack, and "[…]" means a function consisting of locked scripts (in this case, a stack-based language). Similarly, scripts can be run one after another using a common stack instead of concatenating the scripts. In either case, when run together, the scripts use Alice's public key P A (included in the locking script of the output of Tx0) to verify that the unlocking script in the input of Tx1 contains Alice's signature when signing the expected portion of the data. The expected partial data itself (the "message") also needs to be included in order to perform this verification. In an embodiment, the signed data includes the entire Tx1 (so there is no need to include a separate element to plaintext specify the signed partial data, as it is already present).

[0061] Those skilled in the art will be familiar with the details of verification by public-private cryptography. Basically, if Alice has signed a message using her private key encryption, then given Alice's public key and the message in plain text, other entities such as node 104 can verify that the message must have been signed by Alice. Signing typically includes hashing the message, signing the hash value, and marking this to the message as a signature, so that any holder of the public key can verify the signature. Therefore, it should be noted that in embodiments, any reference to signing a particular data fragment or transaction portion, etc. herein can mean signing the hash value of the data fragment or transaction portion.

[0062] If the unlocking script in Tx1 satisfies one or more conditions specified in the locking script of Tx0 (so, in the example shown, if Alice's signature is provided and verified in Tx1), then the blockchain node 104 considers Tx1 to be valid. This means that the blockchain node 104 will add Tx1 to the pending transaction ordered pool 154. The blockchain node 104 will also forward the transaction Tx1 to one or more other blockchain nodes 104 in the network 106 so that it will propagate throughout the network 106. Once Tx1 is valid and included in the blockchain 150, this will define UTXO0 from Tx0 as spent. It should be noted that Tx1 is only valid if it spends unspent transaction output 203. If it attempts to spend an output that has already been spent by another transaction 152, then Tx1 will be invalid even if all other conditions are met. Therefore, the blockchain node 104 also needs to check whether the UTXO referenced in the previous transaction Tx0 has been spent (that is, whether it has formed a valid input for another valid transaction). This is one of the reasons why it is important for the blockchain 150 to impose a defined order on transactions 152. In practice, a given blockchain node 104 may maintain a separate database marking the UTXO 203 of a transaction 152 as having been spent, but ultimately defining whether a UTXO has been spent depends on whether it has formed a valid input to another valid transaction in the blockchain 150.

[0063] If the total amount specified in all outputs 203 of a given transaction 152 is greater than the total amount pointed to by all its inputs 202, this is another basis for failure in most transaction models. Therefore, such a transaction will not be propagated or included in block 151.

[0064] Note that in the UTXO-based transaction model, a given UTXO needs to be spent as a whole. You cannot "leave behind" a portion of the amount defined in a UTXO as spent while spending another portion. However, the amount of a UTXO can be split between multiple outputs of subsequent transactions. For example, the amount defined in UTXO0 of Tx0 can be split between multiple UTXOs in Tx1. Therefore, if Alice does not want to give all of the amount defined in UTXO0 to Bob, she can use the remaining portion to make change for herself in the second output of Tx1, or to pay another party.

[0065] In practice, Alice will also typically need to include a fee for the Bitcoin node 104 that successfully includes Alice's transaction 104 in block 151. If Alice does not include such a fee, Tx0 may be rejected by the blockchain node 104, and therefore, although technically valid, may not be propagated and included in the blockchain 150 (if the blockchain node 104 does not want to accept transaction 152, the node protocol does not force the blockchain node 104 to accept it). In some protocols, the transaction fee does not require its own separate output 203 (i.e., no separate UTXO is required). Instead, any difference between the total amount pointed to by input 202 and the total amount specified by output 203 of a given transaction 152 will be automatically provided to the blockchain node 104 that issued the transaction. For example, assume that a pointer to UTXO0 is the only input to Tx1, and Tx1 has only one output UTXO1. If the amount of digital assets specified in UTXO0 is greater than the amount specified in UTXO1, the difference may be allocated (or spent) by the node 104 that wins the proof-of-work race to create the block containing UTXO1. Alternatively or additionally, this does not necessarily preclude the possibility of explicitly specifying a transaction fee in one of the UTXOs 203 in its own transaction 152.

[0066] Alice and Bob's digital assets consist of the UTXO locked to them in any transaction 152 anywhere in the blockchain 150. Therefore, in general, the assets of a given party 103 are scattered among the UTXOs of various transactions 152 throughout the blockchain 150. No single number defining the total balance of a given party 103 is stored anywhere in the blockchain 150. The role of the wallet function of the client application 105 is to collate the various UTXO values ​​locked to the respective parties and not yet spent in other subsequent transactions. To achieve this, it can query a copy of the blockchain 150 stored at any one Bitcoin node 104.

[0067] It should be noted that script code is often represented schematically (i.e., using an imprecise language). For example, an opcode (opcode) may be used to represent a particular function. "OP_..." refers to a particular opcode of the scripting language. For example, OP_RETURN is a scripting language opcode that, when preceded by OP_FALSE at the beginning of a locking script, creates an unspendable output of a transaction that can store data within the transaction, thereby immutably recording the data in the blockchain 150. For example, the data may include a file to be stored in the blockchain.

[0068] Typically, the inputs to a transaction contain a digital signature corresponding to the public key PA. In an embodiment, this is based on ECDSA using the elliptic curve secp256k1. The digital signature signs a specific piece of data. In an embodiment, for a given transaction, the signature will sign part of the transaction input and part or all of the transaction output. Signing a specific part of the output depends on the SIGHASH flag. The SIGHASH flag is typically a 4-byte code included at the end of the signature that selects the output to be signed (and is therefore fixed at the time of signing).

[0069] The locking script is sometimes referred to as "scriptPubKey", which means that it usually includes the public key of the party to which the corresponding transaction is locked. The unlocking script is sometimes referred to as "scriptSig", which means that it usually provides the corresponding signature. However, more generally speaking, in all applications of blockchain 150, the conditions for UTXO redemption do not necessarily include verification of the signature. More generally speaking, the scripting language can be used to define any one or more conditions. Therefore, the more general terms "locking script" and "unlocking script" may be preferred.

[0070] 3. Side Channels

[0071] like Figure 1 As shown, the client application on each of Alice and Bob's computer devices 102a, 120b can include additional communication functions. This additional function enables Alice 103a to establish a separate side channel 107 with Bob 103b (at the instigation of any party or third party). Side channel 107 enables data to be exchanged away from the blockchain network. Such communication is sometimes referred to as "off-chain" communication. For example, this can be used to exchange transactions 152 between Alice and Bob without registering the transaction (yet) on the blockchain network 106 or publishing it on the chain 150 until one of the parties chooses to broadcast it to the network 106. Sharing transactions in this way is sometimes referred to as sharing "transaction templates". The transaction template may lack one or more inputs and / or outputs required to form a complete transaction. Alternatively or additionally, side channel 107 can be used to exchange any other transaction-related data, such as keys, negotiation amounts or terms, data content, etc.

[0072] The side channel 107 may be established via the same packet switching network 101 as the blockchain network 106. Alternatively or additionally, the side channel 301 may be established via a different network such as a mobile cellular network or a local area network such as a wireless local area network, or even via a direct wired or wireless link between Alice's and Bob's devices 102a, 102b. In general, a side channel 107 referred to anywhere in this document may include any one or more links via one or more networking technologies or communication media that are used to exchange data "off-chain", i.e., off-chain. The bundle or collection of off-chain links may be referred to as a side channel 107 as a whole. Therefore, it should be noted that if Alice and Bob are said to exchange certain information or data, etc., via a side channel 107, this does not necessarily mean that all of this data must be sent over exactly the same link or even the same type of network.

[0073] 4. Node software

[0074] Figure 3 An example of node software 450 running on each blockchain node 104 of the network 106 in an example of a UTXO-based or output-based model is shown. It should be noted that another entity may run the node software 450 without being classified as a node 104 on the network 106, i.e., not performing the actions required of the node 104. The node software 450 may include, but is not limited to, a protocol engine 451, a scripting engine 452, a stack 453, an application-level decision engine 454, and a collection of one or more blockchain-related functional modules 455. Each node 104 may run node software that includes, but is not limited to, all three of the following: a consensus module 455C (e.g., proof of work), a propagation module 455P, and a storage module 455S (e.g., a database). The protocol engine 401 is typically configured to identify different fields of a transaction 152 and process such fields according to the node protocol. When a transaction 152i (Tx m-1 )’s output (e.g., UTXO) is an input transaction 152j (Tx j ), the protocol engine 451 identifies Tx j The unlocking script in and passes it to the script engine 452. The protocol engine 451 also j Pointer in the input to identify and retrieve Tx i .Tx i may be published on blockchain 150, in which case the protocol engine may retrieve Tx from the copy of block 151 of blockchain 150 stored at node 104 i . Or, Tx i It can also be published on blockchain 150. In this case, protocol engine 451 can retrieve Tx from unpublished ordered transaction set 154 maintained by node 104. i Regardless of the method used, the script engine 451 will identify Tx i The locked script in the reference output is passed to the script engine 452.

[0075] Therefore, the script engine 452 has Tx i The locking script and the j The unlocking script for the corresponding input. For example, Figure 2 Transaction markers Txj0 and Txj1 are shown in FIG, but the same transaction can also be applied to any transaction pair. As previously described, the script engine 452 runs two scripts together, which will include placing data on and retrieving data from the stack 453 according to the stack-based scripting language used (e.g., script).

[0076] By running the scripts simultaneously, the script engine 452 determines whether the unlocking script satisfies one or more criteria defined in the locking script, i.e., whether the unlocking script unlocks the output including the locking script? The script engine 452 returns the result of the determination to the protocol engine 451. If the script engine 452 determines that the unlocking script does meet one or more criteria specified in the corresponding locking script, the result "TRUE" is returned. Otherwise, the result "FALSE" is returned.

[0077] In the output-based model, the result "TRUE" from the script engine 452 is one of the conditions for the validity of the transaction. Typically, one or more further protocol-level conditions evaluated by the protocol engine 451 must also be satisfied; for example, Tx j The total amount of digital assets specified in the inputs of tx does not exceed the total amount pointed to in its outputs, and tx i The pointed output of has not been spent by another valid transaction. The protocol engine 451 evaluates the result from the script engine 452 and one or more protocol-level conditions, and only if they are all TRUE, the protocol engine verifies the transaction Tx j The protocol engine 451 outputs an indication of whether the transaction is valid to the application-level decision engine 454. j Only when the conditions are really valid, the decision engine 454 can choose to control the consensus module 455C and the propagation module 455P at the same time to execute its Tx j· This includes the consensus module 455C, adding Tx to the corresponding ordered transaction set 154 of the node. j , for incorporation into block 151; and propagation module 455P, Tx j Forwarded to another blockchain node 104 in the network 106. Optionally, in an embodiment, the application-level decision engine 454 may apply one or more additional conditions before triggering one or both of these functions. For example, the decision engine may choose to publish a transaction only if the transaction is valid and sufficient transaction fees are reserved.

[0078] In addition, it should be noted that in this article, the terms "TRUE" and "FALSE" are not necessarily limited to returning results that are expressed only in the form of a single binary number (bit), although this is indeed a possible implementation. More generally, "TRUE" can refer to any state indicating a successful or positive result, while "FALSE" can refer to any state indicating an unsuccessful or non-positive result. For example, in an account-based model, the combination of implicit protocol-level verification of signatures and additional positive outputs of smart contracts can be used to indicate that the result is "TRUE" (if both individual results are TRUE, the overall result is considered to be TRUE).

[0079] 5. Elliptic Curve Arithmetic in Scripts

[0080] Figure 4 An exemplary system 400 for implementing an embodiment of the present disclosure is shown. The system 400 includes a first script generator (Alice 103a), a second script generator (Bob 103b), and one or more engines in the form of a blockchain node 104 of a blockchain network 106. It should be understood that this is merely an illustrative example, and in general the script generator and the script engine can be implemented by any suitable entity, not just Alice 103a, Bob 103b, and the blockchain node 104. In some examples, the first script generator may include a function library that is configured to output a first script. The function library may allow a user to update one or more values ​​(e.g., a modulus value, a scalar value, etc.) of the first script to generate a first script specific to a specific use case.

[0081] continue Figure 4 In the example of , Alice 103a is configured to generate a first script for a first blockchain transaction. As shown, Alice 103a can also generate a first transaction and send the first transaction to the blockchain network 106. Alternatively, Alice 103a can provide the first script to a different entity (e.g., a different user) to submit to the blockchain network 106 as part of a blockchain transaction. Figure 4 In the example of , the first script constitutes part of a locking script that locks the output of the first transaction. In other examples, the first script may constitute part of an unlocking script ("second script") of a second transaction. The blockchain node 104 of the blockchain network 106 is configured to receive the first transaction and the second transaction and execute the first script and the second script together.

[0082] 5.1. Modular inverse operation

[0083] The first script includes a modular inverse operation script. The modular inverse operation script is configured to generate a modular inverse of a target integer using a modular value, and the modular value is coprime to the target integer. The target integer and the modular value are provided as inputs to the modular inverse operation script. In some examples, the input is included in the first script (i.e., the same script as the modular inverse operation script). In other examples, the input is included in a second script of a second blockchain transaction. For example, the second script can be an unlocking script of the second transaction, or constitute a part of the unlocking script. Figure 4 As shown, a second transaction may be generated by Bob 103b and submitted to the blockchain network 106.

[0084] In an embodiment, the modular inverse operation script is configured to generate the modular inverse of the target integer when the modular value is a prime number n=p, in which case:

[0085] x -1 ≡xp -2 mod p

[0086] Where (p-2) is called the reduced modulus. In some embodiments, 0 <x<p。

[0087] The following assumes that the element to be reversed is in (0, p) and is therefore an integer, which allows the use of the opcode OP_MOD.

[0088] Value xp -2 modp can be calculated using the square multiplication algorithm. Since the reduced modulus value (p-2) is known, there is no need to test bits and branch accordingly. Instead, carefully write the script using the fact that the modulus p is known.

[0089] Starting from x, p at the top of the stack, the goal is to calculate all square values And move the ith square to the alt stack only if the ith bit of p-2 is set. Since it is known which bits of p-2 are set, no branching is required. Then, iteratively extract the retained square values ​​from the stack and multiply them. It should be noted that the structure of the resulting script outlined below is hard-coded to the integer p-2.

[0090] The modular inverse script is configured to generate each square value in a sequence of square values. For i=0, the first square value is equal to the target integer (x). Each subsequent square value is generated by taking the immediately preceding square value in the sequence and multiplying it by itself, i.e., squaring the immediately preceding square value. That is, each subsequent square value is calculated by the following equation:

[0091] s i+1 =(s i ) 2

[0092] where s i is the i-th square value in the sequence of square values.

[0093] Assumptions is a little-endian binary expression of known exponent p-2. The modular inverse operation script is configured to include in the result each of the square values ​​corresponding to the set bit of the reduced modulus value. That is, if the i-th bit of the reduced modulus value is set (set equal to 1), then the i-th square value is included in the result by moving to the alt stack. The result can be initialized to an empty array and updated by adding each of the related square values.

[0094] The modular inverse script is configured to multiply the square value of the result, thereby generating a result value by returning all retained values ​​from the alt stack of the previous step, and multiplying these retained values ​​modulo p. The modular inverse script is configured to calculate the remainder of the result value with respect to the modulo value (p), and output the calculated value as the modular inverse (x -1 ). For example, the modular inverse may be output to a stack-based memory 453. Additionally or alternatively, the modular inverse may be output for use by a different script of the first script, as described below.

[0095] In some embodiments, the modular inverse operation script may be further configured to push a square value corresponding to a set value (bit) of the reduced modular value to an alt stack. The modular inverse operation script may also be configured to interactively extract the pushed square value from the alt stack for multiplication via the main stack.

[0096] The modular inverse script may also be configured to remove the squared value from the main stack after the modulus of the result value has been calculated.

[0097] The modular inverse operation script may also be configured to calculate the remainder of each square value with respect to the modular value (p), which remainder is to be included in the result. The modular inverse operation script may also be configured to calculate the remainders of all generated square values.

[0098] Below is pseudo code that can be used to write an exemplary modular inversion script [mod invert wth branchless square and multiply], which is configured to calculate and output the target integer <x>For the modulus The exemplary scripts shown here are written in the Script scripting language (e.g., as used by the Bitcoin blockchain). It should be understood that the described embodiments are not limited to any particular scripting language, and Script is used only as an example. Other suitable scripting languages ​​may be used.

[0099] 1. Add opcode: / / initialize

[0100] OP_SWAP

[0101] 2. For i=0 to κ-2, perform the following operations:

[0102] ·if Then add opcode: / / if bit is set

[0103] OP_DUP OP_TOALTSTACK

[0104] Add opcodes:

[0105] OP_DUP OP_MUL

[0106] OP_OVER OP_MOD

[0107] 3. For i = 1 to hw p-2 -1, then add the opcode:

[0108] OP_FROMALTSTACK OP_MUL

[0109] OP_OVER OP_MOD

[0110] 4. Add opcode: / / Finalize (remove unwanted values ​​from the stack)

[0111] OP_NIP

[0112] Among them hw p-2 yes The Hamming weight of . Assume yes (bits set), so

[0113] Since the script is hardcoded for the reduction modulo value (p-2), no branching is done in the script. This saves about 12 opcodes per iteration, thus saving 12log(p) bytes in script size, making the script more efficient.

[0114] Initialization requires 1 opcode, moving the appropriate square to the alt stack requires 2 bytes, calculating each modular square requires 4 bytes, and returning and modularly multiplying each retained square requires 4 bytes as shown above. Therefore, the size of the script is as follows:

[0115] size([mod invert via branchless square and multiply])

[0116] : =1+2hw p-2 +4(κ-1)+4(hw p-2 -1)

[0117] =4κ+6hgw p-2 -7.

[0118] For sparse p-2 (a small number of bits are set), this is significantly better than the size of the branched square multiplication script. As a further optimization, the modular inversion script can be configured to reduce modp after a predefined number of squared values ​​have been generated (i.e., every few iterations).

[0119] It will be appreciated that the structure of the script depends on the reduction modulo value p-2, since the number of iterations of the squaring step depends on the number of bits of p-2, and the squared values ​​included in the result depend on the value of each bit of p-2.

[0120] In this article, the script [mod invert via branchless square and multiply] can be referred to as [modular invert].

[0121] 5.2. Point addition

[0122] The modular inverse script can be used to compute the modular inverse of an integer as part of the addition of two elliptic curve points.

[0123] Assume that p is an odd prime number, and Make 4a 3 -27b 2 ≠ 0. The Weierstrass elliptic curve is the set For any two points P, Q∈E a,b,p , the group law (addition) is defined as follows:

[0124] 1. If Then P+Q:=Q

[0125] 2. Otherwise, if Then P+Q:=P

[0126] 3. Otherwise, if P = -Q, then

[0127] 4. Otherwise, P+Q:=(x + : =λ 2 -x1-x2,y + : =λ(x1-x3)-y1), where P: =(x1y1), Q: =(x2,y2), and:

[0128] a. If P≠Q, then

[0129] b. If P = Q, then

[0130] The inverse of an affine point P:=(x,y) is defined as -P:=(x,-y). All the above operations are based on carried out.

[0131] The most expensive operation in dot addition is computing the modular inverse. In terms of size, the cost in the script is even higher because the loop must be unrolled.

[0132] The first script may include a point addition script configured to obtain a first elliptic curve point (P) and a second elliptic curve point (Q) and a modulus value (p). In the script, the elliptic curve points P and Q may be represented as (x1, y1) and (x2, y2), respectively. The point addition script is configured to output an addition result (P+Q) of the first point and the second point. The addition result (P+Q) is referred to herein as a first target point. In some examples, the first elliptic curve point and / or the second elliptic curve point may be obtained from a second script of a second transaction. When calculating the first target point, the point addition script is configured to calculate a lambda value λ. As shown above, λ is based on numerator and denominator values. The numerator and denominator are calculated in the script. Then, the point addition script is configured to calculate the inverse of the denominator and multiply the inverse of the denominator by the numerator to calculate λ. In other words, the target integer and modulus value input to the modulus inverse operation script are the calculated denominator and p, respectively. Then, the point addition script uses the calculated λ to calculate the first target point according to Equation 4.

[0133] The point addition script is configured to calculate the numerator and denominator according to equation 4a and equation 4b above, depending on whether the first point and the second point are equal. The point addition script can be configured to determine whether the first point and the second point are equal in the script. This means that the script for calculating λ only needs to be included once as part of the point addition script. This, in turn, means that the modular inverse operation script only needs to be included once as part of the point addition script.

[0134] The point addition script can also be configured to determine whether either the first point or the second point is equal to the identity element. And only if either the first or the second point is not equal to the identity element Calculate λ in the case of .

[0135] The lower box shows an exemplary point addition script [Add points], which is configured to calculate and output the addition operation result of two elliptic curve points.

[0136]

[0137] The script [Add points] assumes a stack whose top 5 elements are initialized from bottom to top to y2, x2, y1, x1, p - the coordinates of the addend points P and Q and the modulus (also translated as modulus) p. After completion, the script pops P, Q and p and sets the coordinate y of P+Q to + ,x + (in this order) onto the stack. The script is defined so that during the generation of λ, it calls the inversion subroutine only once, instead of calling the inversion subroutine (twice) in branch statements (4a) and (4b).

[0138] More precisely, if The subroutine script [Computeλ] (see below) then computes the appropriate numerator N and denominator D (integer-based) in branches (4a) and (4b). In the joint branch (4), D is modularly inverted and finally computed λ and P+Q. Upon completion, the script pushes the scalar λ onto the stack above coordinates P and Q.

[0139] The script [Add points from precomputedλ] (see below) is used to calculate P+Q. The script assumes a stack whose top 6 elements are initialized from bottom to top to y2, x2, y1, x1, λ, p. Once completed, the script adds the coordinates y of the point P+Q + ,x + Pushes onto the stack at coordinates P and Q, and consumes λ, p.

[0140] Adding two points depends mainly on the complexity of the modular inverse operation. Specifically, the script contains 37 opcodes and subroutines:

[0141] size([Add points])=37

[0142] +2 / / size([Duplicate points])

[0143] +9 / / 2×size([Duplicate points])

[0144] +7 / / size([Nagate point])

[0145] +5 / / size ([Areequal points])

[0146] +34+size([Modular invert]) / / size([Computeλ])

[0147] =100+size([Modular invert])

[0148] The lower box shows an exemplary script [Compute λ], which is configured to calculate and output λ based on the numerator, denominator and modulus value. This exemplary script utilizes a modular inverse operation script.

[0149]

[0150] The lower box shows an exemplary script [Add points with precomputed λ] configured to calculate and output a target point based on the first and second points and the precomputed value of λ.

[0151]

[0152] 5.3. Point Subtraction

[0153] The first script may include a point subtraction script configured to subtract one elliptic curve point from another elliptic curve point. In some examples, the point subtraction script may include a point addition script.

[0154] The point subtraction script is configured to obtain a third elliptic curve point and a modulus value. The point subtraction script is configured to invert the third elliptic curve point using the modulus value and output the result to the point addition script as the first elliptic curve point or the second elliptic curve point. That is, the point subtraction script inverts the elliptic curve point and then adds it to another elliptic curve point through the point addition script.

[0155] The lower box shows an exemplary Negate point script [Negate point], which can be used by the point subtraction script to negate an elliptic curve point.

[0156]

[0157] This operation yields the inverse of a point. This operation is implemented for Weierstrass curves, where the negation of a point P=(x,y) is defined as -P := (x, -y mod p). The negatepoint script consumes the point and pushes its negation. The negatepoint script assumes a stack whose point coordinates are reduced to modp (minimal positive residue), which allows the use of OP_MOD. Negating a point requires 7 bytes.

[0158] The subtraction of two points can be done using the [Negate point] and [Add points] scripts as described previously. The resulting complexity is the sum of the complexity of the two scripts:

[0159] size([Subtract points])=size([Negate point])+size([Add points]).

[0160] 5.4. Point Doubling

[0161] The modular inverse script can be used to compute the modular inverse of an integer as part of doubling an elliptic curve point. Point doubling is defined above in equation 4b.

[0162] The first script may include a point doubling script configured to obtain a fourth elliptic curve point (P) and a modulus value (p). In the script, the elliptic curve point P may be represented as (x1, y1). The point doubling script is configured to output a doubling of the elliptic curve point (2P). The doubling (2P) is referred to herein as the second target point. It should be noted that, in general, labels such as "first", "second", "third", etc. are used as arbitrary labels and do not necessarily imply an order or the presence of any other values ​​unless the context requires otherwise. For example, the second target point may be calculated without calculating the first target point. Similarly, "first" and "second", etc. may be used as labels for the same or different values ​​or other types of data. For example, the "first" elliptic curve point and the "third" elliptic curve point may be the same point.

[0163] In some examples, the elliptic curve point to be doubled may be obtained from a second script of the second transaction.

[0164] The point doubling script can be configured to calculate the second lambda value in a similar manner to the point addition script described above. That is, the numerator and denominator are calculated (e.g., using equation 4b), the modular inversion script is used to calculate the inverse of the denominator, and then the numerator is multiplied by the inverse of the denominator to generate lambda. The point doubling script is then configured to calculate the second target point using the third elliptic curve point (P) and lambda.

[0165] The box below shows an example point doubling script [Double points], which is configured to compute and output the doubling of an elliptic curve point. Takes a point and a modulus, and pushes its doubling result, consuming the parameters.

[0166] Doubling a point depends primarily on the modular inverse. However, the constant is slightly smaller than adding two points using [Add points]. Specifically:

[0167] size([Double point])=79+

[0168] size([mod invert wth branchless square and multiply]).

[0169]

[0170] 5.5. Scalar multiplication

[0171] The first script may include a first scalar multiplication (MBS) script configured to multiply a fifth elliptic curve point (P) by a scalar (k). In addition, it should be noted that "fifth" is used here only as a convenient label. The first MBS script is configured to obtain a fifth elliptic curve point, a scalar value, and a modulus value. The scalar value is represented in binary or converted to binary in the script. The first MBS script is configured to use a double-and-add algorithm to calculate kP, referred to herein as a third target elliptic curve point.

[0172] To calculate kP, the double addition algorithm iteratively calculates the double

[0173] D1: =2P, D2: =D1+D1=2 2 P,…,D n-1 :=D n-2 +D n-2 =2 n-1 P,

[0174] and D is set if and only if the i-th bit of scalar k is set i Add to the obtained point R.

[0175] More specifically, the first MBS script includes a series of sub-scripts to be executed in sequence. Each sub-script is associated with a corresponding index and includes an instance of a point doubling script (e.g., [Double point]). It should be remembered that the point doubling script utilizes a modular inverse operation script.

[0176] The first subscript in the series is configured to double the fifth elliptic curve point, i.e., calculate D1: =2P. This is called the first intermediate result. The next subscript in the series is configured to double the first intermediate result, i.e., calculate D2: =D1+D1=2 2 P. This is called the second intermediate result. The process is repeated one or more times. Typically, each subscript is configured to generate a corresponding intermediate result by doubling a previous value, where the previous value is the fifth elliptic curve point (P) or the previous intermediate result (D i-1 ).

[0177] The first MBS script is configured to calculate kP by adding the intermediate results generated by the sub-scripts whose corresponding index is associated with the corresponding bit set (i.e., equal to 1) of the scalar k. In other words, if the i-th bit is set, the i-th intermediate result generated by the i-th sub-script is added to the result value. The result value can be initialized to an empty array and updated by adding each of the related intermediate results.

[0178] The lower box shows an exemplary first MBS script [Multiply by scalar via double-and-add], which is configured to calculate and output scalar multiplication of elliptic curve points. Take a point, a scalar, and a modulus, and push the resulting scalar multiplication result.

[0179]

[0180] [Multiply by scalar via double-and-add] Use the script shown in the box below as a subroutine that, for points R and D based on an elliptic curve and a scalar k (double), updates R with either itself or R+D based on the value of the i-th bit of the scalar k. After the subroutine executes, the top of the stack is either P (bit not set) or P+D (bit set). This leaves the scalar as the third element from the top of the stack.

[0181]

[0182] Now, calculate the number of bytes to do a scalar multiplication using double addition. There are two factors here, the size n of the scalar k and the size k of the modulo p of the base field (in secp256k1, both factors are 256 bits long). The script has 9n opcodes and subroutines:

[0183] size([Multiplybyscalar])=9n+6n-3 / / (2(n-1)+1)×size([Load modulus])+79n+size([Modular invert]) / / n×

[0184] size([Double point])+120n+n·size([Modular invert]) / / n×

[0185] size([Add points if bit set])

[0186] =214n+2n·size([Modular invert])-3

[0187] 5.6. Scalar Multiplication—Fixed Point

[0188] The first script may include a second scalar multiplication (MBS) script configured to multiply a sixth elliptic curve point (P) by a scalar (k). Furthermore, it should be noted that both "second" and "sixth" are used herein merely as convenient labels. The second MBS script is different from the first MBS script. That is, the first MBS script and the second MBS script are different types of scripts configured to perform different functions. The second MBS script is configured to multiply a predefined elliptic curve point by a scalar using a modulus value. The scalar value is represented in binary, or converted to binary in the script. Like the first MBS script, the second MBS script is also configured to use a double addition algorithm to calculate kP, referred to herein as a fourth target elliptic curve point. However, in this case, the precomputed double D i , instead of calculating that doubling in the script.

[0189] The second MBS script includes a series of sub-scripts to be executed in sequence. Each sub-script is associated with a corresponding index and includes an instance of a point addition script (e.g., [Add points]). Each sub-script includes a corresponding pre-computed doubling of the sixth elliptic curve point. That is, the first sub-script includes a first doubling D1: =2P, and the second sub-script includes a second doubling D2: =D1+D1=2 2 P, etc. Each subscript is configured to add the corresponding double to the result using the dot addition script if the corresponding bit of the scalar is set (i.e., equal to 1). In other words, if the i-th bit is set, the i-th subscript is configured to add the i-th double D to the result. i Add to the result value. The result value may be initialized to an empty array and updated by adding each of the doubles in the associated double.

[0190] The lower box shows an exemplary second MBS script [MultiplyPby scalar], which is configured to compute and output a scalar multiplication of elliptic curve points. Take a scalar and a modulus, and push the resulting scalar multiplication result.

[0191] Compared to the double-add script shown above, this script saves the doubling operation, yielding:

[0192]

[0193]

[0194] 6. Other scripts

[0195] This section shows multiple scripts that can be included as part of the first script. It should be understood that these scripts are merely examples, and based on this disclosure, those skilled in the art will be able to develop equivalent scripts that perform equivalent functions. The same applies to the exemplary scripts described above.

[0196] 6.1. Determine whether a bit is equal to 1 or 0

[0197] Assume (b κ-1 ,…,b0) is a k-bit integer Assume that is the length in bytes of λ. The i-th bit b of λ can be tested by bitwise operation i Is it set to 1:

[0198] 1. Compute the 81-bit representation of the integer 1, which has 81-1 0s followed by a 1 in big-endian byte order.

[0199] 2. Shift the 1 bits to the left by a total of i positions. This is equivalent to calculating 2 i (If the position index starts at 1, move i-1 positions.)

[0200] 3. In 2 i Perform a Boolean AND operation between λ and λ.

[0201] The box below shows an example script [Is bit set] that is configured to take a target bit and a scalar as arguments. The first line pushes the integer 1 as an array of l bytes in big-endian byte order (required for bitwise OP_AND); since OP_NUM2BIN converts to a number in little-endian byte order, the bit 1 is appended directly to the right end of the array of 0s of length (l-1). The second line sets only the i-th bit of the pushed 1. The third line leaves the number res at the top of the stack, which is 2 i (bit is set, b i =1) or 0 (bit not set, b i =0). Skip details, which can be interpreted as the Boolean value of a branch in an OP_IF statement.

[0202]

[0203] After execution, this will show the state of the stack after each line. l is a byte array of length l representing the integer n in big-endian byte order.

[0204]

[0205] The size of the script [Is bit set] is 9 bytes regardless of the size of λ.

[0206] 6.2. Click Copy

[0207] Sometimes it is beneficial to be able to copy two points P:=(x1, y1) and Q:=(x2, y2). This can be achieved using the following example script. Copying a pair of points requires two bytes.

[0208]

[0209] 6.3. Point Equality

[0210] Two points of an elliptic curve are equal if and only if their coordinates are the same. The script that implements this logic is given in the box below. The script consumes the coordinates of the points and pushes 1 to the stack if the points are equal, and 0 to the stack otherwise. The script assumes a stack where the coordinates of the points have been reduced mod p. Checking whether two points are equal requires 5 bytes.

[0211]

[0212] 6.4. Unit element

[0213] Assume ε is an empty array. Use the following equation to represent the identity element of the Weierstrass curve,

[0214] where ε represents an empty array. In some examples, the script engine interprets the integer 128 as positive zero. Therefore, this choice ensures that the unit element is not part of the set of affine points of the curve: the coordinate of 0 in the script engine is given by 0x00 instead of 0x80.

[0215] Compared to point equality, tests whether a given point is It can be completed more efficiently. Just check whether the first coordinate matches 0x80 which is a byte array. See the following script [Is identity element]. This script assumes that the coordinates are reduced modulo p, i.e., they are in [0, p). If the point is the identity element, this script consumes the point and pushes 1. Otherwise, it pushes 0. Checking whether a point is the identity element of the curve requires 3 bytes.

[0216]

[0217] 6.5. Modular Reduction

[0218] The opcode OP_MOD is implemented using the remainder operator % in the script engine. In C language, integer division truncates integers towards 0, so % may output a negative number. Therefore, for -n < x < n, x = x, n OP_MOD. In other words, the output range of OP_MOD is not the residue system. For example:

[0219] -2 = -5, 3 OP_MOD.

[0220] The modulo reduction can be implemented using the exemplary script shown in the following box. Specifically, the range output of this script is the least residue system {0, 1, …, n - 1}. For example:

[0221] 1 = -5, 3 [Reduce mod].

[0222] This script assumes that x, n exist at the top of the stack and outputs x mod n ∈ [0, n), thus consuming the arguments. This script secretly (i.e., in combination with the script engine OP_MOD implementation) calculates (x % p + p) % p. The operation of reducing an integer modulo p requires 10 bytes.

[0223]

[0224] 6.6. Loading a module from the alt stack

[0225] To avoid hard - coding the modulus in many advanced scripts, the following script can be defined and saved in the alt stack. Assume the modulus has been moved to the alt stack.

[0226]

[0227] 6.7. Changing the base

[0228] Assuming that the number of logarithms in a known base G is P, the size of scalar multiplications for any point P (unknown when the script is created) can be significantly improved. For a fixed G, assuming P = xG, then kP = (xk)G. Therefore, the only steps required are to calculate y = xy and run the fixed point script passing the scalar y as an argument. The example script shown in the box below can achieve this. It should be noted that x: = log G P is passed as an argument. The script outputs yP. The size of the script exceeds the size of the underlying fixed point script by only 3 bytes.

[0229]

[0230] 7. Exemplary Use Cases

[0231] The EC arithmetic in the above script can be used to redeem UTXO. Some example use cases are provided below.

[0232] 7.1. Pedersen Commitment

[0233] A UTXO can be spent if a party knows the opening m,r of a Pedersen commitment C=xG+rP specified in the locking script. The generators G and H are known. By hiding the commitment, a message m from a small set can be committed. For example, m can be a bit, or a string from a small public set. This can be useful in hashed time lock contracts (HTLCs) where it is desirable for the commitment scheme to hide the commitment value.

[0234] In one embodiment, a script may be provided that includes two instances of the second scalar multiplication (MBS) script presented in Section 5.6 above, and one instance of the point addition script described in Section 5.2. The script also includes a commitment point.

[0235] The script is configured to implement an MBS script to multiply H by a scalar r to compute a first elliptic curve point rH, where r is provided in the unlocking script. The script is configured to run a second instance of a second MBS script to multiply G by a scalar m to compute a second elliptic curve point mG. The script is configured to run a point addition script to compute the sum of rH and mG to compute a candidate commitment point C * Finally, the script is configured to verify whether the calculated candidate commitment point is equal to the commitment point of the script.

[0236] The lower box shows an example script [Open Pedersen commitmentC] that is configured to compute and output candidate commitment points on m and r.

[0237]

[0238] The UTXO can only be spent if the committed opportunity is known. The commitment C and the generators G,H are hardcoded in the locking script. The opportunity (m,r) is given in the unlocking script. It should be noted that the committed message m can be a single bit.

[0239] The size of the script is as follows:

[0240]

[0241] The curve is based on the base domain of the κ position In secp256k1 this results in a script of about 1.5MB.

[0242] 7.2 Private Key Puzzle

[0243] When using the private key puzzle, the funds can only be spent by disclosing the signature key s corresponding to the public key P:=s·G.

[0244] The private key puzzle can be implemented by exposing the ECDSA ephemeral key, resulting in an extremely light locking script consisting of only a few opcodes.

[0245] This approach requires regenerating the private key off-chain using the contents of the unlocking script. EC arithmetic can be used to envision locking scripts that impose further constraints on the signing key (the solution to the puzzle).

[0246] This is applicable to contingent payments for goods. For example, it can be applied to outsource vanity addresses without off-chain computation or off-chain communication. In fact, having a key pair (s buyer ,P buyer ) can publish a transaction whose locking script enforces the following three conditions on the ECDSA key pair (s,P) given in the unlocking script:

[0247] i. Use scripts [MultiplyGby scalar] and [Are equal points] to enforce P=s·G.

[0248] ii. Forced vanity address d: = RIPEMD160(SHA256(P+P buyer ) contains a predetermined pattern. To generate d, you can use the script [Add points], input P and hard-coded P buyer and the opcode OP_HASH160. To check d against a hardcoded pattern, OP_SPLIT can be used.

[0249] Any party spending the transaction will provide a signature key s, so the buyer can derive the signature key S of the vanity address buyer +s.

[0250] A script may be provided, the script comprising the predetermined public key and the predetermined address, an instance of the second MBS, and an instance of the point addition script.

[0251] The script is configured to obtain a private key and a candidate address from an unlocking script of a subsequent transaction. The script is also configured to input the private key into an instance of a second MBS script to generate a candidate public key. Then, for example, using the [Are equalpoints] script, verify in the script whether the generated candidate public key is equal to the predetermined candidate key. The script is also configured to input the candidate public key and the predetermined public key into an instance of a point addition script to generate a candidate elliptic curve point, and hash the generated candidate elliptic curve point to generate a candidate address. The script is configured to verify whether the candidate address matches the predetermined address, or a portion of the candidate address matches a portion of the predetermined address.

[0252] On secp256k1 the locking script is about 700KB.

[0253] 7.3 Payment to Ciphertext

[0254] In this case, the transaction is redeemed by knowing the plaintext m and the decryption key sk, which decrypts to a fixed ciphertext C. The locking script contains C and implements the decryption algorithm.

[0255] ElGamal can be used, but it should be understood that any group-based encryption scheme will work. Given an ElGamal ciphertext C = (C0, C1) on an elliptic curve (specified in the locking script), the locking script decrypts C into m * :=C1-skC0 and check if m=m * This is again done with EC arithmetic: using fixed-point scalar multiplication and point subtraction.

[0256] 8. Further comments

[0257] Other variations or uses of the disclosed technology may become apparent to those skilled in the art once given the disclosure herein.The scope of the present disclosure is not limited by the described embodiments but only by the appended claims.

[0258] For example, some of the embodiments above have been described in terms of the Bitcoin network 106, the Bitcoin blockchain 150, and the Bitcoin node 104. However, it should be understood that the Bitcoin blockchain is a specific example of a blockchain 150, and the above description can generally be applied to any blockchain. That is, the present invention is in no way limited to the Bitcoin blockchain. More generally, any references to the Bitcoin network 106, the Bitcoin blockchain 150, and the Bitcoin node 104 above can be replaced with reference to the blockchain network 106, the blockchain 150, and the blockchain node 104, respectively. Blockchains, blockchain networks, and / or blockchain nodes can share some or all of the characteristics of the Bitcoin blockchain 150, the Bitcoin network 106, and the Bitcoin node 104 described above.

[0259] In a preferred embodiment of the present invention, the blockchain network 106 is a Bitcoin network, and the Bitcoin node 104 performs at least all of the functions described in creating, publishing, propagating and storing blocks 151 of the blockchain 150. It is not excluded that there may be other network entities (or network elements) that perform only one or some of these functions but not all of them. That is, a network entity may perform the functions of propagating and / or storing blocks without creating and publishing blocks (remember that these entities are not considered to be nodes of the preferred Bitcoin network 106).

[0260] In other embodiments of the present invention, the blockchain network 106 may not be a Bitcoin network. In these embodiments, it is not excluded that the node can perform at least one or part of the functions of creating, publishing, propagating and storing blocks 151 of the blockchain 150, but not all of the functions. For example, on these other blockchain networks, "node" may be used to refer to a network entity that is configured to create and publish blocks 151 but does not store and / or propagate these blocks 151 to other nodes.

[0261] Even more generally, any reference above to the term "Bitcoin node" 104 may be replaced with the term "network entity" or "network element," where such entity / element is configured to perform some or all of the roles in creating, publishing, propagating, and storing blocks. The functionality of such a network entity / element may be implemented in hardware in the same manner as described above with reference to blockchain node 104.

[0262] It should be understood that the above embodiments are described by way of example only. In more general terms, a method, apparatus or program may be provided according to any one or more of the following statements.

[0263] Statement 1. A computer-implemented method for enabling elliptic curve arithmetic to be performed using blockchain transactions, wherein the method is performed by a script generator and comprises: generating a first script for a first blockchain transaction, wherein the first script comprises a modular inverse operation script, and wherein the modular inverse operation script is configured to perform the following steps when executed by a script engine: obtaining a target integer (x) and a modulus value (p), wherein the target integer and the modulus value are relatively prime and the modulus value is a prime number; and, outputting a modular inverse (y) of the target integer, wherein the modular inverse is generated by: generating a sequence of square values, wherein a first square value is equal to the target integer (x), and wherein each subsequent square value in the sequence of square values ​​is generated by multiplying the immediately preceding square value by itself; for each set bit of a reduced modulus value (p-2), wherein the reduced modulus value is an integer less than the modulus value by 2 and represented in binary, including the corresponding square value in the sequence of square values ​​in a result; multiplying the square values ​​of the results to generate a result value; and, calculating the modulus of the result value with respect to the modulus value (p), wherein the modulus of the result value is output as the modular inverse (y); and, outputting the first script for inclusion in the first blockchain transaction.

[0264] Statement 2. The method of statement 1, wherein the modular inverse operation script can be further configured to push the square value of the result to an alternative stack.

[0265] Statement 3. The method of statement 2, wherein the modular inverse operation script can be further configured to extract the square value of the result from the alternative stack for multiplication via the main stack.

[0266] Statement 4. The method of statement 3, wherein the modular inverse operation script can be further configured to remove the square value from the main stack after the modulus of the result value has been calculated.

[0267] Statement 5. The method of any preceding statement, wherein the modular inverse operation script can be hard-coded to the reduced modular value (p-2).

[0268] Statement 6. The method according to any of the preceding statements, wherein the modular inverse operation script can also be configured to perform a reduction operation on the modular value after a predetermined number of square values ​​have been generated.

[0269] Statement 7. A method according to any of the preceding statements, wherein the method may also include: including the first script in the first blockchain transaction; and submitting the first blockchain transaction to one or more blockchain nodes and / or one or more blockchain users.

[0270] Statement 8. A method according to any of the preceding statements, wherein outputting the first script may include: sending the first script to one or more blockchain users.

[0271] Statement 9. A method according to any of the preceding statements, wherein the first script may include a point addition script, the point addition script being configured to: obtain a first elliptic curve point, a second elliptic curve point and the modulus value; and, output a first target elliptic curve point by performing elliptic curve addition of the first elliptic curve point and the second elliptic curve point, wherein the point addition script includes the modular inverse operation script, and wherein performing the elliptic curve addition includes: calculating a first lambda value, the first lambda value being used to calculate a corresponding x-coordinate and a corresponding y-coordinate of the first target elliptic curve point, wherein calculating the first lambda value includes calculating a first numerator value and a first denominator value, and wherein the point addition script is configured to execute the modular inverse operation script with the first denominator value set to the target integer so as to generate a modular inverse of the first denominator value, and wherein the first lambda value is calculated by multiplying the first numerator value by the modular inverse of the first denominator value.

[0272] Statement 10. A method according to statement 9, wherein the point addition script may include a first branch and a second branch, the first branch being configured to generate the first numerator value and the second numerator value when the first elliptic curve point and the second elliptic curve point are equal, the second branch being configured to generate the first numerator value and the second numerator value when the first elliptic curve point and the second elliptic curve point are not equal, and wherein the modular inverse operation script is executed after executing the first branch or the second branch, so that the modular inverse operation script is included once as part of the point addition script.

[0273] Statement 11. A method according to statement 9 or 10, wherein the first script may include a point subtraction script, and the point subtraction script is configured to: obtain a third elliptic curve point and the modulus value; output the second elliptic curve point to the point addition script, wherein the second elliptic curve point is generated by calculating the modulus of the third elliptic curve point using the modulus value and inverting the result.

[0274] Statement 12. A method according to any of the preceding statements, wherein the first script may include a point doubling script, the point doubling script being configured to: obtain a fourth elliptic curve point and the modulus value; and, output a second target elliptic curve point by doubling the fourth elliptic curve point, wherein the point doubling script includes the modulo inverse operation script, and wherein performing the doubling operation of the fourth elliptic curve point may include: calculating a second λ value, the second λ value being used to calculate a corresponding x-coordinate and a corresponding y-coordinate of the second target elliptic curve point, wherein calculating the second λ value includes calculating a second numerator value and a second denominator value, and wherein the point doubling script is configured to execute the modulo inverse operation script with the second denominator value set to the target integer so as to generate a modulo inverse of the second denominator value, and wherein the second λ value is calculated by multiplying the second numerator value by the modulo inverse of the second denominator value.

[0275] Statement 13. A method according to statement 12, wherein the first script may include a first scalar multiplication (MBS) script, the first MBS script being configured to: obtain a fifth elliptic curve point, the modulus value, and a first scalar value, wherein the first scalar value is represented in binary, and each corresponding bit of the binary representation is associated with a corresponding index; output a third target elliptic curve point by multiplying the fifth elliptic curve point by the scalar value using a double addition algorithm, wherein the first MBS script includes a series of sub-scripts to be executed in sequence, each sub-script is associated with a corresponding index and includes an instance of the point doubling script, wherein A first sub-script in the sub-scripts is configured to double the fifth elliptic curve point using the point doubling script and output a corresponding intermediate result, wherein each consecutive sub-script in the series is configured to double the corresponding intermediate result output by a previous sub-script in the series using the point doubling script, and wherein the first MBS script is configured to generate the third target elliptic curve point by adding the corresponding intermediate results generated by the corresponding sub-scripts with corresponding indices corresponding to the same corresponding indices of the corresponding bits of the binary representation of the first scalar value that are set to 1.

[0276] Statement 14. A method according to statement 9 or any dependent statement thereof, wherein the first script may include a second scalar multiplication (MBS) script, the second MBS script being configured to: obtain a second scalar value, wherein the second scalar value is represented in binary, and each corresponding bit of the binary representation is associated with a corresponding index i; and output a fourth target elliptic curve point by multiplying a corresponding fifth elliptic curve point with the second scalar value, wherein the second MBS script includes a series of sub-scripts to be executed in sequence, each sub-script being associated with a corresponding index i and including an instance of the point addition script, each sub-script including a 2-bit integer corresponding to the corresponding fifth elliptic curve point. i The second MBS script is configured to generate the fourth target elliptic curve point by adding the corresponding elliptic curve points belonging to the corresponding sub-scripts with corresponding indices corresponding to the same corresponding indices of the corresponding bits of the binary representation of the second scalar that are set to 1.

[0277] Statement 15. A method according to any of the preceding statements, wherein the first script includes a set bit determination script, which is configured to determine, for each corresponding bit, whether each corresponding bit of the binary representation of a given scalar is set to 1 by: outputting the integer 1 as an l-byte array in big-endian byte order, where l is the byte length of the scalar; setting the corresponding bit of the l-byte array to 1; and, comparing the corresponding bit of the scalar with the corresponding bit of the l-byte array, wherein if the corresponding bit of the scalar matches the corresponding bit of the l-byte array, determining that the corresponding bit is set to 1.

[0278] Statement 16. A method according to any of the preceding statements, wherein the first script includes a modular reduction script, and the modular reduction script is configured to: obtain a corresponding integer x and a corresponding modular value p; and output the modular reduction of the corresponding integer by calculating (x%p+p)%p, where % is a remainder operator.

[0279] Statement 17. A method according to statement 14 or any of its dependent statements, wherein the first script may include a commitment point, two corresponding instances of the second MBS script, and a corresponding instance of the point addition script, and wherein the first script is configured to: obtain a first candidate scalar and a second candidate scalar, the first candidate scalar and the second candidate scalar being included in an unlocking script of a second blockchain transaction; input the first candidate scalar to the first corresponding instance of the second MBS script to generate a first candidate elliptic curve point; input the second candidate scalar to the second corresponding instance of the second MBS script to generate a second candidate elliptic curve point; input the first candidate elliptic curve point and the second candidate elliptic curve point to the corresponding instance of the point addition script to generate a candidate commitment point; and, verify whether the candidate commitment point is equal to the commitment point.

[0280] Statement 18. A method according to statement 14 or any of its dependent statements, wherein the first script may include a predetermined public key and a predetermined address, and wherein the first script is configured to: obtain a private key and a candidate address, wherein the private key and the candidate address are included in an unlocking script of a second blockchain transaction; input the private key into the second MBS to generate a candidate public key, wherein the corresponding fifth elliptic curve point of the second MBS is a public key generation point; verify whether the candidate public key is equal to the predetermined public key; input the candidate public key and the predetermined public key into an instance of the point addition script to generate a candidate elliptic curve point; hash the candidate elliptic curve point using one or more hash functions to generate a candidate address; and, verify whether the candidate address matches the predetermined address, or whether a portion of the candidate address matches a portion of the predetermined address.

[0281] Statement 19. A computer-implemented method for performing elliptic curve arithmetic using blockchain transactions, wherein the method is executed by a scripting engine and comprises: obtaining a first blockchain transaction, wherein the first blockchain transaction comprises a first script, wherein the first script comprises a modular inverse operation script, and wherein the modular inverse operation script is configured to perform the following steps when executed by the scripting engine: obtaining a target integer (x) and a modulus value (p), wherein the target integer and the modulus value are relatively prime, and the modulus value is a prime number; and, outputting a modular inverse (y) of the target integer, wherein the modular inverse is generated by: generating a sequence of square values, wherein a first square value is equal to the target integer (x), and wherein each subsequent square value in the sequence of square values ​​is generated by replacing the immediately preceding square value with the value of wherein the first script and the second script are executed together to generate the modular inverse of the target integer.

[0282] Statement 20. A computer device, comprising: a memory, the memory comprising one or more memory units; and a processing device, the processing device comprising one or more processing units, wherein the memory stores code configured to run on the processing device, and the code is configured to execute a method according to any one of statements 1 to 19 when running on the processing device.

[0283] Statement 21. A computer program embodied on a computer readable memory and configured to, when executed on one or more processors, perform the method of any one of statements 1 to 19. < / x> < / pa>

Claims

1. A computer-implemented method for enabling elliptic curve arithmetic to be performed using blockchain transactions, wherein the method is performed by a script generator and comprises: Generate a first script for a first blockchain transaction, wherein the first script includes a modular inverse operation script, and wherein the modular inverse operation script is configured to perform the following steps when executed by a script engine: Obtaining a target integer (x) and a modulus value (p), wherein the target integer and the modulus value are relatively prime, and the modulus value is a prime number, and Output the modular inverse (y) of the target integer, where the modular inverse is generated by: generating a sequence of square values, wherein a first square value is equal to the target integer (x), and wherein each subsequent square value in the sequence of square values ​​is generated by multiplying an immediately preceding square value by itself; for each set bit of a reduced modulus value (p-2), wherein the reduced modulus value is an integer less than the modulus value by 2 and represented in binary, including the corresponding square value in the sequence of square values ​​in the result; multiplying the squared values ​​of the results to generate a result value; as well as calculating a modulus of the result value relative to the modulus value (p), wherein the modulus of the result value is output as the modular inverse (y); and The first script is outputted for inclusion in the first blockchain transaction. 2 . The method of claim 1 , wherein the modular inverse operation script is further configured to push the square value of the result to a substitution stack.

3. The method of claim 2, wherein the modular inverse operation script is further configured to extract the square value of the result from the alternative stack for multiplication via the main stack. 4 . The method of claim 3 , wherein the modular inverse operation script is further configured to remove the square value from the main stack after the modulus of the result value has been calculated.

5. A method according to any preceding claim, wherein the modular inverse operation script is hard-coded to the reduced modular value (p-2).

6. A method according to any preceding claim, wherein the modular inverse operation script is further configured to perform a modular reduction operation on the modular value after a predetermined number of square values ​​have been generated.

7. A method according to any preceding claim, comprising: including the first script in the first blockchain transaction; as well as Submitting the first blockchain transaction to one or more blockchain nodes and / or one or more blockchain users.

8. The method of any preceding claim, wherein outputting the first script comprises: The first script is sent to one or more blockchain users.

9. A method according to any preceding claim, wherein the first script comprises a point addition script, the point addition script being configured to: Obtaining a first elliptic curve point, a second elliptic curve point, and the modulus value; and Outputting a first target elliptic curve point by performing elliptic curve addition of the first elliptic curve point and the second elliptic curve point, wherein the point addition script includes the modular inverse operation script, and wherein performing the elliptic curve addition includes: and calculating a first lambda value for calculating a corresponding x-coordinate and a corresponding y-coordinate of the first target elliptic curve point, wherein calculating the first lambda value comprises calculating a first numerator value and a first denominator value, and wherein the point addition script is configured such that the modular inverse operation script is executed with the first denominator value set to the target integer to generate a modular inverse of the first denominator value, and wherein the first lambda value is calculated by multiplying the first numerator value by the modular inverse of the first denominator value.

10. The method of claim 9, wherein the point addition script comprises a first branch and a second branch, the first branch being configured to generate the first numerator value and the second numerator value if the first elliptic curve point and the second elliptic curve point are equal, the second branch being configured to generate the first numerator value and the second numerator value if the first elliptic curve point and the second elliptic curve point are not equal, and wherein the modular inverse operation script is executed after executing the first branch or the second branch, so that the modular inverse operation script is included once as part of the point addition script.

11. The method of claim 9 or 10, wherein the first script comprises a point subtraction script, the point subtraction script being configured to: Obtaining a third elliptic curve point and the modulus value; The second elliptic curve point is output to the point addition script, wherein the second elliptic curve point is generated by calculating a modulus of the third elliptic curve point using the modulus value and inverting the result.

12. A method according to any preceding claim, wherein the first script comprises a point doubling script, the point doubling script being configured to: Obtaining a fourth elliptic curve point and the modulus value; and Outputting a second target elliptic curve point by doubling the fourth elliptic curve point, wherein the point doubling script includes the modular inverse operation script, and wherein performing the doubling operation of the fourth elliptic curve point includes: and calculating a second lambda value for calculating a corresponding x-coordinate and a corresponding y-coordinate of the second target elliptic curve point, wherein calculating the second lambda value comprises calculating a second numerator value and a second denominator value, and wherein the point doubling script is configured such that the modular inverse operation script is executed with the second denominator value set to the target integer to generate a modular inverse of the second denominator value, and wherein the second lambda value is calculated by multiplying the second numerator value by the modular inverse of the second denominator value.

13. The method of claim 12, wherein the first script comprises a first multiplication scalar (MBS) script, the first MBS script being configured to: Obtaining a fifth elliptic curve point, the modulus value, and a first scalar value, wherein the first scalar value is represented in binary, each corresponding bit of the binary representation being associated with a corresponding index; A third target elliptic curve point is output by multiplying the fifth elliptic curve point by the scalar value using a double addition algorithm, wherein the first MBS script includes a series of sub-scripts to be executed in sequence, each sub-script being associated with a corresponding index and including an instance of the point doubling script, wherein a first sub-script in the sub-scripts is configured to double the fifth elliptic curve point using the point doubling script and output a corresponding intermediate result, wherein each consecutive sub-script in the series is configured to double the corresponding intermediate result output by a previous sub-script in the series using the point doubling script, and wherein the first MBS script is configured to generate the third target elliptic curve point by adding the corresponding intermediate results generated by the corresponding sub-scripts having corresponding indices corresponding to the same corresponding indices of the corresponding bits of the binary representation of the first scalar value that are set to 1.

14. The method of claim 9 or any claim dependent thereon, wherein the first script comprises a second multiplication by scalar (MBS) script, the second MBS script being configured to: obtaining a second scalar value, wherein the second scalar value is represented in binary, each corresponding bit of the binary representation being associated with a corresponding index i; and outputting a fourth target elliptic curve point by multiplying the corresponding fifth elliptic curve point by the second scalar value, wherein the second MBS script comprises a series of sub-scripts to be executed in sequence, each sub-script being associated with a corresponding index i and comprising an instance of the point addition script, each sub-script comprising a 2-scalar value corresponding to the corresponding fifth elliptic curve point i The second MBS script is configured to generate the fourth target elliptic curve point by adding the corresponding elliptic curve points belonging to the corresponding sub-scripts with corresponding indices corresponding to the same corresponding indices of the corresponding bits of the binary representation of the second scalar that are set to 1.

15. A method according to any preceding claim, wherein the first script comprises a set bit determination script configured to determine, for each respective bit, whether each respective bit of a binary representation of a given scalar is set to 1 by: Output the integer 1 as an array of l bytes in big-endian byte order, where l is the length in bytes of the scalar; Setting the corresponding bit of the 1-byte array to 1; and The corresponding bit of the scalar is compared with the corresponding bit of the 1-byte array, wherein if the corresponding bit of the scalar matches the corresponding bit of the 1-byte array, it is determined that the corresponding bit is set to 1.

16. A method according to any preceding claim, wherein the first script comprises a modular reduction script, the modular reduction script being configured to: Get the corresponding integer x and the corresponding modulus value p; and The modular reduction of the corresponding integers is output by computing (x%p+p)%p, where % is the remainder operator.

17. The method of claim 14 or any claim dependent therefrom, wherein the first script comprises commitment points, two respective instances of the second MBS script and a respective instance of the point addition script, and wherein the first script is configured to: Obtain a first candidate scalar and a second candidate scalar, wherein the first candidate scalar and the second candidate scalar are included in an unlocking script of a second blockchain transaction; inputting the first candidate scalar into a first corresponding instance of the second MBS script to generate a first candidate elliptic curve point; inputting the second candidate scalar into a second corresponding instance of the second MBS script to generate a second candidate elliptic curve point; inputting the first candidate elliptic curve point and the second candidate elliptic curve point into the respective instances of the point addition script to generate a candidate commitment point; as well as Verify whether the candidate commitment point is equal to the commitment point.

18. The method of claim 14 or any claim dependent therefrom, wherein the first script comprises a predetermined public key and a predetermined address, and wherein the first script is configured to: Obtaining a private key and a candidate address, wherein the private key and the candidate address are included in an unlocking script of a second blockchain transaction; inputting the private key into the second MBS to generate a candidate public key, wherein the corresponding fifth elliptic curve point of the second MBS is a public key generation point; Verifying whether the candidate public key is equal to the predetermined public key; inputting the candidate public key and the predetermined public key into an instance of the point addition script to generate a candidate elliptic curve point; hashing the candidate elliptic curve point using one or more hash functions to generate a candidate address; as well as Verify whether the candidate address matches the predetermined address, or whether a portion of the candidate address matches a portion of the predetermined address.

19. A computer-implemented method for performing elliptic curve arithmetic using blockchain transactions, wherein the method is performed by a scripting engine and comprises: Obtain a first blockchain transaction, wherein the first blockchain transaction includes a first script, wherein the first script includes a modular inverse operation script, and wherein the modular inverse operation script is configured to perform the following steps when executed by a script engine: Obtaining a target integer (x) and a modulus value (p), wherein the target integer and the modulus value are relatively prime, and the modulus value is a prime number, and Output the modular inverse (y) of the target integer, where the modular inverse is generated by: generating a sequence of square values, wherein a first square value is equal to the target integer (x), and wherein each subsequent square value in the sequence of square values ​​is generated by multiplying an immediately preceding square value by itself; for each set bit of a reduced modulus value (p-2), wherein the reduced modulus value is an integer less than the modulus value by 2 and represented in binary, including the corresponding square value in the sequence of square values ​​in the result; multiplying the squared values ​​of the results to generate a result value; as well as calculating a modulus of the result value relative to the modulus value (p), wherein the modulus of the result value is output as the modulus inverse (y); as well as Obtaining a second blockchain transaction, wherein the second blockchain transaction includes a second script, wherein the second script includes the target integer (x) and the modulus value (p); And, executing the first script and the second script together to generate the modular inverse of the target integer.

20. A computer device, comprising: a memory, the memory comprising one or more memory units; as well as A processing device comprising one or more processing units, wherein the memory stores a code arranged to be executed on the processing device, the code being configured to execute the method according to any one of claims 1 to 19 when executed on the processing device.

21. A computer program embodied on a computer readable memory and configured to, when run on one or more processors, perform the method according to any one of claims 1 to 19.