A query service settlement method and system for optimizing gas consumption of a smart contract

CN117911112BActive Publication Date: 2026-11-06ZHEJIANG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410079947.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-19
Publication Date
2026-11-06
Estimated Expiration
2044-01-19

AI Technical Summary

Technical Problem

In public blockchain smart contracts, the query service settlement process consumes a lot of gas fees, and traditional order settlement methods result in high gas overhead.

Method used

A batch payment process based on the Merkle order tree is adopted. By constructing the Merkle order tree and storing the Merkle root in the smart contract, gas overhead is reduced, and a notary solution is designed to resolve order disputes, thereby realizing batch settlement and fee payment.

Benefits of technology

It significantly reduces the gas fees of smart contracts, ensures the transparency, immutability and auditability of the settlement process, and ensures fair resolution of order disputes by the notary office, thus achieving a fair and secure settlement process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117911112B_ABST
    Figure CN117911112B_ABST
Patent Text Reader

Abstract

The application discloses a query service settlement method and system for optimizing gas consumption of an intelligent contract, and the query service settlement system comprises a query service providing end, a user end, a notarization end, an intelligent contract and a blockchain browser, wherein the notarization end is used for solving order disputes between the query service providing end and the user and processing payment of an overdue order; the intelligent contract uses a batch payment process based on a Merkle order tree to complete order payment settlement between the user and the query service providing end; and the blockchain browser is used for querying transaction information on a blockchain for the notarization end and helping to confirm non-payment of an overdue order. The batch settlement method based on the Merkle order tree is realized through the intelligent contract, gas consumption is reduced, meanwhile, payment transaction is open and transparent, tamper-proof and easy to audit, and the fairness, safety and efficiency of the query service settlement process are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of blockchain application technology, and in particular to a query service settlement method and system for optimizing smart contract gas overhead. Background Technology

[0002] Blockchain technology establishes an immutable distributed ledger through a consensus mechanism. Currently, blockchain technology is widely used in cross-border payments, supply chain management, transaction settlement, and electronic certificates. Bitcoin is one of the earliest representatives of public blockchain technology. Following Bitcoin, emerging public blockchain technologies have often innovated and improved in key aspects, including core design elements such as smart contracts, consensus protocols, application scenarios, and incentive mechanisms. Smart contracts are considered the execution engine of the blockchain. By writing business logic in smart contracts, the secure and trusted execution environment of the blockchain can be fully utilized to realize complex business scenarios requiring trust among multiple parties.

[0003] 1. Smart Contracts and Gas Mechanisms

[0004] Once a smart contract is deployed on a blockchain, its code executes automatically and is immutable. Executing a smart contract consumes computational resources. A gas mechanism is used to measure the computational cost of executing a smart contract, preventing invalid calculations or infinite loops. Users pay gas fees when executing smart contracts to compensate for the computational costs incurred by nodes in the blockchain network.

[0005] 2. Outsourced inquiry service methods

[0006] Outsourced query services typically occur when the data provider lacks sufficient computing resources to directly provide query services to the user. In this model, the data provider sends outsourced data to a third-party query service provider; the user then initiates a query request to the third-party provider. The query service provider returns a query result R to the user along with a cryptographic proof (VerificationObject, VO) demonstrating the validity of the result. The user can then verify the query result locally using the result R and the VO. If the outsourced query result is correct, the user pays the query service provider a fee to cover the provider's computational costs.

[0007] 3. Order settlement based on field storage

[0008] To settle a service order, traditional order settlement smart contracts require storing all information, including the order ID, amount, user information, and query service provider information, within the blockchain smart contract (blockchain Storage space). While this approach is direct and reliable, the operational cost of order settlement schemes based on field storage is extremely high. Each data storage or modification operation within the blockchain smart contract consumes a significant amount of gas, leading to substantial gas overhead from numerous data operations. This results in the problem of high gas consumption during the settlement process.

[0009] In comparison, adding key order information to the input fields of a contract call transaction significantly reduces gas consumption. This method not only ensures that order information is public, transparent, immutable, and easily auditable on the blockchain ledger, but also significantly reduces gas consumption during the settlement process. Therefore, designing a novel order settlement scheme that records key order information only in the input transactions of the contract call, while simultaneously enabling batch order settlement, will be an effective solution to the problem of high operating costs for settlement contracts. Summary of the Invention

