Smart contract Gas consumption optimization method and device for anonymous transaction and storage medium

By moving the Merkle tree update operation from the Ethereum smart contract to the user side, the problem of high Gas consumption in anonymous transactions in smart contracts is solved, and transaction costs are reduced and anonymity and security are guaranteed.

CN119865341AInactive Publication Date: 2025-04-22SOUTHEAST UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411938749.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-04-22
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The high consumption of Gas required for anonymous transactions in Ethereum smart contracts leads to an increase in transaction costs and limits the popularity of anonymous transaction applications.

Method used

Move the update operation of generating a large number of Gas consumed in the smart contract to the user side. The user side only submits update results and proofs to the smart contract, and the smart contract verifies the proof and receives the updated results.

Benefits of technology

It significantly reduces transaction costs, optimizes Gas consumption, and ensures transaction anonymity and security, improving the technical level and application scope of the Ethereum platform.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119865341A_ABST
    Figure CN119865341A_ABST
Patent Text Reader

Abstract

The invention discloses an anonymous transaction-oriented smart contract Gas consumption optimization method and device and a storage medium, an update operation of a Merkle tree generating a large amount of Gas consumption in a smart contract is moved to a user side, the user side only submits an update result and a proof to the smart contract, the smart contract verifies the proof and receives the update result, and the update result is updated to the user side. According to the method, the technical level and the application range of the Ethereum platform can be improved, a safer and more reliable service is provided for the user, and the technical progress and development of the whole block chain industry can be promoted.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of blockchain, and mainly relates to a smart contract Gas consumption optimization method, device and storage medium for anonymous transactions. Background Art

[0002] As a leading smart contract platform, Ethereum currently supports many decentralized applications, especially in the fields of financial services and cryptocurrency trading. These applications rely on Ethereum's smart contract function to handle complex transaction logic and ensure the credibility and transparency of transactions. On Ethereum, anonymous transactions play a pivotal role. Ethereum not only supports cryptocurrency transactions, but also executes complex business logic through smart contracts. Although Ethereum provides powerful smart contracts, all its transaction data and the status of smart contracts are public by default. This high degree of transparency increases the trust of the network, but also exposes the user's transaction activities, which may lead to the tracking of user identity and behavior. In order to solve this problem, developers and researchers have designed and developed a variety of anonymous transaction solutions on the Ethereum platform. These solutions are implemented through smart contracts, mainly using zero-knowledge proof (Zero-Knowledge Proof, ZKP), ring signatures and coin mixing technology, etc., aiming to hide the identity information of transaction users or transaction amounts. Among them, Tornado Cash is one of the most famous anonymous transaction solutions. As a completely decentralized anonymous transaction protocol, Tornado Cash uses zero-knowledge proof to realize anonymous fund transfer on Ethereum. By generating a proof to verify the legitimacy of the transaction, users can send cryptocurrency from one address to another without revealing their identity, greatly enhancing the privacy and security of the transaction. Anonymous transactions are not only a technical requirement on the Ethereum platform, but also a commitment to user privacy protection. By providing an effective anonymous transaction solution, users can be protected from unnecessary privacy threats, while also promoting the healthy development of Ethereum and the entire blockchain ecosystem.

[0003] Although anonymous transaction smart contracts provide enhanced privacy protection for Ethereum users, they also face some technical and operational challenges in practical applications. In Ethereum, deployers deploy smart contracts that support different functions on the blockchain, and users can run these functions with specific inputs through smart contract calls. In order to avoid dead loops in smart contracts and prevent denial of service (DoS) attacks, Ethereum charges transaction fees, namely gas fees, to users who call smart contracts, and uses these fees as part of the reward for miners who execute smart contracts. However, due to the sharp rise in the price of Ethereum tokens (Ether, ETH) and network congestion in the past few years, even simple transactions may require high transaction gas fees. In addition, anonymous transaction contracts usually require complex cryptographic operations, such as generating and verifying zero-knowledge proofs, which often consume a lot of gas and increase transaction costs. Therefore, gas consumption has become a major burden for Ethereum users, which greatly limits the popularity of anonymous transaction applications based on Ethereum.

