Privacy protection method, device, electronic device and program product for smart contracts

By using sub-privacy trigger scripts and setting summary algorithms in smart contracts to protect the privacy and security of smart contracts, the problems of small scope of application and low privacy and security in the prior art are solved, and broader applicability and higher security and privacy are achieved.

CN119272335BActive Publication Date: 2025-04-11HANGZHOU HIGH-TECH ZONE (BINJIANG) INSTITUTE OF BLOCKCHAIN & DATA SECURITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411783033.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-06
Publication Date
2025-04-11
Estimated Expiration
2044-12-06

AI Technical Summary

Technical Problem

The existing technology is difficult to meet the actual needs of smart contracts, and its scope of application is small, which reduces the privacy and security of smart contracts.

Method used

By obtaining the variable identifier entered by the user to be traded, the sub-privacy trigger script and the ciphertext of the sub-privacy trigger script of the other participating users, the target variable corresponding to the variable identifier in the smart contract, and obtain the setting ciphertext of the target variable. According to the setting digest algorithm, the ciphertext of the sub-privacy trigger script and the sub-privacy trigger script are calculated to obtain the target ciphertext. If the target ciphertext is the same as the set ciphertext, then the bytecode of the determination script in the sub-privacy trigger script is executed to obtain the execution result. If the execution result is successful, a setting operation is performed on the target variable.

Benefits of technology

It improves the security and privacy of smart contracts, avoids illegal operations by illegal participants, and expands the scope of application.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119272335B_ABST
    Figure CN119272335B_ABST
Patent Text Reader

Abstract

The present application is applicable to the field of blockchain technology, and provides a privacy protection method, device, electronic device and program product for smart contracts, the method comprising: in response to a transaction instruction, obtaining a variable identifier, a sub-privacy trigger script and the sub-privacy trigger script ciphertext of each of the other participating users input by the transaction user; determining the target variable corresponding to the variable identifier from the smart contract, and obtaining the setting ciphertext corresponding to the target variable; calculating the sub-privacy trigger script and each sub-privacy trigger script ciphertext according to the setting summary algorithm to obtain the target ciphertext; if the target ciphertext is the same as the setting ciphertext, executing the judgment script bytecode in the sub-privacy trigger script to obtain the execution result; if the execution result is successful, performing the setting operation on the target variable. Compared with the prior art, the present application not only improves the privacy and security of smart contracts, but is also not limited to the alliance chain, thereby expanding the scope of application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of blockchain technology, and in particular, relates to a privacy protection method, device, electronic device and program product for smart contracts. Background Art

[0002] At present, the smart contract technology on the blockchain is completely open and transparent, which is mainly reflected in the openness of the contract business logic and target variables. This will result in the account behavior operated by the smart contract being completely public, and the user's privacy cannot be guaranteed.

[0003] Existing technologies usually use alliance chain technology, which prevents participants other than alliance chain nodes from directly obtaining information about the contract status. However, for participants in alliance chain nodes, the data of smart contracts is still completely transparent. It can be seen that existing technologies are difficult to meet actual needs. Not only is the scope of application small, but it also reduces the privacy and security of smart contracts. Summary of the invention

[0004] The embodiments of the present application provide a privacy protection method, device, electronic device and program product for a smart contract to solve the problem that the prior art is difficult to meet actual needs, not only has a small scope of application, but also reduces the privacy and security of the smart contract.

[0005] In a first aspect, an embodiment of the present application provides a privacy protection method for a smart contract, including:

[0006] In response to the transaction instruction, obtain the variable identifier input by the user to be traded, the sub-privacy trigger script, and the ciphertext of the sub-privacy trigger scripts of the remaining participating users; the sub-privacy trigger script is used to unlock the corresponding state variable in the smart contract;

[0007] Determine the target variable corresponding to the variable identifier in the smart contract, and obtain the setting ciphertext corresponding to the target variable; the setting ciphertext is calculated by a setting digest algorithm;

[0008] Calculate the sub-privacy trigger script and each of the sub-privacy trigger script ciphertexts according to the set summary algorithm to obtain a target ciphertext;

[0009] If the target ciphertext is the same as the set ciphertext, the determination script bytecode in the sub-privacy trigger script is executed to obtain an execution result; the determination script bytecode is used to determine whether the target variable can be unlocked;

[0010] If the execution result is successful, a setting operation is performed on the target variable.

[0011] Optionally, obtaining the setting ciphertext corresponding to the target variable includes:

[0012] determining a target state of the target variable;

[0013] If the target state is a locked state, the setting ciphertext is obtained.

[0014] Optionally, calculating the sub-privacy trigger script and each of the sub-privacy trigger script ciphertexts according to the set summary algorithm to obtain a target ciphertext includes:

[0015] Obtaining a callback method signature corresponding to the target variable;

[0016] Calculate the callback method signature and the sub-privacy trigger script respectively according to the set digest algorithm to obtain a first ciphertext corresponding to the signature and a second ciphertext corresponding to the sub-privacy trigger script;

[0017] The first ciphertext, the second ciphertext, and each of the sub-privacy trigger script ciphertexts are calculated according to the set summary algorithm to obtain the target ciphertext.

[0018] Optionally, the sub-privacy trigger script includes a callback method parameter; and performing a setting operation on the target variable includes:

[0019] Obtaining a callback method signature corresponding to the target variable;

[0020] Determine a target callback method from the smart contract according to the callback method signature;

[0021] The target callback method is executed according to the callback method parameters to perform the setting operation on the target variable.

[0022] Optionally, before obtaining the variable identifier, the sub-privacy trigger script and the ciphertext of the sub-privacy trigger scripts of the remaining participating users input by the user to be traded in response to the transaction instruction, the method further includes:

[0023] In response to a lock instruction, determining a current state of the target variable;

[0024] If the current state is a locked state, outputting a prompt message for prompting that the target variable cannot be locked again;

[0025] If the current state is an unlocked state, the target variable is locked.

[0026] Optionally, locking the target variable includes:

