WO2023098058A1 - 区块链智能合约读写集构建方法及装置 - Google Patents

区块链智能合约读写集构建方法及装置 Download PDF

Info

Publication number
WO2023098058A1
WO2023098058A1 PCT/CN2022/102164 CN2022102164W WO2023098058A1 WO 2023098058 A1 WO2023098058 A1 WO 2023098058A1 CN 2022102164 W CN2022102164 W CN 2022102164W WO 2023098058 A1 WO2023098058 A1 WO 2023098058A1
Authority
WO
WIPO (PCT)
Prior art keywords
smart contract
read
statement
basic block
processed
Prior art date
Application number
PCT/CN2022/102164
Other languages
English (en)
French (fr)
Inventor
李陈希
李辉忠
张开翔
范瑞彬
Original Assignee
深圳前海微众银行股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳前海微众银行股份有限公司 filed Critical 深圳前海微众银行股份有限公司
Publication of WO2023098058A1 publication Critical patent/WO2023098058A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3829Payment protocols; Details thereof insuring higher security of transaction involving key management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/40Authorisation, e.g. identification of payer or payee, verification of customer or shop credentials; Review and approval of payers, e.g. check credit lines or negative lists
    • G06Q20/405Establishing or using transaction specific rules

Definitions

  • This application relates to the block chain technology of financial technology (Fintech), in particular to a method and device for constructing a block chain smart contract read-write set.
  • the blockchain system is a multi-center, tamper-proof, and non-repudiation distributed storage system. Therefore, the blockchain system is more and more used in the financial industry.
  • the development of smart contracts is a milestone in the development of blockchain technology, which provides more powerful logic functions and can meet business requirements in various fields. , developed into multiple fields.
  • the present application provides a method and device for constructing a blockchain smart contract read-write set.
  • the embodiment of the present application provides a method for constructing a blockchain smart contract read-write set, the method comprising:
  • the establishment of a control flow graph corresponding to the smart contract to be processed based on the one or more basic blocks includes:
  • the control flow graph corresponding to the smart contract to be processed is established according to the first statement and the target address of the jump statement.
  • the establishment of the control flow graph corresponding to the smart contract to be processed according to the first statement and the target address of the jump statement includes:
  • the determination of the target data source according to the code statement that initiates the blockchain storage read and write request in each basic block includes:
  • the target data source is determined based on a program variable used as a key in each basic block.
  • Program variables including:
  • each basic block According to the code statement that initiates the block chain storage read and write request in each basic block, respectively determine the conversion function of each basic block, wherein the conversion function is used to determine the conflict domain based on the execution of a code statement a next collision domain, which is the set of program variables used as keys in the basic block;
  • program variables used as keys in each basic block during the read and write process are respectively located.
  • the conversion function of each basic block is determined respectively according to the code statement that initiates the block chain storage read and write request in each basic block, including:
  • code statement that initiates the block chain storage read and write request in each basic block respectively determine the first set of all program variables with fixed values in the code statement of each basic block, and each basic block
  • the code statement of the block will be used as the second set of all program variables for indexing data access requests to the blockchain system
  • the first set and the second set respectively determine the transformation function of each basic block.
  • the determining the target data source based on the program variable used as a key in each basic block includes:
  • the division of the smart contract to be processed into one or more basic blocks includes:
  • the constructing the read-write set of the smart contract to be processed according to the target data source includes:
  • the target data source is composed of the transaction input of the smart contract to be processed, blockchain system environment information or constants, then based on the target data source, construct the read-write set of the smart contract to be processed.
  • the determining the code statement for initiating a block chain storage read and write request in each basic block of the control flow graph based on the control flow graph includes:
  • the embodiment of the present application provides a block chain smart contract read-write set construction device, the device includes:
  • a contract division module used to divide the smart contract to be processed into one or more basic blocks when compiling the smart contract to be processed
  • a graph building module configured to create a control flow graph corresponding to the smart contract to be processed based on the one or more basic blocks
  • a read-write determination module configured to determine a code statement for initiating a block chain storage read-write request in each basic block of the control flow graph based on the control flow graph;
  • the source determination module is used to determine the source of the target data according to the code statement that initiates the block chain storage read and write request in each basic block;
  • the read-write set construction module is used to construct the read-write set of the smart contract to be processed according to the target data source.
  • the graph building module is specifically configured to:
  • the control flow graph corresponding to the smart contract to be processed is established according to the first statement and the target address of the jump statement.
  • the graph building module is specifically configured to:
  • the source determination module is specifically configured to:
  • the target data source is determined based on a program variable used as a key in each basic block.
  • the source determination module is specifically configured to:
  • each basic block According to the code statement that initiates the block chain storage read and write request in each basic block, respectively determine the conversion function of each basic block, wherein the conversion function is used to determine the conflict domain based on the execution of a code statement a next collision domain, which is the set of program variables used as keys in the basic block;
  • program variables used as keys in each basic block during the read and write process are respectively located.
  • the source determination module is specifically configured to:
  • code statement that initiates the block chain storage read and write request in each basic block respectively determine the first set of all program variables with fixed values in the code statement of each basic block, and each basic block
  • the code statement of the block will be used as the second set of all program variables for indexing data access requests to the blockchain system
  • the first set and the second set respectively determine the transformation function of each basic block.
  • the source determination module is specifically configured to:
  • the contract division module is specifically used for:
  • the read-write set construction module is specifically used for:
  • the target data source is composed of the transaction input of the smart contract to be processed, blockchain system environment information or constants, then based on the target data source, construct the read-write set of the smart contract to be processed.
  • the read-write determination module is specifically configured to:
  • the method and device for constructing the block chain smart contract read-write set provided by the embodiment of the present application, when compiling the smart contract to be processed, the method divides the smart contract into one or more basic blocks, based on the one or more basic Block, establish the corresponding control flow graph, and then, based on the control flow graph, determine the code statement that initiates the block chain storage read and write request in each basic block in the graph, so that, according to the code statement, determine the source of the target data, according to The target data source constructs the read-write set of the above-mentioned smart contract.
  • FIG. 1 is a schematic diagram of a block chain smart contract reading and writing set construction system architecture provided by the embodiment of the present application;
  • FIG. 2 is a schematic flow diagram of a method for constructing a block chain smart contract read-write set provided by the embodiment of the present application;
  • FIG. 3 is a schematic flow diagram of another blockchain smart contract read-write set construction method provided by the embodiment of the present application.
  • FIG. 4 is a schematic flow diagram of establishing a control flow graph provided by an embodiment of the present application.
  • FIG. 5 is a schematic diagram of a control flow diagram corresponding to a certain smart contract provided by the embodiment of the present application.
  • FIG. 6 is a schematic flow diagram of another method for constructing a blockchain smart contract read-write set provided by the embodiment of the present application.
  • FIG. 7 is a schematic structural diagram of a block chain smart contract read-write set construction device provided by the embodiment of the present application.
  • Fig. 8 shows a possible structural schematic diagram of a block chain smart contract read-write set construction device of the present application.
  • each transaction in the blockchain system is executed based on the transaction read-write set (the key contained in the read-write set means the exclusive use of its corresponding data, for example, in the transfer problem, the read-write
  • the write set contains the account address of the initiator and the account address of the recipient), and the transaction execution system of the blockchain organizes different transactions into a dependency graph, and schedules transactions to be executed in parallel according to the preceding and following dependencies in the dependency graph.
  • the blockchain system needs to increase the parallel processing capability of transactions as much as possible on the premise of ensuring the concurrent security of blockchain data.
  • the smart contract developer generally constructs the transaction read-write set when the transaction is not executed, and declares the specific read-write set construction rules of the transaction in the form of metadata in the smart contract source code. For example: For a simple transfer transaction, the read-write set of each transfer transaction is composed of the sender address and receiver address in the transaction input parameters. At the same time, smart contract developers need to explicitly call the public interface exposed by the underlying system of the blockchain to register the read-write set. When executing related transactions, the transaction execution system of the blockchain will read the pre-registered read-write set construction rules to construct the read-write set of the transaction, and then arrange all the transactions in the block as transactions according to the content of the read-write set Dependency graph and schedule execution.
  • the construction of the existing read-write set increases the mental burden and workload of smart contract developers when developing parallel smart contracts. Developers must be very careful when specifying the transaction read-write set construction rules, because if the read-write set construction rules If it is not declared correctly, it is very likely that the blockchain system will fall into disastrous consequences where consensus cannot be reached. Moreover, the construction of the existing read-write set requires smart contract developers to abide by certain rules, such as implementing interfaces such as the registration of read-write set rules in the contract as required, and the declaration of data dependencies must follow certain format specifications. For transaction input parameters, these parameters must be placed at the forefront of the smart contract function parameter list. These requirements and specifications have increased the complexity of smart contract development.
  • the embodiment of this application proposes a blockchain smart contract read-write set construction method, which analyzes the transaction read-write set construction rules during the compilation period, and can construct the read-write set of the function without actually executing the smart contract function. , does not require the participation of smart contract developers, solves the existing problem of constructing transaction read-write sets by smart contract developers, increasing the mental burden and workload of smart contract developers, reduces the complexity of parallel smart contract development, and speeds up the transaction as a whole Processing efficiency. Moreover, the embodiment of this application is completely transparent to smart contract developers, who only need to write contracts in the way of writing serial contracts, thus better improving the experience of developers when developing parallel smart contracts.
  • the above-mentioned blockchain system can be understood as a trusted distributed storage system jointly maintained by multiple nodes.
  • the bottom layer of the blockchain is a chain composed of a series of blocks.
  • each block also records the hash value of the previous block.
  • a block consists of a block header and a block body, where the block header defines important fields such as the height of the block and the hash value of the previous block, while the block body mainly stores transaction data.
  • the blockchain uses cryptography to ensure the security of data transmission and access, and uses a chain structure to ensure that the data on the chain cannot be tampered with.
  • the above smart contract can be understood as a collection of code and data running on the blockchain system, in which the code is responsible for implementing the functions of the smart contract, the data is responsible for storing the state of the smart contract, and the smart contract can receive and send information.
  • any operation is performed by sending transactions. Transactions are initiated by users and sent to blockchain nodes through clients. After the blockchain node receives the transaction, it will package the transaction into a block and execute it.
  • the above read-write set can be understood as the read-write set generated during the execution of the transaction.
  • the read set contains the set of keys read during transaction execution, and the write set contains the set of keys written.
  • the keys in the read set and write set can overlap.
  • a blockchain smart contract read-write set construction method provided by this application can be applied to the block chain smart contract read-write set construction system architecture schematic diagram shown in Figure 1.
  • Figure 1 uses a certain transfer in the financial field Take the construction of the transaction read-write set in the smart contract of the transaction as an example.
  • the system may include a receiving device 101 , a processing device 102 and a display device 103 .
  • the receiving device 101 may be an input/output interface or a communication interface, which may be used to receive the smart contract of the above-mentioned transfer transaction.
  • the processing device 102 can obtain the above-mentioned smart contract through the above-mentioned receiving device 101, and then perform static program analysis on the above-mentioned smart contract, and construct a transaction read-write set during compilation.
  • smart contract developers there is no need for smart contract developers to participate, thereby reducing the mental burden and workload of smart contract developers, reducing the complexity of parallel smart contract development, and speeding up the overall transaction processing efficiency.
  • the embodiment of this application is completely transparent to smart contract developers, who only need to write contracts in the way of writing serial contracts, thus better improving the experience of developers when developing parallel smart contracts.
  • the above-mentioned static program analysis can be understood as referring to a method of analyzing certain program attributes without running the program.
  • the results of static program analysis cannot be completely accurate. For programs with infinite execution paths (such as programs containing infinite recursion), it is impossible to enumerate all possible execution paths of the program.
  • the display device 103 can be used to display the above-mentioned construction process of the transaction read-write set and the like.
  • the display device may also be a touch screen, configured to receive user instructions while displaying the above content, so as to realize interaction with the user.
  • the processing device 102 may send the constructed transaction read-write set to the transaction execution system.
  • the transaction execution system can arrange all transactions in the block into a transaction dependency graph according to the content of the read-write set and schedule execution.
  • processing device may be implemented by a processor reading instructions in a memory and executing the instructions, or may be implemented by a chip circuit.
  • the above system is only an exemplary system, and can be set according to application requirements during specific implementation.
  • the structure shown in the embodiment of the present application does not constitute a specific limitation on the architecture of the blockchain smart contract read-write set construction system.
  • the above architecture may include more or fewer components than shown in the illustrations, or combine some components, or split some components, or arrange different components, which may be determined according to actual applications. The scene is determined, and there is no limitation here.
  • the components shown in FIG. 1 can be implemented in hardware, software, or a combination of software and hardware.
  • system architecture described in the embodiment of the present application is to illustrate the technical solutions of the embodiments of the present application more clearly, and does not constitute a limitation to the technical solutions provided in the embodiments of the present application.
  • evolution of the technology and the emergence of new business scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.
  • FIG. 2 is a schematic flow diagram of a method for constructing a block chain smart contract read-write set provided by the embodiment of the present application.
  • the execution subject of this embodiment may be the processing device in the embodiment shown in Figure 1, which may be determined according to the actual situation .
  • the blockchain smart contract read-write set construction method provided by the embodiment of the present application includes the following steps:
  • S201 When compiling the smart contract to be processed, divide the smart contract to be processed into one or more basic blocks.
  • the smart contract to be processed above can be determined according to the actual situation, for example, the smart contract of a certain transfer transaction in the financial field described in FIG. 1 above.
  • the above-mentioned processing device may scan the above-mentioned smart contract to be processed when compiling the above-mentioned smart contract to be processed, and determine the code structure of the above-mentioned smart contract to be processed, so that, according to the code structure and the preset basic block conditions, the above-mentioned pending Smart contracts are divided into one or more basic blocks, so that the subsequent analysis process can be carried out in units of basic blocks, and batch processing of program statements improves analysis performance.
  • the above preset basic block conditions may include the following conditions: the control flow can only enter the block from the first program statement of the basic block, that is to say, there is no transfer statement jumping to the middle or end instruction of the basic block; except The last program statement of a basic block, the control flow will not jump or stop until it leaves the basic block.
  • control flow graph can be understood as an abstract representation of a process or program, representing all the paths traversed during the execution of a program.
  • a control flow graph represents the possible flow of execution of all basic blocks within a process in the form of a graph.
  • Each vertex in the control flow graph corresponds to a basic block and uses directed edges to represent branches.
  • the processing device When the above-mentioned processing device compiles the smart contract, it scans the smart contract to determine its code structure, and then divides the smart contract into basic blocks based on the code structure, and then establishes a corresponding control flow graph based on the basic blocks to obtain the program execution process. All paths will be traversed, which is convenient for subsequent processing and meets application needs.
  • S203 Based on the above control flow graph, determine a code statement in each basic block of the above control flow graph that initiates a block chain storage read and write request.
  • the above-mentioned processing device can obtain the read-write request code statement stored in the pre-stored blockchain, so that, based on the read-write request code statement and the above-mentioned control flow graph, in each basic block of the above-mentioned control flow graph, identify A code statement that initiates a block chain storage read and write request.
  • the above-mentioned pre-stored block chain storage read and write request code statement may be set by relevant technical personnel.
  • the above-mentioned processing device obtains the information set by the above-mentioned technician, so that, based on the information, in each basic block of the above-mentioned control flow graph, a code statement that initiates a block chain storage read-write request is identified.
  • S204 Determine the target data source according to the code statement for initiating a blockchain storage read and write request in each of the above basic blocks.
  • the above-mentioned processing device can identify the code statement that initiates the block chain storage read-write request in each of the above-mentioned basic blocks, and locate the code statement used as the key in each basic block during the read-write process through the parameters used in the call statement. , and thus, based on the program variable used as a key in each basic block, the above-mentioned target data source is determined.
  • the above-mentioned processing device can add a preset label to the above-mentioned program variable, and reversely propagate the label along the data flow path to the entry point of smart contract execution, so as to finally identify the target data source of the above-mentioned program variable according to the label.
  • the smart contract function "transfer” will use “user_1” as the index to modify the corresponding value in the state variable "balance”. This statement will cause a write request for blockchain storage.
  • a preset label can be added to the "user_1” variable, and then the label is propagated backwards in the code logic.
  • the second line of code is an assignment statement, that is, the value of the "user_1” variable is assigned by the "user_2” variable, so the above label is propagated to the "user_2" variable. After that, the reverse propagation process reaches the entry point of the contract function "transfer", and the analysis process ends.
  • the read and write set of the "transfer” function comes from the value of "user_2" in the transaction input, that is, for different transactions that call the "transfer” contract function, As long as the value of "user_2" in the transaction input is not the same, these transactions will not have read-write conflicts during execution, resulting in abnormal blockchain data status.
  • the above-mentioned preset label can be determined according to the actual situation, for example, adding the label "key” to the above-mentioned program variable used as a key.
  • the above preset labels are used to highlight the above program variables used as keys
  • S205 According to the above-mentioned source of target data, construct the read-write set of the above-mentioned smart contract to be processed.
  • the above-mentioned processing device may determine whether the above-mentioned target data source is constituted by the transaction input of the above-mentioned smart contract to be processed, blockchain system environment information or constants. If the above-mentioned target data source is composed of transaction input of the above-mentioned smart contract to be processed, blockchain system environment information or constants, the above-mentioned processing device can construct the read-write set of the above-mentioned smart contract to be processed based on the above-mentioned source of target data, and can Encode the source information of the read-write centralized key into the program output, which can be used by the subsequent smart contract execution system.
  • the above-mentioned processing device when compiling the smart contract to be processed, divides the smart contract into one or more basic blocks, establishes a corresponding control flow graph based on the one or more basic blocks, and further, based on the The control flow graph determines the code statement that initiates the block chain storage read and write request in each basic block in the graph, so that, according to the code statement, the target data source is determined, and the read and write set of the above smart contract is constructed according to the target data source .
  • the embodiment of this application is completely transparent to smart contract developers, who only need to write contracts in the way of writing serial contracts, which better improves the experience of developers when developing parallel smart contracts.
  • FIG. 3 is a schematic flowchart of another method for constructing a blockchain smart contract read-write set proposed by the embodiment of the present application. As shown in Figure 3, the method includes:
  • S301 When compiling the smart contract to be processed, divide the smart contract to be processed into one or more basic blocks.
  • step S301 is the same as that of the above step S201, which will not be repeated here.
  • S302 Based on the above-mentioned one or more basic blocks, determine the first statement and the jump statement in each program statement of the above-mentioned smart contract to be processed.
  • the process of establishing the control flow graph by the above processing device may be as shown in FIG. 4 .
  • the above-mentioned processing device determines the first statement and the jump statement in each program statement of the above-mentioned smart contract to be processed, it can sort the above-mentioned each program statement according to the target address of the above-mentioned first statement and the jump statement, and sort the sorted Each program statement is deduplicated, and then, based on each program statement after deduplication, determine the basic block node in the above control flow graph, and based on the target address of each jump statement in each program statement after deduplication, determine the above control flow
  • the basic block points to the directed edge of the basic block where the target address is located, so that the control flow graph corresponding to the above-mentioned smart contract to be processed is established according to the above-mentioned basic block nodes and directed edges.
  • control flow diagram corresponding to the smart contract established by the above-mentioned processing device using the process shown in FIG. 4 may be shown in FIG. 5 .
  • I is greater than or equal to the number of program statements in FN, it means that all statements have been processed, and jump to (9), otherwise jump to (5);
  • S305 Determine the target data source according to the code statement initiating the blockchain storage read and write request in each of the above basic blocks.
  • steps S304-S306 are implemented in the same manner as the above-mentioned steps S203-S205, and will not be repeated here.
  • the above-mentioned processing device may determine the first statement and the jump statement in each program statement of the smart contract to be processed based on the above-mentioned one or more basic blocks, so that, according to the first statement and the jump statement Target address, establish the control flow graph corresponding to the smart contract to be processed above, so that the subsequent analysis process can be carried out in units of basic blocks in the control flow graph, batch processing program statements, and improve analysis performance.
  • the above-mentioned processing device does not require the participation of smart contract developers in the process of constructing the above-mentioned read-write set, which solves the existing problem that the smart contract developer constructs the transaction read-write set, which increases the mental burden and workload of the smart contract developer.
  • the above-mentioned processing device determines the source of the above-mentioned target data according to the code statement that initiates the block chain storage read-write request in each of the above-mentioned basic blocks, it also considers the code statement that initiates the block chain storage read-write request in each of the above-mentioned basic blocks.
  • the code statement respectively locates the program variables used as keys in each basic block during the reading and writing process, and then, based on the program variables used as keys in each basic block, determines the source of the above-mentioned target data.
  • FIG. 6 is a schematic flowchart of another method for constructing a blockchain smart contract read-write set proposed by the embodiment of the present application. As shown in Figure 6, the method includes:
  • S601 When compiling the smart contract to be processed, divide the smart contract to be processed into one or more basic blocks.
  • S603 Based on the above control flow graph, determine a code statement in each basic block of the above control flow graph that initiates a block chain storage read and write request.
  • steps S601-S603 are implemented in the same manner as the above-mentioned steps S201-S203, and will not be repeated here.
  • S604 According to the code statement initiating the block chain storage read and write request in each basic block above, respectively locate the program variable used as the key in each basic block during the read and write process.
  • the above-mentioned processing device can respectively determine the conversion function of each basic block according to the code statement initiating the block chain storage read-write request in each of the above-mentioned basic blocks, and then, based on the conversion function of each basic block, respectively locate the read Program variable used as key in each basic block during write.
  • the conversion function is used to determine the next conflict domain based on the conflict domain after a code statement is executed, and the conflict domain is a set of program variables used as keys in the basic block. If there is a variable in the conflict domain of a basic block, it means that before the program statement of the basic block is executed, the value in the variable will be directly used as a key to initiate a data access request to the blockchain system.
  • the processing device determines the conversion function of each basic block, it can determine all the fixed values in the code statement of each basic block according to the code statement that initiates the block chain storage read and write request in each basic block.
  • the first set of program variables, and the second set of all program variables that will be used as indexes in the code statements of each basic block to initiate data access requests to the blockchain system thus, according to the first set and the second set , respectively determine the transition function of each basic block.
  • the processing device may first determine a propagation function f s corresponding to each statement S in the smart contract function.
  • f s is used to calculate the conflict domain based on the previous statement in the data propagation direction.
  • a new conflict domain is obtained, and the new conflict domain will be used to calculate the read-write set at the statement S.
  • the formalization of f s can be expressed as:
  • x is used as an input, indicating the conflict domain after the statement S is executed
  • def s indicates the set of all variables with fixed values in the statement S
  • use s indicates that the statement S will be used as an index to initiate a data access request to the blockchain system
  • a collection of variables, ⁇ represents a union.
  • Runtime means to initiate a data access request to the blockchain system with a value calculated at runtime
  • Env means to initiate a data access request to the blockchain system with a certain execution context information as the key. That is, when the conflict domain contains Runtime, it means that the function will initiate a data access request to the blockchain system with a value calculated at runtime. Similarly, when the conflict domain contains Env, it means that the function will use a certain This type of execution context information is used as a key to initiate a data access request to the blockchain system.
  • the above-mentioned processing device can deduce the conversion function of the basic block BB, that is, the conversion function of the basic block BB is based on the first set of all program variables with fixed values in the code statement of the basic block, And the code statement of the basic block will be determined by the second set of all program variables used as indexes to initiate data access requests to the blockchain system.
  • transition function of the basic block BB can be expressed as:
  • S 1 , S 2 , ..., S n represent the 1st, 2nd, ..., nth program statements in the basic block BB.
  • the process of collision domain of a block may include the following steps:
  • ENTRY be the basic block where the smart contract function entry to be analyzed is located
  • BB be the I-th basic block in the control flow diagram
  • the above code is used to locate the keys used as keys in each basic block during the read and write process based on the conversion function of each basic block.
  • the program variable is to locate the conflict domain of each basic block in the process of reading and writing. The changes of the conflict domain of each basic block are shown in the following table:
  • the above-mentioned processing device determines that IN[ENTRY] is ⁇ S1, S2, S3 ⁇ , that is, the read-write set of the smart contract function "foo" is composed of the parameters S1, S2, and S3 in the transaction input.
  • BB has multiple predecessor nodes in the direction of data propagation, that is, multiple different basic blocks can reach the basic block BB through different execution paths, then BB
  • the conflict domain of is the union of the conflict domains calculated on each path, that is, ignoring the branch statement of the program, it is approximately considered that all paths may be reached.
  • the above-mentioned processing device can add a preset label to the program variable used as a key in each of the above-mentioned basic blocks, and then propagate the label backward along the data flow path of the above-mentioned smart contract to be processed to the above-mentioned smart contract to be processed The entry point for contract execution, identifying the target data source for program variables used as keys in each basic block.
  • the above-mentioned processing device can construct the read-write set of the above-mentioned smart contract before actually executing the above-mentioned smart contract function, and then, The source information of the read-write centralized key is encoded into the program output, which can be used by the subsequent smart contract execution system, and the parallel processing capability of transactions can be improved as much as possible under the premise of ensuring the concurrent security of blockchain data.
  • S606 According to the above-mentioned source of target data, construct the read-write set of the above-mentioned smart contract to be processed.
  • step S606 is the same as that of the above step S205, which will not be repeated here.
  • the above-mentioned processing device determines the source of the above-mentioned target data according to the code statement that initiates the block chain storage read-write request in each of the above-mentioned basic blocks, it also considers the block chain storage read-write request initiated in each of the above-mentioned basic blocks
  • the code statement of the write request locates the program variables used as keys in each basic block during the read and write process, and then, based on the program variables used as keys in each basic block, determines the source of the above target data. Construct the read-write set of the above smart contract functions before execution, reduce the mental burden and workload of smart contract developers, reduce the complexity of parallel smart contract development, and speed up the overall transaction processing efficiency.
  • the embodiment of this application is completely transparent to smart contract developers, who only need to write contracts in the way of writing serial contracts, which better improves the experience of developers when developing parallel smart contracts.
  • FIG. 7 is a schematic structural diagram of a block chain smart contract read-write set building device provided by an embodiment of the present application. For ease of description, only the parts related to the embodiment of the present application are shown. 7 is a schematic structural diagram of a block chain smart contract read-write set construction device provided by the embodiment of the present application.
  • the block chain smart contract read-write set construction device 70 includes: a contract division module 701, a graph creation module 702, a reading Write determination module 703 , source determination module 704 and read-write set construction module 705 .
  • the block chain smart contract read-write set construction device here may be the above-mentioned processing device itself, or a chip or an integrated circuit that realizes the function of the processing device. What needs to be explained here is that the division of the contract division module, graph creation module, read-write determination module, source determination module, and read-write set building module is only a division of logical functions. Physically, the two can be integrated or can be independent.
  • the contract division module 701 is configured to divide the smart contract to be processed into one or more basic blocks when compiling the smart contract to be processed.
  • a graph creation module 702 configured to create a control flow graph corresponding to the smart contract to be processed based on the one or more basic blocks.
  • the read-write determination module 703 is configured to determine a code statement in each basic block of the control flow graph that initiates a block chain storage read-write request based on the control flow graph.
  • the source determination module 704 is configured to determine the source of the target data according to the code statement initiating the block chain storage read and write request in each basic block.
  • the read-write set construction module 705 is configured to construct the read-write set of the smart contract to be processed according to the target data source.
  • the graph building module 702 is specifically configured to:
  • the control flow graph corresponding to the smart contract to be processed is established according to the first statement and the target address of the jump statement.
  • the graph creation module 702 is specifically configured to:
  • the source determination module 704 is specifically configured to:
  • the target data source is determined based on a program variable used as a key in each basic block.
  • the source determination module 704 is specifically configured to:
  • each basic block According to the code statement that initiates the block chain storage read and write request in each basic block, respectively determine the conversion function of each basic block, wherein the conversion function is used to determine the conflict domain based on the execution of a code statement a next collision domain, which is the set of program variables used as keys in the basic block;
  • program variables used as keys in each basic block during the read and write process are respectively located.
  • the source determination module 704 is specifically configured to:
  • code statement that initiates the block chain storage read and write request in each basic block respectively determine the first set of all program variables with fixed values in the code statement of each basic block, and each basic block
  • the code statement of the block will be used as the second set of all program variables for indexing data access requests to the blockchain system
  • the first set and the second set respectively determine the transformation function of each basic block.
  • the source determination module 704 is specifically configured to:
  • the contract division module 701 is specifically used for:
  • the read-write set building module 705 is specifically used for:
  • the target data source is composed of the transaction input of the smart contract to be processed, blockchain system environment information or constants, then based on the target data source, construct the read-write set of the smart contract to be processed.
  • the read/write determination module 702 is specifically configured to:
  • the device provided in the embodiment of the present application can be used to implement the technical solution of the above method embodiment, and its implementation principle and technical effect are similar, so the embodiments of the present application will not repeat them here.
  • FIG. 8 schematically provides a possible structural diagram of the block chain smart contract read-write set construction device described in this application.
  • a blockchain smart contract read-write set building device 800 includes at least one processor 801 and a communication interface 803 . Further optionally, a memory 802 and a bus 804 may also be included.
  • the blockchain smart contract read-write set building device 800 may be the above-mentioned processing device, which is not particularly limited in this application.
  • the number of processors 801 may be one or more, and FIG. 8 only shows one of the processors 801.
  • the processor 801 may be a central processing unit (central processing unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) or a digital signal processing (Digital Signal Process, DSP). If the block chain smart contract read-write set construction device 800 has multiple processors 801, the types of the multiple processors 801 may be different, or may be the same.
  • multiple processors 801 of the blockchain smart contract read-write set construction device 800 can also be integrated into a multi-core processor.
  • the memory 802 stores computer instructions and data; the memory 802 can store the computer instructions and data required to realize the above-mentioned block chain smart contract reading and writing set construction method provided by this application, for example, the memory 802 stores the data used to realize the above block chain smart contract Directives that read and write the steps of the set build method.
  • the memory 802 may be any one or any combination of the following storage media: non-volatile memory (such as read only memory (ROM), solid state disk (SSD), hard disk (HDD), optical disk), volatile memory.
  • the communication interface 803 may provide information input/output for the at least one processor. Any one or any combination of the following components may also be included: a network interface (such as an Ethernet interface), a wireless network card and other devices with network access functions.
  • a network interface such as an Ethernet interface
  • the communication interface 803 can also be used for data communication between the blockchain smart contract read-write set construction device 800 and other computing devices or terminals.
  • a thick line represents the bus 804 .
  • the bus 804 can connect the processor 801 with the memory 802 and the communication interface 803 .
  • the processor 801 can access the memory 802 through the bus 804 , and can also use the communication interface 803 to perform data interaction with other computing devices or terminals.
  • the blockchain smart contract read-write set construction device 800 executes the computer instructions in the memory 802, so that the blockchain smart contract read-write set construction device 800 realizes the above-mentioned blockchain smart contract read-write set provided by this application The construction method, or make the blockchain smart contract read-write set construction device 800 deploy the above-mentioned block chain smart contract read-write set construction device.
  • the memory 802 may include a contract division module 701 , a graph creation module 702 , a read-write determination module 703 , a source determination module 704 and a read-write set construction module 705 .
  • the inclusion here only refers to the functions of the contract division module, graph creation module, read-write determination module, source determination module and read-write set building module when the instructions stored in the memory are executed, and is not limited to the physical structure .
  • block chain smart contract reading and writing set construction equipment can be implemented not only through software as shown in Figure 8 above, but also as a hardware module, or as a circuit unit, through hardware.
  • the present application provides a computer-readable storage medium, the computer program product includes computer instructions, and the computer instructions instruct a computing device to execute the above-mentioned blockchain smart contract read-write set construction method provided by the present application.
  • the present application provides a computer program product, including computer instructions, and the computer instructions are executed by a processor to construct the above-mentioned block chain smart contract read-write set construction method provided in the present application.
  • the present application provides a chip, including at least one processor and a communication interface, and the communication interface provides information input and/or output for the at least one processor. Further, the chip may further include at least one memory, and the memory is used to store computer instructions. The at least one processor is used to call and run the computer instructions to execute the above-mentioned blockchain smart contract read-write set construction method provided by this application.
  • the disclosed devices and methods may be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of the units is only a logical function division. In actual implementation, there may be other division methods.
  • multiple units or components can be combined or May be integrated into another system, or some features may be ignored, or not implemented.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
  • the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
  • each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit.
  • the above-mentioned integrated units can be implemented in the form of hardware, or in the form of hardware plus software functional units.

