diff --git a/examples/where+geomean/data.json b/examples/where+geomean/data.json new file mode 100644 index 0000000..9adf6c0 --- /dev/null +++ b/examples/where+geomean/data.json @@ -0,0 +1,31 @@ +{ + "input_data": [ + [ + 33.0, 15.0, 38.0, 38.0, 70.0, 44.0, 34.0, 67.0, 54.0, 78.0, 80.0, 21.0, + 41.0, 47.0, 57.0, 50.0, 65.0, 43.0, 51.0, 54.0, 62.0, 68.0, 45.0, 39.0, + 51.0, 48.0, 48.0, 42.0, 37.0, 75.0, 40.0, 48.0, 65.0, 26.0, 42.0, 53.0, + 51.0, 56.0, 74.0, 54.0, 55.0, 15.0, 58.0, 46.0, 64.0, 59.0, 39.0, 36.0, + 62.0, 39.0, 72.0, 32.0, 82.0, 76.0, 88.0, 51.0, 44.0, 35.0, 18.0, 53.0, + 52.0, 45.0, 64.0, 31.0, 32.0, 61.0, 66.0, 59.0, 50.0, 69.0, 44.0, 22.0, + 45.0, 45.0, 46.0, 42.0, 83.0, 53.0, 53.0, 69.0, 53.0, 33.0, 48.0, 49.0, + 34.0, 66.0, 29.0, 66.0, 52.0, 45.0, 83.0, 54.0, 53.0, 31.0, 71.0, 60.0, + 30.0, 33.0, 43.0, 26.0, 55.0, 56.0, 56.0, 54.0, 57.0, 68.0, 58.0, 61.0, + 62.0, 38.0, 52.0, 74.0, 76.0, 37.0, 42.0, 54.0, 38.0, 38.0, 30.0, 31.0, + 52.0, 41.0, 69.0, 40.0, 46.0, 69.0, 29.0, 28.0, 66.0, 41.0, 40.0, 36.0, + 52.0, 58.0, 46.0, 42.0, 85.0, 45.0, 70.0, 49.0, 48.0, 34.0, 18.0, 39.0, + 64.0, 46.0, 54.0, 42.0, 45.0, 64.0, 46.0, 68.0, 46.0, 54.0, 47.0, 41.0, + 69.0, 27.0, 61.0, 37.0, 25.0, 66.0, 30.0, 59.0, 67.0, 34.0, 36.0, 40.0, + 55.0, 58.0, 74.0, 55.0, 66.0, 55.0, 72.0, 40.0, 27.0, 38.0, 74.0, 52.0, + 45.0, 40.0, 35.0, 46.0, 64.0, 41.0, 50.0, 45.0, 42.0, 22.0, 25.0, 55.0, + 39.0, 58.0, 56.0, 62.0, 55.0, 65.0, 57.0, 34.0, 44.0, 47.0, 70.0, 60.0, + 34.0, 50.0, 43.0, 60.0, 66.0, 46.0, 58.0, 76.0, 40.0, 49.0, 64.0, 45.0, + 22.0, 50.0, 34.0, 44.0, 76.0, 63.0, 59.0, 36.0, 59.0, 47.0, 70.0, 64.0, + 44.0, 55.0, 50.0, 48.0, 66.0, 40.0, 76.0, 48.0, 75.0, 73.0, 55.0, 41.0, + 43.0, 50.0, 34.0, 57.0, 50.0, 53.0, 28.0, 35.0, 52.0, 52.0, 49.0, 67.0, + 41.0, 41.0, 61.0, 24.0, 43.0, 51.0, 40.0, 52.0, 44.0, 25.0, 81.0, 54.0, + 64.0, 76.0, 37.0, 45.0, 48.0, 46.0, 43.0, 67.0, 28.0, 35.0, 25.0, 71.0, + 50.0, 31.0, 43.0, 54.0, 40.0, 51.0, 40.0, 49.0, 34.0, 26.0, 46.0, 62.0, + 40.0, 25.0, 61.0, 58.0, 56.0, 39.0, 46.0, 53.0, 21.0, 57.0, 42.0, 80.0 + ] + ] +} diff --git a/examples/where+geomean/where+geomean.ipynb b/examples/where+geomean/where+geomean.ipynb new file mode 100644 index 0000000..91539da --- /dev/null +++ b/examples/where+geomean/where+geomean.ipynb @@ -0,0 +1,369 @@ +{ + "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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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": 13, + "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", + "comb_data_path = os.path.join('prover/comb_data.json')" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "======================= ZK-STATS FLOW =======================" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "data_path = os.path.join('data.json')\n", + "dummy_data_path = os.path.join('shared/dummy_data.json')\n", + "\n", + "f_raw_input = open(data_path, \"r\")\n", + "data = json.loads(f_raw_input.read())[\"input_data\"][0]\n", + "data_tensor = torch.reshape(torch.tensor(data),(1, len(data), 1))\n", + "\n", + "# dummy data for data consumer: arbitraryyy, just to make sure after filtered, it's not empty\n", + "dummy_data = np.random.uniform(1, 100, len(data))\n", + "json.dump({\"input_data\":[dummy_data.tolist()]}, open(dummy_data_path, 'w'))\n", + "\n", + "# where(element > 30)\n", + "dummy_data_tensor = torch.reshape(torch.tensor(dummy_data), (1, len(dummy_data),1 ))\n", + "gt30_dummy_data_tensor = dummy_data_tensor[dummy_data_tensor > 30].reshape(1,-1,1)\n", + "dummy_theory_output = torch.exp(torch.mean(torch.log(gt30_dummy_data_tensor)))\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_88041/1017795205.py:11: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_88041/1017795205.py:11: TracerWarning: Converting a tensor to a Python boolean 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_88041/1017795205.py:11: 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_88041/1017795205.py:11: 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_88041/1017795205.py:13: 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 (torch.abs((torch.log(self.w)*num_fil_X)-torch.sum(torch.log(fil_X)))<=num_fil_X*torch.log(torch.tensor(1.01)), self.w)\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", + "\n", + " def forward(self,X):\n", + " # where part\n", + " num_fil_X = torch.sum((X>30).double())\n", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 1 for ele in X[0]])\n", + " # fil_X = torch.where(X>30, X, 1)\n", + " return (torch.abs((torch.log(self.w)*num_fil_X)-torch.sum(torch.log(fil_X)))<=num_fil_X*torch.log(torch.tensor(1.01)), self.w)\n", + " \n", + "verifier_define_calculation(verifier_model, verifier_model_path, [dummy_data_path])" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "new tensor: torch.Size([1, 272, 1])\n", + "Theory_output: tensor(50.8632)\n", + "==== Generate & Calibrate Setting ====\n", + "scale: [8]\n", + "setting: {\"run_args\":{\"tolerance\":{\"val\":0.0,\"scale\":1.0},\"input_scale\":8,\"param_scale\":8,\"scale_rebase_multiplier\":10,\"lookup_range\":[-196532,29696],\"logrows\":18,\"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\":1514,\"total_const_size\":5,\"model_instance_shapes\":[[1],[1]],\"model_output_scales\":[0,8],\"model_input_scales\":[8],\"module_sizes\":{\"kzg\":[],\"poseidon\":[14432,[1]],\"elgamal\":[0,[0]]},\"required_lookups\":[\"Abs\",{\"Div\":{\"denom\":100.49927}},{\"GreaterThan\":{\"a\":0.0}}],\"check_mode\":\"UNSAFE\",\"version\":\"7.0.0\",\"num_blinding_factors\":null}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_88041/609443682.py:15: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_88041/609443682.py:15: TracerWarning: Converting a tensor to a Python boolean 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_88041/609443682.py:15: 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_88041/609443682.py:15: 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_88041/609443682.py:18: 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 (torch.abs((torch.log(self.w)*num_fil_X)-torch.sum(torch.log(fil_X)))<=num_fil_X*torch.log(torch.tensor(1.01)), self.w)\n" + ] + } + ], + "source": [ + "# prover calculates settings, send to verifier\n", + "gt30_data_tensor = data_tensor[data_tensor > 30].reshape(1,-1,1)\n", + "print(\"new tensor: \", gt30_data_tensor.size())\n", + "theory_output = torch.exp(torch.mean(torch.log(gt30_data_tensor)))\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", + " \n", + " def forward(self,X):\n", + " # where part\n", + " num_fil_X = torch.sum((X>30).double())\n", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 1 for ele in X[0]])\n", + " # fil_X = torch.where(X>30, X, 1)\n", + "\n", + " return (torch.abs((torch.log(self.w)*num_fil_X)-torch.sum(torch.log(fil_X)))<=num_fil_X*torch.log(torch.tensor(1.01)), self.w)\n", + "\n", + " \n", + "\n", + "prover_gen_settings([data_path], comb_data_path, prover_model,prover_model_path,[8], \"resources\", settings_path)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "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: 25.365365266799927 seconds\n", + "=======================================\n", + "Theory output: tensor(50.8632)\n", + "!@# compiled_model exists? True\n", + "!@# compiled_model exists? True\n", + "==== Generating Witness ====\n", + "witness boolean: 1.0\n", + "witness result 1 : 50.86328125\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': [[[11768814371718170976, 435173728250646979, 519717007263840094, 1741290966923863957], [12436184717236109307, 3962172157175319849, 7381016538464732718, 1011752739694698287], [9740814119635710701, 8723924064432029923, 17927155970413989335, 152971583043225146]]], 'proof': '2c11f90c783f3ffabcfecf8c573d5ac2b434f642ff4d57a1d081323a194bc5eb1f29c6fff5a4b7a9dbdb79c78ec896b4210aa486f7b975dc4b6bf7ccf443173c25c443bd2018c6c5a4001610e67bcf57824c04ecc8bb38919ef2e446a7cd67772787e44fea30ab6e39bf075954fd6c57c6f32e85b614f99e52d457e65cf7cdf716794bc4cc2bf2a5cfd0f1c59f32c28d79e00822e2d2eec5310344cd86f77f1527223ad569bd3c7d86d4bb57d34599c919e60a462f813fb2d0ebc757b1dcf6c213b1aae242f042e18ae67debd4862bd236214512aea62b4e992c639c3cdfbf3d2b8fde663e3a1136c733c7dba1260093239ea0d234b9c6d07dd5315190d23dae0c47958fa45bea2465380050f3258822fc9cc59eb53856355495b3efa1fd4810302e61d80c9a1743d0b1b0eac3111680a2d0fa2cce0b8bd5136186f3392590560d6d67e5e71a57a9b8887a98e7e36420485306d791ff7534f586e5ba8e2ceb010d4927bc1255bf286266dbe754d25444ec59cbaa7fbb2b2e32a9b70260b96d760395e60469c1765ff231f0ffee5776de57c17d8f73f946bf658b2192bbf694d52165ed7d6213ba85ca0a29091c524e8a6a2911f35ce787c2524627a1c8c8044b290cff88e57c902ba9f65c89c8d4f6cae9957bc99ba97bcc8c21750d56de456d220d70abb2531057dbaa1948c1c65baa94c5a67af5261d10f5547f237a16c79d249ff99127f126c9c27f559da936d4e6aead4d449ebb81c6dcbf4f92f12ebee41bb89f06f4c8c62ff977efe03fecc39917578e460be03e0db32e150515b2503c26a5f355d2a7a3933a667aaffd6b00ed8ae82146a588e0180d757e78baa21bb20ef8bdc1d6b84d2bff573c6b774396dbe39c187c6145aff6bf42ac0dd27090000cbe6555dd663344a4cc8e9b21dc734a78f6b239dcb1390b9aa9f246023b23110b1772e571d06ef1fb46273007ff93f1ca51e2332cbb9838a1e5f1040fe9ee910cbe6555dd663344a4cc8e9b21dc734a78f6b239dcb1390b9aa9f246023b23110b1772e571d06ef1fb46273007ff93f1ca51e2332cbb9838a1e5f1040fe9ee91274f282038e4e1457adef543c488b72963b38b55dfac8d0293f9287067478c3a2dda1dca2e28f86085530c4490a68251ca2c97cc2f4d8433b5471cc688a334ba2938fadfea029cda57ee620615700966d11c661d926bce7f671ab0160e5810031604f629c8252b3693f0e06bbea7922257ce4c5a2839ecb830c3ee5422b425f105b6624267078bc4082991a4a5ed4d8962adb2c41e37f3b2858ad166c440453709a1e07b6b1f2e806e36c452f79f48388cd6a12f95449ee6c3f79041f3187e072b1b0e94a0ed8a7df1a91dffa6dcd8014cfbe2a85117bdea95e798bdbd4a68821fe65b0e535ee3f500529ad338f48488dc3b338d64d92aa5e2182f1d0f5b4b6f2c9d1f96495953ea0e995b77774d36b1977d9de46d7935af58383a92cf51530e1508a8e66972f160ed9b189d563d770f43005df1f95a87a52ac756c5ccf7930e019861ca070d3fbf69e98b76b3a162ea32bbb854e55207c9b7fd975599d3712b29b240a2bca8e5e1b74c4b1072fd28a3a586aca6f12eeff559f812cb78311c7005b3fe0330d73db517d520de2d0b1383901e7b0897cd31d9e033d784a31229eb05e5d25cb912bbe5b9fbce79070676434490fe1c38be735e1127968094c481eb2ad58bbe0273cd31807b9d032248a691d7ec1e8687c116a9717b1aac85333bdf04c6c5ed5d0a7d015bcbe98509f673b8a2167520681ac0fe74b365b7e9b638aa26338503d0f999fef8ea14a4e252a63d73d4a323efd792f8fb3381579281be1c1bc90cf482d11785a81334f77373b19a14a79e2b7d312d9cdbe4ae269baa710312fc599ea8f23608aa3cd75a7c903655a15faef8f28c2f4f86d99335ce997fbb1752512b7265d8c3023714f1d4c243cb5d709b1b41c176242de42911de75b1501ca2fca33cd4ec68b32d3598f0f5ae7cb57af704cbaef52ce8b1f67253280f822cccc5018e3f2d08fee07471dce449909622a77f24a86c42760ff4b4d3ca6ff4068f55932263eb888ceee28ed4844ffbbd984d7c8c666a6537ca45a7368e67130b40e3954e9745deeb75729168ed8ac4582529e4a78ba41c893a87178de44f6026b6bb1021d27bae5fb66de7a606727c9d661cfb5e7fe90fc5d00f2462b80de02e5f070cc7422ba4750f62675ed5d66134e7d99b9f85b744293045fc416b52ab2945d613e24de735a368f67931b186aef810c66e1d6eefdd2276b537fe76e35309c2908ce956ff1f7835ae0b1fa377c954d6cba166540c67e6ffb141b21981070b8317cfd1374d5aff490040bfea320c91b4653b939fa12072171f191412b708108dceb42e7c0b29253fbec1b19ad20d5db0674855602d60f6f536e7ac7bf1d503b9aab6d8103aad82a4aa9451afb66bf03969ee1b0d7d4d8a1a05be55232ad008bc25d9984b6dca43eda1b497cb5a3e138198ad61af29016d2b19ec79e87c971b628c78e597d5d7614be3a7f869ab7c999076b567565516c16db043998fc93d19b07867404ae04356a5f483b8b7a20fae37a3349c76ef5842fdd92997f48f432ea2cc98fcdac40be098aacc38378573a92324db201e36c48c5d9e9a793cbf0f1e6f0012f18009f1f456a12f79450bde7086d76965b47f3e6897b164aaed829b2ba5dec09928c10807b63b95827fe630d0c5d828ef897399dea9761e90f22b4020ad4ba04ea5e7ac636a9ba7e64316eb9706c0b98389a2c5e5f70c633981545d2d30d4114a33de8005e1e89897277f6a025de34e614dc358befbc5a9ddedc93e22b10d5305e473c512f10eb6f24005215ebc7ea0554f5e65db80ddaf5c36c67125144e715bd7c74ea36938cdc6fcca7787eeb3721a61a5b674b8e16599fa505d1e1c4bbce8de60933c0fa38e4469dc1c81ecca3ad007f9b413966b3facd9aa132a310115d330e1e46a549198f367804f8c1069abeb7bcf0ece039e93b60a569c2f9d5622835a9215c490f820fd49dd14cf6c122f12e022039674adc4d9fe5dee1d50f31b70a811efdf40b323fda886dbc62ac21f9b0680b2a2d98d94d79774a3237a0e8898780f49ed1227cfc53297f9d85e9283ad6ef2dd914188caa5cc1afd0a00ab17b92cfc7ac64206ce4233ae1ce338a8282d2dc087ba6014060d1158ec1b7e2acb8fe44a732cd7bf351d714ad2a478f8c73ca25094862a5991aeea8d02288ae73af19f846eec53acfef757f9e25aec664a5339c801cef8b89ba549b88b01e95619047327c22670496a7842ab2c6daaeb41820417371bacaa677a75a7f02270c65ce6cf54d62697cfd9c2e1c83e3cdfd2c4951e7e7adf3b8d0854584dc211945ddd5e829ea141cb04de9e1878cf067fa16463746b1f02d0f56ae8e18ef927bdfa2eb0958e525c378a4958f257042c9ac7902dca409e05b8a709a2ed7de309d0e2618a345566dd2f1015fd031ff6348fd42e5cd95342518389db0b03b8cc205094f9d2826724e7483f04887ef30f2a51537f271a7c79b4cb7fbb4372206d02bd5ffd63b668306532c5ff161d3a670b2577b3ee4b23ae1df5802e8457007e299a1a7c7562d8aec01a84f11b96ecc1988235717bd12d71640838f040cadb6d0e0854b673cf346653da22342abf209236cbf1f7faf920c1edd6749bf6500c5923e0709e49632ff71616f16ea983aa8f0da622f1d99df585c1a31a5720cac91d04e6813906849495d124995e52e3ea640fa98f8f61d53db7f76b110b79d291390000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004e6813906849495d124995e52e3ea640fa98f8f61d53db7f76b110b79d2913919328ab1606c8a24fe7e895aaac1f1f448b2cbcb481235da0cc72a3d84a7e7dc27a8127ed0917b5e40e68e75e1027990b4fffdb0cfa80e57a53a1235968b00a70f67680bb45a6a32d9f1962a6f2b960634c7cba10ea065231d3a0ebddfeec4b014162c691024e0406deb857f2753e84117e51da23e8f5e0b6c5c2a92372d3c1800c9ecae3f1f021851320c6c31269175ddc145881c9c6f3000fa5b64bc755be62096aeac24557387c65f632766e840f7d5e15e7531f99734383a038781e421c5108b60485db86d5710089f769296efef376cd9970b1507bd8871a12f38b5ccc500000000000000000000000000000000000000000000000000000000000000001d5cdf8c2005e115c7e2b58d33cd4fbf4cd333c935c49a2c1c44c4b632011d6a2aa7bac033a049a9d2cbf09f402a96a19a718b51c068458ba193cc1fc2da051b262c7509ed27eef40ae80ba812e1405dfa78839e451b59074473ea3a6c0a817c1d74678d6b326ef20ef4de6890ad7ebf7e0bddecfc29b0a4fe0d56d693e7700210ff9050df3e543556b3d5d25a8a1e627756536d40cf6cc2ce79e32b4a48770e0e3d0995d533e993ff2b285aff9dac55c4ffb8c7ab5e541adfd0c8b0eca4f00c1ddfe5b88e26c5151f2b3b99aed2ccc917ac782097513d31fbeaf1aba42df6252873b0e761dc0b8bed2eb4ae3f04ea75c7a09fce8286ffc6171d85b712f15be427c11bedfe3b689fd66c7697618af57a2c57d243d7644fa7f65f69953275adca246434577a44e54ed9d68975ea08eaadba2e87b6ba59c47c46b27dea37dc585c014196d7af224d0c81b687ad0b5f4c3d41e6f4cdc1f5b8f413965c432dbe7a7d291b137c2dea4ec3eb63864c772ebf53b351f9067bdaaa8fa730fdb66c7e82c128af4a9f34ff45174651c326b01ae61f0394009642edc37cdd0b34ecdc103fad16d88905e1b0999afaa02cf35f1eb1e749ccf80230d6f8f10b71488df0a3644001a2ee17d4b9d2daf1f46a39b9b8c1bb8a711369fb4cf65af71f4f175b9ac5d7195d5c23264202ed45a2e62a7489c7881219e1d8f321e6a6b48fd917ac4fd67b2885993115e6eda5605bc44573a56af8f982684129268edecc52bc6ce72e0eea176188c2af19171cadc0b4893dfdb8a1feded3b5e70dcbad0c197d4482c4820307b98cecc5d007a330010123cb293dbe47545ce1c26e7ca98ea9c3f92299bf470512ca29a8e396f85ab5249ad2e0f4dea229adfeb3d683b4f04e307e32f2ae0a2d27ccb760dd18c4565a287a00ae25e6be6f4960b892c847f70174314ec2b38f303c2506d3bcfa181b9453840aa90fd39ae3f52a4caa562b98289e3681c7501724462b96fa26f8c6f31721c281fde0ddb96e43498539d9732149e3e8824ca1f51b3baeda336929bd6e7dc012b83c7df097de564c3d45c1284eccddb269c7eb8013514ed44c951b8a8960ec13bee41de46c36caab5fc1fe9d59a22eda9c37e4e10f8511d61b3690e023278c5613fb5da7d67d4864d6f1eea996e90e4590b1cbea196a418e9e7324df9a4bd2210d308d4b95114afcc8e1aae1e685c5dac72c1d7f2e6542fc1a47dd2b675256c1eb261c6e5d52e0208972f73fb86c9c1dab9a2ad20595b1f3f3943ae62dc96b9f11e1f62ac5de4b685bb19454bbe833866b292e5a18f08c12cfeade02deecf22067fcd5f9e22ad05c60518ba7c6c8a51f8683476a0d5815ae37bd505c60a6969a6443f4ab8c1ce5fe18fcde5ab492e7f7d2b2ccd10595b1f3f3943ae62dc96b9f11e1f62ac5de4b685bb19454bbe833866b292e5a23be4508d32c31da6abeb6598b6d33a6b16b42270fea8983dfd4fd6bbb7461a80ae016bee7464662a54b568968fff3059719b1f0df45faca5880dfc1d28094571395294162f62b450cb7eec35127114fe0e25df93f551778b552245150aa4a690480e2752c82e78056bfbbabd5674cad52b7fe9656108857608865d0c289271626f6375eb214b8c86831e6df39179522aef7674a75692bb01554a8f31fb6ea1d0a09daa386fb7bba3b688a2894c5684491c4a6e4e1cd8a66cdf19e3229c30c0a1511952e85c499fc5c6b5e4f9999a37af512041df02b33f04b63c371ee6c28ae272fa5ec9c00555b473b041500b33cadfca201d4799207f9da91ad0b477cfe25299c50d20591b422a1a46fad28c38750ca35bcc4c46a67dedfd62f6e269f97bc01abf41f0b37bd71eef2facc1b4bee338101d85b5667503b40744816465407c60a8984ea04afead379a1f256db95d82175d805b2a7a56bbfb38c7222b907702d2381ecb5e519a622d2863fb689b9007b3418c3b6fdd1902cb6bfae57f39ce7d925fe85fac3604b5a8ad221a4c5513a13b2460842b583f40b129c4ddd9dff36a6', 'transcript_type': 'EVM'}\n", + "Time gen prf: 34.68142795562744 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", + "verifier_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, comb_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "num_inputs: 1\n", + "prf instances: [[[11768814371718170976, 435173728250646979, 519717007263840094, 1741290966923863957], [12436184717236109307, 3962172157175319849, 7381016538464732718, 1011752739694698287], [9740814119635710701, 8723924064432029923, 17927155970413989335, 152971583043225146]]]\n", + "proof boolean: 1.0\n", + "proof result 1 : 50.86328125\n", + "verified\n" + ] + } + ], + "source": [ + "# Verifier verifies\n", + "verifier_verify(proof_path, settings_path, vk_path)" + ] + }, + { + "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 +} diff --git a/examples/where+mean/where+mean.ipynb b/examples/where+mean/where+mean.ipynb index ef132d1..ca4d7bf 100644 --- a/examples/where+mean/where+mean.ipynb +++ b/examples/where+mean/where+mean.ipynb @@ -2,14 +2,14 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Requirement already satisfied: ezkl==5.0.8 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from -r ../../requirements.txt (line 1)) (5.0.8)\n", + "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", @@ -17,30 +17,30 @@ "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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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.1 is available.\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" ] @@ -52,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -71,7 +71,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -86,7 +86,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ @@ -117,7 +117,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -128,30 +128,33 @@ "data = json.loads(f_raw_input.read())[\"input_data\"][0]\n", "data_tensor = torch.reshape(torch.tensor(data),(1, len(data), 1))\n", "\n", - "# dummy data for data consumer: make the bound approx same as real data\n", - "dummy_data = np.random.uniform(min(data), max(data), len(data))\n", + "# dummy data for data consumer: arbitraryyy, just to make sure after filtered, it's not empty\n", + "dummy_data = np.random.uniform(1, 100, len(data))\n", "json.dump({\"input_data\":[dummy_data.tolist()]}, open(dummy_data_path, 'w'))\n", "\n", "# where(element > 30)\n", "dummy_data_tensor = torch.reshape(torch.tensor(dummy_data), (1, len(dummy_data),1 ))\n", "gt30_dummy_data_tensor = dummy_data_tensor[dummy_data_tensor > 30].reshape(1,-1,1)\n", - "dummy_theory_output = torch.mean(gt30_dummy_data_tensor)\n", - "\n" + "dummy_theory_output = torch.mean(gt30_dummy_data_tensor)" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_58237/4035532840.py:19: TracerWarning: Converting a tensor to a Python boolean 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", - " if new_X_cons:\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:ConstantOfShape, node name: /ConstantOfShape): input typestr: T1, has unsupported 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" + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_83676/2311067536.py:11: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_83676/2311067536.py:11: TracerWarning: Converting a tensor to a Python boolean 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_83676/2311067536.py:11: 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_83676/2311067536.py:11: 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n" ] } ], @@ -162,33 +165,20 @@ " 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.new_X = nn.Parameter(data = gt30_dummy_data_tensor,requires_grad = False )\n", "\n", " def forward(self,X):\n", " # where part\n", - " # Many of these implementations are weird, but make it satisfy zkp of ezkl.\n", - " len_ratio = self.new_X.size()[1]/X.size()[1]\n", - " X_where = torch.zeros(len_ratio*X.size()[1]).reshape(1,-1,1)\n", - " X_where[0]=self.new_X[0]\n", - " # constraint that new_X is indeed X where element is greater than 30\n", - " new_X_cons = torch.sum((torch.abs(X[X>30].reshape(1,-1,1)-X_where)<=torch.abs(0.01*X_where)).double())==X_where.size()[1]\n", - "\n", - " # can't put new_X_cons directly into return\n", - " if new_X_cons:\n", - " # value from mean calculation\n", - " value = torch.abs(torch.sum(X_where)-X_where.size()[1]*(self.w))<=torch.abs(0.01*X_where.size()[1]*self.w)\n", - " else:\n", - " # return false aka 0\n", - " value = X_where.size()[1]<0\n", - "\n", - " return (value, self.w)\n", + " num_fil_X = torch.sum((X>30).double())\n", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + " # fil_X = torch.where(X>30, X, 0)\n", + " return (torch.abs(torch.sum(fil_X)-num_fil_X*(self.w))<=torch.abs(0.01*num_fil_X*self.w), self.w)\n", " \n", "verifier_define_calculation(verifier_model, verifier_model_path, [dummy_data_path])" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 36, "metadata": {}, "outputs": [ { @@ -197,17 +187,29 @@ "text": [ "new tensor: torch.Size([1, 272, 1])\n", "Theory_output: tensor(52.3676)\n", - "==== Generate & Calibrate Setting ====\n", - "scale: [0]\n", - "setting: {\"run_args\":{\"tolerance\":{\"val\":0.0,\"scale\":1.0},\"input_scale\":0,\"param_scale\":0,\"scale_rebase_multiplier\":10,\"lookup_range\":[0,0],\"logrows\":14,\"num_inner_cols\":1,\"variables\":[[\"batch_size\",1]],\"input_visibility\":{\"Hashed\":{\"hash_is_public\":true,\"outlets\":[]}},\"output_visibility\":\"Public\",\"param_visibility\":\"Private\"},\"num_rows\":14432,\"total_assignments\":300,\"total_const_size\":0,\"model_instance_shapes\":[[1],[1]],\"model_output_scales\":[0,0],\"model_input_scales\":[0],\"module_sizes\":{\"kzg\":[],\"poseidon\":[14432,[1]],\"elgamal\":[0,[0]]},\"required_lookups\":[],\"check_mode\":\"UNSAFE\",\"version\":\"5.0.8\",\"num_blinding_factors\":null}\n" + "==== Generate & Calibrate Setting ====\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_58237/605661225.py:23: TracerWarning: Converting a tensor to a Python boolean 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", - " if new_X_cons:\n" + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_83676/1510789480.py:16: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_83676/1510789480.py:16: TracerWarning: Converting a tensor to a Python boolean 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_83676/1510789480.py:16: 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_83676/1510789480.py:16: 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "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\":[-160256,1254],\"logrows\":18,\"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\":1516,\"total_const_size\":5,\"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\":100.0}},{\"GreaterThan\":{\"a\":0.0}}],\"check_mode\":\"UNSAFE\",\"version\":\"7.0.0\",\"num_blinding_factors\":null}\n" ] } ], @@ -223,33 +225,22 @@ " 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.new_X = nn.Parameter(data = gt30_data_tensor,requires_grad = False )\n", + " \n", " def forward(self,X):\n", " # where part\n", - " # Many of these implementations are weird, but make it satisfy zkp of ezkl.\n", - " len_ratio = self.new_X.size()[1]/X.size()[1]\n", - " X_where = torch.zeros(len_ratio*X.size()[1]).reshape(1,-1,1)\n", - " X_where[0]=self.new_X[0]\n", - " # constraint that new_X is indeed X where element is greater than 30\n", - " new_X_cons = torch.sum((torch.abs(X[X>30].reshape(1,-1,1)-X_where)<=torch.abs(0.01*X_where)).double())==X_where.size()[1]\n", - "\n", - " # can't put new_X_cons directly into return\n", - " if new_X_cons:\n", - " # value from mean calculation\n", - " value = torch.abs(torch.sum(X_where)-X_where.size()[1]*(self.w))<=torch.abs(0.01*X_where.size()[1]*self.w)\n", - " else:\n", - " # return false aka 0\n", - " value = X_where.size()[1]<0\n", - "\n", - " return (value, self.w)\n", + " num_fil_X = torch.sum((X>30).double())\n", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + " # fil_X = torch.where(X>30, X, 0)\n", + " # print(\"fil_X: \", fil_X)\n", + " return (torch.abs(torch.sum(fil_X)-num_fil_X*(self.w))<=torch.abs(0.01*num_fil_X*self.w), self.w)\n", " \n", "\n", - "prover_gen_settings([data_path], comb_data_path, prover_model,prover_model_path, [0], \"resources\", settings_path)" + "prover_gen_settings([data_path], comb_data_path, prover_model,prover_model_path, [2], \"resources\", settings_path)" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 37, "metadata": {}, "outputs": [ { @@ -272,27 +263,6 @@ "output_type": "stream", "text": [ "spawning module 0\n", - "spawning module 2\n", - "spawning module 0\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Time setup: 1.1477460861206055 seconds\n", - "=======================================\n", - "Theory output: tensor(52.3676)\n", - "==== Generating Witness ====\n", - "witness boolean: 1.0\n", - "witness result 1 : 52.0\n", - "==== Generating Proof ====\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ "spawning module 2\n" ] }, @@ -300,25 +270,48 @@ "name": "stdout", "output_type": "stream", "text": [ - "proof: {'instances': [[[17970410297053518904, 9046703063145816218, 2851759239208196922, 164045840560226117], [12436184717236109307, 3962172157175319849, 7381016538464732718, 1011752739694698287], [1460628720732602093, 15005283833837523956, 127539993950163949, 306168462079750959]]], 'proof': '1289303ff75cc3a36210dc5e377af615ad526dfbfc4387a5a8f7a44ee62719ce20e1e2fc3ffb67c5971c242f10f2671dc5a17ec7d0ee05c3311030ec726089521166dec04b07cfb114a6b7ea458944358fcfad10411f0a83a3e94c3b1e72dea620e1ccb7c0aa14cc54f5a1f5778ecaecffaa1e517dec3323afa66ca3b6be2e512232240181e6e51423118aae1e7663755002c14da7c0504beed4f5f7dd6a07591e97f8d2e537449c97778d00388bdaf276e340095f159fce486bc863254327bc1b73b288190efbf9163bddfce9563ab6667b6bca5ce0e98fe065dd6a85dab79906a71fd2b1be61db96aa1c4397ea48431661dee3831acab659cc07f52d9f85e621a26b64dcfd9b1c23ef2569ffb55f3b84dcb6d2d3a6b7d579a0cf2b05e53f442ff33a97e06d698ec2c50acb148138b8cb41fd52bc23efb4182e0ac5712195030a730bb35847c220ec8c78b0f320bbae00a136fe0753fd88d1ea1c067f3da98806b247194b0d90e1521104b6bf389c7636980cf5d1a31277267d2eb8c9943ebd0225fd3e1b1649f02ad97a7f44608155e10d4a525b74dcad7d0e95fd1ed4a34b043755be061af67b580569bfad841fba0eb28bedf25f540f5033736ef3163ab90b588ce748d7bc05099f42f3a038fceaa4003b381f23194a7f452889405e0e0f13f865ca3c2ae40e86481f0eb9eac5dd7ac5b7c4e22831f373a35242ff197e1127466a1c96974eb991b7a062b864b6b2c4823d3a1dac61d5fa7f891dac2507ef2defd7b1f00ff804adee07689c6ff4daae0a61517d9c876aa74104be7ef42d531027abdbc23ca683890ddca4860977e58149cad5ec943eba6a89fa9b1ac38f960657e4925976fa747c32fd38fb87a943bf45b5c85d72809b071f7f843f2e6ffd2f93999b34b98464bb03f7423fe90ced3459c75639bdd7e912762682d3b1f6232c6839276ff6fb691368c83fcfcdba767dca161a1d791a330c38b0d4478e025111cc7bbc945bc8c9835e28f65f316d5c41d8aeeac78e5e06229b91969844f8340b17edc167a45a581cd1b92e7da66b6a401133c0ebeba6ddad119b97a4ab69bb054945c742be279355a1527b74559e400d323473580a162cca090ea57a22701d1e3f3dedabdfe2d593320929f69b93f7c56ae68ee49e8d3db6ce522a39dbb0f7169856b5507eaab418784ed2e4303da89b8058d49f8526770f343e1cafc8f203263a5265552bbf33eb3e019c22c49362e568f7ebe30fb62c2d203bacfd2f23fd0ff6f494ca5571f951c0d710d37a1d0ad2d6f18e253fdad325edc7809c6ed1c61d0e0014ea8641fb54e25adecfafa969334fe79168336fc0a7b2bb282703441e143483a00c94ce288bf32160e1cea8d15111bf7b26b100c8051f4d31c2c84b1604da8905cd78ced44b1872ef3e52cf016aa81da7680d318fc5593cba0e326dd90ecad8896c3f328cc20b853e1389a8519220c9b3ec22ae2ba3e539fd0df7620b06b3a672e38d6f75a36cb3555734c37c2976e076fab9377ea56ea1e78752fc092ae83bff8b738aebd0e37e1a0f46d9feee77353da7ba00a2dc2e188e57620f361639dd24a5d2df5c4ab37578e5e6f73af06fcc79f8fd93d3e84a0045cb12462025964f501982e42e5b15c278ed5d0e1d9cf32cac88bf7d4940738d8d1e5bb56617b043eb5b9fb06b5d440717e3b45ae0dd679269e42097b40680292127b788e82df6b59848bf2d2f70acb04fcf5c78b18a398f22f47fb3e74e83862ac9789c241826adb1d93ba77690f43b794eb06cb8551d215bf6deb3e2c93ee6d8331b21552c46741faa9458b52a589a83ae9f0304aacbe6a55e666d7cbc980638b24ed57510386b511c0cd6ef0b111d07901ca812d795c429dbed5ae17e1e70cfe5953a9015d1b0bb7047bf949545c18f207fe2e0da50ac4da3d99bd63e407d51253aa5b815a2941036fee495cc21bbdd720d0302fce40fa6e0d17bed971c3e19799ec29f1811915b255896ad5289588157ece52a0f42e8d9f8bfeacdd5bed26635f3ab5105b62286ede799d68158fd99722ef73d51c6fcbdcbf4f22ffb54a3d79d2b86371de05267f242456b5ce3ad8bd8322073e9976bc2e7d3fa8ca533a97818daa30f20ad3ec6bfbddad9e914156472fe70f0db1a1d7bd8a26bbb8f5839318f0d17f30498da66b8b1fefdff0dcbcb864f04926b3d5ecd149404dd9c09d9f3e629d22c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000239d8eb5148c9b5161321486eadf0ca9d3c65679af98a60232a4fee2fcc082092af0f51a02816e25d08430b9aed2f88d2c69f5240de9cea0084922db9817b84919eb02c41e3e6da3510d34970ef372abd37cc3407249ed1c8265a61f0ec89d9a2256bb3d41c8ffd1047b32bdca666ad63af428d124fa2d1469e39d7dab0dcf181cd91ec0b991e146556123044a162012a42c2508c89748c99e9a17c485585134111e3d308007083e81c40a12d6b6d161ff8d45136070c2a12f804191f4f2bd5c13eed9df843fc1427866ba71e70fb82f5b1e8972fd1276dfbcd8d883e0d952971297d2ebc35b047fa7f458eb0ae48db4c6b15eafb9dff4654348ba3a7ec82a5b1e8a1506dc536b42fc0beb72548d2308c62489eb1fe7482747ca190650116ab80c4d1c8ac0f305b1da6099925a9135919ab49d90c34a274d693cd6eed95ff71e03f5c3c018840d46043b475028c5d8262dd74f8f39ea8267021620f06e7467c0035133d3db911fb612a5a1f2ccff2dba6ad4ac90b250c116244237e61c6aaf0c1eb83f7dab47fa8bf2006d7a1a6ae3fbd869c6bd92269b0c5b0e2aa8cf2204ef108ed2c21c5827d8b79e733034112757e1c0a301844c3419778a4095442414a92e34d188ce9694f211357863fcc42a75b90672223728e0a4ff4728a43709a745239e55f9aae98897abeea12ad8f3c8757d76632632fc1eda9216c6e77165e498103971c162bfe9b10a7915e57c858f4e3d9755aa576d7f9c97d908183f4b99521194ca5d584866dfc2a3dae1424f8519f4b15aa85f0ba6d9c3810af1241d45852db07d3fe86a01e5cdc1ea7fc64c7fac6faf6f40368c2270cad838c852346a741e54e9d6e9e8e8dfc4aea98ee03530ba68f4e9eb6d31079f09e3561eacf144d62198919cc9afa09c546cd4951cc2c1f8ae7f35bcdfbd1794cc1e27241bd9bc45115f91f191314e87b67b250960f0d4a5c04fd8e9014bb20c9a96a2da3db6567a', 'transcript_type': 'EVM'}\n", - "Time gen prf: 1.5523650646209717 seconds\n" + "Time setup: 25.330917835235596 seconds\n", + "=======================================\n", + "Theory output: tensor(52.3676)\n", + "!@# compiled_model exists? True\n", + "!@# compiled_model exists? True\n", + "==== Generating Witness ====\n", + "witness boolean: 1.0\n", + "witness result 1 : 52.25\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': [[[12572659313263335624, 14443766455855958404, 432930639589567449, 1881177029071802301], [12436184717236109307, 3962172157175319849, 7381016538464732718, 1011752739694698287], [18278699600166517679, 8643075271396760825, 7891176514265388517, 2236426588013702123]]], 'proof': '081b32cfa53a82a5e5e325fab4c025bafd3ffd877ab54dad1470d8b4abef97af2522f63b20599b39f35cffc313f6eb4c3686d5c65fd1cb11330fcc56467194172776ffe88ba29f73f22fbf1a124dc8f59f63f1331a7f65b67086f65104017a721f088a939e9ee96f7c214428ff53e4a5d9ad37436952c99bbbf5691a83eb389d0692475598c9ce2355d43f1f84ca9628b45f1c7dc1d31277c578f00016cae77210afe97e45126411c0894bec0b67d5bb4843e5a9c46fd81415e5cc8f0618f7e418519ac84eb119d8f6bec0061c870eb47485cdd10844a2b2aa24eaa4d8b9cd6f2769a9c783c41264f03462820254a4c38a2883fa85273d5239fe1a67e5f5914c1cba82f8f4aa4c5fe1acea94d570a9f03d3e2300f1776037b33b1a40a044c2c909461ca28ba4811b84686c24e5ea4bc4eb1cf0c86d8fb5518e72071d2d2a0738025f8c0eb3037213f2c2d4acb988fac25745899130cea698ab8c81633f1ce5492986e393e534fa2f25158f413d194eeb89d1d787eeb03fb68e4428d75bbd2e1804f8b063dfb382ac7bc9d43a7653ca00aff828c1603931a9a5250a62184f12fc29250f853b0d086e7025b66ed65a129f695fa4d9ba2e40f2e8bec8dffe6d59cf0962172e5d68fb3b3cab61530c864dbec879783cd2bf00caccc0d36bc7d72ab5072dde239c382f45767123509d560cb7da15927dc06b408592d7ef49f1226e542c55dea3f6e6f39d4f0829f00e18d8a0c80936ef5e87de0c3e7985ad6c2cff531ddc7986c745dc360e83eb430bf71faf25a71a42e5710ec1cc4815e3b042ca242fd52de9807395c243e323d10ec7da9cd18661267e1f302a79d60cd17ee1f12300700e80a02a2ec0ee85e8ffce7de3063e340a2973ef1bfcc9c1128c67e266e50f1b07e67db81a510ad2b6fda1b5dc23112b007d8b82a396f7956529bc5e57e40175719678100f2533f6ada12fcaadd998d61afef581b08b7da8709c48a96c4f0cbe6555dd663344a4cc8e9b21dc734a78f6b239dcb1390b9aa9f246023b23110b1772e571d06ef1fb46273007ff93f1ca51e2332cbb9838a1e5f1040fe9ee910665f0395141f52e19ac3358e2d9912712fc7e57ce0e5e252a92ab6790d3bd97175158e620f37e2e33a2d17c8d730b0ce30b851daf25b288da8890e54bf9206c2f0ac331a615e4ba69bfc4706e5d527ce1621a463ccf0526ec0831b7d65524b02721291a993e156ad2e0b5694c23357be742fecc3c4a6489c327cd4f06124da8202660a1c2c6091636476d30dd9b34a48577f9dd258b7882dc999008abb9a35d1c5b1f9d8d64fdabcd7fb8f3a6bcb8374ca013c009698d79f87170d9351f3809195363e5bbc4c9f38b4dc0f6e2287ae0e15e20f4b53b666d48aea3ea47b0be28150394ebb18567ffc021cd3894837e14caa78a119b637a8ea307f86415483d3626dadd2a24e3c180d0edc5746828ebfef9bda2e858fa8799bec644b164e09cee2083f9cf5cf0dfc31dc7017cf3eb9ec0017a7a4de58bafe9144a8ebe4ed8bc9825fd668e1c2a2fbabf04f7c008520224657efaff73528cd4ad296f0216a5076224691eef089da76b7d549c8eb24fb63173aef9ea61674f7c78b102be5946ac1d248b3c0c6a3fa6103b1e4a7cdceab0e236629a7a660630782083de01c411e77700db151e1be624ab914e6ee131f4792a858af99029a873db7f6e4b3491025f3e2ca54e6930e31078823fad4fb653e79e2276f448e2440f2a7e33fb3d643f23de26c73e748630c7da3d2968d61e46405008d5a091eeed6e179fedb3d89531d0d9016c8d774809d2a2d2999e1f71910cf15381572fdf4b5401dcde9f926bc85fd7107b86aa0bc90658ef6f7278c71340937a1c1f30114ee8f0e5166d1ef4320b170be001d5fc929f01258e6c881102625322bfb01b28a955d97740634415c0c71017a5a62216f89975924029bfc356fbd6117044deb78bd082d2c2a7930d4d45a317dd3b90b0eed54cfcf2d10c674e5c735c72d46d90d1096b61167b91a38fb41e13c74c0ebb6c0275d54cc8ae277224f8d1db7477835672bfa906034804f59da30324bb1cff2071e9144836831fdd50f1233ec6ebce0c21ce99ce93b2d31ded652d5d19c12f59b70f14f128c63fe743661b882d91aece5c6f11c7a7699593b6810de109b996138a8b6273f285ee07bb4015d48576239a8cb47e2fb64cc70337800a80f4199f43b14e6be6985aeaa76a5a3d55fbb85bee1c0cc2eae628313944970f8a8488e97a8a662aafd550fe19686edf820c64f6879911d3a37f9a574104482df1a73e6464b68f8f035a0032b86460f49ed01886dba02a476ca336fb492a32006c3106ba2a75599e76f2d3eff33db3f1389f8101e1261e1fbeedd751f8a01408cee66b6de09e3ec763231b5556678c6c7adc94a98b9be6fbbb5873f77f970d001741cc292fad087f17421b488725d4ad21c0cd4b2a86db82a5078c0ff36d50024130e781bb4d5f66e4f83bcc2a1f4f94528a9ea5e1b649317702824d1db94130141dc21e083c8414841ca098604da358cc7361cc1442d51ce1947809c34ee6254aecc1facb733732c51490f7fa4e4b3e34212daa61ca1871fb0e20e96520202734c31246577b7665cff1e2585751955fde85b7c9da75f2840bab35b41ef4d41759ca0832289feef9d50f92618b239d50ee1132d68ad7eb3bd6444ce012732e104b5a6390d164e34cde3611edcaeb2a32958185c954bf04a47fce8eb30b79162859793431fcb970cae4635921d8362f991f6fb68341f88730987c22081f04982be3b32763570cacfed7636539087911e481e9a950462aa37b7d9e8c57a98ed12ae8931138112eec6731996a27de8f8683e1b945ae306b896fcad4025e9a848f12e917138766b4aebe5504055e5769e0cf0f726578d0e1183e3e596ebef756580670d336615fcc058eaa19e933923b0d0f435dc488c3a91e0730cb6d79a6cffc28ba99acd45e6d9c146ec93865c7ec81f182be890aafa9a4720aba958e56deb217837ead25bb11866e839f1d5ea37bda027014d9d5ed5a8479f40b80773261e92712b6fce6faf6941e62e5fb03459a28507685c6661b6a1c42158dbce520d71226c9e41350e1b5e27b2df6f0e62328f7e2ecfd8d6f7b57037acd9300de234ddf1ce20cceaf0ee0ad45a02ba69258c3c1bba8374b242ebb69a9273f08837577c4082524e188e2a2fc21070c5fa94651737de5c7239e4e7d7ae8f2968c3a83edec23f934fc124dcb9695c1ba710f1580de76ae1d0aea6443c6b6d65f97cd2a79f22a9c672b7ba8d00b59a976ec174a16c517e15ab56600935239ed3218f5f0dd1e19902a5d006362a2e5007dd64a7fdd63fa2cb8cc4a52f910505e41237dfa5320301c09d661f49be85da7a0629606333f0321d48e2ca721d723c1d22b8bda80b4296368fc408e19ff8cc2c7af58bf0b2a25b11f6c009aa8995e62dd33707c624513ba93130b87fec8f2d3cfb495c7e6e2e75774a8691a9306d0a94c6c0818005d0b31362d3fc4bc9d8b1264929dc4843c8574187907f21a63a28e6e5f6dd9dae211b55e0fc8fb22509f9afbc8266977089ea248293dc0cca162ad711b58395c622c100daaae50171cd88d60847ffb2a188b5e2f636adc5cc7cf7c74eaa3d5650524e0e4669a4c39657a8119cfd641e59c39b64c2400e86a5a1740fdfbb3446c22161f4d1e8189457945947cec4c6b842fe1e0e9f5bf7779aaec3844c1dacd8bed2291310f11495aa950fa73aad5bd4859c3f30cd8bdc210ead55c1937d0a336ee0ddf2f8c18793b33750d7c2c353aba87a556fd7f336aee55ee9294f3132713e100000000000000000000000000000000000000000000000000000000000000002291310f11495aa950fa73aad5bd4859c3f30cd8bdc210ead55c1937d0a336ee2fba578ffbd3e290d4c68c312ecfc58008e20df5bbbaac01135a8429d95a075b1ccfca4bca3f8f4792790fd6c152c288faeb49e56045b009aa6d06605adac26709c560b7e6478c3457f778e0443946035c65a8b19d8622853eb152fff989d095222dab7e6d930efa0e2f61b2f5096d638f5a6a9fdafa70448287635da54aad02236ad55b7e3bac9c01bf3adf485849f8e7d2b88a70d6b8eebd46511ac21bbddc18b023037def35734299912bfa55e0ef70a7b61efe63c4bbd05039a9ad990aad259f635da213b241bc7cd1145ea4a65c063c5aac5f8ab218ad0b2314fdf944ae000000000000000000000000000000000000000000000000000000000000000007a01ecf30d7ac4bf586b7243c0e3d1c4f145e946a774804e39eed3c41f760d717a33a8f0c497107cc8472a9fd46bdd53fe3eea084518c3fcacd27335ab159e801bae49733fcb7044032472b0acd5cc0ca96541f2bece10b10cc10a2829890b404d11271eddbb10e69366141f8150ff9a987330c91ef97cd61d0c5dee3a52f630d824a69960a778e01a354ac5789d42634446ba392e661c67b1b4a255bacb1001284d5c34f52bf7f54708162e4fea77270ecc24e3a215f6f00d00d0f6ea9c26525ad9a83c9d9ccfc23bdb93c4a02e74bc066d0c1e23c0f90e1bf30ca9cbdbe4b0bb91c6d16746ad9f610095713d22e60a2e44aa8db19dd19c71a85f08edeed301ad0d3e62f14295079eac36f2eee3fa8e9a5b27b3fd220d66df10a3c7b7db90012baf3d782990c51bc3a23120238967df609fcc4ea8fb38500093ea3a4f015bb0fcea37c4ef90ff8d60d7dc83cf7ea24c2c2b19ed13e1b6335b2480d661be3a811ca3c42293928d7d578866b3b15df74a7325ba4258176ebc9e7ff242654156a08c566832c3da952e78838f12a1195ac0aa66ee95e9913e959d08a792dd8dab42c8f729d41e0d7ec7176c7ffed98403e24f81395903cd08f8ac4a46c949ff8ef1f93eb6ed2d1e13bc07250e10c1ca2e8ac0a81fb3a70af83c9a2641489c0f2e72ffdb099134f58dfc5e1cba2c29f2a5aae7b26cc3b785986560c9122e111abce27618b39cb81c4d6578a5a365101d55fc9f85b8af0d6d249d067ff8bb1ffdaa50bab1b6be6cd669fc010416bd4340731541bf2b4921fa4bb0efc65b3a66fa4a629c3689dc8d856838497513b0b03f8cb77a9bb8edff4d8456af87057671c637b0b5f5f731fc686810fa5d7efcc4f3276834b74bd1ccb653c6c131626eb9a4cf61e4fc9fe55669bc7da924e38494ff341098b61fc778266ca4f986e19a0c6db4f212b5a9a2f9b911a7e7171f70e04ee3e998f77aeddab6cd584411cb436a13de3045c3c19eaea6d33bb39e878ff664e7c71c9d3ce4f74f70c73a1fbe751e2763a1f1c08c01deca1dd2dbf7176d2de3c9983d84d3dcfcff7c8b64e2f6fe923e1b81961389b5fd68e162d13ac2499bcd72ff2bf8df16d2edd6f917c8afdaedaeda8149d1c174166bd1427b4589ef4be777cababc123036577028bad9684ba0db10c0426c2ee4ec6aedb694ddd3f05f057f79b39c8e94db683bd91f371525ef08207088f6a796a6c7447c22ca34787ae656733099d0b5e0eb7afc36c03a683db25100da7cd95182825fc83d5ece43cf2c6c4f28df3a8a04f0e4f0c2add2d5acb46af1e49ba45838b90fa1bb22744d221327e23a0f2ddf1cadbedcf97190cf273adab2177a9e12b99ed9a95eed19b1e3011ae88b0433d7d564b8c7f7e690f08df7b3610f25dac07a764f62bb9168b5d6c612d8d1f6747a69ef1a1340ec43d13e29a0a21adb2512106ac682590197eb0e9a30e604cabf56846be394af7b28ea8be2034303e43b07686b633ebf21fd08b92c8c52d1b36cd993f16332d3c7ff54a2a02d92a050fd51265a731fe02ef81fb4ec198dcdc89a7e37b95fbd171d1cece4bcd201bfbcb9a83b71d22a4d4d0e8fc26edd0fe6c02cfb351ce18133cfa82fb98b866038ffce7dc40deebabd6a14bddc1cb43052f7125043bc748a47cef17966b3f2621c6a2969903dd94c1450ed37d8558bbb4f14e5ca411692ea18815bdfdb063411e118ec19ed679f7763e4a0575dd00afe8dd91fb2aba2f34a86e9fe1753a4e0f0c8e2909c017bbb5d44b1668965969d7ec9a87bf1e1d765a6473cdea1a82453a004aa9ccb568aeaccd840b8bcf8052d7d92010a75deaad4dad65ff6b1340c66926e59e73039838f7b63e2a5b7937a1177fe7c788242e0ef8625187be1b994f011e0d6419170de85b0693565dfdb4bb69c730fdba2292d249e8497af178ba0acf1d51cd33f34c586539ad2b0d2606f848650f6344095cfa9a7277d753a24eea30181e7da29bf29db13d32f14a2274a9eb6bf659832a2d3d889de5d3520c9ba64b', 'transcript_type': 'EVM'}\n", + "Time gen prf: 35.382965087890625 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", - "verifier_setup(verifier_model_path, verifier_compiled_model_path, settings_path, srs_path,vk_path, pk_path )\n", + "verifier_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, comb_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path, srs_path)" + "prover_gen_proof(prover_model_path, comb_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path)" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 39, "metadata": {}, "outputs": [ { @@ -326,16 +319,16 @@ "output_type": "stream", "text": [ "num_inputs: 1\n", - "prf instances: [[[17970410297053518904, 9046703063145816218, 2851759239208196922, 164045840560226117], [12436184717236109307, 3962172157175319849, 7381016538464732718, 1011752739694698287], [1460628720732602093, 15005283833837523956, 127539993950163949, 306168462079750959]]]\n", + "prf instances: [[[12572659313263335624, 14443766455855958404, 432930639589567449, 1881177029071802301], [12436184717236109307, 3962172157175319849, 7381016538464732718, 1011752739694698287], [18278699600166517679, 8643075271396760825, 7891176514265388517, 2236426588013702123]]]\n", "proof boolean: 1.0\n", - "proof result 1 : 52.0\n", + "proof result 1 : 52.25\n", "verified\n" ] } ], "source": [ "# Verifier verifies\n", - "verifier_verify(proof_path, settings_path, vk_path, srs_path)" + "verifier_verify(proof_path, settings_path, vk_path)" ] }, { diff --git a/examples/where+median/data.json b/examples/where+median/data.json new file mode 100644 index 0000000..cbf3cf3 --- /dev/null +++ b/examples/where+median/data.json @@ -0,0 +1,31 @@ +{ + "input_data": [ + [ + 15.0, 38.0, 38.0, 70.0, 44.0, 34.0, 67.0, 54.0, 78.0, 80.0, 21.0, 41.0, + 47.0, 57.0, 50.0, 65.0, 43.0, 51.0, 54.0, 62.0, 68.0, 45.0, 39.0, 51.0, + 48.0, 48.0, 42.0, 37.0, 75.0, 40.0, 48.0, 65.0, 26.0, 42.0, 53.0, 51.0, + 56.0, 74.0, 54.0, 55.0, 15.0, 58.0, 46.0, 64.0, 59.0, 39.0, 36.0, 62.0, + 39.0, 72.0, 32.0, 82.0, 76.0, 88.0, 51.0, 44.0, 35.0, 18.0, 53.0, 52.0, + 45.0, 64.0, 31.0, 32.0, 61.0, 66.0, 59.0, 50.0, 69.0, 44.0, 22.0, 45.0, + 45.0, 46.0, 42.0, 83.0, 53.0, 53.0, 69.0, 53.0, 33.0, 48.0, 49.0, 34.0, + 66.0, 29.0, 66.0, 52.0, 45.0, 83.0, 54.0, 53.0, 31.0, 71.0, 60.0, 30.0, + 33.0, 43.0, 26.0, 55.0, 56.0, 56.0, 54.0, 57.0, 68.0, 58.0, 61.0, 62.0, + 38.0, 52.0, 74.0, 76.0, 37.0, 42.0, 54.0, 38.0, 38.0, 30.0, 31.0, 52.0, + 41.0, 69.0, 40.0, 46.0, 69.0, 29.0, 28.0, 66.0, 41.0, 40.0, 36.0, 52.0, + 58.0, 46.0, 42.0, 85.0, 45.0, 70.0, 49.0, 48.0, 34.0, 18.0, 39.0, 64.0, + 46.0, 54.0, 42.0, 45.0, 64.0, 46.0, 68.0, 46.0, 54.0, 47.0, 41.0, 69.0, + 27.0, 61.0, 37.0, 25.0, 66.0, 30.0, 59.0, 67.0, 34.0, 36.0, 40.0, 55.0, + 58.0, 74.0, 55.0, 66.0, 55.0, 72.0, 40.0, 27.0, 38.0, 74.0, 52.0, 45.0, + 40.0, 35.0, 46.0, 64.0, 41.0, 50.0, 45.0, 42.0, 22.0, 25.0, 55.0, 39.0, + 58.0, 56.0, 62.0, 55.0, 65.0, 57.0, 34.0, 44.0, 47.0, 70.0, 60.0, 34.0, + 50.0, 43.0, 60.0, 66.0, 46.0, 58.0, 76.0, 40.0, 49.0, 64.0, 45.0, 22.0, + 50.0, 34.0, 44.0, 76.0, 63.0, 59.0, 36.0, 59.0, 47.0, 70.0, 64.0, 44.0, + 55.0, 50.0, 48.0, 66.0, 40.0, 76.0, 48.0, 75.0, 73.0, 55.0, 41.0, 43.0, + 50.0, 34.0, 57.0, 50.0, 53.0, 28.0, 35.0, 52.0, 52.0, 49.0, 67.0, 41.0, + 41.0, 61.0, 24.0, 43.0, 51.0, 40.0, 52.0, 44.0, 25.0, 81.0, 54.0, 64.0, + 76.0, 37.0, 45.0, 48.0, 46.0, 43.0, 67.0, 28.0, 35.0, 25.0, 71.0, 50.0, + 31.0, 43.0, 54.0, 40.0, 51.0, 40.0, 49.0, 34.0, 26.0, 46.0, 62.0, 40.0, + 25.0, 61.0, 58.0, 56.0, 39.0, 46.0, 53.0, 21.0, 57.0, 42.0, 80.0 + ] + ] +} diff --git a/examples/where+median/where+median.ipynb b/examples/where+median/where+median.ipynb new file mode 100644 index 0000000..720c65f --- /dev/null +++ b/examples/where+median/where+median.ipynb @@ -0,0 +1,379 @@ +{ + "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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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": 4, + "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", + "comb_data_path = os.path.join('prover/comb_data.json')" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "======================= ZK-STATS FLOW =======================" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "data_path = os.path.join('data.json')\n", + "dummy_data_path = os.path.join('shared/dummy_data.json')\n", + "\n", + "f_raw_input = open(data_path, \"r\")\n", + "data = np.array(json.loads(f_raw_input.read())[\"input_data\"][0])\n", + "# data_tensor = torch.reshape(torch.tensor(data),(1, len(data), 1))\n", + "\n", + "# dummy data for data consumer: arbitraryyy, just to make sure after filtered, it's not empty\n", + "dummy_data = np.random.uniform(1,100, len(data))\n", + "json.dump({\"input_data\":[dummy_data.tolist()]}, open(dummy_data_path, 'w'))\n", + "\n", + "# where(element > 30)\n", + "# dummy_data_tensor = torch.reshape(torch.tensor(dummy_data), (1, len(dummy_data),1 ))\n", + "# gt30_dummy_data_tensor = dummy_data_tensor[dummy_data_tensor > 30].reshape(1,-1,1)\n", + "dummy_theory_output = torch.tensor(np.median(dummy_data[dummy_data>30]))\n", + "# print(int(len(dummy_data)/2))\n", + "dummy_lower_to_median = torch.tensor(np.sort(dummy_data[dummy_data>30])[int(len(dummy_data[dummy_data>30])/2)-1])\n", + "dummy_upper_to_median = torch.tensor(np.sort(dummy_data[dummy_data>30])[int(len(dummy_data[dummy_data>30])/2)])\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "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", + " # to check: why cant do with num_fil_X with X>30 first?\n", + " num_lowest = torch.sum((X<=30).double())\n", + " num_fil_X = X.size()[1]-num_lowest\n", + " min_X = torch.min(X)\n", + " fil_X = torch.where(X>30, X, min_X-1)\n", + " # fil_X = torch.tensor([ele[0] if ele[0]>30 else min_X -1 for ele in X[0]])\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_lesshalf_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", + "verifier_define_calculation(verifier_model, verifier_model_path, [dummy_data_path])" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Theory_output: tensor(51., 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,2168],\"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\":17417,\"total_const_size\":2720,\"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", + "theory_output = torch.tensor(np.median(data[data>30]))\n", + "lower_to_median = torch.tensor(np.sort(data[data>30])[int(len(data[data>30])/2)-1])\n", + "upper_to_median = torch.tensor(np.sort(data[data>30])[int(len(data[data>30])/2)])\n", + "\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", + " # to check: why cant do with num_fil_X with X>30 first?\n", + " num_lowest = torch.sum((X<=30).double())\n", + " num_fil_X = X.size()[1]-num_lowest\n", + " min_X = torch.min(X)\n", + " fil_X = torch.where(X>30, X, min_X-1)\n", + " # fil_X = torch.tensor([ele[0] if ele[0]>30 else min_X -1 for ele in X[0]])\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_lesshalf_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", + "prover_gen_settings([data_path], comb_data_path, prover_model,prover_model_path, [2], \"resources\", settings_path)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "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.083611011505127 seconds\n", + "=======================================\n", + "Theory output: tensor(51., 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 : 51.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], [16329468921151224777, 10175872942536559546, 2714029846925971291, 664661156343181352]]], 'proof': '1e964b382349da606ad48bbc473e4bfd0cdb0467511de4a114c3bfb14fd136c22808330170f7921a3f86587cffa5650530fe46c39ed13d4667bb1212bf7294832e25fab63a8da1314224b334055173e2ceb15dd59b49ea5cdfe8d4ca3d03bbcc210cde1f93ab50f94a17ceb47dc2b8b85f3a6afdbf79576eeebe7c144c3cfd210a36829bf027f1ebd798a779fc3631935d61ecc9e892f62694356d86653445a12ed30addea978f2f76f8fcf15a0b39de4c110865492ca4a9829741ef93e0869c1572c5b98debda8306208e3ac4f2791af9f907a1250053495f7d5ce89bcba2da04c2f3cbe5f9c0e66fd3a9424dc0ea8d2fd9442c26ce842ba376b80b92bfe9400c9770d8e37d0ac1af04fbc06c9f3b866d0dd5034cd1802a1c4247cd9a02a20b0fceac2ea6dcbd03d59bec590fbf573828b0dce1d315aa513a7758845305b64518de4eb175b6aac15dc8da520d13b901e7a1664a7aea3a98f405ae76eb512e971ef36a3200ce03f6099c0d184841b9f67d0840c670cae2e0db37caa3c935993d1761e8f17ff15c7385cf2d689390a719246c442d452702cd47091c9d1c2459c028f6f579b15a6799bf0a940bd88696500bebd6676f11126a3c3362a5c9c3534409ef056af22f3dff87829095f03337761a20289bf1660d78abf7eb0a31f6b79a1885c6f33e9456304df725281a5c79c4760f08df66c836c047380887bb06dbcb0065ff6a493df581d6788b3f22daa85dc794312964ba253c16e80e2d455b707126b0c6942b502b6bd72cb6ce876b3926c0ed7e02e32758f8ef4978ebd1e978842a7077728c5b351166882d9ab8ac12fcd5a4d3819e78b6c47e99f2c74f8cfedf1582f4b08de0cc484e44b3acd663ab3f900eee39234aa3b799ca09cb68bb63f42ff50c12db12e7366d46e7a02f6db307d0e167439f6e90d494a7d9f6871a26a01b3bca881616ab48b058394aacd3dbc2b9242ae970005c1bf9d5e4922fcf27020e57d0d965b525fa0e28b00eb7e55833f5d966f0888e0253c8b59965ab482c1201733b5773c604b6ef325c8cb61083c00209970851f9303bd492dd0fc3ec49d513ee8951b7bb70f4b526dce052cd8d2d7804454c9399ada12583929c39eb612d27dc058e8551544be2029188be999bf216d280df881d91e1c19b24663437561b111a46367b2fd0957e1a0bc64d93ca6aaa1a9ecf3e65a81568b594479aa5e6560355a390ff4ce2245a6924f53e614b54f7f52e8a8267cfd4c4fc6b35e48703f40ba1b44cc7f328dfe06a0a2954f1881eb1ec187d4083fa57dfb4bb2d8497c6fb2b2e970febedabaf5c95366908e0c90ecd379df79071b0e57ac17197af813c53105dade3188d564c2098eec6848b2bb72cc74b2de6f4966517af714da24f2cca2e415654867b72c619f9d6e70bfb58fccd62b25b201f8d4bff39a0921a024bf70c9a71b9bad702efd7a6fd3515e64af7956b2b4019fedc7dc58c06cc6d363c851e5b60f4a2288240536e9b34801bface708bd7b8db23c1e41666bacf1419be6c257fc0cc8d726b87375b3b1a9b6b07021ada521009e0576fef3aafa4a59ae946198c1e828eee14c9cd8df3fe00c0a731c8c06e22442825048d24bcaf69f268e019fe6f98e1a05c0241591fbcb1346145bcaed03d23f04ad927c8791e069260ca295b4a2ee667c618f65fb98ed7749d0fc0648390d4871399305a554cf5075f201f289566288639a8098f1e34ee8eac2a5f8c2cf5a000282fd040e11bae82a967021a1b6647cec907304d8063fff56c4272719ee39c69c26ea9b0e6c8be807168105dade3188d564c2098eec6848b2bb72cc74b2de6f4966517af714da24f2cca2e415654867b72c619f9d6e70bfb58fccd62b25b201f8d4bff39a0921a024bf71f31626024c5cbacaf4bbc28b1eb1b075c646afee0a91700ef53e5b62a78398c29f41fb2aef0806e17c79eec5ae20470b0f99fb73757ab8ab545f920952e5c89196c16e9874a7102f671d2e84af3131aaa0b16d765d0f20b3c50b76dc5d8941d038f7e201c2ccc598193c9d265cf6d2811df76c92fed69148fe1cf23dfd26da827244453a8c22fbc882558db0d6e0f219858b6bcb111c306145a2c9c10b9fbff05d6de93afff13a577a67f2db59e9ae4ac1544429adf87ff1ee0b1428b0c547714ef5a14cdd83594374df2593da2f69fefb71c802492655dd75bfd2594e7432913ab51d00be929a1afccc32ea39249555d50c272d7ab96464984d90da3ad55f5012a04ca03da0a1f6afa94831841446f485e3cf6b448daa9e701ae0ef0b4cafb10710087e08b90fa0a682509dd2337ebabcbcd73403a11554a45798adf96f323231df25aca25e3a0e1be6bbc7ce1b513167fd4bb973d54015a732fc8820df43d1db4ca2eee7394bb0739f328b60e91c067494cd051edeb0a04cc8b8b70aa838e1d0c30b693491c7cce1291c452475b06df0aeb2bca9a738b693222f15b377e8300b308ca5af7010cd5e72e0739547b6737f9b83569a76bd2638b7ae772ad48f60064a20b8db339ac56ee8b5c219be05eea3a05b0218e9e2121b8a886634a1a2d193f6fffbc3305484141392ee19698eb5bad133cadda8878ad880a188cadad040cfdcffaf69920396d8e33966f440310f92e775e221f792830e5fb679aad53272c17c198d924c45e73ffe42544311a19c1a02b2dfab5e6f9e2484317307cb3de067d65382403fc40c11023def9ec1022d8d1a2b96ffe4d0ab22f7e33b314527203db8b5d35b0c12a2c9e717c4c7627495b8db8362f64c0daad18cecf43860825057adde52718481a3ae743359fbb0dfbbfecb7726f63489cc2cddd10cb6481bc210e63872880ec91804329336f0830a01e9ecea715880a42b82e06f20eddf318124038a8b86c772f2cd43f0ee41d11c04a00f760d36a46d3836504a60bbb740623826621c6b70665fb8af582967f1494e16515acc85e74b42573d26da3389ca52570ff845d4d7fffb6bdc9c4e2fa687c7ff232197b39aa422b074246caf631f802befd33c4300a3f26b9a282def59452fcf755b16ccecdecd7db35cde39ed7ea192a64404c19758314f7eec44d01dd5937e89a8cc6d17b74633305e4469172c32494d77a1b3e29accb9a4b05b3d7353cd1fe12f03edb3b3f7a3739c8295a0a6b0ab97f6ca7eec2b3dea0f492e09874bd61c875301cd97dfe1f83a77957e15eb924087423ef41cac4e4d1c8b0f4cad2f5509dc3b971d7329d884620091661a10c2ede8c4ea655bd58271ad54d3b6107b20e56808294e1cda69c8b257c898933e311f46b4f34f609106b3efafafe6459c2023a553a2856cbc4685d454576fa45b01a346aa77b79a0a01403927a0523021881b90bd83fead74c13791893e02060180f1c743e8b9e9f589c1958e3a89b05dd24f7790ca859ac72e625446fef31a9302842b58c34c9515a5a4e0f2302bbdca50e5845b675ff1ae77ff14c98b7420ed505773715908b3d0273857e7d3f7be0f636a30f1ef5a4ec60f6c5feac9c9ff48308d6b88d27a8bf17dc28efa1936bf38d25788d9e1ed661876415c21e1d32a9d31ae62ac6b49b130d5938ea72c58786817465da25211872dc2b5d02ba19c44f6426fe85f6a622b7d335634df4bfb7efdd0949a4e2d0958c4fad290978d6bd25ff2bfd8a53797b546b4d58ca1ec338628e39357d93b733830e18ed5410ca15a335184d616ee3478ce9b7b40bee23fd5102f678fc6d51cfcf2ef8077e5039281ea60ea6da1da0359475ae069414c8b12eb5b01642657b46c89aabdbfd23b36b944715aea898be0cc13e1c5f0da4062e9a01b5beaf7e6bbac1616683eada57f3f7ed034bf9f7ed40747daca7d8ae558d2ec712fbed59248d3bf553ddfb60064e669727f68270ea74dde02a7789617afcb17e1fe52641e1eb453ebe2863865e778d4408e0197da176e7cde0fda511e5cb2f5424625a9856aa9e48048f4ae6527316ca068831c75a32f343d95eea4a1dfb7281caf0bc4b0185184697d9e94f10570d8602eae28a2becdbb83590383be7bdde84ebeb7589b214eb8ec90cf2aa90a627a4236fe4a81f92bb9c3da2014f49920c8f91b7120e9932cb282b2f112b15bb90332f625099d363fa17d5a49d273a74a3b1cf0c721b3d1fb6bd486fafd312d895dd2d1b0800723f2bcc8883836d3a112b948a1e2d966567c266f219cf2d2ee6fd6a2057fdad62c1db31491ceacdd032620188e51bd59a79b8968b619aec26507f1d0f78b07aafa9f86c7ca14c13cc6878e0ea9855bd9118ec9803f2edb9883badad0b533be802140fd1cdd1681a6e17e24964581668904a9e0cbb54bad00485c0e509e39dfbeb9b415e5563efce400c8ae72799b8762a4bb134d389b4833f7f83151128d105c8144a81134950040d1b348957f22e468bfb6b2e8e98d203202157c90a7fec8fa8691115c7cbdaddde78a84aff32f3bc23cfce97e635d39059dc7f2124ab5149c87547616d101666bd4756800f8aea0d7a0cbada59c156acf515b75b03db8de435d3931f0836e318f36f6e5923e49b83fdf2a7d26b59e099202527230a2ebc7f1d74f41bca43fe098b8ebed23e2e7517d21ca50d0672914372703eb30b28990be6a4f8c9561a72f8688e056b7c0ebe4734d2ac8bffa6b3ac717576652479ab1d005eb943ed658089194aee207aa72c367a57bd520758887773a409f20ccef411edadbc7dced77e80d5874173b47f77044bcf614880736c08c6735f9f16cd9c76aa455fcf1c0aa0c810403b5e247333b61a80d7e7ba823469c55277110072285e066d6acc01f65ca9b6a86b9b83795d792636d704a1f4ff76250bb4c80c2f6aa76356d175d17267195d57071bb0f34b5860fc657ddc5a96a7fdc255c90be52e7607a56e270f68d6acda2377bd2c91da3d658198e7c490e411c75d1e69165fb29d53127bc0374bab7332813a35b3c55526baad730ef2b2aa6218bee3cd26d93e225889980477e4d4a475b407b91d24e329f4b621bd998458bde151449403e16ec3a289757b13311dbb28b8aa1b6dc09556eb779c04919ffd1724403b1500000000000000000000000000000000000000000000000000000000000000001a98203227c083c71253c23210b56dda353769549181b07ae1f34fd834ea638e018f5601983574e20f5cbab3043f367f060cc2f112c2a749d64d33fad568f74914e01605d6c37d352a6da428bd11f2114c508a646347fc01299757bb9c47ed7e110e8a235e6037df7a63850c154a7c89f9cb89265c03361bd02c15c08711cc9f00000000000000000000000000000000000000000000000000000000000000000ecfde2a2ae707a41fb08a4693437c5ed643ca5e287e0d41f2c473abf30266aa0d707f0a96dc29a1a29ce601509bc5542b829d52bb985cdeac7542a4231dd18f02993fe3e9c2cabfc5273fd44747c1e9b3eb87d8c984d2c10e3830bd4c5533b20c441ac2228caef8d7cfb1ccf33e1caff61fd527839893f65504538cb3af7abf139fa14425a2efd00bf0eec3dc89821b04150fa57559a0e006aa2687f62d670401cc73298195ecedcd772cf327c9ab36c9f88afc5b9531301b1ee0cc6a67738d1d72eb817fd8c6699d5ca99e6edaf83f571abe080d6aaeaf00c03a595579b1bd26abbde6ff2022e827a119d643f12d085f94c65e222973ef5484292f559cc20411faba2492e0cd196a1d4678284ff3619c943fdeb1b1009b0be4c7df5bccde882ae5a073aec10a5fbb2128aa24594d46a032c39cf458de22648bc92239585b08117dba6ed05798c59c18e86f1a76ba8b2020af1279e1d3ea6602c3cfc56d909d22b869a34d199ba75128c0ada3603a3e9cd5ddae1952280459c2b9cf8c71e1f4123b8aa8f19a6e08c35dfca38e39960f419783736dc0f81692fa91fe3c5e54bb2f0e3443e68c9f0efc71b296e313964f21d7a060511ce3a397a8d0324f85fdc625492ae54ddb3719c0e6673573c16c1bf37910d66144111a662308b690b45ff61aa3b7e50e5a3630f0944017836beb1ded1cefc6f231862eb0b10658b40008c00901837ff14de9389e3dba3606c21d2a6db6749848950c42a6f72373addb57cf03a1203f1e8951bbb9f627ae5b1f6debc55dcb16ee2721d5c53ba9e2d40fbf4f24d55aab99600d917458da3e29cf7648d35f0200c82b142d92e1fed492d0856606cdd87e96911fd0286943b13fb1b4036ed474e4189b5aa2a2201e8315598ca21c7b078a2b9d296cdd944bbce328208d755a3603a9aa55f3be1a6b3378f6010d0c2a5c171c6b0a94cdfa093c015745607dc9ab136a5711c6b0e1e5388ee6ae5e07c3bc0075cbe6e4174937b46f01ebe4e3b289022bd58c693306260c28fe33c001659e28a4e9d3b7be70031006a255d90e71e603860f48ff1d41346a199db77523363bb2be27e627dea87bfcb5162df04ebbd6e51f111afbac421f71429b33532ae04ea3779ae40a98b9c1733b858c475b4bf18393912b59e461bbc5cbb273420c8b2686a4d90a0b5158f157a04be3e59d5e9fdc6363848cbc3fbf2e2d74e58321a5a44f6adc381b11128c3fe1a3f5061aa77281a7e842f3812216bdbb52b26608e7b49c121ec7a65110980d6e859532724a413782437aa7f83597ad29ade0e916c4b0e45a3935491930d279b515ae5d6f429c82241362e50fe2bb014fa03a91019906ed2dfca25f8700edba68eea961b6647ccff489ed7a0cc4fff5fbb7f50504d5254f831747e65ee18c666f5a731383162e44ee79399523211ed767ac09510f8315515db7d73028fc8e940937aab4ecd5a9f55c4b5b88d7365f01ad45f52011f548c7f71d74fd2999fd1d1c13b11c98fcb3a926bc35700338f6fa3086a7b91c3dca3cb8843f8b2951fdd4e8f7effcf13383801e770c77e00d8aeadb47b6f305557d59acec1660c7990c8cafaec141527586bfb41cb80eb9824ec83b551a680bd16aefa68cd37a437b67cd726f108d92a8efe561751f60971dd943196ec36c05173739dd8c1b50abc686f83ffd4bd3676f54587dbf4b4c7ccd9d55839c8b1a2231f5f8bf3d4ab621dce659d5e845c785191309418c7c86c1e312182923fc7b2d7d7b49032d70bf66d12cfb509a0a6ea48d035e4ec4679b33f7d8dcfb02e7c203a21a2f33ea7d3588087ceb6482ddf0f97a3bc32e568ffbbf84c8c903194b4024e9caf78e464ff0d2df5b54fa942af73ed1434c91029c9079ed42e08db9568e176e44c9b3013395604aa8e754acfd4969987235f67e98e22e2c75a98eb825042eaf5714c15b09ccfa5c098091aaf197582ded7925dcdf664e77a83de30006921013136a96a92c38de0b1c16eb32d3d92eec4039b56d1eb18d03822c3517a10b2113245b5b07cb59b45dc0804da266fe3c5bf92c8b871202696a76d9da9d2de10b80f5453a397cdd6f565290985ef292f974dbfc321c710bc8ef61472bde0b9f2b9e4a48bf42e68092fbd204d563aa27be0ca08281fc4a0ee724278b002c41d022fc78d498a9ff87592e935a25c61b9ec641dbf4a63c2afaeaf93af0662c9454021bc834ec9faf29f0d55e2e83517445d8cebef1b806f5cb6dcb44677358d5b20855a5d15e14817a8f0bdae446744f13d94f93ec4bef753a8de87e8fb2dd7e3328877e5cbdea1050c426d42bf08327dc369354baa1269a0379ca89ab7610d7be2011699effee1012a0f07fe064540575a3bdf1a7fdd6d9726c00282069b6e5a7262876a226fd3f5c88d4f35c1433b3be486284cb65f110dfc12882392396c6ea2ebf8ad1a04f68ea2ae694e4ca70a92b3d05008c39e89665c8e802808bc0f2032c9c811025acf563f48917cd26aed4166ed2e9d0eb41169fb985aa6026d4def50a9d3c6e0d632ed55f6dc03a5f963162738e40e42084a126e8af053531df387a2d8d9b0032bcd12e0a7992b894a55434fd948eb377673f0f1023b07856ad97f02387043636153ccd3da68c7f62daecaabfc43f0e71deb1a07fb7d8cc6f4d29772873c40b8e3d19afd61dfa83417a92827ba1f8aff496708b28ed27f20ec784a0275bee154fe942a55adec5e181e98604a720a2c3b9d3578e53ae6ff049a0f60b11ec9ffe9a9293aec07bdd70fd0317cb393758597866535548e0dffa34c4abe317c6d545deea16d8656a297f2680a27c381c65b44ae3962427ea17337598ae79075bae3664d77d9b871f6f79620733e6283281907711dd47728aa9bd5eb436be1b8bc978688e133a6bf2447c95205bb2572fe04de383855087e863821621d3391f64929df242a5cc1a73692d50f7fcdba5bf8d36f75a85c17b38cd6e388493271a1596833441c1c83b114ab6e61f969ff73c39515fbfa95570945b14466d805a2d4301d73e0485dc3d0cdcf137ceecd63bce3ae7058590b133e5ec237109d78b262876a226fd3f5c88d4f35c1433b3be486284cb65f110dfc12882392396c6ea15383223f73dfbf672d4a45dfd9663e37bafbddf1db230de0bb6bd680efa223522c9f3786c87d667b9f8b78392d33878c1374ac6f1fd31d89cf989ce8cd39b3714c3aefe00c0ee2b25df97b044428b6a94cdfb37cfddd27069c92d90caa11e4823952c4c2b1ebb90aa2cb7300129fe7190ba6638a12c270b9badc4f51b638ae5', 'transcript_type': 'EVM'}\n", + "Time gen prf: 3.9971389770507812 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", + "verifier_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, comb_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "num_inputs: 1\n", + "prf instances: [[[1780239215148830498, 13236513277824664467, 10913529727158264423, 131860697733488968], [12436184717236109307, 3962172157175319849, 7381016538464732718, 1011752739694698287], [16329468921151224777, 10175872942536559546, 2714029846925971291, 664661156343181352]]]\n", + "proof boolean: 1.0\n", + "proof result 1 : 51.0\n", + "verified\n" + ] + } + ], + "source": [ + "# Verifier verifies\n", + "verifier_verify(proof_path, settings_path, vk_path)" + ] + }, + { + "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 +} diff --git a/examples/where+mode/data.json b/examples/where+mode/data.json new file mode 100644 index 0000000..cbf3cf3 --- /dev/null +++ b/examples/where+mode/data.json @@ -0,0 +1,31 @@ +{ + "input_data": [ + [ + 15.0, 38.0, 38.0, 70.0, 44.0, 34.0, 67.0, 54.0, 78.0, 80.0, 21.0, 41.0, + 47.0, 57.0, 50.0, 65.0, 43.0, 51.0, 54.0, 62.0, 68.0, 45.0, 39.0, 51.0, + 48.0, 48.0, 42.0, 37.0, 75.0, 40.0, 48.0, 65.0, 26.0, 42.0, 53.0, 51.0, + 56.0, 74.0, 54.0, 55.0, 15.0, 58.0, 46.0, 64.0, 59.0, 39.0, 36.0, 62.0, + 39.0, 72.0, 32.0, 82.0, 76.0, 88.0, 51.0, 44.0, 35.0, 18.0, 53.0, 52.0, + 45.0, 64.0, 31.0, 32.0, 61.0, 66.0, 59.0, 50.0, 69.0, 44.0, 22.0, 45.0, + 45.0, 46.0, 42.0, 83.0, 53.0, 53.0, 69.0, 53.0, 33.0, 48.0, 49.0, 34.0, + 66.0, 29.0, 66.0, 52.0, 45.0, 83.0, 54.0, 53.0, 31.0, 71.0, 60.0, 30.0, + 33.0, 43.0, 26.0, 55.0, 56.0, 56.0, 54.0, 57.0, 68.0, 58.0, 61.0, 62.0, + 38.0, 52.0, 74.0, 76.0, 37.0, 42.0, 54.0, 38.0, 38.0, 30.0, 31.0, 52.0, + 41.0, 69.0, 40.0, 46.0, 69.0, 29.0, 28.0, 66.0, 41.0, 40.0, 36.0, 52.0, + 58.0, 46.0, 42.0, 85.0, 45.0, 70.0, 49.0, 48.0, 34.0, 18.0, 39.0, 64.0, + 46.0, 54.0, 42.0, 45.0, 64.0, 46.0, 68.0, 46.0, 54.0, 47.0, 41.0, 69.0, + 27.0, 61.0, 37.0, 25.0, 66.0, 30.0, 59.0, 67.0, 34.0, 36.0, 40.0, 55.0, + 58.0, 74.0, 55.0, 66.0, 55.0, 72.0, 40.0, 27.0, 38.0, 74.0, 52.0, 45.0, + 40.0, 35.0, 46.0, 64.0, 41.0, 50.0, 45.0, 42.0, 22.0, 25.0, 55.0, 39.0, + 58.0, 56.0, 62.0, 55.0, 65.0, 57.0, 34.0, 44.0, 47.0, 70.0, 60.0, 34.0, + 50.0, 43.0, 60.0, 66.0, 46.0, 58.0, 76.0, 40.0, 49.0, 64.0, 45.0, 22.0, + 50.0, 34.0, 44.0, 76.0, 63.0, 59.0, 36.0, 59.0, 47.0, 70.0, 64.0, 44.0, + 55.0, 50.0, 48.0, 66.0, 40.0, 76.0, 48.0, 75.0, 73.0, 55.0, 41.0, 43.0, + 50.0, 34.0, 57.0, 50.0, 53.0, 28.0, 35.0, 52.0, 52.0, 49.0, 67.0, 41.0, + 41.0, 61.0, 24.0, 43.0, 51.0, 40.0, 52.0, 44.0, 25.0, 81.0, 54.0, 64.0, + 76.0, 37.0, 45.0, 48.0, 46.0, 43.0, 67.0, 28.0, 35.0, 25.0, 71.0, 50.0, + 31.0, 43.0, 54.0, 40.0, 51.0, 40.0, 49.0, 34.0, 26.0, 46.0, 62.0, 40.0, + 25.0, 61.0, 58.0, 56.0, 39.0, 46.0, 53.0, 21.0, 57.0, 42.0, 80.0 + ] + ] +} diff --git a/examples/where+mode/where+mode.ipynb b/examples/where+mode/where+mode.ipynb new file mode 100644 index 0000000..0ae1d74 --- /dev/null +++ b/examples/where+mode/where+mode.ipynb @@ -0,0 +1,392 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 14, + "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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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": 15, + "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": 16, + "metadata": {}, + "outputs": [], + "source": [ + "%run -i ../../zkstats/core.py" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": 17, + "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", + "comb_data_path = os.path.join('prover/comb_data.json')" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "======================= ZK-STATS FLOW =======================" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "def mode_within(data_array, percent):\n", + " max_sum_freq = 0\n", + " mode = data_array[0]\n", + "\n", + " for check_val in set(data_array):\n", + " sum_freq = sum(1 for ele in data_array if abs(ele - check_val) <= abs(percent * check_val / 100))\n", + "\n", + " if sum_freq > max_sum_freq:\n", + " mode = check_val\n", + " max_sum_freq = sum_freq\n", + "\n", + " return mode" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "data_path = os.path.join('data.json')\n", + "dummy_data_path = os.path.join('shared/dummy_data.json')\n", + "\n", + "f_raw_input = open(data_path, \"r\")\n", + "data = np.array(json.loads(f_raw_input.read())[\"input_data\"][0])\n", + "# data_tensor = torch.reshape(torch.tensor(data),(1, len(data), 1))\n", + "\n", + "# dummy data for data consumer: arbitraryyy, just to make sure after filtered, it's not empty\n", + "dummy_data = np.random.uniform(1,100, len(data))\n", + "json.dump({\"input_data\":[dummy_data.tolist()]}, open(dummy_data_path, 'w'))\n", + "\n", + "# where(element > 30)\n", + "# dummy_data_tensor = torch.reshape(torch.tensor(dummy_data), (1, len(dummy_data),1 ))\n", + "# gt30_dummy_data_tensor = dummy_data_tensor[dummy_data_tensor > 30].reshape(1,-1,1)\n", + "dummy_theory_output = torch.tensor(mode_within(dummy_data[dummy_data>30],1))\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_89165/3199990219.py:11: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else min_X -1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_89165/3199990219.py:11: TracerWarning: Converting a tensor to a Python boolean 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else min_X -1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_89165/3199990219.py:11: 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else min_X -1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_89165/3199990219.py:11: 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else min_X -1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_89165/3199990219.py:13: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n", + " result = torch.tensor([torch.logical_or(torch.sum((torch.abs(X-ele[0])<=torch.abs(0.01*ele[0])).double())<=count_equal, torch.abs(min_X-1-ele[0])<=torch.abs(0.01*ele[0])) for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_89165/3199990219.py:13: 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", + " result = torch.tensor([torch.logical_or(torch.sum((torch.abs(X-ele[0])<=torch.abs(0.01*ele[0])).double())<=count_equal, torch.abs(min_X-1-ele[0])<=torch.abs(0.01*ele[0])) for ele in X[0]])\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", + "\n", + " def forward(self,X):\n", + " # where part\n", + " min_X = torch.min(X)\n", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else min_X -1 for ele in X[0]])\n", + " count_equal = torch.sum((torch.abs(X-self.w)<=torch.abs(0.01*self.w)).double())\n", + " result = torch.tensor([torch.logical_or(torch.sum((torch.abs(X-ele[0])<=torch.abs(0.01*ele[0])).double())<=count_equal, torch.abs(min_X-1-ele[0])<=torch.abs(0.01*ele[0])) for ele in X[0]])\n", + " return (torch.sum(result) == X.size()[1], self.w)\n", + "verifier_define_calculation(verifier_model, verifier_model_path, [dummy_data_path])" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_89165/461458.py:15: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else min_X -1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_89165/461458.py:15: TracerWarning: Converting a tensor to a Python boolean 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else min_X -1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_89165/461458.py:15: 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else min_X -1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_89165/461458.py:15: 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", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else min_X -1 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_89165/461458.py:17: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n", + " result = torch.tensor([torch.logical_or(torch.sum((torch.abs(X-ele[0])<=torch.abs(0.01*ele[0])).double())<=count_equal, torch.abs(min_X-1-ele[0])<=torch.abs(0.01*ele[0])) for ele in X[0]])\n" + ] + }, + { + "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\":[0,0],\"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\":299,\"total_const_size\":0,\"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\":[],\"check_mode\":\"UNSAFE\",\"version\":\"7.0.0\",\"num_blinding_factors\":null}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_89165/461458.py:17: 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", + " result = torch.tensor([torch.logical_or(torch.sum((torch.abs(X-ele[0])<=torch.abs(0.01*ele[0])).double())<=count_equal, torch.abs(min_X-1-ele[0])<=torch.abs(0.01*ele[0])) for ele in X[0]])\n" + ] + } + ], + "source": [ + "# prover calculates settings, send to verifier\n", + "theory_output = torch.tensor(mode_within(data[data>30],1))\n", + "\n", + "\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", + "\n", + " def forward(self,X):\n", + " # where part\n", + " min_X = torch.min(X)\n", + " fil_X = torch.tensor([ele[0] if ele[0]>30 else min_X -1 for ele in X[0]])\n", + " count_equal = torch.sum((torch.abs(X-self.w)<=torch.abs(0.01*self.w)).double())\n", + " result = torch.tensor([torch.logical_or(torch.sum((torch.abs(X-ele[0])<=torch.abs(0.01*ele[0])).double())<=count_equal, torch.abs(min_X-1-ele[0])<=torch.abs(0.01*ele[0])) for ele in X[0]])\n", + " return (torch.sum(result) == X.size()[1], self.w)\n", + "\n", + "prover_gen_settings([data_path], comb_data_path, prover_model,prover_model_path, [2], \"resources\", settings_path)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "spawning module 0\n", + "spawning module 2\n", + "spawning module 0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "==== setting up ezkl ====\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "spawning module 2\n", + "spawning module 0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Time setup: 1.3078458309173584 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 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "proof: {'instances': [[[1780239215148830498, 13236513277824664467, 10913529727158264423, 131860697733488968], [12436184717236109307, 3962172157175319849, 7381016538464732718, 1011752739694698287], [12341676197686541490, 2627393525778350065, 16625494184434727973, 1478518078215075360]]], 'proof': '1f9ee4c186f5c5a89f93d5ebd603104cd3aef47605542790c6eafdfbf0db47da12f265474542cb1e6d6844469f1fb9270d2a4efd3fbc137507274f89528317ee1ab9e9f0d1cea2fc89eaa4edff89d5f99938a9c7511d268653b0be77f14b348e3057747663dd3e49c2e89ccda09e624d4706b63e3852f5ce019d9c1b22eb47e91d871570117db109dae096aca44d606f3dde8f8c8368234be799da23d10cea961a1996dda8b139b97dd54454cdf41d5e3d4fcda307a2528d4f52445495b1e7d505958e7035a63538b4171a43774a8127d6e271533d8b5fb9bd3c75745147e2872abb221b6e5d925b18377260471e3bc7e7b3ce09bc3bcde57dce119012d2c541037b9919204bdb6537b6bd485155cb973964f1261a485d54d429d9f15fc24bbf2ece8bb42379e104bb699035b839256c880316cdc771714744613fdb8159a59a0916897b752f61ef906f9bb893c804e530b9ee51bb05b79f95fabef46c0f1e75017164f1cefe8b726f197859c9dba62014e3f85a23f4f76966d4605aea83622d1cfafd687079b67fa3fec66abbe878c17074a5c2cf3373368f7658a7548c74ee0e663af8dce1c6f49c6c2c6cf5f857ffa3f4787d273ab6d8c1d203c1df13747a05c7f85b78886a9ff29cfa374a998652d3b2a5b4c80487f1e8b0f0b75752536820d0029079483ff7943bcde1c100689eab925c03ef77c8402ee0a4e8b9e376330d62bb3f66fc80112bf77b00db6e18edeb86ece7cf822bf22aa2d7a2f999ff152c3b35a6c293e12a22280cee736015a14ac2b3b04100828135ac5289b973f7cd012fded97e6a42fffac2d6ec8d550895edc0c39f85fdf9c2a22cf8c5cf3be8bb25b18fdd9650aef464f7d68c5a714f2f24f5a8b3643defa29a550a5d15c06d32030d3a9666f3decf740259434b2bdce20361d82b1ee37207b3280947a6de17031e3d3b40375743b7d4b541f84d22d7d51116d1d3aaa574861a3732c428ee49c60b53370b292bbf45e539f2062cd5983ede0c3efb0a6165c0e5fe1b0bd3d91a5322cc1d372f45f25e505e30e766ca024ed0d5df4d1171b053894b54a0c3f89f0f0fc4b37ae1a33786d5168b943c19e370d83c028b48b8e5b6fc30d034acf422722153dc40515a542cb99cfa617d47c5a0734ca7df8463ca5389a5906857fc51a203e849931152c9155ed631e4137aa5d6808553e43dcb8fdc6e548a501f1ae16f04380d6498a64cd63e94a0a4cd537d528344d56f6861d2f2a1b5b0619038a77529b0e83133d80438b62167effbcfc610089386b71603c1890a098136e66a939e22159be15314b5f7753fb8a91f5a0c5cb9e244590eadd4c3135d8707bbbb14d5079ded7fea98bc3b46468d4a2e3a04ab3971c3185fa0693c47f3fbc726d39a582f13b8fc615738855ffb6868a24a18c96266df2799ff1baa3c6a61c72cc484f40aa9fc96f026b1d8a193da51dbcfd505bfd6acb4bf3f75b7b274ef46b83be3a32bbf761b739320a1781f424cb3eaf834cd5aae76c3c9e284e7080ce9403b72d026491b98ee3977499fb2ee2fc7893e9f1cd0c5c636e8e6401b30a8e39873d5601192a1edf6781c8de13a70714d1df8acc89630b49f2156823506c1987552957c064683c510388cb8ed3ae15c83326e56b1ca8aa63456fe687ed2879a7f08525d24d8c5db174f2f847969e521bc991d509fbdc31bbc12e01a417e74f8c399077821c539359d3df2549a09a0417ecfa492fb7700f502ee2fbdb6f3f5b900715db412b9ab65a5ce9f63d2331367f6afcdaed7edfe26f2dd7d31c50b721a7bbe6152197c24e847d5de6fc4c910a09269a7225af29eb0416a0be87b4a03bdead833f31cd3145c7366308463e1a7fd5939699c44f1a4a6e8f443982c463e4ba24f104d2ceb5f3d65734299c6b704e693f085798ed985552a8dbbda6e3705f9b67895962b465bc3fd6e84075e0f2f9d1f01341adc0c0889be59cccddd174c9e801ef9442359c94b490e5ef98b6eaf27703b4c8d5b8e9a7f8b5fb04cc9f9f9376d027bb920af9f752c687888a0ef71077869d8296e3352e4f3f0bb7669bc04fe6aff6f9413076102f95fd8096caa431cdb2da7a066023bd81ddd706038873d62a2f878f1047dbff6c43eda9ad95b130afc3d9f4ba19d7ee0f803c63fffdf59d785d397a508dbefad85cbc68503f70c57c42d63798a05848e701dfdd600a039a64e0fa3781fe808c51c41bc4f7bf6de729fef89f7c94bb891bb8c77cfceb7aa59cff8b5300c8445decfbff7fa70321dfe6924b0a8e00bbab11443e2153b4480dff634072115091aea92b4b1da09f1b59addc7f8cf69805224ee2199ac202702a4338963621bc262d58bf79d16ae288e4af9b0ae0f7bd68c2ba36d572bd439d752fea60eba19868d2f1c4d54e7b0f00817d236173ba8e5f6c43e011161a16fbe744b5c1fd711a19fb17748a52308aad654d4678bf6f9408482e11ee0edb6f0501044e6cc3419378606a6bc1b0403480f67d1cf8fcd70982150eac19eed1bb6ca4630363c82015de21d540a7f8ba94e71cde5304bf1fa02604f104e3876de5def6f53293c8512e605191bd256bf964d7d41baacf689c406e7ce8bb77e8dfdf74d3ff924bead0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000021d2f8689226d604914a4e970fee4497cfeb49c630880a422fa5930d41438b820f6bef9c8557e44a5112aa1ceb91cf86712759b180949a7257ffa862a32fedc71b1919aa95462af826ad497b5dfabcb000eb4cbc0b4ce65a0edb326c7dfd68881644e71be430ea08d4607e6031672826e8f6d4317ae4c7ef1b7b762be8c2b4d90e6ad86ef64e5a857ea8ade232261da9a26e7ca89760d15ff1beb8fa91a1de5d2056d02aceebb389cec4d70cc7016044e569f122429c32f966a79fa93f015f6e210a04a45122dd0300bb371ba92d334c12c8a05bd4497abbc28d39fbb3520cb9221556e9b3bb9fd1ac81d792146d29aecf992a5ee1ec2299ab89111484f705d023c85c20ba505928084a514a1f03d08d666898a11415faffa09ca988ea779cba206f063988e1bd16a5c0ddc5c5f90834f6983cc65dd7f5ae808f619bd356502f2a08c36c9a599d6753cedf549aa84534bb44adb45bac2d841e159c4286e9ccc30164f54b6efa059303ef6353e4d705b4d3e94fa45da62fa1829ae478aacbdd09257bcdf0fee94b216cb012fbba814fd043e7aade1801c86338039063898f018b26be5a499dfb8eacc75336c8bd23aebb2a48189f49894998ef5d05fb2b07379616dac657b2380eb3086db1b83ced2bdc0a67741c0fe794849c6d8dffbb1fecec0c96d62817ffe59b3203983df80efed225a752093e6be22e252afa0bc7876d4d04b0512e13f4d95f569ff8532cf9ffe92a101cf135f7d35c2e0400088a0a95f5007ed14e31be5798832e498757d3e07a8f6b38147814d7c98f74b5370e4a4bca0272b7e7c760ef43ef45c6e8596eac78bd2a62a924da657aed9b5ea2ac1f93750be0980c0f46f0db287419514a8a8f630ff624cc7fbc376c8c03a58f3d168f380fa855cf3b8d3a3d18491d7d511903d76ab88f2bdf2d282d9cc2b64c634a733f18c9f5ff9fe5894c2d9675d531a9586a63441992d0c14689fbbbfdf16ba4b8e321bcd1c9cdef7f16a6b2264773f2aff7e810abab9652b1b7f84b01a911ff453d2badfdb99ebe7561b662b01e5fd35a1cdb3cb8008ba2d2f98b7388ea1bfa4c7009c5171eb20b760fe52120d01b6165c962bcb7640eac4d5d49deaf118a90f98a', 'transcript_type': 'EVM'}\n", + "Time gen prf: 1.7057161331176758 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", + "verifier_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, comb_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "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)" + ] + }, + { + "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 +} diff --git a/examples/where+stdev/data.json b/examples/where+stdev/data.json new file mode 100644 index 0000000..619750d --- /dev/null +++ b/examples/where+stdev/data.json @@ -0,0 +1,31 @@ +{ + "input_data": [ + [ + 23.0, 75.0, 38.0, 38.0, 70.0, 44.0, 34.0, 67.0, 54.0, 78.0, 80.0, 21.0, + 41.0, 47.0, 57.0, 50.0, 65.0, 43.0, 51.0, 54.0, 62.0, 68.0, 45.0, 39.0, + 51.0, 48.0, 48.0, 42.0, 37.0, 75.0, 40.0, 48.0, 65.0, 26.0, 42.0, 53.0, + 51.0, 56.0, 74.0, 54.0, 55.0, 15.0, 58.0, 46.0, 64.0, 59.0, 39.0, 36.0, + 62.0, 39.0, 72.0, 32.0, 82.0, 76.0, 88.0, 51.0, 44.0, 35.0, 18.0, 53.0, + 52.0, 45.0, 64.0, 31.0, 32.0, 61.0, 66.0, 59.0, 50.0, 69.0, 44.0, 22.0, + 45.0, 45.0, 46.0, 42.0, 83.0, 53.0, 53.0, 69.0, 53.0, 33.0, 48.0, 49.0, + 34.0, 66.0, 29.0, 66.0, 52.0, 45.0, 83.0, 54.0, 53.0, 31.0, 71.0, 60.0, + 30.0, 33.0, 43.0, 26.0, 55.0, 56.0, 56.0, 54.0, 57.0, 68.0, 58.0, 61.0, + 62.0, 38.0, 52.0, 74.0, 76.0, 37.0, 42.0, 54.0, 38.0, 38.0, 30.0, 31.0, + 52.0, 41.0, 69.0, 40.0, 46.0, 69.0, 29.0, 28.0, 66.0, 41.0, 40.0, 36.0, + 52.0, 58.0, 46.0, 42.0, 85.0, 45.0, 70.0, 49.0, 48.0, 34.0, 18.0, 39.0, + 64.0, 46.0, 54.0, 42.0, 45.0, 64.0, 46.0, 68.0, 46.0, 54.0, 47.0, 41.0, + 69.0, 27.0, 61.0, 37.0, 25.0, 66.0, 30.0, 59.0, 67.0, 34.0, 36.0, 40.0, + 55.0, 58.0, 74.0, 55.0, 66.0, 55.0, 72.0, 40.0, 27.0, 38.0, 74.0, 52.0, + 45.0, 40.0, 35.0, 46.0, 64.0, 41.0, 50.0, 45.0, 42.0, 22.0, 25.0, 55.0, + 39.0, 58.0, 56.0, 62.0, 55.0, 65.0, 57.0, 34.0, 44.0, 47.0, 70.0, 60.0, + 34.0, 50.0, 43.0, 60.0, 66.0, 46.0, 58.0, 76.0, 40.0, 49.0, 64.0, 45.0, + 22.0, 50.0, 34.0, 44.0, 76.0, 63.0, 59.0, 36.0, 59.0, 47.0, 70.0, 64.0, + 44.0, 55.0, 50.0, 48.0, 66.0, 40.0, 76.0, 48.0, 75.0, 73.0, 55.0, 41.0, + 43.0, 50.0, 34.0, 57.0, 50.0, 53.0, 28.0, 35.0, 52.0, 52.0, 49.0, 67.0, + 41.0, 41.0, 61.0, 24.0, 43.0, 51.0, 40.0, 52.0, 44.0, 25.0, 81.0, 54.0, + 64.0, 76.0, 37.0, 45.0, 48.0, 46.0, 43.0, 67.0, 28.0, 35.0, 25.0, 71.0, + 50.0, 31.0, 43.0, 54.0, 40.0, 51.0, 40.0, 49.0, 34.0, 26.0, 46.0, 62.0, + 40.0, 25.0, 61.0, 58.0, 56.0, 39.0, 46.0, 53.0, 21.0, 57.0, 42.0, 80.0 + ] + ] +} diff --git a/examples/where+stdev/where+stdev.ipynb b/examples/where+stdev/where+stdev.ipynb new file mode 100644 index 0000000..353e90f --- /dev/null +++ b/examples/where+stdev/where+stdev.ipynb @@ -0,0 +1,373 @@ +{ + "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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "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", + "comb_data_path = os.path.join('prover/comb_data.json')" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "======================= ZK-STATS FLOW =======================" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "data_path = os.path.join('data.json')\n", + "dummy_data_path = os.path.join('shared/dummy_data.json')\n", + "\n", + "f_raw_input = open(data_path, \"r\")\n", + "data = json.loads(f_raw_input.read())[\"input_data\"][0]\n", + "data_tensor = torch.reshape(torch.tensor(data),(1, len(data), 1))\n", + "\n", + "# dummy data for data consumer: arbitraryyy, just to make sure after filtered, it's not empty\n", + "dummy_data = np.round(np.random.uniform(1,100,len(data)),1)\n", + "json.dump({\"input_data\":[dummy_data.tolist()]}, open(dummy_data_path, 'w'))\n", + "\n", + "dummy_data_tensor = torch.reshape(torch.tensor(dummy_data), (1, len(dummy_data),1 ))\n", + "gt30_dummy_data_tensor = dummy_data_tensor[dummy_data_tensor > 30].reshape(1,-1,1)\n", + "dummy_theory_output = torch.sqrt(torch.var(gt30_dummy_data_tensor, correction = 1))\n", + "dummy_data_mean = torch.mean(gt30_dummy_data_tensor)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/278749945.py:11: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n", + " fil_mean_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/278749945.py:11: TracerWarning: Converting a tensor to a Python boolean 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", + " fil_mean_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/278749945.py:11: 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", + " fil_mean_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/278749945.py:11: 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", + " fil_mean_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/278749945.py:13: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n", + " fil_std_X = torch.tensor([ele[0] if ele[0]>30 else self.data_mean for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/278749945.py:13: TracerWarning: Converting a tensor to a Python boolean 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", + " fil_std_X = torch.tensor([ele[0] if ele[0]>30 else self.data_mean for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/278749945.py:13: 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", + " fil_std_X = torch.tensor([ele[0] if ele[0]>30 else self.data_mean for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/278749945.py:13: 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", + " fil_std_X = torch.tensor([ele[0] if ele[0]>30 else self.data_mean for ele in X[0]])\n", + "/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" + ] + } + ], + "source": [ + "# Verifier/ data consumer side:\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.data_mean = nn.Parameter(data = dummy_data_mean, requires_grad = False)\n", + "\n", + " def forward(self,X):\n", + " num_fil_X = torch.sum((X>30).double())\n", + " fil_mean_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + " x_mean_cons = torch.abs(torch.sum(fil_mean_X)-num_fil_X*(self.data_mean))<=torch.abs(0.01*num_fil_X*self.data_mean)\n", + " fil_std_X = torch.tensor([ele[0] if ele[0]>30 else self.data_mean for ele in X[0]])\n", + " return (torch.logical_and(torch.abs(torch.sum((fil_std_X-self.data_mean)*(fil_std_X-self.data_mean))-self.w*self.w*(num_fil_X-1))<=torch.abs(0.02*self.w*self.w*(num_fil_X-1)),x_mean_cons),self.w)\n", + "verifier_define_calculation(verifier_model, verifier_model_path, [dummy_data_path])" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/1125113063.py:15: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n", + " fil_mean_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/1125113063.py:15: TracerWarning: Converting a tensor to a Python boolean 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", + " fil_mean_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/1125113063.py:15: 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", + " fil_mean_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/1125113063.py:15: 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", + " fil_mean_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/1125113063.py:17: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n", + " fil_std_X = torch.tensor([ele[0] if ele[0]>30 else self.data_mean for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/1125113063.py:17: TracerWarning: Converting a tensor to a Python boolean 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", + " fil_std_X = torch.tensor([ele[0] if ele[0]>30 else self.data_mean for ele in X[0]])\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "theory output: tensor(12.7586)\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\":[-161232,28184],\"logrows\":18,\"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\":1531,\"total_const_size\":10,\"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\":100.0}},{\"GreaterThan\":{\"a\":0.0}}],\"check_mode\":\"UNSAFE\",\"version\":\"7.0.0\",\"num_blinding_factors\":null}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/1125113063.py:17: 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", + " fil_std_X = torch.tensor([ele[0] if ele[0]>30 else self.data_mean for ele in X[0]])\n", + "/var/folders/89/y9dw12v976ngdmqz4l7wbsnr0000gn/T/ipykernel_90366/1125113063.py:17: 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", + " fil_std_X = torch.tensor([ele[0] if ele[0]>30 else self.data_mean for ele in X[0]])\n" + ] + } + ], + "source": [ + "# Prover/ data owner side\n", + "gt30_data_tensor = data_tensor[data_tensor > 30].reshape(1,-1,1)\n", + "theory_output = torch.sqrt(torch.var(gt30_data_tensor, correction = 1))\n", + "data_mean = torch.mean(gt30_data_tensor)\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.data_mean = nn.Parameter(data = data_mean, requires_grad = False)\n", + " \n", + " def forward(self,X):\n", + " num_fil_X = torch.sum((X>30).double())\n", + " fil_mean_X = torch.tensor([ele[0] if ele[0]>30 else 0 for ele in X[0]])\n", + " x_mean_cons = torch.abs(torch.sum(fil_mean_X)-num_fil_X*(self.data_mean))<=torch.abs(0.01*num_fil_X*self.data_mean)\n", + " fil_std_X = torch.tensor([ele[0] if ele[0]>30 else self.data_mean for ele in X[0]])\n", + " return (torch.logical_and(torch.abs(torch.sum((fil_std_X-self.data_mean)*(fil_std_X-self.data_mean))-self.w*self.w*(num_fil_X-1))<=torch.abs(0.02*self.w*self.w*(num_fil_X-1)),x_mean_cons),self.w)\n", + "\n", + "prover_gen_settings([data_path], comb_data_path, prover_model,prover_model_path, [2], \"resources\", settings_path)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "spawning module 0\n", + "spawning module 2\n", + "spawning module 0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "==== setting up ezkl ====\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "spawning module 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Time setup: 25.42341899871826 seconds\n", + "=======================================\n", + "Theory output: tensor(12.7586)\n", + "!@# compiled_model exists? True\n", + "!@# compiled_model exists? True\n", + "==== Generating Witness ====\n", + "witness boolean: 1.0\n", + "witness result 1 : 12.75\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': [[[10537101196673941533, 17227541574925932677, 11187715152301828262, 1869164017182098189], [12436184717236109307, 3962172157175319849, 7381016538464732718, 1011752739694698287], [12362648763242643187, 13940026059969050459, 6027715406760125980, 2781413989188023337]]], 'proof': '02ecac8771c25429cb97b0c77e17c8feaef23d31ae3f04d0b7f10928db0ddba02b2ad7e8663816d7a53156717244a5bc3405c6fd4a8172e738bdddb12fb7c2f2181dc584ec2853d593cfba9186743315f9dcd1dcc367c90c8545bd0a24182b311d28ce0e515b6a06c2169fff5defb339f537fde1c60b7d1f6a5c7275ff18185e09bb583af239a39477c969a52b7cf7db251e8564aaccf1dcfa366928d042642911991cb23f723681c2e7a23c01efb8daa10018f46fe8539f5fb5da23fc3e15032be23f0df8d833bd95372af1ba67796e15ae4412629b0d1cb2f619597a146a6819a60cb3c3d881b2e8acd707c08a20cd946626f9c39a107ca1f214eaac4db4731e13f89e8d1793608bdd5704f83e1cba9d52bef43574ad8e506b28b63b5872022279edb85ad4dbe9e1d3f91941fb0a9462b117c9cef36539fb2bdee36bd8f7662c44c7173e7d4d3a54fe9ca4a6959870e9e2a6d242841e418d162e7552795fc720e036194d1853d1746267d49fa45507d7cf73ec6ce5caa285034ec9248de14404dd0ce80bc35b3ac20bce9394b2f58ec9d1c03b146f9c6c3dcfc80eb707c71c1043f3d7ac25c675f38ff4e7074ae716d2362e2467236e58c8337fb4b304de8a2332b4cc068d7b012a4cb18caa8c3d673dd7b3f4ce0475ad3eb52e7ab995326d072da647d83a15f86b3a4c7250520296fd9325560847cba50475615f6636184a28d3703705cb82ef6d8a64ba03a84048731f41b395dc55d38986ab85568e46542d91ef3ca5b709dd9834c520b7336311bd14809e73cb5c95a3b16d8b3ade7a7d0f8a069d0843e587cd480cd987f091a729a2dbbce4fbc5590170f22bd903ad421ef300629361be0bebbbb8ff497b378d9c0fb56610c2aa0db184f950aa7c572e11e160a640e9f7f68f8bb1fcbbdc1dd29544f99437c8243dd8395efdbb02533703051ee9b24c9918696375849752d6ad5b5e02a1603d9f717c8945ddb09b9d440a0fe70379a0a4b488534f61f3f6cd84087e47b2c3dd86e7aa7548793ade72d2153f7131af4892a6d8139cc143c811a2098a915439db6cca9ec916d54863040a0cbe6555dd663344a4cc8e9b21dc734a78f6b239dcb1390b9aa9f246023b23110b1772e571d06ef1fb46273007ff93f1ca51e2332cbb9838a1e5f1040fe9ee9128bd919e4fcb9154b79324acc912268291b5ddcbab67b557de783964d78e39142530493609744357eb27b6d9bd2045a0893f0dfc86599ff71c930b26e9cecb9919958a848095ec7f2a16a2c43ae50398678b351b8c21326164b787fdfa2ec5e1206c9b7466ebc8477218e9b6c3b54aaa84c9aafc680232ef3246a5d19ba089ac186b1a5ae85b5ad096bce3b36f64d84623113df7ad5181dbd651214cbca4359710a38a40f56267f29de43814776b8763d305eeba9ecb4a6e1b618c27740ad470164f1473084e423758a7301778721ce2af1db1e986842f2817cd7d2105f0e96b1a171c1d14a3bb382b9b4d5d8bd140de0c15abdbe8bd74168353a70b4f95a6bb081dd3306a6e6cbf720001b5c844f469bb695986d4972de212ed82e5ddf268650682cdec9d5bbf101e9abb7c5e3c023e34beeadc2b95202850b5343ee041b30909b46dc72c76c9967dac44360ec94ee55ae8daf8a72773727327329332bd53dd177c989ccd6a3dec8679d390185c0007d8eecb1c7bc92b1b9b0ddad12a9ff5c42e6ac35e5bb42ccbcd1b04bc2c80855399011b7bbe8a6c119ee662116f923ec91f9a1723c79ddddc460f2fceaee57d7ec4c5c5dc962f02ec208b1a79bcc098e227d2ffbf0653c3fa7aa3a7feb528acccc3194e27715a4596d0f07a5059784141145c606f5d8e8b0fb9e12fc22a582396397aed2fa2a90c3e34920dd5c02b8bf518c436a3277c0c89cdda02b4ba53fae989eb6b18366e15be66cbfd3a74361449187f3bd538bc7e207e9ec5930fe9c1abc12afee06c68ae3897d075b3f5483ef12367b1448083643850787208fbb52b170c3d648a9604ae3119701869daba53a2147cb60de5c2c2b5a55e04c6f4d445b7355e2d7afdb9d5a810a07fc13211bd781d5b4406f24c1f5d17ee64ab217250b161f11924aea36aa819d17e45e1ff245909e8add958f96d9bfe78da616948a87aecb3d3145fc9308be3d1335dd1474c7927fc5c2cc5a54bcb8b432da901417777cf5d0fe50b5661cb9c55631971d8678b066bd75904c09102663fae2f5028c83fd7fe1e821bb71babe732603c45d224c20f547ba29c09e1b9ede49283d3dfa37df89bd5008ae5d8ba5c48565ff2ebd2c22445a0e7096c13e4fd4ba6ea42951d7deab49f6fc9b26dae4db12485fea95c610c477511af7b0d280b5f1c0614fb05f72d6032b299d52660c7e1cdce24b0605f27cb04a62872c7c27cde22edc91a5a40c5eaa31f9451cb1f13ed280885771d9a2d51de511a41095358d3a5e4033d7fcfc926e97962aec06b2fca34457ca1a7080852bd9345da12ac613c472c275ba5aa10a98bc4189d239274053a7ba3affbee0ef66222e2f905747adb3fc467d5482c899a5a51e2d7f864d55d40403b4877050239252fcf6b6381626fa4853eb64f53e0cb01f404584e2653707ea196c1f808141489e2b858d61f4857639595ac3e22c5f4bc275784c07baf7466409bb1d0ce2fab5245eff73f7c4a5f29a2976d65abe03117fbbc4d83bc8e50c898793921a40ffee33251c8a80c9795e5f01886056102e5567a5f81bb23ce8526a27d17412820cbc4563f7a520c5922d9d1837caa5e8b32b24071ef707f806e69b49d61a8750ab6b7acae4a27b1acfbf9dac001c913ebf1b3185567d31c64257badd30de3b31f64307a50aac4dfd0d0e59e9aa151a3908168e233841e39ee1dc3a79803cbeb2b2f9ef3e674fca281405cc3dc183de1add6ed931d546ef2775dfb4dce3bb78c186d609a2e1db803f5c7a0ea5d83e566022bd181f09bdc01bf104f23530cc001000a7f13796567bc8b4f79220f4b3cb71cc9a6c9901b0ea4ee64571a6758c14e25fac55e1157fc04440b641ca366bc3cc8fd778bed1bc31dbade381cd43848e3151babadc0aa3d8db147814a6e9f472d0f4a9170e5746bade92d1e9258ccb52822d6a74b4713ac1d01609a1e5cea5f3e4e690d823a4cdd9f18e28a6ad151bfd30ad130403db64f4be5cade7c40d6e87ec5807941f194def8e701ee6eb2905b9e173291b5d2de835398f9fbbf138bf6916f68c84c0ab08574de67728549a718ce1875be44ce51df218df7e74c72ef67ae3761f9c42be1c7a7497403a6cd54416312fb2f3dddd31f07153b339db323d8829f73ca1ee53b83756d4b9f8a35b1cd352853c5a4a6e99719792a964afc1de9a84280a40ab3a1db5061c7b0411cfe55f408508a0593b983fab7c0cfdd728f8f05499f6b98e1ff444020001a3fe931ebc21ddba720b12c3f1032c2447396d1baf541aa87e37e9a5fb0aaea39958c053bdf2e7e93a207f824ff47b4cbd7778ccf03c2dfd453a40ebbc37319bfc4942870fb0a689f8ff5cb34393b397b3136feff78b61d83495f1fa87b897926c3850c07cf1ab3338e0f76c9ce68aa996f73821a75ab93be31a4bba92d38be4006e1d9182e12cbea615e0e0ad39dacdfe2b0193289de64c26cb89e7ef80e8c7d8901179354254f8b36d0f643308a43aed2309d92ae99f1ed3be644866fa729532113a40dc90542960562362ee547687f63ecafbfefd95755566e551ce22b75a17190c308b418e0fad73797478ad22b1d1f11098eb20e5408eaa44c0cefe25c6c42598fe2871662c184b1efbc6e9f862ce9679aba4c9b55bf4076b310e083cf40b4a217070e267107efc32832f19aefc771a9d630e8abdd6b3c2e4abc8d8636ec96eb8422c700000000000000000000000000000000000000000000000000000000000000002f26d502e77bfcf2e9a9c777e3d16c5fca8ff9bb7584d8e227680cf5ebbb38361a3c3678dabb29bf64162eb3edda462c00ab7a547d791dc2af9b93ed3d5884b91cd9c1e4f6d2933b9c7ae1dd21190e0a063086c5e71d9473213fd3ed7bdb07bf0c70f6983a2d78a6be9c1afd2b45a78aca8a58e9420b25ba386d7702316769960818d79f3c1461061414822ca06f6eebcba976b7c07faae3d83f6030ec45f80c20a8352e436028dc4fdc25828e62d9733019e61c12a22c9b5380f7644e0ad8ae2af1a0531edea1058dfecf9a7187104605e4c1b8efe6cc4b3cade20713b5eb672d09b4eb73f7a188bcb90c5db9c39d5d5d78feee48d63a7f2a8cea44f25974d31fede0c4cb0da0d12f22cf446a3ff97c346d19ef4a2cd802e641983ee96c6de112bf86b6a3bcbcf0d57e234fa007536356ac0f0f6177459ba6cadb0c20e9429607659955a4eebe7dbfa649660fc447e07931ac56ad06ff0e074349700c07f71707724170c90485e51d630ff7dbca329698997ae640b40bdf1f3eb366520b6b5a27a5f6583bfefb59cb8475e0bf69635681d366b6cc23ccbacf69450e289774320d9971866829a6d66609460bc611058c8973ba3e0fa3748b11696edfd7c5bd621e792fc00896fa010a1c77e3b2f84cefd0e82a00349a37c22a145bd755129fbc165e8f08bfde9a9d00bae3594d5ad195acd1a85b503c2286074415051673c266144fd64d933b646c56504e9912bdcb90036c002a68c7408b0bcf4b07b21cc86d05382359eaf650c43e494e1ca74e1a8f4820bc06986e0857dfb7716b2faa7a0e03adf2e8548b23ae4922ae54f41315e4c04d2cb6ae3db5d06771bcc235f4e408087f397257b38612cbbb44fd6298217660993521204eec3b2de492eea187ec440d26661b2de08a9cfd5115794dc99ee622800dd5bea6334409cf41ea7609212a0f7e511bce34eb3dcfd3e8ef9bec15e79f174699d098908d47dbffe1be3f8ecf0a7fb3844644a7387e13f83ca878ec25285e725621aa14e40e2ffc2acfbfd3530a0b431700f4abd337b57242b19e57ec5d5257a359960d39d8598abda6639c260508354c1a14a7c4e4d2f62f67a4a6f77413c8877df53fd9fa37333745c35c2d263e7ed254defd8f690355e987928387a8376b46cd535a90fafc7bf2f0ed3e3a25354a102141f8b55111f39840e46510cdcc44837d1587c33c7b7cf843f60e3100567f0e44087b7fa80e59966d126998749b412c331719c725f0510c1fe1ae560a59cb292a0bef8115e348e341c79f2bc1c0d8261ea18607b97ec8ecbd1b9d1e2d73ed0b15ea7abff25dc816db5193959fa691b8e0ba83848670c3ba8fa15cf21e1daad8bf0c0e9e5b5210ece948042108c7cbb22622330736a96d256ca621a312f7b93829baa0d29820cba5930a5674925c22635f41a0130bb5516b079fcda5130485882f8902f1a46ca2042dcc39d4ab011e95431b04a0d1f98024816b3ea404916063a4bdadbc9b8c71aa72e4cb6924f0404f94e3164351630572488a2cc621c7fec0042dc696d13b079826101db22f45715247194a75395626c36fb5b4bd086075accb08310febee3957c75e2fb339837e2f880a1879b0b4dbd94f94dda8221c5cb15b0be008091dbd73b5354723599c4a6dcab2aae8b6dd1f78d1e35a7d04a47d3f86bca5dc4edfdab3edc8fe06ad74c78a83f4ccd481622d70f7a02c2c06d05a71207993e1f947cdeae19f01f5176d18c32059c4b2395c8c0cf7a15665006d8cfddaf17205070b39695604d57879d292ea30a51994802d21c41e8979cf10be4df5f0d899fac09707ce993f7ee09b3284c2d12d329e74111a305ea1c8a82be2ef91616c970737de98a11eb522503ccb57d8c6541a24d7f71de33e6329c21abcc95cb2416491857611f7b50d8462738f717e955b66b1d3295c178ce9aa3a249cba30ea6c4659e8409756a753522a6f1acba8d5c63d72b14577f9b175d0052d8f7d44c82f8755e46d14828808ed38d7f1aef3f9acfb4d1c7ff71c4f4dbc181d9642d7dada25bc9b8f532b3c5a96acbbc3f0c63539c76177d61b31deea3b210a77e464be305a1da60b98fe62ff11b34b86f556dcdd5596469baf4ccc2f3d3c25ab3836469c899ad80f137e196a61f4bb8da122963dbeae42c26a47c6ef037e284a414afbe7510989546fb427e7ad5759184d00d61a57f0d38af8df624dfae109d92594332448177d95638a18ecd8c1f24ebadfc608be706aa56a0745982bd21964b8cc1fc4e43fb5bcc8a88599fe14acd95798f08f776703582aaee1bf21f21ad3533db56c8b1f6975d3489f2405d5c79ebfa3ea6508587e294bd317d243c524eb096e221646cf4260ebe47791d9acf794159392be8ace1670676164a521b4', 'transcript_type': 'EVM'}\n", + "Time gen prf: 34.71966505050659 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", + "verifier_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, comb_data_path, witness_path, prover_compiled_model_path, settings_path, proof_path, pk_path)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "num_inputs: 1\n", + "prf instances: [[[10537101196673941533, 17227541574925932677, 11187715152301828262, 1869164017182098189], [12436184717236109307, 3962172157175319849, 7381016538464732718, 1011752739694698287], [12362648763242643187, 13940026059969050459, 6027715406760125980, 2781413989188023337]]]\n", + "proof boolean: 1.0\n", + "proof result 1 : 12.75\n", + "verified\n" + ] + } + ], + "source": [ + "# Verifier verifies\n", + "verifier_verify(proof_path, settings_path, vk_path)" + ] + }, + { + "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 +}