[0027] Obtain the preset judgment script bytecode and preset callback method parameters corresponding to each participating user;

[0028] Generate a sub-privacy trigger script for each participating user based on the preset determination script bytecode and preset callback method parameters corresponding to each participating user;

[0029] The callback method signature corresponding to the target variable and the sub-privacy trigger script of each participating user are calculated according to the set summary algorithm to obtain a third ciphertext corresponding to the callback method signature and a sub-privacy trigger script ciphertext of each participating user;

[0030] Calculate the third ciphertext and the sub-privacy trigger script ciphertext of each participating user according to the set digest algorithm to obtain the set ciphertext;

[0031] The target variable is locked based on the set ciphertext.

[0032] Optionally, after locking the target variable based on the set ciphertext, the method further includes:

[0033] For any participating user, the sub-privacy trigger script of the participating user and the ciphertext of the sub-privacy trigger scripts corresponding to other participating users are sent to the terminal device of the participating user; the other participating users refer to all participating users except the participating user.

[0034] In a second aspect, an embodiment of the present application provides a privacy protection device for a smart contract, including:

[0035] A first acquisition unit is used to obtain, in response to a transaction instruction, a variable identifier input by the user to be traded, a sub-privacy trigger script, and the ciphertext of the sub-privacy trigger scripts of the remaining participating users; the sub-privacy trigger script is used to unlock the corresponding state variable in the smart contract;

[0036] A second acquisition unit is used to determine a target variable corresponding to the variable identifier in the smart contract, and obtain a setting ciphertext corresponding to the target variable; the setting ciphertext is calculated by a setting digest algorithm;

[0037] A first calculation unit, configured to calculate the sub-privacy trigger script and each of the sub-privacy trigger script ciphertexts according to the set summary algorithm to obtain a target ciphertext;

[0038] A first execution unit is configured to execute a determination script bytecode in the sub-privacy trigger script to obtain an execution result if the target ciphertext is the same as the set ciphertext; the determination script bytecode is used to determine whether the target variable can be unlocked;

[0039] The second execution unit is used to perform a setting operation on the target variable if the execution result is successful.

[0040] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the privacy protection method for a smart contract as described in any one of the first aspects above is implemented.

[0041] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the privacy protection method of the smart contract as described in any one of the first aspects above.

[0042] In a fifth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device can execute the privacy protection method of the smart contract described in any one of the first aspects above.

[0043] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:

[0044] The privacy protection method of a smart contract provided by the embodiment of the present application is to determine the target variable corresponding to the obtained variable identifier from the smart contract, and obtain the set ciphertext corresponding to the target variable; calculate the obtained sub-privacy trigger script and each sub-privacy trigger script ciphertext according to the set summary algorithm to obtain the target ciphertext; if the target ciphertext is the same as the set ciphertext, execute the judgment script bytecode in the sub-privacy trigger script to obtain the execution result; if the execution result is successful, perform the set operation on the target variable. Compared with the prior art, the present application can only perform corresponding operations on a certain state variable of the smart contract after the sub-privacy trigger script of the transaction user and the sub-privacy trigger script ciphertext of the other participating users meet the requirements, that is, they are legal, thereby avoiding illegal operations of illegal participants and improving the security of the smart contract. At the same time, when unlocking the state variable, the present application will only disclose the sub-privacy trigger script of the transaction user, and the sub-privacy trigger scripts of the other participating users are not disclosed, protecting the privacy of the other participating users, thereby improving the privacy of the smart contract. In addition, the present application is not limited to the alliance chain, thereby expanding the scope of application. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0046] Figure 1This is a flowchart of a privacy protection method for a smart contract provided by an embodiment of the present application;

[0047] Figure 2 is a flowchart of an implementation method of a privacy protection method for a smart contract provided by another embodiment of the present application;

[0048] Figure 3 is a flowchart of a privacy protection method for a smart contract provided in yet another embodiment of the present application;

[0049] Figure 4 It is a structural diagram of a privacy protection device for a smart contract provided in one embodiment of the present application;

[0050] Figure 5 It is a schematic diagram of the structure of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0051] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.

[0052] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0053] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0054] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0055] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0056] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0057] At present, the smart contract technology on the blockchain is completely open and transparent, mainly reflected in the openness of the contract business logic and state variables. This will result in the account behavior operated by the smart contract being completely public, and the user's privacy cannot be guaranteed. For example, in a scenario related to digital assets, user A locks an asset in a smart contract, allowing his wife B to withdraw it at any time, and also allowing his child C to withdraw it after 12 months. At this time, no matter who ultimately operates between wife B and child C, the account information of the two and the conditions for withdrawing assets have been made public, leaving security risks.

[0058] Existing smart contract technology can realize the release and transfer of digital assets, and can be deployed on the alliance chain to achieve a certain degree of data hiding. Although the alliance chain and permission control can prevent participants other than the alliance chain nodes from directly obtaining information about the contract status, the data of the smart contract is still completely transparent to the participants of the alliance chain nodes. In addition, by tracking all transactions on the chain, the status data of the smart contract can also be restored to a certain extent.

[0059] Therefore, this application proposes a privacy protection method for smart contracts, which can protect the privacy of other participating users when a user operates a state variable in the smart contract. At the same time, it can also improve the security of the state variables to prevent them from being operated by illegal participants.

[0060] The privacy protection method of the above-mentioned smart contract will be described in detail with specific embodiments below.

[0061] See also Figure 1 , Figure 1 This is a flowchart of the implementation of the privacy protection method of the smart contract provided by an embodiment of the present application. In the embodiment of the present application, the execution subject of the privacy protection method of the smart contract is an electronic device. Among them, the electronic device is a node device of the blockchain.

[0062] like Figure 1 As shown, the privacy protection method of the smart contract provided by an embodiment of the present application may include S101 to S105, which are described in detail as follows:

[0063] In S101, in response to a transaction instruction, the variable identifier input by the user to be traded, the sub-privacy trigger script, and the ciphertext of the sub-privacy trigger scripts of the remaining participating users are obtained; the sub-privacy trigger script is used to unlock the corresponding state variables in the smart contract.