[0010] To address the issue of high gas fees incurred during query service settlement in public blockchain smart contracts, this invention proposes a query service settlement method and system that optimizes smart contract gas overhead. Through a batch payment process based on a Merkle order tree, it achieves large-scale batch settlement of query service orders, ensuring the immutability and auditability of payment transactions. Simultaneously, a notary-based query order dispute resolution solution is designed to effectively handle and process query orders and ensure payment when disputes arise between the user and the query service provider, guaranteeing a fair and secure settlement process.

[0011] This invention first provides a query service settlement system that optimizes gas overhead, comprising: a query service provider, a user, a notary, a smart contract, and a blockchain explorer;

[0012] The smart contract is used to record the addresses of the notary office, the query service provider, and the user, to pre-deposit fees for the user, and to complete the settlement of order fees between the user and the query service provider.

[0013] The query service provider is used to provide query services to users when a user initiates a query service request, and to return query information to the user including the query order, query result, and the cryptographic proof (VO) of the query result. The query service provider is also used to construct a Merkle order tree and store the Merkle root in a smart contract. When the smart contract settles order fees, it only needs to call the Merkle root, thereby reducing the smart contract's gas overhead. The query order includes the order number, order amount, and the user's public chain address. The Merkle order tree includes K unpaid query orders, where K is an integer greater than or equal to 1.

[0014] The user terminal is used to initiate query service requests, receive query information returned by the query service provider, and verify the query results based on the cryptographic proof of the query result (VO). The user terminal is also used to pay for completed query services based on the query order.

[0015] The notary office is used to resolve disputes between the query service provider and the user regarding query orders;

[0016] The blockchain explorer is used to obtain specific information about transactions on the public blockchain for the notary and to confirm whether the order has been paid. The specific information about the transaction includes the creation time of the query service order, the amount of the query service order, the user's account balance, and the contract call behavior.

[0017] The present invention also provides a query service settlement method based on the above-mentioned query service settlement system, comprising the following steps:

[0018] 1) Deploy smart contracts in the public blockchain and record the notary office address and query service provider address in the smart contracts;

[0019] 2) The user deposits fees in advance into the smart contract and records the user's public chain address in the smart contract;

[0020] 3) The user initiates a query request to the query service provider. After receiving the query request, the query service provider sends the query results, the cryptographic proof of the query results (VO), the query order, and the query service provider's signature on the query information to the user. Before the number of unpaid service orders reaches K, the query service provider stores the orders locally. After the number of unpaid service orders reaches K, the query service provider constructs a Merkle order tree based on the K unpaid service orders and stores the Merkle root in the smart contract.

[0021] 4) After receiving the query information, the user signs the query information and verifies the query result based on the cryptographic proof VO of the query result; after the user verifies the correctness of the query result, it calls the smart contract to pay the query order fee to the query service provider.

[0022] 5) When the user fails to complete the payment within the service order fee payment period, the query service provider sends the query information to the notary office. The notary office queries the specific information of the transaction through the blockchain explorer, verifies the query results, and processes the payment issue of the query order based on the correctness of the verified query results.

[0023] As a preferred embodiment of the present invention, step 4), in which the user terminal calls the smart contract to pay the query service provider for the query order fee, specifically includes the following steps:

[0024] 4.1) The user client queries the query service provider for the payment certificate of the payment order, where multiple payment orders use a single payment certificate to achieve batch settlement;

[0025] 4.2) The query service provider generates payment proofs corresponding to user-paid orders based on the Merkle order tree and sends the payment proofs to the user.

[0026] 4.3) The user receives the payment certificate and transmits it to the smart contract. After verifying the payment certificate, the smart contract deducts the total order fee from the pre-deposited funds on the user's end and transfers it to the query service provider's account.

[0027] As a preferred embodiment of the present invention, step 5) specifically includes the following steps:

[0028] 5.1) When the user receives the query result and has not paid within the waiting time threshold T, the query service provider will send the query order and query result receipt information, which includes the signatures of the query service provider and the user, to the notary office.

[0029] 5.2) The notary office verifies the signatures of the received information by both the user and the query service provider, parses the received information to obtain the query results and specific information of the service order; and confirms by querying the blockchain explorer that the order has indeed not been paid and has exceeded the payment time threshold T.

[0030] 5.3) The notary office confirms the correctness of the query result based on the cryptographic proof VO and the query result. If the query result is incorrect, no operation is performed. If the query result is correct, the notary office queries the query service provider for the payment proof corresponding to the order. The query service provider has already sent the received information to the notary office. After parsing, the notary office can obtain the order ID, amount and user address.

[0031] 5.4) The notary office uses the payment certificate and order information to call the SettlePay function of the smart contract. After verifying the payment certificate, the smart contract deducts the total order fee from the fee pre-deposited by the user and transfers it to the account of the query service provider.

[0032] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0033] 1) An organizational architecture for a query service settlement system that optimizes gas costs is presented. Batch settlement is achieved through smart contracts. Key parameters of service orders do not need to be directly stored in the blockchain's storage space, but only need to be recorded in the blockchain's ledger space as inputs to the contract call transaction. This reduces gas costs while ensuring that settlement transactions are open, transparent, tamper-proof, and easy to audit.

[0034] 2) A batch payment process based on Merkle order tree is proposed, and a method for constructing Merkle order tree, a method for generating proof of batch payment for multiple orders, and a proof verification method based on smart contract are given; a service order fee payment scheme that saves gas is implemented.

[0035] 3) A novel order dispute resolution solution based on a notary office is proposed for the first time. Since service orders and query results are signed by both the user and the service provider, the notary office verifies the validity of the messages and the correctness of the query results, and then uses a batch payment process to settle payments for valid orders. Attached Figure Description

[0036] Figure 1 A schematic diagram of the architecture of a query service settlement system with optimized gas overhead;

[0037] Figure 2 A flowchart for the outsourced query service process;

[0038] Figure 3 A schematic diagram of the Merkle order tree;

[0039] Figure 4 A flowchart for the notary office to handle disputes between the user and the query service provider. Detailed Implementation

[0040] The present invention will be further described and illustrated below with reference to specific embodiments. The embodiments described are merely examples of the content of this disclosure and do not limit the scope of the invention. The technical features of each embodiment in the present invention can be combined accordingly, provided that there is no mutual conflict.

[0041] like Figure 1As shown, the participating entities of the query service settlement system for optimizing gas overhead according to the present invention include a server, a user, a notary, a smart contract, and a blockchain explorer.

[0042] The query service provider is used to provide query services to users when a user initiates a query service request, and to return query information to the user including query orders, query results, and the cryptographic proof of the query results (VO). The query service provider is also used to construct a Merkle order tree based on K unpaid query orders. The query order includes the order number, order amount, and the user's public chain address.

[0043] The user terminal is used to initiate query service requests, receive query information returned by the query service provider, and verify the query results based on the cryptographic proof of the query result (VO). The user terminal is also used to pay for completed query services based on the query order.

[0044] The notary office is used to resolve disputes between the service provider and the user regarding query orders. For example, if the user receives the query results but delays payment, the service provider can request the notary office to send the query results and service order, bearing the signatures of both the service provider and the user, to the notary office. The notary office verifies the validity of the signatures and then verifies the correctness of the query results, thus settling the payment for the service order. The notary office can resolve disputes fairly and impartially, protecting the rights of both the user and the service provider.

[0045] The smart contract is used to record the addresses of the user terminal, the notary terminal, and the query service provider, pre-deposit fees for the user terminal, and complete the settlement of order fees between the user terminal and the query service provider based on the Merkle order tree.

[0046] The blockchain explorer is used to obtain specific information about transactions on the public blockchain for the notary and to confirm whether the order has been paid. The specific information about the transaction includes the creation time of the query service order, the amount of the query service order, the user's account balance, and the contract call behavior.

[0047] like Figure 2 As shown, the present invention also provides a query service settlement method based on the above-mentioned query service settlement system, comprising the following steps:

[0048] 1) Deploy smart contracts in the public blockchain and record the notary office address and query service provider address in the smart contracts;

[0049] 2) The user deposits fees in advance into the smart contract and records the user's public chain address in the smart contract;

[0050] In one specific embodiment of the invention, a user client requests to pre-deposit a fee C into a smart contract, and the user client's public blockchain address is recorded in the smart contract. The query service provider approves the user client's fee storage request, and the user client successfully transfers a portion of the fee C from their account balance to the smart contract. Once the smart contract code is deployed to the public blockchain, it is immutable. Within the contract logic, only the user client can request to withdraw the fee C; no one else can transfer the fee C. When the user client requests to withdraw the remaining fee, it must be approved by the query service provider or a notary office before the remaining fee can be withdrawn.

[0051] 3) The user initiates a query request to the query service provider. After receiving the query request, the query service provider sends the query results, the cryptographic proof of the query results (VO), the query order, and the query service provider's signature on the query information to the user. Before the number of unpaid service orders reaches K, the query service provider stores the orders locally. After the number of unpaid service orders reaches K, the query service provider constructs a Merkle order tree based on the K unpaid service orders and stores the Merkle root in the smart contract.

[0052] like Figure 2 As shown, in one specific embodiment of the present invention, the user client initiates a query request Q to the query service provider. The query service provider generates a query order corresponding to Q, which records the order number ID, the order amount fee, and the user client's address ADD. user The query service provider executes Q locally and returns the query result R to the user, along with a cryptographic proof VO demonstrating the correctness of the query result; at the same time, it also sends the service order number ID and order amount fee to the user.

[0053] Suppose that the query service provider has K-1 unpaid service orders locally, including unpaid orders between the query service provider and other users. Then, the query service provider should build the following locally: Figure 3 The Merkle order tree is shown, and the Merkle root is stored in the smart contract.

[0054] The query service provider constructs a Merkle order tree as follows. Each leaf node in the Merkle order tree is the hash value of a service order. The query service provider builds a Merkle order tree based on K unpaid service orders. Before accumulating K orders, the query service provider temporarily stores the orders locally. For query service providers with a large number of orders, the accumulation rate of unpaid service orders is very fast. The leaf node hashes of the Merkle order tree are shown below. The definition is as shown in formula (1), where "|" is the connector. As shown in formula (1), the hash value of a service order is calculated by combining the hash value of the user's public chain address, the hash value of the order amount, and the hash value of the order number.

[0055]

[0056] After the query service provider builds the Merkle order tree locally, it stores the Merkle root of the Merkle order tree on the blockchain by calling the StoreRoot function of the smart contract.

[0057] 4) After receiving the query information, the user signs the query information and verifies the query result based on the cryptographic proof VO of the query result; after the user verifies the correctness of the query result, it calls the smart contract to pay the query order fee to the query service provider.

[0058] In one specific embodiment of the present invention, the query service provider signs the message returned to the user to indicate that it indeed sent the message. The user also signs the message to indicate that it indeed received the message. The user receives the query result R and the corresponding proof VO. A query result verification algorithm is executed locally. If the user verifies and finds the query result to be incorrect, no further action is required, and there is no need to proceed to the subsequent order payment steps.

[0059] The client queries the service provider for payment proofs (Proofs) for its service orders. Multiple orders can use a single Proof for batch settlement. The service provider generates Proofs for each of the client's orders based on a Merkle order tree. The client sends the payment proofs to the smart contract, which verifies the Proofs and deducts the total order fee from the service provider's account. If the client's orders are N5 and N6, the service provider will then use a different method to calculate the payment proof. Figure 3 The Merkle order tree shown will generate proof of payment. The client calls the VerifyPay function of the smart contract, sending the proof and the amount and ID of the service order to the smart contract. The address for the client to call the contract is Add. user Therefore, it can be calculated in the contract. If the value matches the Merkle root stored by the query service provider in steps 2-5), the contract can verify the correctness of the Proof and the order, thereby enabling batch payment for orders N5 and N6: deducting the fee for orders N5 and N6 from the pre-stored fee C in the smart contract and transferring it to the query service provider.