[0004] At present, although some projects have tried to reduce the gas consumption of these smart contracts through technological innovation, such as by optimizing the code of smart contracts or using more efficient cryptographic algorithms, many obstacles still need to be overcome before large-scale promotion. In addition, with the continuous development of blockchain technology and related regulations, these anonymous transaction solutions also need to be constantly adjusted and improved to adapt to the new technology and regulatory environment. Although there are many methods that can reduce gas consumption to a certain extent, they are not suitable for smart contract applications such as Tornado Cash that are aimed at privacy protection. Furthermore, most of these methods can only achieve limited gas savings, showing the limitations of their application scope. An ideal solution should be applicable to both public and private applications, and be able to set a unified maximum gas fee standard for various operations and different types of inputs. Therefore, there is an urgent need for an efficient and secure method to solve the problem of high gas consumption on Ethereum smart contracts. Summary of the invention

[0005] The present invention is aimed at the problem of high Gas consumption in existing anonymous transaction applications, and provides a smart contract Gas consumption optimization method, device and storage medium for anonymous transactions. The update operation of the Merkle tree that generates a large amount of Gas consumption in the smart contract is moved to the user end. The user end only submits the update result and proof to the smart contract, and the smart contract verifies the proof and receives the updated result to complete the transaction. The method of the present invention can not only improve the technical level and application scope of the Ethereum platform, provide users with a safer and more reliable service, but also promote the technological progress and development of the entire blockchain industry.

[0006] In order to achieve the above-mentioned purpose, the technical solution adopted by the present invention is: a smart contract gas consumption optimization method for anonymous transactions, which moves the update operation of the Merkle tree that generates a large amount of gas consumption in the smart contract to the user end. The user end only submits the update result and proof to the smart contract, and the smart contract verifies the proof and receives the updated result, thereby completing the transaction.

[0007] As an improvement of the present invention, a smart contract gas consumption optimization method for anonymous transactions includes the following steps:

[0008] S1: In the initialization phase, a security parameter λ is given and a list of system common parameters is generated, specifically:

[0009]

[0010] Where p is a prime number; are three multiplicative cyclic groups of order p that satisfy the bilinear pairing e: g and h are and Generator of Z p is a finite field;

[0011] S2: The user generates a random number k and a random number r, calculates the hash value through the PedersenHash method and uses it as the commitment cmt, and passes the cmt to the smart contract for checking and verification;

[0012] S3: The user obtains cmt by listening to deposit events and corresponding indexes;

[0013] S4: The user constructs a Merkle tree based on the cmt obtained in step S3, inserts the cmt and updates the Merkle tree to obtain a new root;

[0014] S5: Determine input parameters and variables before generating the proof, wherein the input parameters and variables include at least the latest root from the local update that is publicly accessible u , the root from the checksum calculation c , path element path from the current node to the root node obtained by the user path e and the path element path for circuit path calculation e '; By calculating the elliptic curve point pi a , pi b and pi c The three coefficient polynomials obtained generate a proof and prove that the relevant formula is established; the proof is specifically:

[0015]

[0016] Among them, pk is the proof key; leaf is the leaf node of the Merkle tree;

[0017] S6: The user takes the tuple (π,root u ) is sent to the smart contract;

[0018] S7: Received tuple (π, root u ), the smart contract uses the verification vk and calculates whether π is valid; when the verification is true, the smart contract updates the value of the root and stores it in the root array, completing the deposit operation request;

[0019] S8: The user obtains a random string and binds it to ETH or ERC-20 tokens to be used as a withdrawal voucher.

[0020] As an improvement of the present invention, in step S2, the generated random numbers kk and rr are calculated using the PedersenHash method, and the calculation formula is:

[0021] P(k,r)=g k h r .

[0022] As an improvement of the present invention, the Merkle tree constructed in step S4 stores the hash value of the combination of the left and right child nodes for non-leaf nodes, and repeatedly hashes upward until the root node is obtained.

