A method and system for collaborative secure computing on and off the chain based on sharded blockchain

By introducing sharded blockchain and smart contracts into federated learning, the safe circulation and privacy protection of data are achieved, the security risks of traditional data management systems and the communication overhead of federated learning are solved, and data privacy protection and system scalability are improved. .

CN118368053BActive Publication Date: 2024-09-20SHANDONG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410773274.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-17
Publication Date
2024-09-20
Estimated Expiration
2044-06-17

AI Technical Summary

Technical Problem

Traditional centralized data management systems have security risks such as data leakage, unauthorized access, and data tampering in data circulation and multi-party sharing scenarios. In addition, the communication overhead during federated learning model training is high, resulting in data leakage and inconvenience to the global model. Behavior.

Method used

Adopting an on-chain and off-chain collaborative secure computing method based on sharded blockchain, ensuring that client data always remains encrypted through encryption gradient sharing and aggregation, and utilizing blockchain sharding and smart contracts to achieve secure circulation and privacy protection of data , while dynamically adjusting committee members to improve system fairness and transparency.

Benefits of technology

It significantly improves the level of data privacy protection and system scalability, reduces network congestion and processing delays, ensures the security and controllability of data during circulation and sharing, and promotes the development of data-driven application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118368053B
    Figure CN118368053B
Patent Text Reader

Abstract

The present invention discloses a method and system for collaborative secure computing on and off the chain based on a sharded blockchain, which relates to the technical field of collaborative secure computing on and off the chain, including: obtaining a key pair and a global model, and selecting a client as a committee member, and the remaining clients as training clients; the training client performs local training according to the global model, generates a model gradient, encrypts the model gradient according to the key pair, and uploads the encrypted gradient to the blockchain system; the committee members obtain the encrypted gradient and perform scoring, and upload the scoring results to the blockchain system; the blockchain system is divided into multiple shards, and the sharded blockchain system updates the global model according to the scoring results and selects the committee members for the next round of model training. Ensure secure model gradient sharing and aggregation, thereby achieving secure data circulation and privacy protection; at the same time, each shard can process different data requests in parallel to improve response speed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of on-chain and off-chain collaborative secure computing technology, and in particular to an on-chain and off-chain collaborative secure computing method and system based on sharded blockchain. Background Art

[0002] The on-chain and off-chain collaborative secure computing framework is a system used to ensure the security of data during transmission and sharing. With the rapid development of information technology and the Internet, coupled with the rise of technologies such as multi-party computing and artificial intelligence, the way of data circulation has evolved from the traditional "one-to-one" to "many-to-many", and data security issues have attracted more and more attention.

[0003] Traditional centralized data management systems provide convenience to a certain extent, but they also face multiple security risks such as data leakage, unauthorized access, and data tampering. Traditional data protection mechanisms usually rely on strict access control and complex encryption technologies. Although these methods can prevent illegal access to data to a certain extent, they have problems such as inefficiency in data circulation and multi-party sharing scenarios. In addition, data stored in centralized servers may also become the target of hacker attacks. Once the security protection measures of the data management system are breached, all data may be leaked at once, resulting in irreversible consequences. Therefore, data security issues have become an important factor hindering the smooth flow of data and cooperation between subjects. Therefore, a more secure and reliable framework is needed to protect the security of data.

[0004] Federated learning aims to protect user privacy while using distributed data sources to train models by training models on local clients and updating global models by sharing model parameters or gradients. Its advantages are privacy protection, data diversity, reduced communication costs, and real-time updates. Combining federated learning with the on-chain and off-chain collaborative secure computing framework can further improve data security and privacy protection, ensure the security and controllability of data during circulation and sharing, and promote the development and application of data-driven application scenarios.

[0005] However, due to the frequent transmission of gradients and models between participants and the central server during the training of the federated learning model, the communication overhead of the entire federated system is relatively large. At the same time, there are also behaviors that are not conducive to the global model, such as data leakage, node poisoning, and free riding. Summary of the invention

[0006] In order to solve the above problems, the present invention proposes an on-chain and off-chain collaborative secure computing method and system based on sharded blockchain, which ensures that during model training and gradient processing, client data always remains encrypted, ensuring secure model gradient sharing and aggregation, thereby achieving secure data circulation and privacy protection; at the same time, each shard can process different data requests in parallel to improve response speed.

[0007] In order to achieve the above object, the present invention adopts the following technical solution:

[0008] In a first aspect, the present invention provides an on-chain and off-chain collaborative secure computing method based on a sharded blockchain, which is applied to a client and includes:

[0009] Obtain the key pair and global model, and select the client as the committee member, and the rest of the clients as training clients;

[0010] The training client performs local training based on the global model, generates model gradients, encrypts the model gradients based on the key pair, and uploads the encrypted gradients to the blockchain system;

[0011] The committee members obtain the encrypted gradients and perform scoring, and upload the scoring results to the blockchain system, which is divided into multiple shards, so that the sharded blockchain system updates the global model and selects committee members for the next round of model training according to the scoring results.

