This repository serves as a template for creating proof tasks using Python and Gramine for secure computation.
This template provides a basic structure for building proof tasks that:
- Read input files from the
/input
directory - Process the data securely
- Write proof results to the
/output
directory - Use the
/sealed
directory for secure storage (when available)
The project is designed to work with Gramine, a lightweight library OS that enables running unmodified applications in secure enclaves, such as Intel SGX (Software Guard Extensions). This allows the code to run in a trusted execution environment, ensuring confidentiality and integrity of the computation.
my_proof/
: Contains the main proof logicproof.py
: Implements the proof generation logic__main__.py
: Entry point for the proof execution
demo/
: Contains sample input and output for testing.github/workflows/
: CI/CD pipeline for building and releasingDockerfile
: Defines the container image for the proof taskpython.manifest.template
: Gramine manifest template for secure executionconfig.yaml
: Configuration file for Gramine Shielded Containers (GSC)
To use this template:
- Fork this repository
- Modify the
my_proof/proof.py
file to implement your specific proof logic - Update the
python.manifest.template
if you need to add any additional files or change the configuration - Commit your changes and push to your repository
The main proof logic is implemented in my_proof/proof.py
. To customize it:
- Modify the
expected_words
list to include the keywords you're looking for - Adjust the
process_on_disk
andprocess_in_memory
functions to implement your specific proof generation logic - Update the
generate_proof
function if you need to change how input files are processed or results are written
To run the proof locally, without Gramine, you can use Docker:
docker build -t my-proof .
docker run \
--rm \
--volume $(pwd)/demo/sealed:/sealed \
--volume $(pwd)/demo/input:/input \
--volume $(pwd)/demo/output:/output \
my-proof
Before building and signing your graminized Docker image, you need to generate a signing key. Gramine provides a tool called gramine-sgx-gen-private-key
for this purpose. Here's how to use it:
-
If you have Gramine installed on your system, you can use the following command:
gramine-sgx-gen-private-key enclave-key.pem
This will generate a new RSA 3072 key suitable for signing SGX enclaves and save it as
enclave-key.pem
in the current directory. -
If you don't have Gramine installed, you can use OpenSSL to generate a compatible key:
openssl genrsa -3 -out enclave-key.pem 3072
This generates an RSA 3072-bit key with the public exponent set to 3, which is required for SGX enclaves.
Make sure to keep this key secure, as it will be used to sign your enclaves. You'll use this key in the gsc sign-image
step of the GSC workflow.
This template includes a GitHub Actions workflow that automatically:
- Builds a Docker image with your code
- Creates a Gramine-shielded container (GSC) image
- Publishes the GSC image as a GitHub release
To use this workflow, you need to:
- Set up a signing key, as described above, and add it as a GitHub secret named
SIGNING_KEY
- Push your changes to the
main
branch or create a pull request
Intel SGX (Software Guard Extensions) is a set of security-related instruction codes built into modern Intel CPUs. It allows parts of a program to be executed in a secure enclave, isolated from the rest of the system.
To load a released image with docker, copy the URL from the release and run:
curl -L https://github.com/vana-com/vana-satya-proof-template-temporary/releases/download/v9/gsc-my-proof-latest.tar.gz | docker load
To run the image:
docker run \
--rm \
--volume /gsc-my-proof/input:/input \
--volume /gsc-my-proof/output:/output \
gsc-my-proof
If your application relies on Gramine-enabled SGX features like sealing, remote attestation, etc., you may need to mount additional volumes and devices:
docker run \
--rm \
--volume /gsc-my-proof/input:/input \
--volume /gsc-my-proof/output:/output \
--device /dev/sgx_enclave:/dev/sgx_enclave \
--volume /var/run/aesmd:/var/run/aesmd \
--volume /mnt/gsc-my-proof/sealed:/sealed \
gsc-my-proof
This template leverages several security features:
- Secure Enclaves: The proof runs inside an SGX enclave, isolating it from the rest of the system.
- Encrypted Storage: The
/sealed
directory is automatically encrypted/decrypted by Gramine, providing secure storage for sensitive data. - Input/Output Isolation: Input and output directories are mounted separately, ensuring clear data flow boundaries.
- Minimal Attack Surface: The Gramine manifest limits the files and resources accessible to the enclave, reducing potential vulnerabilities.
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.
If you have suggestions for improving this template, please open an issue or submit a pull request.