[0064] In an embodiment of the present application, when the user to be traded wants to perform a corresponding operation on a state variable in a smart contract (such as transferring digital assets, etc.), the user to be traded can send a transaction instruction to the electronic device.

[0065] It should be noted that the transaction instruction carries the transaction information of the user to be traded, which includes but is not limited to variable identifiers, sub-privacy trigger scripts, and the ciphertext of the sub-privacy trigger scripts of the other participating users.

[0066] Among them, the sub-privacy trigger script is used to unlock the corresponding state variables in the smart contract.

[0067] The variable identifier can be the key value of the state variable.

[0068] In the embodiment of the present application, the state variable specifically refers to the state variable that can be operated by the user within the smart contract logic, including but not limited to a certain digital asset in a digital asset trading scenario.

[0069] The sub-privacy trigger script includes but is not limited to the judgment script bytecode and callback method parameters.

[0070] Among them, the judgment script bytecode refers to the conditional judgment logic written in the smart contract language, which is used to determine whether the corresponding state variable can be unlocked, that is, whether the conditions for unlocking the state variable are met.

[0071] It should be noted that the judgment script bytecode can be written according to actual needs and is not limited here.

[0072] The callback method parameter refers to the calling parameter used to pass into the callback method. After determining that the script bytecode meets the conditions, the smart contract execution engine can call the callback method through the callback method parameter to execute subsequent logic and implement the corresponding operation on the state variable.

[0073] It should be noted that the callback method defines the processing logic after the state variable is unlocked.

[0074] In some possible embodiments, the sub-privacy trigger script may also include a ciphertext corresponding to the sub-privacy trigger script.

[0075] Among them, the above ciphertext can be obtained by calculating the judgment script bytecode and callback method parameters in the sub-privacy trigger script by setting a digest algorithm.

[0076] In the embodiment of the present application, the set digest algorithm includes but is not limited to: message digest algorithm (Message-Digest Algorithm, MD5) and secure hash algorithm (Secure Hash Algorithm, SHA) and the like.

[0077] In practical applications, an information digest algorithm is an algorithm that calculates information of any length into a "fingerprint" or "message digest" of a fixed length.

[0078] A secure hash algorithm is an algorithm that calculates a fixed-length string (also known as a message digest) corresponding to a digital message.

[0079] In an embodiment of the present application, after the electronic device detects the above-mentioned transaction instruction, since the transaction instruction carries the transaction information to be input by the transaction user, the electronic device can extract the transaction information from the transaction instruction, thereby obtaining the variable identifier input by the transaction user, the sub-privacy trigger script and the ciphertext of the sub-privacy trigger script of each of the other participating users.

[0080] It should be noted that the ciphertexts of the sub-privacy trigger scripts of the other participating users are also calculated by the set summary algorithm.

[0081] In S102, a target variable corresponding to the variable identifier in the smart contract is determined, and a setting ciphertext corresponding to the target variable is obtained; the setting ciphertext is calculated by a setting digest algorithm.

[0082] In the embodiment of the present application, after obtaining the variable identifier, the electronic device can determine the state variable that the transaction user needs to operate (such as transaction), that is, the target variable, according to the variable identifier.

[0083] It should be noted that the electronic device pre-stores the setting ciphertext of each state variable in the locked state, so the electronic device can obtain the setting ciphertext corresponding to the target variable from its own storage. The setting ciphertext is calculated by the setting digest algorithm.

[0084] In one embodiment of the present application, since only the state variable in the locked state is set with its corresponding setting ciphertext, in order to improve work efficiency, the electronic device can specifically obtain the setting ciphertext corresponding to the target variable through the following steps, which are detailed as follows:

[0085] determining a target state of the target variable;

[0086] If the target state is a locked state, the setting ciphertext is obtained.

[0087] In this embodiment, the electronic device can detect the target state of the target variable at this time, wherein the target state includes but is not limited to: a locked state and an unlocked state.

[0088] When the electronic device detects that the target state of the target variable is a locked state, it indicates that the target variable is indeed a state variable that the transaction user needs to operate. At the same time, the target variable has its corresponding setting ciphertext, that is, the electronic device stores the setting ciphertext. Therefore, the electronic device can obtain the setting ciphertext corresponding to the target variable.

[0089] In some possible embodiments, the electronic device may execute a smart contract through a smart contract execution engine so that the smart contract detects whether a target variable is locked, that is, detects a target state of the target variable.

[0090] In one embodiment of the present application, when the electronic device detects that the target state of the target variable is an unlocked state, it indicates that the target variable is not a state variable that the trading user needs to operate, or in other words, the target variable does not have a corresponding set ciphertext, that is, the electronic device does not store the set ciphertext. Therefore, in order to improve the security of the smart contract, the electronic device can output a prompt message for indicating that the transaction of the target variable is wrong, and stop the transaction of the target variable.

[0091] In S103, the sub-privacy trigger script and each of the sub-privacy trigger script ciphertexts are calculated according to the set summary algorithm to obtain a target ciphertext.

[0092] In an embodiment of the present application, in order to detect whether the user to be traded has the authority to perform corresponding operations on the target variable, the electronic device can calculate the acquired sub-privacy trigger script and each sub-privacy trigger script ciphertext according to a set summary algorithm to obtain the target ciphertext.

[0093] In some possible embodiments, the electronic device can control the smart contract execution engine to calculate the above-mentioned sub-privacy trigger script and each sub-privacy trigger script ciphertext according to a set summary algorithm to obtain the target ciphertext.

[0094] In one embodiment of the present application, in order to improve the calculation accuracy of the target ciphertext, the electronic device can specifically Figure 2 The target ciphertext is calculated in steps S201 to S203, as described in detail below:

[0095] In S201, a callback method signature corresponding to the target variable is obtained.

[0096] In S202, the callback method signature and the sub-privacy trigger script are calculated respectively according to the set digest algorithm to obtain a first ciphertext corresponding to the signature and a second ciphertext corresponding to the sub-privacy trigger script.