[0012] In a second aspect, the present invention provides an on-chain and off-chain collaborative secure computing method based on a sharded blockchain, which is applied to a blockchain system, including:

[0013] Send the global model to the client, select committee members from the client, and use the remaining clients as training clients; so that the training client performs local training according to the global model, generates model gradients, and encrypts the model gradients according to the obtained key pairs, and uploads the obtained encrypted gradients to the blockchain system through smart contracts. At the same time, the committee members obtain the encrypted gradients and perform scoring, and upload the scoring results to the blockchain system;

[0014] The blockchain system is divided into multiple shards. The sharded blockchain system updates the global model and selects committee members for the next round of model training based on the scoring results.

[0015] As an optional implementation, the process of selecting the committee members for the next round of model training includes: weighting the scoring results of the encrypted gradients of the training client in the current round and the previous round to elect the committee members for the next round of model training, where the weights for:

[0016] ;

[0017] in, is the scoring result of the encrypted gradient of the training client i in this round, is the scoring result of the encrypted gradient of the previous round of training client i.

[0018] As an optional implementation, during local training, the dataset used by the training client i in local training is used. Calculate the model gradient: ;

[0019] According to the aggregation gradient and learning rate Update the local model: ;

[0020] The encrypted gradient obtained after encrypting the model gradient is:

[0021] ;

[0022] in, is the global model parameter; Given the global model parameters The loss function under is the loss function The gradient of The local model parameters for the t+1th round of model training; is the global model parameter of the tth round of model training; The data is in ciphertext state; is the private key, is the public key; is the random number selected by the training client i when performing homomorphic encryption; g is an integer.

[0023] As an optional implementation, obtain the global model and then decrypt it for local training: ;in, is the global model parameter; is the global model parameter in the encrypted state, , is the private key, is the public key.

[0024] As an optional implementation, the scoring results are sorted from large to small, the first K% encrypted gradients are selected for updating the global model and selecting committee members for the next round of model training, and the last k% encrypted gradients are discarded.

[0025] As an optional implementation, the process of updating the global model includes:

[0026] According to the dataset used by the training client i in local training Calculate the weight of training client i : ;

[0027] According to weight Encrypted gradients for training client i Weighted, get weighted encrypted gradient :

[0028] ;

[0029] Aggregate the weighted encrypted gradients of all training clients into the total encrypted gradient through homomorphic addition :

[0030] ;

[0031] Using learning rate Update the global model:

[0032] ;

[0033] in, is the data in ciphertext state; J is the number of training clients; j is the cumulative parameter when calculating the total data set, is the dataset of the jth training client; is the private key; is the public key; Aggregate gradients for all training clients; is the global model parameter; is the global model parameter of the t-th model training in the ciphertext state; is the global model parameter of the t+1th model training in the encrypted state.

[0034] As an optional implementation, a new client may be added at any time during the model training process. The new client will automatically default to a training client and perform local training by acquiring the latest global model.

[0035] In a third aspect, the present invention provides an on-chain and off-chain collaborative secure computing system based on a sharded blockchain, comprising:

[0036] The acquisition module is configured to acquire the key pair and the global model, and the selected clients serve as committee members, and the remaining clients serve as training clients;

[0037] The training encryption module is configured to train the client to perform local training according to the global model, generate model gradients, encrypt the model gradients according to the key pair, and upload the obtained encrypted gradients to the blockchain system;

[0038] The scoring module is configured to obtain encrypted gradients and score committee members, and upload the scoring results to the blockchain system, which is divided into multiple shards, so that the sharded blockchain system updates the global model according to the scoring results and selects committee members for the next round of model training.

[0039] In a fourth aspect, the present invention provides an on-chain and off-chain collaborative secure computing system based on a sharded blockchain, comprising:

[0040] The sending module is configured to send the global model to the client, select committee members from the client, and use the remaining clients as training clients; so that the training client performs local training according to the global model, generates model gradients, and encrypts the model gradients according to the obtained key pairs, and uploads the obtained encrypted gradients to the blockchain system through the smart contract, and at the same time enables the committee members to obtain the encrypted gradients and perform scoring, and upload the scoring results to the blockchain system;

[0041] The update module is configured to divide the blockchain system into multiple shards. The sharded blockchain system updates the global model and selects committee members for the next round of model training based on the scoring results.

[0042] Compared with the prior art, the present invention has the following beneficial effects:

[0043] (1) Enhanced data privacy protection: This invention combines homomorphic encryption algorithms and sharded blockchain technology to ensure that client data remains encrypted throughout the entire model training and gradient processing process. As a result, data is protected when it is uploaded to the blockchain after local training, and the actual data content will not be leaked even when processed on the blockchain, thereby significantly improving the level of data privacy protection.

[0044] (2) Improve system scalability and processing efficiency: Through blockchain sharding technology, data and transaction loads are distributed to multiple independent shards, significantly improving the processing capacity and scalability of the entire blockchain system. Each shard can process different transactions and data requests in parallel, reducing network congestion and processing delays, improving the overall performance and response speed of the blockchain system, and enabling the blockchain system to easily adapt to the growing user needs and data volume, with good scalability and efficient data processing capabilities.

