dot-ring 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dot_ring-0.1.0/LICENSE +21 -0
- dot_ring-0.1.0/MANIFEST.in +5 -0
- dot_ring-0.1.0/PKG-INFO +220 -0
- dot_ring-0.1.0/README.md +172 -0
- dot_ring-0.1.0/dot_ring/__init__.py +118 -0
- dot_ring-0.1.0/dot_ring/curve/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/curve/curve.py +334 -0
- dot_ring-0.1.0/dot_ring/curve/e2c.py +16 -0
- dot_ring-0.1.0/dot_ring/curve/fast_math.c +10863 -0
- dot_ring-0.1.0/dot_ring/curve/fast_math.pyx +100 -0
- dot_ring-0.1.0/dot_ring/curve/field_arithmetic.c +15179 -0
- dot_ring-0.1.0/dot_ring/curve/field_arithmetic.pyx +408 -0
- dot_ring-0.1.0/dot_ring/curve/field_element.py +208 -0
- dot_ring-0.1.0/dot_ring/curve/glv.py +309 -0
- dot_ring-0.1.0/dot_ring/curve/montgomery/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/curve/montgomery/mg_affine_point.py +418 -0
- dot_ring-0.1.0/dot_ring/curve/montgomery/mg_curve.py +143 -0
- dot_ring-0.1.0/dot_ring/curve/point.py +310 -0
- dot_ring-0.1.0/dot_ring/curve/short_weierstrass/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/curve/short_weierstrass/sw_affine_point.py +667 -0
- dot_ring-0.1.0/dot_ring/curve/short_weierstrass/sw_curve.py +76 -0
- dot_ring-0.1.0/dot_ring/curve/specs/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/curve/specs/baby_jubjub.py +110 -0
- dot_ring-0.1.0/dot_ring/curve/specs/bandersnatch.py +184 -0
- dot_ring-0.1.0/dot_ring/curve/specs/bandersnatch_sw.py +225 -0
- dot_ring-0.1.0/dot_ring/curve/specs/bls12_381_G1.py +352 -0
- dot_ring-0.1.0/dot_ring/curve/specs/bls12_381_G2.py +528 -0
- dot_ring-0.1.0/dot_ring/curve/specs/curve25519.py +163 -0
- dot_ring-0.1.0/dot_ring/curve/specs/curve448.py +167 -0
- dot_ring-0.1.0/dot_ring/curve/specs/ed25519.py +163 -0
- dot_ring-0.1.0/dot_ring/curve/specs/ed448.py +249 -0
- dot_ring-0.1.0/dot_ring/curve/specs/jubjub.py +110 -0
- dot_ring-0.1.0/dot_ring/curve/specs/p256.py +171 -0
- dot_ring-0.1.0/dot_ring/curve/specs/p384.py +140 -0
- dot_ring-0.1.0/dot_ring/curve/specs/p521.py +137 -0
- dot_ring-0.1.0/dot_ring/curve/specs/secp256k1.py +214 -0
- dot_ring-0.1.0/dot_ring/curve/twisted_edwards/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/curve/twisted_edwards/te_affine_point.py +424 -0
- dot_ring-0.1.0/dot_ring/curve/twisted_edwards/te_curve.py +131 -0
- dot_ring-0.1.0/dot_ring/curve/twisted_edwards/te_projective_point.py +137 -0
- dot_ring-0.1.0/dot_ring/ring_proof/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/ring_proof/columns/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/ring_proof/columns/columns.py +171 -0
- dot_ring-0.1.0/dot_ring/ring_proof/constants.py +83 -0
- dot_ring-0.1.0/dot_ring/ring_proof/constraints/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/ring_proof/constraints/aggregation.py +49 -0
- dot_ring-0.1.0/dot_ring/ring_proof/constraints/constraints.py +244 -0
- dot_ring-0.1.0/dot_ring/ring_proof/curve/bandersnatch.py +18 -0
- dot_ring-0.1.0/dot_ring/ring_proof/curve/bls12_381.py +1 -0
- dot_ring-0.1.0/dot_ring/ring_proof/hash.py +28 -0
- dot_ring-0.1.0/dot_ring/ring_proof/helpers.py +160 -0
- dot_ring-0.1.0/dot_ring/ring_proof/pcs/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/ring_proof/pcs/kzg.py +232 -0
- dot_ring-0.1.0/dot_ring/ring_proof/pcs/pairing.py +29 -0
- dot_ring-0.1.0/dot_ring/ring_proof/pcs/srs.py +119 -0
- dot_ring-0.1.0/dot_ring/ring_proof/pcs/utils.py +49 -0
- dot_ring-0.1.0/dot_ring/ring_proof/polynomial/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/ring_proof/polynomial/fft.py +192 -0
- dot_ring-0.1.0/dot_ring/ring_proof/polynomial/interpolation.py +74 -0
- dot_ring-0.1.0/dot_ring/ring_proof/polynomial/ntt.c +8829 -0
- dot_ring-0.1.0/dot_ring/ring_proof/polynomial/ntt.pyx +65 -0
- dot_ring-0.1.0/dot_ring/ring_proof/polynomial/ops.py +296 -0
- dot_ring-0.1.0/dot_ring/ring_proof/proof/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/ring_proof/proof/aggregation_poly.py +38 -0
- dot_ring-0.1.0/dot_ring/ring_proof/proof/linearization_poly.py +108 -0
- dot_ring-0.1.0/dot_ring/ring_proof/proof/quotient_poly.py +28 -0
- dot_ring-0.1.0/dot_ring/ring_proof/transcript/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/ring_proof/transcript/phases.py +43 -0
- dot_ring-0.1.0/dot_ring/ring_proof/transcript/serialize.py +66 -0
- dot_ring-0.1.0/dot_ring/ring_proof/transcript/transcript.py +123 -0
- dot_ring-0.1.0/dot_ring/ring_proof/verify.py +290 -0
- dot_ring-0.1.0/dot_ring/vrf/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/vrf/ietf/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/vrf/ietf/ietf.py +155 -0
- dot_ring-0.1.0/dot_ring/vrf/pedersen/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/vrf/pedersen/pedersen.py +221 -0
- dot_ring-0.1.0/dot_ring/vrf/ring/__init__.py +0 -0
- dot_ring-0.1.0/dot_ring/vrf/ring/ring_root.py +29 -0
- dot_ring-0.1.0/dot_ring/vrf/ring/ring_vrf.py +359 -0
- dot_ring-0.1.0/dot_ring/vrf/vrf.py +265 -0
- dot_ring-0.1.0/dot_ring.egg-info/PKG-INFO +220 -0
- dot_ring-0.1.0/dot_ring.egg-info/SOURCES.txt +87 -0
- dot_ring-0.1.0/dot_ring.egg-info/dependency_links.txt +1 -0
- dot_ring-0.1.0/dot_ring.egg-info/requires.txt +17 -0
- dot_ring-0.1.0/dot_ring.egg-info/top_level.txt +1 -0
- dot_ring-0.1.0/pyproject.toml +79 -0
- dot_ring-0.1.0/setup.cfg +4 -0
- dot_ring-0.1.0/setup.py +103 -0
- dot_ring-0.1.0/tests/test_bandersnatch_ark.py +129 -0
dot_ring-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chainscore Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
dot_ring-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dot-ring
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Serves as a library to generate and verify a signature using IETF, Pedersen and Ring VRF-AD Schemes
|
|
5
|
+
Author-email: prasad-kumkar <prasad@chainscore.finance>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/chainscore/dot-ring
|
|
8
|
+
Project-URL: Repository, https://github.com/chainscore/dot-ring
|
|
9
|
+
Project-URL: Issues, https://github.com/chainscore/dot-ring/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/chainscore/dot-ring#readme
|
|
11
|
+
Keywords: VRF,VRF-AD,IETF VRF,Pedersen VRF,Ring Proof,Ring VRF,Signature,Proof,Verify,Cryptography,Zero Knowledge,PCS,KZG,FFT,Polynomial,Interpolation,Ring Root,Commitment,Constraints,fflonk,powers of tau,string to point,point to string,encode to curve,public key,elliptic curve cryptography,proof to hash,bls12_381,Bandersnatch,fiat shamir,pairings
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
21
|
+
Classifier: Topic :: System :: Networking
|
|
22
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
23
|
+
Classifier: Topic :: Database
|
|
24
|
+
Classifier: Topic :: Utilities
|
|
25
|
+
Classifier: Topic :: System :: Archiving
|
|
26
|
+
Classifier: Topic :: Communications
|
|
27
|
+
Classifier: Typing :: Typed
|
|
28
|
+
Requires-Python: >=3.12
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: numpy>=2.2.3
|
|
32
|
+
Requires-Dist: sympy>=1.13.1
|
|
33
|
+
Requires-Dist: pytest>=8.3.5
|
|
34
|
+
Requires-Dist: py-ecc>=8.0.0
|
|
35
|
+
Requires-Dist: gmpy2>=2.1.0
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == "dev"
|
|
40
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
41
|
+
Requires-Dist: pytest-timeout>=2.1.0; extra == "dev"
|
|
42
|
+
Requires-Dist: pytest-xdist>=3.0.0; extra == "dev"
|
|
43
|
+
Requires-Dist: Cython>=3.0.0; extra == "dev"
|
|
44
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
45
|
+
Requires-Dist: setuptools>=65.0.0; extra == "dev"
|
|
46
|
+
Requires-Dist: wheel>=0.38.0; extra == "dev"
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
[](https://github.com/Chainscore/dot-ring/actions/workflows/test.yml)
|
|
52
|
+
[](https://codecov.io/gh/Chainscore/dot-ring)
|
|
53
|
+
[](https://www.python.org/downloads/)
|
|
54
|
+
[](LICENSE)
|
|
55
|
+
[](https://github.com/psf/black)
|
|
56
|
+
|
|
57
|
+
`@dot-ring` is a Python library for generating Verifiable Random Functions with Additional Data (VRF-AD) on 10+ Elliptic Curves, including IETF, Pedersen VRF and Ring Proof.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
Specifications in compliance:
|
|
61
|
+
- [Bandersnatch VRF](https://github.com/davxy/bandersnatch-vrf-spec/blob/main/specification.md)
|
|
62
|
+
- [Ring Proof](https://github.com/davxy/ring-proof-spec)
|
|
63
|
+
- [RFC9381](https://datatracker.ietf.org/doc/rfc9381)
|
|
64
|
+
- [RFC9380](https://datatracker.ietf.org/doc/rfc9380)
|
|
65
|
+
- [BCGSV23](https://eprint.iacr.org/2023/002)
|
|
66
|
+
- [MSZ21](https://eprint.iacr.org/2021/1152)
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Installation & Setup
|
|
70
|
+
|
|
71
|
+
### Prerequisites
|
|
72
|
+
- Python 3.12 or higher
|
|
73
|
+
- [uv](https://github.com/astral-sh/uv) (Recommended for dependency management)
|
|
74
|
+
|
|
75
|
+
### Installation using uv (Recommended)
|
|
76
|
+
|
|
77
|
+
1. **Install uv** (if not already installed):
|
|
78
|
+
```bash
|
|
79
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
2. **Clone the repository**:
|
|
83
|
+
```bash
|
|
84
|
+
git clone https://github.com/chainscore/dot-ring.git
|
|
85
|
+
cd dot-ring
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
3. **Run the setup script**:
|
|
89
|
+
This script installs all dependencies, builds `blst` bindings, and compiles Cython extensions.
|
|
90
|
+
```bash
|
|
91
|
+
./setup.sh
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Manual Installation
|
|
95
|
+
|
|
96
|
+
If you prefer not to use `uv` or the setup script, you can install using pip:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pip install .
|
|
100
|
+
# For development dependencies
|
|
101
|
+
pip install .[dev]
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
To install `blst` manually:
|
|
105
|
+
```bash
|
|
106
|
+
git clone https://github.com/supranational/blst.git .blst
|
|
107
|
+
cd .blst/bindings/python
|
|
108
|
+
./run.me
|
|
109
|
+
# Then ensure the generated blst.py and shared library are in your PYTHONPATH or site-packages
|
|
110
|
+
export PYTHONPATH=YOUR_PATH_HERE/blst/bindings/python:$PYTHONPATH
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Example Usage
|
|
114
|
+
```python
|
|
115
|
+
# Sample test vector
|
|
116
|
+
secret_key="3d6406500d4009fdf2604546093665911e753f2213570a29521fd88bc30ede18"
|
|
117
|
+
alpha=""
|
|
118
|
+
salt=""
|
|
119
|
+
add=""
|
|
120
|
+
ring_pks="7b32d917d5aa771d493c47b0e096886827cd056c82dbdba19e60baa8b2c60313d3b1bdb321123449c6e89d310bc6b7f654315eb471c84778353ce08b951ad471561fdb0dcfb8bd443718b942f82fe717238cbcf8d12b8d22861c8a09a984a3c5a1b1da71cc4682e159b7da23050d8b6261eb11a3247c89b07ef56ccd002fd38b4fd11f89c2a1aaefe856bb1c5d4a1fad73f4de5e41804ca2c17ba26d6e10050c86d06ee2c70da6cf2da2a828d8a9d8ef755ad6e580e838359a10accb086ae437ad6fdeda0dde0a57c51d3226b87e3795e6474393772da46101fd597fbd456c1b3f9dc0c4f67f207974123830c2d66988fb3fb44becbbba5a64143f376edc51d9"
|
|
121
|
+
```
|
|
122
|
+
### For IETF VRF
|
|
123
|
+
```python
|
|
124
|
+
from dot_ring import Bandersnatch, IETF_VRF
|
|
125
|
+
|
|
126
|
+
# Generate Proof
|
|
127
|
+
proof: IETF_VRF = IETF_VRF[Bandersnatch].proof(alpha, secret_key, add)
|
|
128
|
+
# Or from bytes
|
|
129
|
+
proof_bytes = proof.to_bytes()
|
|
130
|
+
proof: IETF_VRF = IETF_VRF[Bandersnatch].from_bytes(proof_bytes)
|
|
131
|
+
|
|
132
|
+
# Verify Proof
|
|
133
|
+
public_key = IETF_VRF[Bandersnatch].get_public_key(secret_key)
|
|
134
|
+
is_valid: bool = proof.verify(public_key, alpha, add)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### For Pedersen VRF
|
|
138
|
+
```python
|
|
139
|
+
from dot_ring import Bandersnatch, PedersenVRF
|
|
140
|
+
|
|
141
|
+
# Generate Proof
|
|
142
|
+
proof: PedersenVRF = PedersenVRF[Bandersnatch].proof(alpha, secret_key, add)
|
|
143
|
+
# Or import from bytes
|
|
144
|
+
proof_bytes = proof.to_bytes()
|
|
145
|
+
proof: PedersenVRF = PedersenVRF[Bandersnatch].from_bytes(proof_bytes)
|
|
146
|
+
|
|
147
|
+
# Verify Proof
|
|
148
|
+
# Public key is blinded in Pedersen VRF and included in the proof
|
|
149
|
+
is_valid: bool = proof.verify(alpha, add)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### For Ring VRF
|
|
153
|
+
```python
|
|
154
|
+
from dot_ring import Bandersnatch, RingVRF
|
|
155
|
+
|
|
156
|
+
# Parse keys if they are in a single byte string
|
|
157
|
+
keys_list = RingVRF[Bandersnatch].parse_keys(ring_pks)
|
|
158
|
+
|
|
159
|
+
# Generate ring root commitment
|
|
160
|
+
ring_root = RingVRF[Bandersnatch].construct_ring_root(keys_list)
|
|
161
|
+
|
|
162
|
+
# Generate Ring VRF proof
|
|
163
|
+
# producer_key is the public key corresponding to secret_key
|
|
164
|
+
producer_key = RingVRF[Bandersnatch].get_public_key(secret_key)
|
|
165
|
+
proof: RingVRF = RingVRF[Bandersnatch].proof(alpha, add, secret_key, producer_key, keys_list)
|
|
166
|
+
# Or from bytes
|
|
167
|
+
proof_bytes = proof.to_bytes() # 768 bytes ring proof
|
|
168
|
+
proof: RingVRF = RingVRF[Bandersnatch].from_bytes(proof_bytes)
|
|
169
|
+
# Verify Ring VRF Proof
|
|
170
|
+
is_valid: bool = proof.verify(alpha, add, ring_root)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
## Testing
|
|
175
|
+
|
|
176
|
+
You can run the test suite with **pytest** using `uv`:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
uv run pytest tests/
|
|
180
|
+
```
|
|
181
|
+
See [TESTING.md](./TESTING.md) for an overview of the test suite and instructions on running tests.
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
## Docker Setup
|
|
185
|
+
|
|
186
|
+
### Build the Docker Image
|
|
187
|
+
```bash
|
|
188
|
+
docker build -t dot_ring .
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Run tests inside a container
|
|
192
|
+
```bash
|
|
193
|
+
docker run -it dot_ring uv run pytest tests/
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Generate a Coverage report
|
|
197
|
+
- Terminal summary
|
|
198
|
+
```bash
|
|
199
|
+
docker run -it dot_ring uv run pytest tests/ --cov=dot_ring --cov-report=term-missing
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
- HTML report
|
|
203
|
+
```bash
|
|
204
|
+
docker run -it dot_ring uv run pytest tests/ --cov=dot_ring --cov-report=html
|
|
205
|
+
open htmlcov/index.html #open it in your browser
|
|
206
|
+
```
|
|
207
|
+
Access an interactive shell inside the container
|
|
208
|
+
```bash
|
|
209
|
+
docker run -it dot_ring bash
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Contact
|
|
213
|
+
|
|
214
|
+
Prasad // Chainscore Labs
|
|
215
|
+
|
|
216
|
+

|
|
217
|
+
|
|
218
|
+
[Email](mailto:prasad@chainscore.finance)
|
|
219
|
+
|
|
220
|
+
[Website](https://chainscore.finance)
|
dot_ring-0.1.0/README.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
[](https://github.com/Chainscore/dot-ring/actions/workflows/test.yml)
|
|
4
|
+
[](https://codecov.io/gh/Chainscore/dot-ring)
|
|
5
|
+
[](https://www.python.org/downloads/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://github.com/psf/black)
|
|
8
|
+
|
|
9
|
+
`@dot-ring` is a Python library for generating Verifiable Random Functions with Additional Data (VRF-AD) on 10+ Elliptic Curves, including IETF, Pedersen VRF and Ring Proof.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Specifications in compliance:
|
|
13
|
+
- [Bandersnatch VRF](https://github.com/davxy/bandersnatch-vrf-spec/blob/main/specification.md)
|
|
14
|
+
- [Ring Proof](https://github.com/davxy/ring-proof-spec)
|
|
15
|
+
- [RFC9381](https://datatracker.ietf.org/doc/rfc9381)
|
|
16
|
+
- [RFC9380](https://datatracker.ietf.org/doc/rfc9380)
|
|
17
|
+
- [BCGSV23](https://eprint.iacr.org/2023/002)
|
|
18
|
+
- [MSZ21](https://eprint.iacr.org/2021/1152)
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation & Setup
|
|
22
|
+
|
|
23
|
+
### Prerequisites
|
|
24
|
+
- Python 3.12 or higher
|
|
25
|
+
- [uv](https://github.com/astral-sh/uv) (Recommended for dependency management)
|
|
26
|
+
|
|
27
|
+
### Installation using uv (Recommended)
|
|
28
|
+
|
|
29
|
+
1. **Install uv** (if not already installed):
|
|
30
|
+
```bash
|
|
31
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
2. **Clone the repository**:
|
|
35
|
+
```bash
|
|
36
|
+
git clone https://github.com/chainscore/dot-ring.git
|
|
37
|
+
cd dot-ring
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
3. **Run the setup script**:
|
|
41
|
+
This script installs all dependencies, builds `blst` bindings, and compiles Cython extensions.
|
|
42
|
+
```bash
|
|
43
|
+
./setup.sh
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Manual Installation
|
|
47
|
+
|
|
48
|
+
If you prefer not to use `uv` or the setup script, you can install using pip:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install .
|
|
52
|
+
# For development dependencies
|
|
53
|
+
pip install .[dev]
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
To install `blst` manually:
|
|
57
|
+
```bash
|
|
58
|
+
git clone https://github.com/supranational/blst.git .blst
|
|
59
|
+
cd .blst/bindings/python
|
|
60
|
+
./run.me
|
|
61
|
+
# Then ensure the generated blst.py and shared library are in your PYTHONPATH or site-packages
|
|
62
|
+
export PYTHONPATH=YOUR_PATH_HERE/blst/bindings/python:$PYTHONPATH
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Example Usage
|
|
66
|
+
```python
|
|
67
|
+
# Sample test vector
|
|
68
|
+
secret_key="3d6406500d4009fdf2604546093665911e753f2213570a29521fd88bc30ede18"
|
|
69
|
+
alpha=""
|
|
70
|
+
salt=""
|
|
71
|
+
add=""
|
|
72
|
+
ring_pks="7b32d917d5aa771d493c47b0e096886827cd056c82dbdba19e60baa8b2c60313d3b1bdb321123449c6e89d310bc6b7f654315eb471c84778353ce08b951ad471561fdb0dcfb8bd443718b942f82fe717238cbcf8d12b8d22861c8a09a984a3c5a1b1da71cc4682e159b7da23050d8b6261eb11a3247c89b07ef56ccd002fd38b4fd11f89c2a1aaefe856bb1c5d4a1fad73f4de5e41804ca2c17ba26d6e10050c86d06ee2c70da6cf2da2a828d8a9d8ef755ad6e580e838359a10accb086ae437ad6fdeda0dde0a57c51d3226b87e3795e6474393772da46101fd597fbd456c1b3f9dc0c4f67f207974123830c2d66988fb3fb44becbbba5a64143f376edc51d9"
|
|
73
|
+
```
|
|
74
|
+
### For IETF VRF
|
|
75
|
+
```python
|
|
76
|
+
from dot_ring import Bandersnatch, IETF_VRF
|
|
77
|
+
|
|
78
|
+
# Generate Proof
|
|
79
|
+
proof: IETF_VRF = IETF_VRF[Bandersnatch].proof(alpha, secret_key, add)
|
|
80
|
+
# Or from bytes
|
|
81
|
+
proof_bytes = proof.to_bytes()
|
|
82
|
+
proof: IETF_VRF = IETF_VRF[Bandersnatch].from_bytes(proof_bytes)
|
|
83
|
+
|
|
84
|
+
# Verify Proof
|
|
85
|
+
public_key = IETF_VRF[Bandersnatch].get_public_key(secret_key)
|
|
86
|
+
is_valid: bool = proof.verify(public_key, alpha, add)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### For Pedersen VRF
|
|
90
|
+
```python
|
|
91
|
+
from dot_ring import Bandersnatch, PedersenVRF
|
|
92
|
+
|
|
93
|
+
# Generate Proof
|
|
94
|
+
proof: PedersenVRF = PedersenVRF[Bandersnatch].proof(alpha, secret_key, add)
|
|
95
|
+
# Or import from bytes
|
|
96
|
+
proof_bytes = proof.to_bytes()
|
|
97
|
+
proof: PedersenVRF = PedersenVRF[Bandersnatch].from_bytes(proof_bytes)
|
|
98
|
+
|
|
99
|
+
# Verify Proof
|
|
100
|
+
# Public key is blinded in Pedersen VRF and included in the proof
|
|
101
|
+
is_valid: bool = proof.verify(alpha, add)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### For Ring VRF
|
|
105
|
+
```python
|
|
106
|
+
from dot_ring import Bandersnatch, RingVRF
|
|
107
|
+
|
|
108
|
+
# Parse keys if they are in a single byte string
|
|
109
|
+
keys_list = RingVRF[Bandersnatch].parse_keys(ring_pks)
|
|
110
|
+
|
|
111
|
+
# Generate ring root commitment
|
|
112
|
+
ring_root = RingVRF[Bandersnatch].construct_ring_root(keys_list)
|
|
113
|
+
|
|
114
|
+
# Generate Ring VRF proof
|
|
115
|
+
# producer_key is the public key corresponding to secret_key
|
|
116
|
+
producer_key = RingVRF[Bandersnatch].get_public_key(secret_key)
|
|
117
|
+
proof: RingVRF = RingVRF[Bandersnatch].proof(alpha, add, secret_key, producer_key, keys_list)
|
|
118
|
+
# Or from bytes
|
|
119
|
+
proof_bytes = proof.to_bytes() # 768 bytes ring proof
|
|
120
|
+
proof: RingVRF = RingVRF[Bandersnatch].from_bytes(proof_bytes)
|
|
121
|
+
# Verify Ring VRF Proof
|
|
122
|
+
is_valid: bool = proof.verify(alpha, add, ring_root)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
## Testing
|
|
127
|
+
|
|
128
|
+
You can run the test suite with **pytest** using `uv`:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
uv run pytest tests/
|
|
132
|
+
```
|
|
133
|
+
See [TESTING.md](./TESTING.md) for an overview of the test suite and instructions on running tests.
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
## Docker Setup
|
|
137
|
+
|
|
138
|
+
### Build the Docker Image
|
|
139
|
+
```bash
|
|
140
|
+
docker build -t dot_ring .
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Run tests inside a container
|
|
144
|
+
```bash
|
|
145
|
+
docker run -it dot_ring uv run pytest tests/
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Generate a Coverage report
|
|
149
|
+
- Terminal summary
|
|
150
|
+
```bash
|
|
151
|
+
docker run -it dot_ring uv run pytest tests/ --cov=dot_ring --cov-report=term-missing
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
- HTML report
|
|
155
|
+
```bash
|
|
156
|
+
docker run -it dot_ring uv run pytest tests/ --cov=dot_ring --cov-report=html
|
|
157
|
+
open htmlcov/index.html #open it in your browser
|
|
158
|
+
```
|
|
159
|
+
Access an interactive shell inside the container
|
|
160
|
+
```bash
|
|
161
|
+
docker run -it dot_ring bash
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Contact
|
|
165
|
+
|
|
166
|
+
Prasad // Chainscore Labs
|
|
167
|
+
|
|
168
|
+

|
|
169
|
+
|
|
170
|
+
[Email](mailto:prasad@chainscore.finance)
|
|
171
|
+
|
|
172
|
+
[Website](https://chainscore.finance)
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""
|
|
2
|
+
dot-ring: A Python library for Verifiable Random Functions with Additional Data (VRF-AD).
|
|
3
|
+
|
|
4
|
+
Supports 10+ elliptic curves including IETF, Pedersen VRF and Ring Proof.
|
|
5
|
+
|
|
6
|
+
Example usage:
|
|
7
|
+
>>> from dot_ring import Bandersnatch, IETF_VRF, PedersenVRF, RingVRF
|
|
8
|
+
>>>
|
|
9
|
+
>>> # IETF VRF
|
|
10
|
+
>>> proof = IETF_VRF[Bandersnatch].proof(alpha, secret_key, additional_data)
|
|
11
|
+
>>> is_valid = proof.verify(public_key, alpha, additional_data)
|
|
12
|
+
>>>
|
|
13
|
+
>>> # Pedersen VRF
|
|
14
|
+
>>> proof = PedersenVRF[Bandersnatch].proof(alpha, secret_key, additional_data)
|
|
15
|
+
>>> is_valid = proof.verify(alpha, additional_data)
|
|
16
|
+
>>>
|
|
17
|
+
>>> # Ring VRF
|
|
18
|
+
>>> ring_root = RingVRF[Bandersnatch].construct_ring_root(keys_list)
|
|
19
|
+
>>> proof = RingVRF[Bandersnatch].proof(alpha, ad, secret_key, producer_key, keys)
|
|
20
|
+
>>> is_valid = proof.verify(alpha, ad, ring_root)
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
__version__ = "0.1.0"
|
|
24
|
+
|
|
25
|
+
# =============================================================================
|
|
26
|
+
# VRF Implementations
|
|
27
|
+
# =============================================================================
|
|
28
|
+
from dot_ring.vrf.ietf.ietf import IETF_VRF
|
|
29
|
+
from dot_ring.vrf.pedersen.pedersen import PedersenVRF
|
|
30
|
+
from dot_ring.vrf.ring.ring_vrf import RingVRF
|
|
31
|
+
|
|
32
|
+
# =============================================================================
|
|
33
|
+
# Curve Variants - Primary curves
|
|
34
|
+
# =============================================================================
|
|
35
|
+
from dot_ring.curve.specs.bandersnatch import Bandersnatch
|
|
36
|
+
from dot_ring.curve.specs.bandersnatch_sw import Bandersnatch_SW
|
|
37
|
+
from dot_ring.curve.specs.ed25519 import Ed25519_RO, Ed25519_NU
|
|
38
|
+
from dot_ring.curve.specs.ed448 import Ed448_RO, Ed448_NU
|
|
39
|
+
from dot_ring.curve.specs.curve25519 import Curve25519_RO, Curve25519_NU
|
|
40
|
+
from dot_ring.curve.specs.curve448 import Curve448_RO, Curve448_NU
|
|
41
|
+
|
|
42
|
+
# NIST curves
|
|
43
|
+
from dot_ring.curve.specs.p256 import P256_RO, P256_NU
|
|
44
|
+
from dot_ring.curve.specs.p384 import P384_RO, P384_NU
|
|
45
|
+
from dot_ring.curve.specs.p521 import P521_RO, P521_NU
|
|
46
|
+
from dot_ring.curve.specs.secp256k1 import Secp256k1_RO, Secp256k1_NU
|
|
47
|
+
|
|
48
|
+
# ZK-friendly curves
|
|
49
|
+
from dot_ring.curve.specs.baby_jubjub import BabyJubJub
|
|
50
|
+
from dot_ring.curve.specs.jubjub import JubJub
|
|
51
|
+
|
|
52
|
+
# BLS12-381 curves
|
|
53
|
+
from dot_ring.curve.specs.bls12_381_G1 import BLS12_381_G1_RO, BLS12_381_G1_NU
|
|
54
|
+
from dot_ring.curve.specs.bls12_381_G2 import BLS12_381_G2_RO, BLS12_381_G2_NU
|
|
55
|
+
|
|
56
|
+
# =============================================================================
|
|
57
|
+
# Convenience aliases
|
|
58
|
+
# =============================================================================
|
|
59
|
+
Ed25519 = Ed25519_RO
|
|
60
|
+
Ed448 = Ed448_RO
|
|
61
|
+
Curve25519 = Curve25519_RO
|
|
62
|
+
Curve448 = Curve448_RO
|
|
63
|
+
P256 = P256_RO
|
|
64
|
+
P384 = P384_RO
|
|
65
|
+
P521 = P521_RO
|
|
66
|
+
Secp256k1 = Secp256k1_RO
|
|
67
|
+
BLS12_381_G1 = BLS12_381_G1_RO
|
|
68
|
+
BLS12_381_G2 = BLS12_381_G2_RO
|
|
69
|
+
|
|
70
|
+
# =============================================================================
|
|
71
|
+
# Public API
|
|
72
|
+
# =============================================================================
|
|
73
|
+
__all__ = [
|
|
74
|
+
# Version
|
|
75
|
+
"__version__",
|
|
76
|
+
# VRF implementations
|
|
77
|
+
"IETF_VRF",
|
|
78
|
+
"PedersenVRF",
|
|
79
|
+
"RingVRF",
|
|
80
|
+
# Primary curves
|
|
81
|
+
"Bandersnatch",
|
|
82
|
+
"Bandersnatch_SW",
|
|
83
|
+
"Ed25519",
|
|
84
|
+
"Ed25519_RO",
|
|
85
|
+
"Ed25519_NU",
|
|
86
|
+
"Ed448",
|
|
87
|
+
"Ed448_RO",
|
|
88
|
+
"Ed448_NU",
|
|
89
|
+
"Curve25519",
|
|
90
|
+
"Curve25519_RO",
|
|
91
|
+
"Curve25519_NU",
|
|
92
|
+
"Curve448",
|
|
93
|
+
"Curve448_RO",
|
|
94
|
+
"Curve448_NU",
|
|
95
|
+
# NIST curves
|
|
96
|
+
"P256",
|
|
97
|
+
"P256_RO",
|
|
98
|
+
"P256_NU",
|
|
99
|
+
"P384",
|
|
100
|
+
"P384_RO",
|
|
101
|
+
"P384_NU",
|
|
102
|
+
"P521",
|
|
103
|
+
"P521_RO",
|
|
104
|
+
"P521_NU",
|
|
105
|
+
"Secp256k1",
|
|
106
|
+
"Secp256k1_RO",
|
|
107
|
+
"Secp256k1_NU",
|
|
108
|
+
# ZK-friendly curves
|
|
109
|
+
"BabyJubJub",
|
|
110
|
+
"JubJub",
|
|
111
|
+
# BLS12-381
|
|
112
|
+
"BLS12_381_G1",
|
|
113
|
+
"BLS12_381_G1_RO",
|
|
114
|
+
"BLS12_381_G1_NU",
|
|
115
|
+
"BLS12_381_G2",
|
|
116
|
+
"BLS12_381_G2_RO",
|
|
117
|
+
"BLS12_381_G2_NU",
|
|
118
|
+
]
|
|
File without changes
|