[0023] As another improvement of the present invention, the equation proved to be true in step S5 is specifically:

[0024] root u =root c ∧P(k,r)=leaf∧path e =path e ′.

[0025] As another improvement of the present invention, the method in step S7 where the smart contract uses vk and verifies whether π is valid by calculation is as follows:

[0026] Verify(vk,root u ,π).

[0027] In order to achieve the above object, the technical solution adopted by the present invention is: a device includes at least one processor and at least one memory, wherein

[0028] The memory has computer-readable instructions stored thereon;

[0029] The computer-readable instructions are executed by one or more of the processors, so that the device implements the above-mentioned smart contract Gas consumption optimization method for anonymous transactions.

[0030] In order to achieve the above-mentioned purpose, the technical solution also adopted by the present invention is: a storage medium on which computer-readable instructions are stored, and the computer-readable instructions are executed by one or more processors to implement the above-mentioned smart contract Gas consumption optimization method for anonymous transactions.

[0031] Compared with the prior art, the present invention discloses a smart contract Gas consumption optimization method, device and storage medium for anonymous transactions. Taking Tornado Cash as a typical anonymous transaction scenario, the present invention uses Merkle tree, zero-knowledge circuit and other knowledge to model, deeply analyzes the Gas consumption of smart contracts, and successfully locates the key operational problems that lead to high Gas consumption. The method for reducing Gas consumption based on zero-knowledge proof disclosed in the present invention ensures the security and correctness of transferring smart contract operations to local execution, thereby optimizing transaction costs without sacrificing security. Compared with the prior art, the present invention has the following beneficial effects:

[0032] (1) Ensuring the security of private transactions: The method of the present invention ensures security while ensuring the anonymity of transactions. Tornado Cash involves processing financial currency transactions, which requires a high level of security, so this is very important for it. Groth16 is considered very secure and has a strong record of use in Ethereum applications.

[0033] (2) High verification efficiency: The computational complexity of generating and verifying commitments is at most linear. Groth16 has been proven to be very efficient in pairing-based cryptography. In addition, Groth16 proof size is relatively small, which means less data needs to be transmitted. It helps reduce the Gas cost required to process transactions on Ethereum.

[0034] (3) Strong scalability: In order to support more functions, the present invention implements an updateable circuit structure and rapid iteration. Tornado Cash will adopt a more powerful and advanced zero-knowledge proof solution under diversified tasks, reducing transaction costs and meeting more needs while protecting user privacy and fund security.

[0035] (4) The present invention discloses a smart contract Gas consumption optimization method, device and storage medium for anonymous transactions. Taking into account the application requirements of anonymous transaction scenarios, the method can effectively reduce the Gas consumption of smart contracts while ensuring the anonymity of transactions. It can not only improve the technical level and application scope of the Ethereum platform, significantly reduce transaction costs, and provide users with a safer and more reliable service, but also promote the technological progress and development of the entire blockchain industry. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 1 It is a schematic diagram of an application scenario of the smart contract Gas consumption optimization method for anonymous transactions of the present invention;

[0037] Figure 2 This is the environmental system architecture diagram used by the smart contract Gas consumption optimization method for anonymous transactions of the present invention;

[0038] Figure 3 It is a step implementation diagram of the method for optimizing smart contract Gas consumption for anonymous transactions of the present invention;

[0039] Figure 4 is a comparison chart of experimental results of the improved Gas consumption in the test example of the present invention and the Gas consumption in the original process;

[0040] Figure 5 This is a comparison chart of the experimental results of the improved request start time and proof generation time in the test example of the present invention;

[0041] Figure 6 It is a comparison chart of the improved request processing time in the test example of the present invention and the original request processing practice. DETAILED DESCRIPTION

[0042] The present invention will be further explained below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the following specific embodiments are only used to illustrate the present invention and are not used to limit the scope of the present invention.

[0043] Example 1

