Transaction analysis method in blockchain system and blockchain node
By dividing the smart contract state into multiple data objects and setting up multiple APIs, the problem of low efficiency in transaction conflict detection in blockchain systems is solved, and fast and efficient read-write conflict detection is achieved.
Patent Information
- Application Number
- CN202510125352.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-26
- Publication Date
- 2026-01-09
- Estimated Expiration
- 2045-01-26
AI Technical Summary
In existing blockchain systems, the efficiency of conflict detection for multiple transactions is low, especially for smart contract transactions, which have long pre-execution times, making it difficult to quickly complete read-write conflict detection.
The contract state of a smart contract is divided into multiple data objects and stored in different locations in the data storage system. Multiple APIs are set up to access these data objects. By analyzing the calls to the target function and APIs of the transaction pair, it can be determined whether there are read-write conflicts between transactions.
It improves the efficiency of transaction conflict detection, reduces pre-execution time, and enables fast and efficient detection of multiple transaction conflicts.
Smart Images

Figure CN120047141B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present specification belong to the technical field of computer technology, and particularly relate to a transaction analysis method in a blockchain system and a blockchain node. BACKGROUND
[0002] A blockchain system is a new application mode of distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm and other computer technologies. In the blockchain system, data blocks are combined into a chain-type data structure in a sequential manner according to time sequence, and a distributed ledger is ensured to be non-tamperable and non-forgable by means of cryptography. Due to the characteristics of decentralization, information non-tamperability and autonomy, the blockchain system has been paid more and more attention and applied.
[0003] In order to improve the transaction execution efficiency in the blockchain system, a plurality of transactions which are expected to be executed and have an arrangement order can be pre-executed. The pre-execution result of a single transaction includes the key of a state variable which needs to be accessed by the blockchain system due to the execution of the transaction, and the access type corresponding to the state variable, wherein the access type includes reading and / or writing. For any transaction, the pre-execution result of the transaction can be used to determine whether the transaction and other transactions in the blockchain system have read-write conflict; for each transaction having read-write conflict, it needs to be executed in series according to the arrangement order, and for each transaction not having read-write conflict, it can be executed in parallel to improve the transaction execution efficiency.
[0004] It is desirable to have a new scheme to facilitate more efficient conflict detection for a plurality of transactions. SUMMARY
[0005] The purpose of the present application is to provide a transaction analysis method in a blockchain system and a blockchain node.
[0006] In a first aspect, a transaction analysis method in a blockchain system is provided. The blockchain system has a smart contract deployed therein. A contract state of the smart contract is divided into a plurality of data objects. The plurality of data objects have different storage locations in a data storage system. The blockchain system includes a plurality of application programming interfaces (APIs) for accessing the plurality of data objects. The method includes determining a target function in the smart contract expected to be called by a first transaction; determining a plurality of target APIs called in the target function; and determining an analysis result according to the first transaction, the plurality of target APIs, and an access type corresponding to each of the plurality of target APIs. The analysis result is used to determine whether a read-write conflict exists between the first transaction and other transactions. The analysis result includes a plurality of grouping keys and an access type corresponding to each of the plurality of grouping keys. The plurality of grouping keys include a contract address of the smart contract and identification information of a plurality of data objects accessed by the first transaction via the plurality of target APIs. The access type corresponding to the contract address is read.
[0007] In a second aspect, a blockchain node in a blockchain system is provided. The blockchain system has a smart contract deployed therein. A contract state of the smart contract is divided into a plurality of data objects. The plurality of data objects have different storage locations in a data storage system. The blockchain system includes a plurality of APIs for accessing the plurality of data objects. The blockchain node includes a function determination unit configured to determine a target function in the smart contract expected to be called by a first transaction; an interface determination unit configured to determine a plurality of target APIs called in the target function; and an analysis processing unit configured to determine an analysis result according to the first transaction, the plurality of target APIs, and an access type corresponding to each of the plurality of target APIs. The analysis result is used to determine whether a read-write conflict exists between the first transaction and other transactions. The analysis result includes a plurality of grouping keys and an access type corresponding to each of the plurality of grouping keys. The plurality of grouping keys include a contract address of the smart contract and identification information of a plurality of data objects accessed by the first transaction via the plurality of target APIs. The access type corresponding to the contract address is read.
[0008] In a third aspect, a computer-readable storage medium is provided. The computer-readable storage medium has a computer program stored thereon. When the computer program is executed in a computing device, the computing device performs the method in the first aspect.
[0009] In the technical solution provided by the embodiments of the present specification, the contract state of the smart contract is divided into a plurality of data objects and stored in different storage locations in the data storage system, and a plurality of APIs for accessing the plurality of data objects are set in the blockchain system; for any first transaction for calling the smart contract, only the specific calling condition of the plurality of APIs in a certain target function included in the smart contract indicated by the first transaction needs to be analyzed, and the access condition of the plurality of data objects by the blockchain system in the process of actually executing the first transaction, i.e., in the process of executing the target function according to the first transaction, can be obtained, so that an analysis result that can be used to judge whether the first transaction and other transactions have read-write conflicts is obtained, and in this process, the first transaction does not need to be pre-executed for too much time, which is beneficial to more quickly and efficiently complete the conflict detection of a plurality of transactions containing the first transaction and having an arrangement order. BRIEF DESCRIPTION OF DRAWINGS
[0010] In order to more clearly illustrate the technical solutions in the embodiments of the present specification, the drawings needed in the embodiment description will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments described in the present specification, and other drawings can be obtained by those skilled in the art without creative labor.
[0011] Figure 1 An architecture diagram of a blockchain system exemplarily provided in the embodiments of the present specification;
[0012] Figure 2 A flowchart of a transaction analysis method in a blockchain system provided in the embodiments of the present specification;
[0013] Figure 3 A structural schematic diagram of a blockchain node in a blockchain system provided in the embodiments of the present specification. DETAILED DESCRIPTION
[0014] In order to make those skilled in the art better understand the technical solutions in the present specification, the technical solutions in the embodiments of the present specification will be described clearly and completely below with reference to the drawings. Obviously, the described embodiments are only some of the embodiments of the present specification, not all. Based on the embodiments in the present specification, all other embodiments obtained by those skilled in the art without creative labor should be within the scope of protection of the present specification.
[0015] Figure 1 An architecture diagram of a blockchain system exemplarily provided in the embodiments of the present specification. The blockchain system can include N blockchain nodes, wherein Figure 1Eight blockchain nodes, Node 1-Node 8, are shown as examples. The connection lines between the nodes schematically represent the connections between the nodes, and the aforementioned connections are used to support the transmission of data between different nodes.
[0016] The blockchain system can provide the function of a smart contract. The smart contract in the blockchain system is a contract that can be triggered to execute by a transaction. The smart contract can be defined in the form of contract code. Invoking the smart contract in the blockchain system is to initiate a transaction pointing to the contract address of the smart contract, so that each node in the blockchain system runs the corresponding contract code in a distributed manner.
[0017] In various blockchain systems that introduce smart contracts, accounts can generally be divided into two types:
[0018] Contract account (CA): mainly used to store the contract code of the corresponding smart contract and the value of the state variable in the smart contract, and generally can only be activated by calling an external account;
[0019] Externally owned account (EOA): an account registered by an external user in the blockchain system.
[0020] The design of external accounts and contract accounts is actually a mapping of account addresses to account states. The account state of any account generally includes fields such as nonce, balance, storageRoot, code, and / or codeHash. nonce and balance exist in both external accounts and contract accounts, and code, codeHash, and storageRoot attributes are generally only valid on contract accounts.
[0021] The contract account is used to store the contract state of the smart contract. After the smart contract is deployed in the blockchain system, a corresponding contract account will be generated. This contract account will generally have some states, which are defined by state variables in the smart contract and generate new values when the smart contract is created and executed. The smart contract generally refers to a contract defined in digital form in a blockchain environment that can automatically execute clauses. When a clause in the contract is triggered (the execution condition is met), the code can be automatically executed. The contract state of the smart contract contains the values of multiple state variables; in specific technical scenarios, the values of the state variables are generally stored in the data storage system in the form of key-value pairs. The key of any state variable can be determined based on the declaration position of the state variable in the contract code during the compilation or execution of the smart contract, or based on the variable name of the state variable and / or a number of previous state variables in the smart contract that have a nested relationship with the state variable.
[0022] In order to improve the transaction execution efficiency in the blockchain system, a plurality of transactions which are expected to be executed and have an arrangement order can be pre-executed, and the pre-execution result of a single transaction includes the key of a state variable which needs to be accessed by the blockchain system due to the execution of the transaction, and the access type corresponding to the state variable, wherein the access type includes reading and / or writing across domains. For any transaction, the pre-execution result of the transaction can be used to determine whether the transaction has read-write conflict with other transactions in the blockchain system; for each transaction which has read-write conflict, it needs to be executed in series according to the arrangement order, and for each transaction which does not have read-write conflict, it can be executed in parallel to improve the transaction execution efficiency.
[0023] For a single transaction, the time spent on pre-executing the transaction is comparable to the time spent on actually executing the transaction; especially for the transaction which calls the smart contract, the time spent on pre-executing the transaction is usually relatively large. In addition, parallel execution is usually required for pre-executing a plurality of transactions to improve the pre-execution efficiency of the transactions. If there are many transactions which have read-write conflict in the plurality of transactions which are expected to be executed, the correct pre-execution result of the plurality of transactions can be obtained through a plurality of rounds of parallel execution process, which results in that the time spent on pre-executing the plurality of transactions is close to or even greater than the time spent on serially executing the plurality of transactions, that is, a lot of time is needed to obtain the correct pre-execution result of each transaction, which means that it is difficult to quickly complete the conflict detection of the plurality of transactions.
[0024] In the embodiments of the present specification, a transaction analysis method in a blockchain system and a blockchain node are provided. The contract state of a smart contract is divided into a plurality of data objects, the plurality of data objects have different storage locations in the related data storage system, and the blockchain system includes a plurality of APIs for accessing the plurality of data objects; when read-write analysis of a first transaction is needed, a target function in a smart contract which is expected to be called by the first transaction can be determined first; then a plurality of target APIs called in the target function are determined; finally, an analysis result is determined according to the first transaction, the plurality of target APIs, and the access types corresponding to the plurality of target APIs, the analysis result can be used to determine whether the first transaction has read-write conflict with other transactions, the analysis result includes a plurality of grouping keys and the access types corresponding to the plurality of grouping keys, the plurality of grouping keys include the contract address of the smart contract called by the first transaction, and the identification information of a plurality of data objects accessed by the first transaction through the plurality of target APIs, and the access type corresponding to the contract address of the smart contract called by the first transaction is reading.
[0025] Thus, by dividing the contract state of the smart contract into a plurality of data objects, storing the plurality of data objects in different storage locations in the data storage system, and pre-providing a plurality of APIs for accessing the plurality of data objects in the blockchain system, for any first transaction for calling the smart contract, only the specific calling of the plurality of APIs in a certain target function included in the smart contract indicated by the first transaction needs to be analyzed, and the access of the plurality of data objects by the blockchain system in the process of actually executing the first transaction, i.e., in the process of executing the target function according to the first transaction, can be obtained, so as to obtain an analysis result that can be used to determine whether the first transaction and other transactions have read-write conflicts. In this process, no excessive time is spent on pre-execution of the first transaction, which is beneficial to more quickly and efficiently complete conflict detection of a plurality of transactions containing the first transaction and having an arrangement order.
[0026] In addition, the identification information of the data object is used as a grouping key, which is separated from the key (i.e., the storage key) of the state variable, which can improve the flexibility of smart contract programming and facilitate the organization of more rich business semantics and state models in the smart contract.
[0027] In addition, for different transactions, the analysis processes of different transactions are irrelevant to each other; therefore, the analysis processes of multiple transactions can be executed in parallel in the embodiments of the present specification, so as to quickly obtain the analysis results corresponding to the multiple transactions respectively.
[0028] In the blockchain system, the data objects can also be divided into object categories. For any target category in the plurality of object categories that can exist, a first API and a second API corresponding to the target category and allowed to be called by the smart contract can be set. It should be particularly noted that the first API is used to read the value of the state variable from the data object belonging to the target category under the calling of the smart contract, and the corresponding access type is "write"; the second API is used to write the value of the state variable into the data object belonging to the target category under the calling of the smart contract, and the corresponding access type is "read".
[0029] For example, based on whether the state variable in the data object is associated with a user account registered in the blockchain system, the data object can be divided into two object categories, a contract state container (CSC) and a contract shared object (CSO). Herein, the CSC is expressed as a first category, and the CSO is expressed as a second category.
[0030] The first API and the second API of the CSC and the CSO can be set as follows:
[0031] template <typename T = void, typename... Args>
[0032] void set_private(const Account& to, const std::string& key, T& value);
[0033] / / set_private() is the second API corresponding to CSC, in its input parameters, the parameter name const Account& to is used to represent the account address of the user account / external account, and when set_private() is called, the parameter value of const Account& to passed in can be used to determine the identification information of a certain data object belonging to CSC; const std::string& key is used to represent the key of the accessed state variable, and T& value is used to represent the value of a certain state variable to be stored in the data storage system template <typename T = void, typename... Args>
[0034] T get_private(const Account& to, const std::string& key);
[0035] / / get_private() is the first API corresponding to ASO, in its input parameters, the parameter name const Account& to is used to represent the account address of the user account / external account, and when set_private() is called, the parameter value of const Account& to passed in can be used to determine the identification information of a certain data object belonging to CSC; const std::string& key is used to represent the key of the accessed state variable; the return value is the value of the accessed state variable
[0036] template <typename T = void, typename... Args>
[0037] void set_shared(const std::string& root, const std::string& key, T& value);
[0038] / / set_shared() is the second API corresponding to the CSO, in the input parameters, the parameter value of const std::string&root can be used to determine the identification information of a certain data object belonging to the CSO, const std::string&key is used to represent the key of the accessed state variable, and T&value is used to represent the value of a certain state variable to be stored in the data storage system
[0039] template<typename T=void,typename...Args>
[0040] T&value get_shared(const std::string&root,const std::string&key);
[0041] / / get_shared() is the first API corresponding to the CSO, in the input parameters, the parameter value of const std::string&root can be used to determine the identification information of a data object belonging to the CSO, const std::string&key is used to represent the key of the accessed state variable, and the return value is the value of the accessed state variable
[0042] For some object classes, such as the CSO in the foregoing example, other special APIs that can be used to implement predetermined transactions can also be set in addition to the first API and the second API, for example, the third API in the following example can also be set for the CSO:
[0043] bool value has_shared(const std::string&root,const std::string&key);
[0044] / / has_shared() is the third API corresponding to the CSO, in the input parameters, the parameter value of const std::string&root can be used to determine the identification information of a data object belonging to the CSO, and const std::string&key is used to represent the key of the accessed state variable; the third API is used to query whether a certain state variable exists in the data object belonging to the CSO; it can be understood that the access type corresponding to the third API is "read".
[0045] For any first data object belonging to the CSC, each state variable included in the first data object can be associated with the same first account; for any two different first data objects belonging to the CSC, each includes state variables associated with different user accounts. Correspondingly, the identification information of the first data object can be determined based on the account address of the associated user account, for example, based on the contract address of the smart contract to which the first data object belongs and the account address of the associated user account.
[0046] For any second data object belonging to the CSO, the second data object can be predefined by the contract code of the smart contract; that is, one or more second data objects belonging to the CSO can be defined in the contract code of the smart contract. Correspondingly, the identification information of the second data object can also be predefined by the contract code of the smart contract.
[0047] For example, user accounts Alice and Bob registered in the blockchain system can each hold a certain token such as Token1 issued by smart contract Contract1, meaning that in the contract state of smart contract Contract1, the balance information of user accounts Alice and Bob holding Token1 can be recorded by state variables such as M1 and M2, in addition to the transaction frequency of user accounts Alice and Bob trading Token1 recorded by state variables M3 and M4, and the circulation limit of Token1 issued by user accounts Alice and Bob recorded by state variable M5. In this case, state variables M1 and M3 can be divided into a data object Alice.Contract1 associated with user account Alice and belonging to the CSC, state variables M2 and M4 can be divided into a data object Bob.Contract1 associated with user account Bob and belonging to the CSC, and state variable M5 can be divided into a data object Root1.Contract1 belonging to the CSO.
[0048] A single data object can include values of multiple state variables. In order to facilitate quick access to state variables, a single data object can use a tree structure to organize the values of the multiple state variables included in the data object. A leaf node of the tree structure stores the value of a state variable, while the directed path between the root node and the parent node of a leaf node stores the key of the state variable corresponding to the value stored in the leaf node, and the identification information of the data object is stored in the root node.
[0049] In addition to the plurality of APIs that can be set in the blockchain system for accessing the data objects, other APIs can also be set for reading data information from the related transactions under the invocation of the smart contract. For example, Account get_account() can also be set in the blockchain system for reading the account address corresponding to the user account initiating the transaction from the transaction for invoking the smart contract under the invocation of a certain smart contract. Account get_contract() can also be set for reading the contract address of the smart contract invoked by the transaction under the invocation of a certain smart contract.
[0050] The plurality of data objects included in the smart contract have different storage locations in the data storage system. For example, the data objects belonging to the CSC are stored under the associated user account; the data objects belonging to the CSO are still stored under the contract account. Continuing the foregoing example: the data object Alice.contract1 can be stored under the associated user account Alice, the data object Bob.Contract1 can be stored under the associated user account Bob, and the data object Root1.Contract1 can be stored under the contract account of the smart contract Contract1.
[0051] The foregoing exemplary introduces how to divide the data objects of the contract state of the smart contract, and exemplary introduces how to set the API allowed to be invoked by the smart contract in the blockchain system. The following exemplary describes the analysis of the read-write situation of the contract state of the transaction for invoking the smart contract in the blockchain system when conflict detection is required for a plurality of transactions.
[0052] Figure 2 A flowchart of a transaction analysis method in a blockchain system provided in an embodiment of the present specification. The blockchain system has a smart contract deployed therein, the contract state of the smart contract is divided into a plurality of data objects, and the plurality of data objects have different storage locations in the data storage system; the blockchain system, more specifically, in the blockchain nodes included in the blockchain system, a plurality of APIs allowed to be invoked by the smart contract are pre-set, and the plurality of APIs can access the plurality of data objects included in the contract state of the smart contract under the invocation of the smart contract.
[0053] Referring to Figure 2 The method can include, but is not limited to, some or all of the following steps S201-S209.
[0054] Step S201, determining that the first transaction indicates a target function in the invoked smart contract.
[0055] For a first transaction for invoking a smart contract, the form field of the transaction contains an account address corresponding to a user account initiating the transaction, the to field contains a contract address corresponding to the invoked smart contract, and the data field contains invocation parameters, such as a function identifier of a target function invoked in the smart contract and input parameters of the target function, and the like.
[0056] Take the following example of the pseudo code of the smart contract Contract1 as an example:
[0057] / / ********************** / /
[0058] class MyContract{
[0059] / / Deposit() is used to increase the balance of a certain token, such as Token1, held by a user account
[0060] void Deposit(uint64_t value){
[0061] auto balance=get_private<uint64_t>(get_account(),"balance");
[0062] set_private(get_account(),"balance",balance+value);
[0063] }
[0064] / / Withdraw() is used to increase the balance of a certain token, such as Token1, held by a user account
[0065] void Withdraw(uint64_t value){
[0066] auto balance=get_private<uint64_t>(get_account(),"balance");
[0067] set_private(get_account(),"balance",balance-value);
[0068] }
[0069] / / Transfer() is used to transfer a certain token between user accounts, biz_id is the transaction identifier of the related transaction; if the transaction corresponding to biz_id has occurred (for example, judged by idempotent operation), it fails, if it has not occurred, the balance change operation of the corresponding account is performed, and it is recorded that the transaction has occurred
[0070] void Transfer(const std::string&biz_id, const Account&to, uint64_t value) {
[0071] require(!has_shared("root1", biz_id, "already exsit"), );
[0072] co_call(get_account(), get_contract(), "Withdraw", value);
[0073] co_call(to, get_contract(), "Deposit", value);
[0074] set_shared("root1", biz_id, "");
[0075] }
[0076] / / GetBalance() is used to query the balance of a certain token, for example Token1, held by a user account
[0077] uint64_t GetBalance() {
[0078] return get_private<uint64_t>(get_account(), "balance");
[0079] }
[0080] }.
[0081] / / ********************** / /
[0082] The Contract1 in the above example includes functions Deposit(), Withdraw(), Transfer(), and GetBalance().
[0083] Based on the smart contract Contract1 of the above example, when a user account, for example, Alice, expects to transfer a certain token, for example, Token1, issued by Contract1 to another user account, for example, Bob, and the transfer share is, for example, 100, a transaction, for example, transaction Tx1 = Alice.Contract1.Transfer(Bob, 100), for calling Contract1 can be initiated by user account Alice. The from field of Tx1 includes the account address of Alice, the to field includes the contract address of Contract1, and the data field can include the function identifier of the target function Transfer() and the input parameter of Transfer(). The input parameter of Transfer() can specifically include the account address of user account Bob and the transfer share 100 of Token1 expected to be transferred. Correspondingly, the function identifier of Transfer() can be obtained from the data field of transaction Tx1, and the contract address of Contract1 can be read from the to field of transaction Tx1. Then, based on the contract address of Contract1 and the function identifier of Transfer(), the function Transfer() in Contract1 is determined as the target function expected to be called by transaction Tx1.
[0084] Based on the smart contract Contract1 of the above example, when a user account, for example, Dave, expects to subscribe a certain token, for example, Token1, issued by Contract1, and the subscription share is, for example, 100, a transaction, for example, transaction Tx2 = Dave.Contract1.Deposit(100), for calling Contract1 can be initiated by user account Dave. The from field of transaction Tx2 includes the account address of Dave, the to field includes the contract address of Contract1, and the data field can include the function identifier of the target function Deposit() and the input parameter of Deposit(). The input parameter of Deposit() can include the subscription share 100 of Token1 expected to be subscribed by user account Dave. Correspondingly, the function identifier of Deposit() can be obtained from the data field of transaction Tx2, and the contract address of Contract1 can be read from the to field of transaction Tx2. Based on the contract address of Contract1 and the function identifier of Deposit(), the function Deposit() in Contract1 is determined as the target function expected to be called by transaction Tx2.
[0085] In step S203, a plurality of target APIs called in the target function are determined.
[0086] By analyzing the called target function, it can be determined that the target function calls several target APIs.
[0087] In continuation of the foregoing example, when the target function is Transfer() included in the smart contract Contract1, it can be learned through analysis of Transfer() that the target APIs called in Transfer() include: has_shared() and set_shared called directly by Transfer(), get_private() and set_private() called indirectly by Transfer() through co_call(), Depost(), and get_private() and set_private() called indirectly by Transfer() through co_call(), Withdraw().
[0088] In continuation of the foregoing example, when the target function is Deposit() included in the smart contract Contract1, it can be learned through analysis of Deposit() that the target APIs called in Deposit() include: get_private() and set_private().
[0089] In step S205, according to the first transaction, the several target APIs, and the access types corresponding to the several target APIs respectively, the analysis result of the first transaction is determined, the analysis result of the first transaction is used to judge whether the first transaction and other transactions exist read-write conflict, the analysis result of the first transaction includes a plurality of grouping keys and the access types corresponding to the plurality of grouping keys respectively, the plurality of grouping keys include the contract address of the smart contract, and the first transaction indicates the identification information of the several data objects accessed through the several target APIs, the access type corresponding to the contract address is read.
[0090] The contract address of the called smart contract can be obtained from the first transaction, the contract address is determined as a grouping key, and the access type corresponding to the contract address is set to read; in continuation of the foregoing example, the contract address of the smart contract Contract1 can be obtained from the to field of the transaction Tx1 or the transaction Tx2, and the access type corresponding to the contract address is set to read. In addition, the identification information of the several data objects accessed by the first transaction through the several target APIs can be taken as the grouping keys in the analysis result and set the access types through part or all of the following steps 2511 to step S2055.
[0091] In step S2051, the input parameters of the target API when the target function is executed according to the first transaction are determined.
[0092] For a single target API, in the execution of the target function according to the first transaction, there can be some input parameters of the target API from the first transaction, and there can also be some input parameters of the target API provided by the target function; that is, both the input parameters of the target API from the first transaction and the input parameters of the target API from the target function are possible.
[0093] In the foregoing example, when the first transaction is transaction Tx1, by analyzing the calling conditions of Transfer() on several target APIs, it can be determined that in the execution of Transfer() according to transaction Tx1, the input parameters of the several target APIs are respectively as follows.
[0094] The input parameters of has_shared() include "root1" and transaction identifier "biz_id", both of which are obtained from Transfer();
[0095] The input parameters of set_shared() include "root1" and transaction identifier "biz_id", both of which are obtained from Transfer();
[0096] The input parameters of get_private() include: in the case where Transfer() indirectly calls get_private() through co_call(), Withdraw(), the input parameters include the account address of Alice and "balance", where "balance" refers to the key of the state variable used to represent the balance of a certain token held by Alice; in the case where Transfer() indirectly calls get_private() through co_call(), Deposit(), the input parameters include the account address of Bob and "balance", where "balance" refers to the key of the state variable used to represent the balance of a certain token held by Bob; wherein the account addresses of Alice and Bob are from transaction Tx1;
[0097] The input parameters of set_private() include: the account address of Alice, "balance", and balance-value in the case that Transfer() indirectly calls set_private() through co_call(), Withdraw(); the account address of Bob, "balance", and balance+value in the case that Transfer() indirectly calls set_private() through co_call(), Deposit(); wherein the value of value in balance-value and balance+value is from transaction Tx1, i.e., the value of value is 100.
[0098] Continuing the foregoing example, when the first transaction is transaction Tx2, by analyzing the calls of Deposit() to the target APIs, it can be determined that the input parameters of each of the target APIs are determined when executing Deposit() according to transaction Tx2.
[0099] The input parameters of get_private() include: the account address of user account Dave and "balance";
[0100] The input parameters of set_private() include: the account address of user account Dave, "balance", and balance+value.
[0101] In step S2053, the identification information of the data object accessed by the target API according to the first transaction is determined according to the input parameters, and the identification information is determined as the grouping key.
[0102] Continuing the foregoing example, when the first transaction is transaction Tx1:
[0103] For the input parameters of has_shared(), the identification information such as "Root1.Contract1" can be determined according to "root1";
[0104] For the input parameters of set_shared(), the identification information such as "Root1.Contract1" can be determined according to "root1";
[0105] For the input parameters of get_private(), the identification information such as Alice.Contract1 associated with Alice can be determined according to the account address of Alice, and the identification information such as Bob.Contract1 associated with Bob can be determined according to the account address of Bob;
[0106] Similar to the input parameters of get_private(), for the input parameters of set_private(), the identification information of the data object associated with Alice, such as Alice.Contract1, can be determined according to the account address of Alice, and the identification information of the data object associated with Bob, such as Bob.Contract1, can be determined according to the account address of Bob.
[0107] Continuing the foregoing example, when the first transaction is transaction Tx2, the following can be obtained:
[0108] For the input parameters of get_private(), the identification information of the data object associated with Dave, such as Dave.Contract1, can be determined according to the account address of account Dave.
[0109] Similar to the input parameters of get_private(), for the input parameters of set_private(), the identification information of the data object associated with Dave, such as Dave.Contract1, can be determined according to the account address of account Dave.
[0110] In step S2055, the access type corresponding to the identification information is set to the access type corresponding to the target API.
[0111] Continuing the foregoing example, when the first transaction is transaction Tx1, the following can be obtained:
[0112] The read-write type corresponding to has_shared() is "read", and the access type corresponding to set_shared() is "write". For the identification information determined according to the input parameters of has_shared() and set_shared(), such as Root1.Contract1, the access type corresponding to the identification information Root1.Contract1 can be set to "read" and "write";
[0113] The access type corresponding to get_private() is "read", and the access type corresponding to set_private() is "write". For the identification information determined according to the input parameters of get_private() and set_private(), such as Alice.Contract1 and Bob.Contract1, the access types corresponding to Alice.Contract1 and Bob.Contract1 can be set to "read" and "write".
[0114] Finally, for the foregoing example of transaction Tx1, the following analysis results shown in Table 1 can be obtained:
[0115]
[0116]
[0117] Table 1
[0118] In the foregoing example, when the first transaction is transaction Tx2, the following can be obtained.
[0119] The access type corresponding to get_private() is "read", and the access type corresponding to set_private() is "write". For the identification information determined according to the input parameters of get_private() and set_private(), for example, Dave.Contractl, the access types corresponding thereto can be set to "read" and "write". Finally, the analysis result of transaction Tx2 can be as shown in Table 2.
[0120]
[0121] Table 2
[0122] It should be particularly noted that the foregoing steps S2051-S2055 are merely exemplary. For example, each function included in the smart contract Contractl can be pre-marked with a target parameter that can be used to determine the identification information of a data object. For each API that takes the target parameter as an input parameter, the access type corresponding to the API is set to the access type corresponding to the target parameter. In this way, when the target function is executed according to the first transaction, the parameter values corresponding to the target parameters in the target function can be determined first. Then, the identification information corresponding to each data object that can be accessed is determined according to the parameter values corresponding to the target parameters, respectively. Finally, the access types corresponding to the identification information as the grouping keys are determined according to the access types corresponding to the target parameters, respectively.
[0123] The foregoing steps S201-S205 describe in detail the process of analyzing the first transaction to obtain an analysis result. The obtained analysis result will be used to detect whether there is a read-write conflict between the first transaction and other transactions. For example, the blockchain system can need to perform conflict detection on multiple transactions belonging to the same block according to the arrangement order of the multiple transactions before actually executing the multiple transactions. Finally, the transactions that have a read-write conflict are executed serially, and the transactions that do not have a read-write conflict are executed in parallel. On the basis of the foregoing steps S201-S205, the following steps S207 and S209 can also be performed.
[0124] Step S207, determine whether there is a same target grouping key in the analysis result of the first transaction and the analysis result of the second transaction, the arrangement position of the second transaction in the plurality of transactions is after the first transaction.
[0125] The analysis result of the second transaction can be obtained through a process similar to the foregoing steps S201-S205.
[0126] Taking the first transaction as the transaction Tx1 in the foregoing example and the second transaction as the transaction Tx2 in the foregoing example as an example, it can be found through comparing the analysis result of the transaction Tx1 in the foregoing example and the analysis result of the transaction Tx2 that there is a same target grouping key “Contract1 contract address” in the analysis result of the transaction Tx1 and the analysis result of the transaction Tx2.
[0127] If there is no same target grouping key in the analysis result of the first transaction and the analysis result of the second transaction, it indicates that there is no read-write conflict between the first transaction and the second transaction. If there is a same target grouping key in the analysis result of the first transaction and the analysis result of the second transaction, the following step S209 can be continued to execute, and when the access type corresponding to the target grouping key in the analysis result of the first transaction includes writing, it is determined that there is a read-write conflict between the first transaction and the second transaction.
[0128] In the foregoing steps S201-S209, the process of analyzing the transaction for calling the smart contract to obtain the analysis result is mainly described. For other transactions such as a transfer transaction, the account addresses contained in the from field and the to field of the transfer transaction can be directly taken as the grouping keys, and the access types corresponding thereto are set to “read” and “write”.
[0129] Based on the same concept as the foregoing method embodiment, the present specification embodiment also provides a blockchain node 300 in a blockchain system, wherein the blockchain system is deployed with a smart contract, a contract state of the smart contract is divided into a plurality of data objects, the plurality of data objects have different storage locations in a data storage system, and the blockchain system includes a plurality of APIs for accessing the plurality of data objects. Referring to Figure 3As shown, the blockchain node 300 comprises: a function determining unit 301 configured to determine a target function in the smart contract expected to be invoked by a first transaction; an interface determining unit 303 configured to determine a plurality of target APIs invoked in the target function; and an analysis processing unit 305 configured to determine an analysis result according to the first transaction, the plurality of target APIs, and an access type corresponding to each of the plurality of target APIs, the analysis result being used to determine whether the first transaction and other transactions have read-write conflicts, the analysis result comprising a plurality of grouping keys and an access type corresponding to each of the plurality of grouping keys, the plurality of grouping keys comprising a contract address of the smart contract, and the first transaction indicating identification information of a plurality of data objects accessed through the plurality of target APIs, the access type corresponding to the contract address being read.
[0130] The embodiments of the present specification further provide a computer readable storage medium having computer programs / instructions stored thereon, which, when executed in a computer, cause the computer to perform the transaction analysis method in the blockchain system provided in each of the foregoing embodiments.
[0131] The embodiments of the present specification further provide a computing device comprising a memory and a processor, the memory having computer programs / instructions stored therein, and the processor, when executing the computer programs / instructions, implements the transaction analysis method in the blockchain system provided in each of the foregoing embodiments.
[0132] In the 1990s, it was quite obvious to distinguish whether an improvement in a technology was in hardware (e.g., improvement in circuit structures of diodes, transistors, switches, etc.) or in software (improvement in method flow). However, as technology has evolved, many improvements in method flow today can be considered as direct improvements in hardware circuit structures. Designers almost always obtain the corresponding hardware circuit structures by programming the improved method flow into hardware circuits. Therefore, it cannot be said that an improvement in a method flow cannot be implemented by hardware entity modules. For example, a programmable logic device (PLD) (e.g., a field programmable gate array (FPGA)) is an integrated circuit whose logic function is determined by user programming of the device. A digital system is "integrated" on a PLD by the designer programming it, rather than by asking a chip manufacturer to design and fabricate a custom integrated circuit chip. Moreover, instead of manually fabricating integrated circuit chips, this programming is now mostly implemented by "logic compiler" software, which is similar to software compilers used in program development, and the original code to be compiled is written in a specific programming language, which is called a hardware description language (HDL), and there are many such languages, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc., and the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should be aware that, as long as the method flow is logically programmed in the above-mentioned hardware description languages and programmed into an integrated circuit, a hardware circuit implementing the logical method flow can be easily obtained.
[0133] The controller can be implemented in any suitable way, for example, the controller can take the form of, for example, a microprocessor or processor and a computer readable medium storing computer readable program code, such as software or firmware, executable by the (micro)processor, logic gates, switches, an application specific integrated circuit (ASIC), a programmable logic controller and an embedded microcontroller, examples of which include but are not limited to the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20 and Silicone Labs C8051F320, the memory controller can also be implemented as part of the control logic of the memory. The skilled person will also appreciate that, in addition to implementing the controller in pure computer readable program code, it is possible to implement the controller in the form of logic gates, switches, an application specific integrated circuit, a programmable logic controller and an embedded microcontroller, etc. to perform the same functions by logically programming the method steps. Such a controller can therefore be considered to be a hardware component, and the means included therein to perform the various functions can also be considered to be structures within the hardware component. Alternatively, or even additionally, the means to perform the various functions can be considered to be both a software module implementing the method and a structure within a hardware component.
[0134] The systems, apparatuses, modules or units illustrated by the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a server system. Of course, the present application does not rule out that with the development of future computer technologies, computers implementing the functions of the above embodiments can be personal computers, laptop computers, vehicle human-computer interaction devices, cellular phones, camera phones, smart phones, personal digital assistants, media players, navigation devices, email devices, game consoles, tablet computers, wearable devices, or combinations of any of these devices.
[0135] Although the method operations of the embodiments of the present specification are described in sequential order, some of the operations can in practical implementations be performed concurrently, in parallel, or in a different order. The above description of the embodiments of the present specification is provided as an example only and is not intended to be limiting. For example, the steps recited in the examples or flow charts can include more, fewer, or different steps than those described. The order in which the steps are presented is merely one example and is not intended to be limiting. The steps can be performed in an order different than presented, or performed in parallel, or in a different order, for example in a parallel processor or multi-threaded processing environment, or even in a distributed data processing environment. The terms "comprise", "comprising", or any other variation thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can also include other elements not expressly listed or inherent to such process, method, article, or apparatus. Exclusion of such elements is only present if it is expressly stated that these elements are excluded. For example, use of the terms "first", "second", or the like does not denote any order or importance, but rather the terms are used to distinguish one element from another.
[0136] For ease of description, the above apparatuses are described in functional modules for description. Of course, when implementing one or more of the present specification, the functions of the modules can be implemented in one or more software and / or hardware, or the modules implementing the same function can be implemented by a combination of sub-modules or sub-units. The apparatus embodiments described above are merely illustrative. For example, the division of the units is only a logical function division, and in actual implementation, another division mode can be used, for example, a plurality of units or components can be combined or integrated into another system, or some features can be omitted or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed elements can be indirect coupling or communication connection through some interfaces, devices or units, and can be electrical, mechanical or other forms.
[0137] The present application is described with reference to flowcharts and / or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, as well as combinations of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing apparatus to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing apparatus produce a means for implementing the functions specified in the flowcharts and / or block diagrams. Figure 1 The functions of one or more flows and / or blocks Figure 1 The apparatuses that implement the functions specified in one or more flows and / or blocks.
[0138] These computer program instructions can also be stored in a computer- readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instructions which implement the Figure 1 function specified in the flow or flows and / or blocks Figure 1 of the block or blocks.
[0139] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the Figure 1 function specified in the flow or flows and / or blocks Figure 1 of the block or blocks.
[0140] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0141] The memory can include non-persistent memory and / or volatile memory, such as random access memory (RAM) and / or cache memory, non-volatile memory, such as read-only memory (ROM), EPROM, and / or flash memory, etc. The memory is an example of computer readable media.
[0142] Computer readable media includes permanent and non-permanent, moveable and non- moveable media that can be implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile discs (DVDs) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, graphene storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that is accessible to a computing device. According to the definition herein, computer readable media does not include transitory media, such as modulated data signals and carrier waves.
[0143] Those skilled in the art will appreciate that the one or more embodiments described herein can be provided as a method, system or computer program product. Accordingly, the one or more embodiments described herein can take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the one or more embodiments described herein can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, etc.) embodying computer readable code.
[0144] The one or more embodiments described herein can be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform particular tasks or implement particular abstract data types. The one or more embodiments described herein can also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules can be located in both local and remote computer storage media including memory storage devices.
[0145] The various embodiments described in this specification are described in the context of progressive embodiments, with each embodiment building on the previous one. The same or similar parts between embodiments are cross-referenced as appropriate. Each embodiment focuses on the differences between that embodiment and the previous one. In particular, the system embodiments are described relatively simply, as they are substantially similar to the method embodiments. In the description of the specification, the use of the terms "one embodiment", "some embodiments", "example", "specific example" or "some examples" means that the particular feature, structure, material or characteristic being described is included in at least one embodiment or example of the specification. Illustrative representations of the above terms do not necessarily refer to the same embodiment or example in the specification. Moreover, the particular features, structures, materials or characteristics being described can be combined in any suitable manner in one or more embodiments or examples. Furthermore, the skilled person can combine and combine features of different embodiments or examples and characteristics of different embodiments or examples, without contradicting each other.
[0146] The above only describes embodiments of the one or more embodiments of the specification and is not intended to limit the one or more embodiments of the specification. The one or more embodiments of the specification can have various modifications and changes for those skilled in the art. Any modification, equivalent replacement, improvement, etc. within the spirit and principle of the specification shall be included in the scope of the claims.
Claims
1. A transaction analysis method in a blockchain system, wherein a smart contract is deployed in the blockchain system, a contract state of the smart contract is divided into a plurality of data objects, the plurality of data objects have different storage locations, and a plurality of application programming interfaces (APIs) for accessing the plurality of data objects are included in the blockchain system, the method comprising: determining that a first transaction indicates a target function in the smart contract that is invoked; determining a plurality of target APIs that are invoked in the target function; determining an analysis result according to the first transaction, the plurality of target APIs, and access types corresponding to the plurality of target APIs, the analysis result being used to determine whether the first transaction and other transactions have read-write conflicts, the analysis result including a plurality of grouping keys and access types corresponding to the plurality of grouping keys, the plurality of grouping keys including a contract address of the smart contract and identification information of a plurality of data objects accessed by the first transaction via the plurality of target APIs, and the access type corresponding to the contract address being read.
2. The method of claim 1, wherein determining the analysis result based on the first transaction, the number of target APIs, and the access type corresponding to each of the number of target APIs comprises: obtaining the contract address of the smart contract from the first transaction, determining the contract address as a grouping key, and setting the access type corresponding to the contract address as read.
3. The method of claim 1, wherein the determining the analysis result according to the first transaction, the plurality of target APIs, and the access types corresponding to the plurality of target APIs comprises: determining input parameters of the target APIs when the target function is executed according to the first transaction; determining identification information of data objects accessed by the first transaction via the target APIs according to the input parameters, and determining the identification information as a grouping key; setting the access type corresponding to the identification information as the access type corresponding to the target APIs.
4. The method of claim 3, the determining an input parameter of the target API when executing the objective function according to the first transaction, comprising: obtaining the input parameters of the target APIs from the first transaction.
5. The method of claim 3, said determining an input parameter of the target API when executing the objective function according to the first transaction, comprising: obtaining the input parameters of the target APIs from the target function.
6. The method of claim 1, wherein the plurality of data objects are divided into a plurality of object categories, for any target category in the plurality of object categories, a first API and a second API corresponding to the target category are included in the plurality of APIs, the first API is used to read values of state variables from data objects belonging to the target category, and the second API is used to write values of state variables to data objects belonging to the target category. wherein The access type corresponding to the first API is read, and the access type corresponding to the second API is write.
7. The method of claim 6, wherein a first category is included in the plurality of object categories, for a first data object belonging to the first category, each state variable in the first data object is associated with a same first user account, and identification information of the first data object is determined based on an account address of the first user account.
8. The method of claim 6, wherein a second category is included in the plurality of object categories, and identification information of a second data object belonging to the second category is predefined by contract code of the smart contract.
9. The method of claim 1, wherein the data object is a tree structure, a directed path between a root node and a leaf node of the tree structure stores a key of a state variable corresponding to a value stored in the leaf node, and the identification information of the data object is stored in the root node.
10. The method of any one of claims 1-9, wherein the first transaction is included in a plurality of transactions having an arrangement order, and the plurality of transactions further includes a second transaction having an arrangement position after the first transaction, and the method further comprises: determining whether a same target grouping key exists in an analysis result of the first transaction and an analysis result of the second transaction; and if the target grouping key exists, determining that the first transaction and the second transaction have a read-write conflict when an access type corresponding to the target grouping key in the analysis result of the first transaction includes writing. The blockchain node comprises: a function determination unit configured to determine a target function in the smart contract expected to be invoked by a first transaction; 11.A blockchain node in a blockchain system, wherein a smart contract is deployed in the blockchain system, wherein a contract state of the smart contract is divided into a plurality of data objects, wherein the plurality of data objects have different storage locations, and wherein the blockchain system comprises a plurality of application programming interfaces (APIs) for accessing the plurality of data objects. an interface determination unit configured to determine a plurality of target APIs invoked in the target function; an analysis processing unit configured to determine an analysis result according to the first transaction, the plurality of target APIs, and an access type corresponding to each of the plurality of target APIs, the analysis result being used to determine whether the first transaction has a read-write conflict with other transactions, the analysis result including a plurality of grouping keys and an access type corresponding to each of the plurality of grouping keys, the plurality of grouping keys including a contract address of the smart contract and identification information of a plurality of data objects accessed by the first transaction through the plurality of target APIs, and the access type corresponding to the contract address being reading.
12. A computer-readable storage medium having a computer program stored thereon, when the computer program is executed in a computing device, the computing device executes the method of any one of claims 1-10.
Citation Information
Patent Citations
Intelligent contract transaction rapid execution method based on fine-grained read-write analysis
CN116630040A
Intelligent contract vulnerability detection method and system based on hybrid fuzzy test
CN117828616A