Skip to content

Commit

Permalink
Migrate to Volara TEE
Browse files Browse the repository at this point in the history
  • Loading branch information
set committed Sep 30, 2024
1 parent 4cc68b7 commit a0b8235
Show file tree
Hide file tree
Showing 26 changed files with 753 additions and 121 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ demo/*
!demo/input/

.idea/
.critical_reward_failures/
data/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

CMD ["python", "-m", "my_proof"]
CMD ["python", "-m", "volara_proof"]
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ This template provides a basic structure for building proof tasks that:
"ownership": 1.0, // A score between 0 and 1 to verify the ownership of the file
"quality": 0.6024096385542169, // A score between 0 and 1 to show the quality of the file
"uniqueness": 0, // A score between 0 and 1 to show unique the file is, compared to others in the DLP
"attributes": { // Custom attributes that can be added to the proof to provide extra context about the encrypted file
"attributes": {
// Custom attributes that can be added to the proof to provide extra context about the encrypted file
"total_score": 0.5,
"score_threshold": 0.83,
"email_verified": true
Expand All @@ -31,7 +32,7 @@ The project is designed to work with [Gramine](https://gramine.readthedocs.io/en

## Project Structure

- `my_proof/`: Contains the main proof logic
- `volara_proof/`: Contains the main proof logic
- `proof.py`: Implements the proof generation logic
- `__main__.py`: Entry point for the proof execution
- `demo/`: Contains sample input and output for testing
Expand All @@ -45,13 +46,13 @@ The project is designed to work with [Gramine](https://gramine.readthedocs.io/en
To use this template:

1. Fork this repository
2. Modify the `my_proof/proof.py` file to implement your specific proof logic
2. Modify the `volara_proof/proof.py` file to implement your specific proof logic
3. Update the `my-proof.manifest.template` if you need to add any additional files or change the configuration
4. Commit your changes and push to your repository

## Customizing the Proof Logic

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.
The main proof logic is implemented in `volara_proof/proof.py`. To customize it, update the `Proof.generate()` function to change how input files are processed.

The proof can be configured using environment variables. When running in an enclave, the environment variables must be defined in the `my-proof.manifest.template` file as well. The following environment variables are used for this demo proof:

Expand Down
Binary file modified demo/input/archive.zip
Binary file not shown.
Binary file added demo/input/tweets.data
Binary file not shown.
3 changes: 2 additions & 1 deletion my-proof.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ sgx.max_threads = 4

# Whitelist ENV variables that get passed to the enclave
# Using { passthrough = true } allows values to be passed in from the Satya node's /RunProof endpoint
loader.env.USER_EMAIL = { passthrough = true }
loader.env.COOKIES = { passthrough = true }
loader.env.VOLARA_API_KEY = { passthrough = true }

# Gramine gives a warning that allowed_files is not safe in production, but it
# should generally be fine for our use case which inherently assumes that input
Expand Down
32 changes: 0 additions & 32 deletions my_proof/models/proof_response.py

This file was deleted.

73 changes: 0 additions & 73 deletions my_proof/proof.py

This file was deleted.

8 changes: 7 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
pydantic
pydantic==2.7.1
python-gnupg==0.5.2
requests==2.31.0
twitter-api-client==0.10.22
flatbuffers==24.3.25
numpy==2.0.1
aiohttp
File renamed without changes.
21 changes: 12 additions & 9 deletions my_proof/__main__.py → volara_proof/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@
import zipfile
from typing import Dict, Any

from my_proof.proof import Proof
from volara_proof.proof import Proof

INPUT_DIR, OUTPUT_DIR, SEALED_DIR = '/input', '/output', '/sealed'
INPUT_DIR, OUTPUT_DIR, SEALED_DIR = "./demo/input", "./demo/output", "./demo/sealed"

logging.basicConfig(level=logging.INFO, format='%(message)s')
logging.basicConfig(level=logging.INFO, format="%(message)s")


def load_config() -> Dict[str, Any]:
"""Load proof configuration from environment variables."""
config = {
'dlp_id': 1234, # Set your own DLP ID here
'use_sealing': os.path.isdir(SEALED_DIR),
'input_dir': INPUT_DIR,
'user_email': os.environ.get('USER_EMAIL', None),
"dlp_id": 1234, # Set your own DLP ID here
"use_sealing": os.path.isdir(SEALED_DIR),
"input_dir": INPUT_DIR,
"cookies": os.environ.get("COOKIES", None),
"volara_api_key": os.environ.get("VOLARA_API_KEY", None),
"file_id": os.environ.get("FILE_ID", None),
"miner_address": os.environ.get("MINER_ADDRESS", None),
}
logging.info(f"Using config: {json.dumps(config, indent=2)}")
return config
Expand All @@ -38,7 +41,7 @@ def run() -> None:
proof_response = proof.generate()

output_path = os.path.join(OUTPUT_DIR, "results.json")
with open(output_path, 'w') as f:
with open(output_path, "w") as f:
json.dump(proof_response.dict(), f, indent=2)
logging.info(f"Proof generation complete: {proof_response}")

Expand All @@ -52,7 +55,7 @@ def extract_input() -> None:
input_file = os.path.join(INPUT_DIR, input_filename)

if zipfile.is_zipfile(input_file):
with zipfile.ZipFile(input_file, 'r') as zip_ref:
with zipfile.ZipFile(input_file, "r") as zip_ref:
zip_ref.extractall(INPUT_DIR)


Expand Down
21 changes: 21 additions & 0 deletions volara_proof/buffers/raw/tweet.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Volara;


table Tweet {
handle:string;
user_id:string;
tweet_id:string;
text:string;
likes:int;
retweets:int;
replies:int;
quotes:int;
created_at:ulong;
subtweet_id:string;
}

table Tweets {
tweets:[Tweet];
}

root_type Tweets;
Loading

0 comments on commit a0b8235

Please sign in to comment.