[0044] Smart contract gas consumption optimization method for anonymous transactions is mainly used in Figure 1In the mixed currency transaction scenario shown, ETH deposits are withdrawn from different addresses. After the user deposits ETH, he presents a zero-knowledge proof zk proof to prove that he has deposited the money, and then withdraws the money from a new address, thereby cutting off the association between the deposit and withdrawal addresses. When withdrawing money, users are allowed to withdraw money from different addresses, without requiring the funds originally deposited by the user. It only requires proof that the user has made a deposit and has the corresponding amount. Once the proof is completed, the smart contract will directly transfer the corresponding amount of funds to the user. Through this process, the connection between deposits and withdrawals is broken, and the transaction cannot be tracked by external observers, ensuring the anonymity of the user.

[0045] The method of the present invention is a mixed currency transaction based on zero-knowledge proof, and the system architecture is as follows Figure 2 As shown, it mainly includes on-chain Ethereum smart contracts and off-chain components. The on-chain component uses Tornado Cash smart contracts to realize anonymous asset transactions; the off-chain mainly includes a transaction system to handle events of user balance status changes and regularly handle off-chain account and asset transactions. In the method of the present invention, users can verify the validity of their transactions while maintaining the anonymity of their identities, thereby ensuring their privacy and security.

[0046] In addition, Tornado Cash smart contracts store assets, verify zero-knowledge proofs, and provide methods for deposits and withdrawals. These features allow users to freely manage their assets without worrying about the control or restrictions of centralized institutions. Since smart contracts are deployed on the EVM network, their stability and reliability can be guaranteed, allowing users to use the platform with confidence for anonymous asset transactions.

[0047] A smart contract gas consumption optimization method for anonymous transactions, the transaction flow chart is as follows: Figure 3 As shown, the update operation of the Merkle tree that generates a large amount of Gas consumption in the smart contract is moved to the user side. The user side only needs to submit the update result and proof to the smart contract. After that, the smart contract verifies the proof and receives the updated result.

[0048] In this embodiment, the Solidity language is used to write smart contracts under the Linux system, the Truffle development test framework is used, and the smart contracts are deployed to Ganache-CLI for testing.

[0049] Tornado Cash requires a series of arithmetic circuits to be built before deployment. These circuits are determined by Tornado Cash's relationships, which are basically programs. When deployed, the smart contract first builds a Merkle tree and keeps the root array. All deposit records of Tornado Cash are stored in this array to ensure successful execution of operations, even if there are delays in withdrawals. Whenever a new deposit behavior is generated, the contract will write its corresponding characteristic value commitment into a leaf node and then update the root of the Merkle tree.

[0050] To prevent a transaction from being replayed, a small identifier can be set. To prevent a commitment from being deposited twice, the commitment is mapped to a boolean variable. If the boolean value is false, it has not been committed and can be inserted. When the insertion is completed, the value is set to true.

[0051] A smart contract gas consumption optimization method for anonymous transactions includes the following steps:

[0052] Step S1: Perform the initialization process, give a security parameter λ, generate a system public parameter list, and generate necessary public system parameters in the initialization phase to ensure that subsequent steps are executed correctly.

[0053] In order to construct two types of zero-knowledge transactions, deposits and withdrawals, a specific circuit C needs to be designed to ensure that the user's state before and after the algorithm is executed and the constructed transactions are valid and legal. It should be noted that the algorithm is executed only once by a trusted third party; the detailed process is shown in Algorithm 1:

[0054]

[0055] The Merkle tree transaction data is then verified. The Merkle proof uses a single data block to prove the validity of a larger amount of data. The main idea of ​​the Merkle proof is that only the root "Hash12345678" of the Merkle tree needs to be stored on Ethereum so that multiple transactions (Tx1, ..., Tx8) can be verified. For example, if a user wants to prove the validity of "Tx4" on node Node4, he will need to provide the data information "Tx4", "Hash3", "Hash12" and "Hash5678". Then the user's contract will be able to recalculate the Merkle root "Hash12345678" and check whether it is consistent with the root stored on Ethereum. According to the given path, the root hash is calculated from bottom to top for verification. The specific algorithm is shown in Algorithm 2. Therefore, when it is required to prove the existence of a transaction record, the user will not need to store the hash values ​​of all transactions, but only need to get the path from the leaf node to the root, without the participation of all leaf nodes. This greatly reduces the amount of calculation.