[0097] In S203, the first ciphertext, the second ciphertext, and each of the sub-privacy trigger script ciphertexts are calculated according to the set digest algorithm to obtain the target ciphertext.

[0098] In this embodiment, the electronic device pre-stores the callback method signatures of each state variable in the smart contract. Therefore, at this time, the electronic device can obtain the callback method signature corresponding to the target variable from its own storage.

[0099] It should be noted that the callback method signature is used to find the called callback method in the smart contract.

[0100] In this embodiment, the electronic device can control the smart contract execution engine to calculate the callback method signature according to the set digest algorithm to obtain the first ciphertext corresponding to the callback method signature; the electronic device can also control the smart contract execution engine to calculate the sub-privacy trigger script of the transaction user according to the set digest algorithm to obtain the second ciphertext corresponding to the sub-privacy trigger script of the transaction user.

[0101] Afterwards, the electronic device can control the smart contract execution engine to combine the above-mentioned first ciphertext, the second ciphertext, and each sub-privacy trigger script ciphertext to obtain the first combined data.

[0102] In some possible embodiments, the first combined data may be obtained by combining: [first ciphertext, second ciphertext, first sub-privacy trigger script ciphertext, , the Nth sub-privacy trigger script ciphertext]. Where N specifically refers to the total number of remaining participating users.

[0103] It should be noted that the order of the ciphertexts of the sub-privacy trigger scripts can be determined according to actual needs and is not limited here.

[0104] In this embodiment, after obtaining the above-mentioned first combination data, the electronic device can control the smart contract execution engine to calculate the first combination data according to the set summary algorithm, so as to obtain the ciphertext corresponding to the first combination data, that is, the target ciphertext.

[0105] In the embodiment of the present application, after obtaining the target ciphertext, the electronic device may compare the target ciphertext with the acquired setting ciphertext of the target variable to detect whether the target ciphertext matches the setting ciphertext.

[0106] In one implementation of an embodiment of the present application, the electronic device can control the smart contract execution engine to compare the target ciphertext with the acquired set ciphertext of the target variable.

[0107] In one embodiment of the present application, when the electronic device detects that the target ciphertext is the same as the set ciphertext, that is, the target ciphertext matches the set ciphertext, steps S104 to S105 may be executed.

[0108] In another embodiment of the present application, when the electronic device detects that the target ciphertext is different from the set ciphertext, that is, the target ciphertext does not match the set ciphertext, it indicates that the sub-privacy trigger script input by the user to be traded is wrong. Therefore, the electronic device can output a prompt message to prompt the user to be traded that the sub-privacy trigger script input is wrong.

[0109] In S104, if the target ciphertext is the same as the set ciphertext, the determination script bytecode in the sub-privacy trigger script is executed to obtain an execution result; the determination script bytecode is used to determine whether the target variable can be unlocked.

[0110] In the embodiment of the present application, when the electronic device detects that the target ciphertext is the same as the set ciphertext, that is, the target ciphertext matches the set ciphertext, it indicates that the sub-privacy trigger script input by the transaction user is correct. Therefore, the electronic device can control the smart contract execution engine to execute the judgment script bytecode in the sub-privacy trigger script and obtain the execution result.

[0111] The execution results include but are not limited to: successful execution and failed execution. Successful execution is used to indicate that the sub-privacy trigger script input by the transaction user meets the conditions for unlocking the target variable. Failed execution is used to indicate that the sub-privacy trigger script input by the transaction user does not meet the conditions for unlocking the target variable.

[0112] In one embodiment of the present application, when the electronic device detects that the execution result is successful, it can execute step S105.

[0113] In another embodiment of the present application, when the electronic device detects that the execution result is an execution failure, it indicates that the sub-privacy trigger script input by the user to be traded does not meet the conditions for unlocking the target variable, that is, the target variable cannot be unlocked at this time, that is, the user to be traded cannot perform corresponding operations on the target variable. Therefore, the electronic device can output a prompt message to prompt that the sub-privacy trigger script input by the user to be traded does not meet the conditions for unlocking the target variable.

[0114] In S105, if the execution result is successful, a setting operation is performed on the target variable.

[0115] In the embodiment of the present application, when the electronic device detects that the execution result is successful, it means that the sub-privacy trigger script input by the transaction user meets the conditions for unlocking the target variable, that is, the target variable can be unlocked at this time, that is, the transaction user can perform corresponding operations on the target variable, so the electronic device can perform a setting operation on the target variable. The setting operation can be determined according to actual needs and is not limited here.

[0116] In some possible embodiments, when the target variable is a digital asset, its setting operation may be a digital asset transfer operation.

[0117] In one embodiment of the present application, since the sub-privacy trigger script of the user to be traded also includes a callback method parameter, in order to improve the execution success rate of the target variable and improve the user experience, the electronic device can specifically implement step S105 according to the following steps, which are described in detail as follows:

[0118] Obtaining a callback method signature corresponding to the target variable;

[0119] Determine a target callback method from the smart contract according to the callback method signature;

[0120] The target callback method is executed according to the callback method parameters to perform the setting operation on the target variable.

[0121] In this embodiment, after determining that the execution result is successful, the electronic device can obtain the callback method signature corresponding to the target variable, and control the smart contract execution engine to find the target callback method matching the target variable from the smart contract according to the callback method signature. Afterwards, the electronic device can control the smart contract execution engine to input the callback method parameters into the target callback method, and execute the target callback method, thereby realizing the setting operation of the target variable.

[0122] In some possible embodiments, when the operation is set as a digital asset transfer operation, the callback method parameters may include the account address of the user to be traded.

