Skip to content

Commit bbf79df

Browse files
committed
latest scoring
1 parent 7a7b061 commit bbf79df

File tree

13 files changed

+453
-442
lines changed

13 files changed

+453
-442
lines changed

Dockerfile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
FROM python:3.11-slim
2-
3-
WORKDIR /app
4-
5-
COPY . /app
6-
7-
# Install any needed packages specified in requirements.txt
8-
RUN pip install --no-cache-dir -r requirements.txt
9-
10-
CMD ["python", "-m", "psl_proof"]
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
COPY . /app
6+
7+
# Install any needed packages specified in requirements.txt
8+
RUN pip install --no-cache-dir -r requirements.txt
9+
10+
CMD ["python", "-m", "psl_proof"]

LICENSE

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
The MIT License (MIT)
2-
3-
Copyright © 2024 Corsali, Inc. dba Vana
4-
Copyright © 2024 CryptoLock Cybersecurity Solutions Ltd. dba dFusion AI
5-
6-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7-
8-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9-
10-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1+
The MIT License (MIT)
2+
3+
Copyright © 2024 Corsali, Inc. dba Vana
4+
Copyright © 2024 CryptoLock Cybersecurity Solutions Ltd. dba dFusion AI
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9+
10+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 120 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,121 @@
1-
# Vana Satya Proof of Contribution - dFusion Private Social Lens
2-
3-
This repository serves as a template for creating a [proof of contribution](https://docs.vana.org/vana/core-concepts/key-elements/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 that can be added to the proof to provide extra context about the encrypted file
23-
"total_score": 0.5,
24-
"score_threshold": 0.83,
25-
"email_verified": true
26-
}
27-
}
28-
```
29-
30-
The project is designed to work with Intel TDX (Trust Domain Extensions), providing hardware-level isolation and security guarantees for confidential computing workloads.
31-
32-
## Project Structure
33-
34-
- `psl_proof/`: Contains the main proof logic
35-
- `proof.py`: Implements the proof generation logic
36-
- `__main__.py`: Entry point for the proof execution
37-
- `models/`: Data models for the proof system
38-
- `demo/`: Contains sample input and output for testing
39-
- `Dockerfile`: Defines the container image for the proof task
40-
- `requirements.txt`: Python package dependencies
41-
42-
## Getting Started
43-
44-
To use this template:
45-
46-
1. Fork this repository
47-
2. Modify the `psl_proof/proof.py` file to implement your specific proof logic
48-
3. Update the project dependencies in `requirements.txt` if needed
49-
4. Commit your changes and push to your repository
50-
51-
## Customizing the Proof Logic
52-
53-
The main proof logic is implemented in `psl_proof/proof.py`. To customize it, update the `Proof.generate()` function to change how input files are processed.
54-
55-
The proof can be configured using environment variables.
56-
57-
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.
58-
59-
## Proof Scores
60-
61-
Loop through chat/conversal list, get average scores
62-
1. Quality scores (qs) based on Timely, Thoughtful & Contextual
63-
2. Uniqueness scores (us) based,
64-
a. For each chat, fetch the timestamp of the last entry.
65-
b. Determine the time difference (td) between the last entry and the current timestamp:
66-
c. If td > 1 hour, assign a Uniqueness Score of 1.0 for that chat, else 0.0
67-
3. Detemine the total score (ts)
68-
a. if us > 0, then add value to ts.
69-
70-
Determine score:
71-
valid flag alway true
72-
normalise total score to value range 0 to 1
73-
total score is restricted by Minimum & Maximum value
74-
75-
76-
## Local Development
77-
78-
To run the proof locally for testing, you can use Docker:
79-
80-
```bash
81-
docker build -t psl-proof .
82-
docker run \
83-
--rm \
84-
--volume $(pwd)/input:/input \
85-
--volume $(pwd)/output:/output \
86-
--env USER_EMAIL=user123@gmail.com \
87-
psl-proof
88-
```
89-
90-
## Running with Intel TDX
91-
92-
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.
93-
94-
Common volume mounts and environment variables:
95-
96-
```bash
97-
docker run \
98-
--rm \
99-
--volume /path/to/input:/input \
100-
--volume /path/to/output:/output \
101-
--env USER_EMAIL=user123@gmail.com \
102-
psl-proof
103-
```
104-
105-
Remember to populate the `/input` directory with the files you want to process.
106-
107-
## Security Features
108-
109-
This template leverages several security features:
110-
111-
1. **Hardware-based Isolation**: The proof runs inside a TDX-protected environment, isolating it from the rest of the system
112-
2. **Input/Output Isolation**: Input and output directories are mounted separately, ensuring clear data flow boundaries
113-
3. **Minimal Container**: Uses a minimal Python base image to reduce attack surface
114-
115-
## Contributing
116-
117-
If you have suggestions for improving this proof, please submit a pull request.
118-
119-
## License
120-
1+
# Vana Satya Proof of Contribution - dFusion Private Social Lens
2+
3+
This repository serves as a template for creating a [proof of contribution](https://docs.vana.org/vana/core-concepts/key-elements/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 that can be added to the proof to provide extra context about the encrypted file
23+
"total_score": 0.5,
24+
"score_threshold": 0.83,
25+
"email_verified": true
26+
}
27+
}
28+
```
29+
30+
The project is designed to work with Intel TDX (Trust Domain Extensions), providing hardware-level isolation and security guarantees for confidential computing workloads.
31+
32+
## Project Structure
33+
34+
- `psl_proof/`: Contains the main proof logic
35+
- `proof.py`: Implements the proof generation logic
36+
- `__main__.py`: Entry point for the proof execution
37+
- `models/`: Data models for the proof system
38+
- `demo/`: Contains sample input and output for testing
39+
- `Dockerfile`: Defines the container image for the proof task
40+
- `requirements.txt`: Python package dependencies
41+
42+
## Getting Started
43+
44+
To use this template:
45+
46+
1. Fork this repository
47+
2. Modify the `psl_proof/proof.py` file to implement your specific proof logic
48+
3. Update the project dependencies in `requirements.txt` if needed
49+
4. Commit your changes and push to your repository
50+
51+
## Customizing the Proof Logic
52+
53+
The main proof logic is implemented in `psl_proof/proof.py`. To customize it, update the `Proof.generate()` function to change how input files are processed.
54+
55+
The proof can be configured using environment variables.
56+
57+
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.
58+
59+
## Proof Scores
60+
61+
Loop through chat/conversal list, get average scores
62+
1. Quality scores (qs) based on Timely, Thoughtful & Contextual
63+
2. Uniqueness scores (us) based,
64+
a. For each chat, fetch the timestamp of the last entry.
65+
b. Determine the time difference (td) between the last entry and the current timestamp:
66+
c. If td > 1 hour, assign a Uniqueness Score of 1.0 for that chat, else 0.0
67+
3. Detemine the total score (ts)
68+
a. if us > 0, then add value to ts.
69+
70+
Determine score:
71+
valid flag alway true
72+
normalise total score to value range 0 to 1
73+
total score is restricted by Minimum & Maximum value
74+
75+
76+
## Local Development
77+
78+
To run the proof locally for testing, you can use Docker:
79+
80+
```bash
81+
docker build -t psl-proof .
82+
docker run \
83+
--rm \
84+
--volume $(pwd)/input:/input \
85+
--volume $(pwd)/output:/output \
86+
--env USER_EMAIL=user123@gmail.com \
87+
psl-proof
88+
```
89+
90+
## Running with Intel TDX
91+
92+
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.
93+
94+
Common volume mounts and environment variables:
95+
96+
```bash
97+
docker run \
98+
--rm \
99+
--volume /path/to/input:/input \
100+
--volume /path/to/output:/output \
101+
--env USER_EMAIL=user123@gmail.com \
102+
psl-proof
103+
```
104+
105+
Remember to populate the `/input` directory with the files you want to process.
106+
107+
## Security Features
108+
109+
This template leverages several security features:
110+
111+
1. **Hardware-based Isolation**: The proof runs inside a TDX-protected environment, isolating it from the rest of the system
112+
2. **Input/Output Isolation**: Input and output directories are mounted separately, ensuring clear data flow boundaries
113+
3. **Minimal Container**: Uses a minimal Python base image to reduce attack surface
114+
115+
## Contributing
116+
117+
If you have suggestions for improving this proof, please submit a pull request.
118+
119+
## License
120+
121121
[MIT License](LICENSE)