[0045] (3) Dynamic and fair participation mechanism: The smart contract is responsible for randomly selecting and dynamically adjusting committee members and training client identities to ensure that each participant has a fair opportunity to participate in the scoring and verification process. This not only ensures the fairness and transparency of the system, but also enhances the enthusiasm and willingness of the participants to collaborate.

[0046] Advantages of additional aspects of the present invention will be given in part in the following description, and in part will become obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.

[0048] Figure 1 This is an overall framework diagram of the on-chain and off-chain collaborative secure computing method based on sharded blockchain provided in Example 1 of the present invention. DETAILED DESCRIPTION

[0049] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.

[0050] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.

[0051] It should be noted that the terms used herein are only for describing specific embodiments, and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that the terms "include" and "comprise" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0052] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.

[0053] Example 1

[0054] Federated learning aims to train models on local clients and update global models by sharing model parameters or gradients, thereby using distributed data sources to train models while protecting user privacy. Its advantages are privacy protection, which avoids the risk of sensitive data transmission by processing data and training models locally on the client; data diversity, which improves the generalization ability of the model by using distributed data sources; reduced communication costs, which only requires the transmission of model parameters or gradients, and reduces the amount of data transmission; and real-time updates, where clients can instantly learn new data and share updated model parameters or gradients to achieve rapid model updates. Combining federated learning with an on-chain and off-chain collaborative secure computing framework can further improve data security and privacy protection, ensure the security and controllability of data during circulation and sharing, and promote the development and application of data-driven application scenarios.

[0055] However, due to the frequent transmission of gradients and models between participants and the central server during the training of the federated learning model, the communication overhead of the entire federated system is relatively large. At the same time, there are also behaviors that are not conducive to the global model, such as data leakage, node poisoning, and free riding. Therefore, this embodiment chooses to combine blockchain with federated learning to overcome these challenges.

[0056] Blockchain technology, with its unique decentralized characteristics, data immutability and transparency, provides a new approach to solving these problems. Decentralized data management does not rely on a single central server, which can reduce the risk of single point failure. At the same time, once the data on the blockchain is recorded, it cannot be modified, which enhances the integrity protection of the data. In addition, the smart contract function of blockchain technology can realize the automation of data access and processing, ensuring that only authorized operations can be executed, thereby effectively preventing unauthorized access and data tampering.

[0057] Blockchain sharding technology divides the entire blockchain into multiple shards. Each shard consists of a group of nodes and is independent of each other. It is a relatively independent sub-chain responsible for processing transactions and data within a specific range. These shards can run in parallel, sharing the overhead of blockchain transaction processing between multiple smaller sub-chains, thereby improving the throughput and performance of the entire network. The cross-shard transaction data in the framework is transmitted through the P2P network (peer-to-peer, peer-to-peer network) by the closest common ancestor of the two shards as the coordination node. At the same time, all messages transmitted through the P2P network are serialized using protobuf technology (data description language, a lightweight and efficient serialized data structure protocol, commonly used in data exchange and communication protocols), which improves the efficiency of data transmission and makes the encoding and decoding process of messages more efficient. Shards interact and coordinate through consistency protocols and cross-shard communication mechanisms. At the same time, due to the division of transaction processing overhead, the entire blockchain system significantly reduces the communication, computing and storage capabilities of participating nodes. By distributing transactions and data in different shards for processing, the system's concurrent processing capability and transaction throughput capacity are improved, effectively reducing the load pressure on the entire network.

[0058] At the same time, the Paillier homomorphic encryption algorithm is an encryption algorithm suitable for on-chain and off-chain collaborative secure computing frameworks. It allows homomorphic operations on data in ciphertext without decryption, which can make private data still available during the circulation of the framework. Specifically, the homomorphic addition and multiplication properties of the Paillier homomorphic encryption algorithm under ciphertext can be used to complete the aggregation step of the gradients of each client in the ciphertext state during the federated learning process.

[0059] Therefore, this embodiment designs an on-chain and off-chain collaborative secure computing method based on sharded blockchain, using the core advantages of blockchain technology to establish a secure, transparent, and efficient data circulation environment, which can not only protect data security, but also support data sharing across institutions and geographical boundaries, thereby promoting the maximum utilization of data assets; at the same time, blockchain sharding improves the scalability and transaction processing capabilities of the blockchain network, helping various organizations to make full use of the opportunities brought by modern information technology and cope with increasingly complex data processing needs while ensuring data security.

[0060] The main inventions include:

[0061] (1) Integrate sharded blockchain into the on-chain and off-chain collaborative secure computing framework, significantly improve system scalability and processing speed, reduce transaction latency, and support large-scale data and model training.

[0062] (2) Integrate smart contracts and homomorphic encryption to realize the upload and on-chain processing of encrypted gradients, protect the privacy of on-chain and off-chain data, and ensure the security of model training and updating processes.

[0063] (3) Dynamically adjust the committee based on the client's historical performance to ensure that high-quality members participate in decision-making, improve system fairness and anti-attack capabilities, and optimize overall model performance.

