mirror of
https://github.com/MPCStats/zk-stats-demo.git
synced 2026-01-08 05:13:51 -05:00
- add generate_data_commitment.ipynb for data providers to commit to data - change template.ipynb - support commitment and selected columns - print srs path. need to copy the srs from the path under `assets/out` to make verifyProof work - modify page.tsx to work with generated data
359 lines
30 KiB
Plaintext
359 lines
30 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Requirement already satisfied: torch in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (2.2.2)\n",
|
|
"Requirement already satisfied: zkstats==0.1.5 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (0.1.5)\n",
|
|
"Requirement already satisfied: click<9.0.0,>=8.1.7 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from zkstats==0.1.5) (8.1.7)\n",
|
|
"Requirement already satisfied: ezkl==9.1.0 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from zkstats==0.1.5) (9.1.0)\n",
|
|
"Requirement already satisfied: matplotlib<4.0.0,>=3.8.2 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from zkstats==0.1.5) (3.8.3)\n",
|
|
"Requirement already satisfied: numpy<2.0.0,>=1.26.2 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from zkstats==0.1.5) (1.26.4)\n",
|
|
"Requirement already satisfied: onnx<2.0.0,>=1.15.0 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from zkstats==0.1.5) (1.15.0)\n",
|
|
"Requirement already satisfied: requests<3.0.0,>=2.31.0 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from zkstats==0.1.5) (2.31.0)\n",
|
|
"Requirement already satisfied: scipy<2.0.0,>=1.11.4 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from zkstats==0.1.5) (1.12.0)\n",
|
|
"Requirement already satisfied: statistics<2.0.0,>=1.0.3 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from zkstats==0.1.5) (1.0.3.5)\n",
|
|
"Requirement already satisfied: filelock in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from torch) (3.13.1)\n",
|
|
"Requirement already satisfied: typing-extensions>=4.8.0 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from torch) (4.10.0)\n",
|
|
"Requirement already satisfied: sympy in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from torch) (1.12)\n",
|
|
"Requirement already satisfied: networkx in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from torch) (3.2.1)\n",
|
|
"Requirement already satisfied: jinja2 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from torch) (3.1.3)\n",
|
|
"Requirement already satisfied: fsspec in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from torch) (2024.2.0)\n",
|
|
"Requirement already satisfied: contourpy>=1.0.1 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from matplotlib<4.0.0,>=3.8.2->zkstats==0.1.5) (1.2.0)\n",
|
|
"Requirement already satisfied: cycler>=0.10 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from matplotlib<4.0.0,>=3.8.2->zkstats==0.1.5) (0.12.1)\n",
|
|
"Requirement already satisfied: fonttools>=4.22.0 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from matplotlib<4.0.0,>=3.8.2->zkstats==0.1.5) (4.49.0)\n",
|
|
"Requirement already satisfied: kiwisolver>=1.3.1 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from matplotlib<4.0.0,>=3.8.2->zkstats==0.1.5) (1.4.5)\n",
|
|
"Requirement already satisfied: packaging>=20.0 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from matplotlib<4.0.0,>=3.8.2->zkstats==0.1.5) (23.2)\n",
|
|
"Requirement already satisfied: pillow>=8 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from matplotlib<4.0.0,>=3.8.2->zkstats==0.1.5) (10.2.0)\n",
|
|
"Requirement already satisfied: pyparsing>=2.3.1 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from matplotlib<4.0.0,>=3.8.2->zkstats==0.1.5) (3.1.1)\n",
|
|
"Requirement already satisfied: python-dateutil>=2.7 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from matplotlib<4.0.0,>=3.8.2->zkstats==0.1.5) (2.9.0.post0)\n",
|
|
"Requirement already satisfied: protobuf>=3.20.2 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from onnx<2.0.0,>=1.15.0->zkstats==0.1.5) (4.25.3)\n",
|
|
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from requests<3.0.0,>=2.31.0->zkstats==0.1.5) (3.3.2)\n",
|
|
"Requirement already satisfied: idna<4,>=2.5 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from requests<3.0.0,>=2.31.0->zkstats==0.1.5) (3.6)\n",
|
|
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from requests<3.0.0,>=2.31.0->zkstats==0.1.5) (2.2.1)\n",
|
|
"Requirement already satisfied: certifi>=2017.4.17 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from requests<3.0.0,>=2.31.0->zkstats==0.1.5) (2024.2.2)\n",
|
|
"Requirement already satisfied: docutils>=0.3 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from statistics<2.0.0,>=1.0.3->zkstats==0.1.5) (0.20.1)\n",
|
|
"Requirement already satisfied: MarkupSafe>=2.0 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from jinja2->torch) (2.1.5)\n",
|
|
"Requirement already satisfied: mpmath>=0.19 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from sympy->torch) (1.3.0)\n",
|
|
"Requirement already satisfied: six>=1.5 in /Users/mhchia/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages (from python-dateutil>=2.7->matplotlib<4.0.0,>=3.8.2->zkstats==0.1.5) (1.16.0)\n",
|
|
"\n",
|
|
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
|
|
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
|
|
"Note: you may need to restart the kernel to use updated packages.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"%pip install torch zkstats==0.1.5"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import os\n",
|
|
"from zkstats.core import (\n",
|
|
" prover_gen_settings,\n",
|
|
" prover_gen_proof,\n",
|
|
" setup,\n",
|
|
" verifier_verify,\n",
|
|
")\n",
|
|
"from zkstats.computation import computation_to_model\n",
|
|
"\n",
|
|
"cwd = os.getcwd()\n",
|
|
"\n",
|
|
"# FIXME: fill this in with the path to your data\n",
|
|
"data_path = f\"{cwd}/data.json\"\n",
|
|
"\n",
|
|
"# Paths to the output files\n",
|
|
"output_dir = f\"{cwd}/out\"\n",
|
|
"os.makedirs(output_dir, exist_ok=True)\n",
|
|
"model_onnx_path = f\"{output_dir}/model.onnx\"\n",
|
|
"compiled_model_path = f\"{output_dir}/model.compiled\"\n",
|
|
"\n",
|
|
"pk_path = f\"{output_dir}/model.pk\"\n",
|
|
"vk_path = f\"{output_dir}/model.vk\"\n",
|
|
"proof_path = f\"{output_dir}/model.pf\"\n",
|
|
"settings_path = f\"{output_dir}/settings.json\"\n",
|
|
"witness_path = f\"{output_dir}/witness.json\"\n",
|
|
"comb_data_path = f\"{output_dir}/comb_data.json\"\n",
|
|
"data_commitment_path = f\"{output_dir}/data_commitment.json\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Columns selected by the user"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# FIXME: this should be provided by users\n",
|
|
"selected_columns = [\"x\", \"y\"]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## User-defined Computation\n",
|
|
"\n",
|
|
"A computation should be of type `TComputation`. For example, the following code snippet defines a computation that computes the sum of the private data.\n",
|
|
"\n",
|
|
"```python\n",
|
|
"def computation(state: State, x: list[torch.Tensor]):\n",
|
|
" out_0 = state.median(x[0])\n",
|
|
" out_1 = state.median(x[1])\n",
|
|
" return state.mean(torch.tensor([out_0, out_1]).reshape(1,-1,1))\n",
|
|
"```\n",
|
|
"\n",
|
|
"FIXME: The following code snippet is entirely from the user. You MUST check\n",
|
|
"1. the code only performs zkstats-related operations.\n",
|
|
"2. the computation must not leak any information about the private data."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# This is just a dummy computation. Replace it with user's computation\n",
|
|
"import torch\n",
|
|
"from zkstats.computation import State\n",
|
|
"\n",
|
|
"def computation(state: State, x: list[torch.Tensor]):\n",
|
|
" out_0 = state.median(x[0])\n",
|
|
" out_1 = state.median(x[1])\n",
|
|
" return state.mean(torch.tensor([out_0, out_1]).reshape(1,-1,1))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Generate settings and setup with user's computation."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/var/folders/t3/5psrvr1x0w1_6n9kx2n7d9700000gn/T/ipykernel_22219/2234676788.py:8: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.\n",
|
|
" return state.mean(torch.tensor([out_0, out_1]).reshape(1,-1,1))\n",
|
|
"/var/folders/t3/5psrvr1x0w1_6n9kx2n7d9700000gn/T/ipykernel_22219/2234676788.py:8: TracerWarning: Converting a tensor to a Python float might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!\n",
|
|
" return state.mean(torch.tensor([out_0, out_1]).reshape(1,-1,1))\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"==== Generate & Calibrate Setting ====\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
"\n",
|
|
" <------------- Numerical Fidelity Report (input_scale: 11, param_scale: 11, scale_input_multiplier: 10) ------------->\n",
|
|
"\n",
|
|
"+----------------+----------------+-----------+----------------+----------------+------------------+---------------+---------------+--------------------+--------------------+------------------------+\n",
|
|
"| mean_error | median_error | max_error | min_error | mean_abs_error | median_abs_error | max_abs_error | min_abs_error | mean_squared_error | mean_percent_error | mean_abs_percent_error |\n",
|
|
"+----------------+----------------+-----------+----------------+----------------+------------------+---------------+---------------+--------------------+--------------------+------------------------+\n",
|
|
"| -0.00004863739 | -0.00009727478 | 0 | -0.00009727478 | 0.00004863739 | 0.00009727478 | 0.00009727478 | 0 | 0.0000000047311914 | -0.000001957239 | 0.000001957239 |\n",
|
|
"+----------------+----------------+-----------+----------------+----------------+------------------+---------------+---------------+--------------------+--------------------+------------------------+\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"scale: default\n",
|
|
"setting: {\"run_args\":{\"tolerance\":{\"val\":0.0,\"scale\":1.0},\"input_scale\":11,\"param_scale\":11,\"scale_rebase_multiplier\":10,\"lookup_range\":[-219952,192922],\"logrows\":19,\"num_inner_cols\":2,\"variables\":[[\"batch_size\",1]],\"input_visibility\":{\"Hashed\":{\"hash_is_public\":true,\"outlets\":[]}},\"output_visibility\":\"Public\",\"param_visibility\":\"Private\",\"div_rebasing\":false,\"rebase_frac_zero_constants\":false,\"check_mode\":\"UNSAFE\"},\"num_rows\":2624,\"total_assignments\":735,\"total_const_size\":152,\"model_instance_shapes\":[[1],[1]],\"model_output_scales\":[0,11],\"model_input_scales\":[11,11],\"module_sizes\":{\"kzg\":[],\"poseidon\":[2624,[2]]},\"required_lookups\":[{\"Floor\":{\"scale\":2.0}},\"ReLU\",{\"GreaterThan\":{\"a\":0.0}}],\"required_range_checks\":[],\"check_mode\":\"UNSAFE\",\"version\":\"9.1.0\",\"num_blinding_factors\":null,\"timestamp\":1712764579432}\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"_, model = computation_to_model(computation)\n",
|
|
"prover_gen_settings(\n",
|
|
" data_path,\n",
|
|
" selected_columns,\n",
|
|
" comb_data_path,\n",
|
|
" model,\n",
|
|
" model_onnx_path,\n",
|
|
" \"default\",\n",
|
|
" \"resources\",\n",
|
|
" settings_path,\n",
|
|
")\n",
|
|
"\n",
|
|
"# Determine which srs to use with the logrows in the settings.json\n",
|
|
"with open(settings_path, \"r\") as f:\n",
|
|
" settings = json.load(f)\n",
|
|
"logrows = int(settings[\"run_args\"][\"logrows\"])\n",
|
|
"srs_path = f'~/.ezkl/srs/kzg{logrows}.srs'"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"==== setting up ezkl ====\n",
|
|
"Time setup: 89.43912076950073 seconds\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"setup(model_onnx_path, compiled_model_path, settings_path, vk_path, pk_path)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Generate proof with your data and user's computation."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"==== Generating Witness ====\n",
|
|
"witness boolean: 1.0\n",
|
|
"witness result 1 : 24.85009765625\n",
|
|
"==== Generating Proof ====\n",
|
|
"proof: {'instances': [['4e29ced39e0837ccc54303617bee3278416698caa1099040db7586054c726819', '376d1c5357b7dca3dd77e4cd0cf36c71138900d41c115776af27ccb92d2f742e', '0100000000000000000000000000000000000000000000000000000000000000', 'cdc6000000000000000000000000000000000000000000000000000000000000']], 'proof': '0x027b20205bcca52008ce7af7dbc9c1e0828a3a1a84f7cc330e78a074176100732202e716004915bb4a17d143678fc821dad3d642d0971074016fbde229f77f20157b2b28784f04fba0f796ebe0e51d6de1c6780077d69509d0821d875cc9bd6322ac237ee28a4c289476a4ca1e1c662fbdd4ec166c82a4ef305d18d4c0ce7f9529e988d0efb45efec5f723bdeb9df37f9cc6249d88d35c1ac335b41f855426a6225026ba19763918961cc971bc334d3d230f7a597edc6ecb97fa9803a12da34e2247cdd4e037b029a338562b5c1f38c87104f1007d8ffd3b69eb840dd124ea0803567a5804195c19927d448b269179300893fc7c0c04c69820e5550d9ee89622049a45a972e6d509314746c8beff7f55c7b16b31076ef48190e70d63b9f66f3826006698a06de570c3ad5d41049d909a95db0515e9d4c41f5b608f0b290ff19d0081afe3078844c58e5418ea0da521ee2ce9f64bd4a29ad6fad04ae441009663298ef6a76bcfac87601c60212d5c287fcc6aace4b0b76ed2625e25a3d73c643611d98b3380ab567fcb701b34abd6b867bbe6863db5e61b6f0884c76b78001f7d10ac1e8842409732b541bdab8fee2288ff2c2a9a3950c7eef934bdc496b0783a03ffbaa4ebbe808b8e73677a094a33706226da76c6d245a7fc24094c6b6ecbd621ce8513e3049fd596aabd434df8f3374a7ab6c9a67ab485f91d821c102eac7d2e9c7e11679b4a55f6683c85db7b49c39bf4a613a37f6838c5472f639385ca831d22f2d86b76382cff4c915900e12c7b88d39d7858d19c4a84e7afa780d536e20acb3311d700e56a0c9d7c3676a8b5b132bf8a8ebec305b0e2d6939cb41b3e1d1aeb7ca8c075cf71b1517d79e51e26b747438509d80cf4bd7bac5f668da4605f0acb3311d700e56a0c9d7c3676a8b5b132bf8a8ebec305b0e2d6939cb41b3e1d1aeb7ca8c075cf71b1517d79e51e26b747438509d80cf4bd7bac5f668da4605f0932d9094ea9fd53bb51f8cb645fef7b61b61d5d218d20b015e35903e89f6705171eb73ea5ad64c03652e0e4540e57f1c93f740ee5b926109182908e786dd4490b41e1744d8cd85d168a21256b23a7c91ab8bc4d31126e16559f2e1dddebd751019dc0f416bb0a845834db997583dbec482fe24fae214f7275e7dcd06ae067461606294b37cb5b04efba1a04885fa1c291dad0c5a839b346662412634329d5190933caab4beddbeb22bf6415d4eccb2f1abba1e7c8e5600d4d394f3bad7ee830197468585d8f46981beedf9cc068c44f5f2f6f75e5f6aeec3cc57c753213838f1a1da563b21fedbde6d7bd3e5fa9ee7abccdbf6e2eb3fcfb451453e4d333832914fbf1ac65923179f4987e9b439be89accd4ad289f94996ee826c4d029360dd41bd41790c5a660fad04ae4567d1f28af19d2d974e442821d9a1c610b1e4948741c0caf21167d6f0bd19cde0056098ae35bac4acf256a5227777ae9ec539e519d249ba19551e6e6297a4a8b2af2257241f65e99cc20ecfb39ca1c909447de8e3e28e1cacba1774214eeb184c1582756de71caae267752bb57bae67bb35cfeeb182f43e03770bd8c96f6c069e6b20805ee6f8dd6031e217aba116aad6e9a396f1f12306490f1e9c84350eb51e608f677497e18da07682db71eb6de75a29ecb97a8003394185d54450df8e12a54264db246bb1945df2d31b3709ddcaf98f5a54e72177102348bed0cd9ad05057c2c164ddaf43066a72bd1d6f1ea6698d692f922762c0b46086214e58c161fc9f8ce17c488354f4880b7e85a23e4e2e89193c7ef4015dc31f856e000ef0a3ff39681656d1ae6fe0c449d1ad8e99e68432f14e050560d9ba7b4940cff4208f36bb6459aa35725919b48d5c57f0593bedbb7a53237cf16d799412b9d3bb1baf7194698faaaea851ad212c6503d9e6f33dbd3576a3033202162ed785e3439d6a9fc9ff4e15f1bf8b7abdce153effb52e38ac40794d5cf054a6750505b33a8635f87085deeee89ab3d2dad8a1c355a322fa9c3fe0edc650d71eba177dfb05fdf2385746fa77b57ec4dd6d5711c2d569493b5a73c1c5c00116492ae62f3fa57923e883e6728110ef206288c9a9934aa7a8ebc3fbe782bfe101ac33296bb227ac7f3082f526a10de101dc80846dc42fcd3a01dc5ea421716203262efc1ae61bbcfc96974243198f100b2df5c7a061c3c83a42f14f2719a823014a15b6b8d4acf1ad7cc1d1ec259820bbcad0cb2467c0dc2080e81561bcc900bdba41276d4f63625772a45b779ca94d48fe99e5c0a837c6a43e02dd32ed3ae0750151ee632d01bc6a6a1f0f1725b8b44baf16910d9f690f39520259a27ae031e2f64b3cafa957bf17748422d5f21ea7c6efbe029539c36aa6b58cbb84b0b9519c037cf5850f141dc8ef877ce912db3fdecf56549d0ad35cc8d9226c4cc54700953aad4268154d99f274061ac1c29a823d903cf7defc473b07ecfbda50fb04814e56a31966b89b210cbabef171315d23035c0c279a6f0d52bbbe1bb2ff3033d1d6c2d18ba63160808f436d5b0f5afe1898292d51b6af14a43e2d82d38ea542f1e06b47d7f7947502821152b0bd92ee36129a8ed5210053083e4bc01f0eedb211f7cb96ecf306308ed8c1aefa5bbf677099be4516194b59b5f26542dc774e7c90e63c8eae4fcaabd2fe5203456d82c538381173747fd5791b80341139a4191f92bb805c794aa1bfd5da17951b1168121fd57734a2cbda10685831752d53d7e5326340c95ad3b5dcd8155505f924ee1759245aaf8f274e9348e87f4a1bc4be5250d433a9885b7a1a919ceda4cdda05bdccd5a3c5fb6a8fe553ad8ef741277c7060ae491542cd0db1058bec100d873a915c821bc3593806cce4d58c5e5d1ab64a8150611e23af3734f14838f1f6620c68e3620439e4de65bf825b078cb094f76db2f7d8066c6e597b89a6b41865f7d7890c61278f4fda174f7d91cf97ada1f168b2c2dec553492fc725668a494df18fc94feac05a6280f0d7750945a92178e4a6c0adc69e1e7fbfe899e3daa3c8d3ff1903e615fb89967fe4e760acbe4e4a7bb2510bb4ba4b15b382dc2a3b41d3eb0508dd1821c3926c0ad67c48d371423a747dd2f80ae9ac691201ef41a30eed940a716a9ec5c51927c32f5591c9c31336493772bd302e9cad22a7f00d2695a06b1893719dfbaede4fc3a842725bf0e624e2c2e1a2393533e8902a2d4f0658720aabdce09eaf54a1d30718b4bbb01f25f8443e12a63bf7e0158146e51473bc5d6ae3780ed829ffa070776422f94b84cbe0b1dd62627cdde5888001671099147c59e68893d493808f8a8db5be6135f45fc3140b41cbdc1cfa4006d6e357b2ae9786769f618f6dce06fdec358a85bb6ce59d80a632d4ecf338e4db38cf6ab0367e2d268746acf351262aee57499d9e4d841f96d0e10787c0b31b6b505a9e641f3bc2abe1bc4e95b0d3ab67ad162dea1a9bfecb1901665a23aa17ea9958ca3fd1f6670e0df04c217d58ce4125a82b840bd0ad118e31e98cf9a07c872c4c46370f69a430460d84823cdaf52a60186c2e4b94a2e05250bb4103a09129d4d9d2c8580553b5f9d28e6dbbdf8e3ff601ce04ce61fe9c39915636383a26b2596030ef6f990bf098b3bf3d378ea9361e33330213a7538a4f8267820f1b2afeaf0937a8af39be518e184cbce201e000fb4f2eab6ed6fd5eb72217e69a9fd748ea359fd243183a423e29972c35e7047e343f7692b034fd5f3c300e895457e36d3811886621c04ca9556943ad3eb6ba3ccf73f37efcb48d11b5805c77562e0f0f3c5ba6bf02f6f6c57b1b8bf9316b0afe41268531ba1a13c30020856e4560b43ef77c8d714dc9da31422e5c425896c76b467ef77d73304b7fbb31b6a3ddea9d96de50553d4aef6d4a328649a9e6874996dc5f59c57e9c00ab16d0285e78e4377d89c569e54f2184bb70c5bf97727aa1176db86998c4f6a4fd753000000000000000000000000000000000000000000000000000000000000000028b631501d61324753b83ff408e9c7214cbbb2f74e2667ba307c38cbb7c3e5651815a819eef041f5c4f200d273629a2330b5c05efbe03a5de5db7333f8582c7900000000000000000000000000000000000000000000000000000000000000000e78f94fc8fa8469e112f0910aea479713ec67a10be4f5b96fcfc9c5367e6ed91907555615c4c283c7f844d62b39a502d0743801a6efbb26db52226cabe5267226c581c19c5f247a53be1433f92214ab51604df9ba53a39915bd65e76bebe4f70000000000000000000000000000000000000000000000000000000000000000264f9787caefca476f19458eecd1866a3d9ce23cfd8acb9bee6fa4e2c9256d05069f8dad657f296540d3ba34c72e6a8ec8f5501b1bbe196903274a673ae39a2d000000000000000000000000000000000000000000000000000000000000000011e5b95bc0a10106489892b3a426d294909d3217ecc468dfee22632ae1460eda00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000372d0281b9e8c0c7fa5a7560f7e760c15436b55e7119b3f17a57656984d6b3522754e4d774a732516726ccc3e528080bdfa4bceef1ea200c8e2ef7fddb23745215db6d338c7d4be0353780ea738f235e97406a55faa007543d5f562f7ecf1322b18a847428152c284f9dff57c93b2f2694a351df297fd3557c440b861979b420e7f9a9a33b964330a3bd9dabc8f16d0743e8e4ef5d4b490aa2a1261348c22ef05b5089776b6fcae5a3aaef53b850abf806ae702ecfd2f8221fbca2bf7c8d9501621a0519b4218558c1ea18ab64595532bdda4406a8d408f844349f7c5364a7e08ac3f94f1c4efb9da15586924985534651aa2a95ecc0462b79a1cb6d5706ee22bd0e036788541012a24ecb75425a968dcf4066ea560d8ab6100c2176eb939292f7464fccea486cfb06bc2e6c0b5f6b944b7088fcfdc290b0a43a45864c9f06129450d8c86b7cb8bc8bbf545d13398a15bd3de5846c148e8975826036155f96812fa06483477c73635e5acf50ba4446de2f68ccae4907c1ed675d07f4ff75c5d20a734dbefe05d689f7374dcbe0a2fd45b586b239a4a3ff1e3d59d4c57849bcb20b9b8628d264a97fd8ef06d31f9a473f9e1514695a006ebb058f1c032e703920f428055a7e4b55268043b78156036d5e12692712e3f28ab26906e57917761c01bf7a5e7ad7873a9bc667f3f056a8d769a791ac61bab3824a452deeb26e6d7a12e21d65bc0da68ddbd9b86fa05ffa797ab6fed031ee6bbab596a3f08a7f414c6039df3aaf143491d7e3664cb20ae4d104c3ddf63fc22963216c0652d3cfb6d3e129d3bc42d7eed22d05e7ce3542b27a0b4c0a0ccdfa457fba2f371f9dcbd26430ac864b327a630400d55ae91536fb7d04d21a8790f1c2a9f02aacd9820d6272f19045de066f8d6cfeee226b9e2d1e3fa6b6af0a65da022b0786904f089f5a03106bd2a318f9d0479832e66b27fbcd7057179d3e22f585b63e5ed123bbdc03bbe12d1f9129d5c656b4dba9f14d803d6638f78737acb4d95ddbfc65e5675f082d7188b9c88bfba09bc1f765d1b475a31e47cf6accdd5ba701c90ec078aaa00f296222f794cc1a062f7782ad5636c87e878ce205b8e06422c7693670b127cdf030411d7d42bacfd291cf719759dc7334791afbb8ab291357052840e5d0eeebac11f0751dd6fdaa39ee2f95ad58c6832ee0955f9347707e671291adff585d811cfb70ae58e2924c1f6bcb1468302bcfbd9e6fed363b138d5d62453763397b88fdde3245e347ddf1fcdd03a81acaaba7573096d488d3249c1302cb2b17384b0e1ee952403b7f370074cc17e9ae6c23e88fe66c13fe14d77cf1376b195ed70255f7d251f8400985728d1819b071945d9a9e15aae6fda0cb3225a7deec2344edcfc035d0ca3f345e22916401740f5775cd4c9b0db2a314a0776da6712692f1d3abd5cd12cf8e750386dbb59d149973acc81135d2af07711db5b76a8e1a1085e8484339629e55f172a4ca32650af8d3df480fa5d490be9fc6f62f0fb4253342c7e71d2650ca3f345e22916401740f5775cd4c9b0db2a314a0776da6712692f1d3abd5cd11408609c840d8286eb65a2f3dfe5599ef6c52c6303222aa8e72696dd79c63b4624e66f3ffa30aa6b83c3ae44c822a4a8ee2f2798b6b0b7d1575d6eec111cafba2de7b1e232ab8fbe22abcc9fc1dc03e445c25ed08ffbecca6c3a086222905c03077c9304dc64033c137b72ce39643a5a2dcc1e52e685bcf220891ab8ac297bb513678cbfeab35f04dea11d4df3e9c353f3a4fc08bfebc71c05079770b5ffde4603ea8e23200aa3660eb704d653e3d426fd3e8786c8850fc7fe3b38f113a5895f28de3583ce80e82a1bb1f64e1be28e412f7c6767d4590c0556be287228943c5f0c6af448bb3a704571397efeb1533de33ccbf5f9ca0566731e9d3067f1d9a38e1cbaeb735a60515ecaceb5684917a8e1994dd990dce59d41f291dcf24d52015b0bce1e9f5a41b6c8366a3164a1ce43471212780f99dc979ed6cd095ad302815c1194cf054bd787c9f5c90d8471440242eb27231af94661cf59855a550188dd7203859b37bcd5c587803912039d7aab729444cba2d6132b5f561f659ce2fe308c11eda649a21b525d94146b2fa834a1caf72481c839c47cf57ff4e61f044c164e101447b20ea2d5a6124909cb546a1d70e94f6cb2c4543429d72b7b76b748b5330ad8c05d3d4874690fe57d996bf4c770fa18885b5edcdf655a17b49dfb1d074f27b63e196b97d9d9be2828595460aaf257345aee2a94154d1c5b5d2941db9c35', 'transcript_type': 'EVM'}\n",
|
|
"Time gen prf: 105.25368404388428 seconds\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"prover_gen_proof(\n",
|
|
" model_onnx_path,\n",
|
|
" comb_data_path,\n",
|
|
" witness_path,\n",
|
|
" compiled_model_path,\n",
|
|
" settings_path,\n",
|
|
" proof_path,\n",
|
|
" pk_path,\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Verify the proof to ensure it is correct"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 17,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"ename": "FileNotFoundError",
|
|
"evalue": "[Errno 2] No such file or directory: '/Users/mhchia/projects/work/pse/demo-next/public/assets/out/data_commitment.json'",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
|
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
|
|
"Cell \u001b[0;32mIn[17], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mverifier_verify\u001b[49m\u001b[43m(\u001b[49m\u001b[43mproof_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msettings_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mvk_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mselected_columns\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdata_commitment_path\u001b[49m\u001b[43m)\u001b[49m\n",
|
|
"File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/zkstats-brXmXluj-py3.12/lib/python3.12/site-packages/zkstats/core.py:240\u001b[0m, in \u001b[0;36mverifier_verify\u001b[0;34m(proof_path, settings_path, vk_path, selected_columns, data_commitment_path)\u001b[0m\n\u001b[1;32m 237\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(proof_instance) \u001b[38;5;241m==\u001b[39m len_inputs \u001b[38;5;241m+\u001b[39m len_outputs, \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlengths mismatch: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mlen\u001b[39m(proof_instance)\u001b[38;5;132;01m=}\u001b[39;00m\u001b[38;5;124m, \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mlen_inputs\u001b[38;5;132;01m=}\u001b[39;00m\u001b[38;5;124m, \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mlen_outputs\u001b[38;5;132;01m=}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 239\u001b[0m \u001b[38;5;66;03m# 2.1 Check input commitments\u001b[39;00m\n\u001b[0;32m--> 240\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mdata_commitment_path\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m f:\n\u001b[1;32m 241\u001b[0m data_commitment \u001b[38;5;241m=\u001b[39m json\u001b[38;5;241m.\u001b[39mload(f)\n\u001b[1;32m 242\u001b[0m \u001b[38;5;66;03m# All inputs are hashed so are commitments\u001b[39;00m\n",
|
|
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '/Users/mhchia/projects/work/pse/demo-next/public/assets/out/data_commitment.json'"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"verifier_verify(proof_path, settings_path, vk_path, selected_columns, data_commitment_path)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Print the file paths. You should share the following files back to the user for them to verify the proof. You **SHOULD NOT** share more files otherwise data might be leaked."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Model onnx:\t\t /Users/mhchia/projects/work/pse/demo-next/public/assets/out/model.onnx\n",
|
|
"Settings:\t\t /Users/mhchia/projects/work/pse/demo-next/public/assets/out/settings.json\n",
|
|
"Proof:\t\t\t /Users/mhchia/projects/work/pse/demo-next/public/assets/out/model.pf\n",
|
|
"Verification key:\t /Users/mhchia/projects/work/pse/demo-next/public/assets/out/model.vk\n",
|
|
"Srs path:\t\t ~/.ezkl/srs/kzg19.srs\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(\"Model onnx:\\t\\t\", model_onnx_path)\n",
|
|
"print(\"Settings:\\t\\t\", settings_path)\n",
|
|
"print(\"Proof:\\t\\t\\t\", proof_path)\n",
|
|
"print(\"Verification key:\\t\", vk_path)\n",
|
|
"print(\"Srs path:\\t\\t\", srs_path)"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": ".venv",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.12.1"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|