Technical deep Dive
Server and Encryption
Overview
The Python files implement a Pedersen Commitment scheme for privacy-preserving encrypted values and a Flask web application to facilitate user interaction with the model training process. This includes functionalities for file uploads, model training, and encrypted data handling.
1. Pedersen Commitment Implementation
Imports
The
os
module is used for file handling and generating random bytes.The
sys
module allows interaction with the Python interpreter, particularly for command-line arguments.The
cryptography
library provides the necessary cryptographic primitives, specifically for RSA key generation.
Prime Generation
This function generates a large prime number using RSA. The
bit_length
parameter specifies the size of the prime.It leverages RSA's private key generation to extract the prime ppp.
Pedersen Commitment Class
Initialization: The constructor initializes the Pedersen commitment scheme:
Generates two large primes ppp and qqq.
Initializes the generator ggg and a secret sss from random bytes, ensuring ggg is less than qqq.
Computes hhh using ggg raised to the power of sss modulo qqq.
Commitment Methods
Commit: This method takes a value xxx and commits it using a random value rrr:
The commitment ccc is computed using gxg^xgx and hrh^rhr, both modulo qqq.
Returns the commitment and the random value rrr.
Verify: Validates a commitment against the original value and randomness, ensuring that the provided ccc matches the expected computation.
Add Commitments: Allows the addition of two commitments, crucial for aggregating multiple encrypted values.
Utility Functions
Encrypt Cost: Takes a cost as input, commits it using the Pedersen scheme, and prints the encrypted value. It returns the commitment and the random value.
Aggregate Commitments: Iterates through a list of commitments, adding them together to form a single aggregated commitment.
Flask Web Application
Flask Setup
Initializes a Flask application and enables CORS (Cross-Origin Resource Sharing) to allow requests from other origins.
File Upload Functions
File Validation: These utility functions check if uploaded files have the correct extensions (CSV for datasets and PKL/PY for models).
Routes
Index Route: Renders the main page of the application.
Model Trainer Route: Handles dataset uploads. It checks if the uploaded file is valid, saves it to the specified directory, and redirects to the index page.
Model Upload Route: Accepts model files via JSON data in the request body, saves them, and confirms successful uploads.
Stake Route: Executes a bash script for model training. It captures the output and returns it as a JSON response, providing feedback on the training process.
Last updated