[0064] The method of this embodiment combines the on-chain sharded blockchain system and off-chain federated learning to form an on-chain and off-chain collaborative secure computing framework. Multiple participants (such as medical institutions, financial institutions, etc.) each hold sensitive privacy data. Under this framework, through the federated learning mechanism, participants can conduct collaborative training without leaking their own data. The training data does not leave the local area, and only the encrypted model gradient is shared. The smart contract manages the registration and task allocation of participants on the blockchain, randomly selects some participants as committee members, and others as training clients. After each round of training, the identities are rearranged to ensure fairness and randomness. The training client performs model training locally, and homomorphically encrypts the model gradient obtained through training, and uploads it to the blockchain system through the smart contract. The encryption process allows the ciphertext to be operated to ensure the security of the gradient when it is processed on the chain. The committee members test and score the encrypted gradients on the chain, and the smart contract counts and sorts the scores, and selects clients with high scores as members of the next round of committees to ensure the quality of the model; after scoring, the 10% gradients with the lowest scores are discarded, and the top 90% gradients are aggregated through weighted average to update the global model; the updated global model is distributed to all clients through smart contracts for the next round of training, and newly joined clients automatically obtain the latest global model to participate in training, ensuring the openness and scalability of the system.

[0065] In actual application scenarios, different hospitals can jointly train disease prediction models to improve diagnostic accuracy without sharing specific patient data, or banks can cooperate to train anti-fraud models to improve financial security. Through the above mechanism, the security and privacy protection of the data of each participant are ensured, while efficient collaborative training and model updates are achieved, the model's generalization ability for unknown data is improved, and the data sharing and utilization needs in actual application scenarios are met.

[0066] In the method of this embodiment, it includes training client, committee members and blockchain system. Specifically:

[0067] 1) Training client: The training client hopes to participate in federated learning training without leaking its own private data. Each training client performs model training locally, and after homomorphic encryption of the model gradient obtained from the training, uploads it to the blockchain system through a smart contract;

[0068] The training client relies on smart contracts to manage identity allocation and global model updates to ensure the security and effectiveness of the training process;

[0069] During the federated learning training process, new clients can join at any time. The smart contract will assign them as training clients by default and distribute the latest global model for their training. New clients can seamlessly access and participate in collaborative training without affecting the stability of the existing system.

[0070] 2) Committee members: The smart contract selects some clients as committee members, who are responsible for testing and scoring the encrypted gradients on the chain. Committee members abide by the relevant interaction protocols, score the encrypted gradients fairly, and select highly scored encrypted gradients for global model updates.

[0071] 3) Blockchain system: Smart contracts manage the registration, identity assignment, and gradient scoring sorting of participants on the blockchain system. The blockchain system stores and processes encrypted gradients and uses homomorphic encryption algorithms to ensure the privacy and security of gradient operations. Smart contracts aggregate the top 90% high-scoring gradients, update the global model, and distribute it to all clients.

[0072] Combine the following Figure 1 The method of this embodiment is described in detail, wherein (1)-(9) represent different behaviors or operations respectively, (1) indicates that the key management system distributes key pairs; (2) indicates that the global model is obtained; (3) indicates that the training client performs local training; (4) indicates that the local model gradient is encrypted; (5) indicates that the encrypted gradient is uploaded to the blockchain system; (6) indicates that the committee members obtain the encrypted gradient; (7) indicates that the committee members score the encrypted gradient; (8) indicates that the committee members upload the scoring results to the blockchain system; (9) indicates that the smart contract controls the aggregation of the encrypted gradient on the chain, and the blockchain system is divided into multiple shards (shard 1-shard 9) to form a sharded blockchain system.

[0073] 1) Blockchain Sharding Technology:

[0074] Blockchain sharding is a way to improve the scalability of blockchain. It can divide the entire blockchain network into several segments (or shards). Each network shard can operate independently and be responsible for a part of the transaction. Each network shard only has its own transaction records and status information, and does not need to communicate directly with other network shards. Sharding can effectively transfer the load of a blockchain system to several network shards, thereby increasing the throughput and management capabilities of the website.

[0075] In this embodiment, a complete account book is divided into multiple independent sharded account books, each of which runs as an independent group and can handle specific transactions and data, thereby simulating the effect of blockchain sharding. This design allows each shard to be optimized and adjusted without affecting other shards to meet the needs of different application scenarios. A P2P communication mechanism is adopted, with the closest common ancestor of the two shards as the coordination node. When a transaction needs to be executed across different shards, the relevant transaction data will be transmitted through the P2P network between groups. At the same time, smart contracts are executed between shards to ensure the consistency and integrity of the transaction. Such a design not only ensures the security of the transaction, but also maintains the overall consistency of the system, so that cross-shard transactions can be executed smoothly and safely. In the process of cross-shard communication, in order to ensure the consistency and security of the data, all messages transmitted through the P2P network are serialized.

