Paul Oamen

Zero Knowledge Machine Learning: A Path to Privacy-Preserving, Scalable Innovation in DeFi

in review

October 29, 2024 (3m ago)69 views

1.0. Introduction

Decentralized Finance (DeFi) and blockchain-powered applications have transformed financial interactions, promoting transparency, fairness, and user control over assets. However, unlike centralized platforms—where everything from loans to shopping is carefully tailored to individual preferences—decentralized systems can feel impersonal. This difference goes beyond surface-level aesthetics; it stems from contrasting data practices. Centralized platforms use extensive personal data to create customized, user-centered experiences, while DeFi and blockchain systems prioritize privacy and anonymity. This raises a core question: how can decentralized systems achieve that same level of personalization without compromising user privacy?

Consider Upstart, a leading online lending platform that issued over $4.6 billion in loans in 2023 [1]. By leveraging advanced data analytics, Upstart personalizes loan options based on each user’s financial profile, offering tailored interest rates, rapid approvals, and credit-building support. This data-driven approach not only enhances accessibility but also creates a seamless, user-centered experience that adapts to individual needs. In contrast, AAVE—one of the foremost decentralized lending platforms—manages billions in loans but relies on an overcollateralized model to maintain security in its trustless, anonymous environment [2]. For instance, borrowers may need to provide $10,000 in collateral to secure a $7,000 loan. While this model protects the protocol against default risks, it also restricts accessibility by demanding high collateral, which can deter users looking for flexible and affordable loan options.

This distinction highlights a broader trade-off that extends beyond lending and affects the DeFi ecosystem as a whole. Privacy and security in decentralized finance often come at the expense of personalization and user experience. Meanwhile, as artificial intelligence (AI) continues to transform digital interactions, user expectations are rising. Centralized platforms increasingly use AI to create smooth, intuitive, and highly tailored experiences, setting standards that decentralized systems struggle to match without similar adaptive capabilities.

For DeFi platforms, this raises a crucial challenge: how can they deliver the same personalized, responsive services without compromising on their core values of privacy and user control? Fortunately, advancements in zero-knowledge proofs and zero-knowledge machine learning may hold the key. By enabling intelligent, user-centric features that protect privacy, these innovations offer a promising path forward—one that allows DeFi to bridge the gap between secure decentralization and the high-quality user experience demanded by today’s market.

2.0. What is Zero Knowledge?

Zero-knowledge is a cybersecurity concept dating back to the 1980s that has gained new momentum in modern systems, thanks to today’s advanced computational resources and the development of technologies to support its complex applications. Zero-knowledge technology enables the verification of information without disclosing the information itself. In other words, even though we have "no knowledge" of an actual data, its compliance with specific criteria can still be verified.

This approach has significant potential in the decentralized landscape, offering a promising solution to the growing challenge of balancing data privacy with user experience. Imagine a girl called Eunice wants to take out a loan from AAVE.

Helping Eunice Take a Loan Using Zero-Knowledge Proofs

To help Eunice take a loan on AAVE using zero-knowledge technology, we need to design a solution that allows her to prove her creditworthiness without disclosing sensitive information about her assets or financial history. This approach leverages zero-knowledge proofs, specifically zk-SNARKs (Zero-Knowledge Succinct Non-Interactive Arguments of Knowledge), which enable private verification of data.

1. Define Criteria for Loan Approval in AAVE Terms

For AAVE, loans require overcollateralization to secure funds in a trustless, decentralized system. To streamline Eunice's experience while ensuring AAVE’s security, a zero-knowledge proof can confirm that she meets the collateral requirements without revealing specific asset details. In this context, let C represent Eunice’s collateral amount, L the loan amount she seeks, and r_c the required collateral ratio. For example, if AAVE requires a ratio of , Eunice would need $1.50 in collateral for every $1 loan. Thus, the core requirement can be represented as:

2. Constructing the Zero-Knowledge Circuit for zk-SNARKs