[0056]

[0057] Step S2: The user generates a random number k and a random number r, and uses the PedersenHash method to pass P(k,r)=g k h r To calculate the hash value and use it as the commitment cmt; pass the cmt to the smart contract for checking and verification to prevent the cmt from being submitted;

[0058] Step S3: The user obtains cmt by monitoring deposit events and corresponding indexes;

[0059] Step S4: The user first constructs a Merkle tree with the obtained cmt, then inserts the cmt and updates the Merkle tree to obtain a new root; for the construction of the Merkle tree, for non-leaf nodes, the hash value of the combination of the left and right child nodes is stored, and the hash is repeated upward until the root node is obtained;

[0060] Step S5: Determine input parameters and variables before generating proof; determine the latest root from local updates that can be publicly accessed u and the root from the checksum calculation c ; Determine the path element path from the current node to the root node obtained by the user path e and the path element path for circuit path calculation e '; By calculating the elliptic curve point pi a , pi b and pi c The three coefficient polynomials obtained generate a proof:

[0061]

[0062] And prove that the relevant formula is established:

[0063] root u =root c ∧P(k,r)=leaf∧path e =path e ′;

[0064] Step S6: The user converts the tuple (π, root u ) is sent to the smart contract;

[0065] Step S7: After receiving the tuple (π, root u ) after which the smart contract uses vk and passes Verify(vk,root u,π) calculates and verifies whether π is valid; if the verification is true, the smart contract updates the value of the root and stores it in the root array, completing the deposit operation request;

[0066] Step S8: The user obtains a random string and binds it to ETH or ERC-20 token, which can be used as a voucher for withdrawal.

[0067] Using the method of the present invention, in step S4, the process involving user deposit is as follows:

[0068] S41: Generate a random number secret and nullifier, and use the Pedersen Hash function to calculate as the commitment cmt. The specific calculation is as follows:

[0069] cmt=H(coinCode,amount,secret,nullifier)

[0070] Where amount indicates the deposit amount, and coinCode indicates the code of the currency used (0 == ETH);

[0071] S42: Get all cmts from the smart contract;

[0072] S43: Build a Merkle tree using all the cmts obtained;

[0073] S44: Add the newly calculated cmt to the Merkle tree;

[0074] S45: Generate a zero-knowledge proof, which proves that the user knows the secret and nullifier just added to the leaf of the Merkle tree, and the conversion from the current leaf node RootOld to RootNew in the smart contract is carried out according to the rules; specifically, the leaf node is not deleted, and only a leaf node with the correct format is added;

[0075] S46: Send proof together with ETH and call the deposit smart contract;

[0076] S47: The smart contract verifies the proof of deposit and if everything is OK, stores the commitment and the new root.

[0077] The process of withdrawing money in step S4 is as follows:

[0078] S48: Get all cmts from the smart contract;

[0079] S49: Use the acquired cmts to construct a Merkle tree;

[0080] S410: Generate siblings, i.e. Merkleproof, for cmts whose users know the secret and nullifier;

[0081] S411: Generate a ZK-SNARK proof, including: the user knows the secret of the revealed nullifier, whose commitment is in the Merkle tree, and the root matches the root stored in the smart contract;

[0082] S412: If the proof verification passes and the nullifier has not been used, the smart contract will send ETH to the specified address.

[0083] Test Case

[0084] In order to verify the feasibility and effectiveness of the method of the present invention, a prototype of the method was deployed on the Ganache test network.

[0085] The experimental system adopts the development environment configuration shown in Table 1.

[0086] Parameter name Configuration Linux Ubuntu 18.03 Truffle v5.0.27 Ganache v6.4.5 Memory Size 8GB CPU i7-12700H 2.30GHz