[0076] At the same time, the shard internally supports the use of Practical Byzantine Fault Tolerance (PBF) and Raft consensus protocols. This is because the PBFT protocol can tolerate up to one-third of malicious nodes and is suitable for scenarios with high security requirements. The Raft consensus protocol is popular for its simplicity and easy understanding. It ensures data consistency of all nodes through an election mechanism. It is suitable for small or medium-sized networks that need to reach consensus quickly, without the problems of consuming a lot of computing resources and energy and potential centralization risks like PoW (Proof of Work) and PoS (Proof of Stake). It is more in line with the requirements of sustainable development and frameworks. Studies have shown that the PBFT protocol and the Raft consensus protocol can ensure fast transaction confirmation time and low latency while maintaining high throughput and stability of the system, which is crucial for the data security circulation framework.

[0077] Blockchain sharding technology plays a key role in the data security circulation framework. Combined with smart contracts and PBFT and Raft consensus protocols, it significantly improves the scalability and transaction processing capabilities of the blockchain network. By dividing the network into multiple shards, each shard processes transactions and data independently, effectively increasing the concurrent processing capabilities of the entire system. This approach not only improves throughput, but also reduces the load on a single node, making the framework more scalable.

[0078] 2) Client registration and initialization:

[0079] Each participant (such as medical institutions, financial institutions, etc.) registers as a client in the on-chain and off-chain collaborative secure computing framework, and stores its own digital signature in the blockchain system through a smart contract for identity confirmation and authentication in subsequent steps; receives the key pair generated by the key management system for subsequent data encryption and decryption operations, and obtains the initial global model.

[0080] The key pair generation process is as follows:

[0081] Choose two prime numbers p and q, calculate the product n=pq and the least common multiple ,in Solve the function for the least common multiple; choose an integer g, g is the modulus is an integer that is relatively prime to n and satisfies There exists, among which, the function Defined as: , It is a mathematical operation symbol, referring to the modulus operator.

[0082] At this time, the public key is , the private key is .

[0083] 3) Smart contract selection committee members:

[0084] When the number of clients reaches the expected number before the first round of model training, the smart contract starts and randomly selects some clients as committee members for the first round of model training, and the rest as training clients. Committee members are responsible for scoring and verifying the training results of the training clients to ensure the accuracy and fairness of the model update.

[0085] The identities of committee members and training clients are rearranged by the smart contract after each round of model training. The client corresponding to the gradient is selected as the committee member for the next round of federated learning based on the committee score, ensuring the dynamics and randomness of the system.

[0086] Specifically, the smart contract weights the scoring results of the encrypted gradients of the training client in this round and the previous round to elect the committee members for the next round of model training, where the weights for:

[0087] ;

[0088] in, is the scoring result of the encrypted gradient of the training client i in this round, is the scoring result of the encrypted gradient of the previous round of training client i.

[0089] This weighting strategy is designed to ensure that the election of committee members reflects both recent participation contributions and ongoing effective participation.

[0090] 4) New client joins:

[0091] During the model training process, new clients can join at any time. Newly joined clients will be automatically set as training clients by default, and obtain the latest global model through smart contracts for local training, ensuring the openness and scalability of the system and being able to adapt to ever-changing actual needs.

[0092] 5) Local model training and gradient encryption upload:

[0093] The training client uses its own data to train the model locally and generates model gradients. At the same time, in order to protect data privacy, the model gradients are encrypted using a homomorphic encryption algorithm, and the encrypted gradients are uploaded to the blockchain system through smart contracts to ensure the security of the gradients during transmission and storage.

[0094] During each model training, the training client obtains the latest global model from the blockchain system, decrypts it and uses it for a new round of local training:

[0095] ;

[0096] in, is the global model parameter; is the global model parameter in the encrypted state, , is the private key, is the public key.

[0097] The decrypted global model parameters are used for a new round of local training. A batch of samples are randomly selected from the local data set, and the loss function is calculated using the Multilayer Perceptron (MLP) model. Then, the model parameters are updated through the Stochastic Gradient Descent (SGD) algorithm to minimize the loss function.

[0098] When the training client is training locally, use the dataset used by the training client in local training Compute the gradient of the loss function with respect to the model parameters:

[0099] ;

[0100] Where i is the training client number; is the global model parameter; Given the global model parameters The loss function under is the loss function gradient.

[0101] According to the aggregation gradient And the learning rate Update the local model:

[0102] ;

[0103] in, The local model parameters for the t+1th round of model training; is the global model parameter for the tth round of model training, which is the .

[0104] Since the homomorphic encryption algorithm does not support multiplication and subtraction operations in the ciphertext state, the learning rate is multiplied and negative before the gradient is encrypted, and then the model gradient is encrypted and uploaded to the blockchain system:

[0105] ;

[0106] in, is the data in ciphertext state; n is the public key, which is distributed by the key management system; The random number selected by training client i during homomorphic encryption satisfies and .

[0107] As a result, each training client can independently perform model training without sharing the original data, thereby protecting data privacy.

[0108] 6) Encryption gradient test scoring and ranking:

[0109] The encrypted gradient data uploaded to the blockchain system will be automatically monitored by the smart contract. When the number of encrypted gradients uploaded to the chain reaches the set threshold, the scoring mechanism will be triggered;

[0110] Committee members obtain encryption gradients through smart contracts, score the encryption gradients, and upload the scoring results to the blockchain system;

[0111] The smart contract collects the scoring results and sorts them from large to small. Based on the scoring results, the top K% encrypted gradients (for example, 90%) with high scores are selected for updating the global model, and the k% encrypted gradients with low scores (for example, 10%) are discarded to improve the overall quality of the model.

[0112] 7) Global model update and synchronization:

[0113] The smart contract performs weighted aggregation on the top 90% high-scoring encrypted gradients and updates the global model. The updated global model is distributed to all clients through the smart contract for the next round of local training, ensuring that the model is gradually optimized during continuous iterations and improving its generalization capabilities for unknown data.

[0114] It relies on homomorphic encryption algorithms to support homomorphic addition and multiplication operations under ciphertext. In this process, the gradient weighted average algorithm is used to aggregate the encrypted gradients to update the global model.

[0115] Specifically:

[0116] First, according to the dataset used by each training client in local training Calculate the weight of each training client :

[0117] ;

[0118] Among them, i is the training client number; J is the number of training clients participating in the aggregation; j is the cumulative parameter used when calculating the total data set size, is the dataset of the jth training client.

[0119] Next, using the scalar multiplication homomorphic property of the homomorphic encryption algorithm, according to the weight Encrypted gradients for each training client Weighted, get weighted encrypted gradient :

[0120] .

[0121] Then, the weighted encrypted gradients of all training clients are aggregated into the total encrypted gradient through homomorphic addition :

[0122] .

[0123] Finally, using the learning rate Update global model parameters :

[0124] .

[0125] in, The data is in ciphertext state; is the global model parameter of the t-th model training in the ciphertext state; It is the global model parameter of the t+1th model training in the ciphertext state, that is, the updated global model parameter.

[0126] After aggregation is completed, the training client calls the latest global model in the smart contract to perform the next round of local training until the scheduled training rounds are completed.

[0127] It should be noted that all data is obtained in compliance with laws and regulations and user consent, and the data is used legally.

[0128] Example 2

[0129] Based on the on-chain and off-chain collaborative secure computing method based on sharded blockchain described in Example 1, this embodiment provides an on-chain and off-chain collaborative secure computing method based on sharded blockchain, which is applied to a client and includes:

[0130] Obtain the key pair and global model, and select the client as the committee member, and the rest of the clients as training clients;

[0131] The training client performs local training based on the global model, generates model gradients, encrypts the model gradients based on the key pair, and uploads the encrypted gradients to the blockchain system;

[0132] The committee members obtain the encrypted gradients and perform scoring, and upload the scoring results to the blockchain system, which is divided into multiple shards, so that the sharded blockchain system updates the global model and selects committee members for the next round of model training according to the scoring results.

[0133] Example 3

[0134] Based on the on-chain and off-chain collaborative secure computing method based on sharded blockchain described in Example 1, this embodiment provides an on-chain and off-chain collaborative secure computing method based on sharded blockchain, which is applied to a blockchain system, including:

[0135] Send the global model to the client, select committee members from the client, and use the remaining clients as training clients; so that the training client performs local training according to the global model, generates model gradients, and encrypts the model gradients according to the obtained key pairs, and uploads the obtained encrypted gradients to the blockchain system through smart contracts. At the same time, the committee members obtain the encrypted gradients and perform scoring, and upload the scoring results to the blockchain system;

[0136] The blockchain system is divided into multiple shards. The sharded blockchain system updates the global model and selects committee members for the next round of model training based on the scoring results.

[0137] Example 4

[0138] This embodiment provides an on-chain and off-chain collaborative secure computing system based on a sharded blockchain, including:

[0139] The acquisition module is configured to acquire the key pair and the global model, and the selected clients serve as committee members, and the remaining clients serve as training clients;

[0140] The training encryption module is configured to train the client to perform local training according to the global model, generate model gradients, encrypt the model gradients according to the key pair, and upload the obtained encrypted gradients to the blockchain system;

[0141] The scoring module is configured to obtain encrypted gradients and score committee members, and upload the scoring results to the blockchain system, which is divided into multiple shards, so that the sharded blockchain system updates the global model according to the scoring results and selects committee members for the next round of model training.

[0142] Example 5

[0143] This embodiment provides an on-chain and off-chain collaborative secure computing system based on a sharded blockchain, including:

[0144] The sending module is configured to send the global model to the client, select committee members from the client, and use the remaining clients as training clients; so that the training client performs local training according to the global model, generates model gradients, and encrypts the model gradients according to the obtained key pairs, and uploads the obtained encrypted gradients to the blockchain system through the smart contract, and at the same time enables the committee members to obtain the encrypted gradients and perform scoring, and upload the scoring results to the blockchain system;

[0145] The update module is configured to divide the blockchain system into multiple shards. The sharded blockchain system updates the global model and selects committee members for the next round of model training based on the scoring results.

