diff --git a/eth/demo.ipynb b/eth/demo.ipynb index e3a9019..784d6e0 100644 --- a/eth/demo.ipynb +++ b/eth/demo.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "7ee9405b", + "id": "de3ba1fc", "metadata": {}, "source": [ "## zk-ml: truly private machine learning on blockchain\n", @@ -77,8 +77,8 @@ }, { "cell_type": "code", - "execution_count": 52, - "id": "b8a044b5", + "execution_count": 1, + "id": "1b038a3d", "metadata": {}, "outputs": [], "source": [ @@ -87,28 +87,47 @@ }, { "cell_type": "code", - "execution_count": 53, - "id": "fa6afd0d", + "execution_count": 2, + "id": "5e43b2c5", "metadata": {}, "outputs": [], "source": [ - "alias prepare source ~/.nvm/nvm.sh >/dev/null && nvm use 14.0.0 >/dev/null && yarn >/dev/null && yarn prepare-demo-nocompile > /dev/null" + "alias prepare source ~/.nvm/nvm.sh >/dev/null && nvm use 14.0.0 >/dev/null && yarn >/dev/null && ./zkml add_bounty --amount 1 " ] }, { "cell_type": "code", - "execution_count": 38, - "id": "029549d5", + "execution_count": 3, + "id": "691a2bd9", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hashed inputs: \n", + "\u001b[33m14797455496207951391356508759149962584765968173479481191220882411966396840571n\u001b[39m\n", + "Your Public Key: \n", + "[\n", + " \u001b[33m1201985518978813069048614242908853769836641152766343625459923948687381884866n\u001b[39m,\n", + " \u001b[33m19496081506364456486564631647699620263934626467785977126387698776414945878171n\u001b[39m\n", + "]\n", + "Your Private Key: \n", + "\u001b[33m3078011588103099000651955808511951698555472462434891497141660669970337258902n\u001b[39m\n", + "IPFS available at https://ipfs.io/ipfs/QmWLRJVL5uViT7h64bdeUM3GKMWP9DSWRggGC8igDuQdHR\n", + "Current Balance\n", + "109.616883399991896552\n" + ] + } + ], "source": [ "prepare" ] }, { "cell_type": "code", - "execution_count": 71, - "id": "7bedf55c", + "execution_count": 4, + "id": "0b973c0f", "metadata": {}, "outputs": [ { @@ -128,25 +147,25 @@ }, { "cell_type": "code", - "execution_count": 72, - "id": "6d6ec507", + "execution_count": 5, + "id": "85848687", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Available bounties on dataset: 14797455496207951391356508759149962584765968173479481191220882411966396840571\r\n", - "[\r\n", - " {\r\n", - " PubKey1: \u001b[32m'8385930133524036559273104048419821016491875134467519785353152799140128167921'\u001b[39m,\r\n", - " PubKey2: \u001b[32m'17155255312018438018746349179262607517493307326242830912102091150670145263900'\u001b[39m,\r\n", - " MSEcap: \u001b[32m'12888'\u001b[39m,\r\n", - " Bounty: \u001b[32m'49.0'\u001b[39m,\r\n", - " Issuer: \u001b[32m'0x1CBd3b2770909D4e10f157cABC84C7264073C9Ec'\u001b[39m,\r\n", - " IPFS: \u001b[32m'QmWLRJVL5uViT7h64bdeUM3GKMWP9DSWRggGC8igDuQdHR'\u001b[39m\r\n", - " }\r\n", - "]\r\n" + "Available bounties on dataset: 14797455496207951391356508759149962584765968173479481191220882411966396840571\n", + "[\n", + " {\n", + " PubKey1: \u001b[32m'1201985518978813069048614242908853769836641152766343625459923948687381884866'\u001b[39m,\n", + " PubKey2: \u001b[32m'19496081506364456486564631647699620263934626467785977126387698776414945878171'\u001b[39m,\n", + " MSEcap: \u001b[32m'12888'\u001b[39m,\n", + " Bounty: \u001b[32m'1.0'\u001b[39m,\n", + " Issuer: \u001b[32m'0xd3162F2B88d05C882a1B26031E144753337ACDBF'\u001b[39m,\n", + " IPFS: \u001b[32m'QmWLRJVL5uViT7h64bdeUM3GKMWP9DSWRggGC8igDuQdHR'\u001b[39m\n", + " }\n", + "]\n" ] } ], @@ -156,20 +175,20 @@ }, { "cell_type": "markdown", - "id": "22f8c4cf", + "id": "dc6e6b4e", "metadata": {}, "source": [ "Command:\n", "\n", "```\n", - "zkml download_dataset --hash '14797455496207951391356508759149962584765968173479481191220882411966396840571' --publickey ./keys/out_public.json --walletprivatekey ./keys/.private_key --mse 18406 --path ./ipfs_dataset\n", + "zkml download_dataset --hash '14797455496207951391356508759149962584765968173479481191220882411966396840571' --publickey ./keys/out_public.json --mse 12888 --path ./ipfs_dataset\n", "```" ] }, { "cell_type": "code", - "execution_count": 73, - "id": "8cf3f99b", + "execution_count": 7, + "id": "88fb5cb3", "metadata": {}, "outputs": [ { @@ -181,13 +200,13 @@ } ], "source": [ - "zkml download_dataset --hash '14797455496207951391356508759149962584765968173479481191220882411966396840571' --publickey ./keys/out_public.json --walletprivatekey ./keys/.private_key --mse 12888 --path ./ipfs_dataset" + "zkml download_dataset --hash '14797455496207951391356508759149962584765968173479481191220882411966396840571' --publickey ./keys/out_public.json --mse 12888 --path ./ipfs_dataset" ] }, { "cell_type": "code", - "execution_count": 74, - "id": "a892e539", + "execution_count": 8, + "id": "c26f44d4", "metadata": {}, "outputs": [ { @@ -204,22 +223,21 @@ }, { "cell_type": "code", - "execution_count": 75, - "id": "40cd5e64", + "execution_count": 9, + "id": "49186dc2", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "from sklearn.metrics import mean_squared_error\n", - "\n", "from sklearn.linear_model import LinearRegression" ] }, { "cell_type": "code", - "execution_count": 76, - "id": "bc87a58a", + "execution_count": 10, + "id": "c05394f1", "metadata": {}, "outputs": [], "source": [ @@ -229,8 +247,8 @@ }, { "cell_type": "code", - "execution_count": 77, - "id": "cd040513", + "execution_count": 11, + "id": "ac3e7fa2", "metadata": {}, "outputs": [ { @@ -239,7 +257,7 @@ "((20, 1), (20, 4))" ] }, - "execution_count": 77, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -250,8 +268,8 @@ }, { "cell_type": "code", - "execution_count": 78, - "id": "9a5beb63", + "execution_count": 14, + "id": "db1370a1", "metadata": { "scrolled": true }, @@ -275,22 +293,34 @@ "pred = lr.predict(X)\n", "\n", "# Evaluating Model's Performance\n", - "print('Mean Squared Error:', mean_squared_error(y_test, pred))\n", + "print('Mean Squared Error:', mean_squared_error(Y, pred))\n", "\n", - "mse = mean_squared_error(y_test, pred)" + "mse = mean_squared_error(Y, pred)" ] }, { "cell_type": "code", - "execution_count": 79, - "id": "f9087416", + "execution_count": 16, + "id": "c557151e", "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'numpy.ndarray' object has no attribute 'values'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mW\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcoef_\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreshape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mintercept_\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreshape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mX\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mYt_expected\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mY\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreshape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mAttributeError\u001b[0m: 'numpy.ndarray' object has no attribute 'values'" + ] + } + ], "source": [ "W = lr.coef_.reshape(-1, 1)\n", "b = lr.intercept_.reshape(-1, 1)\n", - "X = X_test.values[:]\n", - "Yt_expected = y_test.values[:].reshape(-1, 1)\n", + "X = X.values[:]\n", + "Yt_expected = Y.values[:].reshape(-1, 1)\n", "\n", "np.save('model/W.npy',W)\n", "np.save('model/b.npy',b)\n", @@ -300,18 +330,10 @@ }, { "cell_type": "code", - "execution_count": 80, - "id": "cd4e6046", + "execution_count": null, + "id": "051e409a", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0.07941453957968247\n" - ] - } - ], + "outputs": [], "source": [ "shuffle = lambda x: np.random.shuffle(x)\n", "shuffle(W)\n", @@ -324,8 +346,8 @@ }, { "cell_type": "code", - "execution_count": 81, - "id": "64d5121d", + "execution_count": null, + "id": "c701563a", "metadata": {}, "outputs": [], "source": [ @@ -367,7 +389,7 @@ }, { "cell_type": "markdown", - "id": "6db80218", + "id": "eb10a39a", "metadata": {}, "source": [ "Command:\n", @@ -379,39 +401,17 @@ }, { "cell_type": "code", - "execution_count": 82, - "id": "75843d81", + "execution_count": null, + "id": "02d90771", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Mean Squared Error actual: 0.07941453957968254\n", - "... quantized 13014\n", - "Mean Squared Error simulated: 0.07939327351522920684\n", - "... quantized 13011\n", - "Circuit Outputs:\n", - "13011\n", - "Proof took 17.02 s\n", - "ERROR: Invalid proof\n", - "\u001b[31mAn unexpected error occurred:\u001b[39m\n", - "\n", - "Error: Could not verify the proof\n", - " at SimpleTaskDefinition.action (/Users/liaopeiyuan/Documents/GitHub/zkml-core/eth/hardhat.config.js:281:26)\n", - " at Environment._runTaskDefinition (/Users/liaopeiyuan/Documents/GitHub/zkml-core/eth/node_modules/\u001b[4mhardhat\u001b[24m/src/internal/core/runtime-environment.ts:217:14)\n", - " at Environment.run (/Users/liaopeiyuan/Documents/GitHub/zkml-core/eth/node_modules/\u001b[4mhardhat\u001b[24m/src/internal/core/runtime-environment.ts:129:14)\n", - " at main (/Users/liaopeiyuan/Documents/GitHub/zkml-core/eth/node_modules/\u001b[4mhardhat\u001b[24m/src/internal/cli/cli.ts:197:5)\n" - ] - } - ], + "outputs": [], "source": [ "zkml claim_bounty --payment 0x2546BcD3c84621e976D8185a91A922aE77ECEc30 --model ./model_shuffled --dataset ./dataset --publickey ./keys/out_public.json --settings ./settings.json" ] }, { "cell_type": "markdown", - "id": "e427688c", + "id": "724d3438", "metadata": {}, "source": [ "Command:\n", @@ -423,75 +423,30 @@ }, { "cell_type": "code", - "execution_count": 83, - "id": "29caa30b", + "execution_count": null, + "id": "f1477fd6", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Mean Squared Error actual: 0.0786589987376446\n", - "... quantized 12891\n", - "Mean Squared Error simulated: 0.07864249526948667579\n", - "... quantized 12888\n", - "Circuit Outputs:\n", - "12888\n", - "Proof took 17.131 s\n", - "INFO: OK!\n", - "Paying 0x2546BcD3c84621e976D8185a91A922aE77ECEc30\n", - "With balance\n", - "10850.6\n", - "Your Public Key: \n", - "[\n", - " \u001b[33m1700643759997457569245863490312877944508569018329107232774239121212875587628n\u001b[39m,\n", - " \u001b[33m12432032059012451124939976221853806268790884588923275757468717217243035579610n\u001b[39m\n", - "]\n", - "Your Private Key: \n", - "\u001b[33m16643980665868843823629143933455494516978640287615526294342242121812095812996n\u001b[39m\n", - "Current Balance\n", - "10899.6\n" - ] - } - ], + "outputs": [], "source": [ "zkml claim_bounty --payment 0x2546BcD3c84621e976D8185a91A922aE77ECEc30 --model ./model --dataset ./dataset --publickey ./keys/out_public.json --settings ./settings.json" ] }, { "cell_type": "code", - "execution_count": 84, - "id": "7ffdc480", + "execution_count": null, + "id": "e425fa00", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Available bounties on dataset: 14797455496207951391356508759149962584765968173479481191220882411966396840571\n", - "[]\n" - ] - } - ], + "outputs": [], "source": [ "zkml list_bounties --hash 14797455496207951391356508759149962584765968173479481191220882411966396840571" ] }, { "cell_type": "code", - "execution_count": 85, - "id": "7dea9bb9", + "execution_count": null, + "id": "80df2810", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Available datasets:\r\n", - "[]\r\n" - ] - } - ], + "outputs": [], "source": [ "zkml list_datasets" ] diff --git a/eth/keys/out_private.json b/eth/keys/out_private.json index 6000084..edc7470 100644 --- a/eth/keys/out_private.json +++ b/eth/keys/out_private.json @@ -1 +1 @@ -"12939888982122786588297871950513013245594730055341970524144179473926819003250" \ No newline at end of file +"3078011588103099000651955808511951698555472462434891497141660669970337258902" \ No newline at end of file diff --git a/eth/keys/out_public.json b/eth/keys/out_public.json index 7f1ef87..e82461d 100644 --- a/eth/keys/out_public.json +++ b/eth/keys/out_public.json @@ -1,4 +1,4 @@ [ - "21424417678069587450946737704454924741331627853168179624159728694316851816330", - "612723402524730177771742584827137671648365705553623030367114986155085572752" + "1201985518978813069048614242908853769836641152766343625459923948687381884866", + "19496081506364456486564631647699620263934626467785977126387698776414945878171" ] \ No newline at end of file diff --git a/eth/model_shuffled/W.npy b/eth/model_shuffled/W.npy index bbf4bfc..a4415af 100644 Binary files a/eth/model_shuffled/W.npy and b/eth/model_shuffled/W.npy differ diff --git a/eth/package.json b/eth/package.json index 236788e..2dcf72a 100644 --- a/eth/package.json +++ b/eth/package.json @@ -37,7 +37,6 @@ "compile": "npx hardhat compile", "deploy-localhost": "npx hardhat run --network localhost scripts/deploy.js", "deploy-xdai": "npx hardhat run --network xdai scripts/deploy.js", - "prepare-demo": "npx hardhat compile && npx hardhat run --network localhost scripts/deploy.js && npx hardhat add_bounty --amount 5", - "prepare-demo-nocompile": "npx hardhat add_bounty --amount 5" + "prepare-demo": "npx hardhat compile && npx hardhat run --network localhost scripts/deploy.js && npx hardhat add_bounty --amount 1" } } diff --git a/eth/zkml b/eth/zkml index d90a6e8..67b5827 100755 --- a/eth/zkml +++ b/eth/zkml @@ -1,2 +1,2 @@ #!/bin/zsh -npx hardhat --network localhost "$@" +npx hardhat --network xdai "$@"