Smart contract access method, device, equipment and storage medium
Through the matching and encryption of account attributes with access policies and the problem of low security of privacy data after smart contract deployment is solved, effective protection of privacy data is achieved, and the security of privacy smart contracts is improved.
Patent Information
- Application Number
- CN202111639763.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-24
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2041-12-24
AI Technical Summary
After the smart contract is deployed on the blockchain, the risk of privacy data leakage due to the public status, and the existing technology cannot effectively protect the security of privacy data.
By obtaining the account attributes of the requested account to match the access policy of the privacy smart contract, access is only allowed when the match is successful, and the attribute encryption algorithm is used to generate private keys and public keys for encryption processing, ensuring that only the appropriate account can access and execute privacy intelligence contract.
Improve the security of privacy smart contracts, control access rights through account attributes, protect privacy data, and reduce the risk of privacy data leakage.
Smart Images

Figure CN114372281B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and in particular to a smart contract access method, device, equipment and storage medium. Background Art
[0002] Smart contracts are currently an indispensable module in blockchain. They are computer protocols designed to disseminate, verify or execute contracts in an information-based manner. Smart contracts allow for trusted transactions without a third party, which are traceable and irreversible.
[0003] When smart contracts are needed to process sensitive data, users do not want the sensitive data to be made public. This requires that smart contracts have the ability to protect data privacy when processing this data. However, after a privacy smart contract is deployed on the blockchain, it is in a public state and anyone can access it, resulting in the risk of privacy data being leaked. Therefore, how to improve the security of privacy smart contracts has become a technical problem that needs to be solved urgently.
[0004] The above contents are only used to assist in understanding the technical solution of the present invention and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of the present invention is to provide a smart contract access method, device, equipment and storage medium, aiming to solve the technical problem of low security of privacy smart contracts in the prior art.
[0006] To achieve the above object, the present invention provides a smart contract access method, which comprises the following steps:
[0007] Upon receiving an access request from a privacy smart contract on the blockchain, obtaining the account attributes of the account requesting access;
[0008] Matching the account attributes with the access policy corresponding to the privacy smart contract;
[0009] When the account attributes successfully match the access policy, the account requesting access is allowed to access the privacy smart contract.
[0010] Optionally, when receiving an access request to a privacy smart contract on the blockchain, before obtaining the account attributes of the account requesting access, the method further includes:
[0011] When encrypting a target smart contract, obtaining an access policy corresponding to the target smart contract;
[0012] The target smart contract is encrypted according to the access policy to obtain a privacy smart contract, and the privacy smart contract is uploaded to the blockchain.
[0013] Optionally, encrypting the target smart contract according to the access policy to obtain a privacy smart contract, and uploading the privacy smart contract to a blockchain, includes:
[0014] Initialize the target smart contract to obtain initialization data;
[0015] Encrypting the initialization data to obtain initialization encrypted data;
[0016] Obtaining the encryption public key of the initialization encryption data, and encrypting the encryption public key by an attribute encryption algorithm according to the access policy to obtain a target encryption public key corresponding to the access policy;
[0017] The target encrypted public key and the initial encrypted data are uploaded to the blockchain to obtain a privacy smart contract.
[0018] Optionally, matching the account attribute with an access policy corresponding to the privacy smart contract includes:
[0019] Generate an access attribute set according to the account attributes, and use an attribute encryption algorithm to generate an attribute private key of the requested access account according to the access attribute set;
[0020] Match the attribute private key with the access policy corresponding to the privacy smart contract.
[0021] Optionally, matching the attribute private key with an access policy corresponding to the privacy smart contract includes:
[0022] Obtaining a target encryption public key corresponding to the access policy;
[0023] The attribute private key is matched with the target encryption public key.
[0024] Optionally, when the account attribute successfully matches the access policy, allowing the account requesting access to access the privacy smart contract includes:
[0025] When the attribute private key successfully matches the target encryption public key, the account requesting access is allowed to access the privacy smart contract.
[0026] Optionally, when the attribute private key successfully matches the target encryption public key, after allowing the requesting access account to access the privacy smart contract, the method further includes:
[0027] Parsing an encrypted public key from the target encrypted public key according to the attribute private key, and calling the privacy smart contract according to the encrypted public key;
[0028] The privacy smart contract is decrypted using the encrypted private key corresponding to the encrypted public key, and the decrypted privacy smart contract is executed.
[0029] In addition, to achieve the above-mentioned purpose, the present invention also proposes a smart contract access device, the device comprising:
[0030] An acquisition module, used to obtain the account attributes of the account requesting access when receiving an access request from a privacy smart contract on the blockchain;
[0031] A matching module, used to match the account attributes with the access policy corresponding to the privacy smart contract;
[0032] An access module is used to allow the account requesting access to access the privacy smart contract when the account attributes successfully match the access policy.
[0033] In addition, to achieve the above-mentioned purpose, the present invention also proposes a smart contract access device, which includes: a memory, a processor, and a smart contract access program stored in the memory and executable on the processor, and the smart contract access program is configured to implement the steps of the smart contract access method described above.
[0034] In addition, to achieve the above-mentioned purpose, the present invention also proposes a storage medium, on which a smart contract access program is stored. When the smart contract access program is executed by a processor, the steps of the smart contract access method described above are implemented.
[0035] When receiving an access request to a privacy smart contract on a blockchain, the present invention obtains the account attributes of the account requesting access; matches the account attributes with the access policy corresponding to the privacy smart contract; and allows the account requesting access to access the privacy smart contract when the account attributes successfully match the access policy. Since the present invention obtains the account attributes of the account accessing the privacy smart contract, and allows access to the privacy smart contract when the account attributes match the access policy corresponding to the privacy smart contract, the permission to access the privacy smart contract can be controlled through the account attributes, thereby achieving the purpose of protecting privacy data and improving the security of the privacy smart contract. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 It is a structural diagram of a smart contract access device in a hardware operating environment involved in an embodiment of the present invention;
[0037] Figure 2 This is a flow chart of the first embodiment of the smart contract access method of the present invention;
[0038] Figure 3This is a schematic diagram of requesting access to an account to access a private smart contract in the first embodiment of the smart contract access method of the present invention;
[0039] Figure 4 This is a flow chart of the second embodiment of the smart contract access method of the present invention;
[0040] Figure 5 This is a schematic diagram of the initialization process in the second embodiment of the smart contract access method of the present invention;
[0041] Figure 6 This is a schematic diagram of a user deploying a privacy smart contract on a blockchain in the second embodiment of the smart contract access method of the present invention;
[0042] Figure 7 This is a structural block diagram of the first embodiment of the smart contract access device of the present invention.
[0043] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0044] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0045] Reference Figure 1 , Figure 1 A schematic diagram of the structure of a smart contract access device in a hardware operating environment according to an embodiment of the present invention.
[0046] like Figure 1 As shown, the smart contract access device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (Wireless-Fidelity, WI-FI) interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM), or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk storage. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0047] Those skilled in the art will understand that Figure 1 The structure shown in does not constitute a limitation on the smart contract access device and may include more or fewer components than shown in the figure, or a combination of certain components, or a different arrangement of components.
[0048] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a smart contract access program.
[0049] exist Figure 1 In the smart contract access device shown, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the smart contract access device of the present invention can be set in the smart contract access device, and the smart contract access device calls the smart contract access program stored in the memory 1005 through the processor 1001, and executes the smart contract access method provided by the embodiment of the present invention.
[0050] The embodiment of the present invention provides a smart contract access method, referring to Figure 2 , Figure 2 Schematic diagram of the process of the first embodiment of the smart contract access method of the present invention.
[0051] In this embodiment, the smart contract access method includes the following steps:
[0052] Step S10: When receiving an access request to a privacy smart contract on the blockchain, obtain the account attributes of the account requesting access.
[0053] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a smart contract access device, etc. The following takes the smart contract access device as an example to illustrate this embodiment and the following embodiments.
[0054] It can be understood that a privacy smart contract can be a smart contract deployed by a user on a blockchain that requires access control; the account requesting access can be an account requesting access to the privacy smart contract deployed on the blockchain, where the account requesting access can be any account created on the blockchain.
[0055] It should be understood that the account attributes may be attributes added to the created account when the account is created on the blockchain, wherein the account attributes include attributes such as organization, department, role, and level; for example, the account attributes may be attributes added to the account when a user with administrator privileges creates an account for other users on the blockchain; the account attributes may also be attributes added to the account when a user creates an account for himself on the blockchain, and this embodiment does not limit this.
[0056] It can be understood that the organization (organization) indicates the organization to which the user corresponding to the account belongs; the department (department) indicates the department to which the user corresponding to the account belongs in the organization; the role (character) indicates the identity of the user corresponding to the account; and the level (level) indicates the identity registration of the user corresponding to the account.
[0057] In a specific implementation, when a smart contract access device receives a request to access a privacy smart contract deployed on a blockchain, it obtains the account attributes of the account requesting access. The account attributes are the attributes added to the account when the account requesting access is created on the blockchain.
[0058] Step S20: Match the account attributes with the access policy corresponding to the privacy smart contract.
[0059] It can be understood that the access policy can be the access permission control policy of the privacy smart contract formulated by the user when deploying the privacy smart contract on the blockchain. The access policy can be composed of account attributes and logical operators; when the user deploys the privacy smart contract on the blockchain, the access policy corresponding to the privacy smart contract is formulated.
[0060] In a specific implementation, the smart contract access device will match the account attributes added to the account when creating a request to access the account on the blockchain with the access permission control policy of the privacy smart contract formulated by the user when deploying the privacy smart contract on the blockchain, where the access policy consists of account attributes and logical operators.
[0061] Step S30: When the account attributes successfully match the access policy, the account requesting access is allowed to access the privacy smart contract.
[0062] In a specific implementation, for example, account attributes include organization, department, character, and level, and logical operators include or and and. When a user deploys a privacy smart contract on a blockchain, the access policy formulated for the privacy smart contract is: [(organization-1and department-2)or(organization-1and level-7)], indicating that the account corresponding to department-2 in organization-1 or the account corresponding to level-7 in organization-1 is allowed to access the privacy smart contract. When the smart contract access device receives a request to access the privacy smart contract, the account attributes of the requested access account obtained are: organization-1and department-2. The account attributes of the requested access account successfully match the access policy corresponding to the privacy smart contract, and the requested access account is allowed to access the privacy smart contract. The above example is for the purpose of clearly illustrating the present embodiment and does not constitute a limitation to the present embodiment.
[0063] Furthermore, in order to improve the security of privacy intelligence, the step S20 includes: generating an access attribute set according to the account attributes, and using an attribute encryption algorithm to generate an attribute private key of the requested access account according to the access attribute set; matching the attribute private key with the access policy corresponding to the privacy intelligence contract.
[0064] It should be understood that when requesting access to an account and requesting access to a privacy smart contract, it is necessary to apply for a secret key first. The account requesting access sends a secret key application request to the smart contract access device. When the smart contract access device receives the secret key application request, it generates an access attribute set based on the account attributes of the account requested to access; the access attribute set can be a set of account attributes of the account requested to access.
[0065] It can be understood that the attribute encryption algorithm can be the CP-ABE algorithm; after the smart contract access device is started, a pair of secret keys {ABE-PK, ABE-MK} will be initialized based on the CP-ABE algorithm; using the attribute encryption algorithm to generate the attribute private key for requesting access to the account according to the access attribute set can be using the CP-ABE algorithm to generate the attribute private key U-ABE-MK for requesting access to the account according to the access attribute set and the secret key pair {ABE-PK, ABE-MK}.
[0066] In the specific implementation, after the smart contract access device is started, a pair of secret keys {ABE-PK, ABE-MK} is initialized based on the CP-ABE algorithm. When the smart contract access device receives a secret key application request, it generates an access attribute set according to the account attributes of the account requested for access, and uses the CP-ABE algorithm to generate the attribute private key U-ABE-MK of the account requested for access based on the access attribute set and the secret key pair {ABE-PK, ABE-MK}.
[0067] In the specific implementation, please refer to Figure 3 The smart contract access device may include a privacy contract agent and a privacy contract execution environment. When requesting access to a privacy smart contract, the account requesting access sends a secret key application request to the privacy contract agent of the smart contract access device. After receiving the secret key application request, the privacy contract agent of the smart contract access device generates an access attribute set S according to the account attributes of the account requested to access. The privacy contract agent sends the access attribute set S of the user to the privacy contract execution environment of the smart contract access device. The privacy contract execution environment uses the CP-ABE algorithm to generate the attribute private key U-ABE-MK of the account requested to access based on the parameters {access attribute set S, ABE-PK, ABE-MK}, and sends U-ABE-MK to the privacy contract agent.
[0068] Furthermore, in order to improve the security of the privacy smart contract, the attribute private key is matched with the access policy corresponding to the privacy smart contract, including: obtaining a target encryption public key corresponding to the access policy; matching the attribute private key with the target encryption public key.
[0069] It is understandable that when deploying a privacy smart contract on the blockchain, the privacy smart contract needs to be encrypted. After encrypting the privacy smart contract, a pair of encrypted public and private key pairs will be generated. The target encrypted public key can be the public key obtained by encrypting the encrypted public key of the privacy smart contract using the attribute encryption algorithm; for example, when a user deploys a privacy smart contract on the blockchain, the privacy smart contract to be deployed and the access policy formulated for the privacy smart contract are sent to the smart contract access device. The smart contract access device encrypts the privacy smart contract to generate an encrypted public key and an encrypted private key. The smart contract access device encrypts the encrypted public key using the CP-ABE algorithm according to the access policy to obtain the target encrypted public key. The target encrypted public key can be represented by C-EN-PK.
[0070] In the specific implementation, the smart contract access device obtains the target encrypted public key corresponding to the access policy set by the user, and matches the attribute private key of the account requesting access with the target encrypted public key.
[0071] Furthermore, in order to improve the security of the privacy smart contract, the step S30 includes: when the attribute private key successfully matches the target encryption public key, allowing the requesting access account to access the privacy smart contract.
[0072] It can be understood that the attribute private key of the account requested for access is matched with the target encryption public key. When the account attributes of the account requested for access comply with the access policy corresponding to the privacy smart contract, the attribute private key and the target encryption public key can be successfully matched.
[0073] In a specific implementation, for example, if the account attributes of the account requested to be accessed comply with the access policy corresponding to the privacy smart contract, the attribute private key and the target encrypted public key can be successfully matched, and the attribute private key can be used to parse the encrypted public key of the privacy smart contract from the target encrypted public key. The corresponding privacy smart contract can be called and accessed based on the parsed encrypted public key.
[0074] Furthermore, in order to improve the security of the privacy smart contract, when the attribute private key and the target encryption public key match successfully, after the requesting access account is allowed to access the privacy smart contract, the method also includes: parsing the encryption public key from the target encryption public key according to the attribute private key, and calling the privacy smart contract according to the encryption public key; decrypting the privacy smart contract through the encryption private key corresponding to the encryption public key, and executing the decrypted privacy smart contract.
[0075] It can be understood that calling the privacy smart contract according to the encrypted public key can be to determine the contract name of the privacy smart contract according to the encrypted public key, and call the privacy smart contract according to the contract name, wherein the called privacy smart contract includes information such as the contract source code and the contract status; in order to protect user information, the contract parameter information can also be encrypted when calling the privacy smart contract.
[0076] In the specific implementation, when the attribute private key of the smart contract access device requests access and the target encrypted public key successfully matches, the encrypted public key for the privacy smart contract is parsed from the target encrypted public key according to the attribute private key of the account requesting access, the contract name of the privacy smart contract is determined by the encrypted public key, the privacy smart contract is called according to the contract name, and when calling the privacy smart contract, the contract parameter information is encrypting by the encrypted public key, the privacy smart contract is decrypted by the encrypted private key of the privacy smart contract, and the decrypted privacy smart contract is executed, and the CP-ABE algorithm is used to encrypt the return data of the privacy smart contract based on {encrypted public key, access policy, ABE-PK}, and the encrypted data is uploaded to the blockchain.
[0077] When receiving an access request to a privacy smart contract on a blockchain, this embodiment obtains the account attributes of the account requesting access; matches the account attributes with the access policy corresponding to the privacy smart contract; and allows the account requesting access to access the privacy smart contract when the account attributes successfully match the access policy. Since this embodiment obtains the account attributes of the account accessing the privacy smart contract, and allows access to the privacy smart contract when the account attributes match the access policy corresponding to the privacy smart contract, the permission to access the privacy smart contract can be controlled through the account attributes, thereby achieving the purpose of protecting privacy data and improving the security of the privacy smart contract.
[0078] refer to Figure 4 , Figure 4 Schematic diagram of the flow chart of the second embodiment of the smart contract access method of the present invention.
[0079] Based on the first embodiment above, in this embodiment, before step S10, the method further includes:
[0080] Step S01: When encrypting a target smart contract, obtain the access policy corresponding to the target smart contract.
[0081] It can be understood that the smart contract access device includes a privacy contract agent and a privacy contract execution environment. The privacy contract execution environment can be a trusted execution environment - TEE, which can ensure that the programs inside it are not interfered with by the conventional operating system. It can be regarded as a sandbox environment isolated from the outside world; the privacy contract agent can be a bridge between the privacy contract execution environment and the blockchain, and can perform data processing and data transmission.
[0082] It should be understood that when encrypting the target smart contract, before obtaining the access policy corresponding to the target smart contract, it can also be initialized when the blockchain environment is started.
[0083] It is understandable that the process of smart contract access device initialization can refer to Figure 5 After the blockchain environment is started, the privacy contract agent of the smart contract access device sends an initialization instruction to the privacy contract execution environment. The privacy contract execution environment of the smart contract access device initializes a pair of secret keys {ABE-PK, ABE-MK} based on the CP-ABE algorithm, where ABE-PK is a public parameter and ABE-MK is the master secret key. The privacy contract execution environment sends ABE-PK to the privacy contract agent, and the privacy contract agent uploads ABE-PK to the blockchain. Any account on the blockchain can obtain the ABE-PK.
[0084] It can be understood that when the target smart contract is encrypted, the access policy of the target smart contract can be obtained by sending the target smart contract to be encrypted and the access policy formulated for the target smart contract to the smart contract access device when the user deploys the privacy smart contract on the blockchain, and the privacy contract agent of the smart contract access device obtains the target smart contract and the corresponding access policy.
[0085] It should be understood that when encrypting the target smart contract, if on-chain data on the blockchain is required, the privacy contract agent of the smart contract access device obtains the target smart contract, access policy and on-chain data, and sends the target smart contract, access policy and on-chain data to the privacy contract execution environment of the smart contract access device.
[0086] Step S02: Encrypt the target smart contract according to the access policy to obtain a privacy smart contract, and upload the privacy smart contract to the blockchain.
[0087] It can be understood that encrypting the target smart contract according to the access policy can be that after the privacy contract execution environment of the smart contract access device receives the user's deployment request, the CP-ABE algorithm is used to encrypt the privacy smart contract according to the access policy.
[0088] In the specific implementation, when the user needs to deploy a privacy smart contract on the blockchain, the target smart contract to be encrypted and the access policy formulated for the target smart contract are sent to the smart contract access device. The privacy contract agent of the smart contract access device obtains the target smart contract and the access policy. If on-chain data on the blockchain is required, the on-chain data is obtained at the same time, and the target smart contract, access policy and on-chain data are packaged and sent to the privacy contract execution environment of the smart contract access device. The privacy contract execution environment uses the CP-ABE algorithm to encrypt the target smart contract according to the access policy, obtains the privacy smart contract, and uploads the privacy smart contract to the blockchain to complete the deployment of the privacy smart contract on the blockchain.
[0089] Furthermore, in order to reduce the amount of encrypted data and improve data processing efficiency, the step S03 includes: initializing the target smart contract to obtain initialization data; encrypting the initialization data to obtain initialization encrypted data; obtaining the encryption public key of the initialization encrypted data, and encrypting the encryption public key through the attribute encryption algorithm according to the access policy to obtain the target encryption public key corresponding to the access policy; uploading the target encryption public key and the initialization encrypted data to the blockchain to obtain a privacy smart contract.
[0090] It can be understood that initializing the target smart contract and obtaining the initialization data may be initializing the target smart contract in WASM to obtain the initialization data.
[0091] It should be understood that encrypting the initialization data and obtaining the initialization encrypted data can be that the privacy contract execution environment of the smart contract access device encrypts the initialization data based on the environment hardware inherent key, obtains the initialization encrypted data, and generates a pair of encrypted public and private key pairs {EN-PK, EN-SK}.
[0092] It can be understood that the encryption public key is encrypted according to the access policy using an attribute encryption algorithm, and the target encryption public key corresponding to the access policy is obtained by using a CP-ABE algorithm, and the encryption public key of the initialization encrypted data is encrypted according to the access policy to obtain the target encryption public key corresponding to the access policy.
[0093] In the specific implementation, please refer to Figure 6 For example, when a user deploys a privacy smart contract on the blockchain, the target smart contract and the access policy formulated for the target smart contract are sent to the smart contract access device. The privacy contract agent of the smart contract access device obtains the target smart contract, access policy and on-chain data, and packages the target smart contract, access policy and on-chain data and sends them to the privacy contract execution environment of the smart contract access device. When the privacy contract execution environment receives the user's deployment request, it initializes the target smart contract in WASM, obtains the initialization data, and generates a pair of encrypted public and private key pairs {EN-PK, EN-SK} based on the execution environment hardware inherent secret key to encrypt the initialization data. The privacy contract execution environment uses the CP-ABE algorithm to encrypt the encrypted public key EN-PK of the target smart contract based on the parameters {encrypted public key EN-PK, access policy, ABE-PK}, obtains the target encrypted public key C-EN-PK corresponding to the access policy, and sends the initialized encrypted data and C-EN-PK to the privacy contract agent. The privacy contract agent uploads the initialized encrypted data and C-EN-PK to the blockchain.
[0094] When encrypting the target smart contract, this embodiment obtains the access policy corresponding to the target smart contract; initializes the target smart contract to obtain initialization data; encrypts the initialization data to obtain the initialization encrypted data; obtains the encryption public key of the initialization encrypted data, and encrypts the encryption public key by the attribute encryption algorithm according to the access policy to obtain the target encryption public key corresponding to the access policy; uploads the target encryption public key and the initialization encrypted data to the blockchain to obtain the privacy smart contract. Since this embodiment uses the attribute encryption algorithm to encrypt the encryption public key of the target smart contract according to the access policy formulated by the user to obtain the target encryption public key, uploads the target encryption public key and the initialization encrypted data to the blockchain to complete the deployment of the privacy smart contract, it realizes the control of the privacy smart access rights according to the account attributes, improves the security of the privacy smart contract, and only needs to use the attribute encryption algorithm to encrypt the encryption public key of the target smart contract, which reduces the amount of encrypted data and improves the data processing efficiency.
[0095] In addition, an embodiment of the present invention further proposes a storage medium, on which a smart contract access program is stored. When the smart contract access program is executed by a processor, the steps of the smart contract access method described above are implemented.
[0096] Reference Figure 7 , Figure 7 This is a structural block diagram of the first embodiment of the smart contract access device of the present invention.
[0097] like Figure 7 As shown, the smart contract access device proposed in the embodiment of the present invention includes: an acquisition module 10, a matching module 20 and an access module 30.
[0098] The acquisition module 10 is used to obtain the account attributes of the account requesting access when receiving an access request of the privacy smart contract on the blockchain;
[0099] The matching module 20 is used to match the account attributes with the access policy corresponding to the privacy smart contract;
[0100] The access module 30 is used to allow the account requesting access to access the privacy smart contract when the account attributes successfully match the access policy.
[0101] When receiving an access request to a privacy smart contract on a blockchain, this embodiment obtains the account attributes of the account requesting access; matches the account attributes with the access policy corresponding to the privacy smart contract; and allows the account requesting access to access the privacy smart contract when the account attributes successfully match the access policy. Since this embodiment obtains the account attributes of the account accessing the privacy smart contract, and allows access to the privacy smart contract when the account attributes match the access policy corresponding to the privacy smart contract, the permission to access the privacy smart contract can be controlled through the account attributes, thereby achieving the purpose of protecting privacy data and improving the security of the privacy smart contract.
[0102] Based on the above-mentioned first embodiment of the smart contract access device of the present invention, a second embodiment of the smart contract access device of the present invention is proposed.
[0103] In this embodiment, the acquisition module 10 is also used to obtain the access policy corresponding to the target smart contract when the target smart contract is encrypted; the target smart contract is encrypting according to the access policy to obtain a privacy smart contract, and the privacy smart contract is uploaded to the blockchain.
[0104] The acquisition module 10 is also used to initialize the target smart contract to obtain initialization data; encrypt the initialization data to obtain initialization encrypted data; obtain the encrypted public key of the initialization encrypted data, and encrypt the encrypted public key through the attribute encryption algorithm according to the access policy to obtain the target encrypted public key corresponding to the access policy; upload the target encrypted public key and the initialization encrypted data to the blockchain to obtain a privacy smart contract.
[0105] The matching module 20 is also used to generate an access attribute set based on the account attributes, and use an attribute encryption algorithm to generate an attribute private key of the requested access account based on the access attribute set; and match the attribute private key with the access policy corresponding to the privacy smart contract.
[0106] The matching module 20 is further used to obtain a target encryption public key corresponding to the access policy; and match the attribute private key with the target encryption public key.
[0107] The access module 30 is also used to allow the account requesting access to access the privacy smart contract when the attribute private key successfully matches the target encryption public key.
[0108] The access module 30 is also used to parse the encrypted public key from the target encrypted public key according to the attribute private key, and call the privacy smart contract according to the encrypted public key; decrypt the privacy smart contract through the encrypted private key corresponding to the encrypted public key, and execute the decrypted privacy smart contract.
[0109] Other embodiments or specific implementations of the smart contract access device of the present invention can refer to the above-mentioned method embodiments and will not be described in detail here.
[0110] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0111] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0112] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory / random access memory, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0113] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A smart contract access method, characterized in that: The method comprises: Upon receiving an access request from a privacy smart contract on the blockchain, obtaining the account attributes of the account requesting access; Generate an access attribute set according to the account attributes, and use an attribute encryption algorithm to generate an attribute private key of the requested access account according to the access attribute set; Matching the attribute private key with the access policy corresponding to the privacy smart contract; When the attribute private key successfully matches the access policy, allowing the account requesting access to access the privacy smart contract; When receiving an access request to a privacy smart contract on the blockchain, before obtaining the account attributes of the account requesting access, the method further includes: When encrypting a target smart contract, obtaining an access policy corresponding to the target smart contract; Initialize the target smart contract to obtain initialization data; Encrypting the initialization data based on the environment hardware inherent secret key to obtain initialization encrypted data; Obtaining the encryption public key of the initialization encryption data, and encrypting the encryption public key by an attribute encryption algorithm according to the access policy to obtain a target encryption public key corresponding to the access policy; The target encrypted public key and the initial encrypted data are uploaded to the blockchain to obtain a privacy smart contract.
2. The method according to claim 1, characterized in that The matching of the attribute private key with the access policy corresponding to the privacy smart contract includes: Obtaining a target encryption public key corresponding to the access policy; The attribute private key is matched with the target encryption public key.
3. The method according to claim 2, characterized in that When the attribute private key successfully matches the access policy, allowing the account requesting access to access the privacy smart contract includes: When the attribute private key successfully matches the target encryption public key, the account requesting access is allowed to access the privacy smart contract.
4. The method according to claim 3, characterized in that When the attribute private key successfully matches the target encryption public key, after allowing the requesting access account to access the privacy smart contract, the method further includes: Parsing an encrypted public key from the target encrypted public key according to the attribute private key, and calling the privacy smart contract according to the encrypted public key; The privacy smart contract is decrypted using the encrypted private key corresponding to the encrypted public key, and the decrypted privacy smart contract is executed.
5. A smart contract access device, characterized in that: The device comprises: An acquisition module, used to obtain the account attributes of the account requesting access when receiving an access request from a privacy smart contract on the blockchain; A matching module, used to generate an access attribute set according to the account attributes, and to generate an attribute private key of the requested access account according to the access attribute set using an attribute encryption algorithm; The matching module is further used to match the attribute private key with the access policy corresponding to the privacy smart contract; An access module, configured to allow the account requesting access to access the privacy smart contract when the attribute private key successfully matches the access policy; The acquisition module is also used to obtain the access policy corresponding to the target smart contract when encrypting the target smart contract; initialize the target smart contract to obtain initialization data; encrypt the initialization data based on the inherent secret key of the environment hardware to obtain the initialization encrypted data; obtain the encrypted public key of the initialization encrypted data, and encrypt the encrypted public key through the attribute encryption algorithm according to the access policy to obtain the target encrypted public key corresponding to the access policy; upload the target encrypted public key and the initialization encrypted data to the blockchain to obtain a privacy smart contract.
6. A smart contract access device, characterized in that: The device includes: a memory, a processor, and a smart contract access program stored in the memory and executable on the processor, wherein the smart contract access program is configured to implement the steps of the smart contract access method as described in any one of claims 1 to 4.
7. A storage medium, characterized in that: The storage medium stores a smart contract access program, and when the smart contract access program is executed by the processor, the steps of the smart contract access method according to any one of claims 1 to 4 are implemented.