[0146] It should be noted that embodiments 2-5 correspond to the steps described in embodiment 1, and are the same as the examples and application scenarios implemented by the corresponding steps, but are not limited to the contents disclosed in the above embodiment 1. It should be noted that the above method or module can also be executed in a computer system such as a set of computer executable instructions as part of a system.

[0147] In further embodiments, there is also provided:

[0148] An electronic device includes a memory and a processor, and computer instructions stored in the memory and executed on the processor, wherein when the computer instructions are executed by the processor, the method described in Embodiment 1 or Embodiment 2 or Embodiment 3 is performed. For the sake of brevity, it will not be described in detail here.

[0149] It should be understood that in this embodiment, the processor may be a central processing unit CPU, and the processor may also be other general-purpose processors, digital signal processors DSP, application-specific integrated circuits ASIC, off-the-shelf programmable gate arrays FPGA or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0150] The memory may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory. For example, the memory may also store information about the device type.

[0151] A computer-readable storage medium is used to store computer instructions. When the computer instructions are executed by a processor, the method described in Example 1 or Example 2 or Example 3 is completed.

[0152] The method in Example 1 or Example 2 and Example 3 can be directly embodied as a hardware processor, or a combination of hardware and software modules in the processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware. To avoid repetition, it will not be described in detail here.

[0153] A computer program product includes a computer program, and when the computer program is executed by a processor, the method described in Example 1 or Example 2 or Example 3 is implemented.

[0154] The present invention also provides at least one computer program product tangibly stored on a non-transitory computer-readable storage medium. The computer program product includes computer executable instructions, such as instructions included in a program module, which are executed in a device on a real or virtual processor of the target to perform the process / method as described above. Typically, program modules include routines, programs, libraries, objects, classes, components, data structures, etc. that perform specific tasks or implement specific abstract data types. In various embodiments, the functions of program modules can be combined or divided between program modules as needed. Machine executable instructions for program modules can be executed in local or distributed devices. In distributed devices, program modules can be located in local and remote storage media.

[0155] The computer program code for implementing the method of the present invention can be written in one or more programming languages. These computer program codes can be provided to the processor of a general-purpose computer, a special-purpose computer or other programmable data processing device, so that the program code, when executed by the computer or other programmable data processing device, causes the function / operation specified in the flow chart and / or block diagram to be implemented. The program code can be executed completely on a computer, partially on a computer, as an independent software package, partially on a computer and partially on a remote computer or completely on a remote computer or server.

[0156] In the context of the present invention, computer program codes or related data may be carried by any appropriate carrier to enable a device, apparatus or processor to perform the various processes and operations described above. Examples of carriers include signals, computer readable media, etc. Examples of signals may include electrical, optical, radio, acoustic or other forms of propagation signals, such as carrier waves, infrared signals, etc.

[0157] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with this embodiment can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0158] Although the above describes the specific implementation mode of the present invention in conjunction with the accompanying drawings, it is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art on the basis of the technical solution of the present invention without creative work are still within the scope of protection of the present invention.

Claims

1. A collaborative secure computing method between on-chain and off-chain based on sharded blockchain, characterized in that: Applied to the client, including: Obtain the key pair and global model, and select the client as the committee member, and the rest of the clients as training clients; The training client performs local training based on the global model, generates model gradients, encrypts the model gradients based on the key pair, and uploads the encrypted gradients to the blockchain system; The committee members obtain the encrypted gradients and perform scoring, and upload the scoring results to the blockchain system, which is divided into multiple shards, so that the sharded blockchain system updates the global model and selects committee members for the next round of model training according to the scoring results; After the training client performs model training locally, it homomorphically encrypts the model gradient obtained through training, uploads it to the blockchain system through a smart contract, and updates the global model through weighted average aggregation based on the scoring results; the blockchain system stores and processes encrypted gradients, and uses homomorphic encryption algorithms to ensure the privacy and security of gradient operations; The process of selecting the committee members for the next round of model training includes: weighting the scoring results of the encrypted gradients of the training client in the current round and the previous round to elect the committee members for the next round of model training, where the weighting of the scoring results for: ; in, is the scoring result of the encrypted gradient of the training client i in this round, is the scoring result of the encrypted gradient of the previous round of training client i.

2. A collaborative secure computing method between on-chain and off-chain based on sharded blockchain, characterized in that: Applied to blockchain systems, including: Send the global model to the client, select committee members from the client, and use the remaining clients as training clients; so that the training client performs local training according to the global model, generates model gradients, and encrypts the model gradients according to the obtained key pairs, and uploads the obtained encrypted gradients to the blockchain system through smart contracts. At the same time, the committee members obtain the encrypted gradients and perform scoring, and upload the scoring results to the blockchain system; Divide the blockchain system into multiple shards. The sharded blockchain system updates the global model and selects committee members for the next round of model training based on the scoring results. After the training client performs model training locally, it homomorphically encrypts the model gradient obtained through training, uploads it to the blockchain system through a smart contract, and updates the global model through weighted average aggregation based on the scoring results; the blockchain system stores and processes encrypted gradients, and uses homomorphic encryption algorithms to ensure the privacy and security of gradient operations; The process of selecting the committee members for the next round of model training includes: weighting the scoring results of the encrypted gradients of the training client in the current round and the previous round to elect the committee members for the next round of model training, where the weighting of the scoring results for: ; in, is the scoring result of the encrypted gradient of the training client i in this round, is the scoring result of the encrypted gradient of the previous round of training client i.