psl_proof/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
def load_config() -> Dict[str, Any]:
1616
"""Load proof configuration from environment variables."""
1717
config = {
18-
'dlp_id': 21,
18+
'dlp_id': 4,
1919
'input_dir': INPUT_DIR,
2020
'salt': '5EkntCWI',
21-
# 'validator_base_api_url': 'https://api.vana.genesis.dfusion.ai'
22-
'validator_base_api_url': 'https://b1858a42a344.ngrok-free.app'
21+
'validator_base_api_url': 'https://api.vana.genesis.dfusion.ai'
22+
#'validator_base_api_url': 'https://9634-169-0-170-71.ngrok-free.app'
2323
}
2424
logging.info(f"Using config: {json.dumps(config, indent=2)}")
2525
return config

psl_proof/models/proof_response.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
from typing import Dict, Optional, Any
2-
3-
from pydantic import BaseModel
4-
5-
6-
class ProofResponse(BaseModel):
7-
"""
8-
Represents the response of a proof of contribution. Only the score and metadata will be written onchain, the rest of the proof lives offchain.
9-
10-
Onchain attributes - these are written to the data registry:
11-
score: 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.
12-
metadata: Additional metadata about the proof
13-
14-
Offchain attributes - the remainder of the proof is written to IPFS
15-
dlp_id: The DLP ID is found in the DLP Root Network contract after the DLP is registered.
16-
valid: A single boolean to summarize if the file is considered valid in this DLP.
17-
authenticity: A score between 0 and 1 to rate if the file has been tampered with.
18-
ownership: A score between 0 and 1 to verify the ownership of the file.
19-
quality: A score between 0 and 1 to show the quality of the file
20-
uniqueness: A score between 0 and 1 to show unique the file is, compared to others in the DLP.
21-
attributes: Custom attributes added to the proof to provide extra context about the encrypted file.
22-
"""
23-
24-
dlp_id: int
25-
valid: bool = False
26-
score: float = 0.0
27-
authenticity: float = 0.0
28-
ownership: float = 0.0
29-
quality: float = 0.0
30-
uniqueness: float = 0.0
31-
attributes: Optional[Dict[str, Any]] = {}
32-
metadata: Optional[Dict[str, Any]] = {}
33-
34-
def set_proof_is_invalid(self) :
35-
self.valid = False
36-
self.score = 0.0
37-
self.authenticity = 0.0
38-
self.ownership = 0.0
39-
self.quality = 0.0
40-
self.uniqueness = 0.0
1+
from typing import Dict, Optional, Any
2+
3+
from pydantic import BaseModel
4+
5+
6+
class ProofResponse(BaseModel):
7+
"""
8+
Represents the response of a proof of contribution. Only the score and metadata will be written onchain, the rest of the proof lives offchain.
9+
10+
Onchain attributes - these are written to the data registry:
11+
score: 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.
12+
metadata: Additional metadata about the proof
13+
14+
Offchain attributes - the remainder of the proof is written to IPFS
15+
dlp_id: The DLP ID is found in the DLP Root Network contract after the DLP is registered.
16+
valid: A single boolean to summarize if the file is considered valid in this DLP.
17+
authenticity: A score between 0 and 1 to rate if the file has been tampered with.
18+
ownership: A score between 0 and 1 to verify the ownership of the file.
19+
quality: A score between 0 and 1 to show the quality of the file
20+
uniqueness: A score between 0 and 1 to show unique the file is, compared to others in the DLP.
21+
attributes: Custom attributes added to the proof to provide extra context about the encrypted file.
22+
"""
23+
24+
dlp_id: int
25+
valid: bool = False
26+
score: float = 0.0
27+
authenticity: float = 0.0
28+
ownership: float = 0.0
29+
quality: float = 0.0
30+
uniqueness: float = 0.0
31+
attributes: Optional[Dict[str, Any]] = {}
32+
metadata: Optional[Dict[str, Any]] = {}
33+
34+
def set_proof_is_invalid(self) :
35+
self.valid = False
36+
self.score = 0.0
37+
self.authenticity = 0.0
38+
self.ownership = 0.0
39+
self.quality = 0.0
40+
self.uniqueness = 0.0

psl_proof/models/verification_dtos.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ class VerifyTokenResult:
88
error_text: str
99
proof_token: str
1010
cooldown_period_hours: float = 0 # Cooldown period from backend config
11+
minimum_score: float = 0 # Minimum score threshold from backend config

0 commit comments

Comments
 (0)