To prove the relationship in zero-knowledge, we construct a zk-SNARK circuit that computes the inequality and outputs true or false based on Eunice’s private inputs. The zk-SNARK proof system will create a cryptographic proof, π, that AAVE can verify without ever seeing C or L directly.

The zero-knowledge circuit for this inequality requires several steps. First, a multiplication gate is set up to calculate the required collateral, which we’ll refer to as , through the relation:

Next, to handle the inequality , zk-SNARK circuits, which operate on arithmetic rather than direct inequalities, reformulate the inequality into a circuit-compatible form:

To make this compatible with zk-SNARKs, we introduce an auxiliary variable z and require that:

This setup ensures that if C meets or exceeds , then z is real, validating the proof. If C falls short of , no real z can satisfy this equation, causing the proof to fail. Consequently, the zk-SNARK circuit consists of the two relations:

which together allow Eunice to produce a valid proof only if her collateral meets the required threshold.

3. Proving and Verifying with zk-SNARKs

In the proving phase, Eunice generates a zk-SNARK proof, π, using her private witness values: her collateral C, loan amount L, and the auxiliary variable z. The zk-SNARK system requires a one-time trusted setup to create common reference parameters (CRS), which include the public parameters for both verification and proving keys. Using these, Eunice encodes her values C, L, and z as polynomials, computes the polynomial commitments, and generates the proof π that confirms the validity of the circuit without disclosing C or L.

In the verification phase, AAVE’s smart contract, which includes a zk-SNARK verifier function, checks if π is valid. The verifier function takes π and the public collateral ratio as inputs, performing a verification check. This is achieved through a pairing equation (for instance, in Groth16, a pairing check equation on elliptic curves):

If the pairing equation holds, AAVE’s protocol accepts the proof and grants Eunice the loan; otherwise, the request is denied due to insufficient collateral.

We can extend these concepts to machine learning, creating privacy-preserving systems that drive breakthroughs in AI solutions on Web3 platforms. This fusion of zero-knowledge principles with machine learning has given rise to a new research field: Zero-Knowledge Machine Learning (ZKML).

3.0. Zero-Knowledge Machine Learning (ZKML)

Zero-Knowledge Machine Learning (ZKML) combines zero-knowledge proofs (ZKPs) with machine learning (ML) to enable privacy-preserving data processing. ZKML allows ML models to execute computations while keeping both data and model parameters hidden, verifying results without exposing sensitive information—a critical capability for privacy-sensitive applications like biometric authentication, secure data markets, and DeFi. Emerging research projects such as PSE, ZKML System, EKML, and Worldcoin aim to integrate ZK principles with popular ML frameworks like TensorFlow and Keras.

ZKML envisions a future where decentralized, blockchain-based solutions deliver seamless user experiences comparable to or better than Web2, appealing to users who value satisfaction over technical intricacies. The privacy-first principles of ZKML can be extended to all decentralized domains where data privacy is essential.

Here are some tweets from notable builders in the ZKML space:

Applying ZKML to AAVE

Returning to the AAVE example, ZKML could enable personalized offerings, such as customized interest rates, loan limits, or even allowing some level of under-collateralization based on Eunice’s transaction history. With blockchain’s data interoperability, AAVE’s decision wouldn’t be limited to her interactions within AAVE alone but could also leverage data from other network applications, depending on the model’s training parameters.

The Deep Network: Eunice’s ZKML-Powered Loan on AAVE

Eunice is about to borrow on AAVE, leveraging a cutting-edge zero-knowledge machine learning (ZKML) model. Imagine AAVE’s system uses a deep neural network (DNN) with cryptographic layers, allowing Eunice to receive a tailored loan offer while keeping her financial data private.

Building AAVE’s Zero-Knowledge Deep Neural Network