3. A method for collaborative secure computing on and off the chain based on a sharded blockchain as claimed in claim 1 or 2, characterized in that: When training locally, use the dataset used by the training client i in local training Calculate the model gradient: ; According to the aggregation gradient and learning rate Update the local model: ; The encrypted gradient obtained after encrypting the model gradient is: ; in, is the global model parameter; Given the global model parameters The loss function under is the loss function The gradient of The local model parameters for the t+1th round of model training; is the global model parameter of the tth round of model training; The data is in ciphertext state; is the private key, is the public key; is the random number selected by the training client i when performing homomorphic encryption; g is an integer.

4. A method for collaborative secure computing on and off the chain based on a sharded blockchain as claimed in claim 1 or 2, characterized in that: Get the global model and decrypt it for local training: ;in, is the global model parameter; is the global model parameter in the encrypted state, , is the private key, is the public key.

5. A method for collaborative secure computing on and off the chain based on a sharded blockchain as claimed in claim 1 or 2, characterized in that: Sort the scoring results from large to small, select the first K% encrypted gradients for updating the global model and selecting committee members for the next round of model training, and discard the last k% encrypted gradients.

6. A method for collaborative secure computing on and off the chain based on a sharded blockchain as claimed in claim 1 or 2, characterized in that: The process of updating the global model includes: According to the dataset used by the training client i in local training Calculate the weight of training client i : ; According to weight Encrypted gradients for training client i Weighted, get weighted encrypted gradient : ; Aggregate the weighted encrypted gradients of all training clients into the total encrypted gradient through homomorphic addition : ; Using learning rate Update the global model: ; in, is the data in ciphertext state; J is the number of training clients; j is the cumulative parameter when calculating the total data set, is the dataset of the jth training client; is the private key; is the public key; Aggregate gradients for all training clients; is the global model parameter; is the global model parameter of the t-th model training in the ciphertext state; is the global model parameter of the t+1th model training in the encrypted state.

7. A method for collaborative secure computing on and off the chain based on a sharded blockchain as claimed in claim 1 or 2, characterized in that: If you add a new client at any time during the model training process, the new client will automatically default to the training client and perform local training by obtaining the latest global model.

8. A chain-based and off-chain collaborative secure computing system based on sharded blockchain, characterized in that: include: The acquisition module is configured to acquire the key pair and the global model, and the selected clients serve as committee members, and the remaining clients serve as training clients; The training encryption module is configured to train the client to perform local training according to the global model, generate model gradients, encrypt the model gradients according to the key pair, and upload the obtained encrypted gradients to the blockchain system; A scoring module is configured to obtain encrypted gradients for committee members and perform scoring, and upload the scoring results to a blockchain system, wherein the blockchain system is divided into a plurality of shards, so that the sharded blockchain system updates the global model and selects committee members for the next round of model training according to the scoring results; After the training client performs model training locally, it homomorphically encrypts the model gradient obtained through training, uploads it to the blockchain system through a smart contract, and updates the global model through weighted average aggregation based on the scoring results; The blockchain system stores and processes encrypted gradients, using homomorphic encryption algorithms to ensure the privacy and security of gradient operations; The process of selecting the committee members for the next round of model training includes: weighting the scoring results of the encrypted gradients of the training client in the current round and the previous round to elect the committee members for the next round of model training, where the weighting of the scoring results for: ; in, is the scoring result of the encrypted gradient of the training client i in this round, is the scoring result of the encrypted gradient of the previous round of training client i.

9. A chain-based and off-chain collaborative secure computing system based on sharded blockchain, characterized in that: include: The sending module is configured to send the global model to the client, select committee members from the client, and use the remaining clients as training clients; The training client performs local training based on the global model, generates model gradients, encrypts the model gradients based on the obtained key pair, and uploads the encrypted gradients to the blockchain system through the smart contract. At the same time, the committee members obtain the encrypted gradients and perform scoring, and upload the scoring results to the blockchain system. An update module is configured to divide the blockchain system into multiple shards, and the sharded blockchain system updates the global model and selects committee members for the next round of model training according to the scoring results; After the training client performs model training locally, it homomorphically encrypts the model gradient obtained through training, uploads it to the blockchain system through a smart contract, and updates the global model through weighted average aggregation based on the scoring results; The blockchain system stores and processes encrypted gradients, using homomorphic encryption algorithms to ensure the privacy and security of gradient operations; The process of selecting the committee members for the next round of model training includes: weighting the scoring results of the encrypted gradients of the training client in the current round and the previous round to elect the committee members for the next round of model training, where the weighting of the scoring results for: ; in, is the scoring result of the encrypted gradient of the training client i in this round, is the scoring result of the encrypted gradient of the previous round of training client i.