CN110825363B - Intelligent contract acquisition method and device, electronic equipment and storage medium - Google Patents

Intelligent contract acquisition method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN110825363B
CN110825363B CN201911065071.9A CN201911065071A CN110825363B CN 110825363 B CN110825363 B CN 110825363B CN 201911065071 A CN201911065071 A CN 201911065071A CN 110825363 B CN110825363 B CN 110825363B
Authority
CN
China
Prior art keywords
source
intelligent contract
byte
byte code
codes
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN201911065071.9A
Other languages
Chinese (zh)
Other versions
CN110825363A (en
Inventor
刘兴文
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Knownsec Information Technology Co Ltd
Original Assignee
Beijing Knownsec Information Technology Co Ltd
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 Beijing Knownsec Information Technology Co Ltd filed Critical Beijing Knownsec Information Technology Co Ltd
Priority to CN201911065071.9A priority Critical patent/CN110825363B/en
Publication of CN110825363A publication Critical patent/CN110825363A/en
Application granted granted Critical
Publication of CN110825363B publication Critical patent/CN110825363B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The application provides an intelligent contract acquisition method, an intelligent contract acquisition device, electronic equipment and a storage medium, and relates to the technical field of digital protocols. The method comprises the following steps: acquiring byte codes of the intelligent contract; dividing the byte code of the intelligent contract into a plurality of byte code fragments by taking a function as a unit; inquiring in a comparison database based on the comparison value of each byte code segment to obtain a source code segment corresponding to each byte code segment, wherein the comparison database stores the corresponding relation between each byte code segment and each source code segment; and generating the source codes of the intelligent contracts according to the source code fragments corresponding to each byte code fragment. The method comprises the steps of firstly determining the byte codes of the intelligent contract, then determining the source codes of the intelligent contract without the source codes by the known corresponding relation between the byte codes and the source codes, avoiding the complicated manual reverse acquisition of the source codes of the intelligent contract, and improving the reverse acquisition efficiency of the intelligent contract.

Description

Intelligent contract acquisition method and device, electronic equipment and storage medium
Technical Field
The present application relates to the technical field of digital protocols, and in particular, to an intelligent contract acquiring method, an intelligent contract acquiring device, an electronic device, and a storage medium.
Background
With the rapid development of blockchain and other technologies, hundreds of thousands of intelligent contracts are already running on various websites, such as ethernet workshops and the like. Smart contracts are a special protocol aimed at providing, verifying and executing contracts. In particular, intelligent contracts are an important reason that blockchains are called "decentralised" and allow us to perform traceable, irreversible and secure transactions without the need for third parties. The smart contract contains all the information about the transaction and the resulting operation is only performed after the requirements are met. The smart contracts differ from traditional paper contracts in that they are computer generated. Thus, the code itself interprets the relevant obligations of the participants.
When intelligent contracts are used, knowledge of key functions and the like of the intelligent contracts are beneficial to better utilizing the intelligent contracts. However, most intelligent contracts do not disclose source codes, and under certain requirements, we may need to reverse the intelligent contracts, analyze functions and related information in the intelligent contracts, and the prior art generally disassembles byte codes into contract assemblies by manually reversing the intelligent contracts, relying on expertise and experience of reverse engineers, and disassembles the contract assemblies into source codes, so that the efficiency of acquiring the intelligent contracts is low.
Disclosure of Invention
Accordingly, an objective of the embodiments of the present application is to provide a method, an apparatus, an electronic device and a storage medium for acquiring an intelligent contract, so as to solve the problem of low efficiency of acquiring an intelligent contract in the prior art.
The embodiment of the application provides an intelligent contract acquisition method, which comprises the following steps: acquiring byte codes of the intelligent contract; dividing the byte code of the intelligent contract into a plurality of byte code fragments by taking a function as a unit; inquiring in a comparison database based on the comparison value of each byte code segment to obtain a source code segment corresponding to each byte code segment, wherein the comparison database stores the corresponding relation between each byte code segment and each source code segment; and generating the source codes of the intelligent contracts according to the source code fragments corresponding to each byte code fragment.
In the implementation manner, the intelligent contracts without the public source codes are subjected to byte code analysis, then the comparison database is inquired, and the corresponding source codes of the acquired byte codes are determined based on the corresponding relation between the byte codes and the source codes in the comparison database, so that the intelligent contract source codes are reversely acquired, complicated steps of compiling, decompiling and the like of the byte codes in a manual mode by a professional are not needed, and the efficiency of reversely acquiring the intelligent contract source codes is improved.
Optionally, the partitioning the bytecode of the smart contract into a plurality of bytecode fragments in units of functions includes: based on the function boundary feature and the flow jump feature, the bytecode of the smart contract is partitioned into the plurality of bytecode fragments in function units.
In the implementation manner, the byte code segmentation is performed by taking the function as a unit by using the function limit or the flow jump, so that the byte code of the intelligent contract can be accurately divided into a plurality of byte code fragments, and the characteristics of open source intelligent contract source codes acquired from the intelligent contract release platform are met.
Optionally, the method further comprises: acquiring source codes and byte codes of one or more open source intelligent contracts; dividing the source code of the open source intelligent contract into a plurality of source code fragments by using a regular expression and taking a function as a unit; dividing the byte code of the open source intelligent contract into a plurality of byte code fragments by taking a function as a unit based on a function limit characteristic and a flow jump characteristic; determining a comparison value for each byte code segment of the open source intelligent contract; and creating the comparison database based on the one-to-one correspondence of the comparison value of each byte code segment of the open source intelligent contract and each source code segment of the open source intelligent contract.
In the implementation manner, the comparison database is established based on the byte codes and the source codes of the open-source intelligent contracts by taking the functions as units, and the byte codes and the source codes of all the open-source intelligent contracts in the comparison database are in one-to-one correspondence, so that the efficiency of acquiring the intelligent contract source codes through the comparison database is improved.
Optionally, the obtaining the source code and the byte code of one or more open source smart contracts includes: based on the address in each open source intelligent contract, respectively creating a byte code folder and a source code folder, wherein each open source intelligent contract corresponds to one byte code folder and one source code folder; and inputting the byte codes of each open-source intelligent contract into a corresponding byte code folder, and inputting the source codes of each open-source intelligent contract into a corresponding source code folder.
In the implementation manner, the byte codes and the source codes are respectively stored in the byte code folder and the source code folder based on the address in each open source intelligent contract, and the corresponding folders are processed in batches when the byte codes and the source codes are acquired, so that the intelligent contract acquisition efficiency is further improved.
Optionally, the check value is a hash value, and the determining the check value of each byte code segment of the open source smart contract includes: a hash value of each byte code fragment of the open source smart contract is determined.
In the implementation manner, the hash value is used as a comparison value, the corresponding source code is determined and acquired through the hash value, and the situation that the source code of the open source intelligent contract is reversely acquired through compiling and decompiling the byte code in a manual identification mode is avoided, so that the source code determining efficiency is improved.
Optionally, the creating the comparison database by using a one-to-one correspondence between the comparison value of each byte code segment of the open source intelligent contract and each source code segment of the open source intelligent contract includes: determining the mapping between the byte code fragments of the open source intelligent contract and the source code fragments of the open source intelligent contract corresponding to the same function; and based on the mapping, establishing the comparison database by taking a comparison value of each byte code segment of the open source intelligent contract as a main key and taking each source code segment of the open source intelligent contract as a value.
In the implementation manner, the comparison value of the byte code fragments of the open source intelligent contract is used as the main key and the source code fragment positions, and the byte code fragments and the source code fragments are stored in a one-to-one correspondence manner, and a comparison database is created, so that the one-to-one correspondence between the byte code fragments and the source code fragments is realized.
The embodiment of the application also provides an intelligent contract acquisition device, which comprises: the acquisition module is used for acquiring byte codes of the intelligent contract; the division module is used for dividing the byte code of the intelligent contract into a plurality of byte code fragments by taking a function as a unit; the comparison module is used for inquiring in a comparison database based on the comparison value of each byte code segment to obtain a source code segment corresponding to each byte code segment, wherein the comparison database stores the corresponding relation between each byte code segment and each source code segment; and the assembly module is used for generating the source codes of the intelligent contracts according to the source code fragments corresponding to each byte code fragment.
In the implementation manner, the intelligent contracts without the public source codes are subjected to byte code analysis, then the comparison database is inquired, and the corresponding source codes of the acquired byte codes are determined based on the corresponding relation between the byte codes and the source codes in the comparison database, so that the intelligent contract source codes are reversely acquired, complicated steps of compiling, decompiling and the like of the byte codes in a manual mode by a professional are not needed, and the efficiency of reversely acquiring the intelligent contract source codes is improved.
Optionally, the segmentation module is specifically configured to: based on the function boundary feature and the flow jump feature, the bytecode of the smart contract is partitioned into the plurality of bytecode fragments in function units.
In the implementation manner, the byte code segmentation is performed by taking the function as a unit by using the function limit or the flow jump, so that the byte code of the intelligent contract can be accurately divided into a plurality of byte code fragments, and the characteristics of open source intelligent contract source codes acquired from the intelligent contract release platform are met.
Optionally, the apparatus further includes a database creation module, and the acquisition module is further configured to: acquiring source codes and byte codes of one or more open source intelligent contracts; the segmentation module is also used for: dividing the source code of the open source intelligent contract into a plurality of source code fragments by using a regular expression and taking a function as a unit; the segmentation module is also used for: dividing the byte code of the open source intelligent contract into a plurality of byte code fragments by taking a function as a unit based on a function limit characteristic and a flow jump characteristic; the control module is further for: determining a comparison value for each byte code segment of the open source intelligent contract; the database creation module is used for: and creating the comparison database based on the one-to-one correspondence of the comparison value of each byte code segment of the open source intelligent contract and each source code segment of the open source intelligent contract.
In the implementation manner, the comparison database is established based on the byte codes and the source codes of the open-source intelligent contracts by taking the functions as units, and the byte codes and the source codes of all the open-source intelligent contracts in the comparison database are in one-to-one correspondence, so that the efficiency of acquiring the intelligent contract source codes through the comparison database is improved.
Optionally, the acquiring module is specifically further configured to: based on the address in each open source intelligent contract, respectively creating a byte code folder and a source code folder, wherein each open source intelligent contract corresponds to one byte code folder and one source code folder; and inputting the byte codes of each open-source intelligent contract into a corresponding byte code folder, and inputting the source codes of each open-source intelligent contract into a corresponding source code folder.
In the implementation manner, the byte codes and the source codes are respectively stored in the byte code folder and the source code folder based on the address in each open source intelligent contract, and the corresponding folders are processed in batches when the byte codes and the source codes are acquired, so that the intelligent contract acquisition efficiency is further improved.
Optionally, the comparison value is a hash value, and the comparison module is specifically further configured to: a hash value of each byte code fragment of the open source smart contract is determined.
In the implementation manner, the hash value is used as a comparison value, the corresponding source code is determined and acquired through the hash value, and the situation that the source code of the open source intelligent contract is reversely acquired through compiling and decompiling the byte code in a manual identification mode is avoided, so that the source code determining efficiency is improved.
Optionally, the comparison database creation module is specifically configured to: determining the mapping between the byte code fragments of the open source intelligent contract and the source code fragments of the open source intelligent contract corresponding to the same function; and based on the mapping, establishing the comparison database by taking a comparison value of each byte code segment of the open source intelligent contract as a main key and taking each source code segment of the open source intelligent contract as a value.
In the implementation manner, the comparison value of the byte code fragments of the open source intelligent contract is used as the main key and the source code fragment positions, and the byte code fragments and the source code fragments are stored in a one-to-one correspondence manner, and a comparison database is created, so that the one-to-one correspondence between the byte code fragments and the source code fragments is realized.
The embodiment of the application also provides electronic equipment, which comprises a memory and a processor, wherein the memory stores program instructions, and the processor executes the steps in any implementation mode when reading and running the program instructions.
Embodiments of the present application also provide a readable storage medium having stored therein computer program instructions which, when read and executed by a processor, perform the steps of any of the above implementations.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments of the present application will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and should not be considered as limiting the scope, and other related drawings can be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic flow chart of an intelligent contract obtaining method according to an embodiment of the present application;
FIG. 2 is a flowchart illustrating a comparison database creation step according to an embodiment of the present application;
FIG. 3 is a schematic diagram of smart contract information issued by the public smart contract issuing platform according to the present embodiment;
FIG. 4 is a schematic diagram illustrating a byte code segmentation step according to an embodiment of the present application;
fig. 5 is a schematic block diagram of an intelligent contract obtaining apparatus according to an embodiment of the present application.
Icon: 30-smart contract acquisition means; 31-an acquisition module; 32-a segmentation module; 33-a control module; 34-assembling the module.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the accompanying drawings in the embodiments of the present application.
The inventor researches and discovers that the existing method for reversely acquiring the source codes of the intelligent contracts without the source is generally to disassemble the byte codes into contract assemblies by manual reverse and relying on the expertise and experience of reverse engineers, and then to disassemble the contract assemblies into the source codes. The method relies on manual mode, so that the method has high requirements on reverse engineers, and meanwhile, a lot of effort and time are required to be spent in reversing an intelligent contract, so that the efficiency is low.
In order to solve the above problems, the embodiments of the present application provide an intelligent contract obtaining method, which uses the source code and the byte code of the disclosed intelligent contract to reversely restore the unpublished intelligent contract. Referring to fig. 1, fig. 1 is a flowchart of an intelligent contract obtaining method according to an embodiment of the present application. The specific steps of the intelligent contract acquisition method can be as follows:
Step S11: byte codes of the smart contract are obtained.
It should be appreciated that this embodiment is illustrated by solidity, and in other examples, programming languages such as LLL, serpent, etc. may be used.
Byte-code (Byte-code) is a binary file consisting of a sequence of op-code or data pairs that contains an executing program. Bytecode is an intermediate code that is more abstract than machine code, often seen as a binary file containing an executing program, much like an object model. The bytecodes are called as such because each bytecode is typically one byte long, but the length of the instruction code varies.
Alternatively, the bytecodes of the smart contracts may be obtained by a corresponding compiler, and typically the specific bytecodes of each function call may be determined.
Step S12: the bytecode of the smart contract is divided into a plurality of bytecode fragments in units of functions.
Specifically, the present embodiment may divide the bytecode of the smart contract into a plurality of bytecode fragments based on the function boundary feature and the flow jump feature in units of functions.
The byte code instruction stream is single byte aligned, the operands of the byte code instruction stream are special and are divided by taking 4 bytes as boundaries, and corresponding gaps are reserved for realizing the alignment, so that the byte code instruction stream can be functionally divided according to the function boundary characteristics of the byte code.
The flow jump instruction in the bytecode is usually a boundary for jumping from one function to the next, so this embodiment can realize the splitting of the bytecode through the flow jump feature, such as unconditional jump instruction goto, goto_w, conditional jump instruction ifeq, iflt, ifle, ifne, ifgt, ifge, ifnull, ifnonnull, and the like.
Step S13: and inquiring in a comparison database based on the comparison value of each byte code segment to obtain a source code segment corresponding to each byte code segment.
The corresponding relation between each byte code segment and each source code segment is stored in the comparison database, and the query function of the corresponding source code segment of the byte code segment can be realized through field matching or other matching mechanisms.
It should be understood that the reference value in this embodiment may be a hash value, or may be a specified string or other identification code that can be associated with a byte code segment one-to-one.
Step S14: and generating the source codes of the intelligent contracts according to the source code fragments corresponding to each byte code fragment.
And combining all source code fragments obtained based on the byte codes to obtain the complete source code of the unopened intelligent contract.
In the steps S11-S14, the byte code analysis is performed on the intelligent contracts without the public source codes to obtain the split byte code fragments taking the single function as a unit, and then the corresponding source codes of the acquired byte codes are determined based on the corresponding relation between the byte code fragments and the source code fragments in the comparison database by querying the comparison database, so that the complete source codes of the intelligent contracts without the public source codes are reversely acquired, and complicated steps such as assembling, decompiling and the like are not needed by professionals through a manual mode, thereby improving the efficiency of reversely acquiring the intelligent contract source codes.
As an alternative embodiment, for the comparison database, the comparison database should be created before performing the comparison query of the bytecode fragments and the source code fragments at step S13. Referring to fig. 2, fig. 2 is a flowchart illustrating a comparison database creation step according to an embodiment of the present application. The specific sub-steps of the comparison database creation step may be as follows:
step S21: source code and bytecode of one or more open source smart contracts are obtained.
Alternatively, the source code and the bytecode of the open source smart contract in this embodiment may be obtained by a public smart contract issuing platform, for example, ethernet, etc. Referring to fig. 3, fig. 3 is a schematic diagram of smart contract information issued by the public smart contract issuing platform according to the present embodiment. Wherein, "functiondiv (uint 256 a, uint256 b)" to "return c; the "part is the source code of the smart contract, and the" ContractCreation Code "successor is the bytecode of the smart contract.
Specifically, a byte code folder and a source code folder can be respectively created based on the address in each open source intelligent contract, wherein each open source intelligent contract corresponds to one byte code folder and one source code folder; the byte code of each open source intelligent contract is input into a corresponding byte code folder, and the source code of each open source intelligent contract is input into a corresponding source code folder.
For example, if the address of a smart contract is 0x00a0b00aebeb f3be5aa5dcb6301b61ab4001e42, the byte code folder at that address may be 0x00a0b00ae b2f3be5a 5bc6301b 61abs 4001e42.Byte, and the source code folder may be 0x00a0b00ae b2f3be5a 5bc6301b 61abs 4001e42.Sol.
Step S22: and dividing the source code of the open source intelligent contract into a plurality of source code fragments by using the regular expression and taking the function as a unit.
According to the embodiment, each source code folder can be treated as a whole, so that the segmentation efficiency of source codes is improved.
Please refer to the following function:
The source code can be divided into two functions by a regular expression, namely:
function test()public{
c=100;
}
And
function add()public{
c=a+b;
}
Step S23: based on the function limit feature and the flow jump feature, the byte code of the open source intelligent contract is divided into a plurality of byte code fragments in a function unit.
The embodiment can treat each byte code folder as a whole, thereby improving the segmentation efficiency of byte codes.
Specifically, referring to fig. 4, fig. 4 is a schematic diagram of a byte code segmentation step provided in an embodiment of the present application, wherein "6080604052348015600f5760080 … … c634300050b0032" on the left side is a byte code file before segmentation, and "5b603d604756 … … b00" and "5b6045605656 … … 5b00" on the right side are two byte codes obtained after segmentation in function units.
Step S24: a comparison value is determined for each byte code segment of the open source smart contract.
In this embodiment, the hash value is used as a reference value, and a hash encryption algorithm needs to be performed on each byte code segment, so as to obtain a corresponding hash value. Alternatively, the hash encryption algorithm may be MD5, SHA-1, SHA-2, SHA-3, SHA-256, or the like.
In byte code fragment encryption based on the SHA-3 hash encryption algorithm, the hash values of "5b603d604756 … … b00" and "5b6045605656 … … 5b00" may be "76273e86f80a83733b244cd46da140ca" and "8add1e3bfa3153f39d81b50b40d0af98", respectively.
In the steps, the hash value is used as a comparison value, corresponding source codes are determined and acquired through the hash value, and the situation that the source codes of the open source intelligent contract are reversely acquired by compiling and decompiling the byte codes in a manual identification mode is avoided, so that the source code determining efficiency is improved.
Step S25: a comparison database is created based on the one-to-one correspondence of the comparison value of each byte code segment of the open source smart contract with each source code segment of the open source smart contract.
Specifically, step S25 may include the following sub-steps: determining the mapping between the byte code fragments of the open source intelligent contract and the source code fragments of the open source intelligent contract corresponding to the same function; based on the mapping, a comparison database is created with the comparison value of each byte code segment of the open source intelligent contract as a primary key and with each source code segment of the open source intelligent contract as a value.
Alternatively, the comparison database may be MySQL, oracle, or other types of databases, and the byte code segments, the source code segments, and their corresponding relationships may be stored in a table or other manner.
Referring to table 1, table 1 is a schematic table of a comparison database according to an embodiment of the present application.
TABLE 1
In the implementation manner, the comparison value of the byte code fragments of the open source intelligent contract is used as the main key and the source code fragment positions, and the byte code fragments and the source code fragment positions are stored in one-to-one correspondence, and a comparison database is created, so that one-to-one correspondence between the byte code fragments and the source code fragments is realized, and the corresponding query efficiency of the source codes and the byte codes is improved.
In order to better execute the intelligent contract acquiring method provided by the embodiment, the embodiment of the application further provides an intelligent contract acquiring device 30. Referring to fig. 5, fig. 5 is a schematic block diagram of an intelligent contract obtaining apparatus according to an embodiment of the present application.
The smart contract acquiring apparatus 30 includes:
an obtaining module 31, configured to obtain a byte code of the intelligent contract;
A partitioning module 32 for partitioning the bytecode of the smart contract into a plurality of bytecode fragments in units of functions;
The comparison module 33 is configured to query in a comparison database based on the comparison value of each byte code segment to obtain a source code segment corresponding to each byte code segment, where the comparison database stores a correspondence between each byte code segment and each source code segment;
and the assembly module 34 is configured to generate the source code of the intelligent contract according to the source code segment corresponding to each byte code segment.
Optionally, the segmentation module 32 is specifically configured to: based on the function boundary feature and the flow jump feature, the bytecode of the intelligent contract is divided into a plurality of bytecode fragments in function units.
Optionally, the smart contract acquiring apparatus 30 further includes a database creation module, and the acquiring module 31 is further configured to acquire source codes and byte codes of one or more open source smart contracts; the segmentation module 32 is further configured to segment the source code of the open-source intelligent contract into a plurality of source code segments by using the regular expression and using the function as a unit; the partitioning module 32 is further configured to partition the bytecode of the open-source intelligent contract into a plurality of bytecode fragments in units of a function based on the function boundary feature and the flow jump feature; the collation module 33 is further configured to determine a collation value for each byte code fragment of the open source smart contract; the database creation module is used for creating a comparison database based on the one-to-one correspondence between the comparison value of each byte code segment of the open source intelligent contract and each source code segment of the open source intelligent contract.
Optionally, the obtaining module 31 is specifically configured to create a byte code folder and a source code folder based on the address in each open source intelligent contract, where each open source intelligent contract corresponds to one byte code folder and one source code folder; the byte code of each open source intelligent contract is input into a corresponding byte code folder, and the source code of each open source intelligent contract is input into a corresponding source code folder.
Optionally, the control module 33 is specifically further configured to: a hash value is determined for each byte code segment of the open source smart contract.
Optionally, the comparison database creation module is specifically configured to: determining the mapping between the byte code fragments of the open source intelligent contract and the source code fragments of the open source intelligent contract corresponding to the same function; based on the mapping, a comparison database is created with the comparison value of each byte code segment of the open source intelligent contract as a primary key and with each source code segment of the open source intelligent contract as a value.
The embodiment of the application also provides electronic equipment, which comprises a memory and a processor, wherein the memory stores program instructions, and when the processor reads and runs the program instructions, the steps of any one of the intelligent contract acquisition methods provided by the embodiment are executed.
It should be understood that the electronic device may be an electronic device having a logic computing function, such as a personal computer (personal computer, PC), a tablet computer, a smart phone, a Personal Digital Assistant (PDA), or the like.
The embodiment of the application also provides a readable storage medium, wherein the readable storage medium stores computer program instructions which execute the steps in the intelligent contract acquisition method when being read and executed by a processor.
In summary, the embodiment of the application provides an intelligent contract obtaining method, an intelligent contract obtaining device, electronic equipment and a storage medium, wherein the intelligent contract obtaining method comprises the following steps: acquiring byte codes of the intelligent contract; dividing the byte code of the intelligent contract into a plurality of byte code fragments by taking the function as a unit; inquiring in a comparison database based on the comparison value of each byte code segment to obtain a source code segment corresponding to each byte code segment, wherein the comparison database stores the corresponding relation between each byte code segment and each source code segment; and generating the source codes of the intelligent contracts according to the source code fragments corresponding to each byte code fragment.
In the implementation manner, the intelligent contracts without the public source codes are subjected to byte code analysis, then the comparison database is inquired, and the corresponding source codes of the acquired byte codes are determined based on the corresponding relation between the byte codes and the source codes in the comparison database, so that the intelligent contract source codes are reversely acquired, complicated steps of compiling, decompiling and the like of the byte codes in a manual mode by a professional are not needed, and the efficiency of reversely acquiring the intelligent contract source codes is improved.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus may be implemented in other manners. The apparatus embodiments described above are merely illustrative, for example, block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of devices according to various embodiments of the present application. In this regard, each block in the block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams, and combinations of blocks in the block diagrams, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, functional modules in the embodiments of the present application may be integrated together to form a single part, or each module may exist alone, or two or more modules may be integrated to form a single part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. The present embodiment therefore also provides a readable storage medium having stored therein computer program instructions which, when read and executed by a processor, perform the steps of any one of the methods of block data storage. Based on this understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a RanDOm Access Memory (RAM), a magnetic disk or an optical disk, or other various media capable of storing program codes.
The above description is only an example of the present application and is not intended to limit the scope of the present application, and various modifications and variations will be apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the protection scope of the present application. It should be noted that: like reference numerals and letters denote like items in the following figures, and thus once an item is defined in one figure, no further definition or explanation thereof is necessary in the following figures.
The foregoing is merely illustrative of the present application, and the present application is not limited thereto, and any person skilled in the art will readily recognize that variations or substitutions are within the scope of the present application.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "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 may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.

Claims (8)

1. An intelligent contract acquisition method, characterized in that the method comprises:
Acquiring byte codes of the intelligent contract;
dividing the byte code of the intelligent contract into a plurality of byte code fragments by taking a function as a unit;
Inquiring in a comparison database based on the comparison value of each byte code segment to obtain a source code segment corresponding to each byte code segment, wherein the comparison database stores the corresponding relation between each byte code segment and each source code segment;
generating the source code of the intelligent contract according to the source code segment corresponding to each byte code segment;
Wherein the method further comprises: acquiring source codes and byte codes of one or more open source intelligent contracts; dividing the source code of the open source intelligent contract into a plurality of source code fragments by using a regular expression and taking a function as a unit; dividing the byte code of the open source intelligent contract into a plurality of byte code fragments by taking a function as a unit based on a function limit characteristic and a flow jump characteristic; determining a comparison value for each byte code segment of the open source intelligent contract; and creating the comparison database based on the one-to-one correspondence of the comparison value of each byte code segment of the open source intelligent contract and each source code segment of the open source intelligent contract.
2. The method of claim 1, wherein the partitioning the bytecode of the smart contract into a plurality of bytecode fragments in units of functions comprises:
Based on the function boundary feature and the flow jump feature, the bytecode of the smart contract is partitioned into the plurality of bytecode fragments in function units.
3. The method of claim 2, wherein the obtaining the source code and the bytecode of the one or more open source smart contracts comprises:
based on the address in each open source intelligent contract, respectively creating a byte code folder and a source code folder, wherein each open source intelligent contract corresponds to one byte code folder and one source code folder;
and inputting the byte codes of each open-source intelligent contract into a corresponding byte code folder, and inputting the source codes of each open-source intelligent contract into a corresponding source code folder.
4. The method of claim 1, wherein the collation value is a hash value, and wherein the determining the collation value for each bytecode fragment of the open source smart contract comprises:
A hash value of each byte code fragment of the open source smart contract is determined.
5. The method of claim 1, wherein said creating the comparison database in a one-to-one correspondence of the comparison value of each byte code segment of the open source smart contract with each source code segment of the open source smart contract comprises:
determining the mapping between the byte code fragments of the open source intelligent contract and the source code fragments of the open source intelligent contract corresponding to the same function;
And based on the mapping, establishing the comparison database by taking a comparison value of each byte code segment of the open source intelligent contract as a main key and taking each source code segment of the open source intelligent contract as a value.
6. An intelligent contract acquisition apparatus, the apparatus comprising:
The acquisition module is used for acquiring byte codes of the intelligent contract;
the division module is used for dividing the byte code of the intelligent contract into a plurality of byte code fragments by taking a function as a unit;
The comparison module is used for inquiring in a comparison database based on the comparison value of each byte code segment to obtain a source code segment corresponding to each byte code segment, wherein the comparison database stores the corresponding relation between each byte code segment and each source code segment;
The assembly module is used for generating the source codes of the intelligent contracts according to the source code fragments corresponding to each byte code fragment;
wherein the device further comprises a database creation module;
The acquisition module is also used for acquiring source codes and byte codes of one or more open-source intelligent contracts;
the segmentation module is further used for segmenting the source codes of the open-source intelligent contracts into a plurality of source code fragments by taking functions as units through regular expressions;
The segmentation module is further used for segmenting the byte code of the open source intelligent contract into a plurality of byte code fragments by taking a function as a unit based on the function limit characteristic and the flow jump characteristic;
the control module is further used for determining a control value of each byte code segment of the open source intelligent contract;
and the database creation module is used for creating the comparison database based on the one-to-one correspondence between the comparison value of each byte code segment of the open source intelligent contract and each source code segment of the open source intelligent contract.
7. An electronic device comprising a memory and a processor, the memory having stored therein program instructions, which when read and executed by the processor, perform the steps of the method of any of claims 1-5.
8. A storage medium having stored therein computer program instructions which, when executed by a processor, perform the steps of the method of any of claims 1-5.
CN201911065071.9A 2019-11-01 2019-11-01 Intelligent contract acquisition method and device, electronic equipment and storage medium Active CN110825363B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911065071.9A CN110825363B (en) 2019-11-01 2019-11-01 Intelligent contract acquisition method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911065071.9A CN110825363B (en) 2019-11-01 2019-11-01 Intelligent contract acquisition method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN110825363A CN110825363A (en) 2020-02-21
CN110825363B true CN110825363B (en) 2024-05-17

Family

ID=69552257

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911065071.9A Active CN110825363B (en) 2019-11-01 2019-11-01 Intelligent contract acquisition method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN110825363B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117688623A (en) * 2020-07-01 2024-03-12 陈子祺 Trusted computing chip based on blockchain
CN111768183B (en) 2020-08-31 2024-04-19 支付宝(杭州)信息技术有限公司 Method for executing intelligent contract, block chain node and storage medium
CN111770204B (en) 2020-08-31 2021-10-22 支付宝(杭州)信息技术有限公司 Method for executing intelligent contract, block chain node and storage medium
CN111768184A (en) 2020-08-31 2020-10-13 支付宝(杭州)信息技术有限公司 Method for executing intelligent contract and block link point
CN111770202B (en) 2020-08-31 2021-10-29 支付宝(杭州)信息技术有限公司 Method for executing intelligent contract, block chain node and storage medium
CN113110843B (en) * 2021-03-05 2023-04-11 卓尔智联(武汉)研究院有限公司 Contract generation model training method, contract generation method and electronic equipment
CN114091111B (en) * 2021-09-09 2022-11-18 深圳前海微众银行股份有限公司 Method and device for storing intelligent contracts of block chains

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102236575A (en) * 2011-07-20 2011-11-09 复旦大学 Dynamical compilation method based on register mapping
CN107274186A (en) * 2017-05-11 2017-10-20 上海点融信息科技有限责任公司 The method and apparatus that intelligent contract-defined interface is obtained in block chain
CN108846753A (en) * 2018-06-06 2018-11-20 北京京东尚科信息技术有限公司 Method and apparatus for handling data
CN109460406A (en) * 2018-10-15 2019-03-12 咪咕文化科技有限公司 Data processing method and device
CN110096338A (en) * 2019-05-10 2019-08-06 百度在线网络技术(北京)有限公司 Intelligent contract executes method, apparatus, equipment and medium
CN110297689A (en) * 2019-05-06 2019-10-01 百度在线网络技术(北京)有限公司 Intelligent contract executes method, apparatus, equipment and medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160321039A1 (en) * 2015-04-29 2016-11-03 Wave Computing, Inc. Technology mapping onto code fragments

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102236575A (en) * 2011-07-20 2011-11-09 复旦大学 Dynamical compilation method based on register mapping
CN107274186A (en) * 2017-05-11 2017-10-20 上海点融信息科技有限责任公司 The method and apparatus that intelligent contract-defined interface is obtained in block chain
CN108846753A (en) * 2018-06-06 2018-11-20 北京京东尚科信息技术有限公司 Method and apparatus for handling data
CN109460406A (en) * 2018-10-15 2019-03-12 咪咕文化科技有限公司 Data processing method and device
CN110297689A (en) * 2019-05-06 2019-10-01 百度在线网络技术(北京)有限公司 Intelligent contract executes method, apparatus, equipment and medium
CN110096338A (en) * 2019-05-10 2019-08-06 百度在线网络技术(北京)有限公司 Intelligent contract executes method, apparatus, equipment and medium

Also Published As

Publication number Publication date
CN110825363A (en) 2020-02-21

Similar Documents

Publication Publication Date Title
CN110825363B (en) Intelligent contract acquisition method and device, electronic equipment and storage medium
US20120317421A1 (en) Fingerprinting Executable Code
CN112631611B (en) Intelligent Pompe deception contract identification method and device
US9721120B2 (en) Preventing unauthorized calls to a protected function
JP2022009556A (en) Method for securing software codes
US10409572B2 (en) Compiled file normalization
Aronson et al. Towards an engineering approach to file carver construction
US10394763B2 (en) Method and device for generating pileup file from compressed genomic data
CN111078279A (en) Processing method, device and equipment of byte code file and storage medium
CN106055375A (en) Application program installation method and device
US20120151600A1 (en) Method and system for protecting intellectual property in software
Li et al. Juxtapp and dstruct: Detection of similarity among android applications
WO2021151347A1 (en) Ios application-based reinforcement method, apparatus, device, and storage medium
CN111260080A (en) Process optimization method, device, terminal and storage medium based on machine learning
US9563635B2 (en) Automated recognition of patterns in a log file having unknown grammar
CN114201756A (en) Vulnerability detection method and related device for intelligent contract code segment
CN109977675B (en) Open source software identification method and device
US10235165B2 (en) Creating optimized shortcuts
JP6674048B2 (en) Judgment device, judgment method and judgment program
CN111221690A (en) Model determination method and device for integrated circuit design and terminal
CN113703753B (en) Method and device for product development and product development system
JP6209901B2 (en) Character data processing method, program, and information processing apparatus
CN110648219B (en) Method and device for standardizing input area of bank transaction system
US20210336973A1 (en) Method and system for detecting malicious or suspicious activity by baselining host behavior
CN116107991A (en) Container label database construction method and device, storage medium and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant