|
| 1 | +# Vana Satya Proof of Contribution - Python Template |
| 2 | + |
| 3 | +This repository serves as a template for creating a [proof of contribution](https://docs.vana.org/docs/proof-of-contribution/) tasks using Python. It is executed on Vana's Satya Network, a group of highly confidential and secure compute nodes that can validate data without revealing its contents to the node operator. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This template provides a basic structure for building proof tasks that: |
| 8 | + |
| 9 | +1. Read input files from the `/input` directory. |
| 10 | +2. Process the data securely, running any necessary validations to prove the data authentic, unique, high quality, etc. |
| 11 | +3. Write proof results to the `/output/results.json` file in the following format: |
| 12 | + |
| 13 | +```json |
| 14 | +{ |
| 15 | + "dlp_id": 1234, // DLP ID is found in the Root Network contract after the DLP is registered |
| 16 | + "valid": false, // A single boolean to summarize if the file is considered valid in this DLP |
| 17 | + "score": 0.7614457831325301, // A score between 0 and 1 for the file, used to determine how valuable the file is. This can be an aggregation of the individual scores below. |
| 18 | + "authenticity": 1.0, // A score between 0 and 1 to rate if the file has been tampered with |
| 19 | + "ownership": 1.0, // A score between 0 and 1 to verify the ownership of the file |
| 20 | + "quality": 0.6024096385542169, // A score between 0 and 1 to show the quality of the file |
| 21 | + "uniqueness": 0, // A score between 0 and 1 to show unique the file is, compared to others in the DLP |
| 22 | + "attributes": { // Custom attributes added to the proof to provide extra context, written offchain in IPFS |
| 23 | + "total_score": 0.5, |
| 24 | + "score_threshold": 0.83, |
| 25 | + "email_verified": true |
| 26 | + }, |
| 27 | + "metadata": { // Custom attributes added to the proof to provide extra context, written onchain |
| 28 | + "dlp_id": 1234 |
| 29 | + } |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +The project is designed to work with Intel TDX (Trust Domain Extensions), providing hardware-level isolation and security guarantees for confidential computing workloads. |
| 34 | + |
| 35 | +## Project Structure |
| 36 | + |
| 37 | +- `my_proof/`: Contains the main proof logic |
| 38 | + - `proof.py`: Implements the proof generation logic |
| 39 | + - `__main__.py`: Entry point for the proof execution |
| 40 | + - `models/`: Data models for the proof system |
| 41 | +- `input/`: Contains a sample input file for testing. In production, the Satya node will mount the decrypted data point to the /input directory of the docker container |
| 42 | +- `output/`: Results output from the container is written here, this is passed to the Satya node after execution |
| 43 | +- `Dockerfile`: Defines the container image for the proof task |
| 44 | +- `requirements.txt`: Python package dependencies |
| 45 | + |
| 46 | +## Getting Started |
| 47 | + |
| 48 | +To use this template: |
| 49 | + |
| 50 | +1. Fork this repository |
| 51 | +2. Modify the `my_proof/proof.py` file to implement your specific proof logic |
| 52 | +3. Update the project dependencies in `requirements.txt` if needed |
| 53 | +4. Commit your changes and push to your repository |
| 54 | + |
| 55 | +## Customizing the Proof Logic |
| 56 | + |
| 57 | +The main proof logic is implemented in `my_proof/proof.py`. To customize it, update the `Proof.generate()` function to change how input files are processed. |
| 58 | + |
| 59 | +The proof can be configured using environment variables, eg: |
| 60 | + |
| 61 | +- `USER_EMAIL`: The email address of the data contributor, to verify data ownership |
| 62 | + |
| 63 | +If you want to use a language other than Python, you can modify the Dockerfile to install the necessary dependencies and build the proof task in the desired language. |
| 64 | + |
| 65 | +## Local Development |
| 66 | + |
| 67 | +To run the proof locally for testing, you can use Docker: |
| 68 | + |
| 69 | +```bash |
| 70 | +docker build -t refiner . |
| 71 | +docker run \ |
| 72 | + --rm \ |
| 73 | + --volume $(pwd)/input:/input \ |
| 74 | + --volume $(pwd)/output:/output \ |
| 75 | + refiner |
| 76 | +``` |
| 77 | + |
| 78 | +## Running with Intel TDX |
| 79 | + |
| 80 | +Intel TDX (Trust Domain Extensions) provides hardware-based memory encryption and integrity protection for virtual machines. To run this container in a TDX-enabled environment, follow your infrastructure provider's specific instructions for deploying confidential containers. |
| 81 | + |
| 82 | +Common volume mounts and environment variables: |
| 83 | + |
| 84 | +```bash |
| 85 | +docker run \ |
| 86 | + --rm \ |
| 87 | + --volume /path/to/input:/input \ |
| 88 | + --volume /path/to/output:/output \ |
| 89 | + |
| 90 | + my-proof |
| 91 | +``` |
| 92 | + |
| 93 | +Remember to populate the `/input` directory with the files you want to process. |
| 94 | + |
| 95 | +## Security Features |
| 96 | + |
| 97 | +This template leverages several security features: |
| 98 | + |
| 99 | +1. **Hardware-based Isolation**: The proof runs inside a TDX-protected environment, isolating it from the rest of the system |
| 100 | +2. **Input/Output Isolation**: Input and output directories are mounted separately, ensuring clear data flow boundaries |
| 101 | +3. **Minimal Container**: Uses a minimal Python base image to reduce attack surface |
| 102 | + |
| 103 | +## Customization |
| 104 | + |
| 105 | +Feel free to modify any part of this template to fit your specific needs. The goal is to provide a starting point that can be easily adapted to various proof tasks. |
| 106 | + |
| 107 | +## Contributing |
| 108 | + |
| 109 | +If you have suggestions for improving this template, please open an issue or submit a pull request. |
| 110 | + |
| 111 | +## License |
| 112 | + |
| 113 | +[MIT License](LICENSE) |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | +- raw data in /input directory |
| 118 | +- encrypt with DLP public key |
| 119 | +- |
| 120 | +- upload refined data to Pinata |
| 121 | +- /output |
| 122 | + - schema.json |
| 123 | + - ipfs URL |
| 124 | + - data.db |
| 125 | + - data.db.encrypted -> encrypted w/ derived encryption key |
| 126 | + |
| 127 | + |
0 commit comments