Block chain smart contract privacy protection method based on trusted execution environment and assembly comparison calculation
By embedding assembly language comparison calculations in a trusted execution environment, the method secures smart contract execution, preventing memory access leaks and inference attacks, ensuring privacy and performance in blockchain networks.
Patent Information
- Application Number
- CN202411258604.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2024-12-27
- Estimated Expiration
- 2044-09-09
AI Technical Summary
Blockchain smart contracts are vulnerable to memory access mode leakage and inference attacks from malicious nodes, compromising privacy and security, especially in trusted execution environments.
Implement a secure enclave within a trusted execution environment using assembly language comparison calculations to execute smart contracts, ensuring secure execution and data confidentiality, and integrate cryptographic keys for encryption and verification.
Prevents memory access pattern leakage and inference attacks, maintaining data integrity and privacy while ensuring high performance and scalability, with secure execution and verification of transactions.
Smart Images

Figure CN119203152A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a blockchain smart contract privacy protection method based on a trusted execution environment and assembly comparison calculation, and belongs to the technical field of blockchain. Background Art
[0002] With the continuous development of blockchain technology, its application scenarios are becoming more and more extensive around the world. As the core of blockchain technology, smart contracts have played a huge role in reducing intermediary dependence and improving transaction efficiency. However, with the widespread application of smart contracts, the privacy protection challenges they face are becoming increasingly severe. All transactions and smart contract execution records in the blockchain network are publicly stored on the chain, and any network node has the ability to access and verify this data. Although this design ensures the immutability and credibility of blockchain data, it also exposes sensitive data and key business logic to the risk of being stolen or analyzed by malicious nodes. For smart contracts, once their execution process or related data is leaked, it may not only infringe on the privacy rights of the contract participants, but also lead to a series of serious consequences such as contract execution failure and financial loss, seriously damaging the credibility and sustainable development of blockchain technology.
[0003] The existing solutions for privacy protection of blockchain smart contracts need to solve the scalability problem of blockchain while ensuring high security. High computing requirements and complex privacy protection protocols may limit the scalability of blockchain networks. Blockchain smart contract privacy protection solutions based on trusted execution environments have the risk of memory access mode leakage. It is urgent to solve how to combine the hardware-level security features of the trusted execution environment with the distributed architecture of the blockchain, so as to more effectively ensure that the transaction processing processes between nodes and within a single node can be carried out in a secure and trusted environment, realize the isolation and protection of the smart contract execution process, and prevent malicious operating systems from inferring attacks on the smart contract execution process.
[0004] After preliminary search, the relevant prior art is as follows:
[0005] Invention patent CN110245506B describes a blockchain-based smart contract management method and device, which manages the call of smart contracts on a blockchain node device equipped with a trusted execution environment. If the smart contract is not marked as managed, its encrypted contract code can be decrypted and executed in the trusted execution environment of the node device, and the execution result is encrypted and stored on the blockchain. This method allows content supervision of specific smart contracts while protecting the privacy of smart contracts, achieving a balance between privacy protection and effective management. Although the use of a trusted execution environment in this patent improves the execution security of smart contracts, these environments may have security vulnerabilities, such as memory access pattern leaks, which may threaten the privacy of data. As the blockchain network expands, the complexity of managing and storing decryption keys may increase, and more complex management mechanisms may be required to track and update regulatory rules. The disadvantages correspond to the purpose of the present invention.
[0006] Invention patent CN110520884B describes an off-chain smart contract service method based on a trusted execution environment, which aims to provide privacy-protected cross-chain data operations. The smart contract service provider, external to the target blockchain network, receives the client's cross-chain data operation request, executes the calculation logic and generates the result through the trusted execution environment, and then returns it to the client. This method involves a data access service provider and may involve verifying whether the parties contain a trusted execution environment to ensure security. In addition, the result may be signed with a private key, and the client can decrypt it using a public key. The system is applicable to cloud servers, and cross-chain data may come from multiple blockchain networks. In cross-chain data operations, it is crucial to ensure that only authorized participants can access and process data. However, the patent text does not mention how to implement access control and permission management of data. This may lead to the risk of unauthorized participants obtaining sensitive information. The patent does not discuss in detail how to prevent the impact of malicious attacks on cross-chain data operations. This makes the service potentially vulnerable and risky in the face of potential security threats. The disadvantages correspond to the purpose of the present invention. Summary of the invention
[0007] The present invention aims to solve the problem that blockchain smart contracts are at risk of being stolen or analyzed by malicious nodes. Although the existing technical solutions provide solutions for blockchain smart contract privacy protection, such as placing smart contracts in a trusted execution environment for execution, the memory access mode leakage problem faced by smart contracts during execution has not been solved. The present invention intends to place the execution process of smart contracts in a secure enclave of a trusted execution environment. The blockchain verifies and records the generated transactions. The smart contract party retrieves and checks the data related to the smart contract and enclave instance, serializes and submits the smart contract status update. By embedding the assembly language comparison algorithm into the trusted execution environment and replacing the comparison calculation in the trusted execution environment, the inference attack of the malicious operating system on the smart contract execution process is effectively prevented.
[0008] In order to solve the above technical problems, the present invention provides a blockchain smart contract privacy protection method based on a trusted execution environment and assembly comparison calculation, comprising the following steps:
[0009] Step 1: Create a secure execution environment
[0010] On the blockchain, through the contract registration transaction, the smart contract is registered and set to execute in the contract enclave. The enclave service provides a secure execution environment where the contract is run in isolation, ensuring that the data is not interfered with by the outside world.
[0011] Step 2: Encryption and Authentication
[0012] The configuration service provides cryptographic keys to ensure that the contract state remains secure when stored externally. Contract owners obtain these keys through configuration requests. Meanwhile, the trusted execution environment attestation service ensures the security and trustworthiness of the execution environment through verification reports and enclave attestations.
[0013] Step 3: Safe execution and protection
[0014] When executing smart contracts, assembly language comparison calculations are used to call comparison operations to prevent memory access pattern leakage. Users obtain the latest status and enclave information, call contract methods to perform operations, and obtain execution results in a secure environment.
[0015] Step 4: Verify and record results
[0016] The user converts the execution results into register states and submits them to the blockchain after signing. The blockchain verifies and records these results to ensure the integrity and traceability of all transactions.
[0017] Furthermore, the blockchain includes contract transactions, enclave transactions, coordination and submission log transactions.
[0018] The contract transaction implements the operations and rules for managing contracts. Specifically, it enables contract owners to register and unregister contracts, as well as add / remove enclaves that can run contracts. In addition, contract owners also use contract transactions to specify a list of configuration services for the contract. The owner of the smart contract ensures the security and trustworthiness of the contract through interaction with the trusted execution environment enclave.
[0019] The enclave transaction implements the operations and rules for managing the enclave. Available operations include registering, updating, and deregistering enclaves. Enclave services must comply with some rules, such as providing the enclave owner, the enclave's public key, and the enclave's certification verified by the Trusted Execution Environment Attestation Service. This information must be verified before submission can be accepted.
[0020] The coordination and commit log transactions distinguish transaction ordering and semantics, allowing the expression of dependencies between state update transactions, and building a dependency graph with off-chain logic and on-chain contract identifiers. Validators enforce dependencies by refusing to rely on uncommitted transactions, and allow serial contract state updates and concurrent execution that depends on other contract states. The legitimacy of the update is guaranteed by the digital signature of the contract enclave.
[0021] Furthermore, the contract transaction functions are as follows:
[0022] Contract transactions implement the operations and rules that manage contracts. Specifically, it enables contract owners to register and unregister contracts, as well as add / remove enclaves that can run contracts. In addition, contract owners use contract transactions to specify a list of configuration services for a contract. The owner of a smart contract ensures the security and trustworthiness of the contract through interaction with the Trusted Execution Environment enclave.
[0023] Furthermore, the enclave transaction functions are as follows:
[0024] Enclave transactions implement operations and rules for managing enclaves. Available operations include registering, updating, and deregistering enclaves. Enclave services must comply with some rules, such as providing the enclave owner, the enclave's public key, and the enclave's attestation verified by the Trusted Execution Environment Attestation Service. This information is verified before submissions can be accepted.
[0025] Furthermore, the coordination and submission of log transactions functions are as follows:
[0026] Coordination and commit log transactions distinguish transaction ordering and semantics, allowing the expression of dependencies between state update transactions, and building a dependency graph with off-chain logic and on-chain contract identifiers. Validators enforce dependencies by refusing to rely on uncommitted transactions, and allow serial contract state updates and concurrent execution that depends on other contract states. The legitimacy of the update is guaranteed by the digital signature of the contract enclave.
[0027] The off-chain logic refers to the calculation or processing performed outside the blockchain network. In contrast to the on-chain logic, the off-chain logic is not directly executed on the blockchain, but is processed in an external system. This approach can be used to reduce the on-chain computing load, improve efficiency, and process complex logic. Common off-chain logic includes:
[0028] 1) Data preprocessing: Cleaning and formatting the data before uploading it to the blockchain.
[0029] 2) Complex computing: Perform complex computing tasks outside the blockchain and then record the results on the blockchain.
[0030] 3) State management: Manage and track changes in system status instead of recording every change on the blockchain.
[0031] The on-chain contract identifier constructs a dependency graph, which refers to the use of smart contract identifiers to represent and construct dependency graphs between different contracts or transactions in a blockchain system. Specifically, the contract identifier means that each smart contract has a unique identifier on the blockchain, usually an address. The dependency graph is a graph structure in which nodes represent smart contracts or transactions and edges represent dependencies. Dependencies can be sequential dependencies between transactions or dependencies on state updates.
[0032] Furthermore, the contract enclave includes a contract interpreter, a smart contract, and a contract status.
[0033] Similar to the Ethereum Virtual Machine, the contract interpreter executes the contract code registered on the blockchain by the contract owner. The contract interpreter is not tied to a specific smart contract, so the contract enclave can run any contract written in the interpreter language. Since the contract interpreter runs in the trusted execution environment enclave, some features are required in the implementation of the interpreter. (i) Contract code sandboxing. This prevents untrusted third parties from implementing malicious contracts to tamper with the rest of the enclave and the enclave service platform. (ii) Small code footprint / trusted computing base. This reduces the complexity of the code, thereby simplifying code audits. (iii) Unique contract representation. This allows participants to easily verify the contract. In addition, all participants can agree on the same copy, which can be identified by a cryptographic hash on the blockchain, avoiding multiple documents due to non-deterministic compilation. Finally, it makes it easy to authenticate and execute the agreed-upon copy within the enclave. (iv) Efficient contract state management. This allows the contract to handle state without having to load it into the enclave in advance.
[0034] The method used by smart contracts to access and update data in the contract state. Since the parties need to agree before using the smart contract in this method, they are expected to be able to communicate with each other offline so that the smart contract code can be shared off-chain. So smart contracts are not necessarily public. Their execution is designed to occur locally within the Trusted Execution Environment enclave of the selected enclave service.
[0035] Smart contract state indicates private data associated with a specific contract. When the contract is running, the contract can access the plaintext state managed by the contract interpreter. In other cases, the contract state is encrypted when stored outside the contract enclave. On the first call of a contract method, the contract interpreter initializes an empty contract state for the contract. On subsequent calls, the contract interpreter reads or modifies the contract state based on the logic implemented by the contract. Because the trusted execution environment maintains the confidentiality of the data, the contract interpreter can access the contract state in plaintext. The contract enclave decrypts / encrypts the contract state before / after the contract needs the data, and these operations are performed using contract-specific keys.
[0036] The configuration service responds to requests from contract owners to configure keys to the contract enclave. These keys are ultimately used to encrypt the contract state. Only the configured contract enclave has access to all keys and is therefore able to decrypt the contract state. The configuration protocol is mediated by the contract owner. The configuration service participates in the protocol as long as it can successfully verify the registration of the contract and enclave on the blockchain. The protocol can be implemented on a generic interface, allowing it to be customized for specific applications / deployment scenarios. The currently implemented protocol allows the configuration service to generate keys and is secure as long as one of the participating configuration services is honest. The purpose of using the configuration service is to make the encryption of smart contract state independent of (i) the enclave and (ii) the enclave service. Among other things, the enclave can ensure that the contract enclave is stateless in terms of the contract, it only needs the contract and the contract state to perform method calls, which can solve the problem of moving state between two enclaves running on different platforms. The enclave service is not trusted by other parties and cannot be trusted to persist critical enclave data, such as sealed storage and encrypted state, once the enclave is terminated and transactions are committed to the ledger. This will make it subject to severe denial of service attacks. The denial of service attack issue is strictly related to the contract state and not to any enclave data in sealed storage.
[0037] The assembly comparison module first allocates enough memory space in the trusted execution environment enclave to store the data to be compared and the temporary data generated during the algorithm execution. Initialize the state variables required for algorithm execution, such as error flags, counters, etc. After that, the data items to be compared are loaded from the outside into the protected memory inside the enclave. This can be achieved by calling the interface provided by the trusted execution environment SDK. The integrity and validity of the data loaded into the enclave can be verified by calculating the hash value of the data and comparing it with the expected value, or using methods such as digital signatures. If the data verification fails, the error is recorded and the algorithm exits. Next, according to the type of input data, the corresponding data type processing logic is selected. For complex data types, it may be necessary to convert them into a format that is easier to compare, such as numerical representation or binary representation. This involves operations such as string parsing and encoding conversion. Then, according to the input comparison type, the corresponding comparison instruction is selected. In x86 assembly language, it is usually implemented through instructions such as CMP, JL, JG, and JE. After that, the data to be compared is loaded into the register, and then the comparison instruction is executed. The comparison result is usually represented by setting flags such as ZF, SF, and OF. Next, the comparison result is obtained according to the flag status after the comparison instruction is executed. For example, if the ZF flag is set to 0, it means that the two data are equal; if the status of the SF and OF flags meet certain conditions, it means that one number is greater than the other, etc. Finally, the corresponding subsequent operations are performed according to the comparison result, including updating the status, triggering events, calling other functions, etc.
[0038] Furthermore, the transaction execution protection includes submitting a transaction request, executing a transaction, and responding to a transaction.
[0039] The method to submit a transaction request is as follows:
[0040] (1) Generate a one-time symmetric key (SEK) using the Advanced Encryption Standard-Counter Mode algorithm. AES-GCM (Advanced Encryption Standard-Galois / Counter Mode) is a symmetric encryption algorithm that combines the Advanced Encryption Standard (AES) and Galois / Counter Mode (GCM) to provide encryption and data integrity verification to ensure data confidentiality and integrity.
[0041] (2) Use the generated SEK to encrypt the transaction request data. This ensures that only entities with the corresponding decryption key can access the original data content.
[0042] (3) Calculate the SHA256 hash value of the original transaction data. This step is used to verify the integrity of the data later to ensure that the data has not been tampered with during transmission. The SEK is then encrypted using the enclave public key, which is obtained from the trusted execution environment enclave (a secure execution environment). The SEK is encrypted using the optimal asymmetric encryption padding public key of the enclave's RSA component.
[0043] (4) The private key is then used to sign the secure hash algorithm 256-bit hash value of the transaction data. This step provides verification of the source of the data and proof of the integrity of the data. The signature confirms that the data was sent by the user holding the corresponding private key and has not been tampered with.
[0044] (5) The encrypted transaction data, encrypted SEK, and encrypted hash value are combined into an encrypted transaction request object. The encrypted transaction request contains all the necessary elements for verification and decryption at the receiving end, while the signature is used to verify the legitimacy of the transaction and the integrity of the data. Finally, the algorithm returns the encrypted transaction request data and signature.
[0045] The transaction execution method is as follows:
[0046] (1) Use the RSA-OAEP algorithm and the enclave private key to decrypt the encrypted SEK to be passed in. The enclave private key is generated and stored in a secure environment and cannot be accessed externally, thereby ensuring the security of the key.
[0047] (2) Decrypt the transaction request data. The transaction request data is encrypted with AES-GCM-256 using SEK to ensure the security of the data during transmission. The data is decrypted using SEK in the enclave to obtain the original transaction content.
[0048] (3) Calculate the SHA256 hash value of the decrypted transaction data to verify the integrity of the data. Decrypt the incoming encrypted hash value and compare it with the calculated hash value. If they are inconsistent, it means that the data has been tampered with during transmission or processing.
[0049] (4) Return an error if the hash value does not match. If the hash value does not match, an error message is returned and the processing flow is interrupted. This ensures that only data that has passed the verification will be further processed.
[0050] (5) Verify the digital signature. If a signature is provided, use the requester's public key to verify the authenticity and validity of the signature. This step ensures that the sender of the data is known and trusted, and that the data has not been modified since it was signed.
[0051] (6) Execute the corresponding business logic based on the decrypted transaction data, including reading and writing databases, executing computing tasks, etc.
[0052] (7) Use the same SEK to encrypt the processing results to ensure the security of the response data when it is returned to the requester.
[0053] (8) Calculate the SHA256 hash value of the response data to verify the integrity of the response data.
[0054] (9) The encrypted response data, the signature of the response hash value, and the hash value itself are returned to the requester. In this way, the requester can verify the integrity and authenticity of the response.
[0055] The transaction response method is as follows:
[0056] (1) Retrieving the public key of a trusted computing node involves obtaining the public key from a database, configuration file, or key management service.
[0057] (2) Retrieve the SEK from the requesting party’s local storage. This ensures that only the two parties who know the key can access the transmitted data content.
[0058] (3) Use the retrieved public key to verify the signature of the transaction response. This typically involves using a public key cryptography algorithm such as RSA or the Elliptic Curve Digital Signature Algorithm (ECDSA) to confirm that the signature matches the encrypted data. If the signature verification fails, an error is returned, indicating that the data may have been tampered with in transit or that the signing key is incorrect.
[0059] (4) Decrypt the encrypted response data using the SEK retrieved in (2). Decryption usually uses a symmetric encryption algorithm (such as AES-GCM), which is fast and secure and suitable for large-scale data processing.
[0060] (5) Return the decrypted data and signature verification result. If the signature verification succeeds, the requester can trust the decrypted data and perform subsequent operations accordingly. If the verification fails, the requester should consider taking security measures, such as recording the security incident or refusing data processing.
[0061] A blockchain smart contract privacy protection system based on a trusted execution environment and assembly comparison calculation is used to implement the smart contract privacy protection method, including two modules: blockchain and contract enclave.
[0062] The blockchain module is used to track blockchain transactions submitted by users (hereinafter referred to as "transactions"), dependencies, registered / updated / deregistered enclaves and smart contracts;
[0063] The Contract Enclave module contains a Trusted Execution Environment enclave with a smart contract interpreter, capable of responding to registration / deregistration in Enclave Registration transactions, adding / removing from the list of enclaves authorized to execute a specific smart contract in Contract Registration transactions, and generating execution results that are submitted to Coordination and Commit Log transactions for verification.
[0064] Compared with the prior art, the advantages of the present invention are as follows: the execution process of the smart contract is placed in a secure enclave of a trusted execution environment, which implements the mandatory execution of data access policies and ensures the confidentiality of data and the integrity of execution. The blockchain verifies and records the generated transactions. The smart contract party retrieves and checks the data related to the smart contract and the enclave instance, and serializes and submits the smart contract status update. By embedding the assembly language comparison algorithm into the trusted execution environment and replacing the comparison calculation in the trusted execution environment, the memory access mode leakage and the memory access mode inference attack of the malicious operating system on the smart contract execution process are effectively prevented. At the same time, it has good scalability under the premise of confidentiality, and has both privacy and high performance, and has high practicality. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] The drawings described herein are used to provide a further understanding of this specification and constitute a part of this specification. The illustrative embodiments and descriptions of this specification are used to explain this specification and do not constitute an improper limitation on this specification. In the drawings:
[0066] Figure 1 The overall architecture of the smart contract privacy protection method based on trusted execution environment and assembly comparison calculation is demonstrated.
[0067] Figure 2 It is a comparative schematic diagram of a blockchain DAPP assembly language that can avoid memory access leakage attacks, shown in an exemplary embodiment;
[0068] Figure 3 It is a process diagram of a contract transaction method shown in an exemplary embodiment;
[0069] Figure 4 is a schematic diagram of the process of enclave registration, update and cancellation shown in an exemplary embodiment;
[0070] Figure 5 The diagram is a schematic diagram of a process of coordinating and submitting log transactions, showing an exemplary embodiment. DETAILED DESCRIPTION
[0071] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this specification.
[0072] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0073] The technical solutions provided by the embodiments of this specification are described in detail below in conjunction with the accompanying drawings.
[0074] Example:
[0075] Figure 1 The overall architecture of the smart contract privacy protection method based on trusted execution environment and assembly comparison computing is presented. The method allows individuals and organizations that do not trust each other to access and update private data through pre-agreed policies. Specifically, the method implements these policies in the smart contract and binds them to the data using the trusted execution environment. These data constitute the smart contract state. Any state update is the result of a smart contract method call. The method call is triggered by the user and executed by the smart contract interpreter. Specifically, the user obtains the latest data from the ledger and requests to call the enclave service that hosts the trusted execution environment enclave. The contract interpreter executes the smart contract code on the input smart contract state, which will cause a state transition and thus produce a new state. This process is performed within the trusted execution environment enclave, which protects the integrity and confidentiality of the smart contract code and data. The smart contract state and code are stored in encrypted form outside the trust boundary of the enclave. The final result is returned to the user. The user finally submits a transaction about the updated state to the blockchain, which is verified and recorded for validity and subsequent audit. The enclave service registers the contract enclave on the blockchain. The enclave is provided in the form of a smart contract execution as a service business model. Registration includes an enclave attestation verification step using the Trusted Execution Environment Attestation Service, which verifies the enclave’s hardware root of trust. The enclave service then commits the registration transaction to the ledger along with the enclave’s verification report.
[0076] Although smart contract execution occurs off-chain, smart contracts are registered on the blockchain by their owners and their execution is authorized by the owner on the enclave service. Registration occurs on the blockchain, while execution authorization is achieved through key configuration. The latter is achieved through a set of configuration services that provide cryptographic services for the state encryption of registered enclaves. The selected configuration service and the actual configured enclave are ultimately exposed on the blockchain in the contract transaction. The blockchain ensures that the method has a single authoritative instance and log. Proofs of operations and identities of the parties involved, i.e. cryptographic signatures, are made public for end-user verification and trust. In addition, the blockchain helps guarantee the atomicity of updates between methods and verify dependencies between transactions. The method state transition cannot be trusted until the associated transaction is submitted to and accepted by the blockchain.
[0077] The assembly language comparison calculation hides the memory access mode of the program. By using the comparison operation written in assembly language, the calculation process is directly converted into CPU register operation, which can avoid the possible memory access mode leakage in the conventional high-level language implementation algorithm. Regardless of how the input data changes, the assembly language comparison module executes the same code path, and the memory access mode will not change due to different inputs, thereby improving the security and privacy protection capabilities of the program.
[0078] Figure 2 This is a schematic diagram of a blockchain DAPP assembly language comparison that can avoid memory access leakage attacks, shown in an exemplary embodiment. Simple execution of high-level languages usually changes the memory access pattern according to the input data. For example, "IF statements" are a common form of leaking memory access patterns. Assuming that the attacker can always observe internal and external calls of the trusted execution environment enclave, but cannot observe internal CPU register operations, the attacker can record the execution time of the above calls and all resource accesses. Conventional smart contract algorithms that do not rely on assembly language comparison calculations are essentially based on comparison calculations, and use many "IF statements" in the declaration stage to determine the maximum value, resulting in memory access pattern leakage.
[0079] The assembly language comparison calculation executes the exact same code path for any data access, and its memory access pattern has nothing to do with the input value, but rather operates on the CPU registers. Replace the "IF statement" with the assembly language comparison calculation, assign the compared values to separate registers, and then set a flag based on the comparison operation you want to test, allowing the highest value to be determined. Exit the assembly language code with the binary value stored in the flag bit, and then perform a simple arithmetic switch. If the flag bit is not set, that is, the value is equal to 0, then the value is retained, indicating that the new value is not greater than the current maximum. If the flag bit is set and the value is equal to 1, the value is changed to the new bid, indicating that the new value is greater than the current maximum.
[0080] We exit from the assembly code and use the binary value stored in flags, then perform a simple arithmetic switch, if the flag is not set, i.e. value = 0, then keep the value, indicating that the new value is not greater than the current maximum; if the flag is set, value = 1, then change the value to the new bid, indicating that the new value is indeed greater than the current maximum.
[0081] Figure 3 The operation process of smart contract transactions is shown. In the contract registration phase, the contract owner submits the contract code and configuration to the trusted execution environment enclave. The trusted execution environment enclave initializes and verifies internally, and then sends a registration request containing the trusted execution environment signature to the blockchain network. The blockchain network distributes the registration request for verification. The verification node applies the consensus mechanism to verify the request and records the registration transaction on the blockchain to complete the registration of the contract. In the contract update and cancellation phase, the contract owner submits the request through the trusted execution environment enclave. After the trusted execution environment enclave receives the request, the trusted execution environment enclave is responsible for verifying the validity of the request and returning the verification success information to the owner. Subsequently, the owner submits the update or cancellation transaction to the blockchain network based on this information to ensure that the contract update and cancellation operations are carried out in a safe and controllable manner. In the contract call phase, the owner initiates a call request to the trusted execution environment enclave. After the trusted execution environment enclave verifies the request, it builds and executes the call transaction. In the contract call phase, the owner initiates a call request to the trusted execution environment enclave. After the trusted execution environment enclave verifies the request, it builds and executes the call transaction to ensure the legitimacy and accuracy of the call operation. After the blockchain network executes the contract logic, it returns the execution result to the trusted execution environment enclave, which then provides it to the contract owner, ensuring the security of the contract call and the integrity of the data.
[0082] Figure 4 The operation process of enclave transactions is shown. In enclave registration transactions, the owner submits a request containing a unique identifier, public key, and digital signature through the consortium chain. The verification node uses the public key to verify the validity of the signature to ensure that the requester is legitimate; the hash function is used to compare the information summary to ensure that the information has not been tampered with. After verification, the registration information is stored in the blockchain in a structured form to ensure information security. In enclave update transactions, the owner or authorizer submits a change request, which must undergo identity authentication, permission check, information consistency, and content verification. Only when the request meets the requirements and passes verification will the update information be recorded in the blockchain to achieve real-time updates. In enclave cancellation transactions, the relevant parties submit a cancellation request and explain the reason. The verification node verifies the identity and authority, reviews the cancellation reason, executes the cancellation decision, and updates the enclave status to cancellation. This change is recorded in the blockchain for subsequent inquiries.
[0083] Figure 5The operation process of coordinating and submitting log transactions is shown. The client first submits a transaction containing a smart contract call request to the alliance chain node. The node analyzes the dependencies between these transactions and builds a dependency graph to ensure the correctness of the state update. Next, the node packages the transactions into blocks according to the dependency graph and sorts them by priority and type. Then, the node verifies the legitimacy and integrity of each transaction and digitally signs it with a private key. Subsequently, the node broadcasts the packaged transaction to other nodes participating in the consensus, and other nodes verify the legitimacy and signature of the transaction and check the dependencies. After the transaction passes the consensus verification, the node records it to the local log and synchronizes the log regularly to ensure data consistency. When executing smart contracts in the trusted execution environment enclave, the node ensures the privacy and integrity of the data. After the execution is completed, the node verifies the legitimacy of the state update and broadcasts the result. When enough nodes agree on the result, the transaction is confirmed. Finally, the client can query the chain status or receive notifications to understand the latest status of the transaction. The entire process ensures the safe and efficient operation of the alliance chain smart contract based on the trusted execution environment.
[0084] It should be noted that the above embodiments are not intended to limit the protection scope of the present invention, and equivalent changes or substitutions made on the basis of the above technical solutions all fall within the protection scope of the claims of the present invention.
Claims
1. A blockchain smart contract privacy protection method based on a trusted execution environment and assembly comparison calculation, characterized in that: The method comprises the following steps: Step 1: Establish a secure execution environment, On the blockchain, through the contract registration transaction, the smart contract is registered and set to execute in the contract enclave. The enclave service provides a secure execution environment where the contract is run in isolation to ensure that the data is not interfered with by the outside world. Step 2: Encryption and verification, The configuration service provides encryption keys to ensure that the contract state remains secure when stored externally. The contract owner obtains these keys through configuration requests. At the same time, the trusted execution environment attestation service ensures the security and trustworthiness of the execution environment through verification reports and enclave attestations. Step 3: Safe execution and protection, When executing smart contracts, assembly language comparison calculations are used to call comparison operations to prevent memory access mode leakage. Users obtain the latest status and enclave information, call contract methods to perform operations, and obtain execution results in a secure environment. Step 4: Verify and record the results. The user will register the execution results and submit them to the blockchain after signing. The blockchain verifies and records these results to ensure the integrity and traceability of all transactions.
2. The method for protecting the privacy of blockchain smart contracts based on a trusted execution environment and assembly comparison calculation according to claim 1 is characterized in that: The blockchain module used in step 1 is as follows: Tracking submitted transactions, dependencies, registered / updated / deregistered enclaves and smart contracts, including: Contract transactions implement the operations and rules for managing contracts. Contract owners can register and unregister contracts, add / remove enclaves where contracts can run, and use contract transactions to specify a list of configuration services for a contract. Enclave transactions implement operations and rules for managing enclaves. Available operations include registering, updating, and deregistering enclaves. Coordination and commit log transactions are used to distinguish transaction ordering and semantics, allowing dependencies between state update transactions to be expressed, and building a dependency graph with off-chain logic and on-chain contract identifiers.
3. The method for protecting the privacy of blockchain smart contracts based on a trusted execution environment and assembly comparison calculation according to claim 1 is characterized in that: The contract enclave module is used in step 1, as follows: a trusted execution environment enclave with a smart contract interpreter, capable of responding to enclave transactions to register / unregister, adding / removing from the list of enclaves authorized to execute a specific contract in a contract transaction, and generating execution results submitted to the coordination and commit log transactions for verification, including: The smart contract interpreter executes the contract code registered by the contract owner on the blockchain, and the contract interpreter is not bound to a specific contract and can run any contract written in the interpreter language; Smart contracts are used to access and update data in the smart contract state. Smart contracts do not have to be public, and their execution is designed to occur locally within the selected trusted execution environment. The contract state indicates the private data associated with a specific contract. When the smart contract is running, the smart contract accesses the plaintext state managed by the contract interpreter. Otherwise, the contract state is encrypted when stored outside the contract enclave.
4. The method for protecting the privacy of blockchain smart contracts based on a trusted execution environment and assembly comparison calculation according to claim 1 is characterized in that: The assembly language comparison calculation in step 3 is as follows: the comparison operation written in assembly language hides the memory access mode of the program, directly converts the calculation process into CPU register operation, and avoids the possible memory access mode leakage in the conventional high-level language implementation algorithm, including: Memory space allocation and state variable initialization: Allocate enough memory space in the enclave to store data and temporary data, and initialize the state variables required by the algorithm; Load data and verify integrity. External data is loaded into protected memory and data integrity and validity are verified. Comparison algorithm preprocessing, select the corresponding processing logic according to the data type, and select the corresponding comparison instruction according to the comparison type; Data loading and comparison: load the data to be compared into the register, execute the comparison instruction, and indicate the comparison result by setting the flag bit; Execute corresponding subsequent operations based on the comparison results, including status update, event triggering, and calling other functions.
5. A blockchain smart contract privacy protection system based on a trusted execution environment and assembly comparison calculation, characterized in that: The method for protecting the privacy of smart contracts according to any one of claims 1 to 4 is characterized by comprising two modules, a blockchain and a contract enclave. The blockchain module is used to track blockchain transactions submitted by users (hereinafter referred to as "transactions"), dependencies, registered / updated / deregistered enclaves and smart contracts; The Contract Enclave module contains a Trusted Execution Environment enclave with a smart contract interpreter, capable of responding to registration / deregistration in Enclave Registration transactions, adding / removing from the list of enclaves authorized to execute a specific smart contract in Contract Registration transactions, and generating execution results that are submitted to Coordination and Commit Log transactions for verification.
Citation Information
Patent Citations
Blockchain-based smart contract management methods, devices, and electronic equipment
CN110245506B
Off-chain smart contract services based on trusted execution environment
CN110520884B
Method for realizing privacy protection in block chain
CN110033368A
System and method for improved blockchain-implemented smart contract
CN112805694A
Method and device for on-chain and off-chain safe and credible cooperative computing based on TEE (Trusted Execution Environment)
CN118332566A
Cited By
Method for extracting and parsing bitcoin transaction autonomy information
US12626253B2
Method for extracting and parsing bitcoin transaction autonomy information
US20250037124A1