[0123] As can be seen from the above, a privacy protection method for a smart contract provided by an embodiment of the present application determines the target variable corresponding to the obtained variable identifier from the smart contract, and obtains the set ciphertext corresponding to the target variable; the obtained sub-privacy trigger script and each sub-privacy trigger script ciphertext are calculated according to the set summary algorithm to obtain the target ciphertext; if the target ciphertext is the same as the set ciphertext, the judgment script bytecode in the sub-privacy trigger script is executed to obtain the execution result; if the execution result is successful, the set operation is performed on the target variable. Compared with the prior art, the present application can only perform corresponding operations on a certain state variable of the smart contract after the sub-privacy trigger script of the transaction user and the sub-privacy trigger script ciphertext of the other participating users meet the requirements, that is, they are legal, thereby avoiding illegal operations of illegal participants and improving the security of the smart contract. At the same time, when unlocking the state variable, the present application will only disclose the sub-privacy trigger script of the transaction user, and the sub-privacy trigger scripts of the other participating users are not disclosed, which protects the privacy of the other participating users, thereby improving the privacy of the smart contract. In addition, the present application is not limited to the alliance chain, thereby expanding the scope of application.

[0124] In one embodiment of the present application, before step S101, in order to improve the security of the target variable, the owner of the target variable can lock the target variable so that the target variable can be accessed only when the ciphertext corresponding to the information input by each participating user related to the target variable meets the conditions (such as Figure 1 The target variable can only be unlocked and the corresponding operation can be performed on the target variable. The participating users related to the target variable can be determined by the owner of the target variable.

[0125] In this embodiment, before step S101, the electronic device can specifically lock the target variable according to the following steps, which are described in detail as follows:

[0126] In response to a lock instruction, determining a current state of the target variable;

[0127] If the current state is a locked state, outputting a prompt message for prompting that the target variable cannot be locked again;

[0128] If the current state is an unlocked state, the target variable is locked.

[0129] In this embodiment, when the owner of the target variable wants to lock the target variable, he can send a locking instruction to the electronic device.

[0130] After detecting the locking instruction, the electronic device can determine the current state of the target variable at this time, wherein the current state includes but is not limited to: a locked state and an unlocked state.

[0131] In this embodiment, the state variables in the smart contract can only be locked once.

[0132] Therefore, when the electronic device detects that the current state of the target variable is a locked state, it indicates that the target variable has been locked and cannot be locked again. Therefore, the electronic device can output a prompt message to indicate that the target variable cannot be locked again.

[0133] When the electronic device detects that the current state of the target variable is unlocked, it means that the target variable has not been locked, that is, the target variable can be locked. Therefore, the electronic device can control the smart contract execution engine to lock the target variable.

[0134] In one embodiment of the present application, in order to improve the security of the target variable and the security of the smart contract, while protecting the privacy of each participating user corresponding to the target variable and improving the privacy of the smart contract, the electronic device can specifically Figure 3 Steps S301 to S305 shown lock the target variable.

[0135] Based on this, see Figure 3 , Figure 3 This is a flowchart of the implementation of the privacy protection method of the smart contract provided by another embodiment of the present application. In this embodiment, the target variable can be locked through steps S301 to S305, as detailed below:

[0136] In S301, the preset determination script bytecode and preset callback method parameters corresponding to each participating user are obtained.

[0137] In S302, based on the preset determination script bytecode and preset callback method parameters corresponding to each of the participating users, a sub-privacy trigger script of each of the participating users is generated.

[0138] In S303, the callback method signature corresponding to the target variable and the sub-privacy trigger script of each participating user are calculated according to the set summary algorithm to obtain the third ciphertext corresponding to the callback method signature and the sub-privacy trigger script ciphertext of each participating user.

[0139] In S304, the third ciphertext and the sub-privacy trigger script ciphertexts of each of the participating users are calculated according to the set digest algorithm to obtain the set ciphertext.

[0140] In S305, the target variable is locked based on the set ciphertext.

[0141] In this embodiment, the owner of the target variable can write the sub-privacy trigger script corresponding to each participating user and write the callback method signature under the blockchain, so as to complete the writing of the privacy trigger script for the target variable.

[0142] It should be noted that since the sub-privacy trigger script includes the judgment script bytecode and callback method parameters, the owner of the target variable writes the sub-privacy trigger script corresponding to each participating user, including the writing of the judgment script bytecode and callback method parameters in each sub-privacy trigger script.

[0143] In this embodiment, since the owner of the target variable performs the above writing under the blockchain, the owner of the target variable can use the set summary algorithm under the blockchain to perform ciphertext calculations on the preset judgment script bytecode and preset callback method parameters corresponding to each participating user, and obtain the sub-privacy trigger script ciphertext of each participating user. Afterwards, the owner of the target variable can associate the sub-privacy trigger script ciphertext of each participating user with the target variable and store it in the blockchain.

[0144] In this embodiment, in order to obtain the final setting ciphertext of the target variable, the owner of the target variable can also use the setting digest algorithm under the blockchain to perform ciphertext calculation on the callback method signature to obtain the third ciphertext corresponding to the callback method signature.

[0145] Afterwards, the owner of the target variable combines the third ciphertext and the sub-privacy trigger script ciphertext of each participating user under the blockchain to obtain the second combined data.

[0146] In some possible embodiments, the second combined data may be obtained by combining: [third ciphertext, first sub-privacy trigger script ciphertext, , the N+1th sub-privacy trigger script ciphertext]. Wherein, N+1 specifically refers to the total number of all participating users.

[0147] It should be noted that the order of the ciphertexts of the sub-privacy trigger scripts can be determined according to actual needs and is not limited here.

[0148] In this embodiment, after the owner of the target variable obtains the above-mentioned second combination data under the blockchain, the owner of the target variable can also use the set summary algorithm under the blockchain to perform ciphertext calculation on the second combination data, thereby obtaining the ciphertext corresponding to the second combination data, that is, the set ciphertext, and associate the set ciphertext with the target variable and store it in the electronic device.

[0149] After obtaining the set ciphertext, the electronic device can lock the target variable based on the set ciphertext, so that the subsequent target variable can only be unlocked when the target ciphertext is the same as the set ciphertext.

[0150] In one embodiment of the present application, since the owner of the target variable writes the sub-privacy trigger script of each participating user under the blockchain, and calculates the sub-privacy trigger script ciphertext corresponding to each participating user under the blockchain, therefore, in order to improve the privacy of the smart contract and protect the privacy of each participating user, for any participating user, the owner of the target variable sends the sub-privacy trigger script of any participating user and the sub-privacy trigger script ciphertext corresponding to other participating users to the terminal device of any participating user under the blockchain. Among them, other participating users refer to all participating users except the any participating user.

[0151] Based on this, each participating user can only obtain his or her own public sub-privacy trigger script and the ciphertext of the sub-privacy trigger scripts of other participating users, that is, each participating user cannot obtain the public sub-privacy trigger scripts of other participating users.

[0152] From the above, it can be seen that the privacy protection method for smart contracts provided in this embodiment improves the security of the target variables and the security of the smart contracts by locking the state variables in the smart contracts, while protecting the privacy of each participating user corresponding to the target variables, thereby improving the privacy of the smart contracts and avoiding the possibility of the target variables being subsequently operated by illegal participants.

[0153] The method in this application will be described below with a specific example. The background of this example is: User A locks an asset M (i.e., target variable) in a smart contract: allowing his wife B (i.e., participating user B) to withdraw it at any time; also allowing his child C (i.e., participating user C) to withdraw it after 12 months; and allowing his brother D (i.e., participating user D) to withdraw it after 10 years.

[0154] First, user A can send a locking instruction for asset M to the electronic device.

[0155] Based on this, user A can write a privacy trigger script under the blockchain, which contains 3 sub-privacy trigger scripts and a callback method signature.

[0156] The callback method parameter is an account address, and the logic of the callback method is to transfer the asset M to the account address.

[0157] The judgment script bytecode recorded in the sub-privacy trigger script 1 is used to indicate whether the account address of the current contract caller is the account address of wife B, and the parameter of its callback method is the account address of wife B. After the conditions are met, the asset M can be transferred to the account address of wife B.

[0158] The judgment script bytecode recorded in the child privacy trigger script 2 is used to indicate whether the account address of the current contract caller is the account address of child C, and whether the current transaction time is 12 months away from the asset M lock time. The parameter of its callback method is the account address of child C. After the conditions are met, asset M can be transferred to the account address of child C.

[0159] The judgment script bytecode recorded in the sub-privacy trigger script 3 is used to indicate whether the account address of the current contract caller is the account address of brother D, and whether the current transaction time is 10 years away from the lock time of asset M. The parameter of its callback method is the account address of brother D. After the conditions are met, asset M can be transferred to the account address of brother D.

[0160] Afterwards, the electronic device can calculate the set ciphertext based on the above callback method signature, sub-privacy trigger script 1, sub-privacy trigger script 2, and sub-privacy trigger script 3.

[0161] Based on this, user A can construct a locking transaction, the content of which includes the variable identifier (Key) of the locked asset M, the set ciphertext of the privacy trigger script, and the signature of the callback method.

[0162] The electronic device detects the locking instruction and processes the locking logic of asset M through the smart contract, thereby locking asset M.

[0163] Specifically, the electronic device can execute the target contract through the smart contract execution engine, check whether user A is the owner of asset M, and after the check is passed, further check whether asset M is locked. If it is not locked, then asset M is marked as locked, and the set ciphertext and callback method signature corresponding to asset M are recorded.

[0164] Afterwards, user A can distribute their privacy scripts to his wife B, child C, and brother D.

[0165] For wife B, sub-privacy trigger script 1 is visible, and user A can distribute the complete sub-privacy trigger script 1, sub-privacy trigger script 2 ciphertext, and sub-privacy trigger script 3 ciphertext to wife B.

[0166] For child C, sub-privacy trigger script 2 is visible, and user A can distribute the complete sub-privacy trigger script 2 and the ciphertext of sub-privacy trigger script 1 and sub-privacy trigger script 3 to child C.

[0167] For brother D, sub-privacy trigger script 3 is visible, and user A can distribute the complete sub-privacy trigger script 3 and the ciphertext of sub-privacy trigger script 1 and sub-privacy trigger script 2 to brother D.

[0168] Six months later, when child C wants to withdraw asset M, child C can construct a transaction instruction and send it to the blockchain. The transaction instruction carries the variable identifier of the locked asset M, the called sub-privacy trigger script 2, the ciphertext of sub-privacy trigger script 1, and the ciphertext of sub-privacy trigger script 3.

[0169] At this point, the electronic device can execute the transaction through the smart contract execution engine. Specifically, after discovering that asset M is indeed locked and the input sub-privacy trigger script 2 is correct, the smart contract execution engine can start executing the judgment script bytecode of sub-privacy trigger script 2. Although the account address of child C meets the conditions, the call fails because the time does not meet the conditions. Therefore, child C cannot withdraw the asset M, that is, asset M cannot be unlocked.

[0170] When stranger E wants to steal asset M, stranger E constructs a transaction instruction and sends it to the blockchain. The transaction instruction carries the variable identifier of the locked asset M, the called forged sub-privacy trigger script 1, and several forged sub-privacy trigger script ciphertexts.

[0171] The electronic device can execute the transaction through the smart contract execution engine. Specifically, when it is found that asset M is indeed locked, but the input ciphertext calculated by the forged sub-privacy trigger script 1 and several forged sub-privacy trigger script ciphertexts cannot match the set ciphertext of asset M, the smart contract execution engine cannot operate asset M, and the call fails, that is, asset M cannot be unlocked, thereby avoiding illegal operations by illegal participants and improving the security of smart contracts.

[0172] When wife B wants to withdraw asset M, wife B can construct a transaction instruction and send it to the blockchain. The transaction instruction carries the variable identifier of the locked asset M, the called sub-privacy trigger script 1, the ciphertext of sub-privacy trigger script 2, and the ciphertext of sub-privacy trigger script 3.

[0173] The electronic device can execute the transaction through the smart contract execution engine. Specifically, when it is found that asset M is indeed locked and the input sub-privacy trigger script 1 is correct, the smart contract execution engine can start to execute the judgment script bytecode of sub-privacy trigger script 1. Since wife B's account address meets the judgment condition, the smart contract execution engine can then call the callback function, pass in the callback function parameter in sub-privacy trigger script 1 (i.e. wife B's account address), unlock asset M and transfer it to wife B's account address.