Landscapes

  • Engineering & Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Theoretical Computer Science (AREA)
  • Accounting & Taxation (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • Finance (AREA)
  • Strategic Management (AREA)
  • General Business, Economics & Management (AREA)
  • Computing Systems (AREA)
  • Development Economics (AREA)
  • Economics (AREA)
  • Stored Programmes (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请提供一种区块链智能合约读写集构建方法及装置,该方法在编译待处理智能合约时,通过将该智能合约划分为一个或多个基本块,基于该一个或多个基本块,建立相应的控制流图,进而,基于该控制流图,确定图中每个基本块中发起区块链存储读写请求的代码语句,从而,根据该代码语句,确定目标数据来源,根据该目标数据来源,构建上述智能合约的读写集。其中,无需智能合约开发者参与,解决了现有由智能合约开发者构造交易读写集,增加智能合约开发者的心智负担和工作量的问题,降低了并行智能合约开发的复杂性,加快交易整体处理效率,而且,对智能合约开发者完全透明,较好地改善了开发者开发并行智能合约时的体验。

Description

区块链智能合约读写集构建方法及装置
本申请要求于2021年12月01日提交中国专利局、申请号为202111446793.6、申请名称为“区块链智能合约读写集构建方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及金融科技(Fintech)的区块链技术,尤其涉及一种区块链智能合约读写集构建方法及装置。
背景技术
随着计算机技术的发展,越来越多的技术应用在金融领域,传统金融业正在逐步向金融科技转变,区块链技术也不例外,但由于金融行业的安全性、实时性要求,其对区块链技术提出更高的要求。
当前分布式存储系统在金融行业中应用越来越广泛。区块链系统是一种多中心、防篡改、防抵赖的分布式存储系统,因此,区块链系统在金融行业中应用越来越多。对于现代的区块链系统来说,智能合约的发展是区块链技术发展的一个里程碑,提供了更加强大的逻辑功能,可以满足各种领域的业务要求将区块链从最初单一数字货币应用,发展融入到了多个领域。
在区块链系统中,为了提升交易整体处理效率,需要在保证区块链数据并发安全的前提下尽可能提高交易的并行处理能力。由于现有区块链系统中每笔交易都需要基于智能合约中读写集执行,因此为了提高交易的并行处理能力,现有一般由智能合约开发者在不执行交易时构造交易读写集,并在智能合约源代码中以元数据的方式声明交易的具体读写集构造规则。然而,现有交易读写集的构造要求智能合约开发者必须遵守一定规则,增加了智能合约开发者的心智负担和工作量,也增加了并行智能合约开发的复杂性,潜在地降低了交易整体处理效率。
发明内容
为解决现有技术中存在的问题,本申请提供一种区块链智能合约读写集构建方法及装置。
第一方面,本申请实施例提供一种区块链智能合约读写集构建方法,所述方法包括:
在编译待处理智能合约时,将所述待处理智能合约划分为一个或多个基本块;
基于所述一个或多个基本块,建立所述待处理智能合约对应的控制流图;
基于所述控制流图,确定所述控制流图的每个基本块中发起区块链存储读写请求的代码语句;
根据所述每个基本块中发起区块链存储读写请求的代码语句,确定目标数据来源;
根据所述目标数据来源,构建所述待处理智能合约的读写集。
在一种可能的实现方式中,所述基于所述一个或多个基本块,建立所述待处理智能合约对应的控制流图,包括:
基于所述一个或多个基本块,确定所述待处理智能合约的各个程序语句中的首语句以及跳转语句;
根据所述首语句和所述跳转语句的目标地址,建立所述待处理智能合约对应的所述控制流图。
在一种可能的实现方式中,所述根据所述首语句和所述跳转语句的目标地址,建立所述待处理智能合约对应的所述控制流图,包括:
根据所述首语句和所述跳转语句的目标地址,对所述各个程序语句进行排序,并对排序后的各个程序语句进行去重;
基于去重后各个程序语句,确定所述控制流图中的基本块节点,并基于所述去重后各个程序语句中每一跳转语句的目标地址,确定所述控制流图中由基本块指向目标地址所在的基本块的有向边;
根据所述基本块节点和所述有向边,建立所述待处理智能合约对应的所述控制流图。
在一种可能的实现方式中,所述根据所述每个基本块中发起区块链存储读写请求的代码语句,确定目标数据来源,包括:
根据所述每个基本块中发起区块链存储读写请求的代码语句,分别定位出读写过程中所述每个基本块中被用作键的程序变量;
基于所述每个基本块中被用作键的程序变量,确定所述目标数据来源。
在一种可能的实现方式中,所述根据所述每个基本块中发起区块链存储读写请求的代码语句,分别定位出读写过程中所述每个基本块中被用作键的程序变量,包括:
根据所述每个基本块中发起区块链存储读写请求的代码语句,分别确定所述每个基本块的转换函数,其中,所述转换函数用于基于一代码语句执行后的冲突域确定下一冲突域,所述冲突域为基本块中被用作键的程序变量的集合;
基于所述每个基本块的转换函数,分别定位出读写过程中所述每个基本块中被用作键的程序变量。
在一种可能的实现方式中,所述根据所述每个基本块中发起区块链存储读写请求的代码语句,分别确定所述每个基本块的转换函数,包括:
根据所述每个基本块中发起区块链存储读写请求的代码语句,分别确定所述每个基本块的代码语句中为定值的所有程序变量的第一集合,以及所述每个基本块的代码语句中会被用作索引向区块链系统发起数据访问请求的所有程序变量的第二集合;
根据所述第一集合和所述第二集合,分别确定所述每个基本块的转换函数。
在一种可能的实现方式中,所述基于所述每个基本块中被用作键的程序变量,确定所述目标数据来源,包括:
在所述每个基本块中被用作键的程序变量上添加预设标签;
将所述预设标签沿所述待处理智能合约的数据流转路径逆向传播至所述待处理智能合约执行的入口点,识别出所述每个基本块中被用作键的程序变量的目标数据来源。
在一种可能的实现方式中,所述将所述待处理智能合约划分为一个或多个基本块,包 括:
扫描所述待处理智能合约,确定所述待处理智能合约的代码结构;
根据所述代码结构以及预设的基本块条件,将所述待处理智能合约划分为所述一个或多个基本块。
在一种可能的实现方式中,所述根据所述目标数据来源,构建所述待处理智能合约的读写集,包括:
判断所述目标数据来源是否由所述待处理智能合约的交易输入、区块链系统环境信息或常量构成;
若所述目标数据来源是由所述待处理智能合约的交易输入、区块链系统环境信息或常量构成,则基于所述目标数据来源,构建所述待处理智能合约的读写集。
在一种可能的实现方式中,所述基于所述控制流图,确定所述控制流图的每个基本块中发起区块链存储读写请求的代码语句,包括:
获取预存的区块链存储的读写请求代码语句;
基于所述区块链存储的读写请求代码语句和所述控制流图,在所述每个基本块中识别出发起区块链存储读写请求的代码语句。
第二方面,本申请实施例提供一种区块链智能合约读写集构建装置,所述装置包括:
合约划分模块,用于在编译待处理智能合约时,将所述待处理智能合约划分为一个或多个基本块;
图形建立模块,用于基于所述一个或多个基本块,建立所述待处理智能合约对应的控制流图;
读写确定模块,用于基于所述控制流图,确定所述控制流图的每个基本块中发起区块链存储读写请求的代码语句;
来源确定模块,用于根据所述每个基本块中发起区块链存储读写请求的代码语句,确定目标数据来源;
读写集构建模块,用于根据所述目标数据来源,构建所述待处理智能合约的读写集。
在一种可能的实现方式中,所述图形建立模块,具体用于:
基于所述一个或多个基本块,确定所述待处理智能合约的各个程序语句中的首语句以及跳转语句;
根据所述首语句和所述跳转语句的目标地址,建立所述待处理智能合约对应的所述控制流图。
在一种可能的实现方式中,所述图形建立模块,具体用于:
根据所述首语句和所述跳转语句的目标地址,对所述各个程序语句进行排序,并对排序后的各个程序语句进行去重;
基于去重后各个程序语句,确定所述控制流图中的基本块节点,并基于所述去重后各个程序语句中每一跳转语句的目标地址,确定所述控制流图中由基本块指向目标地址所在的基本块的有向边;
根据所述基本块节点和所述有向边,建立所述待处理智能合约对应的所述控制流图。
在一种可能的实现方式中,所述来源确定模块,具体用于:
根据所述每个基本块中发起区块链存储读写请求的代码语句,分别定位出读写过程中 所述每个基本块中被用作键的程序变量;
基于所述每个基本块中被用作键的程序变量,确定所述目标数据来源。
在一种可能的实现方式中,所述来源确定模块,具体用于:
根据所述每个基本块中发起区块链存储读写请求的代码语句,分别确定所述每个基本块的转换函数,其中,所述转换函数用于基于一代码语句执行后的冲突域确定下一冲突域,所述冲突域为基本块中被用作键的程序变量的集合;
基于所述每个基本块的转换函数,分别定位出读写过程中所述每个基本块中被用作键的程序变量。
在一种可能的实现方式中,所述来源确定模块,具体用于:
根据所述每个基本块中发起区块链存储读写请求的代码语句,分别确定所述每个基本块的代码语句中为定值的所有程序变量的第一集合,以及所述每个基本块的代码语句中会被用作索引向区块链系统发起数据访问请求的所有程序变量的第二集合;
根据所述第一集合和所述第二集合,分别确定所述每个基本块的转换函数。
在一种可能的实现方式中,所述来源确定模块,具体用于:
在所述每个基本块中被用作键的程序变量上添加预设标签;
将所述预设标签沿所述待处理智能合约的数据流转路径逆向传播至所述待处理智能合约执行的入口点,识别出所述每个基本块中被用作键的程序变量的目标数据来源。
在一种可能的实现方式中,所述合约划分模块,具体用于:
扫描所述待处理智能合约,确定所述待处理智能合约的代码结构;
根据所述代码结构以及预设的基本块条件,将所述待处理智能合约划分为所述一个或多个基本块。
在一种可能的实现方式中,所述读写集构建模块,具体用于:
判断所述目标数据来源是否由所述待处理智能合约的交易输入、区块链系统环境信息或常量构成;
若所述目标数据来源是由所述待处理智能合约的交易输入、区块链系统环境信息或常量构成,则基于所述目标数据来源,构建所述待处理智能合约的读写集。
在一种可能的实现方式中,所述读写确定模块,具体用于:
获取预存的区块链存储的读写请求代码语句;
基于所述区块链存储的读写请求代码语句和所述控制流图,在所述每个基本块中识别出发起区块链存储读写请求的代码语句。
本申请实施例提供的区块链智能合约读写集构建方法及装置,该方法在编译待处理智能合约时,通过将该智能合约划分为一个或多个基本块,基于该一个或多个基本块,建立相应的控制流图,进而,基于该控制流图,确定图中每个基本块中发起区块链存储读写请求的代码语句,从而,根据该代码语句,确定目标数据来源,根据该目标数据来源,构建上述智能合约的读写集。其中,无需智能合约开发者参与,解决了现有由智能合约开发者构造交易读写集,增加智能合约开发者的心智负担和工作量的问题,降低了并行智能合约开发的复杂性,加快交易整体处理效率。而且,本申请实施例对智能合约开发者完全透明,智能合约开发者仅需要以编写串行合约的方式编写合约即可,较好地改善了开发者开发并行智能合约时的体验。
附图说明
图1为本申请实施例提供的一种区块链智能合约读写集构建系统架构示意图;
图2为本申请实施例提供的一种区块链智能合约读写集构建方法的流程示意图;
图3为本申请实施例提供的另一种区块链智能合约读写集构建方法的流程示意图;
图4为本申请实施例提供的一种建立控制流图的流程示意图;
图5为本申请实施例提供的某一智能合约对应的控制流图示意图;
图6为本申请实施例提供的再一种区块链智能合约读写集构建方法的流程示意图;
图7为本申请实施例提供的一种区块链智能合约读写集构建装置的结构示意图;
图8示出了本申请区块链智能合约读写集构建设备的一种可能的结构示意图。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”、“第三”及“第四”等(如果存在)是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的本申请的实施例能够以除了在这里图示或描述的那些以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。
当前在金融行业中,分布式存储系统的应用越来越广泛。例如随着金融行业中数据的爆发式增长,传统存储系统由于磁盘空间不足、处理能力有限等已经不能满足当前数据存储的要求,分布式存储系统的应用在一定程度上解决了传统存储系统的存储瓶颈。区块链系统是一种多中心、防篡改、防抵赖的分布式存储系统,因此,区块链系统在金融行业中应用越来越多。对于现代的区块链系统来说,智能合约的发展是区块链技术发展的一个里程碑,提供了更加强大的逻辑功能,可以满足各种领域的业务要求将区块链从最初单一数字货币应用,发展融入到了多个领域。
在现有技术方案中,区块链系统中每笔交易执行时都要基于交易读写集(读写集中所包含的键意味着对其所对应数据的排他性使用,例如在转账问题中,读写集中包含发起方账户地址及接受方账户地址),区块链的交易执行系统将不同交易组织为依赖关系图,并按照依赖图中的前后依赖关系调度交易并行执行。为了提升区块链系统中交易整体处理效率,区块链系统需要在保证区块链数据并发安全的前提下尽可能提高交易的并行处理能力。因此,现有一般由智能合约开发者在不执行交易时构造交易读写集,并在智能合约源代码中以元数据的方式声明交易的具体读写集构造规则。例如:对于简单的转账交易,每笔转账交易的读写集由交易输入参数中的发送者地址与接收者地址所共同构成。同时,智能合约开发者需要显式调用区块链底层系统所暴露的公开接口进行读写集注册。在执行相关交 易时,区块链的交易执行系统则会读取提前注册的读写集构造规则构建出交易的读写集,随后按照读写集中的内容将区块中的所有交易排列为交易依赖图并进行调度执行。
但是,现有读写集的构造增加了智能合约开发者在开发并行智能合约时的心智负担和工作量,开发者在指定交易读写集构造规则时必须十分谨慎,因为如果读写集构造规则没有正确声明,则极有可能导致区块链系统陷入无法一致共识的灾难性后果。而且,现有读写集的构造要求智能合约开发者必须遵守一定规则,例如按照要求在合约中实现读写集规则注册等接口,且数据依赖项的声明必须遵循一定格式规范,如若读写集来自于交易输入参数则必须将这些参数置于智能合约函数参数列表的前列,这些要求及规范均增加了智能合约开发的复杂性。另外,现有只有在智能合约开发者显式声明及注册读写集构造规则的智能合约,才能够获得区块链交易执行系统并行执行的机会,而其它虽然也能够被并行执行但其开发者未进行注册的智能合约则无法并行执行,从而潜在地降低了交易整体处理效率。
因此,本申请实施例提出一种区块链智能合约读写集构建方法,在编译期进行交易读写集构造规则分析,无需实际执行智能合约函数便可构建出该函数的读写集,其中,不用智能合约开发者参与,解决了现有由智能合约开发者构造交易读写集,增加智能合约开发者的心智负担和工作量的问题,降低了并行智能合约开发的复杂性,加快交易整体处理效率。而且,本申请实施例对智能合约开发者完全透明,智能合约开发者仅需要以编写串行合约的方式编写合约即可,因此较好地改善了开发者开发并行智能合约时的体验。
这里,在本申请实施例中,上述区块链系统可以理解是一种由多个节点共同维护的及信任的分布式存储系统。区块链底层是由一系列区块组成的一条链,每个块上除了记录本块的数据还会记录上一块的哈希值,通过这种方式组成链式的数据结构。一个区块由块头和块体组成,其中块头定义包括该区块高度、上一个区块的哈希值等重要字段,而块体主要存储交易数据。区块链利用密码学的方式保证数据传输和访问的安全,并利用链式结构保证链上数据不可被篡改。
上述智能合约可以理解是运行在区块链系统之上的一份代码和数据的集合,其中代码负责实现智能合约的功能,数据负责存储智能合约状态,智能合约可以接收和发送信息。
上述交易可以理解是在区块链中,任何操作(部署合约、调用合约接口等)都是通过发送交易的方式进行。交易由用户发起,并通过客户端发送至区块链节点。区块链节点在收到交易后,会将交易打包为区块并执行。
上述读写集可以理解是交易在执行期间,产生的读写集。读集包含了交易执行期间所读取的键的集合,写集合则是包含了所写入的键的集合。读集和写集中的键可重叠。
可选地,本申请提供的一种区块链智能合约读写集构建方法,可以适用于图1所示的区块链智能合约读写集构建系统架构示意图,图1以金融领域某一转账交易的智能合约中交易读写集构建为例。如图1所示,该系统可以包括接收装置101、处理装置102和显示装置103。
在具体实现过程中,接收装置101可以是输入/输出接口,也可以是通信接口,可以用于接收上述转账交易的智能合约。
处理装置102可以通过上述接收装置101获取上述智能合约,进而,对上述智能合约进行静态程序分析,在编译期进行交易读写集构造。其中,无需智能合约开发者参与,从 而减轻智能合约开发者的心智负担和工作量,降低了并行智能合约开发的复杂性,加快交易整体处理效率。而且,本申请实施例对智能合约开发者完全透明,智能合约开发者仅需要以编写串行合约的方式编写合约即可,因此较好地改善了开发者开发并行智能合约时的体验。
其中,上述静态程序分析可以理解是指在不运行程序的条件下,对某些程序属性进行分析的方法。静态程序分析的结果无法做到完全精确,对于执行路径无穷的程序(如包含无限递归的程序),无法枚举出所有程序可能的执行路径,即使执行路径有限,由于状态爆炸的问题往往也无法进行路径遍历,因此静态程序分析往往采用近似方法:即若原始的分析目标是对某个性质回答“是”或“否”,近似方法的目标则是将这一目标变为回答“是”、“否”或“不知道”,即允许出现不确定的回答,例如“这段程序可能有漏洞(bug)”。
另外,显示装置103可以用于对上述交易读写集构造过程等进行显示。
显示装置还可以是触摸显示屏,用于在显示的上述内容的同时接收用户指令,以实现与用户的交互。
而且,上述处理装置102在构造得到交易读写集后,可以将构造的交易读写集发送至交易执行系统。这样,交易执行系统可以按照读写集中的内容将区块中的所有交易排列为交易依赖图并进行调度执行。
应理解,上述处理装置可以通过处理器读取存储器中的指令并执行指令的方式实现,也可以通过芯片电路实现。
上述系统仅为一种示例性系统,具体实施时,可以根据应用需求设置。
可以理解的是,本申请实施例示意的结构并不构成对区块链智能合约读写集构建系统架构的具体限定。在本申请另一些可行的实施方式中,上述架构可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置,具体可根据实际应用场景确定,在此不做限制。图1所示的部件可以以硬件,软件,或软件与硬件的组合实现。
另外,本申请实施例描述的系统架构是为了更加清楚的说明本申请实施例的技术方案,并不构成对于本申请实施例提供的技术方案的限定,本领域普通技术人员可知,随着系统架构的演变和新业务场景的出现,本申请实施例提供的技术方案对于类似的技术问题,同样适用。
下面以几个实施例为例对本申请的技术方案进行描述,对于相同或相似的概念或过程可能在某些实施例不再赘述。
图2为本申请实施例提供的一种区块链智能合约读写集构建方法的流程示意图,本实施例的执行主体可以为图1所示实施例中的处理装置,具体可以根据实际情况确定。如图2所示,本申请实施例提供的区块链智能合约读写集构建方法包括如下步骤:
S201:在编译待处理智能合约时,将该待处理智能合约划分为一个或多个基本块。
其中,上述待处理智能合约可以根据实际情况确定,例如上述图1中所述的金融领域某一转账交易的智能合约。
这里,上述处理装置可以在编译上述待处理智能合约时,扫描上述待处理智能合约,确定上述待处理智能合约的代码结构,从而,根据该代码结构以及预设的基本块条件,将上述待处理智能合约划分为一个或多个基本块,这样使得后续的分析过程可以以基本块为 单位进行,批量处理程序语句,提高分析性能。
其中,上述预设的基本块条件可以包括下列条件:控制流只能从基本块的第一条程序语句进入该块,也就是说,没有跳转到基本块中间或末尾指令的转移语句;除了基本块的最后一条程序语句,控制流在离开基本块之前不会跳转或者停机等。
S202:基于上述一个或多个基本块,建立上述待处理智能合约对应的控制流图。
这里,控制流图可以理解是一个过程或程序的抽象表现,代表了一个程序执行过程中会遍历到的所有路径。控制流图用图的形式表示一个过程内所有基本块执行的可能流向。控制流图中每个顶点都对应一个基本块,并使用有向边来表示分支。
上述处理装置在编译智能合约时,通过扫描智能合约确定其代码结构,进而,基于该代码结构将智能合约划分为基本块,从而,基于该基本块建立相应的控制流图,获得程序执行过程中会遍历到的所有路径,便于后续处理,满足应用需要。
S203:基于上述控制流图,确定上述控制流图的每个基本块中发起区块链存储读写请求的代码语句。
示例性的,上述处理装置可以获取预存的区块链存储的读写请求代码语句,从而,基于该读写请求代码语句和上述控制流图,在上述控制流图的每个基本块中识别出发起区块链存储读写请求的代码语句。
其中,上述预存的区块链存储的读写请求代码语句可以是相关技术人员设置的。上述处理装置获取上述技术人员设置的信息,从而,基于该信息,在上述控制流图的每个基本块中识别出发起区块链存储读写请求的代码语句。
S204:根据上述每个基本块中发起区块链存储读写请求的代码语句,确定目标数据来源。
这里,上述处理装置可以在上述每个基本块中识别出发起区块链存储读写请求的代码语句,并通过调用语句所使用的参数定位出读写过程中每个基本块中被用作键的程序变量,从而,基于每个基本块中被用作键的程序变量,确定上述目标数据来源。例如,上述处理装置可以为上述程序变量添加预设标签,并将该标签沿数据流转路径逆向传播至智能合约执行的入口点,从而最终根据标签识别出上述程序变量的目标数据来源。
例如下述以Rust语言编写的智能合约代码为例:
1.pub fn transfer(&mut self,user_1:string,user_2:string){
2.user_1=user_2;
3.self.balance[&user_1]-=amount;
4.}
在代码第3行中,智能合约函数“transfer”会以“user_1”为索引,修改状态变量“balance”中对应的值,此语句会造成一次区块链存储的写请求。当上述处理装置编译该合约时,可以基于第3行代码,为“user_1”变量添加预设标签,随之将该标签在代码逻辑中逆向传播。第2行代码为赋值语句,即“user_1”变量的值由“user_2”变量赋予,因此上述标签传播至“user_2”变量。此后,逆向传播流程抵达合约函数“transfer”的入口点,分析过程结束,“transfer”函数的读写集来自于交易输入中“user_2”的值,即对于调用“transfer”合约函数的不同交易,只要交易输入中的“user_2”的值不相同,则这些交易在执行时一定不会发生读写冲突从而造成区块链数据状态异常。
另外,上述预设标签可以根据实际情况确定,例如在上述被用作键的程序变量上添加 标签“键”。上述预设标签用于突出上述被用作键的程序变量
S205:根据上述目标数据来源,构建上述待处理智能合约的读写集。
在本申请实施例中,上述处理装置可以判断上述目标数据来源是否由上述待处理智能合约的交易输入、区块链系统环境信息或常量构成。如果上述目标数据来源是由上述待处理智能合约的交易输入、区块链系统环境信息或常量构成,则上述处理装置可以基于上述目标数据来源,构建上述待处理智能合约的读写集,并可以将读写集中键的来源信息编码至程序输出中,这些信息可以为后续的智能合约执行系统所利用。
本申请实施例,上述处理装置在编译待处理智能合约时,通过将该智能合约划分为一个或多个基本块,基于该一个或多个基本块,建立相应的控制流图,进而,基于该控制流图,确定图中每个基本块中发起区块链存储读写请求的代码语句,从而,根据该代码语句,确定目标数据来源,根据该目标数据来源,构建上述智能合约的读写集。其中,无需智能合约开发者参与,解决了现有由智能合约开发者构造交易读写集,增加智能合约开发者的心智负担和工作量的问题,降低了并行智能合约开发的复杂性,加快交易整体处理效率。而且,本申请实施例对智能合约开发者完全透明,智能合约开发者仅需要以编写串行合约的方式编写合约即可,较好地改善了开发者开发并行智能合约时的体验。
另外,上述处理装置在建立上述待处理智能合约对应的控制流图时,考虑基于上述一个或多个基本块,确定上述待处理智能合约的各个程序语句中的首语句以及跳转语句,从而,根据该首语句和跳转语句的目标地址,建立上述待处理智能合约对应的控制流图,这样后续的分析过程可以以控制流图中的基本块为单位进行,批量处理程序语句,提高分析性能。图3为本申请实施例提出的另一种区块链智能合约读写集构建方法的流程示意图。如图3所示,该方法包括:
S301:在编译待处理智能合约时,将该待处理智能合约划分为一个或多个基本块。
其中,步骤S301与上述步骤S201的实现方式相同,此处不再赘述。
S302:基于上述一个或多个基本块,确定上述待处理智能合约的各个程序语句中的首语句以及跳转语句。
S303:根据上述首语句和跳转语句的目标地址,建立上述待处理智能合约对应的控制流图。
示例性的,上述处理装置建立控制流图的流程可以如图4所示。上述处理装置在确定上述待处理智能合约的各个程序语句中的首语句以及跳转语句后,可以根据上述首语句和跳转语句的目标地址,对上述各个程序语句进行排序,并对排序后的各个程序语句进行去重,进而,基于去重后各个程序语句,确定上述控制流图中的基本块节点,并基于去重后各个程序语句中每一跳转语句的目标地址,确定上述控制流图中由基本块指向目标地址所在的基本块的有向边,从而,根据上述基本块节点和有向边,建立上述待处理智能合约对应的控制流图。
例如对于下述智能合约函数
Figure PCTCN2022102164-appb-000001
Figure PCTCN2022102164-appb-000002
上述处理装置采用上述图4所示流程建立的该智能合约对应的控制流图可以如图5所示。
在本申请实施例中,如果采用代码实现上述处理装置建立控制流图的过程,可以包括如下步骤:
(1)创建有向图,用于存储待分析智能合约函数FN的控制流图;
(2)创建首语句列表L,L中存放了能够作为首语句的语句编号;
(3)令变量I=0,I用于作为编号索引FN的程序语句;
(4)若I大于或等于FN中程序语句的数目,则表示所有语句已处理完毕,跳转至(9),否则跳转至(5);
(5)若I等于0,则将I加入L中,跳转至(8);
(6)若FN中第I条程序语句为跳转语句,则将该跳转语句的目标地址加入L中,跳转至(8);
(7)若FN中第I-1条指令为跳转语句,则将I加入L中;
(8)令I=I+1,跳转至(4);
(9)对L中的语句编号进行排序;
(10)对L中的语句编号进行去重;
(11)令变量I=0,此时I用于作为编号索引L中的首语句;
(12)若I+1大于或等于L的长度,则跳转至(13),否则跳转至(14);
(13)令终止下标END=FN中语句的数目,跳转至(14);
(14)令终止下标END=L[I+1];
(15)令起始下标START=L[I];
(16)在控制流图中新建基本块节点,其中包含FN中语句序号位于[START,END)(半开半闭区间)之间的所有语句;
(17)I=I+1,跳转至(12);
(18)令I=0;
(19)若I大于或等于控制流图中基本块的数目,则跳转至(23),否则跳转至(20);
(20)令BB为控制流图中第I个基本块;
(21)若BB中最后一条语句为跳转语句,则在控制流图中建立一条由BB指向目标地址所在的基本块的有向边;
(22)I=I+1,跳转至(19);
(23)结束。
S304:基于上述控制流图,确定上述控制流图的每个基本块中发起区块链存储读写请求的代码语句。
S305:根据上述每个基本块中发起区块链存储读写请求的代码语句,确定目标数据来源。
S306:根据上述目标数据来源,构建上述待处理智能合约的读写集。
其中,步骤S304-S306与上述步骤S203-S205的实现方式相同,此处不再赘述。
在本申请实施例中,上述处理装置可以基于上述一个或多个基本块,确定上述待处理智能合约的各个程序语句中的首语句以及跳转语句,从而,根据该首语句和跳转语句的目标地址,建立上述待处理智能合约对应的控制流图,从而后续的分析过程可以以控制流图中的基本块为单位进行,批量处理程序语句,提高分析性能。而且,上述处理装置构建上述读写集的过程中无需智能合约开发者参与,解决了现有由智能合约开发者构造交易读写集,增加智能合约开发者的心智负担和工作量的问题,降低了并行智能合约开发的复杂性,加快交易整体处理效率。另外,本申请实施例对智能合约开发者完全透明,智能合约开发者仅需要以编写串行合约的方式编写合约即可,较好地改善了开发者开发并行智能合约时的体验。
这里,上述处理装置在根据上述每个基本块中发起区块链存储读写请求的代码语句,确定上述目标数据来源时,还考虑根据上述每个基本块中发起区块链存储读写请求的代码语句,分别定位出读写过程中每个基本块中被用作键的程序变量,进而,基于每个基本块中被用作键的程序变量,确定上述目标数据来源。其中,上述处理装置可以根据每个基本块的转换函数,定位出读写过程中每个基本块中被用作键的程序变量,进而识别出该程序变量的数据来源,在实际执行前构造出上述智能合约函数的读写集,减轻智能合约开发者的心智负担和工作量,降低并行智能合约开发的复杂性,加快交易整体处理效率。图6为本申请实施例提出的再一种区块链智能合约读写集构建方法的流程示意图。如图6所示,该方法包括:
S601:在编译待处理智能合约时,将该待处理智能合约划分为一个或多个基本块。
S602:基于上述一个或多个基本块,建立上述待处理智能合约对应的控制流图。
S603:基于上述控制流图,确定上述控制流图的每个基本块中发起区块链存储读写请求的代码语句。
其中,步骤S601-S603与上述步骤S201-S203的实现方式相同,此处不再赘述。
S604:根据上述每个基本块中发起区块链存储读写请求的代码语句,分别定位出读写过程中每个基本块中被用作键的程序变量。
这里,上述处理装置可以根据上述每个基本块中发起区块链存储读写请求的代码语句,分别确定每个基本块的转换函数,进而,基于每个基本块的转换函数,分别定位出读写过程中每个基本块中被用作键的程序变量。
其中,上述转换函数用于基于一代码语句执行后的冲突域确定下一冲突域,上述冲突域为基本块中被用作键的程序变量的集合。如果某个基本块的冲突域中有某个变量,则意味着在执行该基本块的程序语句之前,该变量中的值会被直接用作键向区块链系统发起数据访问请求。
另外,上述处理装置在确定每个基本块的转换函数时,可以根据每个基本块中发起区块链存储读写请求的代码语句,分别确定每个基本块的代码语句中为定值的所有程序变量的第一集合,以及每个基本块的代码语句中会被用作索引向区块链系统发起数据访问请求的所有程序变量的第二集合,从而,根据该第一集合和第二集合,分别确定每个基本块的转换函数。
其中,为了更好的理解上述处理装置确定每个基本块的转换函数的过程,在本申请实施例中,上述处理装置可以先确定智能合约函数中每条语句S对应的一个传播函数f s。f s用于基于数据传播方向上的前一条语句的冲突域计算经过语句S处理后得到新冲突域,该新冲突域会用于计算语句S处的读写集。f s的形式化可以表示为:
f S(x)=(x-def S)∪use S
其中,x作为输入,表示语句S执行之后的冲突域,def s表示语句S中定值的所有变量的集合,use s表示语句S中会被用作索引向区块链系统发起数据访问请求的变量的集合,∪表示并集。
这里上述def s与use s的定义可以如下:
Figure PCTCN2022102164-appb-000003
Figure PCTCN2022102164-appb-000004
其中,
Figure PCTCN2022102164-appb-000005
表示空集。Runtime表示以某个运行时计算出的值为键向区块链系统发起数据访问请求,Env表示以某种执行上下文信息为键向区块链系统发起数据访问请求。即当冲突域包含Runtime时,则意味着函数会以某个运行时计算出的值为键向区块链系统发起数据访问请求,同理,当冲突域包含Env时,则表示函数会以某种执行上下文信息为键向区块链系统发起数据访问请求。
进一步地,基于语句S的传播函数f s,上述处理装置可推出基本块BB的转换函数,即基本块BB的转换函数根据基本块的代码语句中为定值的所有程序变量的第一集合,以及基本块的代码语句中会被用作索引向区块链系统发起数据访问请求的所有程序变量的第二集合确定。
示例性的,基本块BB的转换函数可以表示为:
Figure PCTCN2022102164-appb-000006
其中,S 1,S 2,…,S n表示基本块BB中的第1条、第2条、……、第n条程序语句。
如果定义
Figure PCTCN2022102164-appb-000007
则上述转换函数f BB(x)可以表示为如下形式:
f BB(x)=(x-def BB)∪use BB
这里,如果采用代码实现上述处理装置基于每个基本块的转换函数,分别定位出读写过程中每个基本块中被用作键的程序变量的过程,即定位出读写过程中每个基本块的冲突域的过程,可以包括如下步骤:
(1)创建映射IN,其键为基本块,值为输入至该基本块的读写集;
(2)创建映射OUT,其键为基本块,值为经过该基本块的转换后输出的读写集;
(3)创建队列W,W终于存储待分析的基本块;
(4)令ENTRY为待分析智能合约函数入口所在的基本块;
(5)令变量I=0,I用于索引待分析智能合约函数的基本块;
(6)若I大于等于控制流图中基本块的数量,则跳转至(11),否则跳转至(7);
(7)令BB为控制流图中第I个基本块;
(8)令
Figure PCTCN2022102164-appb-000008
其中
Figure PCTCN2022102164-appb-000009
表示空集;
(9)将BB添加至W尾部;
(10)令I=I+1,跳转至(6);
(11)若W不为空,则跳转至(12),否则跳转至(25);
(12)从W头部弹出一个基本块并放置于BB中;
(13)令OLD_IN=IN[BB];
(14)令
Figure PCTCN2022102164-appb-000010
(15)令变量J=0,J用于索引BB的后继基本块;
(16)若J大于等于BB的后继基本块的数目,则跳转至(20),否则跳转至(17);
(17)令C为BB的第J个后继基本块;
(18)令OUT[BB]=OUT[BB]∪IN[C];
(19)J=J+1,跳转至(16);
(20)令IN[BB]=(OUT[BB]-def BB)∪use BB
(21)若变量Runtime包含于IN[BB]中,则跳转至(22);否则跳转至(23);
(22)IN[ENTRY]={Runtime},跳转至(25);
(23)若OLD_IN不等于IN[BB],则跳转至(24),否则跳转至(11);
(24)将BB的所有前驱基本块添加至W的尾部;
(25)输出IN[ENTRY];
(26)结束。
这里,对于图5控制流图对应的智能合约,在建立控制流图后,采用上述代码,基于每个基本块的转换函数,分别定位出读写过程中每个基本块中被用作键的程序变量,即定位出读写过程中每个基本块的冲突域,各基本块的冲突域变化情况如下表所示:
Figure PCTCN2022102164-appb-000011
Figure PCTCN2022102164-appb-000012
这里,上述处理装置确定IN[ENTRY]为{S1,S2,S3},即智能合约函数“foo”的读写集由交易输入中的S1、S2、S3参数构成。
另外,在本申请实施例中确保并发安全性,在数据传播方向上若某个基本块BB拥有多个前驱节点,即多个不同的基本块可通过不同的执行路径到达基本块BB,则BB的冲突域为各路径上计算所得的冲突域的并集,即忽略程序的分支语句,近似认为所有路径都可能到达。
S605:基于上述每个基本块中被用作键的程序变量,确定目标数据来源。
示例性的,上述处理装置可以在上述每个基本块中被用作键的程序变量上添加预设标签,进而,将该标签沿上述待处理智能合约的数据流转路径逆向传播至上述待处理智能合约执行的入口点,识别出每个基本块中被用作键的程序变量的目标数据来源。如果该目标数据来源是由待处理智能合约的交易输入、区块链系统环境信息或常量构成,则上述处理装置可以在实际执行上述智能合约函数前构造出上述智能合约的读写集,进而,将读写集中键的来源信息编码至程序输出中,为后续的智能合约执行系统所利用,在保证区块链数据并发安全的前提下尽可能提高交易的并行处理能力。
S606:根据上述目标数据来源,构建上述待处理智能合约的读写集。
其中,步骤S606与上述步骤S205的实现方式相同,此处不再赘述。
本申请实施例,上述处理装置在根据上述每个基本块中发起区块链存储读写请求的代码语句,确定上述目标数据来源时,还考虑根据上述每个基本块中发起区块链存储读写请求的代码语句,分别定位出读写过程中每个基本块中被用作键的程序变量,进而,基于每个基本块中被用作键的程序变量,确定上述目标数据来源,在实际执行前构造出上述智能合约函数的读写集,减轻智能合约开发者的心智负担和工作量,降低并行智能合约开发的复杂性,加快交易整体处理效率。而且,本申请实施例对智能合约开发者完全透明,智能合约开发者仅需要以编写串行合约的方式编写合约即可,较好地改善了开发者开发并行智能合约时的体验。
对应于上文实施例的区块链智能合约读写集构建方法,图7为本申请实施例提供的区块链智能合约读写集构建装置的结构示意图。为了便于说明,仅示出了与本申请实施例相关的部分。图7为本申请实施例提供的一种区块链智能合约读写集构建装置的结构示意图,该区块链智能合约读写集构建装置70包括:合约划分模块701、图形建立模块702、读写确定模块703、来源确定模块704以及读写集构建模块705。这里的区块链智能合约读写集构建装置可以是上述处理装置本身,或者是实现处理装置的功能的芯片或者集成电路。这里需要说明的是,合约划分模块、图形建立模块、读写确定模块、来源确定模块以及读 写集构建模块的划分只是一种逻辑功能的划分,物理上两者可以是集成的,也可以是独立的。
其中,合约划分模块701,用于在编译待处理智能合约时,将所述待处理智能合约划分为一个或多个基本块。
图形建立模块702,用于基于所述一个或多个基本块,建立所述待处理智能合约对应的控制流图。
读写确定模块703,用于基于所述控制流图,确定所述控制流图的每个基本块中发起区块链存储读写请求的代码语句。
来源确定模块704,用于根据所述每个基本块中发起区块链存储读写请求的代码语句,确定目标数据来源。
读写集构建模块705,用于根据所述目标数据来源,构建所述待处理智能合约的读写集。
在一种可能的设计中,所述图形建立模块702,具体用于:
基于所述一个或多个基本块,确定所述待处理智能合约的各个程序语句中的首语句以及跳转语句;
根据所述首语句和所述跳转语句的目标地址,建立所述待处理智能合约对应的所述控制流图。
在一种可能的实现方式中,所述图形建立模块702,具体用于:
根据所述首语句和所述跳转语句的目标地址,对所述各个程序语句进行排序,并对排序后的各个程序语句进行去重;
基于去重后各个程序语句,确定所述控制流图中的基本块节点,并基于所述去重后各个程序语句中每一跳转语句的目标地址,确定所述控制流图中由基本块指向目标地址所在的基本块的有向边;
根据所述基本块节点和所述有向边,建立所述待处理智能合约对应的所述控制流图。
在一种可能的实现方式中,所述来源确定模块704,具体用于:
根据所述每个基本块中发起区块链存储读写请求的代码语句,分别定位出读写过程中所述每个基本块中被用作键的程序变量;
基于所述每个基本块中被用作键的程序变量,确定所述目标数据来源。
在一种可能的实现方式中,所述来源确定模块704,具体用于:
根据所述每个基本块中发起区块链存储读写请求的代码语句,分别确定所述每个基本块的转换函数,其中,所述转换函数用于基于一代码语句执行后的冲突域确定下一冲突域,所述冲突域为基本块中被用作键的程序变量的集合;
基于所述每个基本块的转换函数,分别定位出读写过程中所述每个基本块中被用作键的程序变量。
在一种可能的实现方式中,所述来源确定模块704,具体用于:
根据所述每个基本块中发起区块链存储读写请求的代码语句,分别确定所述每个基本块的代码语句中为定值的所有程序变量的第一集合,以及所述每个基本块的代码语句中会被用作索引向区块链系统发起数据访问请求的所有程序变量的第二集合;
根据所述第一集合和所述第二集合,分别确定所述每个基本块的转换函数。
在一种可能的实现方式中,所述来源确定模块704,具体用于:
在所述每个基本块中被用作键的程序变量上添加预设标签;
将所述预设标签沿所述待处理智能合约的数据流转路径逆向传播至所述待处理智能合约执行的入口点,识别出所述每个基本块中被用作键的程序变量的目标数据来源。
在一种可能的实现方式中,所述合约划分模块701,具体用于:
扫描所述待处理智能合约,确定所述待处理智能合约的代码结构;
根据所述代码结构以及预设的基本块条件,将所述待处理智能合约划分为所述一个或多个基本块。
在一种可能的实现方式中,所述读写集构建模块705,具体用于:
判断所述目标数据来源是否由所述待处理智能合约的交易输入、区块链系统环境信息或常量构成;
若所述目标数据来源是由所述待处理智能合约的交易输入、区块链系统环境信息或常量构成,则基于所述目标数据来源,构建所述待处理智能合约的读写集。
在一种可能的实现方式中,所述读写确定模块702,具体用于:
获取预存的区块链存储的读写请求代码语句;
基于所述区块链存储的读写请求代码语句和所述控制流图,在所述每个基本块中识别出发起区块链存储读写请求的代码语句。
本申请实施例提供的装置,可用于执行上述方法实施例的技术方案,其实现原理和技术效果类似,本申请实施例此处不再赘述。
可选地,图8示意性地提供本申请所述区块链智能合约读写集构建设备的一种可能的结构示意图。
参见图8,区块链智能合约读写集构建设备800包括至少一个处理器801以及通信接口803。进一步可选的,还可以包括存储器802和总线804。
其中,区块链智能合约读写集构建设备800可以是上述处理装置,本申请对此不作特别限制。区块链智能合约读写集构建设备800中,处理器801的数量可以是一个或多个,图8仅示意了其中一个处理器801。可选地,处理器801,可以是中央处理器(central processing unit,CPU)、图形处理器(Graphics Processing Unit,GPU)或者数字信号处理(Digital Signal Process,DSP)。如果区块链智能合约读写集构建设备800具有多个处理器801,多个处理器801的类型可以不同,或者可以相同。可选地,区块链智能合约读写集构建设备800的多个处理器801还可以集成为多核处理器。
存储器802存储计算机指令和数据;存储器802可以存储实现本申请提供的上述区块链智能合约读写集构建方法所需的计算机指令和数据,例如,存储器802存储用于实现上述区块链智能合约读写集构建方法的步骤的指令。存储器802可以是以下存储介质的任一种或任一种组合:非易失性存储器(例如只读存储器(ROM)、固态硬盘(SSD)、硬盘(HDD)、光盘),易失性存储器。
通信接口803可以为所述至少一个处理器提供信息输入/输出。也可以包括以下器件的任一种或任一种组合:网络接口(例如以太网接口)、无线网卡等具有网络接入功能的器件。
可选的,通信接口803还可以用于区块链智能合约读写集构建设备800与其它计算设 备或者终端进行数据通信。
进一步可选的,图8用一条粗线表示总线804。总线804可以将处理器801与存储器802和通信接口803连接。这样,通过总线804,处理器801可以访问存储器802,还可以利用通信接口803与其它计算设备或者终端进行数据交互。
在本申请中,区块链智能合约读写集构建设备800执行存储器802中的计算机指令,使得区块链智能合约读写集构建设备800实现本申请提供的上述区块链智能合约读写集构建方法,或者使得区块链智能合约读写集构建设备800部署上述的区块链智能合约读写集构建装置。
从逻辑功能划分来看,示例性的,如图8所示,存储器802中可以包括合约划分模块701、图形建立模块702、读写确定模块703、来源确定模块704以及读写集构建模块705。这里的包括仅仅涉及存储器中所存储的指令被执行时可以分别实现合约划分模块、图形建立模块、读写确定模块、来源确定模块以及读写集构建模块的功能,而不限定是物理上的结构。
另外,上述的区块链智能合约读写集构建设备除了可以像上述图8通过软件实现外,也可以作为硬件模块,或者作为电路单元,通过硬件实现。
本申请提供一种计算机可读存储介质,所述计算机程序产品包括计算机指令,所述计算机指令指示计算设备执行本申请提供的上述区块链智能合约读写集构建方法。
本申请提供一种计算机程序产品,包括计算机指令,所述计算机指令被处理器执行本申请提供的上述区块链智能合约读写集构建方法。
本申请提供一种芯片,包括至少一个处理器和通信接口,所述通信接口为所述至少一个处理器提供信息输入和/或输出。进一步,所述芯片还可以包含至少一个存储器,所述存储器用于存储计算机指令。所述至少一个处理器用于调用并运行该计算机指令,以执行本申请提供的上述区块链智能合约读写集构建方法。
在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。

Claims (14)

  1. 一种区块链智能合约读写集构建方法,其特征在于,包括:
    在编译待处理智能合约时,将所述待处理智能合约划分为一个或多个基本块;
    基于所述一个或多个基本块,建立所述待处理智能合约对应的控制流图;
    基于所述控制流图,确定所述控制流图的每个基本块中发起区块链存储读写请求的代码语句;
    根据所述每个基本块中发起区块链存储读写请求的代码语句,确定目标数据来源;
    根据所述目标数据来源,构建所述待处理智能合约的读写集。
  2. 根据权利要求1所述的方法,其特征在于,所述基于所述一个或多个基本块,建立所述待处理智能合约对应的控制流图,包括:
    基于所述一个或多个基本块,确定所述待处理智能合约的各个程序语句中的首语句以及跳转语句;
    根据所述首语句和所述跳转语句的目标地址,建立所述待处理智能合约对应的所述控制流图。
  3. 根据权利要求2所述的方法,其特征在于,所述根据所述首语句和所述跳转语句的目标地址,建立所述待处理智能合约对应的所述控制流图,包括:
    根据所述首语句和所述跳转语句的目标地址,对所述各个程序语句进行排序,并对排序后的各个程序语句进行去重;
    基于去重后各个程序语句,确定所述控制流图中的基本块节点,并基于所述去重后各个程序语句中每一跳转语句的目标地址,确定所述控制流图中由基本块指向目标地址所在的基本块的有向边;
    根据所述基本块节点和所述有向边,建立所述待处理智能合约对应的所述控制流图。
  4. 根据权利要求1至3中任一项所述的方法,其特征在于,所述根据所述每个基本块中发起区块链存储读写请求的代码语句,确定目标数据来源,包括:
    根据所述每个基本块中发起区块链存储读写请求的代码语句,分别定位出读写过程中所述每个基本块中被用作键的程序变量;
    基于所述每个基本块中被用作键的程序变量,确定所述目标数据来源。
  5. 根据权利要求4所述的方法,其特征在于,所述根据所述每个基本块中发起区块链存储读写请求的代码语句,分别定位出读写过程中所述每个基本块中被用作键的程序变量,包括:
    根据所述每个基本块中发起区块链存储读写请求的代码语句,分别确定所述每个基本块的转换函数,其中,所述转换函数用于基于一代码语句执行后的冲突域确定下一冲突域,所述冲突域为基本块中被用作键的程序变量的集合;
    基于所述每个基本块的转换函数,分别定位出读写过程中所述每个基本块中被用作键的程序变量。
  6. 根据权利要求5所述的方法,其特征在于,所述根据所述每个基本块中发起区块链存储读写请求的代码语句,分别确定所述每个基本块的转换函数,包括:
    根据所述每个基本块中发起区块链存储读写请求的代码语句,分别确定所述每个基本块的代码语句中为定值的所有程序变量的第一集合,以及所述每个基本块的代码语句中会被用作索引向区块链系统发起数据访问请求的所有程序变量的第二集合;
    根据所述第一集合和所述第二集合,分别确定所述每个基本块的转换函数。
  7. 根据权利要求4至6中任一项所述的方法,其特征在于,所述基于所述每个基 本块中被用作键的程序变量,确定所述目标数据来源,包括:
    在所述每个基本块中被用作键的程序变量上添加预设标签;
    将所述预设标签沿所述待处理智能合约的数据流转路径逆向传播至所述待处理智能合约执行的入口点,识别出所述每个基本块中被用作键的程序变量的目标数据来源。
  8. 根据权利要求1至7中任一项所述的方法,其特征在于,所述将所述待处理智能合约划分为一个或多个基本块,包括:
    扫描所述待处理智能合约,确定所述待处理智能合约的代码结构;
    根据所述代码结构以及预设的基本块条件,将所述待处理智能合约划分为所述一个或多个基本块。
  9. 根据权利要求1至8中任一项所述的方法,其特征在于,所述根据所述目标数据来源,构建所述待处理智能合约的读写集,包括:
    判断所述目标数据来源是否由所述待处理智能合约的交易输入、区块链系统环境信息或常量构成;
    若所述目标数据来源是由所述待处理智能合约的交易输入、区块链系统环境信息或常量构成,则基于所述目标数据来源,构建所述待处理智能合约的读写集。
  10. 根据权利要求1至9中任一项所述的方法,其特征在于,所述基于所述控制流图,确定所述控制流图的每个基本块中发起区块链存储读写请求的代码语句,包括:
    获取预存的区块链存储的读写请求代码语句;
    基于所述区块链存储的读写请求代码语句和所述控制流图,在所述每个基本块中识别出发起区块链存储读写请求的代码语句。
  11. 一种区块链智能合约读写集构建装置,其特征在于,包括:
    合约划分模块,用于在编译待处理智能合约时,将所述待处理智能合约划分为一个或多个基本块;
    图形建立模块,用于基于所述一个或多个基本块,建立所述待处理智能合约对应的控制流图;
    读写确定模块,用于基于所述控制流图,确定所述控制流图的每个基本块中发起区块链存储读写请求的代码语句;
    来源确定模块,用于根据所述每个基本块中发起区块链存储读写请求的代码语句,确定目标数据来源;
    读写集构建模块,用于根据所述目标数据来源,构建所述待处理智能合约的读写集。
  12. 一种区块链智能合约读写集构建设备,其特征在于,包括:处理器,以及与所述处理器通信连接的存储器;
    所述存储器存储计算机执行指令;
    所述处理器执行所述存储器存储的计算机执行指令,以实现如权利要求1至10任一项所述的方法。
  13. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中存储有计算机执行指令,当处理器执行所述计算机执行指令时,实现如权利要求1至10任一项所述的方法。
  14. 一种计算机程序产品,包括计算机程序,其特征在于,所述计算机程序被处理器执行时实现如权利要求1至10任一项所述的方法。
PCT/CN2022/102164 2021-12-01 2022-06-29 区块链智能合约读写集构建方法及装置 WO2023098058A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111446793.6A CN113867709B (zh) 2021-12-01 2021-12-01 区块链智能合约读写集构建方法及装置
CN202111446793.6 2021-12-01

Publications (1)

Publication Number Publication Date
WO2023098058A1 true WO2023098058A1 (zh) 2023-06-08

Family

ID=78985503

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/102164 WO2023098058A1 (zh) 2021-12-01 2022-06-29 区块链智能合约读写集构建方法及装置

Country Status (2)

Country Link
CN (1) CN113867709B (zh)
WO (1) WO2023098058A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113867709B (zh) * 2021-12-01 2022-04-12 深圳前海微众银行股份有限公司 区块链智能合约读写集构建方法及装置

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20200201843A1 (en) * 2018-12-19 2020-06-25 International Business Machines Corporation Optimization of chaincode statements
CN112669155A (zh) * 2020-12-31 2021-04-16 杭州趣链科技有限公司 基于区块链的交易分发执行方法、装置服务器及存储介质
US20210318859A1 (en) * 2020-04-13 2021-10-14 International Business Machines Corporation Optimization of execution of smart contracts
CN113688186A (zh) * 2021-08-25 2021-11-23 工银科技有限公司 智能合约执行方法、引擎及区块链节点
CN113867709A (zh) * 2021-12-01 2021-12-31 深圳前海微众银行股份有限公司 区块链智能合约读写集构建方法及装置

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11521202B2 (en) * 2018-08-30 2022-12-06 International Business Machines Corporation Distributed computing and storage network implementing high integrity, high bandwidth, low latency, secure processing
CN111259395B (zh) * 2020-01-16 2022-10-18 图灵人工智能研究院(南京)有限公司 智能合约的利用程序获取方法、装置及存储介质
US11362826B2 (en) * 2020-03-18 2022-06-14 International Business Machines Corporation Endorsement process for non-deterministic application
CN113872948A (zh) * 2020-08-31 2021-12-31 支付宝(杭州)信息技术有限公司 一种执行智能合约的方法、区块链节点和节点设备

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20200201843A1 (en) * 2018-12-19 2020-06-25 International Business Machines Corporation Optimization of chaincode statements
US20210318859A1 (en) * 2020-04-13 2021-10-14 International Business Machines Corporation Optimization of execution of smart contracts
CN112669155A (zh) * 2020-12-31 2021-04-16 杭州趣链科技有限公司 基于区块链的交易分发执行方法、装置服务器及存储介质
CN113688186A (zh) * 2021-08-25 2021-11-23 工银科技有限公司 智能合约执行方法、引擎及区块链节点
CN113867709A (zh) * 2021-12-01 2021-12-31 深圳前海微众银行股份有限公司 区块链智能合约读写集构建方法及装置

Also Published As

Publication number Publication date
CN113867709A (zh) 2021-12-31
CN113867709B (zh) 2022-04-12

Similar Documents

Publication Publication Date Title
Ganty et al. Algorithmic verification of asynchronous programs
US20180158034A1 (en) Dynamic reordering of blockchain transactions to optimize performance and scalability
JP2020522790A (ja) 異種にプログラムされたデータ処理システムの自動依存性アナライザ
Bouajjani et al. Bounded phase analysis of message-passing programs
US20180203746A1 (en) Analysis of application programming interface usage for improving a computer system
CN109508326B (zh) 用于处理数据的方法、装置和系统
WO2008156969A1 (en) Discoscript: a simplified distributed computing scripting language
US10666774B2 (en) Message processing
WO2023098058A1 (zh) 区块链智能合约读写集构建方法及装置
Vasilakis et al. Pash: Light-touch data-parallel shell processing
US9910889B2 (en) Rapid searching and matching of data to a dynamic set of signatures facilitating parallel processing and hardware acceleration
US9430196B2 (en) Message inlining
Bedő BioShake: a Haskell EDSL for bioinformatics workflows
Good The proof of a distributed system in Gypsy
EP4226294A1 (en) Methods and apparatus for parallel quantum computing
US8046750B2 (en) Disco: a simplified distributed computing library
CN113626062A (zh) 可信的应用集成
US20210049016A1 (en) Efficient performance of inner loops on a multi-lane processor
Li et al. Asynchronous multi-process timed automata
Anand et al. Synthesizing and verifying multicore parallelism in categories of nested code graphs
Caires et al. The session abstract machine
Idris et al. MRPack: Multi-algorithm execution using compute-intensive approach in mapreduce
US11188316B2 (en) Performance optimization of class instance comparisons
US20240111694A1 (en) Node identification allocation in a multi-tile system with multiple derivatives
CN112347122B (zh) Sql工作流处理方法、装置、电子设备和存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22899878

Country of ref document: EP

Kind code of ref document: A1