Initialize A Shared Cryptography Library In Enclave Starting With BFV
Introduction
In recent discussions with @ryardley while working on #269, we identified a significant issue in the Enclave codebase related to duplication in several areas of BFV
parameter generation, (de)serialization, and (en|de)coding. This duplication is not only inefficient but also makes the codebase more complex and harder to maintain. To address this issue, we propose the development of a shared cryptography library in Enclave, starting with BFV.
Problem Statement
The Enclave codebase suffers from duplication in several areas related to BFV
parameter generation, (de)serialization, and (en|de)coding. This duplication is repeated across different parts of the codebase, from cipher nodes to test helpers. This not only leads to inefficiencies but also makes the codebase more complex and harder to maintain.
Solution Overview
To address the issue of duplication and complexity in the Enclave codebase, we propose the development of a shared cryptography library in Enclave, starting with BFV. The goal of this library is to abstract the complexity away from developers by providing well-documented and consistent APIs. This library will serve as a foundation for future SDK development and will provide a solid base for consolidating all the BFV crypto logic.
Requirements and Features
Some nice-to-have features for the future SDK could include:
- Be a TS/Cargo package: The SDK should be a TypeScript/Cargo package that can be easily integrated into the Enclave codebase.
- Mostly consist of utility functions: The SDK should consist of utility functions that operate on raw bytes, wrapped in custom types. This will help keep the code lean and fast for WASM.
- Support proving circuits: The SDK should support proving circuits, which will enable the creation of proofs.
- Evolve over time: The SDK should evolve over time based on actual needs and requirements.
- Provide general-purpose crypto: The SDK should provide general-purpose crypto for programs, similar to
wasm-crypto
for CRISP, but more generic. - Use a single
cargo
workspace: The SDK should use a singlecargo
workspace (root-level) to simplify project management.
Initial Plan
Given the complexity and scope of the project, we cannot fully predict what kinds of schemes or cryptographic needs we'll encounter, nor how the SDK should eventually behave. Therefore, the plan is to start small by building a minimal library that consolidates all the BFV crypto logic. This will provide a solid foundation for future SDK development and will unblock PR #345.
Benefits
The development of a shared cryptography library in Enclave, starting with BFV, will have several benefits, including:
- Improved code quality: The library will provide a well-documented and consistent API, which will improve code quality and reduce duplication.
- Simplified maintenance: The library will simplify maintenance by providing a single point of truth for all BFV crypto logic.
- Increased efficiency: The library will increase efficiency by reducing duplication and improving code quality.
- Better scalability: The library will provide a solid foundation for future SDK development, which will enable better scalability and flexibility.
Conclusion
In conclusion, the development of a shared library in Enclave, starting with BFV, is a crucial step towards improving code quality, simplifying maintenance, increasing efficiency, and enabling better scalability. By starting small and building a minimal library that consolidates all the BFV crypto logic, we can provide a solid foundation for future SDK development and unblock PR #345.
Future Work
Some future work that could be considered includes:
- Adding support for other cryptographic schemes: Once the BFV crypto logic is consolidated, we can add support for other cryptographic schemes, such as FHE or LWE.
- Improving the API: We can improve the API by adding more features, such as support for proving circuits or general-purpose crypto.
- Enhancing the library: We can enhance the library by adding more functionality, such as support for multiple programming languages or improved performance.
Roadmap
The roadmap for this project will be as follows:
- Phase 1: Build a minimal library that consolidates all the BFV crypto logic.
- Phase 2: Add support for other cryptographic schemes, such as FHE or LWE.
- Phase 3: Improve the API by adding more features, such as support for proving circuits or general-purpose crypto.
- Phase 4: Enhance the library by adding more functionality, such as support for multiple programming languages or improved performance.
Conclusion
Introduction
In our previous article, we discussed the importance of developing a shared cryptography library in Enclave, starting with BFV. In this article, we will answer some frequently asked questions (FAQs) related to this project.
Q: What is the purpose of developing a shared cryptography library in Enclave?
A: The purpose of developing a shared cryptography library in Enclave is to abstract the complexity away from developers by providing well-documented and consistent APIs. This library will serve as a foundation for future SDK development and will provide a solid base for consolidating all the BFV crypto logic.
Q: Why is it necessary to develop a shared cryptography library in Enclave?
A: It is necessary to develop a shared cryptography library in Enclave because the current codebase suffers from duplication in several areas related to BFV
parameter generation, (de)serialization, and (en|de)coding. This duplication is repeated across different parts of the codebase, from cipher nodes to test helpers. This not only leads to inefficiencies but also makes the codebase more complex and harder to maintain.
Q: What are the benefits of developing a shared cryptography library in Enclave?
A: The benefits of developing a shared cryptography library in Enclave include:
- Improved code quality: The library will provide a well-documented and consistent API, which will improve code quality and reduce duplication.
- Simplified maintenance: The library will simplify maintenance by providing a single point of truth for all BFV crypto logic.
- Increased efficiency: The library will increase efficiency by reducing duplication and improving code quality.
- Better scalability: The library will provide a solid foundation for future SDK development, which will enable better scalability and flexibility.
Q: What is the initial plan for developing the shared cryptography library in Enclave?
A: The initial plan is to start small by building a minimal library that consolidates all the BFV crypto logic. This will provide a solid foundation for future SDK development and will unblock PR #345.
Q: What are the future plans for the shared cryptography library in Enclave?
A: Some future plans for the shared cryptography library in Enclave include:
- Adding support for other cryptographic schemes: Once the BFV crypto logic is consolidated, we can add support for other cryptographic schemes, such as FHE or LWE.
- Improving the API: We can improve the API by adding more features, such as support for proving circuits or general-purpose crypto.
- Enhancing the library: We can enhance the library by adding more functionality, such as support for multiple programming languages or improved performance.
Q: How will the shared cryptography library in Enclave be maintained?
A: The shared cryptography library in Enclave will be maintained by a team of developers who will be responsible for updating the library, fixing bugs, and adding new features.
Q: How can I contribute to the shared cryptography library in Enclave?
A: If you are interested in contributing to the shared cryptography library in Enclave, please reach out to the development team. We welcome contributions from the community and are happy to work with you to improve the library.
Q: What is the timeline for developing the cryptography library in Enclave?
A: The timeline for developing the shared cryptography library in Enclave is as follows:
- Phase 1: Build a minimal library that consolidates all the BFV crypto logic.
- Phase 2: Add support for other cryptographic schemes, such as FHE or LWE.
- Phase 3: Improve the API by adding more features, such as support for proving circuits or general-purpose crypto.
- Phase 4: Enhance the library by adding more functionality, such as support for multiple programming languages or improved performance.
Conclusion
In conclusion, the development of a shared cryptography library in Enclave, starting with BFV, is a crucial step towards improving code quality, simplifying maintenance, increasing efficiency, and enabling better scalability. By starting small and building a minimal library that consolidates all the BFV crypto logic, we can provide a solid foundation for future SDK development and unblock PR #345.