AAVE’s model is a 4-layer deep neural network (DNN) designed to provide advanced inference while maintaining privacy. It comprises an input layer, which encodes Eunice’s financial attributes; two hidden layers that apply transformations through nonlinear activations; and an output layer that generates a risk score for Eunice.

Each layer in this network performs transformations with the formula:

where and represent the weight matrix and bias vector for layer , respectively. The activation functions, and , use ReLU, while is a sigmoid function mapping the output to a probability space.

To guide the model, AAVE minimizes a cost function, , that combines cross-entropy loss and regularization. This is expressed as:

In this equation, denotes the predicted risk probability, represents the actual label (0 for low-risk and 1 for high-risk), and is a regularization term that penalizes large weights for model stability.

Backpropagation with Homomorphic Encryption (HE)

AAVE employs homomorphic encryption (HE) to protect the data used in training. Through HE, gradients can be computed on encrypted weights without revealing . The gradients are calculated as follows:

These gradients are encrypted to ensure that remains accessible only in encoded form. Using gradient descent, AAVE updates the weights with the formula:

where represents the learning rate and denotes the encrypted gradient calculations.

Eunice’s Feature Vector and Encrypted Inference

When Eunice submits her loan request, her wallet encrypts her feature vector, , which includes critical financial data points. These include the collateral-to-loan ratio, represented as , her average account balance, calculated as , where is her balance on day ; and her account’s volatility, expressed as .

These encrypted features form the vector , which is passed through each layer of the DNN.

Step-by-Step Encrypted Inference in Zero-Knowledge

The encrypted inference begins with Eunice’s feature vector , processed by the first hidden layer:

This layer uses a ZK-friendly approximation of ReLU to handle the non-linear activation under encryption. Layer 2 continues the transformation using another ReLU activation:

Here, ReLU is approximated through polynomial functions, such as:

where coefficients are selected to approximate ReLU in the expected value range for , thus allowing for non-linear transformations in an encrypted format.

Finally, the output layer computes Eunice’s risk score :

The sigmoid function maps this score to a probability, reflecting Eunice’s risk level.

Zero-Knowledge Proof (ZKP) of Risk Score

AAVE generates a zk-SNARK proof π, confirming that the encrypted risk score calculation is accurate without revealing the inputs or intermediate values. This proof verifies that was processed correctly through each layer and that the final score is within the valid probability range [0,1].

Calculating Personalized Loan Terms

With Eunice’s risk score , AAVE computes her interest rate, , using a differential equation model. This model captures how risk affects her rate dynamically:

In this equation, is the maximum baseline rate, adjusts risk sensitivity, and accounts for time-dependent decay.

ZK Collateral Verification

To qualify for her loan, Eunice must also prove her collateral C meets the minimum requirement, defined by . This requires that:

Using Pedersen commitments, Eunice commits to V with the equation:

where is a blinding factor. A Bulletproof enables her to prove without revealing or .

Real-Time Monitoring with Differential Privacy

AAVE’s model continuously monitors Eunice’s collateral-to-loan ratio over time, calculated as . Leveraging differential privacy and ZKML, AAVE can detect any dips below a critical threshold and generate alerts if:

Through ZKML, encryption, zk-SNARKs, and Bulletproofs, AAVE provides Eunice with a secure, private, data-driven loan experience, combining confidentiality with compliance in decentralized finance.

4.0. Current Challenges in Zero-Knowledge Machine Learning (ZKML)

The field of zero-knowledge machine learning (ZKML) faces several ongoing challenges, particularly regarding scalability, computational efficiency, model accuracy, and practical deployment. Below are some of the primary challenges, along with mathematical context and examples.

5.0. Conclusion

ZKML is a groundbreaking step toward advancing Web3 and decentralized applications, enabling Web2-level user experiences while preserving privacy. Alongside federated learning and other decentralized AI concepts, ZKML will be crucial in building Decentralized Intelligent Systems (DISs), a foundational element of the digital future. Though still in its infancy with challenges like scalability, latency, verifier efficiency, and security trade-offs, ZKML holds immense potential. With continued innovation, it stands poised to bring privacy, intelligence, and user-centric design to decentralized ecosystems.

