ZKML proof efficiency optimization method based on random sampling
Through the ZKML proof efficiency optimization method based on random sampling, combined with zero-knowledge proof and credit rating, the problem of long proof generation and verification time in the existing technology is solved, efficient proof and verification is achieved, and in trustless scenarios are realized The segmentation verification and credit assessment of the model were carried out.
Patent Information
- Application Number
- CN202411062492.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-05
- Publication Date
- 2024-12-03
AI Technical Summary
The existing ZKML proof scheme has problems such as too long time and large communication overhead in the generation and verification process, and has failed to effectively balance the verification overhead and credibility, especially in the trustless distributed scenarios, the model segmentation verification and Credit assessment is difficult to achieve.
Using the ZKML proof efficiency optimization method based on random sampling, the verification key and proof key are generated through zero-knowledge proof technology (such as zk-Snarks), combined with the credit rating function and the time forgetting factor, the proof generation and verification process is optimized, and the proof generation and verification process is passed through RSA signature ensures the accuracy and security of the key.
Significantly improves the efficiency of proof generation and verification, ensures appropriate sampling ratio and high credibility, and realizes the flexibility of separate verification and credit assessment of the model substructure in trustless scenarios, reduces data dimensions and improves training efficiency.
Smart Images

Figure CN119070983A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of digital economy, and in particular relates to a ZKML proof efficiency optimization method based on random sampling. Background Art
[0003] The booming development of the digital economy is inseparable from the support of new technologies and new methods. The rapid progress in the field of artificial intelligence in the past year has also brought new challenges and opportunities to its development. With the continuous emergence of generative AI large models, the contradiction between users' growing demand for AI use and insecure and imperfect AI-as-a-service platforms has become increasingly prominent. At the same time, many users are unable to train or deploy large models locally due to time and economic costs. The development of zero-knowledge proof technology provides a new solution for the security and privacy protection of the digital economy. By using this technology to generate proofs of the training and prediction process, data privacy and model security can be ensured. At the same time, the proof of the prediction process can be done without leaking detailed information such as the structural parameters of the model, thereby protecting user privacy and enhancing the credibility and security of the digital economic ecosystem.
[0004] Although remarkable achievements have been made in this field, there are still some urgent problems to be solved. Some schemes have a large number of proofs, resulting in long generation time and high communication overhead when transmitting proofs. Some schemes use random sampling ideas to speed up proof generation but do not consider more practical situations, including how to balance the contradiction between verification overhead and verification credibility, as well as the credibility of the training party and data preservation capabilities. Summary of the invention
[0005] The purpose of the present invention is to provide a ZKML proof efficiency optimization method based on random sampling to solve the problems raised in the above background technology.
[0006] To achieve the above object, the present invention provides the following technical solution: a ZKML proof efficiency optimization method based on random sampling, comprising the following steps:
[0007] S1. Model declaration and key generation: Select the underlying zero-knowledge proof technology, convert and compile the calculation process of the machine learning model according to its corresponding zero-knowledge proof primitive, and generate the verification key VK and the proof key PK;
[0008] S2. Key distribution: The proof key PK is distributed to the training party for subsequent generation of the proof body, and the verification key VK is distributed to the user for subsequent verification of the correctness of the proof body;
[0009] S3. The trainer conducts training: The trainer conducts training according to the pre-agreed data set, number of Epochs, and data batches, and saves the intermediate parameters generated by each Batch of each Epoch during training.
[0010] S4. Credit rating function D: All transaction tasks of the training party, including those with historical transaction figures, are marked as abiding by the contract or not abiding by the contract according to whether they abide by the contract or not, and different weights are given. That is, the weight of the abiding by the contract task is set to R good =1, the weight of the non-compliance task is set to R bad =0;
[0011] S5. Construct the total loss function Loss(N): The formula of the total loss function Loss(N) is as follows:
[0012]
[0013] The independent variable N represents the number of simple random sampling, c0 represents the basic verification time cost, c1 represents the single data verification time cost, so c0+c1N represents the total time cost; n represents the total amount of data to be verified, f represents the number of fraudulent data, then As a verification of credibility;
[0014] S6. Proof generation: The training party encapsulates the intermediate data of the corresponding training into Witness for the Batch selected by the user, and then extracts PublicWitness from Witness, which represents the output data of the model, and sends Proof and PublicWitness to the user.
[0015] CCS+PK+Witness→Proof;
[0016] S7. Correctness of user verification results: After verifying the correctness of the results, the user shall record all verification results for use in subsequent cooperation to continue to assess the credit rating of the credit party;
[0017] Proof+VK+PublicWitness→True / False.
[0018] Preferably, the zero-knowledge proof technology in S1 adopts zk-Snarks, which can provide corresponding proofs for calculations that generate specific outputs, so that the speed of verifying proofs is much faster than the speed of executing corresponding calculations, and zk-Snarks adopts any one of Groth16 and Plonk implementation solutions.
[0019] Preferably, after the zero-knowledge proof primitive in S1 is used to convert and compile the calculation process of the machine learning model, a public reference string CCS is obtained, and CCS then generates a verification key VK and a proof key PK. The process of generating the verification key VK and the proof key PK from the string CCS is performed by a third party or under the witness of a third party.
[0020] Preferably, the third party uses RSA signature for authentication, and the calculation process of RSA signature is as follows:
[0021] Signature Algorithm:
[0022] Encode the file m to be signed and map it into h(m);
[0023] calculate
[0024] c1≡(h(m)) d modp,
[0025] c2≡(h(m)) d modq,
[0026] S A (m)≡(c1q (1) q+c2p (1) p)modn,
[0027] Send {m, SA(m)} to the third party T;
[0028] Verification algorithm:
[0029] (S A (m)) e ≡h(m)modn.
[0030] Preferably, the credit rating assessment in S4 first constructs a time forgetting factor, and the formula is as follows:
[0031] w i =e -λt
[0032] Where t represents the time from the corresponding task to the present; λ is the proportional coefficient, which is used to adjust the degree of forgetting; it means that the latest task completion status has the greatest impact on the credit rating, and the longer the time, the smaller the impact.
[0033] Preferably, the credit rating function D is as follows:
[0034]
[0035] Among them, T in the molecule good The number of tasks representing the contract compliance behavior, T badis the number of non-observable tasks, which is multiplied by the corresponding time forgetting factor and added to get the sum of all weights; the denominator represents the sum of weights when all tasks are compliant, ensuring that the value of D is within a reasonable range.
[0036] Preferably, the formula for verifying credibility in S5 is It represents the probability that there is at least one false data in the results of N samplings; since the higher the credibility, the lower the corresponding loss, This is how credibility is integrated into the Loss function, where λ is a proportional factor used to adjust the proportional relationship between credibility and other parameters.
[0037] According to the method for optimizing ZKML proof efficiency based on random sampling in claim 1, it is characterized in that: in S5, when the training party has better credit, its verification credibility is higher, then D+ε is directly multiplied by the credibility, and the credibility is Here, ε is used as a minimum value to prevent the function from losing its meaning when D is 0, and its value is 0.01.
[0038] Preferably, the overall trend of the function graph of the function L(N) in S5 in N∈(0,n) is a concave function that decreases first and then increases, and the horizontal coordinate corresponding to the minimum point is the optimal solution. After that, the user performs N simple random samplings in the data population n that needs to be verified, obtains a sample with a capacity of N, and sends the request to the prover. The aforementioned data population is all training epochs, or all data batches in an epoch.
[0039] Preferably, when training, the training method in S3 normalizes all data and maps weights to the interval [0, 1], so as to reduce the dimension of data for training and improve the efficiency of training;
[0040] The calculation formula for normalization is as follows;
[0041]
[0042] Among them, g is the result of the weight normalization of the input data information, and the output range is between 0 and 1, G is the weight of the input data information, G min is the minimum value among the weights of the input data information, G max It is the maximum value among the weights of the input data information.
[0043] Compared with the prior art, the present invention has the following beneficial effects:
[0044] The present invention can greatly improve the efficiency of proof generation and verification by randomly sampling target data; and the loss function design can help users determine the appropriate sampling ratio with a certain degree of credibility;
[0045] Considering that the model training tasks will be more often carried out in untrusted distributed scenarios, each substructure of the model can be converted and compiled separately and a pair of keys can be generated for each substructure, so that the substructure can be verified separately;
[0046] In a credit-free scenario, the qualities of different training parties are different, so a credit rating function is introduced, in which the time forgetting factor used can give lower weights to more distant tasks and higher weights to tasks closer to the current one; and the basic weights for compliance or non-compliance behaviors can be adjusted arbitrarily according to specific requirements. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 It is a schematic diagram of the steps of the present invention;
[0048] Figure 2 It is a schematic diagram of the Loss function image of the present invention. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] See also Figure 1-Figure 2 The present invention provides a technical solution: a ZKML proof efficiency optimization method based on random sampling, comprising the following steps:
[0051] S1. Model declaration and key generation: Select the underlying zero-knowledge proof technology, convert and compile the calculation process of the machine learning model according to its corresponding zero-knowledge proof primitive, and generate the verification key VK and the proof key PK;
[0052] S2. Key distribution: The proof key PK is distributed to the training party for subsequent generation of the proof body, and the verification key VK is distributed to the user for subsequent verification of the correctness of the proof body;
[0053] S3. The trainer conducts training: The trainer conducts training according to the pre-agreed data set, number of Epochs, and data batches, and saves the intermediate parameters generated by each Batch of each Epoch during training.
[0054] S4. Credit rating function D: All transaction tasks of the training party, including those with historical transaction figures, are marked as abiding by the contract or not abiding by the contract according to whether they abide by the contract or not, and different weights are given. That is, the weight of the abiding by the contract task is set to R good =1, the weight of the non-compliance task is set to R bad =0;
[0055] S5. Construct the total loss function Loss(N): The formula of the total loss function Loss(N) is as follows:
[0056]
[0057] The independent variable N represents the number of simple random sampling, c0 represents the basic verification time cost, c1 represents the single data verification time cost, so c0+c1N represents the total time cost; n represents the total amount of data to be verified, f represents the number of fraudulent data, then As a verification of credibility;
[0058] S6. Proof generation: The training party encapsulates the intermediate data of the corresponding training into Witness for the Batch selected by the user, and then extracts PublicWitness from Witness, which represents the output data of the model, and sends Proof and PublicWitness to the user.
[0059] CCS+PK+Witness→Proof;
[0060] S7. Correctness of user verification results: After verifying the correctness of the results, the user shall record all verification results for use in subsequent cooperation to continue to assess the credit rating of the credit party;
[0061] Proof+VK+PublicWitness→True / False.
[0062] In order to realize zero-knowledge proof and make the verification efficiency greater than the calculation efficiency, in this embodiment, preferably, the zero-knowledge proof technology in S1 adopts zk-Snarks, which can provide corresponding proofs for calculations that generate specific outputs, so that the speed of verifying proofs is much faster than the speed of executing corresponding calculations, and zk-Snarks adopts any one of Groth16 and Plonk implementation schemes.
[0063] In order to improve the accuracy and security of the verification key VK and the proof key PK, witnessing is performed by a third party. In this embodiment, preferably, the zero-knowledge proof primitive in S1 is used to convert and compile the calculation process of the machine learning model to obtain a public reference string CCS, and then the verification key VK and the proof key PK are generated by CCS. The process of generating the verification key VK and the proof key PK by the string CCS is performed by a third party or under the witness of a third party.
[0064] In order to achieve the effectiveness of the third-party witness, in this embodiment, preferably, the third party uses RSA signature for authentication, and the calculation process of RSA signature is as follows:
[0065] Signature Algorithm:
[0066] Encode the file m to be signed and map it into h(m);
[0067] calculate
[0068] c1≡(h(m)) d mod p,
[0069] c2≡(h(m)) d mod q,
[0070] S A (m)≡(c1q (1) q+c2p (1) p)mod n,
[0071] Send {m, SA(m)} to the third party T;
[0072] Verification algorithm:
[0073] (S A (m)) e ≡h(m)mod n.
[0074] In order to calculate the influence of time, in this embodiment, preferably, the credit rating assessment in S4 first constructs a time forgetting factor, and the formula is as follows:
[0075] w i =e -λt
[0076] Where t represents the time from the corresponding task to the present; λ is the proportional coefficient, which is used to adjust the degree of forgetting; it means that the latest task completion status has the greatest impact on the credit rating, and the longer the time, the smaller the impact.
[0077] In order to realize the credit rating calculation process, in this embodiment, preferably, the credit rating function D is as follows:
[0078]
[0079] Among them, T in the molecule good The number of tasks representing the contract compliance behavior, T bad is the number of non-observable tasks, which is multiplied by the corresponding time forgetting factor and added to get the sum of all weights; the denominator represents the sum of weights when all tasks are compliant, ensuring that the value of D is within a reasonable range.
[0080] In order to improve the credibility, reduce the probability of false data, and adjust the proportional relationship between the credibility and the parameter through the proportional factor, in this embodiment, preferably, the formula for verifying the credibility in S5 is It represents the probability that there is at least one false data in the results of N samplings; since the higher the credibility, the lower the corresponding loss, This is how credibility is integrated into the Loss function, where λ is a proportional factor used to adjust the proportional relationship between credibility and other parameters.
[0081] The better the credit, the higher the credibility, so that D+ε is directly multiplied by the credibility, and the rating function D can be prevented from losing consciousness. In this embodiment, preferably, in S5, when the training party has a better credit, its verification credibility is higher, then D+ε is directly multiplied by the credibility, and the credibility is Here, ε is used as a minimum value to prevent the function from losing its meaning when D is 0, and its value is 0.01.
[0082] In order to describe the function L(N), obtain the optimal solution, and transmit the sample for the convenience of the prover to use it for proof, in this embodiment, preferably, the overall trend of the function graph of the function L(N) in S5 in N∈(0,n) is a concave function that decreases first and then increases, and the horizontal coordinate corresponding to the minimum point is the optimal solution. After that, the user performs N simple random sampling in the data population n that needs to be verified, obtains a sample with a capacity of N, and sends the request to the prover. The aforementioned data population is all training epochs, or all data batches in an epoch.
[0083] In order to improve the training efficiency of data information, in this embodiment, preferably, the training party in S3 normalizes all data and maps weights to the interval [0, 1] during training, so as to reduce the dimension of data for training and improve the training efficiency;
[0084] The calculation formula for normalization is as follows;
[0085]
[0086] Among them, g is the result of the weight normalization of the input data information, and the output range is between 0 and 1, G is the weight of the input data information, G min is the minimum value among the weights of the input data information, G max It is the maximum value among the weights of the input data information.
[0087] The working principle and use process of the present invention:
[0088] Step 1: Model declaration and key generation: Select the underlying zero-knowledge proof technology, that is, any implementation of zk-Snarks, including Groth16, Plonk, etc.; convert and compile the calculation process of the machine learning model according to its corresponding zero-knowledge proof primitive to obtain the common reference string CCS (Common Reference String), and then generate the verification key VK (Verify Key) and the proof key PK (Prove Key) from CCS; this process can be carried out by a third party or under the witness of a third party;
[0089] Step 2: Key distribution: PK is distributed to the training party for subsequent generation of the proof body, and VK is distributed to the user for subsequent verification of the correctness of the proof body;
[0090] Step 3: The trainer conducts training based on the pre-agreed data set, number of Epochs, and data batches, and saves the intermediate parameters generated by each Batch of each Epoch during training.
[0091] Step 4: Credit rating function D: Mark all past transaction tasks with the training party as compliance and non-compliance, and give different weights, for example: the weight of the compliance task is set to R good =1, the weight of the non-compliance task is set to R bad =0;
[0092] Construct the time forgetting factor, the formula is as follows:
[0093] w i =e -λt
[0094] Where t represents the time from the corresponding task to the present; λ is the proportional coefficient used to adjust the degree of forgetting. This formula indicates that the latest task completion status has the greatest impact on the credit rating, and the impact is smaller the further away the time is;
[0095] The credit rating function D constructed above is as follows:
[0096]
[0097] The T in the numeratorgood The number of tasks representing the contract compliance behavior, T bad is the number of non-observing tasks, which are multiplied by the corresponding time forgetting factor and added up to get the sum of all weights; the denominator represents the sum of weights when all tasks are compliant, which ensures that the value of D is within a reasonable range;
[0098] Step 5: Construct the total loss function Loss(N): The function value represents the abstract sum of losses of the verification behavior; its formula is as follows:
[0099]
[0100] The independent variable N represents the number of simple random sampling, that is, N samples are taken from the total data to obtain N data, c0 represents the basic verification time cost, such as model loading time, etc., c1 is the single data verification time cost, so c0+c1N represents the total time cost; n represents the total amount of data to be verified, f represents the number of deceptive data, then As the verification credibility, it represents the probability that there is at least one false data in the results of N samplings; since the higher the credibility, the lower the corresponding loss should be, so This is how credibility is integrated into the Loss function, where λ is a proportional factor used to adjust the proportional relationship between credibility and other parameters. Generally, the better the credibility of the training party, the higher its verification credibility should be. Therefore, D+ε is directly multiplied by the credibility, where ε is used as a minimum value to prevent the function from losing its meaning when D is 0, and can be taken as 0.01.
[0101] The function graph of function L(N) at N∈(0,n) is shown in the following figure. Figure 2 As shown in the figure (the parameters are only temporary settings and have no practical significance. They need to be determined according to the specific attributes of the task). The three images in the figure show the trends when the credit rating D is set to 0.2, 0.5 and 0.95 respectively. The overall function is a concave function that decreases first and then increases. The horizontal coordinate corresponding to the minimum point is the optimal solution. After that, the user performs N simple random samplings in the data population n that needs to be verified, obtains a sample with a capacity of N, and sends the request to the prover. The data population mentioned above can be all training epochs, or all data batches in one epoch.
[0102] Step 6: Proof generation: For the batch selected by the user, the training party encapsulates the intermediate data (input and output of the model) during the corresponding training into a Witness, and then extracts the Public Witness from the Witness, which represents the output data of the model; and sends the Proof and Public Witness to the user;
[0103] CCS+PK+Witness→Proof;
[0104] Step 7: The user verifies the correctness of the result and records all the verification results, which can be used to continue to assess the credit rating of the credit party in subsequent cooperation;
[0105] Proof+VK+PublicWitness→True / False.
[0106] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for optimizing ZKML proof efficiency based on random sampling, characterized in that: The following steps are included: S1. Model declaration and key generation: Select the underlying zero-knowledge proof technology, convert and compile the calculation process of the machine learning model according to its corresponding zero-knowledge proof primitive, and generate the verification key VK and the proof key PK; S2. Key distribution: The proof key PK is distributed to the training party for subsequent generation of the proof body, and the verification key VK is distributed to the user for subsequent verification of the correctness of the proof body; S3. The trainer conducts training: The trainer conducts training according to the pre-agreed data set, number of Epochs, and data batches, and saves the intermediate parameters generated by each Batch of each Epoch during training. S4. Credit rating function D: All transaction tasks of the training party, including those with historical transaction figures, are marked as abiding by the contract or not abiding by the contract according to whether they abide by the contract or not, and different weights are given. That is, the weight of the abiding by the contract task is set to R good =1, the weight of the non-compliance task is set to R bad =0; S5. Construct the total loss function Loss(N): The formula of the total loss function Loss(N) is as follows: The independent variable N represents the number of simple random sampling, c0 represents the basic verification time cost, c1 represents the single data verification time cost, so c0+c1N represents the total time cost; n represents the total amount of data to be verified, f represents the number of fraudulent data, then As a verification of credibility; S6. Proof generation: The training party encapsulates the intermediate data of the corresponding training into Witness for the Batch selected by the user, and then extracts PublicWitness from Witness, which represents the output data of the model, and sends Proof and PublicWitness to the user. CCS+PK+Witness→Proof; S7. Correctness of user verification results: After verifying the correctness of the results, the user shall record all verification results for use in subsequent cooperation to continue to assess the credit rating of the credit party; Proof+VK+PublicWitness→True / False.
2. According to claim 1, a ZKML proof efficiency optimization method based on random sampling is characterized in that: The zero-knowledge proof technology in S1 uses zk-Snarks, which can provide corresponding proofs for calculations that generate specific outputs, making the speed of verifying proofs much faster than the speed of executing corresponding calculations, and zk-Snarks uses any one of Groth16 and Plonk implementations.
3. The method for optimizing ZKML proof efficiency based on random sampling according to claim 1, characterized in that: After the zero-knowledge proof primitive in S1 is used to convert and compile the calculation process of the machine learning model, a public reference string CCS is obtained, and CCS then generates a verification key VK and a proof key PK. The process of generating the verification key VK and the proof key PK from the string CCS is performed by a third party or under the witness of a third party.
4. The method for optimizing ZKML proof efficiency based on random sampling according to claim 3, characterized in that: The third party uses RSA signature for authentication. The calculation process of RSA signature is as follows: Signature Algorithm: Encode the file m to be signed and map it into h(m); calculate c1≡(h(m)) d mod p, c2≡(h(m)) d mod q, S A (m)≡(c1q (1) q+c2p (1) p)mod n, Send {m, SA(m)} to the third party T; Verification algorithm: (S A (m)) e ≡h(m)mod n。 5. The method for optimizing ZKML proof efficiency based on random sampling according to claim 1, characterized in that: The credit rating assessment in S4 first constructs a time forgetting factor, and the formula is as follows: w i =e -λt Where t represents the time from the corresponding task to now; λ is a proportional coefficient used to adjust the degree of forgetting; it means that the latest task completion status has the greatest impact on the credit rating, and the further the time, the smaller the impact.
6. The method for optimizing ZKML proof efficiency based on random sampling according to claim 1, characterized in that: The credit rating function D is as follows: Among them, T in the molecule good The number of tasks representing the contract compliance behavior, T bad is the number of non-observable tasks, which is multiplied by the corresponding time forgetting factor and added to get the sum of all weights; the denominator represents the sum of weights when all tasks are compliant, ensuring that the value of D is within a reasonable range.
7. The method for optimizing ZKML proof efficiency based on random sampling according to claim 1, characterized in that: The formula for verifying credibility in S5 is It represents the probability that there is at least one false data in the results of N samplings; since the higher the credibility, the lower the corresponding loss, This is how credibility is integrated into the Loss function, where λ is a proportional factor used to adjust the proportional relationship between credibility and other parameters.
8. The method for optimizing ZKML proof efficiency based on random sampling according to claim 1, characterized in that: In S5, the better the training party's credit is, the higher its verification credibility is. Then D+ε is directly multiplied by the credibility, and the credibility is Here, ε is used as a minimum value to prevent the function from losing its meaning when D is 0, and its value is 0.
01.
9. The method for optimizing ZKML proof efficiency based on random sampling according to claim 1, characterized in that: The overall trend of the function graph of the function L(N) in S5 at N∈(0,n) is a concave function that decreases first and then increases. The horizontal coordinate corresponding to the minimum point is the optimal solution. After that, the user performs N simple random samplings in the data population n that needs to be verified, obtains a sample with a capacity of N, and sends the request to the prover. The data population mentioned above is all training epochs, or all data batches in an epoch.
10. The method for optimizing ZKML proof efficiency based on random sampling according to claim 1, characterized in that: When training, the training method in S3 normalizes all data and maps weights to the interval [0, 1], so as to reduce the dimension of data for training and improve the efficiency of training; The calculation formula for normalization is as follows; Among them, g is the result of the weight normalization of the input data information, and the output range is between 0 and 1, G is the weight of the input data information, G min is the minimum value among the weights of the input data information, G max It is the maximum value among the weights of the input data information.