[0060] 5) When the user fails to complete the payment within the service order fee payment period, the query service provider sends the query information to the notary office. The notary office queries the specific information of the transaction through the blockchain explorer, verifies the query results, and processes the payment issue of the query order based on the correctness of the verified query results.

[0061] In the event of a dispute between the user and the service provider, the notary office needs to verify the query results and handle payment issues for the service order.

[0062] like Figure 4 As shown, in one specific embodiment of the present invention, if the user does not make a payment after receiving the query result, after a waiting time threshold T, the query service provider sends a query order and query result receipt message containing the signatures of both the query service provider and the user to the notary. The notary verifies the signatures of both the user and the query service provider on the message, parses the message to obtain the specific information of the query result and service order; and confirms by querying the blockchain explorer that the order has indeed not been paid and has exceeded the payment time threshold T. The notary executes a verification algorithm based on the cryptographic proof VO and the query result R to confirm the correctness of the outsourced query result. If the query is incorrect, no action is required. If the query result is correct, the notary queries the query service provider for the payment proof Proof corresponding to the order. In one specific embodiment of the present invention, if the user's order is N5 and N6, then the query service provider generates a payment proof. The method used is the same as the method used by users to pay fees. Furthermore, since the service provider has already sent the service order to the notary office, the notary office can obtain the order ID, amount, and user address after parsing.

[0063] The notary office uses the Proof and order information to call the SettlePay function of the smart contract. After verifying the Proof, the contract deducts the corresponding fee from the query service provider's account. In a specific embodiment of the invention, if the user's order is N5 or N6, the notary office adds the Proof and the order amount, ID, and user address to the service order. user It is sent to the smart contract, so it can be calculated within the contract. If the value matches the Merkle root that the query service provider has pre-stored in the contract, the contract can verify the correctness of the Proof and the order, thereby enabling batch payment for orders N5 and N6.

[0064] The query service settlement method of this invention eliminates the need for key parameters of service orders to be stored in the public blockchain's storage space as field records, unlike traditional settlement smart contracts. Instead, these parameters are simply recorded as transaction inputs in the blockchain's ledger space, ensuring transparent, tamper-proof, and auditable settlement transactions. Since the gas costs of storing these parameters in storage space as fields far exceed those of storing them as transaction inputs in the ledger space, the batch payment process based on the Merkle order tree not only achieves batch payment for orders but also reduces the gas costs incurred for service settlement.

[0065] The above-described embodiments are merely illustrative of several implementations of the present invention, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the present invention. Those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these modifications and improvements all fall within the scope of protection of the present invention.

Claims

1. A query service settlement system for optimizing smart contract gas overhead, characterized in that, include: Smart contracts, query service providers, user terminals, notary terminals, and blockchain explorers; The smart contract is used to record the addresses of the notary office, the query service provider, and the user, to pre-deposit fees for the user, and to complete the settlement of order fees between the user and the query service provider. The query service provider is used to provide query services to the user when the user initiates a query service request, and to return query information to the user including the query order, query results, and the cryptographic proof of the query results (VO). The query service provider is also used to construct a Merkle order tree and store the Merkle root in a smart contract. When the smart contract settles order fees, it only needs to call the Merkle root, thereby reducing the gas overhead of the smart contract. The query order includes the order number, order amount, and user address. The Merkle order tree includes K unpaid query orders, where K is an integer greater than or equal to 1. The user terminal is used to initiate a query service request, receive query information returned by the query service provider, and verify the query result based on the cryptographic proof VO of the query result; The client is also used to pay for completed query services based on the query order; The notary office is used to resolve disputes between the query service provider and the user regarding query orders; The blockchain explorer is used to obtain specific information about transactions on the public blockchain for the notary office and to confirm whether the order has been paid. The notary office queries the specific information of the transaction through the blockchain explorer, verifies the query results, and processes the payment issue of the query order based on the correctness of the verified query results. The specific information of the transaction includes the creation time of the query service order, the amount of the query service order, the user's account balance, and the contract call behavior.