[0174] In the above example, for legal participants (such as wife B, child C and brother D) who trigger the transaction of asset M, only their own script information will be disclosed each time, and the script information of other legal participants will still be protected; for illegal participants, they cannot obtain the legal sub-privacy trigger script and cannot operate on asset M.

[0175] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0176] Corresponding to the privacy protection method of a smart contract described in the above embodiment, Figure 4 The following is a schematic diagram showing the structure of a privacy protection device for a smart contract provided by an embodiment of the present application. For ease of explanation, only the part related to the embodiment of the present application is shown. Figure 4 , the privacy protection device 400 of the smart contract includes: a first acquisition unit 41, a second acquisition unit 42, a first calculation unit 43, a first execution unit 44 and a second execution unit 45. Among them:

[0177] The first acquisition unit 41 is used to respond to the transaction instruction and obtain the variable identifier input by the user to be traded, the sub-privacy trigger script and the ciphertext of the sub-privacy trigger script of each of the other participating users; the sub-privacy trigger script is used to unlock the corresponding state variable in the smart contract.

[0178] The second acquisition unit 42 is used to determine the target variable corresponding to the variable identifier in the smart contract, and obtain the setting ciphertext corresponding to the target variable; the setting ciphertext is calculated by a setting summary algorithm.

[0179] The first calculation unit 43 is used to calculate the sub-privacy trigger script and each of the sub-privacy trigger script ciphertexts according to the set summary algorithm to obtain a target ciphertext.

