mirror of
https://github.com/MPCStats/zk-stats-lib.git
synced 2026-01-08 05:04:07 -05:00
399 lines
33 KiB
Plaintext
399 lines
33 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Requirement already satisfied: ezkl==7.0.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from -r ../../requirements.txt (line 1)) (7.0.0)\n",
|
|
"Requirement already satisfied: torch in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from -r ../../requirements.txt (line 2)) (2.1.1)\n",
|
|
"Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from -r ../../requirements.txt (line 3)) (2.31.0)\n",
|
|
"Requirement already satisfied: scipy in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from -r ../../requirements.txt (line 4)) (1.11.4)\n",
|
|
"Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from -r ../../requirements.txt (line 5)) (1.26.2)\n",
|
|
"Requirement already satisfied: matplotlib in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from -r ../../requirements.txt (line 6)) (3.8.2)\n",
|
|
"Requirement already satisfied: statistics in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from -r ../../requirements.txt (line 7)) (1.0.3.5)\n",
|
|
"Requirement already satisfied: onnx in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from -r ../../requirements.txt (line 8)) (1.15.0)\n",
|
|
"Requirement already satisfied: jinja2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from torch->-r ../../requirements.txt (line 2)) (3.1.2)\n",
|
|
"Requirement already satisfied: filelock in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from torch->-r ../../requirements.txt (line 2)) (3.13.1)\n",
|
|
"Requirement already satisfied: sympy in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from torch->-r ../../requirements.txt (line 2)) (1.12)\n",
|
|
"Requirement already satisfied: networkx in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from torch->-r ../../requirements.txt (line 2)) (3.2.1)\n",
|
|
"Requirement already satisfied: fsspec in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from torch->-r ../../requirements.txt (line 2)) (2023.10.0)\n",
|
|
"Requirement already satisfied: typing-extensions in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from torch->-r ../../requirements.txt (line 2)) (4.8.0)\n",
|
|
"Requirement already satisfied: charset-normalizer<4,>=2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from requests->-r ../../requirements.txt (line 3)) (3.3.2)\n",
|
|
"Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from requests->-r ../../requirements.txt (line 3)) (2023.11.17)\n",
|
|
"Requirement already satisfied: idna<4,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from requests->-r ../../requirements.txt (line 3)) (3.6)\n",
|
|
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from requests->-r ../../requirements.txt (line 3)) (2.1.0)\n",
|
|
"Requirement already satisfied: fonttools>=4.22.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib->-r ../../requirements.txt (line 6)) (4.45.1)\n",
|
|
"Requirement already satisfied: cycler>=0.10 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib->-r ../../requirements.txt (line 6)) (0.12.1)\n",
|
|
"Requirement already satisfied: python-dateutil>=2.7 in /Users/jernkun/Library/Python/3.10/lib/python/site-packages (from matplotlib->-r ../../requirements.txt (line 6)) (2.8.2)\n",
|
|
"Requirement already satisfied: pillow>=8 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib->-r ../../requirements.txt (line 6)) (10.1.0)\n",
|
|
"Requirement already satisfied: contourpy>=1.0.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib->-r ../../requirements.txt (line 6)) (1.2.0)\n",
|
|
"Requirement already satisfied: kiwisolver>=1.3.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib->-r ../../requirements.txt (line 6)) (1.4.5)\n",
|
|
"Requirement already satisfied: pyparsing>=2.3.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib->-r ../../requirements.txt (line 6)) (3.1.1)\n",
|
|
"Requirement already satisfied: packaging>=20.0 in /Users/jernkun/Library/Python/3.10/lib/python/site-packages (from matplotlib->-r ../../requirements.txt (line 6)) (23.2)\n",
|
|
"Requirement already satisfied: docutils>=0.3 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from statistics->-r ../../requirements.txt (line 7)) (0.20.1)\n",
|
|
"Requirement already satisfied: protobuf>=3.20.2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from onnx->-r ../../requirements.txt (line 8)) (4.25.1)\n",
|
|
"Requirement already satisfied: six>=1.5 in /Users/jernkun/Library/Python/3.10/lib/python/site-packages (from python-dateutil>=2.7->matplotlib->-r ../../requirements.txt (line 6)) (1.16.0)\n",
|
|
"Requirement already satisfied: MarkupSafe>=2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from jinja2->torch->-r ../../requirements.txt (line 2)) (2.1.3)\n",
|
|
"Requirement already satisfied: mpmath>=0.19 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from sympy->torch->-r ../../requirements.txt (line 2)) (1.3.0)\n",
|
|
"\u001b[33mWARNING: You are using pip version 21.2.3; however, version 23.3.2 is available.\n",
|
|
"You should consider upgrading via the '/usr/local/bin/python3 -m pip install --upgrade pip' command.\u001b[0m\n",
|
|
"Note: you may need to restart the kernel to use updated packages.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"pip install -r ../../requirements.txt"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import ezkl\n",
|
|
"import torch\n",
|
|
"from torch import nn\n",
|
|
"import json\n",
|
|
"import os\n",
|
|
"import time\n",
|
|
"import scipy\n",
|
|
"import numpy as np\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"import statistics\n",
|
|
"import math"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"%run -i ../../zkstats/core.py"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# init path\n",
|
|
"os.makedirs(os.path.dirname('shared/'), exist_ok=True)\n",
|
|
"os.makedirs(os.path.dirname('prover/'), exist_ok=True)\n",
|
|
"verifier_model_path = os.path.join('shared/verifier.onnx')\n",
|
|
"prover_model_path = os.path.join('prover/prover.onnx')\n",
|
|
"verifier_compiled_model_path = os.path.join('shared/verifier.compiled')\n",
|
|
"prover_compiled_model_path = os.path.join('prover/prover.compiled')\n",
|
|
"pk_path = os.path.join('shared/test.pk')\n",
|
|
"vk_path = os.path.join('shared/test.vk')\n",
|
|
"proof_path = os.path.join('shared/test.pf')\n",
|
|
"settings_path = os.path.join('shared/settings.json')\n",
|
|
"srs_path = os.path.join('shared/kzg.srs')\n",
|
|
"witness_path = os.path.join('prover/witness.json')\n",
|
|
"# this is private to prover since it contains actual data\n",
|
|
"sel_data_path = os.path.join('prover/sel_data.json')\n",
|
|
"# this is just dummy random value\n",
|
|
"sel_dummy_data_path = os.path.join('shared/sel_dummy_data.json')"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"======================= ZK-STATS FLOW ======================="
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 23,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"data_path = os.path.join('data.json')\n",
|
|
"dummy_data_path = os.path.join('shared/dummy_data.json')\n",
|
|
"\n",
|
|
"data = np.array(json.loads(open(data_path, \"r\").read())['col_name'])\n",
|
|
"\n",
|
|
"create_dummy(data_path, dummy_data_path)\n",
|
|
"dummy_data = np.array(json.loads(open(dummy_data_path, \"r\").read())['col_name'])\n",
|
|
"\n",
|
|
"dummy_theory_output = torch.tensor(np.median(dummy_data[dummy_data<50]))\n",
|
|
"dummy_lower_to_median = torch.tensor(np.sort(dummy_data[dummy_data<50])[int(len(dummy_data[dummy_data<50])/2)-1])\n",
|
|
"dummy_upper_to_median = torch.tensor(np.sort(dummy_data[dummy_data<50])[int(len(dummy_data[dummy_data<50])/2)])\n",
|
|
"\n",
|
|
"theory_output = torch.tensor(np.median(data[data<50]))\n",
|
|
"lower_to_median = torch.tensor(np.sort(data[data<50])[int(len(data[data<50])/2)-1])\n",
|
|
"upper_to_median = torch.tensor(np.sort(data[data<50])[int(len(data[data<50])/2)])\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"scales = [2]\n",
|
|
"selected_columns = ['col_name']\n",
|
|
"commitment_maps = get_data_commitment_maps(data_path, scales)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 39,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/onnx/symbolic_opset9.py:2174: FutureWarning: 'torch.onnx.symbolic_opset9._cast_Bool' is deprecated in version 2.0 and will be removed in the future. Please Avoid using this function and create a Cast node instead.\n",
|
|
" return fn(g, to_cast_func(g, input, False), to_cast_func(g, other, False))\n",
|
|
"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/onnx/utils.py:1686: UserWarning: The exported ONNX model failed ONNX shape inference. The model will not be executable by the ONNX Runtime. If this is unintended and you believe there is a bug, please report an issue at https://github.com/pytorch/pytorch/issues. Error reported by strict ONNX shape inference: [ShapeInferenceError] (op_type:Where, node name: /Where): Y has inconsistent type tensor(float) (Triggered internally at /Users/runner/work/pytorch/pytorch/pytorch/torch/csrc/jit/serialization/export.cpp:1421.)\n",
|
|
" _C._check_onnx_proto(proto)\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# Verifier/ data consumer side: send desired calculation\n",
|
|
"class verifier_model(nn.Module):\n",
|
|
" def __init__(self):\n",
|
|
" super(verifier_model, self).__init__()\n",
|
|
" # w represents mean in this case\n",
|
|
" self.w = nn.Parameter(data = dummy_theory_output, requires_grad = False)\n",
|
|
" self.lower = nn.Parameter(data = dummy_lower_to_median, requires_grad = False)\n",
|
|
" self.upper = nn.Parameter(data = dummy_upper_to_median, requires_grad = False)\n",
|
|
" def forward(self,X):\n",
|
|
" # where part\n",
|
|
" # need to initiate num_lowest (number of values that get filtered out) before num_fil_X due to constraint behavior\n",
|
|
" filter = X<50\n",
|
|
" num_lowest = X.size()[1]-torch.sum(filter.double())\n",
|
|
" num_fil_X = X.size()[1]-num_lowest\n",
|
|
" min_X = torch.min(X)\n",
|
|
" fil_X = torch.where(filter, X, min_X-1)\n",
|
|
"\n",
|
|
" count_less = torch.sum((fil_X < 0.99*self.w).double()) - num_lowest\n",
|
|
" count_equal = torch.sum((torch.abs(fil_X-self.w)<=torch.abs(0.01*self.w)).double())\n",
|
|
" half_len = torch.floor(torch.div(num_fil_X, 2))\n",
|
|
"\n",
|
|
" # not support modulo yet\n",
|
|
" less_cons = count_less<half_len+2*(num_fil_X/2 - torch.floor(num_fil_X/2))\n",
|
|
" more_cons = count_less+count_equal>half_len\n",
|
|
"\n",
|
|
" # For count_equal == 0 --> imply even length for sure\n",
|
|
" lower_exist = torch.sum((torch.abs(fil_X-self.lower)<=torch.abs(0.01*self.lower)).double())>0\n",
|
|
" lower_cons = torch.sum((fil_X>1.01*self.lower).double())==half_len\n",
|
|
" upper_exist = torch.sum((torch.abs(fil_X-self.upper)<=torch.abs(0.01*self.upper)).double())>0\n",
|
|
" upper_cons = torch.sum((fil_X<0.99*self.upper).double()) - num_lowest==half_len\n",
|
|
" bound = count_less==half_len\n",
|
|
" # 0.02 since 2*0.01\n",
|
|
" bound_avg = (torch.abs(self.lower+self.upper-2*self.w)<=torch.abs(0.02*self.w))\n",
|
|
"\n",
|
|
" median_in_cons = torch.logical_and(less_cons, more_cons)\n",
|
|
" median_out_cons = torch.logical_and(torch.logical_and(bound, bound_avg), torch.logical_and(torch.logical_and(lower_cons, upper_cons), torch.logical_and(lower_exist, upper_exist)))\n",
|
|
"\n",
|
|
" return(torch.where(count_equal==0, median_out_cons, median_in_cons), self.w)\n",
|
|
"\n",
|
|
"\n",
|
|
"verifier_define_calculation(dummy_data_path, selected_columns,sel_dummy_data_path,verifier_model, verifier_model_path)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 40,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Theory_output: tensor(40., dtype=torch.float64)\n",
|
|
"==== Generate & Calibrate Setting ====\n",
|
|
"scale: [2]\n",
|
|
"setting: {\"run_args\":{\"tolerance\":{\"val\":0.0,\"scale\":1.0},\"input_scale\":2,\"param_scale\":2,\"scale_rebase_multiplier\":10,\"lookup_range\":[-582,1208],\"logrows\":14,\"num_inner_cols\":2,\"variables\":[[\"batch_size\",1]],\"input_visibility\":{\"Hashed\":{\"hash_is_public\":true,\"outlets\":[]}},\"output_visibility\":\"Public\",\"param_visibility\":\"Private\"},\"num_rows\":14432,\"total_assignments\":15925,\"total_const_size\":2126,\"model_instance_shapes\":[[1],[1]],\"model_output_scales\":[0,2],\"model_input_scales\":[2],\"module_sizes\":{\"kzg\":[],\"poseidon\":[14432,[1]],\"elgamal\":[0,[0]]},\"required_lookups\":[\"Abs\",{\"Div\":{\"denom\":2.0}},\"ReLU\",{\"Floor\":{\"scale\":4.0}},{\"GreaterThan\":{\"a\":0.0}},\"KroneckerDelta\"],\"check_mode\":\"UNSAFE\",\"version\":\"7.0.0\",\"num_blinding_factors\":null}\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# prover calculates settings, send to verifier\n",
|
|
"print(\"Theory_output: \", theory_output)\n",
|
|
"class prover_model(nn.Module):\n",
|
|
" def __init__(self):\n",
|
|
" super(prover_model, self).__init__()\n",
|
|
" # w represents mean in this case\n",
|
|
" self.w = nn.Parameter(data = theory_output, requires_grad = False)\n",
|
|
" self.lower = nn.Parameter(data = lower_to_median, requires_grad = False)\n",
|
|
" self.upper = nn.Parameter(data = upper_to_median, requires_grad = False)\n",
|
|
" def forward(self,X):\n",
|
|
" # where part\n",
|
|
" # need to initiate num_lowest (number of values that get filtered out) before num_fil_X due to constraint behavior\n",
|
|
" filter = X<50\n",
|
|
" num_lowest = X.size()[1]-torch.sum(filter.double())\n",
|
|
" num_fil_X = X.size()[1]-num_lowest\n",
|
|
" min_X = torch.min(X)\n",
|
|
" fil_X = torch.where(filter, X, min_X-1)\n",
|
|
"\n",
|
|
" count_less = torch.sum((fil_X < 0.99*self.w).double()) - num_lowest\n",
|
|
" count_equal = torch.sum((torch.abs(fil_X-self.w)<=torch.abs(0.01*self.w)).double())\n",
|
|
" half_len = torch.floor(torch.div(num_fil_X, 2))\n",
|
|
"\n",
|
|
" # not support modulo yet\n",
|
|
" less_cons = count_less<half_len+2*(num_fil_X/2 - torch.floor(num_fil_X/2))\n",
|
|
" more_cons = count_less+count_equal>half_len\n",
|
|
"\n",
|
|
" # For count_equal == 0 --> imply even length for sure\n",
|
|
" lower_exist = torch.sum((torch.abs(fil_X-self.lower)<=torch.abs(0.01*self.lower)).double())>0\n",
|
|
" lower_cons = torch.sum((fil_X>1.01*self.lower).double())==half_len\n",
|
|
" upper_exist = torch.sum((torch.abs(fil_X-self.upper)<=torch.abs(0.01*self.upper)).double())>0\n",
|
|
" upper_cons = torch.sum((fil_X<0.99*self.upper).double()) - num_lowest==half_len\n",
|
|
" bound = count_less==half_len\n",
|
|
" # 0.02 since 2*0.01\n",
|
|
" bound_avg = (torch.abs(self.lower+self.upper-2*self.w)<=torch.abs(0.02*self.w))\n",
|
|
"\n",
|
|
" median_in_cons = torch.logical_and(less_cons, more_cons)\n",
|
|
" median_out_cons = torch.logical_and(torch.logical_and(bound, bound_avg), torch.logical_and(torch.logical_and(lower_cons, upper_cons), torch.logical_and(lower_exist, upper_exist)))\n",
|
|
"\n",
|
|
" return(torch.where(count_equal==0, median_out_cons, median_in_cons), self.w)\n",
|
|
"\n",
|
|
"\n",
|
|
"prover_gen_settings(data_path,selected_columns, sel_data_path, prover_model,prover_model_path, scales, \"resources\", settings_path)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 41,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"spawning module 0\n",
|
|
"spawning module 2\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"==== setting up ezkl ====\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"spawning module 0\n",
|
|
"spawning module 2\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Time setup: 2.2689290046691895 seconds\n",
|
|
"=======================================\n",
|
|
"Theory output: tensor(40., dtype=torch.float64)\n",
|
|
"!@# compiled_model exists? True\n",
|
|
"!@# compiled_model exists? True\n",
|
|
"==== Generating Witness ====\n",
|
|
"witness boolean: 1.0\n",
|
|
"witness result 1 : 40.0\n",
|
|
"==== Generating Proof ====\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"spawning module 0\n",
|
|
"spawning module 2\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"proof: {'instances': [[[1780239215148830498, 13236513277824664467, 10913529727158264423, 131860697733488968], [12436184717236109307, 3962172157175319849, 7381016538464732718, 1011752739694698287], [12341676197686541490, 2627393525778350065, 16625494184434727973, 1478518078215075360]]], 'proof': '1bf314349fbcf7a868f9bca361ec5c4adb7c91373fcd803011948b0dd88a5a8302b6e8eb067975b24f1dee1a21df86132539938e2cf88930a9bdaec21f573da717d359f6147239c4a4980800052e9125382810f73e7b5d0968e4c49789bb2d9316a361ae5eabbcd4573ab22558be5d830bf9138d140714a031b4491a36cf673726ce7ba4d1ef9856d5d7b3f61b48dfce57fbb75ebb012985e19971f50bf6d4b00eacf425d8151670bf72f55a38a5903458597389716c4065eeb4873f7ae18b462c3264ef0f52596d16fd996d5636df8488836898a8881a070df2ec25a5154b3d02289417a6e19879bddc97c782296078cae4b0a49d310f84f7d113c81d99066217352f0e1c53bf38a69624719dde6640c85f525e1f9a6c4508b28b3a9945db0b0dd43f9d21ca23561a124354bb0dc686cfd76adb6afb5550e948a74b4ef622e90bfefe71c50dcaed1f09c7c4b046c39e748fe837873d7ca0d961443f595ea7462a4a8560276aa5ef399b8689b1902f332730d9dd74c0916aff65d1a3c9e4b4c01bd4a7ffc1360832e69ac81fd21f9147dcf09ad056a447b768745cdc2ae70f33270036746daad6b19784025ce0a7da85240727c05bcd662306b5cf431332261b26a750ba57a3ea4a4f9b90db29116b9af9a1301f8f01a683935edb0b730a61982554706b6bd7eb027f8e37564dcdc2ce23a24200a917962864f3730b242234dc03b7e630def132be9f04f5f0e304e3956e50bcaff51f70f5d9da20a8bf7ea2d80c3e520149359e6b43609c6b58f0e3d6a9b6ff637871f27b77479cffdde7cb9d0a93ce540a5772b5de28095ae78e2ce242160a40026c05dcd732f43db26b9b2910f9e9e2d89c71deeec5a711eed726ec930694a992ad76ea78006c7f1e1dc636102c4af814d92e20716c0f63b0f2c9648b8cb4b6cfa90ecae9d2536dbcc54002010324934740f41a4a1fee9e401d700da914ee32f7e9baacf11e34ce84424c5f2f933c4faf77cdf5804295aba4cf499af1145df4cf8f6590a9e206030fd693a50c4046b4fd51f902d779582482308cca6ea3065747a75af348d7f509c6fddef12df78d3164be129277296bcd7899a9ce1d91c894a0becc61064f536ec2a9d1d91f65330e24a44523d17221fcf7be7787faee5420a649e48b6d2f5ecdde8937522dcfec521c51154ab1616b9049d4b1629af4f5b89db01e74311baeccefe06a23168b511de920aff71f6352f974d8640d14127c76d09540954a1cbc6fd47653f02c2d14a179691250dedfc6c406d01f52f5140b6adccab4377944dc6630beed600b962df46e8cc004888b1bf6526d5724d746eba377f3527f41ea095c65d0895b105dade3188d564c2098eec6848b2bb72cc74b2de6f4966517af714da24f2cca2e415654867b72c619f9d6e70bfb58fccd62b25b201f8d4bff39a0921a024bf7197a17a9cc2fda3206b4d35fbbe7307ec527a69e2eac6cdb0edf5c476b5ab28416fbf1fbca5e31fdf9408753f0ba2d7c5a86954b27efc94e3a4102b77443ef65257fc0cc8d726b87375b3b1a9b6b07021ada521009e0576fef3aafa4a59ae946198c1e828eee14c9cd8df3fe00c0a731c8c06e22442825048d24bcaf69f268e019fe6f98e1a05c0241591fbcb1346145bcaed03d23f04ad927c8791e069260ca295b4a2ee667c618f65fb98ed7749d0fc0648390d4871399305a554cf5075f2026bff4d10d13da5cbb53abfc8371726b9816fc5c68d9c709e35ba18566e9a51025dc6d9a10b0ff0ade3b31f134d1beecaf06210059df0f62562fe41c84119426105dade3188d564c2098eec6848b2bb72cc74b2de6f4966517af714da24f2cca2e415654867b72c619f9d6e70bfb58fccd62b25b201f8d4bff39a0921a024bf7234297d6d7da6c447e9658e03ec20281378264225c8756fdf18ca46f013536c9018da9fca58504894bad7ddedd61390c5f05a7afed3a9d151f4026c5a28e58ae0d9f056da5c619dfa011f905e8b33491f2581690f9db9e803fbf0dab4ba3d49b141240dace0ac9df2c451c70f4467a401d3a249fc91065a301633264847feba01408d5af4fa10307f8fb6913a08743fa5a22d81789a99f301fa675a2769af6902e3dbb0c61b2b4770e5ec1379891a38d71211b70951da7c1de065dd9079af8d00ab85c2ecdd1ea4a0258fca99c0590f51e006dee7cd6a43538f96248c374d17e08a66467d89446ba68b3ca4ecfe0da685a1131e8e1dffa2bb0613cb6550ee3f8163ef11aa3f1169487194f793e20a9ae563ac714a36fe445748ca0f316bb265a29fc4ba60c40b1b6a5084d883a21db29db3e90fde224ebeace3ef4fc9771cb922297d952de74a4e3574ac4d52ef0f4d87c256f9e81f6bb4511cc42004791ed77072d8cfcdc2b5a4adcf44247f0d3c99b41a1e6f0701d18deb262c37b780248800e007d09b495741b84841d1cb83c9af40b52e69962ee785d276ae76c0a6afbf7300c229fa9e4083824e062fb1aa70b51dfb1543a4f11d963b6c8c9dbae33a8f40d12575d79e7e2026ab1fbf550d4830a080930beb370fed86a2bdc281e352b6601596d4beff757ebc3cd121ee860783ee03e56f2ec985de5f4268df9c28ff05603b27d901dc5579eb2953e569dd9c01de8552ad5fbd58b7c0560efa6512f40c111f2d9733732ad81acdfc78b191706d43f3c7a9a588feaae996ac87d362db1532c70c9a75480457d81c17c7765adfb4995fab1f32a45d2f5bcad027ca1e37271035747135c0bde3ef1b1450b8934f2edae116e93851e0993dff3dca390ed7217040be664bff70f290fa7c43c7d200d99ecda9b7f4c41ea0a7982d7bb2b6da497131010e18388f443c87c58cb488395bc0360f18eb2fd42ca8f8de7b7ab9bbb921890c91e3a6b52770cb948e699292b91f72e19a5e1a3547ace57997adf4cba1d0a94d437880dd841266a3a2f588072e2e08a507fa836f5e96f9b765a4f1bfd3d2ad5f81d5e7f3bf4008597654ea470b164d623bf94ad0382a6f4edebad4d6080036ae6c07321ef768e55a129b1bc6ba979214f61b1e55bbc61a80735f512b16604a3e74c522f48c015e3d3ff8c8ca48d198300e41ccc2a00c1519ca32fc742c0301903221f90ab9fcd281aba7aa5e3d39a00721e59c47febda50bdee73ceb3a72aacaaccefeb9d1fc2f818cb5f02f0888e470994d2e846cbc8ed134f641cbf961c4644e9619fafaf48e952eba883e231cf3e312fe79a916dd876ca6c1e7c382a07bfb1b86801178c1a0e1b981c09055f844358ce00228313af242334d6fb822b059fe8f513148ef78c2085b489c75daca1f55d9d823403878fb824204c63097d079d29f063b9c1cc47253040cc0f1f7a8afdba207523f1baf3dd757f30d4ef39062178a478f1527d990719fe85bec9381057e52f34c998fbe79691b9aa3951b5088cd27ee54a4b88da716be6ab8fc6e5c0e73739c6801e5fd82b5d02605914351fd522c1acafb40d606ecbe7fcc3a55097cd1b97e41e742d8dcb9d18c85124f215aee2628457363ff3af16eef65dcdf7cac3819829ce60d57ce80d270ee120010b3c8e135061e3521545b593411e2dc08cb55a7a8c32cb800bc719d8dfb24050115993a0f4e60c8bcef814263b64b847b9487f35ec016689c9643fa5a9847b842ba2f41d11de2af32376bd106f6905b2752202668596dc107974ecdcac59900f11bd6ce7c6e2040d2e71c12cd27bc85fe1a185ba88297239825e996f4f73ec4f303dc88ead8af45279787849bb132541b5ae136d1c3ee91a8107ecef40e1256f2d79a83f164bca3e51f3351679eea206a0738f71fca7c9541773c20b71152a65261af9233b6317a2191dea0aae67b5cce7c756ceafebb506adc10a4e6b4fbf951e3dd9d9a19cace3262632e034ee836f7c32937f447c04f2bd80ab208c0ac3782ea7cf4b1110480cea7e477548337be4f06114a9781af751fee34b0ab5c5c9f819cda99d00f7dbdbe507d557349140b9ffac0ca915c1dd93d8f6da380ab9d22402b5916c4a823c743eda08310ea88eb408c1d21c09b707fc01f81ee5a586d99e036cb1b774d54a605514c891f38ec077eb5fad6e69d80b6f953c2135a44b84590761d11c48806cb59b5be9157676a5025f16c967db0c0269d48a95529fbe4c3b05642b9f13cd490730da949a92756828957cbb34a8b8024e9e1335678430b3752f5dc12e92900dcbc8b0cbf25f0513ce2e72a9cf71859b7a30bb11fea722068707651b3abca6e73334ce0e50ce3c856ff457c8b499545e16c295987626af9efc089f750e171c334d61bb30bf10d3d4705350399858efb0b33d8b5c3898c7836915a2e49135daf807943e2d71c3c8d956ba9e69e23ecde941216a6278ded7bc29063797f1ab22bf69eee7c87b23830ec37d857a68ccfdbe523954c23fe1969b691432da9892d599c424de73c2c9a53686d6353682e5fead3bb10d2844ff5b9fac2c21be1b7b7f58fcb3250deef071d7862f749b126373650124f22c92194870720ee96a9ab1d88e571f080d57d4b4e2b152c5735ba4489d2ea413370d36f5d2f40d99a7ada96e4c57aef10b2dc5454ae6e5fdad4d91bb8b4542c3d91b79f2709c2c51ae60428e980561aab3eb69f0f5876c2501eef0bf362eadd2142e44e26115249dd99f62678e4e04b4bc98e6e1359b8cc05804d73ab03aab33e7f2b1d547b811b62a21467aa97d84c74037782fe3b36fbd55d67a483249fa1631f800bc69200afdf7e5187e3aadad09e6ac2e5a20923feae9a1b42af3bef35d6b8c60d6ade51b2a01e054711be5c4bdfe682f888ca77e3ed6eda8c1714252a50cf55948d86c12981536743e794596e7eb5aa38f1b2d9ac106e8d031dfb350725fffe11a0a57005dc70eaf128a47d56e1de6eb312081c07f05e2d4503cf68fdd674f9fc4a9d01e12ddce8fabffeae3dfa5d170fbcc990a62d7f141392c5105e04d51fe51ce1604319c5f58ea5aa99d0e8fe6fc862543d4e41e45fbd63686660d8f6708ebe2b9127bb2d3a15aedd1398a7c2716bd17160b83de0e4ac2389e346005e29342029600000000000000000000000000000000000000000000000000000000000000001a0784f30d6e434a105b48ec69b1dddd8bba1bcddffef739a07f7f3aa2a3cc4a2d29fbafd6d87925c6d4ef046e8753bdd36474317075b1e66e7513a2d8b856db15e4919a3e5691877d6c6e738a42cdd0d7d97a30b953ea9a584db1c38b3218531c82e00ffc14bfcd4fd467ee4d515bffe8b5c8821ec00bc030c8e0a1abb02e2b000000000000000000000000000000000000000000000000000000000000000018d7a80e23171a81fb1034b4cbd80a6c110fe4e05a96156ee54a70e6a9434c09296bdc3a7345931876ca771f9a4b667f8bebfc621db0a1a20d509aeb9a72bc35047f8c7e5f2968cc3a77e0e8d0905818882d83af1331f2961c673ad5695f4e282bdf1ddc5ff213f4ec8de95cbe22f8cacd4d4d70258f59f8c3f9ecd0ae8bbdb718c532e9b0f741fc6f0273f8d552b396294a876ca1cf7cc490ff54dbcb0229070966931371d0dafefebee3340e215d341e298b12940841568a45a6f7522285720e5c8f5053fd73627115d0408b85c4d6ff47fde310f35f478aa0239b6e3a069010bc98b85bfdd5f150dc0675e59e294224e1debdaea1bb4869d8282f7da26dd10afcd44380f8db80b5c22540aff99ba8bf19cb5520edd4add4812159ac24915115f4fc487b9b6bf2363de0bad1d91d097be953b08eaa0a4bd5c27a909397ef200bab576a608113d8d1e6f9c36fcac2c03b325b48d5f50dcc4200234781d3d446265e51107e8e0e3f2654a0674a10b462540347d9389c050bb411bd1460deaf601c64478e131734dc6a4c7c8c7e621cbb8e84eec753d3d18e60e77223b6d8f47313d8745bb903891c41676fe3cf8c5d4c650fc15c8d6ecf0b0ff036dc82a4e40228d7d9026fbe9d1a71601a157b6311779a1eac8f17cf964ccdaf116e72e4ed6e0f755b33190dd286c95ac64677c55beaed07565b27ee5028f7d896ca31e08a0229ea4df74328c2c0c5dc82011fca2d716a5b60cefe79ff3a92caeea001c825be0e5e7fea67860b2a761b68e9f7ed7f4767e018156455cf8592df7119389c3259220ca1ae1af16c91683b25e4abef99d7840f8cbe02f63b7c6667e775f3271c5219967b1b47e51a227ba361fd02a03da0f2c0a2b71c94a804b64d7b8ab4aa32542a774c9e3d5662dbcf7f4b170b03ac0d0fa1e5f304479ec63d466123fade321c152363bfb2cc307209cc2ba5f4e3b7f471f585d055f7d3853c59569bcc7b51fe03e3d68dd5445fb4d7614667f3fba728ad31ce9bdd99c51e02cc0203d77f2a322861ea70bb7cfce5909ec8de10889ab76bb33b1ab42da266bd9f88033b5c5e96188a16a7ac87f172e195a591d4038ccd8fc77b0c03320590ec8b7906210f2fa11e805ab3bd6b5b84484ceedbb0546ec574d5016728693a7a8b46942842c81cc5158680193654a546df1f7b76e7616772c610b5e73a1f09deef4aaf5350668d58256d8abb84eb512234a57bfc0bf3e3109cb3173148473731cc128983d2efad7b2853d00c8c43a1faf96117e710ae239f5531ae1e0fc4d1107ed59a889c3078550182cad50a21ca309af111152df6d79870fc9f2d7aee6b0f06716a11aa365a9508ce4e0c3ad9e954194882fafb9bbb9c23a011e7f57305320948d467f026f0c80a544bf7e02066abc19a921f54e655511d643777f6a95d97a8050abfa0414181203fae8473075ff238527d1d14094d7fec7fe0b090cd985eb705be8bf892c74f0f95d2b4478125ab755a285c5631e9a6229ba1c1751e9da1d14f588774eb3e210cc87fc29c5fe0968353f7bfb02d92bd68e0b0483c34f44f88e4d99dfb82fe19261712bc59f22960e09c377bbf25d8967171ffe0b8ec155670bf3bcf43d154a301107e8a19d62c311601b37a491864fb833f4409a145d84f4615df9a616e30441c8d882c9bcc5380f188f2aeb44a2694a08ee191bfbbfd7396ce341d2af490601d4a30c1955f81a54bd42bb15aff70ed28533812f45e892897f3a95bee1782903024a2a1832bb8f63dbca120471aff3a931f6a1f8ce93e699fcfdbfcf02ef3e221a1b5ff6931ae53b4e996cb6728a62b48218a6ad2dde7387926ee9db3c6769f138911c944ea4a92c13b159b8510dd20a8c5ef77daa22139128e75775b0b37351361376c1efbc6a267786db6984c6e83de61bff08e2fe8f407a4951ebec064aa109229a359c4805662d860460a0bd12d8af30110686a0bcd9aaf618d11c33fb62a803f18874605d87603d4b2399501ed295ca1dcfaaec719b36b44036391130d12d5fb55d53e8cdacd8a15adecdd24b4d0e2bcdfb246dddd697667aa92b8e31b06c9b7a8e08e16a0f0ccc6897b317a49ff280e8ff7ca2521439a55ce56cad0301f0713b65f4a8ea14ab6c9213672041bc0bcb223731c44db3b40725356c0d0372b4414999c5005f797941ea3635742bcbc778f4479e9feb0f68d825cd0a219601951901354233bf333898c14356b0e50d6b0ff4b8fdb57c724c8ecd51f793ce421b7511bded446fe4ca0dc6c872fc34645c50829afd66e73c62f3b25c329616e1868e2dcec2fd325b875868bc052d4b398c766a2377a8a07ccd7937c9a2f496a08b39d75b0cc880ef0ee250094dc43b2f5648adffd3b96e5d1b36358f8ac8dda079bdefd4709745834ced63080147d11d5f20dd345f6f4ca1fd9ff10d92b08af29889a144acb5e095ea78936fb8c908c2f85aa6f83b442ece64d81405f62af4213d0a2e56fa2331953f9a65639ba17fcbfbe2e85c3fd2af427198aa66ed64c12034656f2d14829f070b415fd9a1b7ee03da30923e0c96e7900299c8c82f2cdb71bf542447c630dd402a07a846f5448f72b859b506d3273c7a209b1827ffeaa131c22a9e7e376ca4253c885df2ec961c42236541f34267c79200ca280c03ac18a14984f35ec660eb84e0f0df7a5c73a89c824d8782255c118a4e952e94396ba041b6e86938e53ddc92813750ee2f2b2e408faac1ecc310360f1b87bcf257c82700c51faad537bb8190895517d994d725cd7d115e32d37c83ee42239bd5f9a30391f2501d1763c8a51dc2d3f7c1182a324a5785b80e03e23b907a6c5f49bc29f720dd4867d7d210ec823533681ba3acce83c66ad7ed85357b7ded38069aed5e60809c2596d0588e425605ffabaf028ce0ffdad448a1db4c91125bca11b66c273d4084b342c8f5bf4f6cef221341151d081927f79fb98186e10d46417a85748b33b2e03c5e16b8094293ebb619f3af42a329d088df26b8dff498736d2acfa7556370c0f2196a8b769d307449f3937d7f6f485ebfd9a25e21babf0e3cafb5f7d9484079bdefd4709745834ced63080147d11d5f20dd345f6f4ca1fd9ff10d92b08af1eff80917e9d36fb8d25fd9d3b08121f97051e33f605203aa921a4138d1e2a5b25b076a0c479c844be04f1c433289a515e0d73fdb5cedf2fd46992f5cd84a9c6209da3c056d040178317d3fdc26431bb4343c2dbaccac9688ad8438747f9942d2bbd917d5934cf83e9304afea4b34f317650e71e133ff2dae82b459496b4eccb', 'transcript_type': 'EVM'}\n",
|
|
"Time gen prf: 4.096635818481445 seconds\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# Here verifier & prover can concurrently call setup since all params are public to get pk.\n",
|
|
"# Here write as verifier function to emphasize that verifier must calculate its own vk to be sure\n",
|
|
"setup(verifier_model_path, verifier_compiled_model_path, settings_path,vk_path, pk_path )\n",
|
|
"\n",
|
|
"print(\"=======================================\")\n",
|
|
"# Prover generates proof\n",
|
|
"print(\"Theory output: \", theory_output)\n",
|
|
"prover_gen_proof(prover_model_path, sel_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 42,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"num_inputs: 1\n",
|
|
"prf instances: [[[1780239215148830498, 13236513277824664467, 10913529727158264423, 131860697733488968], [12436184717236109307, 3962172157175319849, 7381016538464732718, 1011752739694698287], [12341676197686541490, 2627393525778350065, 16625494184434727973, 1478518078215075360]]]\n",
|
|
"proof boolean: 1.0\n",
|
|
"proof result 1 : 40.0\n",
|
|
"verified\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# Verifier verifies\n",
|
|
"verifier_verify(proof_path, settings_path, vk_path, selected_columns, commitment_maps)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"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.10.0"
|
|
},
|
|
"orig_nbformat": 4
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|