2. A query service settlement method based on the query service settlement system of claim 1, characterized in that, Includes the following steps: 1) Deploy smart contracts in the public blockchain and record the addresses of the notary office, the query service provider, and the user in the smart contracts; 2) The user deposits fees in advance into the smart contract and records the user's public chain address in the smart contract; 3) The user initiates a query request to the query service provider. After receiving the query request from the user, the query service provider sends the query results, the cryptographic proof of the query results (VO), the query information of the query order, and the signature of the query service provider on the query information to the user. Furthermore, before the number of unpaid service orders accumulates to K, the query service provider stores the orders locally. After the number of unpaid service orders accumulates to K, the query service provider constructs a Merkle order tree based on the K unpaid service orders and stores the Merkle root in the smart contract. 4) After receiving the query information, the user signs the query information and verifies the query result based on the cryptographic proof (VO) of the query result; Once the user verifies the correctness of the query results, they pay the query order fee to the query service provider via a smart contract. 5) When the user fails to complete the payment within the service order fee payment period, the query service provider sends the query information to the notary office. The notary office queries the specific information of the transaction through the blockchain explorer, verifies the query results, and processes the payment issue of the query order based on the correctness of the verified query results.

3. The query service settlement method according to claim 2, characterized in that, In step 3), the query service provider will only provide query services to the user if the user has sufficient pre-deposited balance; if the user's pre-deposited balance is insufficient, the query service provider will refuse to provide query services to the user.

4. The query service settlement method according to claim 2, characterized in that, In step 3), the hash value of each leaf node in the Merkle order tree constructed by the query service provider is the hash value of a service order. The hash value of the user's public blockchain address The result is calculated by combining the hash value of the order amount and the hash value of the order number. ; Where "|" is the connector and h(.) is the hash function; after the query service provider builds the Merkle order tree locally, it stores the Merkle root of the Merkle order tree on the public chain by calling the StoreRoot function of the smart contract.

5. The query service settlement method according to claim 2, characterized in that, In step 4), the user's invocation of the smart contract to pay the query service provider for the query order fee specifically includes the following steps: 4.1) The user client queries the query service provider for the payment certificate of the payment order, where multiple payment orders use a single payment certificate to achieve batch settlement; 4.2) The query service provider generates payment proofs corresponding to user-paid orders based on the Merkle order tree and sends the payment proofs to the user. 4.3) The user receives the payment certificate and transmits it to the smart contract. After verifying the payment certificate, the smart contract deducts the total order fee from the pre-deposited funds on the user's end and transfers it to the query service provider's account.

6. The query service settlement method according to claim 2, characterized in that, In step 4), before the number of unpaid orders in the query service provider reaches K, the query service provider will not provide payment proof to the user and the order fee will not be settled temporarily.

7. The query service settlement method according to claim 2, characterized in that, The query service provider signs the received information sent to the user to prove that the received information was sent by the query service provider. When the user receives the query information, it also signs it to prove that it has received the received information.

8. The query service settlement method according to claim 2, characterized in that, Step 5) specifically includes the following steps: 5.1) When the user receives the query result and has not paid within the waiting time threshold T, the query service provider will send the query order and query result receipt information, which includes the signatures of the query service provider and the user, to the notary office. 5.2) The notary office verifies the signatures of the received information by both the user and the query service provider, parses the received information to obtain the query results and specific information of the service order; and confirms by querying the blockchain explorer that the order has indeed not been paid and has exceeded the payment time threshold T. 5.3) The notary office confirms the correctness of the query result based on the cryptographic proof VO and the query result. If the query result is incorrect, no operation is performed. If the query result is correct, the notary office queries the query service provider for the payment proof corresponding to the order. The query service provider has already sent the received information to the notary office. After parsing, the notary office obtains the order ID, amount and user's public chain address. 5.4) The notary office uses the payment certificate and order information to call the SettlePay function of the smart contract. After verifying the payment certificate, the smart contract deducts the total order fee from the fee pre-deposited by the user and transfers it to the account of the query service provider.

Citation Information

Patent Citations

  • Blockchain digital identity authentication method and system based on DNS (Domain Name System)

    CN106789881A

  • Course notary system and method applied to multi-platform education resource sharing

    CN108876669A