[0180] The first execution unit 44 is used to execute the judgment script bytecode in the sub-privacy trigger script to obtain an execution result if the target ciphertext is the same as the set ciphertext; the judgment script bytecode is used to determine whether the target variable can be unlocked.

[0181] The second execution unit 45 is configured to execute a setting operation on the target variable if the execution result is successful.

[0182] In one embodiment of the present application, the second acquisition unit 42 specifically includes: a first determination unit and a third acquisition unit. Among them:

[0183] The first determining unit is used to determine a target state of the target variable.

[0184] The third acquisition unit is used to acquire the setting ciphertext if the target state is a locked state.

[0185] In one embodiment of the present application, the first calculation unit 43 specifically includes: a fourth acquisition unit, a second calculation unit and a third calculation unit. Among them:

[0186] The fourth acquisition unit is used to acquire the callback method signature corresponding to the target variable.

[0187] The second calculation unit is used to calculate the callback method signature and the sub-privacy trigger script respectively according to the set summary algorithm to obtain a first ciphertext corresponding to the signature and a second ciphertext corresponding to the sub-privacy trigger script.

[0188] The third calculation unit is used to calculate the first ciphertext, the second ciphertext and each of the sub-privacy trigger script ciphertexts according to the set summary algorithm to obtain the target ciphertext.

[0189] In one embodiment of the present application, the sub-privacy trigger script includes a callback method parameter; the first execution unit specifically includes: a fifth acquisition unit, a second determination unit and a third execution unit. Among them:

[0190] The fifth acquisition unit is used to acquire the callback method signature corresponding to the target variable.

[0191] The second determining unit is used to determine a target callback method from the smart contract according to the callback method signature.

[0192] The third execution unit is used to execute the target callback method according to the callback method parameters to perform the setting operation on the target variable.

[0193] In one embodiment of the present application, the privacy protection device 400 of the smart contract further includes: a third determination unit, an output unit and a first locking unit.

[0194] The third determining unit is used to determine the current state of the target variable in response to the locking instruction.

[0195] The output unit is used for outputting a prompt message for prompting that the target variable cannot be locked again if the current state is a locked state.

[0196] The first locking unit is used to lock the target variable if the current state is an unlocked state.

[0197] In one embodiment of the present application, the first locking unit specifically includes: a sixth acquisition unit, a generation unit, a fourth calculation unit, a fifth calculation unit and a second locking unit.

[0198] The sixth acquisition unit is used to acquire the preset determination script bytecode and preset callback method parameters corresponding to each participating user.

[0199] The generating unit is used to generate a sub-privacy triggering script for each participating user based on the preset determination script bytecode and preset callback method parameters corresponding to each participating user.

[0200] The fourth calculation unit is used to calculate the callback method signature corresponding to the target variable and the sub-privacy trigger script of each participating user according to the set summary algorithm, so as to obtain the third ciphertext corresponding to the callback method signature and the sub-privacy trigger script ciphertext of each participating user.

[0201] The fifth calculation unit is used to calculate the third ciphertext and the sub-privacy trigger script ciphertext of each participating user according to the set summary algorithm to obtain the set ciphertext.

[0202] The second locking unit is used to lock the target variable based on the set ciphertext.

[0203] In one embodiment of the present application, the privacy protection device 400 of the smart contract also includes: a sending unit.

[0204] The sending unit is used to send the sub-privacy trigger script of any participating user and the ciphertext of the sub-privacy trigger script corresponding to other participating users to the terminal device of the participating user; the other participating users refer to all participating users except the participating user.

[0205] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0206] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0207] Figure 5This is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application. Figure 5 As shown, the electronic device 5 of this embodiment includes: at least one processor 50 ( Figure 5 Only one is shown in the figure), a memory 51, and a computer program 52 stored in the memory 51 and executable on the at least one processor 50. When the processor 50 executes the computer program 52, the steps in any of the above-mentioned privacy protection method embodiments of the smart contract are implemented.

[0208] The electronic device 5 may include, but is not limited to, a processor 50 and a memory 51. Those skilled in the art will appreciate that Figure 5 It is only an example of the electronic device 5 and does not constitute a limitation on the electronic device 5. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include input and output devices, network access devices, etc.

[0209] The processor 50 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0210] In some embodiments, the memory 51 may be an internal storage unit of the electronic device 5, such as a memory of the electronic device 5. In other embodiments, the memory 51 may also be an external storage device of the electronic device 5, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 5. Further, the memory 51 may include both an internal storage unit and an external storage device of the electronic device 5. The memory 51 is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as the program code of the computer program. The memory 51 may also be used to temporarily store data that has been output or is to be output.

