Module: ezkl_utils
Library containing utility functions related to EZKL and the EZKL Proof Service.
EZKLProof
Bases: BaseModel
All of the artifacts needed to verify a proof.
Attributes:
Name | Type | Description |
---|---|---|
ezkl_proof |
Dict[str, Any]
|
Proof dictionary as generated by ezkl |
witness |
Dict[str, Any]
|
Witness used to generate the proof |
verify_key |
Optional[bytes]
|
Verification key used to verify the proof. Available if a new setup has been done, otherwise None |
input |
Optional[List[float]]
|
Input data |
output |
Optional[List[float]]
|
Output data |
flops |
Optional[float]
|
Number of FLOPS in the model |
ezkl_proof_path |
Optional[Path]
|
Path to the proof file |
witness_path |
Optional[Path]
|
Path to the witness file |
settings_path |
Optional[Path]
|
Path to the settings file |
vk_path |
Optional[Path]
|
Path to the verification |
Source code in src/infernet_ml/zk/ezkl/ezkl_utils.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
from_files(proof_path, witness_path, settings_path, flops=None, vk_path=None)
classmethod
Create an EZKLProof object from the files generated by EZKL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
proof_path |
Path
|
Path to the proof file |
required |
witness_path |
Path
|
Path to the witness file |
required |
settings_path |
Path
|
Path to the settings file |
required |
flops |
Optional[float]
|
Number of FLOPS in the model. |
None
|
vk_path |
Optional[Path]
|
Path to the verification key file. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
EZKLProof |
EZKLProof
|
EZKLProof object |
Source code in src/infernet_ml/zk/ezkl/ezkl_utils.py
from_proof_and_verify_key(proof, verify_key, proof_directory=DEFAULT_PROOFS_DIRECTORY)
classmethod
Create an EZKLProof object from the proof and verification key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
proof |
Dict[str, Any]
|
Proof dictionary |
required |
verify_key |
bytes | str
|
Verification key |
required |
proof_directory |
Path
|
Directory to store the proof. Defaults to ~/.cache/ritual/proofs. |
DEFAULT_PROOFS_DIRECTORY
|
Returns:
Name | Type | Description |
---|---|---|
EZKLProof |
EZKLProof
|
EZKLProof object |
Source code in src/infernet_ml/zk/ezkl/ezkl_utils.py
ProofGenerationArgs
Bases: BaseModel
Arguments for generating the proof.
Attributes:
Name | Type | Description |
---|---|---|
compiled_path |
Path
|
Path to the compiled model |
settings_path |
Path
|
Path to the settings |
Source code in src/infernet_ml/zk/ezkl/ezkl_utils.py
generate_proof(artifact_files, input_data, output_data=None, prover_key=None, proof_directory=DEFAULT_PROOFS_DIRECTORY)
async
Generate a proof for the model. If a verifier
Parameters:
Name | Type | Description | Default |
---|---|---|---|
artifact_files |
EZKLArtifact
|
Paths to the various artifacts generated by EZKL |
required |
input_data |
ONNXInput
|
Input data for the model |
required |
output_data |
Optional[ndarray]
|
Output data for the model. Defaults to None. |
None
|
prover_key |
Optional[bytes]
|
Provide a prover key to generate the proof. Defaults to None. If it is not provided, a new circuit setup will happen & a new prover key will be generated. |
None
|
proof_directory |
Optional[Path]
|
Directory to store the proof. Defaults to ~/.cache/ritual/proofs. |
DEFAULT_PROOFS_DIRECTORY
|
Returns:
Name | Type | Description |
---|---|---|
EZKLProof |
EZKLProof
|
Proof and verification key |
Source code in src/infernet_ml/zk/ezkl/ezkl_utils.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
generate_proof_from_repo_id(repo_id, input_vector, hf_token=None)
async
Generate a proof for the model using the provided repo_id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo_id |
str | RitualRepoId
|
Repo ID for the model |
required |
input_vector |
FloatNumpy
|
Input vector for the model |
required |
hf_token |
Optional[str]
|
Hugging Face API token, optional |
None
|
Returns:
Name | Type | Description |
---|---|---|
EZKLProof |
EZKLProof
|
Proof and verification |
Source code in src/infernet_ml/zk/ezkl/ezkl_utils.py
get_proof_dir_and_path(proof, proofs_directory=DEFAULT_PROOFS_DIRECTORY)
Get the proof directory and path for the proof. Prune old items in the proof directory to avoid filling up the disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
proof |
Dict[str, Any]
|
Proof dictionary |
required |
proofs_directory |
Path
|
Directory to store the proof. Defaults to ~/.cache/ritual/proofs. |
DEFAULT_PROOFS_DIRECTORY
|
Returns:
Type | Description |
---|---|
tuple[Path, Path]
|
tuple[Path, Path]: Proof directory and path |
Source code in src/infernet_ml/zk/ezkl/ezkl_utils.py
verify_proof(proof, artifact_files)
async
Verify a proof using the provided artifacts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
proof |
EZKLProof
|
Proof to verify |
required |
artifact_files |
EZKLArtifact
|
Paths to the various artifacts generated |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the proof is valid, False otherwise |