[0087] The present invention tests the improved Gas consumption, request start time and request processing time. The detailed Gas consumption analysis and time analysis are as follows:

[0088] The experimental results of the improved gas consumption and the original process gas consumption are compared. Figure 4 As shown. Due to the level of hash operations in the Merkle tree update, the original process of the deposit consumes up to 9225264 units of Gas. In order to study the relationship between Gas consumption and the number of tree layers, modify the height of the Merkle tree in the env file and compile and deploy again. Then, start the deposit request again and analyze the transaction log in Ganache-CLI. After the improvement, compile and deploy again after modifying the same parameters in the env file and performing the same test. The experimental results show that there is a linear relationship between Gas consumption and input size. Specifically, each time the number of layers is reduced by 1, the Gas consumption in the original process is reduced by 53102 units.

[0089] During the improvement process, no matter how the height of the Merkle tree is changed, the Gas consumption is always fixed at around 310,000 units, while the solution proposed by the method of the present invention reduces 614,753 units and consists of three parts: verification of the proof passed in by the client, update of the root array of the smart contract, comparison of the improved and original Gas cost smart contracts, and other consumption. All three components of Gas consumption are fixed values. It can be predicted that even if the height of the Merkle tree continues to increase or the hash operation is replaced with a more complex operation, the Gas consumption will remain around 310,000. Therefore, it can be concluded that the method of the present invention successfully achieves optimization, effectively reduces Gas consumption, and maintains O(1) cost consumption.

[0090] Especially Figure 4 As shown, the improved Gas consumption is experimentally compared with the Gas consumption of the original process. The results show that when the height of the Merkle tree is greater than 13, the Gas cost is reduced by more than 50% after adopting this method, significantly reducing the cost overhead.

[0091] Time analysis mainly includes two performance indicators: request startup time and request processing time.

[0092] 1) Request start time

[0093] The request start time and proof generation time are as follows Figure 5 As shown. The experimental results show the time to generate a proof and initiate a request in the improved process. It can be found that a large part of the request startup time is composed of the time required to generate the proof. The original process simply creates an object of a deposit and passes the promise to the smart contract. This completes the start of the request between 350 milliseconds and 450 milliseconds. The improved process includes creating a deposit, building a tree, and completing the proof. From the experimental results, it can be found that the proof time increases with the height of the tree, which in turn causes the improved request startup time to increase with the height.

[0094] 2) Request processing time

[0095] The comparison results of the smart contract request processing time-consuming experiment are as follows: Figure 6 As shown. From the experimental results, it can be found that there is a significant difference in the time required for the smart contract to process requests in the original process and the improved process. The original process gets the root after passing and inserting cmt in the smart contract for hashing. As the height increases, more hashes are required, resulting in an increase in time. The improved process is to verify the proof and store it directly into the array. It can be concluded that the time for verification is independent of the height of the tree, and the total time is also independent of the height.

[0096] Example 2

[0097] The method of the present invention can also be applied to devices and storage media, including a device comprising at least one processor and at least one memory, wherein the memory stores computer-readable instructions; the computer-readable instructions are executed by one or more of the processors, so that the device implements the above-mentioned smart contract Gas consumption optimization method for anonymous transactions.

[0098] A storage medium having computer-readable instructions stored thereon, wherein the computer-readable instructions are executed by one or more processors to implement the above-mentioned smart contract gas consumption optimization method for anonymous transactions.

[0099] In summary, the present invention takes anonymous transactions as the research scenario, deeply understands the operating principle of existing anonymous transaction smart contracts, fully analyzes the Gas consumption pattern in anonymous transactions and identifies operations with high Gas consumption, explores Ethereum smart contract Gas optimization methods for anonymous transactions, outsources high-consumption operations of smart contracts to users for execution, and transfers operations with high Gas consumption in smart contracts from smart contracts to local execution, significantly reducing transaction costs. At the same time, the correctness and integrity of operations executed locally are ensured by using zero-knowledge proofs, thereby maintaining the security of transactions. In this way, smart contracts are only responsible for verifying and updating transaction results, thereby reducing the computing and storage requirements on the network. It is a key point and difficulty to reduce the transaction costs on Ethereum while ensuring the anonymity of transactions. The method of the present invention can not only improve the technical level and application scope of the Ethereum platform, provide users with a safer and more reliable service, but also promote the technological progress and development of the entire blockchain industry.

