From d43ea9ab950fb835a99f12ba75c3bc7adc8bfc18 Mon Sep 17 00:00:00 2001 From: Soumya Ghosh Dastidar Date: Thu, 19 Dec 2024 16:10:59 +0530 Subject: [PATCH 1/5] feat: update e2e Signed-off-by: Soumya Ghosh Dastidar --- .../nillion-interactor/E2E_Nillion_Test.ipynb | 588 ++++++++---------- .../binaries/double.nada.bin | Bin 614 -> 620 bytes .../binaries/double.nada.json | 2 +- .../binaries/muscle-perform.nada.bin | Bin 3891 -> 3280 bytes .../binaries/muscle-perform.nada.json | 2 +- .../binaries/thrombosis.nada.bin | Bin 3797 -> 3194 bytes .../binaries/thrombosis.nada.json | 2 +- services/nillion-interactor/compile.sh | 4 +- .../programs/muscle-perform.py | 2 +- .../nillion-interactor/programs/thrombosis.py | 2 +- services/nillion-interactor/requirements.txt | 5 +- 11 files changed, 270 insertions(+), 337 deletions(-) diff --git a/services/nillion-interactor/E2E_Nillion_Test.ipynb b/services/nillion-interactor/E2E_Nillion_Test.ipynb index 9e147ef..d01471f 100644 --- a/services/nillion-interactor/E2E_Nillion_Test.ipynb +++ b/services/nillion-interactor/E2E_Nillion_Test.ipynb @@ -23,7 +23,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T19:26:51.222994Z", @@ -40,65 +40,66 @@ "name": "stdout", "output_type": "stream", "text": [ - "Requirement already satisfied: nada-dsl==0.6.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (0.6.0)\n", - "Requirement already satisfied: asttokens~=2.4 in /Users/aisha/Library/Python/3.12/lib/python/site-packages (from nada-dsl==0.6.0) (2.4.1)\n", - "Requirement already satisfied: richreports~=0.2 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from nada-dsl==0.6.0) (0.2.0)\n", - "Requirement already satisfied: parsial~=0.1 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from nada-dsl==0.6.0) (0.1.0)\n", - "Requirement already satisfied: sortedcontainers~=2.4 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from nada-dsl==0.6.0) (2.4.0)\n", - "Requirement already satisfied: six>=1.12.0 in /Users/aisha/Library/Python/3.12/lib/python/site-packages (from asttokens~=2.4->nada-dsl==0.6.0) (1.16.0)\n", - "\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip3 install --upgrade pip\u001b[0m\n", + "Requirement already satisfied: nada-dsl==0.7.2 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (0.7.2)\n", + "Requirement already satisfied: asttokens~=2.4 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nada-dsl==0.7.2) (2.4.1)\n", + "Requirement already satisfied: richreports~=0.2 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nada-dsl==0.7.2) (0.2.0)\n", + "Requirement already satisfied: parsial~=0.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nada-dsl==0.7.2) (0.1.0)\n", + "Requirement already satisfied: sortedcontainers~=2.4 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nada-dsl==0.7.2) (2.4.0)\n", + "Requirement already satisfied: typing_extensions~=4.12.2 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nada-dsl==0.7.2) (4.12.2)\n", + "Requirement already satisfied: six>=1.12.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from asttokens~=2.4->nada-dsl==0.7.2) (1.17.0)\n", "Note: you may need to restart the kernel to use updated packages.\n", - "Requirement already satisfied: py-nillion-client==0.6.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (0.6.0)\n", - "Requirement already satisfied: protobuf<5.0.dev0,>=4.21.6 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from py-nillion-client==0.6.0) (4.25.4)\n", - "\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip3 install --upgrade pip\u001b[0m\n", + "Requirement already satisfied: python-dotenv==1.0.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (1.0.0)\n", "Note: you may need to restart the kernel to use updated packages.\n", - "Requirement already satisfied: nillion-python-helpers==0.2.3 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (0.2.3)\n", - "Requirement already satisfied: cosmpy<0.10.0,>=0.9.2 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from nillion-python-helpers==0.2.3) (0.9.2)\n", - "Requirement already satisfied: pytest-asyncio<0.24.0,>=0.23.7 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from nillion-python-helpers==0.2.3) (0.23.8)\n", - "Requirement already satisfied: python-dotenv==1.0.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from nillion-python-helpers==0.2.3) (1.0.0)\n", - "Requirement already satisfied: bech32 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (1.2.0)\n", - "Requirement already satisfied: ecdsa in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (0.19.0)\n", - "Requirement already satisfied: googleapis-common-protos in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (1.65.0)\n", - "Requirement already satisfied: grpcio in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (1.66.1)\n", - "Requirement already satisfied: jsonschema<5,>=3.2.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (4.23.0)\n", - "Requirement already satisfied: protobuf<5.0dev,>=4.21.6 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (4.25.4)\n", - "Requirement already satisfied: pycryptodome<4.0.0,>=3.18.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (3.20.0)\n", - "Requirement already satisfied: python-dateutil in /Users/aisha/Library/Python/3.12/lib/python/site-packages (from cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (2.9.0.post0)\n", - "Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (2.32.3)\n", - "Requirement already satisfied: pytest<9,>=7.0.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from pytest-asyncio<0.24.0,>=0.23.7->nillion-python-helpers==0.2.3) (8.3.2)\n", - "Requirement already satisfied: attrs>=22.2.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (24.2.0)\n", - "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (2023.12.1)\n", - "Requirement already satisfied: referencing>=0.28.4 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (0.35.1)\n", - "Requirement already satisfied: rpds-py>=0.7.1 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (0.20.0)\n", - "Requirement already satisfied: iniconfig in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from pytest<9,>=7.0.0->pytest-asyncio<0.24.0,>=0.23.7->nillion-python-helpers==0.2.3) (2.0.0)\n", - "Requirement already satisfied: packaging in /Users/aisha/Library/Python/3.12/lib/python/site-packages (from pytest<9,>=7.0.0->pytest-asyncio<0.24.0,>=0.23.7->nillion-python-helpers==0.2.3) (24.1)\n", - "Requirement already satisfied: pluggy<2,>=1.5 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from pytest<9,>=7.0.0->pytest-asyncio<0.24.0,>=0.23.7->nillion-python-helpers==0.2.3) (1.5.0)\n", - "Requirement already satisfied: six>=1.9.0 in /Users/aisha/Library/Python/3.12/lib/python/site-packages (from ecdsa->cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (1.16.0)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from requests->cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (3.3.2)\n", - "Requirement already satisfied: idna<4,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from requests->cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (3.8)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from requests->cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (2.2.2)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from requests->cosmpy<0.10.0,>=0.9.2->nillion-python-helpers==0.2.3) (2024.8.30)\n", - "\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip3 install --upgrade pip\u001b[0m\n", + "Requirement already satisfied: nillion_client==0.1.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (0.1.1)\n", + "Requirement already satisfied: cosmpy==0.9.2 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion_client==0.1.1) (0.9.2)\n", + "Requirement already satisfied: secp256k1==0.14.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion_client==0.1.1) (0.14.0)\n", + "Requirement already satisfied: base58==2.1.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion_client==0.1.1) (2.1.1)\n", + "Requirement already satisfied: tenacity==9.0.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion_client==0.1.1) (9.0.0)\n", + "Requirement already satisfied: nillion-client-core==0.1.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion_client==0.1.1) (0.1.1)\n", + "Requirement already satisfied: nillion-client-proto==0.1.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion_client==0.1.1) (0.1.1)\n", + "Requirement already satisfied: pyyaml==6.0.2 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion_client==0.1.1) (6.0.2)\n", + "Requirement already satisfied: bech32 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (1.2.0)\n", + "Requirement already satisfied: ecdsa in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (0.19.0)\n", + "Requirement already satisfied: googleapis-common-protos in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (1.66.0)\n", + "Requirement already satisfied: grpcio in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (1.68.1)\n", + "Requirement already satisfied: jsonschema<5,>=3.2.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (4.23.0)\n", + "Requirement already satisfied: protobuf<5.0dev,>=4.21.6 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (4.25.5)\n", + "Requirement already satisfied: pycryptodome<4.0.0,>=3.18.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (3.21.0)\n", + "Requirement already satisfied: python-dateutil in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (2.9.0.post0)\n", + "Requirement already satisfied: requests in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (2.32.3)\n", + "Requirement already satisfied: grpcio-tools==1.62.3 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion-client-proto==0.1.1->nillion_client==0.1.1) (1.62.3)\n", + "Requirement already satisfied: betterproto==2.0.0b7 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion-client-proto==0.1.1->nillion_client==0.1.1) (2.0.0b7)\n", + "Requirement already satisfied: cffi>=1.3.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from secp256k1==0.14.0->nillion_client==0.1.1) (1.17.1)\n", + "Requirement already satisfied: grpclib<0.5.0,>=0.4.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (0.4.7)\n", + "Requirement already satisfied: typing-extensions<5.0.0,>=4.7.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (4.12.2)\n", + "Requirement already satisfied: setuptools in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from grpcio-tools==1.62.3->nillion-client-proto==0.1.1->nillion_client==0.1.1) (75.6.0)\n", + "Requirement already satisfied: pycparser in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cffi>=1.3.0->secp256k1==0.14.0->nillion_client==0.1.1) (2.22)\n", + "Requirement already satisfied: attrs>=22.2.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy==0.9.2->nillion_client==0.1.1) (24.3.0)\n", + "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy==0.9.2->nillion_client==0.1.1) (2024.10.1)\n", + "Requirement already satisfied: referencing>=0.28.4 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy==0.9.2->nillion_client==0.1.1) (0.35.1)\n", + "Requirement already satisfied: rpds-py>=0.7.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy==0.9.2->nillion_client==0.1.1) (0.22.3)\n", + "Requirement already satisfied: six>=1.5 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from python-dateutil->cosmpy==0.9.2->nillion_client==0.1.1) (1.17.0)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from requests->cosmpy==0.9.2->nillion_client==0.1.1) (3.4.0)\n", + "Requirement already satisfied: idna<4,>=2.5 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from requests->cosmpy==0.9.2->nillion_client==0.1.1) (3.10)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from requests->cosmpy==0.9.2->nillion_client==0.1.1) (2.2.3)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from requests->cosmpy==0.9.2->nillion_client==0.1.1) (2024.12.14)\n", + "Requirement already satisfied: h2<5,>=3.1.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from grpclib<0.5.0,>=0.4.1->betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (4.1.0)\n", + "Requirement already satisfied: multidict in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from grpclib<0.5.0,>=0.4.1->betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (6.1.0)\n", + "Requirement already satisfied: hyperframe<7,>=6.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from h2<5,>=3.1.0->grpclib<0.5.0,>=0.4.1->betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (6.0.1)\n", + "Requirement already satisfied: hpack<5,>=4.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from h2<5,>=3.1.0->grpclib<0.5.0,>=0.4.1->betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (4.0.0)\n", "Note: you may need to restart the kernel to use updated packages.\n", - "Requirement already satisfied: python-dotenv==1.0.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (1.0.0)\n", - "\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip3 install --upgrade pip\u001b[0m\n", + "Requirement already satisfied: cryptography==44.0.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (44.0.0)\n", + "Requirement already satisfied: cffi>=1.12 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cryptography==44.0.0) (1.17.1)\n", + "Requirement already satisfied: pycparser in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cffi>=1.12->cryptography==44.0.0) (2.22)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ - "%pip install nada-dsl==0.6.0\n", - "%pip install py-nillion-client==0.6.0\n", - "%pip install nillion-python-helpers==0.2.3\n", - "%pip install python-dotenv==1.0.0\n" + "%pip install nada-dsl==0.7.2\n", + "%pip install python-dotenv==1.0.0\n", + "%pip install nillion_client==0.1.1\n", + "%pip install cryptography==44.0.0" ] }, { @@ -110,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:05.762189Z", @@ -120,13 +121,26 @@ }, "outputs": [], "source": [ - "import py_nillion_client as nillion\n", - "from py_nillion_client import NodeKey, UserKey\n", + "import argparse\n", + "import asyncio\n", + "import os\n", + "\n", + "from nillion_client import (\n", + " InputPartyBinding,\n", + " Network,\n", + " NilChainPayer,\n", + " NilChainPrivateKey,\n", + " OutputPartyBinding,\n", + " SecretInteger,\n", + " UserId,\n", + " Permissions,\n", + " VmClient,\n", + " PrivateKey,\n", + ")\n", "from dotenv import load_dotenv\n", - "from nillion_python_helpers import get_quote_and_pay, create_nillion_client, create_payments_config\n", - "from cosmpy.aerial.client import LedgerClient\n", - "from cosmpy.aerial.wallet import LocalWallet\n", - "from cosmpy.crypto.keypairs import PrivateKey" + "from nillion_client.ids import UUID\n", + "from nillion_client.payer import DummyPayer\n", + "import hashlib" ] }, { @@ -140,7 +154,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:08.870617Z", @@ -157,14 +171,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "Loading environment variables from /Users/aisha/.config/nillion/nillion-devnet.env\n", + "Loading environment variables from /home/hello/.config/nillion/nillion-devnet.env\n", "NILLION_CLUSTER_ID: 9e68173f-9c23-4acc-ba81-4f079b639964\n", - "NILLION_BOOTNODE_MULTIADDRESS: /ip4/127.0.0.1/tcp/37939/p2p/12D3KooWMvw1hEqm7EWSDEyqTb6pNetUVkepahKY6hixuAuMZfJS\n", - "NILLION_BOOTNODE_WEBSOCKET: /ip4/127.0.0.1/tcp/54936/ws/p2p/12D3KooWMvw1hEqm7EWSDEyqTb6pNetUVkepahKY6hixuAuMZfJS\n", "NILLION_NILCHAIN_CHAIN_ID: nillion-chain-devnet\n", "NILLION_NILCHAIN_JSON_RPC: http://127.0.0.1:48102\n", "NILLION_NILCHAIN_REST_API: http://localhost:26650\n", - "NILLION_NILCHAIN_GRPC: localhost:26649\n", + "NILLION_NILCHAIN_GRPC: http://localhost:26649\n", + "NILLION_GRPC_ENDPOINT: http://127.0.0.1:37939\n", "NILLION_NILCHAIN_PRIVATE_KEY_0: 9a975f567428d054f2bf3092812e6c42f901ce07d9711bc77ee2cd81101f42c5\n", "NILLION_NILCHAIN_PRIVATE_KEY_1: 1e491133b9408b39572a29f91644873decea554224b20e2b0b923aeb860a1c18\n", "NILLION_NILCHAIN_PRIVATE_KEY_2: 980488572f235316cdb330191f8bafe4e635efbe88b3a40f5bee9bd21047c059\n", @@ -202,7 +215,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:12.833625Z", @@ -216,8 +229,18 @@ "text": [ "Cluster ID: 9e68173f-9c23-4acc-ba81-4f079b639964\n", "Chain ID: nillion-chain-devnet\n", - "GRPC Endpoint: localhost:26649\n" + "GRPC Endpoint: http://localhost:26649\n" ] + }, + { + "data": { + "text/plain": [ + "Network(chain_id='nillion-chain-devnet', chain_grpc_endpoint='http://localhost:26649', nilvm_grpc_endpoint='http://127.0.0.1:37939')" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -227,30 +250,10 @@ "\n", "print(f\"Cluster ID: {cluster_id}\")\n", "print(f\"Chain ID: {chain_id}\")\n", - "print(f\"GRPC Endpoint: {grpc_endpoint}\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Each actor will need its own node key so we define a utility function here." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "ExecuteTime": { - "end_time": "2024-08-09T23:28:16.326786Z", - "start_time": "2024-08-09T23:28:16.320243Z" - } - }, - "outputs": [], - "source": [ - "import uuid\n", - "def gen_node_key():\n", - " return NodeKey.from_seed(uuid.uuid4().hex)" + "print(f\"GRPC Endpoint: {grpc_endpoint}\")\n", + "\n", + "network = Network.from_config(\"devnet\")\n", + "network" ] }, { @@ -262,7 +265,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:19.828183Z", @@ -272,9 +275,9 @@ "outputs": [], "source": [ "monadic_seed = \"monadic_seed\"\n", - "monadic_userkey = UserKey.from_seed(monadic_seed)\n", - "monadic_client = create_nillion_client(monadic_userkey, gen_node_key())\n", - "monadic_party_id = monadic_client.party_id\n", + "monadic_userkey = PrivateKey(hashlib.sha256(monadic_seed.encode()).digest())\n", + "monadic_payer = DummyPayer()\n", + "monadic_client = await VmClient.create(monadic_userkey, network, monadic_payer)\n", "monadic_user_id = monadic_client.user_id" ] }, @@ -287,7 +290,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:22.512975Z", @@ -297,9 +300,9 @@ "outputs": [], "source": [ "snipper_seed = \"snipper_seed\"\n", - "snipper_userkey = UserKey.from_seed(snipper_seed)\n", - "snipper_client = create_nillion_client(snipper_userkey, gen_node_key())\n", - "snipper_party_id = snipper_client.party_id\n", + "snipper_userkey = PrivateKey(hashlib.sha256(snipper_seed.encode()).digest())\n", + "snipper_payer = DummyPayer()\n", + "snipper_client = await VmClient.create(snipper_userkey, network, snipper_payer)\n", "snipper_user_id = snipper_client.user_id" ] }, @@ -312,7 +315,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:28.760101Z", @@ -322,9 +325,9 @@ "outputs": [], "source": [ "patient_seed = \"patient_seed\"\n", - "patient_userkey = UserKey.from_seed(patient_seed)\n", - "patient_client = create_nillion_client(patient_userkey, gen_node_key())\n", - "patient_party_id = patient_client.party_id\n", + "patient_userkey = PrivateKey(hashlib.sha256(patient_seed.encode()).digest())\n", + "patient_payer = DummyPayer()\n", + "patient_client = await VmClient.create(patient_userkey, network, patient_payer)\n", "patient_user_id = patient_client.user_id" ] }, @@ -337,7 +340,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:31.282228Z", @@ -347,47 +350,77 @@ }, "outputs": [], "source": [ - "payments_config = create_payments_config(chain_id, grpc_endpoint)\n", - "payments_client = LedgerClient(payments_config)\n", - "payments_wallet = LocalWallet(\n", - " PrivateKey(bytes.fromhex(os.getenv(\"NILLION_NILCHAIN_PRIVATE_KEY_0\"))),\n", - " prefix=\"nillion\",\n", - ")" + "nilchain_key: str = os.getenv(\"NILLION_NILCHAIN_PRIVATE_KEY_0\") # type: ignore\n", + "payer = NilChainPayer(\n", + " network,\n", + " wallet_private_key=NilChainPrivateKey(bytes.fromhex(nilchain_key)),\n", + " gas_limit=10000000,\n", + ")\n", + "\n", + "payer_seed=\"payer_seed\"\n", + "\n", + "# We will identify ourselves with the pre-configured private key\n", + "signing_key = PrivateKey(hashlib.sha256(payer_seed.encode()).digest())\n", + "payer_client= await VmClient.create(signing_key, network, payer)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Configuration for the program to use. Change the contents of the below cell to use another program. " + "Add funds to clients" ] }, { "cell_type": "code", - "execution_count": 10, - "metadata": { - "ExecuteTime": { - "end_time": "2024-08-09T23:28:33.143041Z", - "start_time": "2024-08-09T23:28:33.134076Z" - }, - "id": "rEr0_JkMuVci" - }, + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "💰 Adding some funds to the executor client balance: 100000 uNIL\n" + ] + } + ], + "source": [ + "funds_amount = 100000\n", + "print(f\"💰 Adding some funds to the executor client balance: {funds_amount} uNIL\")\n", + "await payer_client.add_funds(funds_amount)\n", + "await payer_client.add_funds(funds_amount, target_user=patient_user_id)\n", + "await payer_client.add_funds(funds_amount, target_user=monadic_user_id)\n", + "await payer_client.add_funds(funds_amount, target_user=snipper_user_id)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Configuration for the program to use. Change the contents of the below cell to use another program." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, "outputs": [], "source": [ "program_name = \"double\"\n", - "program_mir_path = f\"binaries/double.nada.bin\"" + "program_mir_path = f\"binaries/double.nada.bin\"\n", + "program = open(program_mir_path, \"rb\").read()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "As a baseline, let's ensure that the user can store the program and run it on their own secret. " + "As a baseline, let's ensure that the user can store the program and run it on their own secret." ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:41.524938Z", @@ -400,21 +433,19 @@ "output_type": "stream", "text": [ "The patient is storing the program on the network\n", - "Getting quote for operation...\n", - "Quote cost is 2 unil\n", - "Submitting payment receipt 2 unil, tx hash D1584C1F65DAFA2701F73117E739E136C32A609AF6EF7FB43102E95337A98499\n", - "Action ID: 229XQCZoSQk9zDx4ixKXg8wAqCy7HnmUjcTuMe7D1bUVhNG7kYNF4xeZYjRsEtJUhKFvXwfM65ixFWDRhptfHCqw/double\n", - "The patient is storing a secret on the network\n", - "Getting quote for operation...\n", - "Quote cost is 482 unil\n", - "Submitting payment receipt 482 unil, tx hash 8070A55743C4A1A3DA557B9D288FD964A6DA58D27E2F2DB973FFF938E8425FE6\n", + "Program ID: 4b367ad186fa672387ca7fb6ea9f75c13cc53a82/double/sha256/35f9b61f28b8e9aafbc987766f6ff549892aafe1d65256aa6feec84b1f5b6bf0\n", + "The patient is storing a secret on the network\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ "The patient is running the program on the secret..\n", - "Getting quote for operation...\n", - "Quote cost is 3 unil\n", - "Submitting payment receipt 3 unil, tx hash 108432FF46244933B87378BBADE5F1F58F5E4CFA478F96B6DA8D8224A7288698\n", - "The computation was sent to the network. compute_id: 9881886b-174a-4ea1-88b2-2f974e739cfd\n", - "✅ Compute complete for compute_id 9881886b-174a-4ea1-88b2-2f974e739cfd\n", - "🖥️ The result is {'my_output': 4}\n" + "The computation was sent to the network. compute_id: 862ecd60-1438-4c23-b11a-01cc03f4d64f\n", + "✅ Compute complete for compute_id 862ecd60-1438-4c23-b11a-01cc03f4d64f\n", + "🖥️ The result is {'my_output': SecretInteger(4)}\n", + "💰 Final client balance: 99028 uNIL\n" ] } ], @@ -425,85 +456,52 @@ "\n", "print(\"The patient is storing the program on the network\")\n", "\n", - "async def store_program():\n", - " receipt_store_program = await get_quote_and_pay(\n", - " patient_client,\n", - " nillion.Operation.store_program(program_mir_path),\n", - " payments_wallet,\n", - " payments_client,\n", - " cluster_id,\n", - " )\n", - "\n", - " # Store the program\n", - " action_id = await patient_client.store_program(\n", - " cluster_id, program_name, program_mir_path, receipt_store_program\n", - " )\n", - " return action_id\n", + "program_id = await patient_client.store_program(\n", + " program_name, program,\n", + ").invoke()\n", "\n", - "action_id = await store_program()\n", - "print(f\"Action ID: {action_id}\")\n", + "print(f\"Program ID: {program_id}\")\n", "\n", "print(\"The patient is storing a secret on the network\")\n", "\n", - "program_id = f\"{patient_user_id}/{program_name}\"\n", - "\n", - "new_secret = nillion.NadaValues(\n", - " {\n", - " \"foo\": nillion.SecretInteger(2),\n", - " }\n", - ")\n", + "values = {\"foo\": SecretInteger(2) }\n", "\n", "# Set permissions for the client to compute on the program\n", - "permissions = nillion.Permissions.default_for_user(patient_user_id)\n", - "permissions.add_compute_permissions({patient_user_id: {program_id}})\n", - "\n", - "# Pay for and store the secret in the network and print the returned store_id\n", - "receipt_store = await get_quote_and_pay(\n", - " patient_client,\n", - " nillion.Operation.store_values(new_secret, ttl_days=5),\n", - " payments_wallet,\n", - " payments_client,\n", - " cluster_id,\n", - ")\n", + "permissions = Permissions.defaults_for_user(patient_user_id).allow_compute(\n", + " patient_user_id, program_id\n", + " )\n", + "\n", "# Store a secret\n", "store_id = await patient_client.store_values(\n", - " cluster_id, new_secret, permissions, receipt_store\n", - ")\n", + " values=values, ttl_days=5, permissions=permissions\n", + ").invoke()\n", + "\n", "\n", "print(\"The patient is running the program on the secret..\")\n", "\n", "party_name = \"Party1\"\n", - "compute_bindings = nillion.ProgramBindings(program_id)\n", - "compute_bindings.add_input_party(party_name, patient_party_id)\n", - "compute_bindings.add_output_party(party_name, patient_party_id)\n", - "computation_time_secrets = nillion.NadaValues({})\n", - "\n", - "# Pay for the compute\n", - "receipt_compute = await get_quote_and_pay(\n", - " patient_client,\n", - " nillion.Operation.compute(program_id, computation_time_secrets),\n", - " payments_wallet,\n", - " payments_client,\n", - " cluster_id,\n", - ")\n", + "\n", + "input_bindings = [InputPartyBinding(party_name, patient_user_id)]\n", + "output_bindings = [OutputPartyBinding(party_name, [patient_user_id])]\n", + "\n", + "computation_time_secrets = {}\n", "\n", "# Compute on the secret\n", "compute_id = await patient_client.compute(\n", - " cluster_id,\n", - " compute_bindings,\n", - " [store_id],\n", - " computation_time_secrets,\n", - " receipt_compute,\n", - ")\n", + " program_id,\n", + " input_bindings,\n", + " output_bindings,\n", + " values=computation_time_secrets,\n", + " value_ids=[store_id]\n", + ").invoke()\n", "\n", "# 8. Return the computation result\n", "print(f\"The computation was sent to the network. compute_id: {compute_id}\")\n", - "while True:\n", - " compute_event = await patient_client.next_compute_event()\n", - " if isinstance(compute_event, nillion.ComputeFinishedEvent):\n", - " print(f\"✅ Compute complete for compute_id {compute_event.uuid}\")\n", - " print(f\"🖥️ The result is {compute_event.result.value}\")\n", - " break" + "result = await patient_client.retrieve_compute_results(compute_id).invoke()\n", + "print(f\"✅ Compute complete for compute_id {compute_id}\")\n", + "print(f\"🖥️ The result is {result}\")\n", + "balance = await patient_client.balance()\n", + "print(f\"💰 Final client balance: {balance.balance} uNIL\")" ] }, { @@ -517,7 +515,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 20, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:49.395066Z", @@ -535,33 +533,16 @@ "name": "stdout", "output_type": "stream", "text": [ - "Getting quote for operation...\n", - "Quote cost is 2 unil\n", - "Submitting payment receipt 2 unil, tx hash 0A2FBDA6C851AB4319E6E3A8B0D4B015E6E95044CD29C1D0DCC75EAEA8429570\n", - "Action ID: 3Uaays4LAuJ7QGbAC94etCHAr1dzt9NBnX4Q3QMY16cpJNYstDNBv6efyrgGeKfBAemaECUCxApThCfLxcmJbAPj/double\n" + "Program ID: ac9f9cea344cdbeaaa76ecca9eea25b21b0a1742/double/sha256/35f9b61f28b8e9aafbc987766f6ff549892aafe1d65256aa6feec84b1f5b6bf0\n" ] } ], "source": [ - "async def store_program():\n", - " receipt_store_program = await get_quote_and_pay(\n", - " monadic_client,\n", - " nillion.Operation.store_program(program_mir_path),\n", - " payments_wallet,\n", - " payments_client,\n", - " cluster_id,\n", - " )\n", - "\n", - " # Store the program\n", - " action_id = await monadic_client.store_program(\n", - " cluster_id, program_name, program_mir_path, receipt_store_program\n", - " )\n", - " return action_id\n", - "\n", - "# Use this in your Jupyter notebook cell\n", - "action_id = await store_program()\n", - "print(f\"Action ID: {action_id}\")\n", - "\n" + "mondaic_program_id = await monadic_client.store_program(\n", + " program_name, program,\n", + ").invoke()\n", + "\n", + "print(f\"Program ID: {mondaic_program_id}\")\n" ] }, { @@ -578,51 +559,33 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 24, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:54.210051Z", "start_time": "2024-08-09T23:28:52.165103Z" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Getting quote for operation...\n", - "Quote cost is 482 unil\n", - "Submitting payment receipt 482 unil, tx hash 61F8428B0BA42AE5B1D62C5588EC1055A556DD14E116ECD5EBD56A838720B5F8\n" - ] - } - ], + "outputs": [], "source": [ - "program_id = f\"{monadic_user_id}/{program_name}\"\n", + "program_id = mondaic_program_id\n", "\n", - "new_secret = nillion.NadaValues(\n", - " {\n", - " \"foo\": nillion.SecretInteger(2),\n", + "values = {\n", + " \"foo\": SecretInteger(2),\n", " }\n", - ")\n", + "\n", "\n", "# Set permissions for the client to compute on the program\n", - "permissions = nillion.Permissions.default_for_user(patient_user_id)\n", - "permissions.add_update_permissions(set([monadic_user_id]))\n", - "permissions.add_compute_permissions({monadic_user_id: {program_id}})\n", - "permissions.add_compute_permissions({snipper_user_id: {program_id}})\n", - "\n", - "# Pay for and store the secret in the network and print the returned store_id\n", - "receipt_store = await get_quote_and_pay(\n", - " patient_client,\n", - " nillion.Operation.store_values(new_secret, ttl_days=5),\n", - " payments_wallet,\n", - " payments_client,\n", - " cluster_id,\n", - ")\n", + "permissions = Permissions.defaults_for_user(patient_user_id)\\\n", + " .allow_update(monadic_user_id)\\\n", + " .allow_compute(monadic_user_id, program_id)\\\n", + " .allow_compute(snipper_user_id,program_id)\n", + "\n", + "\n", "# Store a secret\n", - "store_id = await patient_client.store_values(\n", - " cluster_id, new_secret, permissions, receipt_store\n", - ")" + "new_store_id = await patient_client.store_values(\n", + " values=values, ttl_days=5, permissions=permissions\n", + ").invoke()" ] }, { @@ -636,7 +599,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:59.264419Z", @@ -648,12 +611,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "Getting quote for operation...\n", - "Quote cost is 3 unil\n", - "Submitting payment receipt 3 unil, tx hash B6291177FFAC17961AE56CABFE813944EB3142AA184B1778A41884FA4CA2FC34\n", - "The computation was sent to the network. compute_id: 0c211b76-5f39-44ad-ae64-029a7547a22e\n", - "✅ Compute complete for compute_id 0c211b76-5f39-44ad-ae64-029a7547a22e\n", - "🖥️ The result is {'my_output': 4}\n" + "The computation was sent to the network. compute_id: 6a92aaa6-734f-435d-a71b-5d30e9d61c83\n", + "✅ Compute complete for compute_id 6a92aaa6-734f-435d-a71b-5d30e9d61c83\n", + "🖥️ The result is {'my_output': SecretInteger(4)}\n", + "💰 Final client balance: 99991 uNIL\n" ] } ], @@ -663,38 +624,28 @@ "os.environ['RUST_BACKTRACE'] = 'full'\n", "\n", "party_name = \"Party1\"\n", - "compute_bindings = nillion.ProgramBindings(program_id)\n", - "compute_bindings.add_input_party(party_name, monadic_party_id)\n", - "compute_bindings.add_output_party(party_name, monadic_party_id)\n", - "\n", - "computation_time_secrets = nillion.NadaValues({})\n", - "\n", - "# Pay for the compute\n", - "receipt_compute = await get_quote_and_pay(\n", - " monadic_client,\n", - " nillion.Operation.compute(program_id, computation_time_secrets),\n", - " payments_wallet,\n", - " payments_client,\n", - " cluster_id,\n", - ")\n", + "\n", + "input_bindings = [InputPartyBinding(party_name, monadic_user_id)]\n", + "output_bindings = [OutputPartyBinding(party_name, [monadic_user_id])]\n", + "\n", + "computation_time_secrets = {}\n", "\n", "# Compute on the secret\n", "compute_id = await monadic_client.compute(\n", - " cluster_id,\n", - " compute_bindings,\n", - " [store_id],\n", - " computation_time_secrets,\n", - " receipt_compute,\n", - ")\n", + " program_id,\n", + " input_bindings,\n", + " output_bindings,\n", + " values=computation_time_secrets,\n", + " value_ids=[new_store_id]\n", + ").invoke()\n", "\n", "# 8. Return the computation result\n", "print(f\"The computation was sent to the network. compute_id: {compute_id}\")\n", - "while True:\n", - " compute_event = await monadic_client.next_compute_event()\n", - " if isinstance(compute_event, nillion.ComputeFinishedEvent):\n", - " print(f\"✅ Compute complete for compute_id {compute_event.uuid}\")\n", - " print(f\"🖥️ The result is {compute_event.result.value}\")\n", - " break" + "result = await monadic_client.retrieve_compute_results(compute_id).invoke()\n", + "print(f\"✅ Compute complete for compute_id {compute_id}\")\n", + "print(f\"🖥️ The result is {result}\")\n", + "balance = await monadic_client.balance()\n", + "print(f\"💰 Final client balance: {balance.balance} uNIL\")" ] }, { @@ -706,7 +657,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 26, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:41:25.749809Z", @@ -718,57 +669,38 @@ "name": "stdout", "output_type": "stream", "text": [ - "Getting quote for operation...\n", - "Quote cost is 3 unil\n", - "Submitting payment receipt 3 unil, tx hash 71D060161BA2A3BCB88FD17F5BF5DE4F25BEC8BDD55C0D81EC847894C7F6308B\n", - "The computation was sent to the network. compute_id: 9382e2cb-ba4d-409e-a839-2efe38580052\n", - "✅ Compute complete for compute_id 9382e2cb-ba4d-409e-a839-2efe38580052\n", - "🖥️ The result is {'my_output': 4}\n" + "The computation was sent to the network. compute_id: 55d5ce02-fb26-4adf-9447-fe8c6e3bc0b6\n", + "✅ Compute complete for compute_id 55d5ce02-fb26-4adf-9447-fe8c6e3bc0b6\n", + "🖥️ The result is {'my_output': SecretInteger(4)}\n", + "💰 Final client balance: 99992 uNIL\n" ] } ], "source": [ "party_name = \"Party1\"\n", - "compute_bindings = nillion.ProgramBindings(program_id)\n", - "compute_bindings.add_input_party(party_name, snipper_party_id)\n", - "compute_bindings.add_output_party(party_name, snipper_party_id)\n", - "\n", - "computation_time_secrets = nillion.NadaValues({})\n", - "\n", - "# Pay for the compute\n", - "receipt_compute = await get_quote_and_pay(\n", - " snipper_client,\n", - " nillion.Operation.compute(program_id, computation_time_secrets),\n", - " payments_wallet,\n", - " payments_client,\n", - " cluster_id,\n", - ")\n", + "\n", + "input_bindings = [InputPartyBinding(party_name, snipper_user_id)]\n", + "output_bindings = [OutputPartyBinding(party_name, [snipper_user_id])]\n", + "\n", + "computation_time_secrets = {}\n", "\n", "# Compute on the secret\n", "compute_id = await snipper_client.compute(\n", - " cluster_id,\n", - " compute_bindings,\n", - " [store_id],\n", - " computation_time_secrets,\n", - " receipt_compute,\n", - ")\n", + " program_id,\n", + " input_bindings,\n", + " output_bindings,\n", + " values=computation_time_secrets,\n", + " value_ids=[new_store_id]\n", + ").invoke()\n", "\n", "# 8. Return the computation result\n", "print(f\"The computation was sent to the network. compute_id: {compute_id}\")\n", - "while True:\n", - " compute_event = await snipper_client.next_compute_event()\n", - " if isinstance(compute_event, nillion.ComputeFinishedEvent):\n", - " print(f\"✅ Compute complete for compute_id {compute_event.uuid}\")\n", - " print(f\"🖥️ The result is {compute_event.result.value}\")\n", - " break" + "result = await snipper_client.retrieve_compute_results(compute_id).invoke()\n", + "print(f\"✅ Compute complete for compute_id {compute_id}\")\n", + "print(f\"🖥️ The result is {result}\")\n", + "balance = await snipper_client.balance()\n", + "print(f\"💰 Final client balance: {balance.balance} uNIL\")" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -776,7 +708,7 @@ "provenance": [] }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -790,7 +722,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.12.7" } }, "nbformat": 4, diff --git a/services/nillion-interactor/binaries/double.nada.bin b/services/nillion-interactor/binaries/double.nada.bin index 9b101eaf061cbde3be313c81b27cd6d34087711c..7e805d97a802be586cdef5fe35cdb7ced500daf6 100644 GIT binary patch delta 136 zcmaFH@`hzX4J#7^5KL@T4PgW^fPfE(VQglw2m?b}em;l^69(%6@>zfw#)iqkXt36a jzkW#YL(M2oPRvOxiZ7`wNG;YYsO*?*$0RdZfyoU3n8pzv delta 121 zcmaFE@{DCd4eJDFRc6MCjjADF1_J{F3lPKD7wS})8G(El%?xD208ESzC;(%_WfJ6M2XdN$SZJ~kQxpIp=M#qj diff --git a/services/nillion-interactor/binaries/double.nada.json b/services/nillion-interactor/binaries/double.nada.json index 5d9930b..890060c 100644 --- a/services/nillion-interactor/binaries/double.nada.json +++ b/services/nillion-interactor/binaries/double.nada.json @@ -1 +1 @@ -{"functions":[],"parties":[{"name":"Party1","source_ref_index":3}],"inputs":[{"type":"SecretInteger","party":"Party1","name":"foo","doc":"","source_ref_index":1}],"literals":[],"outputs":[{"name":"my_output","operation_id":4347741072,"party":"Party1","type":"SecretInteger","source_ref_index":2}],"operations":{"4347741072":{"Addition":{"id":4347741072,"left":4347690704,"right":4347690704,"type":"SecretInteger","source_ref_index":0}},"4347690704":{"InputReference":{"id":4347690704,"refers_to":"foo","type":"SecretInteger","source_ref_index":1}}},"source_files":{"double.py":"from nada_dsl import *\n\ndef nada_main():\n party1 = Party(name=\"Party1\")\n a = SecretInteger(Input(name=\"foo\", party=party1))\n\n result = a + a\n\n return [Output(result, \"my_output\", party1)]\n"},"source_refs":[{"file":"double.py","lineno":7,"offset":131,"length":18},{"file":"double.py","lineno":5,"offset":75,"length":54},{"file":"double.py","lineno":9,"offset":0,"length":0},{"file":"double.py","lineno":4,"offset":41,"length":33}]} \ No newline at end of file +{"functions":[],"parties":[{"name":"Party1","source_ref_index":3}],"inputs":[{"type":"SecretInteger","party":"Party1","name":"foo","doc":"","source_ref_index":1}],"literals":[],"outputs":[{"name":"my_output","operation_id":2,"party":"Party1","type":"SecretInteger","source_ref_index":2}],"operations":{"1":{"InputReference":{"id":1,"refers_to":"foo","type":"SecretInteger","source_ref_index":1}},"2":{"Addition":{"id":2,"left":1,"right":1,"type":"SecretInteger","source_ref_index":0}}},"source_files":{"double.py":"from nada_dsl import *\n\ndef nada_main():\n party1 = Party(name=\"Party1\")\n a = SecretInteger(Input(name=\"foo\", party=party1))\n\n result = a + a\n\n return [Output(result, \"my_output\", party1)]\n"},"source_refs":[{"file":"scalar_types.py","lineno":136,"offset":0,"length":0},{"file":"double.py","lineno":5,"offset":75,"length":54},{"file":"double.py","lineno":9,"offset":0,"length":0},{"file":"double.py","lineno":4,"offset":41,"length":33}]} \ No newline at end of file diff --git a/services/nillion-interactor/binaries/muscle-perform.nada.bin b/services/nillion-interactor/binaries/muscle-perform.nada.bin index 3af350dd16207032fcf1d9da4da8b0cc8870c381..c01bcaaf7ce368495a8ac0073f49eca09af744e7 100644 GIT binary patch literal 3280 zcmb7GO^+Nk5FH>u7`_w2H^e(!rpXd*&j!IpS}q`=Tp%JVaX@I~%y@Pi`U~5wXm1?( zO`JLK7x*zq)U*9&Jj%>USlaco>s7s~YLB}|qd1;P^9yNysI9*&$7%I!nxB(-oAFYz zoSU}um%S;|dUS2C3oWkg*X$P)`}s68onwL{7`T`b1poDd;3VfBG52zde2?T=PG)UC z7&p}ZLzrZ6H}(WQVAYdg-z4^$tQj~j6Fw}F`G8Bzc&iiEaY59W;n zh;$|~6wmH*{y>PtECp%OiG_nld>|Mj=dm;h6EjBWFP)hwh{PlwBPxk($a}I!OdAy# z06n3N2NnXvI|W`A0tN(#*$N6WKrZk~@EVQK5@MD1@|L`s@rZBl;NcWtAYo!A99qXG z4gv;dViH5^NPHvEVr9h4fC>x%ANswS{9q&ADR3hbAZ9Bl$N;&(&E$upNzB$W4*2|0 zyp{M!h?oi8OSUlGN((#_;*Zl_{!HFZdk9FpGvGUkh=9Z&rM*1hyJ-&ri5W0Fykrlj z3>ZY5I1CcQ!;4#^(fbL2M9d7RzyN%3a6zUR5Fp+uz&i~=h}km=GC(enmru+d@?qw! z$@@=C9v^1T&wm@lyu)}Pa=w!MF|elqWROR{oPQ80flti(*r=SJUx&ox(J$xI#)IDs zZc&@hdSh3eZSMA$ed|)( zm38Hp<>y}$wT~-V2joYRs=8xiMA6MRLTh*6JJ2x~Y(}4by$|304h3NOTJGZ(~*7(7;P93Rg zwWc4c63ZPaEzK%+pwU%3E$)xUN=6^PIMk^Mui0s<8*@5|uiQx?{Q(D`48nM179#mT z3O_e?`k?IxpZFk54r8p-7_lgV>-yDtrT?1sbdV6mYkO||Tx8}*gejC|6iH@A+2Wi? z5valZ2G40I<*QSbM=b7EtGTJ2nNIU>py6?#US=_GN+zpF`ac(uhJdHe&V{x-0OKh_lNU9ZUx-ph9jbRX;;2$mriBDO`gt5^i@G$mR-s2blOhO@#DaaysqbW;*RTd{3v!j z9eW)&hS?6|!Q?uTN7zo}^`q{{9SuBhqTS2cN~*bBnI3;ces9Xov;wELbjAg*4=cN`aSbJtXjv>%0D$M>~2 z=yyAQZxA~=a&8`;sHMvZ&@9jf6%{F@(+DW$*qaM(9n0DxFP-x zsX=46&=-*dyO&p1c7y)8VmEN;p!@8f+%Kgj>8M;kRd_)ouZt(YnJ(mhDCJ6TnYalJ zzBSw(YbWP-AvF37eYAYjVmL;K(+?GUKrioE-0-g5Sr7698*j26v9~&bSuW#wEk1m1 z{4rReF;B_?&kPW-+_DNy@`Y9`iPl+DjxjLu$BI*+m(n~iij71NstE-R=a8IgurZL# zFq7c~Jyp4AFoTn3Ly#EBiXJWXE8kpW`l2(65i^9?=7L7|#>NYP$I4)Tfu=K2D?c*E8hnuM|VUB#VgBEg~Q z@xzB<&U|Q6G>oxVng{k?q;9J}h@ergsF7-YRR<_&_=#Ss)*0e^n{4MbndjkHe=yTo zJk2J1vy(q1a&b1Ds5FRz!zdrCWHOs(g?g`EukWajj&=A=u0}zwBQ;IcvrmUA%UybB z^gUm_IM&6n&Qv~~=xM4|lB+=Fvn)vqI-O=JNR>{bc^0IhRsmthy3i!{6M68dg9DYM zQ4$7)&ex%W{DSzhQBq_uIOO>FOr;v9vqYYSvEb&f{Ds>G0)OmIVy=u z_^xvK^M6c=bZjFq36iwgdR(t7S~K&GRr|`kkeX>Q(fix>wY1%$_%MbaqJ(&+LsI#a z96!=o^JzMp7lLQN_O6w+ZzZ-`hP9lE8~IDr%R-ElBFK((aY$+o*$|lEx>ku?L&_S) zCnwkk{Vj7gjVn*~RaIhZFNqKJIM>Z)^;i*%;j8OXZ)>--!D+33h_W^-gF!BfddbL@ zT&M+}93TdKUDN>UZ!s-`F&V*rzfXVL_BhE8^LZHRJdfvm-LyDT2j|+Yiealm;{wZE z-Qv<+kHA`Ntk%rD$w}Rs`n^m)*TJ|c8M5W9zWi)naAjGZUA1i=^r#HC^;P}4ZT8x! zUC%#H-%;o9(0(e2XW}IS6`Mf!=<;uxrdyjpcj@wL0)4*;#BYXz=GDiWKy2(^1lryN rx= target_snp_1).if_else((target_snp_1 >= snp1).if_else(Integer(1), Integer(0)), Integer(0))\n eq2 = (genotype1 >= target_genotype_1).if_else((target_genotype_1 >= genotype1).if_else(Integer(1), Integer(0)), Integer(0))\n\n\n total = eq1 + eq2\n\n is_successful = (total >= Integer(2)).if_else((Integer(2) >= total).if_else(Integer(1), Integer(0)), Integer(0))\n\n result = is_successful.reveal()\n\n return [Output(result, \"Result\", party1)]\n"},"source_refs":[{"file":"muscle-perform.py","lineno":27,"offset":890,"length":35},{"file":"muscle-perform.py","lineno":25,"offset":772,"length":116},{"file":"muscle-perform.py","lineno":23,"offset":749,"length":21},{"file":"muscle-perform.py","lineno":20,"offset":618,"length":128},{"file":"muscle-perform.py","lineno":14,"offset":372,"length":68},{"file":"muscle-perform.py","lineno":17,"offset":473,"length":34},{"file":"muscle-perform.py","lineno":19,"offset":509,"length":108},{"file":"muscle-perform.py","lineno":13,"offset":313,"length":58},{"file":"muscle-perform.py","lineno":16,"offset":442,"length":30},{"file":"muscle-perform.py","lineno":29,"offset":0,"length":0},{"file":"muscle-perform.py","lineno":10,"offset":277,"length":33}]} \ No newline at end of file +{"functions":[],"parties":[{"name":"Party1","source_ref_index":10}],"inputs":[{"type":"SecretInteger","party":"Party1","name":"genotype1","doc":"","source_ref_index":4},{"type":"SecretInteger","party":"Party1","name":"snp1","doc":"","source_ref_index":7}],"literals":[{"name":"3","value":"0","type":"Integer"},{"name":"2","value":"1","type":"Integer"},{"name":"1","value":"9","type":"Integer"},{"name":"0","value":"11","type":"Integer"},{"name":"4","value":"2","type":"Integer"}],"outputs":[{"name":"Result","operation_id":28,"party":"Party1","type":"SecretInteger","source_ref_index":9}],"operations":{"1":{"InputReference":{"id":1,"refers_to":"snp1","type":"SecretInteger","source_ref_index":7}},"2":{"InputReference":{"id":2,"refers_to":"genotype1","type":"SecretInteger","source_ref_index":4}},"3":{"LiteralReference":{"id":3,"refers_to":"0","type":"Integer","source_ref_index":8}},"4":{"LiteralReference":{"id":4,"refers_to":"1","type":"Integer","source_ref_index":5}},"5":{"Not":{"id":5,"this":34,"type":"SecretBoolean","source_ref_index":1}},"6":{"Not":{"id":6,"this":33,"type":"SecretBoolean","source_ref_index":1}},"7":{"LiteralReference":{"id":7,"refers_to":"2","type":"Integer","source_ref_index":6}},"8":{"LiteralReference":{"id":8,"refers_to":"3","type":"Integer","source_ref_index":6}},"9":{"IfElse":{"id":9,"this":6,"arg_0":7,"arg_1":8,"type":"SecretInteger","source_ref_index":6}},"10":{"LiteralReference":{"id":10,"refers_to":"3","type":"Integer","source_ref_index":6}},"11":{"IfElse":{"id":11,"this":5,"arg_0":9,"arg_1":10,"type":"SecretInteger","source_ref_index":6}},"12":{"Not":{"id":12,"this":32,"type":"SecretBoolean","source_ref_index":1}},"13":{"Not":{"id":13,"this":31,"type":"SecretBoolean","source_ref_index":1}},"14":{"LiteralReference":{"id":14,"refers_to":"2","type":"Integer","source_ref_index":3}},"15":{"LiteralReference":{"id":15,"refers_to":"3","type":"Integer","source_ref_index":3}},"16":{"IfElse":{"id":16,"this":13,"arg_0":14,"arg_1":15,"type":"SecretInteger","source_ref_index":3}},"17":{"LiteralReference":{"id":17,"refers_to":"3","type":"Integer","source_ref_index":3}},"18":{"IfElse":{"id":18,"this":12,"arg_0":16,"arg_1":17,"type":"SecretInteger","source_ref_index":3}},"19":{"Addition":{"id":19,"left":11,"right":18,"type":"SecretInteger","source_ref_index":2}},"20":{"LiteralReference":{"id":20,"refers_to":"4","type":"Integer","source_ref_index":0}},"21":{"Not":{"id":21,"this":30,"type":"SecretBoolean","source_ref_index":1}},"22":{"LiteralReference":{"id":22,"refers_to":"4","type":"Integer","source_ref_index":0}},"23":{"Not":{"id":23,"this":29,"type":"SecretBoolean","source_ref_index":1}},"24":{"LiteralReference":{"id":24,"refers_to":"2","type":"Integer","source_ref_index":0}},"25":{"LiteralReference":{"id":25,"refers_to":"3","type":"Integer","source_ref_index":0}},"26":{"IfElse":{"id":26,"this":23,"arg_0":24,"arg_1":25,"type":"SecretInteger","source_ref_index":0}},"27":{"LiteralReference":{"id":27,"refers_to":"3","type":"Integer","source_ref_index":0}},"28":{"IfElse":{"id":28,"this":21,"arg_0":26,"arg_1":27,"type":"SecretInteger","source_ref_index":0}},"29":{"LessThan":{"id":29,"left":22,"right":19,"type":"SecretBoolean","source_ref_index":1}},"30":{"LessThan":{"id":30,"left":19,"right":20,"type":"SecretBoolean","source_ref_index":1}},"31":{"LessThan":{"id":31,"left":4,"right":2,"type":"SecretBoolean","source_ref_index":1}},"32":{"LessThan":{"id":32,"left":2,"right":4,"type":"SecretBoolean","source_ref_index":1}},"33":{"LessThan":{"id":33,"left":3,"right":1,"type":"SecretBoolean","source_ref_index":1}},"34":{"LessThan":{"id":34,"left":1,"right":3,"type":"SecretBoolean","source_ref_index":1}}},"source_files":{"muscle-perform.py":"from nada_dsl import *\n\n\n# Checks based on SNP rs1815739 whether someone is a sprinter or an endurance athelete\n# Genotype TT indicates endurance athlete\n# We arbitrarily assume sprinter otherwise\n# This program returns 0 if sprinter, 1 if endurance athelete\ndef nada_main():\n\n party1 = Party(name=\"Party1\")\n\n\n snp1 = SecretInteger(Input(name=\"snp1\", party=party1))\n genotype1 = SecretInteger(Input(name=\"genotype1\", party=party1))\n\n target_snp_1 = Integer(11)\n target_genotype_1 = Integer(9)\n\n eq1 = (snp1 >= target_snp_1).if_else((target_snp_1 >= snp1).if_else(Integer(1), Integer(0)), Integer(0))\n eq2 = (genotype1 >= target_genotype_1).if_else((target_genotype_1 >= genotype1).if_else(Integer(1), Integer(0)), Integer(0))\n\n\n total = eq1 + eq2\n\n is_successful = (total >= Integer(2)).if_else((Integer(2) >= total).if_else(Integer(1), Integer(0)), Integer(0))\n\n result = is_successful\n\n return [Output(result, \"Result\", party1)]\n"},"source_refs":[{"file":"muscle-perform.py","lineno":25,"offset":772,"length":116},{"file":"scalar_types.py","lineno":200,"offset":0,"length":0},{"file":"scalar_types.py","lineno":136,"offset":0,"length":0},{"file":"muscle-perform.py","lineno":20,"offset":618,"length":128},{"file":"muscle-perform.py","lineno":14,"offset":372,"length":68},{"file":"muscle-perform.py","lineno":17,"offset":473,"length":34},{"file":"muscle-perform.py","lineno":19,"offset":509,"length":108},{"file":"muscle-perform.py","lineno":13,"offset":313,"length":58},{"file":"muscle-perform.py","lineno":16,"offset":442,"length":30},{"file":"muscle-perform.py","lineno":29,"offset":0,"length":0},{"file":"muscle-perform.py","lineno":10,"offset":277,"length":33}]} \ No newline at end of file diff --git a/services/nillion-interactor/binaries/thrombosis.nada.bin b/services/nillion-interactor/binaries/thrombosis.nada.bin index 2ece5410826b6f7c033170b2cd29f8674ab26612..a720ff1eaa70730cb774506e2183cd267196bdd7 100644 GIT binary patch literal 3194 zcma)8+m0hO5N%klVYx2%YfX4bv!hWuyRZl;JixS@9kMOj6H+Bq|e03ECD$~rUNSR-%AL7T0VWuUe+H&QoE{5i#2-Xk8u0CCLqK8%^otkA z{VoFr5jzfzM89~!lx6Qm01`1XpaKJM;oyQy(I7zFE5I)rf)KN26l8!@Ae}xjYske+ zOOw{0m^?0K%1_@7Vt&K8AyU3*{%EiXfHv~zm-3GS#q)_dKNc$Gr=LS&^5~cHImS1w zUD;-H(YVT;Y%hO{9t*WeUCzt%xm!!M**3P7PX>dJ`U`>V>y);3F9Zp4~)XKN>8sTQfqu@tcE zMH$SEaxn8vS=FQbi-Bm{`U{3k#hmec4LfI zH5JVCrv6XD#4C5Uo6U@K$SZJEhfybar=)8c)^w8l8X;ac%EA9Ef%TU)Rl8CSiG&?0 zKYqJwv1J17Scc(p$5k)#p9VaKdS73BxBk$N%T{}QVA0&HT$lD7*Im5fkAv0!AE5l2 zPc7CTazi8h}zpA#i~eu#jB{&ywd?C4FB Rhk}mx6L4+2t`Uy3{|jELow)!2 literal 3797 zcmb7H%Z}qj6b&%E!T>=$Bpwn)&nAIZ%db3))GPqew0KNry3v3JXdG8Lu_m#D?aZiI z@D1U)f)z`CgawQI13SKgdtG&6x28ifwMZS;J@=lfTer$iqoLbFrhm-z!yqfp?WTEp z*z}K3f06Nov5Zxc7Uy$i9vfFSdTn z^?HHwyH=Oi) z?<;rE?|Oc35Lrsv%8`SC9N1k*l}>m-(r>DKF)fzS?^oD@QN39#@+ALIyQaHF>xO2& zO3%Q*8gI@zHsj~o81U-*-%6F$2Ra7x*NUI(v6pFVXfWchKGU|%cuBy5Ft=Tngs@02rydxoY@M2^nk`@-_$@!uHr59ggt=`yGt5CsQ4Zxg zOlb%vP}_DQn1dSw>EzS_!-m_0=Z>3X_@SPESvm%zRO_X=GTX|2z)Mq3C{>P&)47zj zycjIV&TW@{LFu$cRUBYZMtQ(EW)I8KHyCkt*(dCG>#WKbFpfaIvdPZR)JC1xI&nZ{lO*v3XK7`l%6{ct=rI?Wv&NcVXV8X2YQ%8d2Y>>hB(_^ ze=LWWGp^6FKFw8%I1jR)^;!X5pI1{e^*SAXqH|NeatuZt;6B5C^O~`bIQwON;~p^g z2V&wCQ}@GOupe;C)H%)x?hf`tz2nT3c{b+<`Pt?CA`beeDK@ualBKgzn#cLU{QM8I zs}YTfB#^ur&C{$9Z#J9P#CsDJ-pR!%$dwdnB2GRXiY)J0PFLKUsA8frk*712 zCQ3|#Tx4;6M?`5RDj5oLWWMUe(UFJ~8HYika*?FjESPGSG`i?i6PYk;3UD&c!@S$5}8FnJN}pk_$`3QC($U*gSF}N>eK0@XBXF zoU}V{HwCqM`PnKCMfpk8PJ)>_+|!>&d!3R&Z)Gx{sF1{tlR}ME);><=i^7n}zPGRA z9O`Ht?TB~M|9XRTe~41N2(qy%&h#9hZaZ4Q7!iVW!030HrMvpprqMRLzjG+6V4Z_F zI#bhJwcFJoQ;1pF5Y6uFuOnNXiw{P|VVU(rDlH6EK_LhWs{&W7ou!MkpvpQFywbPm z*U<})^OHpwsyyd;X%6Wis?({IXfO4iI-N2{9Ivv%xHSb?`JGK_YvqGX-BrP~ZMH&} zsuMi4bif@ZXXHA`CVWu9D$TBD}VV T@Ddr&F3kgfI$os+Z&3dqTgcJr diff --git a/services/nillion-interactor/binaries/thrombosis.nada.json b/services/nillion-interactor/binaries/thrombosis.nada.json index 156594a..90e352b 100644 --- a/services/nillion-interactor/binaries/thrombosis.nada.json +++ b/services/nillion-interactor/binaries/thrombosis.nada.json @@ -1 +1 @@ -{"functions":[],"parties":[{"name":"Party1","source_ref_index":10}],"inputs":[{"type":"SecretInteger","party":"Party1","name":"genotype","doc":"","source_ref_index":4},{"type":"SecretInteger","party":"Party1","name":"snp","doc":"","source_ref_index":7}],"literals":[{"name":"0420609fa1d35394f41049df03ef341f","value":"0","type":"Integer"},{"name":"10d33944d37d5b1b833be6fd73d3033c","value":"1","type":"Integer"},{"name":"95f937652c869546ae950ce422fddbae","value":"7","type":"Integer"},{"name":"2219253adcecfae08b67c9c486fce6f2","value":"12","type":"Integer"},{"name":"be9dc3499e38754968f0ed1e2d88d815","value":"2","type":"Integer"}],"outputs":[{"name":"Result","operation_id":4372391568,"party":"Party1","type":"Integer","source_ref_index":9}],"operations":{"4372386064":{"Not":{"id":4372386064,"this":4372391574,"type":"SecretBoolean","source_ref_index":3}},"4372391572":{"LessThan":{"id":4372391572,"left":4372332240,"right":4372383440,"type":"SecretBoolean","source_ref_index":6}},"4372387920":{"IfElse":{"id":4372387920,"this":4372386064,"arg_0":4372387280,"arg_1":4372387792,"type":"SecretInteger","source_ref_index":3}},"4372386384":{"Not":{"id":4372386384,"this":4372391573,"type":"SecretBoolean","source_ref_index":3}},"4372385552":{"LiteralReference":{"id":4372385552,"refers_to":"0420609fa1d35394f41049df03ef341f","type":"Integer","source_ref_index":6}},"4372391571":{"LessThan":{"id":4372391571,"left":4372389392,"right":4372388304,"type":"SecretBoolean","source_ref_index":1}},"4372391573":{"LessThan":{"id":4372391573,"left":4372383696,"right":4372382800,"type":"SecretBoolean","source_ref_index":3}},"4372332240":{"InputReference":{"id":4372332240,"refers_to":"snp","type":"SecretInteger","source_ref_index":7}},"4372387792":{"LiteralReference":{"id":4372387792,"refers_to":"0420609fa1d35394f41049df03ef341f","type":"Integer","source_ref_index":3}},"4372387280":{"IfElse":{"id":4372387280,"this":4372386384,"arg_0":4372386832,"arg_1":4372387152,"type":"SecretInteger","source_ref_index":3}},"4372384656":{"LiteralReference":{"id":4372384656,"refers_to":"10d33944d37d5b1b833be6fd73d3033c","type":"Integer","source_ref_index":6}},"4372383440":{"LiteralReference":{"id":4372383440,"refers_to":"2219253adcecfae08b67c9c486fce6f2","type":"Integer","source_ref_index":8}},"4372382800":{"InputReference":{"id":4372382800,"refers_to":"genotype","type":"SecretInteger","source_ref_index":4}},"4372383824":{"Not":{"id":4372383824,"this":4372391572,"type":"SecretBoolean","source_ref_index":6}},"4372388304":{"Addition":{"id":4372388304,"left":4372385680,"right":4372387920,"type":"SecretInteger","source_ref_index":2}},"4372391056":{"LiteralReference":{"id":4372391056,"refers_to":"0420609fa1d35394f41049df03ef341f","type":"Integer","source_ref_index":1}},"4372390416":{"LiteralReference":{"id":4372390416,"refers_to":"0420609fa1d35394f41049df03ef341f","type":"Integer","source_ref_index":1}},"4372386832":{"LiteralReference":{"id":4372386832,"refers_to":"10d33944d37d5b1b833be6fd73d3033c","type":"Integer","source_ref_index":3}},"4372389648":{"Not":{"id":4372389648,"this":4372391571,"type":"SecretBoolean","source_ref_index":1}},"4372390544":{"IfElse":{"id":4372390544,"this":4372389648,"arg_0":4372390096,"arg_1":4372390416,"type":"SecretInteger","source_ref_index":1}},"4372388880":{"Not":{"id":4372388880,"this":4372391570,"type":"SecretBoolean","source_ref_index":1}},"4372388752":{"LiteralReference":{"id":4372388752,"refers_to":"be9dc3499e38754968f0ed1e2d88d815","type":"Integer","source_ref_index":1}},"4372384208":{"Not":{"id":4372384208,"this":4372391569,"type":"SecretBoolean","source_ref_index":6}},"4372384976":{"LiteralReference":{"id":4372384976,"refers_to":"0420609fa1d35394f41049df03ef341f","type":"Integer","source_ref_index":6}},"4372391569":{"LessThan":{"id":4372391569,"left":4372383440,"right":4372332240,"type":"SecretBoolean","source_ref_index":6}},"4372391574":{"LessThan":{"id":4372391574,"left":4372382800,"right":4372383696,"type":"SecretBoolean","source_ref_index":3}},"4372391568":{"Reveal":{"id":4372391568,"this":4372391184,"type":"Integer","source_ref_index":0}},"4372387152":{"LiteralReference":{"id":4372387152,"refers_to":"0420609fa1d35394f41049df03ef341f","type":"Integer","source_ref_index":3}},"4372383696":{"LiteralReference":{"id":4372383696,"refers_to":"95f937652c869546ae950ce422fddbae","type":"Integer","source_ref_index":5}},"4372389392":{"LiteralReference":{"id":4372389392,"refers_to":"be9dc3499e38754968f0ed1e2d88d815","type":"Integer","source_ref_index":1}},"4372391570":{"LessThan":{"id":4372391570,"left":4372388304,"right":4372388752,"type":"SecretBoolean","source_ref_index":1}},"4372385104":{"IfElse":{"id":4372385104,"this":4372384208,"arg_0":4372384656,"arg_1":4372384976,"type":"SecretInteger","source_ref_index":6}},"4372385680":{"IfElse":{"id":4372385680,"this":4372383824,"arg_0":4372385104,"arg_1":4372385552,"type":"SecretInteger","source_ref_index":6}},"4372391184":{"IfElse":{"id":4372391184,"this":4372388880,"arg_0":4372390544,"arg_1":4372391056,"type":"SecretInteger","source_ref_index":1}},"4372390096":{"LiteralReference":{"id":4372390096,"refers_to":"10d33944d37d5b1b833be6fd73d3033c","type":"Integer","source_ref_index":1}}},"source_files":{"thrombosis.py":"from nada_dsl import *\n\n# Checks based on SNP rs6025 whether someone has risk for thrombosis\n# Genotype GG indicates normal risk of thrombosis\n# We arbitrarily assume elevated risk otherwise\n# This program returns 0 if normal risk, 1 if elevated risk\ndef nada_main():\n party1 = Party(name=\"Party1\")\n snp = SecretInteger(Input(name=\"snp\", party=party1))\n genotype = SecretInteger(Input(name=\"genotype\", party=party1))\n\n target_snp = Integer(12)\n target_genotype = Integer(7)\n\n eq1 = (snp >= target_snp).if_else((target_snp >= snp).if_else(Integer(1), Integer(0)), Integer(0))\n eq2 = (genotype >= target_genotype).if_else((target_genotype >= genotype).if_else(Integer(1), Integer(0)), Integer(0))\n total = eq1 + eq2\n\n isSuccess = (total >= Integer(2)).if_else((Integer(2) >= total).if_else(Integer(1), Integer(0)), Integer(0))\n result = isSuccess.reveal()\n\n return [Output(result, \"Result\", party1)]\n"},"source_refs":[{"file":"thrombosis.py","lineno":20,"offset":852,"length":31},{"file":"thrombosis.py","lineno":19,"offset":739,"length":112},{"file":"thrombosis.py","lineno":17,"offset":716,"length":21},{"file":"thrombosis.py","lineno":16,"offset":593,"length":122},{"file":"thrombosis.py","lineno":10,"offset":359,"length":66},{"file":"thrombosis.py","lineno":13,"offset":456,"length":32},{"file":"thrombosis.py","lineno":15,"offset":490,"length":102},{"file":"thrombosis.py","lineno":9,"offset":302,"length":56},{"file":"thrombosis.py","lineno":12,"offset":427,"length":28},{"file":"thrombosis.py","lineno":22,"offset":0,"length":0},{"file":"thrombosis.py","lineno":8,"offset":268,"length":33}]} \ No newline at end of file +{"functions":[],"parties":[{"name":"Party1","source_ref_index":10}],"inputs":[{"type":"SecretInteger","party":"Party1","name":"genotype","doc":"","source_ref_index":4},{"type":"SecretInteger","party":"Party1","name":"snp","doc":"","source_ref_index":7}],"literals":[{"name":"3","value":"0","type":"Integer"},{"name":"2","value":"1","type":"Integer"},{"name":"1","value":"7","type":"Integer"},{"name":"0","value":"12","type":"Integer"},{"name":"4","value":"2","type":"Integer"}],"outputs":[{"name":"Result","operation_id":28,"party":"Party1","type":"SecretInteger","source_ref_index":9}],"operations":{"1":{"InputReference":{"id":1,"refers_to":"snp","type":"SecretInteger","source_ref_index":7}},"2":{"InputReference":{"id":2,"refers_to":"genotype","type":"SecretInteger","source_ref_index":4}},"3":{"LiteralReference":{"id":3,"refers_to":"0","type":"Integer","source_ref_index":8}},"4":{"LiteralReference":{"id":4,"refers_to":"1","type":"Integer","source_ref_index":5}},"5":{"Not":{"id":5,"this":34,"type":"SecretBoolean","source_ref_index":1}},"6":{"Not":{"id":6,"this":33,"type":"SecretBoolean","source_ref_index":1}},"7":{"LiteralReference":{"id":7,"refers_to":"2","type":"Integer","source_ref_index":6}},"8":{"LiteralReference":{"id":8,"refers_to":"3","type":"Integer","source_ref_index":6}},"9":{"IfElse":{"id":9,"this":6,"arg_0":7,"arg_1":8,"type":"SecretInteger","source_ref_index":6}},"10":{"LiteralReference":{"id":10,"refers_to":"3","type":"Integer","source_ref_index":6}},"11":{"IfElse":{"id":11,"this":5,"arg_0":9,"arg_1":10,"type":"SecretInteger","source_ref_index":6}},"12":{"Not":{"id":12,"this":32,"type":"SecretBoolean","source_ref_index":1}},"13":{"Not":{"id":13,"this":31,"type":"SecretBoolean","source_ref_index":1}},"14":{"LiteralReference":{"id":14,"refers_to":"2","type":"Integer","source_ref_index":3}},"15":{"LiteralReference":{"id":15,"refers_to":"3","type":"Integer","source_ref_index":3}},"16":{"IfElse":{"id":16,"this":13,"arg_0":14,"arg_1":15,"type":"SecretInteger","source_ref_index":3}},"17":{"LiteralReference":{"id":17,"refers_to":"3","type":"Integer","source_ref_index":3}},"18":{"IfElse":{"id":18,"this":12,"arg_0":16,"arg_1":17,"type":"SecretInteger","source_ref_index":3}},"19":{"Addition":{"id":19,"left":11,"right":18,"type":"SecretInteger","source_ref_index":2}},"20":{"LiteralReference":{"id":20,"refers_to":"4","type":"Integer","source_ref_index":0}},"21":{"Not":{"id":21,"this":30,"type":"SecretBoolean","source_ref_index":1}},"22":{"LiteralReference":{"id":22,"refers_to":"4","type":"Integer","source_ref_index":0}},"23":{"Not":{"id":23,"this":29,"type":"SecretBoolean","source_ref_index":1}},"24":{"LiteralReference":{"id":24,"refers_to":"2","type":"Integer","source_ref_index":0}},"25":{"LiteralReference":{"id":25,"refers_to":"3","type":"Integer","source_ref_index":0}},"26":{"IfElse":{"id":26,"this":23,"arg_0":24,"arg_1":25,"type":"SecretInteger","source_ref_index":0}},"27":{"LiteralReference":{"id":27,"refers_to":"3","type":"Integer","source_ref_index":0}},"28":{"IfElse":{"id":28,"this":21,"arg_0":26,"arg_1":27,"type":"SecretInteger","source_ref_index":0}},"29":{"LessThan":{"id":29,"left":22,"right":19,"type":"SecretBoolean","source_ref_index":1}},"30":{"LessThan":{"id":30,"left":19,"right":20,"type":"SecretBoolean","source_ref_index":1}},"31":{"LessThan":{"id":31,"left":4,"right":2,"type":"SecretBoolean","source_ref_index":1}},"32":{"LessThan":{"id":32,"left":2,"right":4,"type":"SecretBoolean","source_ref_index":1}},"33":{"LessThan":{"id":33,"left":3,"right":1,"type":"SecretBoolean","source_ref_index":1}},"34":{"LessThan":{"id":34,"left":1,"right":3,"type":"SecretBoolean","source_ref_index":1}}},"source_files":{"thrombosis.py":"from nada_dsl import *\n\n# Checks based on SNP rs6025 whether someone has risk for thrombosis\n# Genotype GG indicates normal risk of thrombosis\n# We arbitrarily assume elevated risk otherwise\n# This program returns 0 if normal risk, 1 if elevated risk\ndef nada_main():\n party1 = Party(name=\"Party1\")\n snp = SecretInteger(Input(name=\"snp\", party=party1))\n genotype = SecretInteger(Input(name=\"genotype\", party=party1))\n\n target_snp = Integer(12)\n target_genotype = Integer(7)\n\n eq1 = (snp >= target_snp).if_else((target_snp >= snp).if_else(Integer(1), Integer(0)), Integer(0))\n eq2 = (genotype >= target_genotype).if_else((target_genotype >= genotype).if_else(Integer(1), Integer(0)), Integer(0))\n total = eq1 + eq2\n\n isSuccess = (total >= Integer(2)).if_else((Integer(2) >= total).if_else(Integer(1), Integer(0)), Integer(0))\n result = isSuccess\n\n return [Output(result, \"Result\", party1)]\n"},"source_refs":[{"file":"thrombosis.py","lineno":19,"offset":739,"length":112},{"file":"scalar_types.py","lineno":200,"offset":0,"length":0},{"file":"scalar_types.py","lineno":136,"offset":0,"length":0},{"file":"thrombosis.py","lineno":16,"offset":593,"length":122},{"file":"thrombosis.py","lineno":10,"offset":359,"length":66},{"file":"thrombosis.py","lineno":13,"offset":456,"length":32},{"file":"thrombosis.py","lineno":15,"offset":490,"length":102},{"file":"thrombosis.py","lineno":9,"offset":302,"length":56},{"file":"thrombosis.py","lineno":12,"offset":427,"length":28},{"file":"thrombosis.py","lineno":22,"offset":0,"length":0},{"file":"thrombosis.py","lineno":8,"offset":268,"length":33}]} \ No newline at end of file diff --git a/services/nillion-interactor/compile.sh b/services/nillion-interactor/compile.sh index a8a37ee..ec18f8b 100755 --- a/services/nillion-interactor/compile.sh +++ b/services/nillion-interactor/compile.sh @@ -7,8 +7,8 @@ time pynadac --target-dir binaries --generate-mir-json programs/thrombosis.py echo "Compiling muscle-perform.py" time pynadac --target-dir binaries --generate-mir-json programs/muscle-perform.py -echo "Compiling muscle-perform-array.py" -time pynadac --target-dir binaries --generate-mir-json programs/muscle-perform-array.py +# echo "Compiling muscle-perform-array.py" +# time pynadac --target-dir binaries --generate-mir-json programs/muscle-perform-array.py echo "Compiling double.py" time pynadac --target-dir binaries --generate-mir-json programs/double.py diff --git a/services/nillion-interactor/programs/muscle-perform.py b/services/nillion-interactor/programs/muscle-perform.py index 25de340..63a7a5f 100644 --- a/services/nillion-interactor/programs/muscle-perform.py +++ b/services/nillion-interactor/programs/muscle-perform.py @@ -24,6 +24,6 @@ def nada_main(): is_successful = (total >= Integer(2)).if_else((Integer(2) >= total).if_else(Integer(1), Integer(0)), Integer(0)) - result = is_successful.reveal() + result = is_successful return [Output(result, "Result", party1)] diff --git a/services/nillion-interactor/programs/thrombosis.py b/services/nillion-interactor/programs/thrombosis.py index 9924b75..b7bad4d 100644 --- a/services/nillion-interactor/programs/thrombosis.py +++ b/services/nillion-interactor/programs/thrombosis.py @@ -17,6 +17,6 @@ def nada_main(): total = eq1 + eq2 isSuccess = (total >= Integer(2)).if_else((Integer(2) >= total).if_else(Integer(1), Integer(0)), Integer(0)) - result = isSuccess.reveal() + result = isSuccess return [Output(result, "Result", party1)] diff --git a/services/nillion-interactor/requirements.txt b/services/nillion-interactor/requirements.txt index 98a46ab..a658411 100644 --- a/services/nillion-interactor/requirements.txt +++ b/services/nillion-interactor/requirements.txt @@ -1,6 +1,7 @@ python-dotenv==1.0.0 -nada-dsl==0.6.0 -py-nillion-client==0.6.0 pytest-asyncio>=0.23.6 Flask[async]==3.0.3 flask-cors==4.0.0 +cryptography>=44.0.0 +nillion-client==0.1.1 +nada-dsl==0.7.2 \ No newline at end of file From 57620b4d7dd61a58bc0d8b28b389328da5139e5a Mon Sep 17 00:00:00 2001 From: gdsoumya Date: Mon, 23 Dec 2024 21:41:26 +0530 Subject: [PATCH 2/5] feat: update permissions later without overwriting Signed-off-by: gdsoumya --- .../nillion-interactor/E2E_Nillion_Test.ipynb | 92 ++++++++++++------- 1 file changed, 60 insertions(+), 32 deletions(-) diff --git a/services/nillion-interactor/E2E_Nillion_Test.ipynb b/services/nillion-interactor/E2E_Nillion_Test.ipynb index d01471f..31482cd 100644 --- a/services/nillion-interactor/E2E_Nillion_Test.ipynb +++ b/services/nillion-interactor/E2E_Nillion_Test.ipynb @@ -111,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 26, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:05.762189Z", @@ -134,12 +134,14 @@ " SecretInteger,\n", " UserId,\n", " Permissions,\n", + " PermissionsDelta,\n", " VmClient,\n", " PrivateKey,\n", ")\n", "from dotenv import load_dotenv\n", "from nillion_client.ids import UUID\n", "from nillion_client.payer import DummyPayer\n", + "from nillion_client.permissions import (ComputePermissionCommand, ComputePermissions,ComputePermission)\n", "import hashlib" ] }, @@ -154,7 +156,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:08.870617Z", @@ -215,7 +217,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:12.833625Z", @@ -238,7 +240,7 @@ "Network(chain_id='nillion-chain-devnet', chain_grpc_endpoint='http://localhost:26649', nilvm_grpc_endpoint='http://127.0.0.1:37939')" ] }, - "execution_count": 7, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -265,7 +267,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:19.828183Z", @@ -290,7 +292,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:22.512975Z", @@ -315,7 +317,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:28.760101Z", @@ -340,7 +342,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:31.282228Z", @@ -373,7 +375,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -402,7 +404,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -420,7 +422,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:41.524938Z", @@ -434,18 +436,12 @@ "text": [ "The patient is storing the program on the network\n", "Program ID: 4b367ad186fa672387ca7fb6ea9f75c13cc53a82/double/sha256/35f9b61f28b8e9aafbc987766f6ff549892aafe1d65256aa6feec84b1f5b6bf0\n", - "The patient is storing a secret on the network\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ + "The patient is storing a secret on the network\n", "The patient is running the program on the secret..\n", - "The computation was sent to the network. compute_id: 862ecd60-1438-4c23-b11a-01cc03f4d64f\n", - "✅ Compute complete for compute_id 862ecd60-1438-4c23-b11a-01cc03f4d64f\n", + "The computation was sent to the network. compute_id: 2b348f6c-260b-4626-8839-dab228c51f66\n", + "✅ Compute complete for compute_id 2b348f6c-260b-4626-8839-dab228c51f66\n", "🖥️ The result is {'my_output': SecretInteger(4)}\n", - "💰 Final client balance: 99028 uNIL\n" + "💰 Final client balance: 99514 uNIL\n" ] } ], @@ -515,7 +511,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:49.395066Z", @@ -552,14 +548,13 @@ "Have the Patient store a secret on the network such that:\n", "- The Patient has all the regular persmissions\n", "- Monadic is able to modify permissions and compute on the secret\n", - "- Snipper is able to compute on the secret\n", "\n", "TODO: Establish a chain by having Monadic actually assign compute access to Snipper" ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 39, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:54.210051Z", @@ -579,7 +574,6 @@ "permissions = Permissions.defaults_for_user(patient_user_id)\\\n", " .allow_update(monadic_user_id)\\\n", " .allow_compute(monadic_user_id, program_id)\\\n", - " .allow_compute(snipper_user_id,program_id)\n", "\n", "\n", "# Store a secret\n", @@ -599,7 +593,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 40, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:59.264419Z", @@ -611,8 +605,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "The computation was sent to the network. compute_id: 6a92aaa6-734f-435d-a71b-5d30e9d61c83\n", - "✅ Compute complete for compute_id 6a92aaa6-734f-435d-a71b-5d30e9d61c83\n", + "The computation was sent to the network. compute_id: b4f84bd0-0317-42b3-8376-8e02675a8733\n", + "✅ Compute complete for compute_id b4f84bd0-0317-42b3-8376-8e02675a8733\n", "🖥️ The result is {'my_output': SecretInteger(4)}\n", "💰 Final client balance: 99991 uNIL\n" ] @@ -648,6 +642,40 @@ "print(f\"💰 Final client balance: {balance.balance} uNIL\")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Update permissions on the value to give snipper bot compute perms" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "existing compute perms count 1\n", + "new compute perms count 2\n" + ] + } + ], + "source": [ + "compute = ComputePermissions()\n", + "compute.permissions[snipper_user_id] = ComputePermission()\n", + "compute.permissions[snipper_user_id].program_ids.add(mondaic_program_id)\n", + "allowCompute = PermissionsDelta(compute=ComputePermissionCommand(grant=compute))\n", + "existingPermissions = await patient_client.retrieve_permissions(new_store_id).invoke()\n", + "await patient_client.update_permissions(new_store_id, allowCompute).invoke()\n", + "newPermissions = await patient_client.retrieve_permissions(new_store_id).invoke()\n", + "\n", + "print(\"existing compute perms count\", len(existingPermissions.compute.permissions))\n", + "print(\"new compute perms count\", len(newPermissions.compute.permissions))\n" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -657,7 +685,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 42, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:41:25.749809Z", @@ -669,10 +697,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "The computation was sent to the network. compute_id: 55d5ce02-fb26-4adf-9447-fe8c6e3bc0b6\n", - "✅ Compute complete for compute_id 55d5ce02-fb26-4adf-9447-fe8c6e3bc0b6\n", + "The computation was sent to the network. compute_id: 117e212e-97a7-4481-ad61-07d277468115\n", + "✅ Compute complete for compute_id 117e212e-97a7-4481-ad61-07d277468115\n", "🖥️ The result is {'my_output': SecretInteger(4)}\n", - "💰 Final client balance: 99992 uNIL\n" + "💰 Final client balance: 99988 uNIL\n" ] } ], From 9ccc06a133847f0239a31504bf8dbbed837beb1d Mon Sep 17 00:00:00 2001 From: gdsoumya Date: Mon, 13 Jan 2025 21:24:45 +0530 Subject: [PATCH 3/5] feat add testnet support for e2e notebook Signed-off-by: gdsoumya --- .../nillion-interactor/E2E_Nillion_Test.ipynb | 270 ++++++++++-------- 1 file changed, 158 insertions(+), 112 deletions(-) diff --git a/services/nillion-interactor/E2E_Nillion_Test.ipynb b/services/nillion-interactor/E2E_Nillion_Test.ipynb index 31482cd..8935f00 100644 --- a/services/nillion-interactor/E2E_Nillion_Test.ipynb +++ b/services/nillion-interactor/E2E_Nillion_Test.ipynb @@ -23,7 +23,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T19:26:51.222994Z", @@ -40,57 +40,57 @@ "name": "stdout", "output_type": "stream", "text": [ - "Requirement already satisfied: nada-dsl==0.7.2 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (0.7.2)\n", - "Requirement already satisfied: asttokens~=2.4 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nada-dsl==0.7.2) (2.4.1)\n", - "Requirement already satisfied: richreports~=0.2 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nada-dsl==0.7.2) (0.2.0)\n", - "Requirement already satisfied: parsial~=0.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nada-dsl==0.7.2) (0.1.0)\n", - "Requirement already satisfied: sortedcontainers~=2.4 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nada-dsl==0.7.2) (2.4.0)\n", - "Requirement already satisfied: typing_extensions~=4.12.2 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nada-dsl==0.7.2) (4.12.2)\n", - "Requirement already satisfied: six>=1.12.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from asttokens~=2.4->nada-dsl==0.7.2) (1.17.0)\n", + "Requirement already satisfied: nada-dsl==0.7.2 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (0.7.2)\n", + "Requirement already satisfied: asttokens~=2.4 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from nada-dsl==0.7.2) (2.4.1)\n", + "Requirement already satisfied: richreports~=0.2 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from nada-dsl==0.7.2) (0.2.0)\n", + "Requirement already satisfied: parsial~=0.1 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from nada-dsl==0.7.2) (0.1.0)\n", + "Requirement already satisfied: sortedcontainers~=2.4 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from nada-dsl==0.7.2) (2.4.0)\n", + "Requirement already satisfied: typing_extensions~=4.12.2 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from nada-dsl==0.7.2) (4.12.2)\n", + "Requirement already satisfied: six>=1.12.0 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from asttokens~=2.4->nada-dsl==0.7.2) (1.17.0)\n", "Note: you may need to restart the kernel to use updated packages.\n", - "Requirement already satisfied: python-dotenv==1.0.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (1.0.0)\n", + "Requirement already satisfied: python-dotenv==1.0.0 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (1.0.0)\n", "Note: you may need to restart the kernel to use updated packages.\n", - "Requirement already satisfied: nillion_client==0.1.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (0.1.1)\n", - "Requirement already satisfied: cosmpy==0.9.2 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion_client==0.1.1) (0.9.2)\n", - "Requirement already satisfied: secp256k1==0.14.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion_client==0.1.1) (0.14.0)\n", - "Requirement already satisfied: base58==2.1.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion_client==0.1.1) (2.1.1)\n", - "Requirement already satisfied: tenacity==9.0.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion_client==0.1.1) (9.0.0)\n", - "Requirement already satisfied: nillion-client-core==0.1.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion_client==0.1.1) (0.1.1)\n", - "Requirement already satisfied: nillion-client-proto==0.1.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion_client==0.1.1) (0.1.1)\n", - "Requirement already satisfied: pyyaml==6.0.2 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion_client==0.1.1) (6.0.2)\n", - "Requirement already satisfied: bech32 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (1.2.0)\n", - "Requirement already satisfied: ecdsa in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (0.19.0)\n", - "Requirement already satisfied: googleapis-common-protos in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (1.66.0)\n", - "Requirement already satisfied: grpcio in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (1.68.1)\n", - "Requirement already satisfied: jsonschema<5,>=3.2.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (4.23.0)\n", - "Requirement already satisfied: protobuf<5.0dev,>=4.21.6 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (4.25.5)\n", - "Requirement already satisfied: pycryptodome<4.0.0,>=3.18.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (3.21.0)\n", - "Requirement already satisfied: python-dateutil in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (2.9.0.post0)\n", - "Requirement already satisfied: requests in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (2.32.3)\n", - "Requirement already satisfied: grpcio-tools==1.62.3 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion-client-proto==0.1.1->nillion_client==0.1.1) (1.62.3)\n", - "Requirement already satisfied: betterproto==2.0.0b7 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from nillion-client-proto==0.1.1->nillion_client==0.1.1) (2.0.0b7)\n", - "Requirement already satisfied: cffi>=1.3.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from secp256k1==0.14.0->nillion_client==0.1.1) (1.17.1)\n", - "Requirement already satisfied: grpclib<0.5.0,>=0.4.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (0.4.7)\n", - "Requirement already satisfied: typing-extensions<5.0.0,>=4.7.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (4.12.2)\n", - "Requirement already satisfied: setuptools in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from grpcio-tools==1.62.3->nillion-client-proto==0.1.1->nillion_client==0.1.1) (75.6.0)\n", - "Requirement already satisfied: pycparser in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cffi>=1.3.0->secp256k1==0.14.0->nillion_client==0.1.1) (2.22)\n", - "Requirement already satisfied: attrs>=22.2.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy==0.9.2->nillion_client==0.1.1) (24.3.0)\n", - "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy==0.9.2->nillion_client==0.1.1) (2024.10.1)\n", - "Requirement already satisfied: referencing>=0.28.4 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy==0.9.2->nillion_client==0.1.1) (0.35.1)\n", - "Requirement already satisfied: rpds-py>=0.7.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy==0.9.2->nillion_client==0.1.1) (0.22.3)\n", - "Requirement already satisfied: six>=1.5 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from python-dateutil->cosmpy==0.9.2->nillion_client==0.1.1) (1.17.0)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from requests->cosmpy==0.9.2->nillion_client==0.1.1) (3.4.0)\n", - "Requirement already satisfied: idna<4,>=2.5 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from requests->cosmpy==0.9.2->nillion_client==0.1.1) (3.10)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from requests->cosmpy==0.9.2->nillion_client==0.1.1) (2.2.3)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from requests->cosmpy==0.9.2->nillion_client==0.1.1) (2024.12.14)\n", - "Requirement already satisfied: h2<5,>=3.1.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from grpclib<0.5.0,>=0.4.1->betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (4.1.0)\n", - "Requirement already satisfied: multidict in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from grpclib<0.5.0,>=0.4.1->betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (6.1.0)\n", - "Requirement already satisfied: hyperframe<7,>=6.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from h2<5,>=3.1.0->grpclib<0.5.0,>=0.4.1->betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (6.0.1)\n", - "Requirement already satisfied: hpack<5,>=4.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from h2<5,>=3.1.0->grpclib<0.5.0,>=0.4.1->betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (4.0.0)\n", + "Requirement already satisfied: nillion_client==0.1.1 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (0.1.1)\n", + "Requirement already satisfied: cosmpy==0.9.2 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from nillion_client==0.1.1) (0.9.2)\n", + "Requirement already satisfied: secp256k1==0.14.0 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from nillion_client==0.1.1) (0.14.0)\n", + "Requirement already satisfied: base58==2.1.1 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from nillion_client==0.1.1) (2.1.1)\n", + "Requirement already satisfied: tenacity==9.0.0 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from nillion_client==0.1.1) (9.0.0)\n", + "Requirement already satisfied: nillion-client-core==0.1.1 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from nillion_client==0.1.1) (0.1.1)\n", + "Requirement already satisfied: nillion-client-proto==0.1.1 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from nillion_client==0.1.1) (0.1.1)\n", + "Requirement already satisfied: pyyaml==6.0.2 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from nillion_client==0.1.1) (6.0.2)\n", + "Requirement already satisfied: bech32 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (1.2.0)\n", + "Requirement already satisfied: ecdsa in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (0.19.0)\n", + "Requirement already satisfied: googleapis-common-protos in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (1.66.0)\n", + "Requirement already satisfied: grpcio in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (1.68.1)\n", + "Requirement already satisfied: jsonschema<5,>=3.2.0 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (4.23.0)\n", + "Requirement already satisfied: protobuf<5.0dev,>=4.21.6 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (4.25.5)\n", + "Requirement already satisfied: pycryptodome<4.0.0,>=3.18.0 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (3.21.0)\n", + "Requirement already satisfied: python-dateutil in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (2.9.0.post0)\n", + "Requirement already satisfied: requests in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from cosmpy==0.9.2->nillion_client==0.1.1) (2.32.3)\n", + "Requirement already satisfied: grpcio-tools==1.62.3 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from nillion-client-proto==0.1.1->nillion_client==0.1.1) (1.62.3)\n", + "Requirement already satisfied: betterproto==2.0.0b7 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from nillion-client-proto==0.1.1->nillion_client==0.1.1) (2.0.0b7)\n", + "Requirement already satisfied: cffi>=1.3.0 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from secp256k1==0.14.0->nillion_client==0.1.1) (1.17.1)\n", + "Requirement already satisfied: grpclib<0.5.0,>=0.4.1 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (0.4.7)\n", + "Requirement already satisfied: typing-extensions<5.0.0,>=4.7.1 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (4.12.2)\n", + "Requirement already satisfied: setuptools in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from grpcio-tools==1.62.3->nillion-client-proto==0.1.1->nillion_client==0.1.1) (75.6.0)\n", + "Requirement already satisfied: pycparser in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from cffi>=1.3.0->secp256k1==0.14.0->nillion_client==0.1.1) (2.22)\n", + "Requirement already satisfied: attrs>=22.2.0 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy==0.9.2->nillion_client==0.1.1) (24.3.0)\n", + "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy==0.9.2->nillion_client==0.1.1) (2024.10.1)\n", + "Requirement already satisfied: referencing>=0.28.4 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy==0.9.2->nillion_client==0.1.1) (0.35.1)\n", + "Requirement already satisfied: rpds-py>=0.7.1 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from jsonschema<5,>=3.2.0->cosmpy==0.9.2->nillion_client==0.1.1) (0.22.3)\n", + "Requirement already satisfied: six>=1.5 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from python-dateutil->cosmpy==0.9.2->nillion_client==0.1.1) (1.17.0)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from requests->cosmpy==0.9.2->nillion_client==0.1.1) (3.4.0)\n", + "Requirement already satisfied: idna<4,>=2.5 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from requests->cosmpy==0.9.2->nillion_client==0.1.1) (3.10)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from requests->cosmpy==0.9.2->nillion_client==0.1.1) (2.2.3)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from requests->cosmpy==0.9.2->nillion_client==0.1.1) (2024.12.14)\n", + "Requirement already satisfied: h2<5,>=3.1.0 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from grpclib<0.5.0,>=0.4.1->betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (4.1.0)\n", + "Requirement already satisfied: multidict in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from grpclib<0.5.0,>=0.4.1->betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (6.1.0)\n", + "Requirement already satisfied: hyperframe<7,>=6.0 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from h2<5,>=3.1.0->grpclib<0.5.0,>=0.4.1->betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (6.0.1)\n", + "Requirement already satisfied: hpack<5,>=4.0 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from h2<5,>=3.1.0->grpclib<0.5.0,>=0.4.1->betterproto==2.0.0b7->nillion-client-proto==0.1.1->nillion_client==0.1.1) (4.0.0)\n", "Note: you may need to restart the kernel to use updated packages.\n", - "Requirement already satisfied: cryptography==44.0.0 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (44.0.0)\n", - "Requirement already satisfied: cffi>=1.12 in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cryptography==44.0.0) (1.17.1)\n", - "Requirement already satisfied: pycparser in /home/hello/.pyenv/versions/3.12.8/lib/python3.12/site-packages (from cffi>=1.12->cryptography==44.0.0) (2.22)\n", + "Requirement already satisfied: cryptography==44.0.0 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (44.0.0)\n", + "Requirement already satisfied: cffi>=1.12 in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from cryptography==44.0.0) (1.17.1)\n", + "Requirement already satisfied: pycparser in /home/hello/Projects/MonadicDNA/.venv/lib/python3.12/site-packages (from cffi>=1.12->cryptography==44.0.0) (2.22)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } @@ -111,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:05.762189Z", @@ -142,7 +142,8 @@ "from nillion_client.ids import UUID\n", "from nillion_client.payer import DummyPayer\n", "from nillion_client.permissions import (ComputePermissionCommand, ComputePermissions,ComputePermission)\n", - "import hashlib" + "import hashlib\n", + "from ecdsa import SigningKey, SECP256k1" ] }, { @@ -156,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:08.870617Z", @@ -217,7 +218,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:12.833625Z", @@ -229,32 +230,56 @@ "name": "stdout", "output_type": "stream", "text": [ - "Cluster ID: 9e68173f-9c23-4acc-ba81-4f079b639964\n", - "Chain ID: nillion-chain-devnet\n", - "GRPC Endpoint: http://localhost:26649\n" + "Chain ID: nillion-chain-testnet-1\n", + "GRPC Endpoint: https://node-1.nucleus2.nillion-network.nilogy.xyz:14311\n" ] }, { "data": { "text/plain": [ - "Network(chain_id='nillion-chain-devnet', chain_grpc_endpoint='http://localhost:26649', nilvm_grpc_endpoint='http://127.0.0.1:37939')" + "Network(chain_id='nillion-chain-testnet-1', chain_grpc_endpoint='https://testnet-nillion-grpc.lavenderfive.com', nilvm_grpc_endpoint='https://node-1.nucleus2.nillion-network.nilogy.xyz:14311')" ] }, - "execution_count": 3, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "cluster_id = os.getenv('NILLION_CLUSTER_ID')\n", - "chain_id = os.getenv('NILLION_NILCHAIN_CHAIN_ID')\n", - "grpc_endpoint = os.getenv('NILLION_NILCHAIN_GRPC')\n", - "\n", - "print(f\"Cluster ID: {cluster_id}\")\n", + "use_testnet = False\n", + "\n", + "if not use_testnet:\n", + " cluster_id = os.getenv('NILLION_CLUSTER_ID')\n", + " chain_id = os.getenv('NILLION_NILCHAIN_CHAIN_ID')\n", + " nilvm_grpc_endpoint = os.getenv('NILLION_NILCHAIN_GRPC')\n", + " payer_userkey_hex:str = os.getenv(\"NILLION_NILCHAIN_PRIVATE_KEY_0\")\n", + " monadic_seed = \"monadic_seed\"\n", + " monadic_userkey_hex = hashlib.sha256(monadic_seed.encode()).digest().hex()\n", + " snipper_seed = \"snipper_seed\"\n", + " snipper_userkey_hex = hashlib.sha256(snipper_seed.encode()).digest().hex()\n", + " patient_seed = \"patient_seed\"\n", + " patient_userkey_hex = hashlib.sha256(patient_seed.encode()).digest().hex()\n", + " network:Network = Network.from_config(\"devnet\")\n", + "else:\n", + " chain_id = \"nillion-chain-testnet-1\"\n", + " chain_grpc_endpoint = \"https://testnet-nillion-grpc.lavenderfive.com\"\n", + " nilvm_grpc_endpoint = \"https://node-1.nucleus2.nillion-network.nilogy.xyz:14311\"\n", + " payer_userkey_hex = \"11112217e1ba614ee927fdc38a31b686c7b56976aa92451e89f769b518416112\"\n", + " monadic_seed = \"monadic_seed\"\n", + " monadic_userkey_hex = hashlib.sha256(monadic_seed.encode()).digest().hex()\n", + " snipper_seed = \"snipper_seed\"\n", + " snipper_userkey_hex = hashlib.sha256(snipper_seed.encode()).digest().hex()\n", + " patient_seed = \"patient_seed\"\n", + " patient_userkey_hex = hashlib.sha256(patient_seed.encode()).digest().hex()\n", + " network:Network = Network(\n", + " chain_grpc_endpoint=chain_grpc_endpoint,\n", + " chain_id=chain_id,\n", + " nilvm_grpc_endpoint=nilvm_grpc_endpoint \n", + " )\n", + " \n", "print(f\"Chain ID: {chain_id}\")\n", - "print(f\"GRPC Endpoint: {grpc_endpoint}\")\n", + "print(f\"GRPC Endpoint: {nilvm_grpc_endpoint}\")\n", "\n", - "network = Network.from_config(\"devnet\")\n", "network" ] }, @@ -267,7 +292,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:19.828183Z", @@ -276,10 +301,13 @@ }, "outputs": [], "source": [ - "monadic_seed = \"monadic_seed\"\n", - "monadic_userkey = PrivateKey(hashlib.sha256(monadic_seed.encode()).digest())\n", - "monadic_payer = DummyPayer()\n", - "monadic_client = await VmClient.create(monadic_userkey, network, monadic_payer)\n", + "monadic_userkey = NilChainPrivateKey(bytes.fromhex(monadic_userkey_hex))\n", + "monadic_payer = NilChainPayer(\n", + " network,\n", + " wallet_private_key=monadic_userkey,\n", + " gas_limit=1000,\n", + ")\n", + "monadic_client = await VmClient.create(PrivateKey(bytes.fromhex(monadic_userkey_hex)), network, monadic_payer)\n", "monadic_user_id = monadic_client.user_id" ] }, @@ -292,7 +320,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:22.512975Z", @@ -301,10 +329,13 @@ }, "outputs": [], "source": [ - "snipper_seed = \"snipper_seed\"\n", - "snipper_userkey = PrivateKey(hashlib.sha256(snipper_seed.encode()).digest())\n", - "snipper_payer = DummyPayer()\n", - "snipper_client = await VmClient.create(snipper_userkey, network, snipper_payer)\n", + "snipper_userkey = NilChainPrivateKey(bytes.fromhex(snipper_userkey_hex))\n", + "snipper_payer = NilChainPayer(\n", + " network,\n", + " wallet_private_key=snipper_userkey,\n", + " gas_limit=1000,\n", + ")\n", + "snipper_client = await VmClient.create(PrivateKey(bytes.fromhex(snipper_userkey_hex)), network, snipper_payer)\n", "snipper_user_id = snipper_client.user_id" ] }, @@ -317,7 +348,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:28.760101Z", @@ -326,10 +357,13 @@ }, "outputs": [], "source": [ - "patient_seed = \"patient_seed\"\n", - "patient_userkey = PrivateKey(hashlib.sha256(patient_seed.encode()).digest())\n", - "patient_payer = DummyPayer()\n", - "patient_client = await VmClient.create(patient_userkey, network, patient_payer)\n", + "patient_userkey = NilChainPrivateKey(bytes.fromhex(patient_userkey_hex))\n", + "patient_payer = NilChainPayer(\n", + " network,\n", + " wallet_private_key=patient_userkey,\n", + " gas_limit=1000,\n", + ")\n", + "patient_client = await VmClient.create(PrivateKey(bytes.fromhex(patient_userkey_hex)), network, patient_payer)\n", "patient_user_id = patient_client.user_id" ] }, @@ -342,7 +376,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:31.282228Z", @@ -352,18 +386,15 @@ }, "outputs": [], "source": [ - "nilchain_key: str = os.getenv(\"NILLION_NILCHAIN_PRIVATE_KEY_0\") # type: ignore\n", + "payer_privKey = NilChainPrivateKey(bytes.fromhex(payer_userkey_hex))\n", + "\n", "payer = NilChainPayer(\n", " network,\n", - " wallet_private_key=NilChainPrivateKey(bytes.fromhex(nilchain_key)),\n", + " wallet_private_key=payer_privKey,\n", " gas_limit=10000000,\n", ")\n", - "\n", - "payer_seed=\"payer_seed\"\n", - "\n", "# We will identify ourselves with the pre-configured private key\n", - "signing_key = PrivateKey(hashlib.sha256(payer_seed.encode()).digest())\n", - "payer_client= await VmClient.create(signing_key, network, payer)" + "payer_client= await VmClient.create(PrivateKey(bytes.fromhex(payer_userkey_hex)), network, payer)" ] }, { @@ -375,24 +406,39 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "💰 Adding some funds to the executor client balance: 100000 uNIL\n" + "💰 Current Payer Balance: 500000 uNIL\n", + "💰 Current Patient Balance: 496598 uNIL\n", + "💰 Current monadic Balance: 500000 uNIL\n", + "💰 Current sniper Balance: 500000 uNIL\n" ] } ], "source": [ - "funds_amount = 100000\n", - "print(f\"💰 Adding some funds to the executor client balance: {funds_amount} uNIL\")\n", - "await payer_client.add_funds(funds_amount)\n", - "await payer_client.add_funds(funds_amount, target_user=patient_user_id)\n", - "await payer_client.add_funds(funds_amount, target_user=monadic_user_id)\n", - "await payer_client.add_funds(funds_amount, target_user=snipper_user_id)" + "funds_amount = 500000\n", + "bal = await payer_client.balance()\n", + "print(f\"💰 Current Payer Balance: {bal.balance} uNIL\")\n", + "if bal.balance < 400000:\n", + " print(f\"💰 Adding some funds to the executor client balance: {bal.balance} uNIL\")\n", + " await payer_client.add_funds(funds_amount)\n", + "bal = await patient_client.balance()\n", + "print(f\"💰 Current Patient Balance: {bal.balance} uNIL\")\n", + "if bal.balance < 400000:\n", + " await payer_client.add_funds(500000, target_user=patient_user_id)\n", + "bal = await monadic_client.balance()\n", + "print(f\"💰 Current monadic Balance: {bal.balance} uNIL\")\n", + "if bal.balance < 400000:\n", + " await payer_client.add_funds(500000, target_user=monadic_user_id)\n", + "bal = await snipper_client.balance()\n", + "print(f\"💰 Current sniper Balance: {bal.balance} uNIL\")\n", + "if bal.balance < 400000:\n", + " await payer_client.add_funds(500000, target_user=snipper_user_id)\n" ] }, { @@ -404,7 +450,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -422,7 +468,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:41.524938Z", @@ -438,10 +484,10 @@ "Program ID: 4b367ad186fa672387ca7fb6ea9f75c13cc53a82/double/sha256/35f9b61f28b8e9aafbc987766f6ff549892aafe1d65256aa6feec84b1f5b6bf0\n", "The patient is storing a secret on the network\n", "The patient is running the program on the secret..\n", - "The computation was sent to the network. compute_id: 2b348f6c-260b-4626-8839-dab228c51f66\n", - "✅ Compute complete for compute_id 2b348f6c-260b-4626-8839-dab228c51f66\n", + "The computation was sent to the network. compute_id: e52ecb8b-26c5-4d49-9737-c12ec934ee1d\n", + "✅ Compute complete for compute_id e52ecb8b-26c5-4d49-9737-c12ec934ee1d\n", "🖥️ The result is {'my_output': SecretInteger(4)}\n", - "💰 Final client balance: 99514 uNIL\n" + "💰 Final client balance: 496112 uNIL\n" ] } ], @@ -511,7 +557,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 16, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:49.395066Z", @@ -554,7 +600,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 17, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:54.210051Z", @@ -593,7 +639,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:59.264419Z", @@ -605,10 +651,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "The computation was sent to the network. compute_id: b4f84bd0-0317-42b3-8376-8e02675a8733\n", - "✅ Compute complete for compute_id b4f84bd0-0317-42b3-8376-8e02675a8733\n", + "The computation was sent to the network. compute_id: c5d48389-c300-41a2-99d1-202788f3ecb8\n", + "✅ Compute complete for compute_id c5d48389-c300-41a2-99d1-202788f3ecb8\n", "🖥️ The result is {'my_output': SecretInteger(4)}\n", - "💰 Final client balance: 99991 uNIL\n" + "💰 Final client balance: 499995 uNIL\n" ] } ], @@ -651,7 +697,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -685,7 +731,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 20, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:41:25.749809Z", @@ -697,10 +743,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "The computation was sent to the network. compute_id: 117e212e-97a7-4481-ad61-07d277468115\n", - "✅ Compute complete for compute_id 117e212e-97a7-4481-ad61-07d277468115\n", + "The computation was sent to the network. compute_id: b93f96e7-45d0-4e74-92a0-cc4d547cc321\n", + "✅ Compute complete for compute_id b93f96e7-45d0-4e74-92a0-cc4d547cc321\n", "🖥️ The result is {'my_output': SecretInteger(4)}\n", - "💰 Final client balance: 99988 uNIL\n" + "💰 Final client balance: 499996 uNIL\n" ] } ], From d7d72f75628745b19c7f214088ef9cde5809d306 Mon Sep 17 00:00:00 2001 From: gdsoumya Date: Fri, 17 Jan 2025 13:14:47 +0530 Subject: [PATCH 4/5] feat: update nillion interactor to use latest packages and nucleus2 testnet Signed-off-by: gdsoumya --- services/nillion-interactor/.env | 42 +++-- .../nillion-interactor/E2E_Nillion_Test.ipynb | 9 +- services/nillion-interactor/app.py | 178 +++++++++++------- .../helpers/nillion_client_helper.py | 27 +-- .../helpers/nillion_keypath_helper.py | 8 - .../helpers/nillion_payments_helper.py | 11 -- services/nillion-interactor/node.key | 1 - services/nillion-interactor/user.key | 1 - 8 files changed, 157 insertions(+), 120 deletions(-) delete mode 100644 services/nillion-interactor/helpers/nillion_keypath_helper.py delete mode 100644 services/nillion-interactor/helpers/nillion_payments_helper.py delete mode 100644 services/nillion-interactor/node.key delete mode 100644 services/nillion-interactor/user.key diff --git a/services/nillion-interactor/.env b/services/nillion-interactor/.env index 7c1287a..4da14b6 100644 --- a/services/nillion-interactor/.env +++ b/services/nillion-interactor/.env @@ -1,17 +1,25 @@ -NILLION_BOOTNODE_MULTIADDRESS=/ip4/127.0.0.1/tcp/37939/p2p/12D3KooWMvw1hEqm7EWSDEyqTb6pNetUVkepahKY6hixuAuMZfJS -NILLION_CLUSTER_ID=9e68173f-9c23-4acc-ba81-4f079b639964 -NILLION_USERKEY_PATH_PARTY_1=/Users/vishakh/dev/MonadicDNA/services/nillion-interactor/user.key -NILLION_USERKEY_PATH_PARTY_2= -NILLION_USERKEY_PATH_PARTY_3= -NILLION_USERKEY_PATH_PARTY_4= -NILLION_USERKEY_PATH_PARTY_5= -NILLION_NODEKEY_PATH_PARTY_1=/Users/vishakh/dev/MonadicDNA/services/nillion-interactor/node.key -NILLION_NODEKEY_PATH_PARTY_2= -NILLION_NODEKEY_PATH_PARTY_3= -NILLION_NODEKEY_PATH_PARTY_4= -NILLION_NODEKEY_PATH_PARTY_5= -NILLION_BLOCKCHAIN_RPC_ENDPOINT=http://localhost:61391 -NILLION_CHAIN_ID=31337 -NILLION_PAYMENTS_SC_ADDRESS=5fc8d32690cc91d4c39d9d3abcbd16989f875707 -NILLION_BLINDING_FACTORS_MANAGER_SC_ADDRESS=a513e6e4b8f2a923d98304ec87f64353c4d5c853 -NILLION_WALLET_PRIVATE_KEY=df57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e \ No newline at end of file +# NILLION_BOOTNODE_MULTIADDRESS=/ip4/127.0.0.1/tcp/37939/p2p/12D3KooWMvw1hEqm7EWSDEyqTb6pNetUVkepahKY6hixuAuMZfJS +# NILLION_CLUSTER_ID=9e68173f-9c23-4acc-ba81-4f079b639964 +# NILLION_USERKEY_PATH_PARTY_1=/Users/vishakh/dev/MonadicDNA/services/nillion-interactor/user.key +# NILLION_USERKEY_PATH_PARTY_2= +# NILLION_USERKEY_PATH_PARTY_3= +# NILLION_USERKEY_PATH_PARTY_4= +# NILLION_USERKEY_PATH_PARTY_5= +# NILLION_NODEKEY_PATH_PARTY_1=/Users/vishakh/dev/MonadicDNA/services/nillion-interactor/node.key +# NILLION_NODEKEY_PATH_PARTY_2= +# NILLION_NODEKEY_PATH_PARTY_3= +# NILLION_NODEKEY_PATH_PARTY_4= +# NILLION_NODEKEY_PATH_PARTY_5= +# NILLION_BLOCKCHAIN_RPC_ENDPOINT=http://localhost:61391 +# NILLION_CHAIN_ID=31337 +# NILLION_PAYMENTS_SC_ADDRESS=5fc8d32690cc91d4c39d9d3abcbd16989f875707 +# NILLION_BLINDING_FACTORS_MANAGER_SC_ADDRESS=a513e6e4b8f2a923d98304ec87f64353c4d5c853 +# NILLION_WALLET_PRIVATE_KEY=df57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e + +# Nucleus 2 testet setup +MONADIC_PRIVKEY=11112217e1ba614ee927fdc38a31b686c7b56976aa92451e89f769b518416112 +SNIPPER_BOT_PRIVKEY=c653318e9a92e3d8a5fd536f6c3324047b85d294c48b2fdaa8e861b8bd53a3d1 +NILLION_BLOCKCHAIN_RPC_ENDPOINT=https://testnet-nillion-grpc.lavenderfive.com +NILLION_BOOTNODE_MULTIADDRESS=https://node-1.nucleus2.nillion-network.nilogy.xyz:14311 +NILLION_CHAIN_ID=nillion-chain-testnet-1 +THROMBOSIS_PROGRAM_ID=8557268d73e95608764ed372665ce53ec16c5c2b/thrombosis/sha256/1b40f8cf92763b3a19c55a272203e367d2204ad0d2f78c8f1d046afc3147b6b5 \ No newline at end of file diff --git a/services/nillion-interactor/E2E_Nillion_Test.ipynb b/services/nillion-interactor/E2E_Nillion_Test.ipynb index 8935f00..c25937b 100644 --- a/services/nillion-interactor/E2E_Nillion_Test.ipynb +++ b/services/nillion-interactor/E2E_Nillion_Test.ipynb @@ -111,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:05.762189Z", @@ -157,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:08.870617Z", @@ -218,7 +218,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2024-08-09T23:28:12.833625Z", @@ -230,6 +230,7 @@ "name": "stdout", "output_type": "stream", "text": [ + "c653318e9a92e3d8a5fd536f6c3324047b85d294c48b2fdaa8e861b8bd53a3d1\n", "Chain ID: nillion-chain-testnet-1\n", "GRPC Endpoint: https://node-1.nucleus2.nillion-network.nilogy.xyz:14311\n" ] @@ -240,7 +241,7 @@ "Network(chain_id='nillion-chain-testnet-1', chain_grpc_endpoint='https://testnet-nillion-grpc.lavenderfive.com', nilvm_grpc_endpoint='https://node-1.nucleus2.nillion-network.nilogy.xyz:14311')" ] }, - "execution_count": 8, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } diff --git a/services/nillion-interactor/app.py b/services/nillion-interactor/app.py index 988db04..7360775 100644 --- a/services/nillion-interactor/app.py +++ b/services/nillion-interactor/app.py @@ -1,25 +1,23 @@ -import asyncio -from flask import Flask, request, jsonify -from flask_cors import CORS +from quart import Quart, request, jsonify +from quart_cors import cors import os -import py_nillion_client as nillion import sys -import werkzeug -import socket import random import string +from uuid import UUID from dotenv import load_dotenv +from nillion_client import (VmClient, UserId, InputPartyBinding, OutputPartyBinding, SecretInteger, Permissions) + sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from helpers.nillion_client_helper import create_nillion_client -from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile load_dotenv() -app = Flask(__name__) -CORS(app, resources={r"/*": {"origins": "*"}}) +app = Quart(__name__) +app = cors(app, allow_origin="*") def get_random_node_key(): # hostname = socket.gethostname() @@ -30,9 +28,35 @@ def get_random_node_key(): print("Node key: ", result) return result -_userkey = getUserKeyFromFile(os.getenv("NILLION_USERKEY_PATH_PARTY_1")) -_nodekey = nillion.NodeKey.from_seed(get_random_node_key()) -_client = create_nillion_client(_userkey, _nodekey) +_keys = { + "monadic" : bytes.fromhex(os.getenv("MONADIC_PRIVKEY")), + "snipperBot" : bytes.fromhex(os.getenv("SNIPPER_BOT_PRIVKEY")) +} +_clients:dict[str, VmClient] = None + +_default_client = "monadic" + +_program_id = os.getenv("THROMBOSIS_PROGRAM_ID") + +async def initialize_client(): + global _clients, _program_id + if _clients is None: + _clients = {} + print("initializing clients") + for key in _keys : + _clients[key] = await create_nillion_client(_keys[key]) + print("done initializing clients") + if _program_id == '' or _program_id is None: + print("uploading thrombosis program") + _program_id = await upload_thrombosis_program() + print("thrombosis program uploaded, id "+_program_id) + +async def upload_thrombosis_program(): + program_name = "thrombosis" + program_mir_path = f"binaries/thrombosis.nada.bin" + program = open(program_mir_path, "rb").read() + return await _clients[_default_client].store_program(program_name, program,).invoke() + def read_and_filter_23andme(file_storage): # Define the SNPs of interest and their deterministic integer values @@ -70,17 +94,10 @@ def read_and_filter_23andme(file_storage): return results async def store_on_nillion(gene_data): - cluster_id = os.getenv("NILLION_CLUSTER_ID") - party_id = _client.party_id() - user_id = _client.user_id() - party_name = "Party1" - - program_name = "thrombosis" - program_mir_path = f"binaries/thrombosis.nada.bin" - program_id = f"{user_id}/{program_name}" - - secret_bindings = nillion.ProgramBindings(program_id) - secret_bindings.add_input_party(party_name, party_id) + # Set permissions for the client to compute on the program + permissions = Permissions.defaults_for_user(_clients[_default_client].user_id).allow_compute( + _clients[_default_client].user_id, _program_id + ) store_ids = {} @@ -88,79 +105,110 @@ async def store_on_nillion(gene_data): rsid = row['rsid'] rsid_int = row['rsid_int'] genotype_int = row['genotype_int'] - stored_secret = nillion.Secrets({ - "snp": nillion.SecretInteger(6), - "genotype": nillion.SecretInteger(9), - }) - store_id = await _client.store_secrets( - cluster_id, secret_bindings, stored_secret, None - ) + stored_secret = { + "snp": SecretInteger(rsid_int), + "genotype": SecretInteger(genotype_int), + } + store_id = await _clients[_default_client].store_values( + values=stored_secret, ttl_days=5, permissions=permissions + ).invoke() + store_ids[rsid] = store_id return store_ids -async def compute_on_nillion(store_id): - cluster_id = os.getenv("NILLION_CLUSTER_ID") - party_id = _client.party_id() - user_id = _client.user_id() - party_name = "Party1" - program_name = "thrombosis" - program_mir_path = f"binaries/thrombosis.nada.bin" +async def compute_on_nillion(client_id, store_id): - program_id = f"{user_id}/{program_name}" + party_name = "Party1" - compute_bindings = nillion.ProgramBindings(program_id) - compute_bindings.add_input_party(party_name, party_id) - compute_bindings.add_output_party(party_name, party_id) + input_bindings = [InputPartyBinding(party_name, _clients[client_id].user_id)] + output_bindings = [OutputPartyBinding(party_name, [_clients[client_id].user_id])] - computation_time_secrets = nillion.Secrets({}) + computation_time_secrets = {} # Compute on the secret - compute_id = await _client.compute( - cluster_id, - compute_bindings, - [store_id], - computation_time_secrets, - nillion.PublicVariables({}), - ) + compute_id = await _clients[client_id].compute( + _program_id, + input_bindings, + output_bindings, + values=computation_time_secrets, + value_ids=[UUID(f"urn:uuid:{store_id}")] + ).invoke() # Print compute result print(f"The computation was sent to the network. compute_id: {compute_id}") - while True: - compute_event = await _client.next_compute_event() - if isinstance(compute_event, nillion.ComputeFinishedEvent): - print(f"✅ Compute complete for compute_id {compute_event.uuid}") - print(f"🖥️ The result is {compute_event.result.value}") - return compute_event.result.value - + result = await _clients[client_id].retrieve_compute_results(compute_id).invoke() + return result['Result'].value + +async def fund_user(user_id): + try: + uid = UserId.parse(user_id) + except Exception: + return "Invalid UserID" + try: + await _clients[_default_client].add_funds(500000, target_user=uid) + except Exception: + return "Failed to add funds" @app.route('/dataset', methods=['PUT']) async def handle_dataset(): - if 'file' not in request.files: + files = await request.files + if 'file' not in files : return jsonify({'error': 'No file part'}), 400 - file = request.files['file'] + file = files['file'] if file.filename == '': return jsonify({'error': 'No selected file'}), 400 if file: - filtered_data = read_and_filter_23andme(file) - results = await asyncio.wait_for(store_on_nillion(filtered_data), timeout=120) - return jsonify(results) + try: + filtered_data = read_and_filter_23andme(file) + results = await store_on_nillion(filtered_data) + return jsonify(results) + except Exception as e: + print(e) + return jsonify({'error': 'internal error'}), 500 return jsonify({'error': 'File processing failed'}), 500 @app.route('/computations/thrombosis', methods=['POST']) async def thrombosis(): - store_id = request.json.get('store_id') - + store_id = (await request.json).get('store_id') if store_id is None: return jsonify({'error': 'Missing store_id'}), 400 - - result = await asyncio.wait_for(compute_on_nillion(store_id), timeout=120) + client_id = (await request.json).get('client_id') + if client_id is None: + client_id = _default_client + elif client_id not in _clients: + return jsonify({'error': 'Invalid client_id'}), 400 + try: + result = await compute_on_nillion(client_id, store_id) + except Exception as e: + print(e) + return jsonify({'error': 'internal error'}), 500 return jsonify(result) +@app.route('/fund', methods=['POST']) +async def fund(): + user_id = (await request.json).get('user_id') + if user_id is None: + return jsonify({'error': 'Missing user_id'}), 400 + try: + result = await fund_user(user_id) + if result.__contains__("Invalid UserID"): + return jsonify({'error': result}), 400 + elif result.__ne__(""): + return jsonify({'error': result}), 500 + except Exception as e: + print(e) + return jsonify({'error': 'internal error'}), 500 + return jsonify({'message': f"funded {user_id}"}) + @app.route('/') def hello_world(): return "Hello, world!" +@app.before_serving +async def startup(): + await initialize_client() + if __name__ == '__main__': app.run(host='0.0.0.0', debug=True, port=8732) diff --git a/services/nillion-interactor/helpers/nillion_client_helper.py b/services/nillion-interactor/helpers/nillion_client_helper.py index 838817b..f1c6038 100644 --- a/services/nillion-interactor/helpers/nillion_client_helper.py +++ b/services/nillion-interactor/helpers/nillion_client_helper.py @@ -1,15 +1,16 @@ import os -import py_nillion_client as nillion -from helpers.nillion_payments_helper import create_payments_config +from nillion_client import (Network, NilChainPrivateKey, NilChainPayer, PrivateKey, VmClient) -def create_nillion_client(userkey, nodekey): - bootnodes = [os.getenv("NILLION_BOOTNODE_MULTIADDRESS")] - payments_config = create_payments_config() - - return nillion.NillionClient( - nodekey, - bootnodes, - nillion.ConnectionMode.relay(), - userkey, - payments_config, - ) \ No newline at end of file +async def create_nillion_client(priv_key): + network = Network( + chain_grpc_endpoint=os.getenv("NILLION_BLOCKCHAIN_RPC_ENDPOINT"), + chain_id=os.getenv("NILLION_CHAIN_ID"), + nilvm_grpc_endpoint=os.getenv("NILLION_BOOTNODE_MULTIADDRESS"), + ) + wallet_private_key=NilChainPrivateKey(priv_key) + payer = NilChainPayer( + network, + wallet_private_key=wallet_private_key, + gas_limit=10000000, + ) + return await VmClient.create(PrivateKey(priv_key), network, payer) \ No newline at end of file diff --git a/services/nillion-interactor/helpers/nillion_keypath_helper.py b/services/nillion-interactor/helpers/nillion_keypath_helper.py deleted file mode 100644 index 254f1ba..0000000 --- a/services/nillion-interactor/helpers/nillion_keypath_helper.py +++ /dev/null @@ -1,8 +0,0 @@ -import os -import py_nillion_client as nillion - -def getUserKeyFromFile(userkey_filepath): - return nillion.UserKey.from_file(userkey_filepath) - -def getNodeKeyFromFile(nodekey_filepath): - return nillion.NodeKey.from_file(nodekey_filepath) \ No newline at end of file diff --git a/services/nillion-interactor/helpers/nillion_payments_helper.py b/services/nillion-interactor/helpers/nillion_payments_helper.py deleted file mode 100644 index 858801e..0000000 --- a/services/nillion-interactor/helpers/nillion_payments_helper.py +++ /dev/null @@ -1,11 +0,0 @@ -import os -import py_nillion_client as nillion - -def create_payments_config(): - return nillion.PaymentsConfig( - os.getenv("NILLION_BLOCKCHAIN_RPC_ENDPOINT"), - os.getenv("NILLION_WALLET_PRIVATE_KEY"), - int(os.getenv("NILLION_CHAIN_ID")), - os.getenv("NILLION_PAYMENTS_SC_ADDRESS"), - os.getenv("NILLION_BLINDING_FACTORS_MANAGER_SC_ADDRESS"), - ) \ No newline at end of file diff --git a/services/nillion-interactor/node.key b/services/nillion-interactor/node.key deleted file mode 100644 index 3086408..0000000 --- a/services/nillion-interactor/node.key +++ /dev/null @@ -1 +0,0 @@ -23jhTewVfpjnWDH2XjxmtwgcQSG4F34Je6Ryoh7AmV4N4ga6FZwiPpPA6h75MoFgFZ8k434fpBAz3MdoMD82GE7JxgJm6 \ No newline at end of file diff --git a/services/nillion-interactor/user.key b/services/nillion-interactor/user.key deleted file mode 100644 index 6b90760..0000000 --- a/services/nillion-interactor/user.key +++ /dev/null @@ -1 +0,0 @@ -2qNbL7BPz2Nd9F2cDR7DS3xVSwFk3NN5A6YCHdjRUvdn \ No newline at end of file From aa471fbf4ec9b5cd936e43a3b08a515129946e63 Mon Sep 17 00:00:00 2001 From: gdsoumya Date: Fri, 17 Jan 2025 13:19:45 +0530 Subject: [PATCH 5/5] feat: update requirements Signed-off-by: gdsoumya --- services/nillion-interactor/requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/nillion-interactor/requirements.txt b/services/nillion-interactor/requirements.txt index a658411..3dff825 100644 --- a/services/nillion-interactor/requirements.txt +++ b/services/nillion-interactor/requirements.txt @@ -1,7 +1,7 @@ python-dotenv==1.0.0 pytest-asyncio>=0.23.6 -Flask[async]==3.0.3 -flask-cors==4.0.0 +Quart==0.20.0 +quart-cors==0.8.0 cryptography>=44.0.0 nillion-client==0.1.1 nada-dsl==0.7.2 \ No newline at end of file