A smart contract deployment method and apparatus, a computing device, and a storage medium
By using preset conversion rules and reverse conversion rules in the blockchain system to determine the consistency of encryption algorithms between the development end and the blockchain nodes, the problem of invalid deployment of smart contracts due to inconsistent encryption algorithms is solved, thus improving the deployment efficiency of smart contracts.
Patent Information
- Application Number
- CN202311063539.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-22
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2043-08-22
AI Technical Summary
Because blockchain systems support multiple encryption schemes, the encryption scheme configured on the development side may be inconsistent with the encryption scheme configured on the blockchain nodes. This causes smart contracts to be compiled into bytecode that the blockchain nodes cannot correctly recognize, resulting in invalid smart contract deployment and reduced project delivery efficiency.
Before deploying a smart contract, the first bytecode from the development side is obtained and processed according to preset conversion rules to ensure that it is consistent with the encryption algorithm of the blockchain node. Preset reverse conversion rules are used to determine whether it can be deployed correctly, thus avoiding incorrect deployment.
It improves the efficiency of smart contract deployment, avoids erroneous deployment problems caused by inconsistent encryption algorithms, and ensures that smart contracts can be correctly identified and deployed.
Smart Images

Figure CN117176406B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of blockchain, and more particularly to a smart contract deployment method, apparatus, computing device, and storage medium. Background Technology
[0002] Currently, because many blockchain systems support multiple encryption schemes, it is easy for the encryption scheme configured by the user on the development side to be inconsistent with the encryption scheme configured on the blockchain node. This leads to inconsistencies between the encryption algorithms used on the development side and the corresponding encryption algorithms on the blockchain node. For example, the hash algorithm used on the development side may be SHA-256 in the international cryptographic system, while the hash algorithm used on the blockchain node may be SM3 in the Chinese cryptographic system. This causes the development side to compile the smart contract into bytecode that the blockchain node cannot correctly recognize, resulting in the smart contract being incorrectly deployed and thus rendering the smart contract invalid and reducing project delivery efficiency.
[0003] In summary, there is an urgent need for a smart contract deployment method to improve the deployment efficiency of smart contracts in multi-cryptographic blockchains. Summary of the Invention
[0004] This invention provides a smart contract deployment method, apparatus, computing device, and storage medium to improve the deployment efficiency of smart contracts in multi-cryptographic blockchains.
[0005] In a first aspect, the present invention provides a smart contract deployment method applied to a blockchain node. The method includes: obtaining first bytecode from a development end, wherein the first bytecode is obtained by the development end processing original bytecode according to a first encryption algorithm and a preset conversion rule, and the original bytecode is obtained by the development end processing a smart contract according to the first encryption algorithm; then, processing the first bytecode according to a preset inverse conversion rule to obtain original bytecode, wherein the preset inverse conversion rule is the inverse operation of a preset conversion rule; then, processing the original bytecode according to a second encryption algorithm configured in the blockchain node and the preset conversion rule to obtain second bytecode; and if the first bytecode and the second bytecode are consistent, deploying the original bytecode to the blockchain.
[0006] In the above method, the development end processes the original bytecode according to the first encryption algorithm configured by the user to obtain first bytecode that represents the first encryption algorithm. The blockchain node processes the original bytecode according to the second encryption algorithm configured by the blockchain node to obtain second bytecode that represents the second encryption algorithm. By comparing the first bytecode and the second bytecode, it can be determined whether the first encryption algorithm configured by the user on the development end and the second encryption algorithm configured by the blockchain node are the same. If the first bytecode and the second bytecode are the same, it indicates that the first encryption algorithm configured by the user on the development end and the second encryption algorithm configured by the blockchain node are the same, that is, the first encryption algorithm deployed by the user on the development end is correct, and the blockchain node can correctly identify the original bytecode, thus allowing the original bytecode to be deployed to the blockchain. In this way, it is possible to avoid the blockchain node deploying original bytecode that cannot be correctly identified to the blockchain, thereby avoiding the problem of incorrect smart contract deployment and improving the deployment efficiency of smart contracts.
[0007] Optionally, the original bytecode is processed according to the second encryption algorithm configured in the blockchain node and the preset conversion rules to obtain the second bytecode, including: processing the first ASCII code sequence corresponding to the original bytecode using the second encryption algorithm configured in the blockchain node to obtain the first encoding sequence; converting the first ASCII code sequence according to the first encoding sequence and the preset conversion rules to obtain the second ASCII code sequence; and adjusting the original bytecode using the second ASCII code sequence to obtain the second bytecode.
[0008] Based on the above method, a simple and efficient method was implemented to obtain the second bytecode used to characterize the second encryption algorithm.
[0009] Optionally, the first ASCII code sequence corresponding to the original bytecode is obtained by the following methods: sampling the original bytecode according to a preset sampling method to obtain a first sampling sequence; performing ASCII transcoding on the first sampling sequence to obtain a first ASCII code sequence; adjusting the original bytecode using a second ASCII code sequence to obtain a second bytecode, including: converting the second ASCII code sequence into a string to obtain a second sampling sequence; and replacing the corresponding first sampling sequence in the original bytecode with the second sampling sequence according to a preset sampling method to obtain the second bytecode.
[0010] In the above method, sampling the original bytecode can effectively reduce the amount of data processing and the computational resources consumed in determining the second bytecode.
[0011] Optionally, the preset conversion rules are as follows: if the value corresponding to the letter byte in the first encoding sequence is odd, then the corresponding letter byte in the first ASCII code sequence is set to uppercase; if the value corresponding to the letter byte in the first encoding sequence is even, then the corresponding letter byte in the first ASCII code sequence is set to lowercase; or, if the value corresponding to the letter byte in the first encoding sequence is even, then the corresponding letter byte in the first ASCII code sequence is set to uppercase; if the value corresponding to the letter byte in the first encoding sequence is odd, then the corresponding letter byte in the first ASCII code sequence is set to uppercase.
[0012] Since inputting the same ASCII code sequence into different encryption algorithms results in different encoded sequences, the aforementioned preset conversion rules and different encoded sequences will result in different ASCII code sequences. Since different ASCII code sequences correspond to different bytecodes, the aforementioned preset conversion rules ensure that different encryption algorithms correspond to different bytecodes. In other words, by using the aforementioned preset conversion rules, it is possible to intuitively determine whether the first encryption algorithm and the second encryption algorithm are the same through the converted ASCII code sequence or bytecode.
[0013] Optionally, after determining whether the first bytecode and the second bytecode are consistent, the method further includes: if the first bytecode and the second bytecode are inconsistent, refusing to deploy the original bytecode and issuing an error alert.
[0014] In the above method, if the first bytecode and the second bytecode are inconsistent, it indicates that the first encryption algorithm configured by the user on the development side is different from the second encryption algorithm configured by the blockchain node. In other words, the first encryption algorithm deployed by the user on the development side is incorrect, and therefore the original bytecode compiled on the development side cannot be correctly recognized by the blockchain. By refusing to deploy the original bytecode to the blockchain, the blockchain node can be prevented from deploying incorrectly recognized original bytecode, thereby effectively reducing the deployment inefficiency of smart contracts.
[0015] Secondly, the present invention provides a smart contract deployment method applied to the development end. The method includes: processing the smart contract written by the development end according to a first encryption algorithm configured on the development end to obtain raw bytecode; processing the raw bytecode according to the first encryption algorithm and a preset conversion rule to obtain first bytecode; sending the first bytecode to a blockchain node; the first bytecode is used by the blockchain node to obtain second bytecode according to a second encryption algorithm configured on the blockchain node and a preset conversion rule, and determining whether to deploy the smart contract based on the consistency between the first bytecode and the second bytecode.
[0016] Optionally, the original bytecode is processed according to the first encryption algorithm and a preset conversion rule to obtain the first bytecode, including: processing the third ASCII code sequence corresponding to the original bytecode according to the first encryption algorithm to obtain the second encoding sequence; converting the third ASCII code sequence according to the second encoding sequence and the preset conversion rule to obtain the fourth ASCII code sequence; and adjusting the original bytecode through the fourth ASCII code sequence to obtain the first bytecode.
[0017] Optionally, the third ASCII code sequence corresponding to the original bytecode is obtained in the following ways: sampling the original bytecode according to a preset sampling method to obtain a third sampling sequence; performing ASCII transcoding on the third sampling sequence to obtain a third ASCII code sequence; adjusting the original bytecode using a fourth ASCII code sequence to obtain the first bytecode, including: converting the fourth ASCII code sequence into a string form to obtain a fourth sampling sequence; and replacing the corresponding third sampling sequence in the original bytecode with the fourth sampling sequence according to a preset sampling method to obtain the first bytecode.
[0018] Thirdly, the present invention provides a smart contract deployment device applied to a blockchain node. The smart contract deployment device includes: an acquisition unit, configured to acquire first bytecode from a development end, wherein the first bytecode is obtained by the development end processing original bytecode according to a first encryption algorithm and a preset conversion rule, and the original bytecode is obtained by the development end processing a smart contract according to the first encryption algorithm; a processing unit, configured to process the first bytecode according to a preset inverse conversion rule to obtain the original bytecode; wherein the preset inverse conversion rule is the inverse operation of a preset conversion rule; processing the original bytecode according to a second encryption algorithm configured on the blockchain node and the preset conversion rule to obtain second bytecode; and deploying the original bytecode to the blockchain if the first bytecode and the second bytecode are identical.
[0019] Optionally, the processing unit is specifically used to process the first ASCII code sequence corresponding to the original bytecode using the second encryption algorithm configured by the blockchain node to obtain a first encoding sequence; to convert the first ASCII code sequence according to the first encoding sequence and the preset conversion rule to obtain a second ASCII code sequence; and to adjust the original bytecode using the second ASCII code sequence to obtain a second bytecode.
[0020] Optionally, the processing unit is specifically configured to sample the original bytecode according to a preset sampling method to obtain a first sampling sequence; perform ASCII transcoding on the first sampling sequence to obtain a first ASCII code sequence; convert the second ASCII code sequence into a string to obtain a second sampling sequence; and replace the corresponding first sampling sequence in the original bytecode with the second sampling sequence according to the preset sampling method to obtain a second bytecode.
[0021] Optionally, the preset conversion rule is as follows: if the value corresponding to the letter byte in the first encoding sequence is odd, then the corresponding letter byte in the first ASCII code sequence is set to uppercase; if the value corresponding to the letter byte in the first encoding sequence is even, then the corresponding letter byte in the first ASCII code sequence is set to lowercase; or, if the value corresponding to the letter byte in the first encoding sequence is even, then the corresponding letter byte in the first ASCII code sequence is set to uppercase; if the value corresponding to the letter byte in the first encoding sequence is odd, then the corresponding letter byte in the first ASCII code sequence is set to uppercase.
[0022] Optionally, the processing unit is specifically configured to refuse to deploy the original bytecode and issue an error alarm if the first bytecode and the second bytecode are inconsistent.
[0023] Fourthly, the present invention provides a smart contract deployment device applied to a development end. The smart contract deployment device includes: a processing unit, configured to process a smart contract written by the development end according to a first encryption algorithm configured on the development end to obtain raw bytecode; process the raw bytecode according to the first encryption algorithm and a preset conversion rule to obtain first bytecode; and send the first bytecode to a blockchain node; the first bytecode is used by the blockchain node to obtain second bytecode according to a second encryption algorithm configured on the blockchain node and the preset conversion rule, and to determine whether to deploy the smart contract based on the consistency between the first bytecode and the second bytecode.
[0024] Optionally, the processing unit is specifically configured to process the third ASCII code sequence corresponding to the original bytecode according to the first encryption algorithm to obtain a second encoding sequence; convert the third ASCII code sequence according to the second encoding sequence and the preset conversion rule to obtain a fourth ASCII code sequence; and adjust the original bytecode through the fourth ASCII code sequence to obtain a first bytecode.
[0025] Optionally, the processing unit is specifically configured to sample the original bytecode according to a preset sampling method to obtain a third sampling sequence; perform ASCII transcoding on the third sampling sequence to obtain a third ASCII code sequence; convert the fourth ASCII code sequence into a string to obtain a fourth sampling sequence; and replace the corresponding third sampling sequence in the original bytecode with the fourth sampling sequence according to the preset sampling method to obtain a first bytecode.
[0026] Fifthly, the present invention provides a computing device including at least one processor and at least one memory, wherein the memory stores a computer program that, when executed by the processor, causes the processor to perform the smart contract deployment method described in any of the first aspects above.
[0027] In a sixth aspect, the present invention also provides a computer-readable storage medium storing a program that, when run on a computer, causes the computer to execute any of the smart contract deployment methods described in the first aspect. Attached Figure Description
[0028] To more clearly illustrate the technical solutions in this invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0029] Figure 1 A schematic diagram illustrating an application scenario provided by an embodiment of the present invention;
[0030] Figure 2 A flowchart illustrating a method for deploying smart contracts according to an embodiment of the present invention;
[0031] Figure 3 A flowchart of a method for determining the first bytecode provided in an embodiment of the present invention;
[0032] Figure 4 A flowchart illustrating a method for deploying smart contracts according to an embodiment of the present invention;
[0033] Figure 5 A flowchart of a method for determining a second bytecode provided in an embodiment of the present invention;
[0034] Figure 6 This is a structural diagram of a smart contract deployment device provided in an embodiment of the present invention;
[0035] Figure 7 This is a schematic diagram of the structure of a computing device provided in an embodiment of the present invention. Detailed Implementation
[0036] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this invention, and not all of them. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.
[0037] It should be noted that in the description of this invention, "multiple" is understood as "at least two". "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. A connected to B can represent: A and B directly connected, or A and B connected through C. Furthermore, in the description of this invention, terms such as "first" and "second" are used only for descriptive purposes and should not be construed as indicating or implying relative importance or order.
[0038] Figure 1 This is a schematic diagram illustrating an application scenario provided by an embodiment of the present invention. For example... Figure 1 As shown, this application scenario may include a development terminal 101 and at least one blockchain node ( Figure 1 This example only shows one blockchain node 102. The developer endpoint 101 can communicate with at least one blockchain node. The following section provides a detailed introduction to the developer endpoint 101 and at least one blockchain node, using the writing and deployment of smart contracts as examples:
[0039] The development team (101) is used to write smart contracts based on business needs. A smart contract is a type of automated computational code that can be executed on the blockchain, typically used to implement various decentralized applications and digital assets. Furthermore, the compiler within the development team can compile the smart contract into bytecode that can be executed on the blockchain based on the cryptographic algorithms configured by the user, and then send the bytecode to at least one blockchain node.
[0040] At least one blockchain node is used to deploy the bytecode to the blockchain after receiving it, thereby enabling the deployment of smart contracts.
[0041] However, as described in the background section, when a blockchain system supports multiple encryption algorithms, users are prone to misconfiguring encryption algorithms on the development side. This can lead to inconsistencies between the encryption algorithms configured by the user on the development side and those configured by the blockchain nodes. Consequently, the development side compiles the smart contract into bytecode that the blockchain nodes cannot correctly recognize. As a result, the blockchain nodes are unable to correctly deploy the smart contract after receiving the bytecode, leading to invalid smart contract deployment and reduced project delivery efficiency.
[0042] As illustrated in the background example, suppose a blockchain system has its blockchain nodes configured with the SM3 hash algorithm. To ensure the effective deployment of smart contract bytecode within the blockchain, the hash algorithm configured by the user on the development side should also be SM3. However, if the user mistakenly configures the hash algorithm on the development side as SHA-256, the development side will compile the smart contract into bytecode that can only be correctly recognized using the SHA-256 hash algorithm and send this bytecode to the blockchain node. Since the blockchain node is configured with the SM3 hash algorithm, it cannot correctly recognize the bytecode, resulting in the blockchain node's inability to deploy the smart contract correctly, thus rendering the smart contract invalid.
[0043] It should be noted that, generally speaking, for a given blockchain system, the output lengths of the various encryption algorithms it supports are usually equal. For example, a blockchain system may support both the SHA-256 and SM3 encryption algorithms. The output length of both the SHA-256 and SM3 encryption algorithms is 256 bits (32 bytes).
[0044] In view of this, embodiments of the present invention provide a smart contract deployment method, which reduces the inefficiency of smart contract deployment by ensuring that the encryption algorithm configured on the development end is consistent with the encryption algorithm configured on the blockchain node before deploying the smart contract.
[0045] based on Figure 1 The intended application scenario, Figure 2 This is a flowchart illustrating a method for deploying a smart contract according to an embodiment of the present invention. The method is applied to a development end 101, and the executing entity can be a compiler, which can be a device located within the development end 101. Figure 2 As shown, the method includes the following steps:
[0046] Step 201: Process the smart contract written by the development side according to the first encryption algorithm configured on the development side to obtain the original bytecode.
[0047] The first encryption algorithm can be classified as a hash algorithm. A hash algorithm is a mathematical function that maps data of any size to a fixed-length string. As one of the core technologies of blockchain, hash algorithms are widely used in the deployment of smart contracts. Common hash algorithms include SM3, MD5, SHA-1, SHA-256, SHA-384, SHA-512, Keccak256, and so on.
[0048] In this embodiment of the invention, the smart contract written on the development end 101 is compiled according to the first encryption algorithm configured by the user on the development end 101 to obtain the raw bytecode. The raw bytecode can be in the form of a hexadecimal string, and the letter bytes in the string can be all lowercase, all uppercase, or both, without specific limitations.
[0049] In one example, assuming all letter bytes in the original bytecode are lowercase, the original bytecode would be:
[0050] 289c2857a3dccee78abc3ad4598e3756deacccadffffefb964750eac8ab8e37acad7
[0051] e47a30985756de964cadd
[0052] For ease of explanation, the original bytecode from the above example will be used as the example in the following text.
[0053] Step 202: Process the original bytecode according to the first encryption algorithm and the preset conversion rules to obtain the first bytecode.
[0054] Combination Figure 3 The following is a flowchart of a method for determining a first bytecode according to an embodiment of the present invention. The method includes the following steps:
[0055] Step 301: According to the first encryption algorithm, the third ASCII code sequence corresponding to the original bytecode is processed to obtain the second encoding sequence.
[0056] Alternatively, the third ASCII code sequence corresponding to the original bytecode can be obtained in the following way:
[0057] Step a1: Sample the original bytecode according to the preset sampling method to obtain the third sampling sequence.
[0058] In one possible implementation, the preset sampling method can be set according to the output length of the first encryption algorithm. For example, if the output length of the first encryption algorithm is 256 bits (32 bytes), the preset sampling method is to extract 32 bytes from the original bytecode. If the output length of the first encryption algorithm is 128 bits (16 bytes), the preset sampling method is to extract 16 bytes from the original bytecode. The extraction method can be random extraction from the original string or extraction in a fixed order; this embodiment of the invention does not limit this.
[0059] Preferably, the extraction method is as follows: the original string is divided into equal segments, and a fixed length of bytes is taken at the beginning of each segment, and the byte length of the extracted third sampling sequence is equal to the output length of the first encryption algorithm.
[0060] For example, assuming the output length of the first encryption algorithm is 256 bits (32 bytes), the original string is divided into 4 segments, and the first 8 bytes of each segment are taken to form a 32-byte third sampling sequence.
[0061] Taking the original bytecode example above as an example, the original bytecode is divided into 4 segments.
[0062] The first paragraph is:
[0063] 289c2857a3dccee78abc3a
[0064] The second paragraph is:
[0065] d4598e3756deacccadfffe
[0066] The third paragraph is:
[0067] fb964750eac8ab8e37acad
[0068] The fourth paragraph is:
[0069] 7e47a30985756de964cadd
[0070] Take the first 8 bytes of the first segment "289c2857", "d4598e37", "fb964750", and "7e47a309" to form the third sampling sequence. The third sampling sequence is:
[0071] 289c2857d4598e37fb9647507e47a309
[0072] Step a2: Convert the third sampled sequence to ASCII to obtain the third ASCII code sequence.
[0073] Specifically, by performing ASCII transcoding on the third sampling sequence, a third ASCII code sequence that can be recognized by the first encryption algorithm is obtained.
[0074] Taking the third sampled sequence mentioned above as an example, after ASCII transcoding, the resulting third ASCII code sequence is: [50 56 57 99 50 56 53 55 100 52 53 57 56 101 51 55 102 98 57 54 52 55 53 48 55 101 52 55 97 51 48 57]
[0077] After obtaining the third ASCII code sequence, the third ASCII code sequence is processed according to the first encryption algorithm to obtain the second encoded sequence. That is, the third ASCII code sequence is hashed using the first encryption algorithm to obtain the second encoded sequence.
[0078] Taking Keccak256 as an example of the first encryption algorithm, after hashing the third ASCII code sequence in the example above using the first encryption algorithm, a second encoded sequence is obtained. Each byte in the second encoded sequence is represented by a decimal value. The second encoded sequence is as follows: [48 228 28 251 11 50 0 75 97 162 43 197 22 191 178 63 8 160 170 212117 21 35 174 215 190 26 42 225 176 179 11]
[0080] Step 302: Based on the second encoding sequence and the preset conversion rules, the third ASCII code sequence is converted to obtain the fourth ASCII code sequence.
[0081] Optionally, the default conversion rule is:
[0082] If the value of the letter byte in the second encoding sequence is odd, then the corresponding letter byte in the third ASCII code sequence is set to uppercase; if the value of the letter byte in the second encoding sequence is even, then the corresponding letter byte in the third ASCII code sequence is set to lowercase.
[0083] or,
[0084] If the value of the letter byte in the second encoding sequence is even, then the corresponding letter byte in the third ASCII code sequence is set to uppercase; if the value of the letter byte in the second encoding sequence is odd, then the corresponding letter byte in the third ASCII code sequence is set to uppercase.
[0085] For example, taking the case where the preset conversion rule is that when the value of the letter byte in the second encoding sequence is odd, the corresponding letter byte in the third ASCII code sequence is set to uppercase, the conversion of the third ASCII code sequence will be explained as follows:
[0086] In the second encoding sequence of the example above, we can see that the fourth bit in the second encoding sequence corresponds to the fourth bit of the third ASCII code sequence (ASCII code 99, corresponding to the letter byte 'c'). Since the value of the fourth bit in the second encoding sequence is "251", which is an odd number, we set the corresponding letter byte in the third ASCII code sequence to uppercase, that is, we set the ASCII code of the fourth bit of the third ASCII code sequence to 67, corresponding to the letter byte 'C'. The seventh bit from the bottom in the second encoding sequence corresponds to the seventh bit from the bottom in the third ASCII code sequence (ASCII code 101, corresponding to the letter byte 'e'). Since the value of the seventh bit from the bottom in the second encoding sequence is "190", which is an even number, we set the corresponding letter byte in the third ASCII code sequence to lowercase, that is, we keep the ASCII code of the seventh bit from the bottom in the third ASCII code sequence at 101, corresponding to the letter byte 'e'.
[0087] By converting the third ASCII code sequence in the example using the above method, the fourth ASCII code sequence is obtained as follows: [50 56 57 67 50 56 53 55 68 52 53 57 56 69 51 55 102 98 57 54 52 55 53 48 55 101 52 55 65 51 48 57]
[0090] Step 303: Adjust the original bytecode using the fourth ASCII code sequence to obtain the first bytecode.
[0091] Optionally, methods for obtaining the first bytecode through the fourth ASCII code sequence include:
[0092] Step b1: Convert the fourth ASCII code sequence into a string to obtain the fourth sampling sequence.
[0093] Taking the fourth ASCII code sequence mentioned above as an example, converting it into string form yields the fourth sampled sequence:
[0094] 289C2857D4598E37fb9647507e47A309
[0095] Step b2: According to the preset sampling method, replace the corresponding third sampling sequence in the original bytecode with the fourth sampling sequence to obtain the first bytecode.
[0096] Taking the fourth sampling sequence mentioned above as an example, replacing the corresponding third sampling sequence "289c2857" in the original bytecode with "289C2857" in the fourth sampling sequence, replacing the corresponding third sampling sequence "d4598e37" in the original bytecode with "D4598E37" in the fourth sampling sequence, replacing the corresponding third sampling sequence "fb964750" in the original bytecode with "fb964750" in the fourth sampling sequence, and replacing the corresponding third sampling sequence "7e47a309" in the original bytecode with "7e47A309" in the fourth sampling sequence, the resulting first bytecode is:
[0097] 289C2857a3dccee78abc3aD4598E3756deacccadffffefb964750eac8ab8e37acad
[0098] 7e47A30985756de964cadd
[0099] Comparing the first bytecode and the original bytecode reveals that the information and length of the two bytecodes are identical; the only difference lies in the case of some letter bytes. For example, the fourth bit of the original bytecode is the letter byte "c", while the fourth bit of the first bytecode is the letter byte "C".
[0100] In this way, it is equivalent to re-inserting a portion of the sampled bytes from the original bytecode into the first encryption algorithm to obtain the first bytecode corresponding to the first encryption algorithm.
[0101] Step 203: Send the first bytecode to the blockchain node.
[0102] The first bytecode is used by the blockchain node to obtain the second bytecode according to the second encryption algorithm configured by the blockchain node and the preset conversion rules, and to determine whether to deploy the smart contract based on the consistency between the first bytecode and the second bytecode.
[0103] Specifically, after receiving the first bytecode, the developer 101 sends it to the blockchain node. The transmission method can be either through a software development kit (SDK) or a local inter-process communication (IPC) console; there is no limitation on the method. Upon receiving the first bytecode, the blockchain node first restores it to its original bytecode. Then, it processes the original bytecode according to the second encryption algorithm configured on the blockchain node and preset conversion rules to obtain the second bytecode corresponding to the second encryption algorithm. Next, it compares the first and second bytecode. If they match, it indicates that the first and second encryption algorithms are the same, and the first encryption algorithm deployed by the user on the developer side is correct, allowing the smart contract to be deployed. If they do not match, it indicates that the first and second encryption algorithms are different, and the first encryption algorithm deployed by the user on the developer side is incorrect, preventing the smart contract from being deployed.
[0104] Figure 4 This is a flowchart illustrating a method for deploying a smart contract according to an embodiment of the present invention. The method is applied to blockchain node 102. Figure 4 As shown, the method includes the following steps:
[0105] Step 401: Obtain the first bytecode from the development side.
[0106] The first bytecode is obtained by the development end 101 processing the original bytecode according to the first encryption algorithm and preset conversion rules. The original bytecode is obtained by the development end 101 processing the smart contract according to the first encryption algorithm.
[0107] Step 402: Process the first bytecode according to the preset reverse conversion rules to obtain the original bytecode.
[0108] The preset inverse conversion rule is the inverse operation of the preset conversion rule. If the conversion rule for developer 101 is: if the value corresponding to a letter byte in the second encoding sequence is odd, then the corresponding letter byte in the third ASCII code sequence is set to uppercase; if the value corresponding to a letter byte in the second encoding sequence is even, then the corresponding letter byte in the third ASCII code sequence is set to lowercase. Then the preset inverse conversion rule is: set all letter bytes in the first bytecode to lowercase.
[0109] If the conversion rule of developer 101 is: if the value of the letter byte in the second encoding sequence is even, then set the corresponding letter byte in the third ASCII code sequence to uppercase; if the value of the letter byte in the second encoding sequence is odd, then set the corresponding letter byte in the third ASCII code sequence to uppercase. Then the default reverse conversion rule is: set all letter bytes in the first bytecode to uppercase.
[0110] As mentioned above Figure 2 Taking the first bytecode in the example as an example, since its corresponding transcoding rule is that when the value of the letter byte in the second encoding sequence is odd, the corresponding letter byte in the third ASCII code sequence is set to uppercase, the default reverse conversion rule is: set all letter bytes in the first bytecode to lowercase.
[0111] By following the preset reverse transformation rules, blockchain node 102 processes the first bytecode to obtain the original bytecode:
[0112] 289c2857a3dccee78abc3ad4598e3756deacccadffffefb964750eac8ab8e37acad7
[0113] e47a30985756de964cadd
[0114] Step 403: Process the original bytecode according to the second encryption algorithm configured in the blockchain node and the preset conversion rules to obtain the second bytecode.
[0115] The second encryption algorithm can be a hash algorithm. It should be noted that when a user configures the first encryption algorithm on the development side 101, the output length of the first encryption algorithm is the same as the output length of the second encryption algorithm configured on the blockchain node. That is, if the output length of the second encryption algorithm is 256 bits (32 bytes), then the output length of the first encryption algorithm that the user can configure on the development side 101 is always 256 bits (32 bytes).
[0116] Combination Figure 5 The following is a flowchart of a method for determining a second bytecode according to an embodiment of the present invention. The method includes the following steps:
[0117] Step 501: The first ASCII code sequence corresponding to the original bytecode is processed by the second encryption algorithm configured in the blockchain node to obtain the first encoded sequence.
[0118] Alternatively, the first ASCII code sequence corresponding to the original bytecode can be obtained in the following way:
[0119] Step c1: Sample the original bytecode according to the preset sampling method to obtain the first sampling sequence.
[0120] For a detailed introduction to the preset sampling method, please refer to the aforementioned... Figure 3 This will not be elaborated further here. It should be noted that the preset sampling method used by blockchain node 102 is the same as that used by development terminal 101. Therefore, the first sampling sequence obtained by blockchain node 102 after sampling the original bytecode is equal to the third sampling sequence obtained by development terminal 101 after sampling the original bytecode.
[0121] Taking the original bytecode example above, the first sampling sequence obtained is as follows:
[0122] 289c2857d4598e37fb9647507e47a309
[0123] Step c2: Convert the first sampled sequence to ASCII to obtain the first ASCII code sequence.
[0124] Specifically, by performing ASCII transcoding on the first sampling sequence, a first ASCII code sequence that can be recognized by the second encryption algorithm is obtained.
[0125] Taking the first sampled sequence mentioned above as an example, after ASCII transcoding, the resulting first ASCII code sequence is: [50 56 57 99 50 56 53 55 100 52 53 57 56 101 51 55 102 98 57 54 52 55 53 48 55 101 52 55 97 51 48 57]
[0128] After obtaining the first ASCII code sequence, the first ASCII code sequence is processed according to the second encryption algorithm configured in the blockchain node to obtain the first encoded sequence. That is, the first ASCII code sequence is hashed using the second encryption algorithm to obtain the first encoded sequence.
[0129] Taking the second encryption algorithm as SM3 as an example, after hashing the first ASCII code sequence in the example above using the second encryption algorithm, a first encoded sequence is obtained. Each byte in the first encoded sequence is represented by a decimal value. The first encoded sequence is as follows: [147 219 192 139 253 32 101 85 209 127 34 224 68 42 131 178 44 24 133 210 212 61 102 121 195 69 65 112 106 230 115 112]
[0132] Step 502: Convert the first ASCII code sequence according to the first encoding sequence and the preset conversion rules to obtain the second ASCII code sequence.
[0133] Optionally, the default conversion rule is:
[0134] If the value corresponding to the letter byte in the first encoding sequence is odd, then the corresponding letter byte in the first ASCII code sequence is set to uppercase; if the value corresponding to the letter byte in the first encoding sequence is even, then the corresponding letter byte in the first ASCII code sequence is set to lowercase.
[0135] or,
[0136] If the value of the letter byte in the first encoding sequence is even, then the corresponding letter byte in the first ASCII code sequence is set to uppercase; if the value of the letter byte in the first encoding sequence is odd, then the corresponding letter byte in the first ASCII code sequence is set to uppercase.
[0137] For example, taking the case where the preset conversion rule is that the value corresponding to the letter byte in the first encoding sequence is odd, and the corresponding letter byte in the first ASCII code sequence is set to uppercase, the conversion of the first ASCII code sequence will be explained as follows:
[0138] In the first encoded sequence of the above example, we can see that the fourth bit in the first encoded sequence corresponds to the fourth bit of the first ASCII code sequence (ASCII code 99, corresponding to the letter byte 'c'). Since the value of the fourth bit in the first encoded sequence is "139", which is an odd number, we set the corresponding letter byte in the first ASCII code sequence to uppercase, that is, we set the ASCII code of the fourth bit of the first ASCII code sequence to 67, corresponding to the letter byte 'C'. The seventh bit from the bottom in the first encoded sequence corresponds to the seventh bit from the bottom in the first ASCII code sequence (ASCII code 101, corresponding to the letter byte 'e'). Since the value of the seventh bit from the bottom in the first encoded sequence is "69", which is an odd number, we set the corresponding letter byte in the first ASCII code sequence to uppercase, that is, we set the ASCII code of the seventh bit from the bottom in the first ASCII code sequence to 69, corresponding to the letter byte 'E'.
[0139] By converting the first ASCII code sequence in the example using the above method, the second ASCII code sequence represented in decimal is obtained as follows: [50 56 57 67 50 56 53 55 68 52 53 57 56 101 51 55 102 98 57 54 52 55 53 48 55 69 52 55 97 51 48 57]
[0142] Step 503: Adjust the original bytecode using the second ASCII code sequence to obtain the second bytecode.
[0143] Optionally, methods for obtaining the second bytecode from the second ASCII code sequence include:
[0144] Step d1: Convert the second ASCII code sequence into a string to obtain the second sampling sequence.
[0145] Taking the second ASCII code sequence mentioned above as an example, converting it to string form yields the following second sampled sequence:
[0146] 289C2857D4598e37fb9647507E47a309
[0147] Step d2: According to the preset sampling method, replace the corresponding first sampling sequence in the original bytecode with the second sampling sequence to obtain the second bytecode.
[0148] Taking the second sampling sequence mentioned above as an example, replace the corresponding first sampling sequence "289c2857" in the original bytecode with "289C2857" in the second sampling sequence, replace the corresponding first sampling sequence "d4598e37" in the original bytecode with "D4598e37" in the second sampling sequence, replace the corresponding first sampling sequence "fb964750" in the original bytecode with "fb964750" in the second sampling sequence, and replace the corresponding first sampling sequence "7e47a309" in the original bytecode with "7E47a309" in the second sampling sequence. The resulting second bytecode is:
[0149] 289C2857a3dccee78abc3aD4598e3756deacccadffffefb964750eac8ab8e37acad7E47a30985756de964cadd
[0150] Step 404: If the first bytecode and the second bytecode are identical, deploy the original bytecode to the blockchain.
[0151] Specifically, the first bytecode and the second bytecode are compared to determine if they are identical. If they are identical, the original bytecode is deployed to the blockchain. The original bytecode can be obtained by the blockchain node 102 processing either the first or second bytecode again according to a preset inverse transformation rule to obtain the original bytecode. Alternatively, after the blockchain node 102 restores the original bytecode in step 402, it saves it locally. If the first and second bytecodes are identical, the original bytecode is retrieved from the local machine.
[0152] Optionally, if the first bytecode and the second bytecode are inconsistent, the original bytecode should be refused to be deployed and an error warning should be issued.
[0153] Based on the same inventive concept described above, the present invention also provides a smart contract deployment device, which can execute the methods described in the embodiments of the invention. The structure of the smart contract deployment device provided by the present invention can be found in [reference needed]. Figure 6 The smart contract deployment device 600 includes an acquisition unit 601 and a processing unit 602. The acquisition unit 601 acquires first bytecode from the development end, which is obtained by processing original bytecode using a first encryption algorithm and a preset conversion rule. The processing unit 602 processes the first bytecode according to a preset inverse conversion rule to obtain the original bytecode. The preset inverse conversion rule is the reverse operation of a preset conversion rule. The processing unit 602 then processes the original bytecode according to a second encryption algorithm configured on the blockchain node and the preset conversion rule to obtain second bytecode. If the first and second bytecodes match, the original bytecode is deployed to the blockchain.
[0154] For a more detailed description of the acquisition unit 601 and the processing unit 602 described above, please refer to [reference needed]. Figure 4 The relevant descriptions in the method embodiments shown are directly obtained and will not be repeated here.
[0155] Based on the same technical concept, the present invention also provides a computing device, such as... Figure 7 As shown, the computing device 700 includes at least one processor 701 and a memory 702 connected to the at least one processor. The specific connection medium between the processor 701 and the memory 702 is not limited in this invention. Figure 7 Taking the connection between the processor 701 and the memory 702 via a bus as an example, the bus can be divided into address bus, data bus, control bus, etc.
[0156] In this invention, the memory 702 stores instructions that can be executed by at least one processor 701. By executing the instructions stored in the memory 702, at least one processor 701 can perform the steps included in the aforementioned smart contract deployment method.
[0157] The processor 701 serves as the control center of the computing device, connecting various parts of the device via various interfaces and lines. It enables smart contract deployment by running or executing instructions stored in the memory 702 and accessing data stored in the memory 702. Optionally, the processor 701 may include one or more processing units. The processor 701 may integrate an application processor and a modem processor. The application processor primarily handles the operating system, user interface, and applications, while the modem processor primarily handles issuing instructions. It is understood that the modem processor may not be integrated into the processor 701. In some embodiments, the processor 701 and the memory 702 may be implemented on the same chip; in other embodiments, they may be implemented on separate chips.
[0158] The processor 701 can be a general-purpose processor, such as a central processing unit (CPU), digital signal processor, application-specific integrated circuit (ASIC), field-programmable gate array (FPGA), or other programmable logic device, discrete gate or transistor logic device, or discrete hardware component, capable of implementing or executing the methods, steps, and logic block diagrams disclosed in this invention. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of the smart contract deployment method can be directly manifested as execution by a hardware processor, or execution by a combination of hardware and software modules within the processor.
[0159] Memory 702, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. Memory 702 may include at least one type of storage medium, such as flash memory, hard disk, multimedia card, card-type memory, random access memory (RAM), static random access memory (SRAM), programmable read-only memory (PROM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), magnetic storage, magnetic disk, optical disk, etc. Memory 702 can be any other medium capable of carrying or storing desired program code in the form of instructions or data structures that can be accessed by a computer, but is not limited thereto. Memory 702 in this invention can also be a circuit or any other device capable of implementing storage functions for storing program instructions and / or data.
[0160] Based on the same technical concept, the present invention also provides a computer-readable storage medium storing a computer program executable by a computing device, which, when run on the computing device, causes the computing device to perform the steps of the above-described smart contract deployment method.
[0161] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0162] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0163] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0164] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0165] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. A method for deploying smart contracts, characterized in that, Applied to blockchain nodes, including: The first bytecode is obtained from the development end. The first bytecode is obtained by the development end by processing the original bytecode according to the first encryption algorithm and the preset conversion rules. The original bytecode is obtained by the development end by processing the smart contract according to the first encryption algorithm. The first bytecode is processed according to a preset inverse conversion rule to obtain the original bytecode; the preset inverse conversion rule is the inverse operation of the preset conversion rule; The first ASCII code sequence corresponding to the original bytecode is processed according to the second encryption algorithm configured in the blockchain node to obtain the first encoded sequence; According to the first encoding sequence and the preset conversion rule, the first ASCII code sequence is converted to obtain the second ASCII code sequence; the preset conversion rule is: if the value corresponding to the letter byte in the first encoding sequence is odd, then the corresponding letter byte in the first ASCII code sequence is set to uppercase; if the value corresponding to the letter byte in the first encoding sequence is even, then the corresponding letter byte in the first ASCII code sequence is set to lowercase. The original bytecode is adjusted by the second ASCII code sequence to obtain the second bytecode; If the first bytecode and the second bytecode are identical, the original bytecode will be deployed to the blockchain.
2. The method as described in claim 1, characterized in that, The first ASCII code sequence corresponding to the original bytecode is obtained in the following ways: The original bytecode is sampled according to a preset sampling method to obtain a first sampling sequence; The first sampled sequence is converted to ASCII to obtain the first ASCII code sequence; The step of adjusting the original bytecode using the second ASCII code sequence to obtain the second bytecode includes: The second ASCII code sequence is converted into a string to obtain the second sampling sequence; According to the preset sampling method, the first sampling sequence corresponding to the original bytecode is replaced with the second sampling sequence to obtain the second bytecode.
3. The method as described in claim 1, characterized in that, The method further includes: If the first bytecode and the second bytecode are inconsistent, the original bytecode will be refused to be deployed, and an error warning will be issued.
4. A method for deploying smart contracts, characterized in that, Applications on the development side include: The smart contract written by the development end is processed according to the first encryption algorithm configured on the development end to obtain the original bytecode; The original bytecode is processed according to the first encryption algorithm and the preset conversion rules to obtain the first bytecode; The first bytecode is sent to the blockchain node; the first bytecode is used by the blockchain node to process the first ASCII code sequence corresponding to the original bytecode according to the second encryption algorithm configured by the blockchain node, to obtain a first encoding sequence; according to the first encoding sequence and the preset conversion rule, the first ASCII code sequence is converted to obtain a second ASCII code sequence; the preset conversion rule is: if the value corresponding to the letter byte in the first encoding sequence is odd, then the corresponding letter byte in the first ASCII code sequence is set to uppercase; if the value corresponding to the letter byte in the first encoding sequence is even, then the corresponding letter byte in the first ASCII code sequence is set to lowercase; the original bytecode is adjusted by the second ASCII code sequence to obtain the second bytecode, and the consistency between the first bytecode and the second bytecode determines whether to deploy the smart contract.
5. The method as described in claim 4, characterized in that, The step of processing the original bytecode according to the first encryption algorithm and the preset conversion rules to obtain the first bytecode includes: According to the first encryption algorithm, the third ASCII code sequence corresponding to the original bytecode is processed to obtain the second encoding sequence; The third ASCII code sequence is converted according to the second encoding sequence and the preset conversion rule to obtain the fourth ASCII code sequence; The original bytecode is adjusted by the fourth ASCII code sequence to obtain the first bytecode.
6. The method as described in claim 5, characterized in that, The third ASCII code sequence corresponding to the original bytecode is obtained in the following way: The original bytecode is sampled according to a preset sampling method to obtain a third sampling sequence; The third sampled sequence is converted to ASCII to obtain a third ASCII code sequence; The step of adjusting the original bytecode using the fourth ASCII code sequence to obtain the first bytecode includes: The fourth ASCII code sequence is converted into a string to obtain the fourth sampling sequence; According to the preset sampling method, the corresponding third sampling sequence in the original bytecode is replaced with the fourth sampling sequence to obtain the first bytecode.
7. A smart contract deployment device, characterized in that, Applied to blockchain nodes, including: The acquisition unit is used to acquire the first bytecode from the development end. The first bytecode is obtained by the development end processing the original bytecode according to the first encryption algorithm and the preset conversion rules. The original bytecode is obtained by the development end processing the smart contract according to the first encryption algorithm. The processing unit is configured to process the first bytecode according to a preset inverse conversion rule to obtain the original bytecode; the preset inverse conversion rule is the inverse operation of the preset conversion rule; process the first ASCII code sequence corresponding to the original bytecode according to the second encryption algorithm configured by the blockchain node to obtain a first encoding sequence; convert the first ASCII code sequence according to the first encoding sequence and the preset conversion rule to obtain a second ASCII code sequence; the preset conversion rule is: if the value corresponding to the letter byte in the first encoding sequence is odd, then the corresponding letter byte in the first ASCII code sequence is set to uppercase; if the value corresponding to the letter byte in the first encoding sequence is even, then the corresponding letter byte in the first ASCII code sequence is set to lowercase; adjust the original bytecode through the second ASCII code sequence to obtain the second bytecode; and deploy the original bytecode to the blockchain if the first bytecode and the second bytecode are consistent.
8. A computing device, characterized in that, It includes at least one processor and at least one memory, wherein the memory stores a computer program that, when executed by the processor, causes the processor to perform the method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The storage medium stores a program that, when run on a computer, causes the computer to perform the method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Data processing method and apparatus, system and computer readable storage medium
CN107786331A
Method and system for executing smart contract, block chain node and storage medium
CN112866392A