6.0. References

[1] Upstart Holdings, Inc. “Upstart Announces Fourth Quarter and Full Year 2023 Results.” Upstart Network, Inc., 13 Feb. 2024, Upstart Investor Relations.

[2] Llama. “AAVE August 2023 Financials.” Llama Reports, Aug. 2023, llama.xyz/reports/aave/august-2023-financials.pdf.

[3] Thaler, Justin (2013). Time-Optimal Interactive Proofs for Circuit Evaluation. Available at IACR.

[4] Xie, Pengtao, Bilenko, Misha, Finley, Tom, Gilad-Bachrach, Ran, Lauter, Kristin, Naehrig, Michael (2014). Crypto-Nets: Neural Networks over Encrypted Data. Available at arXiv.

[5] Dowlin, Nathan, Gilad-Bachrach, Ran, Laine, Kim, Lauter, Kristin, Naehrig, Michael, Wernsing, John (2016). CryptoNets: Applying Neural Networks to Encrypted Data with High Throughput and Accuracy. Available at Microsoft Research.

[6] Ghodsi, Zahra, Gu, Tianyu, Garg, Siddharth (2017). SafetyNets: Verifiable Execution of Deep Neural Networks on an Untrusted Cloud. Available at arXiv.

[7] Mohassel, Payman, Zhang, Yupeng (2017). SecureML: A System for Scalable Privacy-Preserving Machine Learning. Available at IACR.

[8] Liu, Jian, Juuti, Mika, Lu, Yao, Asokan, N. (2017). Oblivious Neural Network Predictions via MiniONN Transformations. Available at IACR.

[9] Lee, Seunghwa, Ko, Hankyung, Kim, Jihye, Oh, Hyunok (2020). vCNN: Verifiable Convolutional Neural Network based on zk-SNARKs. Available at IACR.

[10] Ali, Ramy E., So, Jinhyun, Avestimehr, A. Salman (2020). On Polynomial Approximations for Privacy-Preserving and Verifiable ReLU Networks. Available at arXiv.

[11] Feng, Boyuan, Qin, Lianke, Zhang, Zhenfei, Ding, Yufei, Chu, Shumo (2021). ZEN: An Optimizing Compiler for Verifiable, Zero-Knowledge Neural Network Inferences. Available at IACR.

[12] Liu, Tianyi, Xie, Xiang, Zhang, Yupeng (2021). zkCNN: Zero Knowledge Proofs for Convolutional Neural Network Predictions and Accuracy. Available at IACR.

[13] Weng, Chenkai, Yang, Kang, Xie, Xiang, Katz, Jonathan, Wang, Xiao (2021). Mystique: Efficient Conversions for Zero-Knowledge Proofs with Applications to Machine Learning. Available at IACR.

[14] Weng, Jiasi, Weng, Jian, Tang, Gui, Yang, Anjia, Li, Ming, Liu, Jia-Nan (2022). pvCNN: Privacy-Preserving and Verifiable Convolutional Neural Network Testing. Available at arXiv.

[15] Angel, Sebastian, Blumberg, Andrew J., Ioannidis, Eleftherios, Woods, Jess (2022). Efficient Representation of Numerical Optimization Problems for SNARKs. Available at IACR.

[16] Kang, Daniel, Hashimoto, Tatsunori, Stoica, Ion, Sun, Yi (2022). Scaling up Trustless DNN Inference with Zero-Knowledge Proofs. Available at thashim.github.io.

[17] Wang, Haodi, Hoang, Thang (2022). ezDPS: An Efficient and Zero-Knowledge Machine Learning Inference Pipeline. Available at arXiv.

[18] Modulus Labs. The Cost of Intelligence: Proving Machine Learning Inference with Zero-Knowledge. Available at Google Drive.