[0100] It should be noted that the above content only illustrates the technical idea of ​​the present invention and cannot be used to limit the protection scope of the present invention. For ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications all fall within the protection scope of the claims of the present invention.

Claims

1. A smart contract gas consumption optimization method for anonymous transactions, characterized by: The update operation of the Merkle tree that generates a large amount of Gas consumption in the smart contract is moved to the user side. The user side only submits the update result and proof to the smart contract. The smart contract verifies the proof and receives the updated result, thus completing the transaction.

2. The method for optimizing smart contract gas consumption for anonymous transactions according to claim 1, characterized in that: The steps include: S1: In the initialization phase, a security parameter λ is given and a list of system common parameters is generated, specifically: Where p is a prime number; are three multiplicative cyclic groups of order p that satisfy the bilinear pairing e: g and h are and Generator of Z p is a finite field; S2: The user generates a random number k and a random number r, calculates the hash value through the Pedersen Hash method and uses it as the commitment cmt, and passes the cmt to the smart contract for checking and verification; S3: The user obtains cmt by listening to deposit events and corresponding indexes; S4: The user constructs a Merkle tree based on the cmt obtained in step S3, inserts the cmt and updates the Merkle tree to obtain a new root; S5: Determine input parameters and variables before generating the proof, wherein the input parameters and variables include at least the latest root from the local update that is publicly accessible u , the root from the checksum calculation c , path element path from the current node to the root node obtained by the user path e and the path element path for circuit path calculation e '; By calculating the elliptic curve point pi a , pi b and pi c The three coefficient polynomials obtained generate a proof and prove that the relevant formula is established; the proof is specifically: Among them, pk is the proof key; leaf is the leaf node of the Merkle tree; S6: The user takes the tuple (π,root u ) is sent to the smart contract; S7: Receive the tuple (π, root u ), the smart contract uses the verification vk and calculates whether π is valid; when the verification is true, the smart contract updates the value of the root and stores it in the root array, completing the deposit operation request; S8: The user obtains a random string and binds it to ETH or ERC-20 tokens to be used as a withdrawal voucher.

3. The method for optimizing smart contract gas consumption for anonymous transactions according to claim 2, characterized in that: In step S2, the Pedersen Hash method is used to calculate the hash value of the generated random numbers k and r, and the calculation formula is: P(k,r)=g k h r 。 4. The method for optimizing smart contract gas consumption for anonymous transactions according to claim 2, characterized in that: The Merkle tree constructed in step S4 stores the hash value of the combination of the left and right child nodes for non-leaf nodes, and repeatedly hashes upward until the root node is obtained.

5. The method for optimizing smart contract gas consumption for anonymous transactions according to claim 2, characterized in that: The equation proved to be true in step S5 is specifically: root u =root c ∧P(k,r)=leaf∧path e =path e 。 6. The method for optimizing smart contract gas consumption for anonymous transactions according to claim 2, characterized in that: In step S7, the smart contract uses vk and verifies whether π is valid by calculation as follows: Verify(vk,root u ,π)。 7. A device, characterized in that: comprises at least one processor and at least one memory, wherein The memory has computer-readable instructions stored thereon; The computer-readable instructions are executed by one or more of the processors, so that the device implements the smart contract gas consumption optimization method for anonymous transactions as described in any one of claims 1-6.

8. A storage medium having computer-readable instructions stored thereon, characterized in that: The computer-readable instructions are executed by one or more processors to implement the smart contract Gas consumption optimization method for anonymous transactions as described in any one of claims 1-6.