[0211] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.

[0212] An embodiment of the present application provides a computer program product. When the computer program product runs on an electronic device, the electronic device can implement the steps in the above-mentioned method embodiments when executing the computer program product.

[0213] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned various method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to an electronic device, a recording medium, a computer memory, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), an electric carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.

[0214] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0215] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A privacy protection method for smart contracts, characterized in that: include: In response to the transaction instruction, obtain the variable identifier input by the user to be traded, the sub-privacy trigger script, and the ciphertext of the sub-privacy trigger scripts of the remaining participating users; the sub-privacy trigger script is used to unlock the corresponding state variable in the smart contract; Determine the target variable corresponding to the variable identifier in the smart contract, and obtain the setting ciphertext corresponding to the target variable; the setting ciphertext is calculated by a setting digest algorithm; Calculate the sub-privacy trigger script and each of the sub-privacy trigger script ciphertexts according to the set summary algorithm to obtain a target ciphertext; If the target ciphertext is the same as the set ciphertext, the determination script bytecode in the sub-privacy trigger script is executed to obtain an execution result; the determination script bytecode is used to determine whether the target variable can be unlocked; If the execution result is successful, performing a setting operation on the target variable; The step of calculating the sub-privacy trigger script and each of the sub-privacy trigger script ciphertexts according to the set summary algorithm to obtain a target ciphertext includes: Obtaining a callback method signature corresponding to the target variable; Calculate the callback method signature and the sub-privacy trigger script respectively according to the set digest algorithm to obtain a first ciphertext corresponding to the signature and a second ciphertext corresponding to the sub-privacy trigger script; The first ciphertext, the second ciphertext, and each of the sub-privacy trigger script ciphertexts are calculated according to the set summary algorithm to obtain the target ciphertext.

2. The privacy protection method of a smart contract as claimed in claim 1, characterized in that: The obtaining of the setting ciphertext corresponding to the target variable includes: determining a target state of the target variable; If the target state is a locked state, the setting ciphertext is obtained.

3. The privacy protection method of the smart contract according to claim 1, characterized in that: The sub-privacy trigger script includes a callback method parameter; the setting operation performed on the target variable includes: Obtaining a callback method signature corresponding to the target variable; Determine a target callback method from the smart contract according to the callback method signature; The target callback method is executed according to the callback method parameters to perform the setting operation on the target variable.

4. The privacy protection method for a smart contract according to any one of claims 1 to 3, characterized in that: Before the step of obtaining the variable identifier, the sub-privacy trigger script and the ciphertext of the sub-privacy trigger scripts of the remaining participating users input by the transaction user in response to the transaction instruction, the step further includes: In response to a lock instruction, determining a current state of the target variable; If the current state is a locked state, outputting a prompt message for prompting that the target variable cannot be locked again; If the current state is an unlocked state, the target variable is locked.

5. The privacy protection method of a smart contract as claimed in claim 4, characterized in that: The locking of the target variable comprises: Obtain the preset judgment script bytecode and preset callback method parameters corresponding to each participating user; Generate a sub-privacy trigger script for each participating user based on the preset determination script bytecode and preset callback method parameters corresponding to each participating user; The callback method signature corresponding to the target variable and the sub-privacy trigger script of each participating user are calculated according to the set summary algorithm to obtain a third ciphertext corresponding to the callback method signature and a sub-privacy trigger script ciphertext of each participating user; Calculate the third ciphertext and the sub-privacy trigger script ciphertext of each participating user according to the set digest algorithm to obtain the set ciphertext; The target variable is locked based on the set ciphertext.

6. The privacy protection method of a smart contract as claimed in claim 5, characterized in that: After locking the target variable based on the set ciphertext, the method further includes: For any participating user, the sub-privacy trigger script of the participating user and the ciphertext of the sub-privacy trigger scripts corresponding to other participating users are sent to the terminal device of the participating user; the other participating users refer to all participating users except the participating user.

7. A privacy protection device for a smart contract, characterized in that: include: A first acquisition unit is used to obtain, in response to a transaction instruction, a variable identifier input by the user to be traded, a sub-privacy trigger script, and the ciphertext of the sub-privacy trigger scripts of the remaining participating users; the sub-privacy trigger script is used to unlock the corresponding state variable in the smart contract; A second acquisition unit is used to determine a target variable corresponding to the variable identifier in the smart contract, and obtain a setting ciphertext corresponding to the target variable; the setting ciphertext is calculated by a setting digest algorithm; A first calculation unit, configured to calculate the sub-privacy trigger script and each of the sub-privacy trigger script ciphertexts according to the set summary algorithm to obtain a target ciphertext; A first execution unit is configured to execute a determination script bytecode in the sub-privacy trigger script to obtain an execution result if the target ciphertext is the same as the set ciphertext; the determination script bytecode is used to determine whether the target variable can be unlocked; A second execution unit, configured to perform a setting operation on the target variable if the execution result is successful; The first calculation unit specifically includes: A fourth acquisition unit, used to acquire a callback method signature corresponding to the target variable; A second calculation unit is used to calculate the callback method signature and the sub-privacy trigger script respectively according to the set summary algorithm to obtain a first ciphertext corresponding to the signature and a second ciphertext corresponding to the sub-privacy trigger script; The third calculation unit is used to calculate the first ciphertext, the second ciphertext and each of the sub-privacy trigger script ciphertexts according to the set summary algorithm to obtain the target ciphertext.

8. An electronic device, characterized in that: The electronic device comprises a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the electronic device implements the privacy protection method for the smart contract as described in any one of claims 1 to 6.

9. A computer program product, characterized in that It includes a computer program, which, when executed, implements the privacy protection method for the smart contract as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Method and device for calling smart contract in block chain

    CN114331442A

  • Privacy protection method and apparatus for account data in blockchain

    WO2024221905A1