From 929ee55c9789c4cb7aa622d1248b78bb9d720c18 Mon Sep 17 00:00:00 2001 From: David Kazlauskas Date: Thu, 5 Sep 2024 09:03:02 +0300 Subject: [PATCH] Publish docker image, fixes for tests of 128/160/256 bit numbers --- .dockerignore | 2 + .github/workflows/publish-image.yml | 69 ++++++ ...90045f2fb25c9ef20ecd96ecf9ca8203f89b7.json | 46 ++++ ...6ed7a4da52492956bde5e6bc7c7505fb7d22d.json | 17 ++ ...a5a33b30ce93fd4122dbd94cab6d9309358c0.json | 18 ++ ...197061136444e3a6f86ce6679b3e42048f337.json | 18 ++ ...8ec9064d5ac5d655efa8aa0927cb7b23bddba.json | 28 +++ ...e8d6b4db9d9309cae6810b4830188ea97088e.json | 41 ++++ ...5e614a9d71b97e5bdd8118f4d7d986a48aeb5.json | 22 ++ ...1f08ee5761187a24d6897391e7c9b82386d27.json | 29 +++ ...ff622e857564cba1193edc4837d604c322b7e.json | 34 +++ ...c6b4fd16cebdcd07cfa14f55cf7dd61c910e6.json | 18 ++ ...ea13ddc3d6994256df2385ca0013178fe5680.json | 20 ++ ...a5989ff4b597f46136bbf5e90c564057e20a1.json | 19 ++ ...8c17d9acc17e159696dbbb943ca8fc26f583a.json | 36 +++ ...9357549bca862b75891a887c86d7e50e24e66.json | 15 ++ ...110baa4dae151e8118da3cc58654f46123f97.json | 12 + ...cdf1a7f8a5c436422f0334382da23505832a7.json | 22 ++ ...5bb467e4c6322c6317269f64351775549cc3b.json | 16 ++ fhevm-engine/Cargo.lock | 7 + fhevm-engine/Cargo.toml | 2 + ...90045f2fb25c9ef20ecd96ecf9ca8203f89b7.json | 46 ++++ ...6ed7a4da52492956bde5e6bc7c7505fb7d22d.json | 17 ++ ...a5a33b30ce93fd4122dbd94cab6d9309358c0.json | 18 ++ ...197061136444e3a6f86ce6679b3e42048f337.json | 18 ++ ...8ec9064d5ac5d655efa8aa0927cb7b23bddba.json | 28 +++ ...e8d6b4db9d9309cae6810b4830188ea97088e.json | 41 ++++ ...5e614a9d71b97e5bdd8118f4d7d986a48aeb5.json | 22 ++ ...1f08ee5761187a24d6897391e7c9b82386d27.json | 29 +++ ...ff622e857564cba1193edc4837d604c322b7e.json | 34 +++ ...c6b4fd16cebdcd07cfa14f55cf7dd61c910e6.json | 18 ++ ...ea13ddc3d6994256df2385ca0013178fe5680.json | 20 ++ ...a5989ff4b597f46136bbf5e90c564057e20a1.json | 19 ++ ...8c17d9acc17e159696dbbb943ca8fc26f583a.json | 36 +++ ...9357549bca862b75891a887c86d7e50e24e66.json | 15 ++ ...110baa4dae151e8118da3cc58654f46123f97.json | 12 + ...cdf1a7f8a5c436422f0334382da23505832a7.json | 22 ++ ...5bb467e4c6322c6317269f64351775549cc3b.json | 16 ++ fhevm-engine/coprocessor/Cargo.toml | 1 + fhevm-engine/coprocessor/Dockerfile | 15 ++ fhevm-engine/coprocessor/docker-compose.yml | 10 + fhevm-engine/coprocessor/src/server.rs | 5 +- .../coprocessor/src/tests/operators.rs | 208 +++--------------- fhevm-engine/coprocessor/src/tests/utils.rs | 29 ++- .../fhevm-engine-common/src/tfhe_ops.rs | 2 +- 45 files changed, 991 insertions(+), 181 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/publish-image.yml create mode 100644 fhevm-engine/.sqlx/query-081b734c487a7cff66e2dead32f90045f2fb25c9ef20ecd96ecf9ca8203f89b7.json create mode 100644 fhevm-engine/.sqlx/query-0e7100ff297ee683be2c7785de36ed7a4da52492956bde5e6bc7c7505fb7d22d.json create mode 100644 fhevm-engine/.sqlx/query-2a1d204391cc36d74d12fd4c4dea5a33b30ce93fd4122dbd94cab6d9309358c0.json create mode 100644 fhevm-engine/.sqlx/query-3f1bf7240bdba491a2457ea9092197061136444e3a6f86ce6679b3e42048f337.json create mode 100644 fhevm-engine/.sqlx/query-542528254fdf7530d949fc433de8ec9064d5ac5d655efa8aa0927cb7b23bddba.json create mode 100644 fhevm-engine/.sqlx/query-6613f90d85256adebd7f00e73b1e8d6b4db9d9309cae6810b4830188ea97088e.json create mode 100644 fhevm-engine/.sqlx/query-69e5a39a57d25b91b21c5fa00f45e614a9d71b97e5bdd8118f4d7d986a48aeb5.json create mode 100644 fhevm-engine/.sqlx/query-7a10f7fd760e16bb6333f63097e1f08ee5761187a24d6897391e7c9b82386d27.json create mode 100644 fhevm-engine/.sqlx/query-80d29059e0d56c3e3b92d98b68cff622e857564cba1193edc4837d604c322b7e.json create mode 100644 fhevm-engine/.sqlx/query-872e18492a01ef297c2747b1168c6b4fd16cebdcd07cfa14f55cf7dd61c910e6.json create mode 100644 fhevm-engine/.sqlx/query-8bcf6b5c5f1613de18e4757e9e7ea13ddc3d6994256df2385ca0013178fe5680.json create mode 100644 fhevm-engine/.sqlx/query-8d6b9984cef8365a2a0f2acd318a5989ff4b597f46136bbf5e90c564057e20a1.json create mode 100644 fhevm-engine/.sqlx/query-a3b21adb66baf8e2a9c899b4d5f8c17d9acc17e159696dbbb943ca8fc26f583a.json create mode 100644 fhevm-engine/.sqlx/query-af833a0f2ac5dd8be30e1de778d9357549bca862b75891a887c86d7e50e24e66.json create mode 100644 fhevm-engine/.sqlx/query-be2b10355e815489836278ccb55110baa4dae151e8118da3cc58654f46123f97.json create mode 100644 fhevm-engine/.sqlx/query-c4a8cd701c76572b62939f26b74cdf1a7f8a5c436422f0334382da23505832a7.json create mode 100644 fhevm-engine/.sqlx/query-d8e7f9a1bdba326cd342f8a01985bb467e4c6322c6317269f64351775549cc3b.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-081b734c487a7cff66e2dead32f90045f2fb25c9ef20ecd96ecf9ca8203f89b7.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-0e7100ff297ee683be2c7785de36ed7a4da52492956bde5e6bc7c7505fb7d22d.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-2a1d204391cc36d74d12fd4c4dea5a33b30ce93fd4122dbd94cab6d9309358c0.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-3f1bf7240bdba491a2457ea9092197061136444e3a6f86ce6679b3e42048f337.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-542528254fdf7530d949fc433de8ec9064d5ac5d655efa8aa0927cb7b23bddba.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-6613f90d85256adebd7f00e73b1e8d6b4db9d9309cae6810b4830188ea97088e.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-69e5a39a57d25b91b21c5fa00f45e614a9d71b97e5bdd8118f4d7d986a48aeb5.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-7a10f7fd760e16bb6333f63097e1f08ee5761187a24d6897391e7c9b82386d27.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-80d29059e0d56c3e3b92d98b68cff622e857564cba1193edc4837d604c322b7e.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-872e18492a01ef297c2747b1168c6b4fd16cebdcd07cfa14f55cf7dd61c910e6.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-8bcf6b5c5f1613de18e4757e9e7ea13ddc3d6994256df2385ca0013178fe5680.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-8d6b9984cef8365a2a0f2acd318a5989ff4b597f46136bbf5e90c564057e20a1.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-a3b21adb66baf8e2a9c899b4d5f8c17d9acc17e159696dbbb943ca8fc26f583a.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-af833a0f2ac5dd8be30e1de778d9357549bca862b75891a887c86d7e50e24e66.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-be2b10355e815489836278ccb55110baa4dae151e8118da3cc58654f46123f97.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-c4a8cd701c76572b62939f26b74cdf1a7f8a5c436422f0334382da23505832a7.json create mode 100644 fhevm-engine/coprocessor/.sqlx/query-d8e7f9a1bdba326cd342f8a01985bb467e4c6322c6317269f64351775549cc3b.json create mode 100644 fhevm-engine/coprocessor/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..aae37fda --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +**/target +.git/ diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml new file mode 100644 index 00000000..4e886386 --- /dev/null +++ b/.github/workflows/publish-image.yml @@ -0,0 +1,69 @@ +name: Publish docker image + +on: + workflow_dispatch: + inputs: + image_tag: + description: 'Image (to be built/pushed) tag (default: latest)' + default: "latest" + type: string + required: false + ref_to_geth: + description: 'Branch, tag or commit SHA1 to checkout fhevm-backend' + required: true + default: "main" + type: string + +env: + DOCKER_IMAGE: ghcr.io/zama-ai/coprocessor + +jobs: + push_to_registry: + name: Push Docker image to GitHub Container Registry + runs-on: ubuntu-latest + permissions: + packages: write + steps: + # space wasn't enough at some point + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be + + - name: Check out repo + uses: actions/checkout@v4 + with: + token: ${{ secrets.SUBMODULES_CHECKOUT_TOKEN }} + ref: ${{ inputs.ref_to_geth }} + lfs: true + submodules: recursive + + - name: Check OS + run: | + lscpu + uname -r + lsb_release -a + + - name: Login to GitHub Container Registry + uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: List files in the repository + run: | + ls ${{ github.workspace }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + platforms: linux/amd64,linux/arm64 + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: fhevm-engine/coprocessor/Dockerfile + push: true + pull: true + platforms: linux/amd64,linux/arm64 + tags: ${{ env.DOCKER_IMAGE }}:${{ inputs.image_tag }},${{ env.DOCKER_IMAGE }}:latest diff --git a/fhevm-engine/.sqlx/query-081b734c487a7cff66e2dead32f90045f2fb25c9ef20ecd96ecf9ca8203f89b7.json b/fhevm-engine/.sqlx/query-081b734c487a7cff66e2dead32f90045f2fb25c9ef20ecd96ecf9ca8203f89b7.json new file mode 100644 index 00000000..bb4e6589 --- /dev/null +++ b/fhevm-engine/.sqlx/query-081b734c487a7cff66e2dead32f90045f2fb25c9ef20ecd96ecf9ca8203f89b7.json @@ -0,0 +1,46 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT tenant_id, output_handle, dependencies, fhe_operation, is_scalar\n FROM computations c\n WHERE is_completed = false\n AND is_error = false\n AND NOT EXISTS (\n SELECT 1\n FROM unnest(c.dependencies) WITH ORDINALITY AS elems(v, dep_index)\n WHERE (c.tenant_id, elems.v) NOT IN ( SELECT tenant_id, handle FROM ciphertexts )\n -- don't select scalar operands\n AND ( NOT c.is_scalar OR c.is_scalar AND NOT elems.dep_index = 2 )\n )\n LIMIT $1\n FOR UPDATE SKIP LOCKED\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "tenant_id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "output_handle", + "type_info": "Bytea" + }, + { + "ordinal": 2, + "name": "dependencies", + "type_info": "ByteaArray" + }, + { + "ordinal": 3, + "name": "fhe_operation", + "type_info": "Int2" + }, + { + "ordinal": 4, + "name": "is_scalar", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [ + false, + false, + false, + false, + false + ] + }, + "hash": "081b734c487a7cff66e2dead32f90045f2fb25c9ef20ecd96ecf9ca8203f89b7" +} diff --git a/fhevm-engine/.sqlx/query-0e7100ff297ee683be2c7785de36ed7a4da52492956bde5e6bc7c7505fb7d22d.json b/fhevm-engine/.sqlx/query-0e7100ff297ee683be2c7785de36ed7a4da52492956bde5e6bc7c7505fb7d22d.json new file mode 100644 index 00000000..2f3d28db --- /dev/null +++ b/fhevm-engine/.sqlx/query-0e7100ff297ee683be2c7785de36ed7a4da52492956bde5e6bc7c7505fb7d22d.json @@ -0,0 +1,17 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO input_blobs(tenant_id, blob_hash, blob_data, blob_ciphertext_count)\n VALUES($1, $2, $3, $4)\n ON CONFLICT (tenant_id, blob_hash) DO NOTHING\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Bytea", + "Bytea", + "Int4" + ] + }, + "nullable": [] + }, + "hash": "0e7100ff297ee683be2c7785de36ed7a4da52492956bde5e6bc7c7505fb7d22d" +} diff --git a/fhevm-engine/.sqlx/query-2a1d204391cc36d74d12fd4c4dea5a33b30ce93fd4122dbd94cab6d9309358c0.json b/fhevm-engine/.sqlx/query-2a1d204391cc36d74d12fd4c4dea5a33b30ce93fd4122dbd94cab6d9309358c0.json new file mode 100644 index 00000000..95593e3f --- /dev/null +++ b/fhevm-engine/.sqlx/query-2a1d204391cc36d74d12fd4c4dea5a33b30ce93fd4122dbd94cab6d9309358c0.json @@ -0,0 +1,18 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO ciphertexts(tenant_id, handle, ciphertext, ciphertext_version, ciphertext_type)\n VALUES ($1, $2, $3, $4, $5)\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Bytea", + "Bytea", + "Int2", + "Int2" + ] + }, + "nullable": [] + }, + "hash": "2a1d204391cc36d74d12fd4c4dea5a33b30ce93fd4122dbd94cab6d9309358c0" +} diff --git a/fhevm-engine/.sqlx/query-3f1bf7240bdba491a2457ea9092197061136444e3a6f86ce6679b3e42048f337.json b/fhevm-engine/.sqlx/query-3f1bf7240bdba491a2457ea9092197061136444e3a6f86ce6679b3e42048f337.json new file mode 100644 index 00000000..c1191fc8 --- /dev/null +++ b/fhevm-engine/.sqlx/query-3f1bf7240bdba491a2457ea9092197061136444e3a6f86ce6679b3e42048f337.json @@ -0,0 +1,18 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO ciphertexts(tenant_id, handle, ciphertext, ciphertext_version, ciphertext_type)\n VALUES($1, $2, $3, $4, $5)\n ON CONFLICT (tenant_id, handle, ciphertext_version) DO NOTHING\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Bytea", + "Bytea", + "Int2", + "Int2" + ] + }, + "nullable": [] + }, + "hash": "3f1bf7240bdba491a2457ea9092197061136444e3a6f86ce6679b3e42048f337" +} diff --git a/fhevm-engine/.sqlx/query-542528254fdf7530d949fc433de8ec9064d5ac5d655efa8aa0927cb7b23bddba.json b/fhevm-engine/.sqlx/query-542528254fdf7530d949fc433de8ec9064d5ac5d655efa8aa0927cb7b23bddba.json new file mode 100644 index 00000000..591c7e3a --- /dev/null +++ b/fhevm-engine/.sqlx/query-542528254fdf7530d949fc433de8ec9064d5ac5d655efa8aa0927cb7b23bddba.json @@ -0,0 +1,28 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT sks_key, cks_key\n FROM tenants\n WHERE tenant_id = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "sks_key", + "type_info": "Bytea" + }, + { + "ordinal": 1, + "name": "cks_key", + "type_info": "Bytea" + } + ], + "parameters": { + "Left": [ + "Int4" + ] + }, + "nullable": [ + false, + true + ] + }, + "hash": "542528254fdf7530d949fc433de8ec9064d5ac5d655efa8aa0927cb7b23bddba" +} diff --git a/fhevm-engine/.sqlx/query-6613f90d85256adebd7f00e73b1e8d6b4db9d9309cae6810b4830188ea97088e.json b/fhevm-engine/.sqlx/query-6613f90d85256adebd7f00e73b1e8d6b4db9d9309cae6810b4830188ea97088e.json new file mode 100644 index 00000000..db25ab32 --- /dev/null +++ b/fhevm-engine/.sqlx/query-6613f90d85256adebd7f00e73b1e8d6b4db9d9309cae6810b4830188ea97088e.json @@ -0,0 +1,41 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT tenant_id, handle, ciphertext, ciphertext_type\n FROM ciphertexts\n WHERE tenant_id = ANY($1::INT[])\n AND handle = ANY($2::BYTEA[])\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "tenant_id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "handle", + "type_info": "Bytea" + }, + { + "ordinal": 2, + "name": "ciphertext", + "type_info": "Bytea" + }, + { + "ordinal": 3, + "name": "ciphertext_type", + "type_info": "Int2" + } + ], + "parameters": { + "Left": [ + "Int4Array", + "ByteaArray" + ] + }, + "nullable": [ + false, + false, + false, + false + ] + }, + "hash": "6613f90d85256adebd7f00e73b1e8d6b4db9d9309cae6810b4830188ea97088e" +} diff --git a/fhevm-engine/.sqlx/query-69e5a39a57d25b91b21c5fa00f45e614a9d71b97e5bdd8118f4d7d986a48aeb5.json b/fhevm-engine/.sqlx/query-69e5a39a57d25b91b21c5fa00f45e614a9d71b97e5bdd8118f4d7d986a48aeb5.json new file mode 100644 index 00000000..8d57cc54 --- /dev/null +++ b/fhevm-engine/.sqlx/query-69e5a39a57d25b91b21c5fa00f45e614a9d71b97e5bdd8118f4d7d986a48aeb5.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT tenant_id FROM tenants WHERE tenant_api_key = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "tenant_id", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [ + false + ] + }, + "hash": "69e5a39a57d25b91b21c5fa00f45e614a9d71b97e5bdd8118f4d7d986a48aeb5" +} diff --git a/fhevm-engine/.sqlx/query-7a10f7fd760e16bb6333f63097e1f08ee5761187a24d6897391e7c9b82386d27.json b/fhevm-engine/.sqlx/query-7a10f7fd760e16bb6333f63097e1f08ee5761187a24d6897391e7c9b82386d27.json new file mode 100644 index 00000000..1cf082db --- /dev/null +++ b/fhevm-engine/.sqlx/query-7a10f7fd760e16bb6333f63097e1f08ee5761187a24d6897391e7c9b82386d27.json @@ -0,0 +1,29 @@ +{ + "db_name": "PostgreSQL", + "query": "\n -- existing computations\n SELECT handle AS \"handle!\", ciphertext_type AS \"ciphertext_type!\"\n FROM ciphertexts\n WHERE tenant_id = $2\n AND handle = ANY($1::BYTEA[])\n UNION\n -- pending computations\n SELECT output_handle AS \"handle!\", output_type AS \"ciphertext_type!\"\n FROM computations\n WHERE tenant_id = $2\n AND output_handle = ANY($1::BYTEA[])\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "handle!", + "type_info": "Bytea" + }, + { + "ordinal": 1, + "name": "ciphertext_type!", + "type_info": "Int2" + } + ], + "parameters": { + "Left": [ + "ByteaArray", + "Int4" + ] + }, + "nullable": [ + null, + null + ] + }, + "hash": "7a10f7fd760e16bb6333f63097e1f08ee5761187a24d6897391e7c9b82386d27" +} diff --git a/fhevm-engine/.sqlx/query-80d29059e0d56c3e3b92d98b68cff622e857564cba1193edc4837d604c322b7e.json b/fhevm-engine/.sqlx/query-80d29059e0d56c3e3b92d98b68cff622e857564cba1193edc4837d604c322b7e.json new file mode 100644 index 00000000..88f0a8e6 --- /dev/null +++ b/fhevm-engine/.sqlx/query-80d29059e0d56c3e3b92d98b68cff622e857564cba1193edc4837d604c322b7e.json @@ -0,0 +1,34 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT tenant_id, pks_key, sks_key\n FROM tenants\n WHERE tenant_id = ANY($1::INT[])\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "tenant_id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "pks_key", + "type_info": "Bytea" + }, + { + "ordinal": 2, + "name": "sks_key", + "type_info": "Bytea" + } + ], + "parameters": { + "Left": [ + "Int4Array" + ] + }, + "nullable": [ + false, + false, + false + ] + }, + "hash": "80d29059e0d56c3e3b92d98b68cff622e857564cba1193edc4837d604c322b7e" +} diff --git a/fhevm-engine/.sqlx/query-872e18492a01ef297c2747b1168c6b4fd16cebdcd07cfa14f55cf7dd61c910e6.json b/fhevm-engine/.sqlx/query-872e18492a01ef297c2747b1168c6b4fd16cebdcd07cfa14f55cf7dd61c910e6.json new file mode 100644 index 00000000..5d1c1e18 --- /dev/null +++ b/fhevm-engine/.sqlx/query-872e18492a01ef297c2747b1168c6b4fd16cebdcd07cfa14f55cf7dd61c910e6.json @@ -0,0 +1,18 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO ciphertexts(tenant_id, handle, ciphertext, ciphertext_version, ciphertext_type)\n VALUES($1, $2, $3, $4, $5)\n ON CONFLICT (tenant_id, handle, ciphertext_version) DO NOTHING\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Bytea", + "Bytea", + "Int2", + "Int2" + ] + }, + "nullable": [] + }, + "hash": "872e18492a01ef297c2747b1168c6b4fd16cebdcd07cfa14f55cf7dd61c910e6" +} diff --git a/fhevm-engine/.sqlx/query-8bcf6b5c5f1613de18e4757e9e7ea13ddc3d6994256df2385ca0013178fe5680.json b/fhevm-engine/.sqlx/query-8bcf6b5c5f1613de18e4757e9e7ea13ddc3d6994256df2385ca0013178fe5680.json new file mode 100644 index 00000000..ccfca8d3 --- /dev/null +++ b/fhevm-engine/.sqlx/query-8bcf6b5c5f1613de18e4757e9e7ea13ddc3d6994256df2385ca0013178fe5680.json @@ -0,0 +1,20 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO ciphertexts(\n tenant_id,\n handle,\n ciphertext,\n ciphertext_version,\n ciphertext_type,\n input_blob_hash,\n input_blob_index\n )\n VALUES($1, $2, $3, $4, $5, $6, $7)\n ON CONFLICT (tenant_id, handle, ciphertext_version) DO NOTHING\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Bytea", + "Bytea", + "Int2", + "Int2", + "Bytea", + "Int4" + ] + }, + "nullable": [] + }, + "hash": "8bcf6b5c5f1613de18e4757e9e7ea13ddc3d6994256df2385ca0013178fe5680" +} diff --git a/fhevm-engine/.sqlx/query-8d6b9984cef8365a2a0f2acd318a5989ff4b597f46136bbf5e90c564057e20a1.json b/fhevm-engine/.sqlx/query-8d6b9984cef8365a2a0f2acd318a5989ff4b597f46136bbf5e90c564057e20a1.json new file mode 100644 index 00000000..525b682c --- /dev/null +++ b/fhevm-engine/.sqlx/query-8d6b9984cef8365a2a0f2acd318a5989ff4b597f46136bbf5e90c564057e20a1.json @@ -0,0 +1,19 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO computations(\n tenant_id,\n output_handle,\n dependencies,\n fhe_operation,\n is_completed,\n is_scalar,\n output_type\n )\n VALUES($1, $2, $3, $4, false, $5, $6)\n ON CONFLICT (tenant_id, output_handle) DO NOTHING\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Bytea", + "ByteaArray", + "Int2", + "Bool", + "Int2" + ] + }, + "nullable": [] + }, + "hash": "8d6b9984cef8365a2a0f2acd318a5989ff4b597f46136bbf5e90c564057e20a1" +} diff --git a/fhevm-engine/.sqlx/query-a3b21adb66baf8e2a9c899b4d5f8c17d9acc17e159696dbbb943ca8fc26f583a.json b/fhevm-engine/.sqlx/query-a3b21adb66baf8e2a9c899b4d5f8c17d9acc17e159696dbbb943ca8fc26f583a.json new file mode 100644 index 00000000..3ebf008c --- /dev/null +++ b/fhevm-engine/.sqlx/query-a3b21adb66baf8e2a9c899b4d5f8c17d9acc17e159696dbbb943ca8fc26f583a.json @@ -0,0 +1,36 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT ciphertext, ciphertext_type, handle\n FROM ciphertexts\n WHERE tenant_id = $1\n AND handle = ANY($2::BYTEA[])\n AND ciphertext_version = $3\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "ciphertext", + "type_info": "Bytea" + }, + { + "ordinal": 1, + "name": "ciphertext_type", + "type_info": "Int2" + }, + { + "ordinal": 2, + "name": "handle", + "type_info": "Bytea" + } + ], + "parameters": { + "Left": [ + "Int4", + "ByteaArray", + "Int2" + ] + }, + "nullable": [ + false, + false, + false + ] + }, + "hash": "a3b21adb66baf8e2a9c899b4d5f8c17d9acc17e159696dbbb943ca8fc26f583a" +} diff --git a/fhevm-engine/.sqlx/query-af833a0f2ac5dd8be30e1de778d9357549bca862b75891a887c86d7e50e24e66.json b/fhevm-engine/.sqlx/query-af833a0f2ac5dd8be30e1de778d9357549bca862b75891a887c86d7e50e24e66.json new file mode 100644 index 00000000..7b3657bd --- /dev/null +++ b/fhevm-engine/.sqlx/query-af833a0f2ac5dd8be30e1de778d9357549bca862b75891a887c86d7e50e24e66.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "\n UPDATE computations\n SET is_completed = true\n WHERE tenant_id = $1\n AND output_handle = $2\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Bytea" + ] + }, + "nullable": [] + }, + "hash": "af833a0f2ac5dd8be30e1de778d9357549bca862b75891a887c86d7e50e24e66" +} diff --git a/fhevm-engine/.sqlx/query-be2b10355e815489836278ccb55110baa4dae151e8118da3cc58654f46123f97.json b/fhevm-engine/.sqlx/query-be2b10355e815489836278ccb55110baa4dae151e8118da3cc58654f46123f97.json new file mode 100644 index 00000000..a02c4f9b --- /dev/null +++ b/fhevm-engine/.sqlx/query-be2b10355e815489836278ccb55110baa4dae151e8118da3cc58654f46123f97.json @@ -0,0 +1,12 @@ +{ + "db_name": "PostgreSQL", + "query": "NOTIFY work_available", + "describe": { + "columns": [], + "parameters": { + "Left": [] + }, + "nullable": [] + }, + "hash": "be2b10355e815489836278ccb55110baa4dae151e8118da3cc58654f46123f97" +} diff --git a/fhevm-engine/.sqlx/query-c4a8cd701c76572b62939f26b74cdf1a7f8a5c436422f0334382da23505832a7.json b/fhevm-engine/.sqlx/query-c4a8cd701c76572b62939f26b74cdf1a7f8a5c436422f0334382da23505832a7.json new file mode 100644 index 00000000..9f86c14f --- /dev/null +++ b/fhevm-engine/.sqlx/query-c4a8cd701c76572b62939f26b74cdf1a7f8a5c436422f0334382da23505832a7.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT cks_key\n FROM tenants\n WHERE tenant_id = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "cks_key", + "type_info": "Bytea" + } + ], + "parameters": { + "Left": [ + "Int4" + ] + }, + "nullable": [ + true + ] + }, + "hash": "c4a8cd701c76572b62939f26b74cdf1a7f8a5c436422f0334382da23505832a7" +} diff --git a/fhevm-engine/.sqlx/query-d8e7f9a1bdba326cd342f8a01985bb467e4c6322c6317269f64351775549cc3b.json b/fhevm-engine/.sqlx/query-d8e7f9a1bdba326cd342f8a01985bb467e4c6322c6317269f64351775549cc3b.json new file mode 100644 index 00000000..350cefd1 --- /dev/null +++ b/fhevm-engine/.sqlx/query-d8e7f9a1bdba326cd342f8a01985bb467e4c6322c6317269f64351775549cc3b.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "\n UPDATE computations\n SET is_error = true, error_message = $1\n WHERE tenant_id = $2\n AND output_handle = $3\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Int4", + "Bytea" + ] + }, + "nullable": [] + }, + "hash": "d8e7f9a1bdba326cd342f8a01985bb467e4c6322c6317269f64351775549cc3b" +} diff --git a/fhevm-engine/Cargo.lock b/fhevm-engine/Cargo.lock index c6f0df9f..92898350 100644 --- a/fhevm-engine/Cargo.lock +++ b/fhevm-engine/Cargo.lock @@ -589,6 +589,7 @@ dependencies = [ "lazy_static", "lru", "prost", + "random", "regex", "serde_json", "sha3", @@ -1945,6 +1946,12 @@ dependencies = [ "getrandom", ] +[[package]] +name = "random" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c7093a82705b48f10d4b165c6482dbe9f58cd63a870d85537e857b2badbd88" + [[package]] name = "rayon" version = "1.10.0" diff --git a/fhevm-engine/Cargo.toml b/fhevm-engine/Cargo.toml index 3c374aa6..7be39b60 100644 --- a/fhevm-engine/Cargo.toml +++ b/fhevm-engine/Cargo.toml @@ -11,3 +11,5 @@ bincode = "1.3.3" sha3 = "0.10.8" anyhow = "1.0.86" +[profile.dev.package.tfhe] +overflow-checks = false \ No newline at end of file diff --git a/fhevm-engine/coprocessor/.sqlx/query-081b734c487a7cff66e2dead32f90045f2fb25c9ef20ecd96ecf9ca8203f89b7.json b/fhevm-engine/coprocessor/.sqlx/query-081b734c487a7cff66e2dead32f90045f2fb25c9ef20ecd96ecf9ca8203f89b7.json new file mode 100644 index 00000000..bb4e6589 --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-081b734c487a7cff66e2dead32f90045f2fb25c9ef20ecd96ecf9ca8203f89b7.json @@ -0,0 +1,46 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT tenant_id, output_handle, dependencies, fhe_operation, is_scalar\n FROM computations c\n WHERE is_completed = false\n AND is_error = false\n AND NOT EXISTS (\n SELECT 1\n FROM unnest(c.dependencies) WITH ORDINALITY AS elems(v, dep_index)\n WHERE (c.tenant_id, elems.v) NOT IN ( SELECT tenant_id, handle FROM ciphertexts )\n -- don't select scalar operands\n AND ( NOT c.is_scalar OR c.is_scalar AND NOT elems.dep_index = 2 )\n )\n LIMIT $1\n FOR UPDATE SKIP LOCKED\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "tenant_id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "output_handle", + "type_info": "Bytea" + }, + { + "ordinal": 2, + "name": "dependencies", + "type_info": "ByteaArray" + }, + { + "ordinal": 3, + "name": "fhe_operation", + "type_info": "Int2" + }, + { + "ordinal": 4, + "name": "is_scalar", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [ + false, + false, + false, + false, + false + ] + }, + "hash": "081b734c487a7cff66e2dead32f90045f2fb25c9ef20ecd96ecf9ca8203f89b7" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-0e7100ff297ee683be2c7785de36ed7a4da52492956bde5e6bc7c7505fb7d22d.json b/fhevm-engine/coprocessor/.sqlx/query-0e7100ff297ee683be2c7785de36ed7a4da52492956bde5e6bc7c7505fb7d22d.json new file mode 100644 index 00000000..2f3d28db --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-0e7100ff297ee683be2c7785de36ed7a4da52492956bde5e6bc7c7505fb7d22d.json @@ -0,0 +1,17 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO input_blobs(tenant_id, blob_hash, blob_data, blob_ciphertext_count)\n VALUES($1, $2, $3, $4)\n ON CONFLICT (tenant_id, blob_hash) DO NOTHING\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Bytea", + "Bytea", + "Int4" + ] + }, + "nullable": [] + }, + "hash": "0e7100ff297ee683be2c7785de36ed7a4da52492956bde5e6bc7c7505fb7d22d" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-2a1d204391cc36d74d12fd4c4dea5a33b30ce93fd4122dbd94cab6d9309358c0.json b/fhevm-engine/coprocessor/.sqlx/query-2a1d204391cc36d74d12fd4c4dea5a33b30ce93fd4122dbd94cab6d9309358c0.json new file mode 100644 index 00000000..95593e3f --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-2a1d204391cc36d74d12fd4c4dea5a33b30ce93fd4122dbd94cab6d9309358c0.json @@ -0,0 +1,18 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO ciphertexts(tenant_id, handle, ciphertext, ciphertext_version, ciphertext_type)\n VALUES ($1, $2, $3, $4, $5)\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Bytea", + "Bytea", + "Int2", + "Int2" + ] + }, + "nullable": [] + }, + "hash": "2a1d204391cc36d74d12fd4c4dea5a33b30ce93fd4122dbd94cab6d9309358c0" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-3f1bf7240bdba491a2457ea9092197061136444e3a6f86ce6679b3e42048f337.json b/fhevm-engine/coprocessor/.sqlx/query-3f1bf7240bdba491a2457ea9092197061136444e3a6f86ce6679b3e42048f337.json new file mode 100644 index 00000000..c1191fc8 --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-3f1bf7240bdba491a2457ea9092197061136444e3a6f86ce6679b3e42048f337.json @@ -0,0 +1,18 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO ciphertexts(tenant_id, handle, ciphertext, ciphertext_version, ciphertext_type)\n VALUES($1, $2, $3, $4, $5)\n ON CONFLICT (tenant_id, handle, ciphertext_version) DO NOTHING\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Bytea", + "Bytea", + "Int2", + "Int2" + ] + }, + "nullable": [] + }, + "hash": "3f1bf7240bdba491a2457ea9092197061136444e3a6f86ce6679b3e42048f337" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-542528254fdf7530d949fc433de8ec9064d5ac5d655efa8aa0927cb7b23bddba.json b/fhevm-engine/coprocessor/.sqlx/query-542528254fdf7530d949fc433de8ec9064d5ac5d655efa8aa0927cb7b23bddba.json new file mode 100644 index 00000000..591c7e3a --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-542528254fdf7530d949fc433de8ec9064d5ac5d655efa8aa0927cb7b23bddba.json @@ -0,0 +1,28 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT sks_key, cks_key\n FROM tenants\n WHERE tenant_id = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "sks_key", + "type_info": "Bytea" + }, + { + "ordinal": 1, + "name": "cks_key", + "type_info": "Bytea" + } + ], + "parameters": { + "Left": [ + "Int4" + ] + }, + "nullable": [ + false, + true + ] + }, + "hash": "542528254fdf7530d949fc433de8ec9064d5ac5d655efa8aa0927cb7b23bddba" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-6613f90d85256adebd7f00e73b1e8d6b4db9d9309cae6810b4830188ea97088e.json b/fhevm-engine/coprocessor/.sqlx/query-6613f90d85256adebd7f00e73b1e8d6b4db9d9309cae6810b4830188ea97088e.json new file mode 100644 index 00000000..db25ab32 --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-6613f90d85256adebd7f00e73b1e8d6b4db9d9309cae6810b4830188ea97088e.json @@ -0,0 +1,41 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT tenant_id, handle, ciphertext, ciphertext_type\n FROM ciphertexts\n WHERE tenant_id = ANY($1::INT[])\n AND handle = ANY($2::BYTEA[])\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "tenant_id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "handle", + "type_info": "Bytea" + }, + { + "ordinal": 2, + "name": "ciphertext", + "type_info": "Bytea" + }, + { + "ordinal": 3, + "name": "ciphertext_type", + "type_info": "Int2" + } + ], + "parameters": { + "Left": [ + "Int4Array", + "ByteaArray" + ] + }, + "nullable": [ + false, + false, + false, + false + ] + }, + "hash": "6613f90d85256adebd7f00e73b1e8d6b4db9d9309cae6810b4830188ea97088e" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-69e5a39a57d25b91b21c5fa00f45e614a9d71b97e5bdd8118f4d7d986a48aeb5.json b/fhevm-engine/coprocessor/.sqlx/query-69e5a39a57d25b91b21c5fa00f45e614a9d71b97e5bdd8118f4d7d986a48aeb5.json new file mode 100644 index 00000000..8d57cc54 --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-69e5a39a57d25b91b21c5fa00f45e614a9d71b97e5bdd8118f4d7d986a48aeb5.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT tenant_id FROM tenants WHERE tenant_api_key = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "tenant_id", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [ + false + ] + }, + "hash": "69e5a39a57d25b91b21c5fa00f45e614a9d71b97e5bdd8118f4d7d986a48aeb5" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-7a10f7fd760e16bb6333f63097e1f08ee5761187a24d6897391e7c9b82386d27.json b/fhevm-engine/coprocessor/.sqlx/query-7a10f7fd760e16bb6333f63097e1f08ee5761187a24d6897391e7c9b82386d27.json new file mode 100644 index 00000000..1cf082db --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-7a10f7fd760e16bb6333f63097e1f08ee5761187a24d6897391e7c9b82386d27.json @@ -0,0 +1,29 @@ +{ + "db_name": "PostgreSQL", + "query": "\n -- existing computations\n SELECT handle AS \"handle!\", ciphertext_type AS \"ciphertext_type!\"\n FROM ciphertexts\n WHERE tenant_id = $2\n AND handle = ANY($1::BYTEA[])\n UNION\n -- pending computations\n SELECT output_handle AS \"handle!\", output_type AS \"ciphertext_type!\"\n FROM computations\n WHERE tenant_id = $2\n AND output_handle = ANY($1::BYTEA[])\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "handle!", + "type_info": "Bytea" + }, + { + "ordinal": 1, + "name": "ciphertext_type!", + "type_info": "Int2" + } + ], + "parameters": { + "Left": [ + "ByteaArray", + "Int4" + ] + }, + "nullable": [ + null, + null + ] + }, + "hash": "7a10f7fd760e16bb6333f63097e1f08ee5761187a24d6897391e7c9b82386d27" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-80d29059e0d56c3e3b92d98b68cff622e857564cba1193edc4837d604c322b7e.json b/fhevm-engine/coprocessor/.sqlx/query-80d29059e0d56c3e3b92d98b68cff622e857564cba1193edc4837d604c322b7e.json new file mode 100644 index 00000000..88f0a8e6 --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-80d29059e0d56c3e3b92d98b68cff622e857564cba1193edc4837d604c322b7e.json @@ -0,0 +1,34 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT tenant_id, pks_key, sks_key\n FROM tenants\n WHERE tenant_id = ANY($1::INT[])\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "tenant_id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "pks_key", + "type_info": "Bytea" + }, + { + "ordinal": 2, + "name": "sks_key", + "type_info": "Bytea" + } + ], + "parameters": { + "Left": [ + "Int4Array" + ] + }, + "nullable": [ + false, + false, + false + ] + }, + "hash": "80d29059e0d56c3e3b92d98b68cff622e857564cba1193edc4837d604c322b7e" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-872e18492a01ef297c2747b1168c6b4fd16cebdcd07cfa14f55cf7dd61c910e6.json b/fhevm-engine/coprocessor/.sqlx/query-872e18492a01ef297c2747b1168c6b4fd16cebdcd07cfa14f55cf7dd61c910e6.json new file mode 100644 index 00000000..5d1c1e18 --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-872e18492a01ef297c2747b1168c6b4fd16cebdcd07cfa14f55cf7dd61c910e6.json @@ -0,0 +1,18 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO ciphertexts(tenant_id, handle, ciphertext, ciphertext_version, ciphertext_type)\n VALUES($1, $2, $3, $4, $5)\n ON CONFLICT (tenant_id, handle, ciphertext_version) DO NOTHING\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Bytea", + "Bytea", + "Int2", + "Int2" + ] + }, + "nullable": [] + }, + "hash": "872e18492a01ef297c2747b1168c6b4fd16cebdcd07cfa14f55cf7dd61c910e6" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-8bcf6b5c5f1613de18e4757e9e7ea13ddc3d6994256df2385ca0013178fe5680.json b/fhevm-engine/coprocessor/.sqlx/query-8bcf6b5c5f1613de18e4757e9e7ea13ddc3d6994256df2385ca0013178fe5680.json new file mode 100644 index 00000000..ccfca8d3 --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-8bcf6b5c5f1613de18e4757e9e7ea13ddc3d6994256df2385ca0013178fe5680.json @@ -0,0 +1,20 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO ciphertexts(\n tenant_id,\n handle,\n ciphertext,\n ciphertext_version,\n ciphertext_type,\n input_blob_hash,\n input_blob_index\n )\n VALUES($1, $2, $3, $4, $5, $6, $7)\n ON CONFLICT (tenant_id, handle, ciphertext_version) DO NOTHING\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Bytea", + "Bytea", + "Int2", + "Int2", + "Bytea", + "Int4" + ] + }, + "nullable": [] + }, + "hash": "8bcf6b5c5f1613de18e4757e9e7ea13ddc3d6994256df2385ca0013178fe5680" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-8d6b9984cef8365a2a0f2acd318a5989ff4b597f46136bbf5e90c564057e20a1.json b/fhevm-engine/coprocessor/.sqlx/query-8d6b9984cef8365a2a0f2acd318a5989ff4b597f46136bbf5e90c564057e20a1.json new file mode 100644 index 00000000..525b682c --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-8d6b9984cef8365a2a0f2acd318a5989ff4b597f46136bbf5e90c564057e20a1.json @@ -0,0 +1,19 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO computations(\n tenant_id,\n output_handle,\n dependencies,\n fhe_operation,\n is_completed,\n is_scalar,\n output_type\n )\n VALUES($1, $2, $3, $4, false, $5, $6)\n ON CONFLICT (tenant_id, output_handle) DO NOTHING\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Bytea", + "ByteaArray", + "Int2", + "Bool", + "Int2" + ] + }, + "nullable": [] + }, + "hash": "8d6b9984cef8365a2a0f2acd318a5989ff4b597f46136bbf5e90c564057e20a1" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-a3b21adb66baf8e2a9c899b4d5f8c17d9acc17e159696dbbb943ca8fc26f583a.json b/fhevm-engine/coprocessor/.sqlx/query-a3b21adb66baf8e2a9c899b4d5f8c17d9acc17e159696dbbb943ca8fc26f583a.json new file mode 100644 index 00000000..3ebf008c --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-a3b21adb66baf8e2a9c899b4d5f8c17d9acc17e159696dbbb943ca8fc26f583a.json @@ -0,0 +1,36 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT ciphertext, ciphertext_type, handle\n FROM ciphertexts\n WHERE tenant_id = $1\n AND handle = ANY($2::BYTEA[])\n AND ciphertext_version = $3\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "ciphertext", + "type_info": "Bytea" + }, + { + "ordinal": 1, + "name": "ciphertext_type", + "type_info": "Int2" + }, + { + "ordinal": 2, + "name": "handle", + "type_info": "Bytea" + } + ], + "parameters": { + "Left": [ + "Int4", + "ByteaArray", + "Int2" + ] + }, + "nullable": [ + false, + false, + false + ] + }, + "hash": "a3b21adb66baf8e2a9c899b4d5f8c17d9acc17e159696dbbb943ca8fc26f583a" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-af833a0f2ac5dd8be30e1de778d9357549bca862b75891a887c86d7e50e24e66.json b/fhevm-engine/coprocessor/.sqlx/query-af833a0f2ac5dd8be30e1de778d9357549bca862b75891a887c86d7e50e24e66.json new file mode 100644 index 00000000..7b3657bd --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-af833a0f2ac5dd8be30e1de778d9357549bca862b75891a887c86d7e50e24e66.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "\n UPDATE computations\n SET is_completed = true\n WHERE tenant_id = $1\n AND output_handle = $2\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Bytea" + ] + }, + "nullable": [] + }, + "hash": "af833a0f2ac5dd8be30e1de778d9357549bca862b75891a887c86d7e50e24e66" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-be2b10355e815489836278ccb55110baa4dae151e8118da3cc58654f46123f97.json b/fhevm-engine/coprocessor/.sqlx/query-be2b10355e815489836278ccb55110baa4dae151e8118da3cc58654f46123f97.json new file mode 100644 index 00000000..a02c4f9b --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-be2b10355e815489836278ccb55110baa4dae151e8118da3cc58654f46123f97.json @@ -0,0 +1,12 @@ +{ + "db_name": "PostgreSQL", + "query": "NOTIFY work_available", + "describe": { + "columns": [], + "parameters": { + "Left": [] + }, + "nullable": [] + }, + "hash": "be2b10355e815489836278ccb55110baa4dae151e8118da3cc58654f46123f97" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-c4a8cd701c76572b62939f26b74cdf1a7f8a5c436422f0334382da23505832a7.json b/fhevm-engine/coprocessor/.sqlx/query-c4a8cd701c76572b62939f26b74cdf1a7f8a5c436422f0334382da23505832a7.json new file mode 100644 index 00000000..9f86c14f --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-c4a8cd701c76572b62939f26b74cdf1a7f8a5c436422f0334382da23505832a7.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT cks_key\n FROM tenants\n WHERE tenant_id = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "cks_key", + "type_info": "Bytea" + } + ], + "parameters": { + "Left": [ + "Int4" + ] + }, + "nullable": [ + true + ] + }, + "hash": "c4a8cd701c76572b62939f26b74cdf1a7f8a5c436422f0334382da23505832a7" +} diff --git a/fhevm-engine/coprocessor/.sqlx/query-d8e7f9a1bdba326cd342f8a01985bb467e4c6322c6317269f64351775549cc3b.json b/fhevm-engine/coprocessor/.sqlx/query-d8e7f9a1bdba326cd342f8a01985bb467e4c6322c6317269f64351775549cc3b.json new file mode 100644 index 00000000..350cefd1 --- /dev/null +++ b/fhevm-engine/coprocessor/.sqlx/query-d8e7f9a1bdba326cd342f8a01985bb467e4c6322c6317269f64351775549cc3b.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "\n UPDATE computations\n SET is_error = true, error_message = $1\n WHERE tenant_id = $2\n AND output_handle = $3\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Int4", + "Bytea" + ] + }, + "nullable": [] + }, + "hash": "d8e7f9a1bdba326cd342f8a01985bb467e4c6322c6317269f64351775549cc3b" +} diff --git a/fhevm-engine/coprocessor/Cargo.toml b/fhevm-engine/coprocessor/Cargo.toml index a77cf978..13b42e80 100644 --- a/fhevm-engine/coprocessor/Cargo.toml +++ b/fhevm-engine/coprocessor/Cargo.toml @@ -33,6 +33,7 @@ sha3.workspace = true [dev-dependencies] testcontainers = "0.21" +random = "0.14.0" [build-dependencies] tonic-build = "0.12" diff --git a/fhevm-engine/coprocessor/Dockerfile b/fhevm-engine/coprocessor/Dockerfile new file mode 100644 index 00000000..f96f4dd5 --- /dev/null +++ b/fhevm-engine/coprocessor/Dockerfile @@ -0,0 +1,15 @@ +FROM rust:1.80.1-bullseye AS build + +RUN apt-get update +RUN apt-get install -y protobuf-compiler + +# we assume we're in the root directory +ADD . /app/ + +RUN cd /app/fhevm-engine/coprocessor && SQLX_OFFLINE=true cargo build --release + +FROM debian:bullseye + +COPY --from=build /app/fhevm-engine/target/release/coprocessor /usr/local/bin + +ENTRYPOINT ["/usr/local/bin/coprocessor"] \ No newline at end of file diff --git a/fhevm-engine/coprocessor/docker-compose.yml b/fhevm-engine/coprocessor/docker-compose.yml index 9fa503ba..78ebb2b2 100644 --- a/fhevm-engine/coprocessor/docker-compose.yml +++ b/fhevm-engine/coprocessor/docker-compose.yml @@ -10,6 +10,16 @@ services: - '5432:5432' volumes: - db:/var/lib/postgresql/data + coproc: + image: coproc:v1 + environment: + - DATABASE_URL=postgresql://postgres:postgres@db:5432/coprocessor + ports: + - '50051:50051' + command: + - --run-bg-worker + - --run-server + - --server-addr=0.0.0.0:50051 volumes: db: driver: local diff --git a/fhevm-engine/coprocessor/src/server.rs b/fhevm-engine/coprocessor/src/server.rs index df71f64a..6877ed3c 100644 --- a/fhevm-engine/coprocessor/src/server.rs +++ b/fhevm-engine/coprocessor/src/server.rs @@ -375,7 +375,10 @@ impl coprocessor::fhevm_coprocessor_server::FhevmCoprocessor for CoprocessorServ let the_num = BigUint::from_bytes_be(&v.be_value).to_string(); let ct = debug_trivial_encrypt_be_bytes(v.output_type as i16, &v.be_value); let decr = ct.decrypt(&client_key); - assert_eq!(the_num, decr, "Trivial encryption must preserve the original value"); + let fhe_bool_type = 0; + if v.output_type != fhe_bool_type { + assert_eq!(the_num, decr, "Trivial encryption must preserve the original value"); + } let (ct_type, ct_bytes) = ct.serialize(); res.push((v.handle, ct_type, ct_bytes)); } diff --git a/fhevm-engine/coprocessor/src/tests/operators.rs b/fhevm-engine/coprocessor/src/tests/operators.rs index 4dcc2e43..fc368d61 100644 --- a/fhevm-engine/coprocessor/src/tests/operators.rs +++ b/fhevm-engine/coprocessor/src/tests/operators.rs @@ -12,6 +12,7 @@ use crate::{ use bigdecimal::num_bigint::BigInt; use fhevm_engine_common::tfhe_ops::{does_fhe_operation_support_both_encrypted_operands, does_fhe_operation_support_scalar}; use fhevm_engine_common::types::{FheOperationType, SupportedFheOperations}; +use random::Source; use strum::IntoEnumIterator; use std::{ops::Not, str::FromStr}; use tonic::metadata::MetadataValue; @@ -74,15 +75,22 @@ fn supported_bits_to_bit_type_in_db(inp: i32) -> i32 { } } +fn random_handle_start() -> u64 { + let time = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH) + .unwrap().as_nanos(); + let mut random_gen = random::default(time as u64); + random_gen.read_u64() +} + #[tokio::test] async fn test_fhe_binary_operands() -> Result<(), Box> { let ops = generate_binary_test_cases(); let app = setup_test_app().await?; let mut client = FhevmCoprocessorClient::connect(app.app_url().to_string()).await?; - let mut handle_counter = 0; + let mut handle_counter: u64 = random_handle_start(); let mut next_handle = || { - let out: i32 = handle_counter; + let out: u64 = handle_counter; handle_counter += 1; out.to_be_bytes().to_vec() }; @@ -218,9 +226,9 @@ async fn test_fhe_unary_operands() -> Result<(), Box> { let app = setup_test_app().await?; let mut client = FhevmCoprocessorClient::connect(app.app_url().to_string()).await?; - let mut handle_counter = 0; + let mut handle_counter: u64 = random_handle_start(); let mut next_handle = || { - let out: i32 = handle_counter; + let out: u64 = handle_counter; handle_counter += 1; out.to_be_bytes().to_vec() }; @@ -331,9 +339,9 @@ async fn test_fhe_casts() -> Result<(), Box> { let app = setup_test_app().await?; let mut client = FhevmCoprocessorClient::connect(app.app_url().to_string()).await?; - let mut handle_counter = 0; + let mut handle_counter = random_handle_start(); let mut next_handle = || { - let out: i32 = handle_counter; + let out: u64 = handle_counter; handle_counter += 1; out.to_be_bytes().to_vec() }; @@ -466,9 +474,9 @@ async fn test_fhe_if_then_else() -> Result<(), Box> { let app = setup_test_app().await?; let mut client = FhevmCoprocessorClient::connect(app.app_url().to_string()).await?; - let mut handle_counter = 0; + let mut handle_counter = random_handle_start(); let mut next_handle = || { - let out: i32 = handle_counter; + let out: u64 = handle_counter; handle_counter += 1; out.to_be_bytes().to_vec() }; @@ -639,7 +647,7 @@ fn generate_binary_test_cases() -> Vec { } else { rhs <<= shift_by; } - let expected_output = compute_expected_binary_output(&lhs, &rhs, op, bits); + let expected_output = compute_expected_binary_output(&lhs, &rhs, op); let operand = op as i32; let fhe_bool_type = 0; let expected_output_type = if op.is_comparison() { @@ -692,7 +700,7 @@ fn generate_unary_test_cases() -> Vec { if op.op_type() == FheOperationType::Unary { let mut inp = BigInt::from(7); inp <<= shift_by; - let expected_output = compute_expected_unary_output(&inp, op, bits); + let expected_output = compute_expected_unary_output(&inp, op); let operand = op as i32; cases.push(UnaryOperatorTestCase { bits, @@ -708,115 +716,31 @@ fn generate_unary_test_cases() -> Vec { cases } -fn compute_expected_unary_output(inp: &BigInt, op: SupportedFheOperations, bits: i32) -> BigInt { +fn compute_expected_unary_output(inp: &BigInt, op: SupportedFheOperations) -> BigInt { match op { SupportedFheOperations::FheNot => { - // TODO: find how this is done appropriately in big int crate - match bits { - 8 => { - let inp: u8 = inp.try_into().unwrap(); - BigInt::from(inp.not()) - } - 16 => { - let inp: u16 = inp.try_into().unwrap(); - BigInt::from(inp.not()) - } - 32 => { - let inp: u32 = inp.try_into().unwrap(); - BigInt::from(inp.not()) - } - 64 => { - let inp: u64 = inp.try_into().unwrap(); - BigInt::from(inp.not()) - } - 128 => { - let inp: u128 = inp.try_into().unwrap(); - BigInt::from(inp.not()) - } - 160 | 256 => { - let (_, mut bytes) = inp.to_bytes_be(); - for byte in bytes.iter_mut() { - *byte = byte.not(); - } - BigInt::from(inp.not()) - } - other => { - panic!("unknown bits: {other}") - } + let (_, mut bytes) = inp.to_bytes_be(); + for byte in bytes.iter_mut() { + *byte = byte.not(); } + BigInt::from_bytes_be(bigdecimal::num_bigint::Sign::Plus, &bytes) } - SupportedFheOperations::FheNeg => match bits { - 8 => { - let inp: i8 = inp.try_into().unwrap(); - BigInt::from(-inp as u8) - } - 16 => { - let inp: i16 = inp.try_into().unwrap(); - BigInt::from(-inp as u16) - } - 32 => { - let inp: i32 = inp.try_into().unwrap(); - BigInt::from(-inp as u32) - } - 64 => { - let inp: i64 = inp.try_into().unwrap(); - BigInt::from(-inp as u64) - } - 128 => { - let inp: i128 = inp.try_into().unwrap(); - BigInt::from(-inp as u128) - } - 160 | 256 => { - inp * -1 - } - other => { - panic!("unknown bits: {other}") + SupportedFheOperations::FheNeg => { + let (_, mut bytes) = inp.to_bytes_be(); + for byte in bytes.iter_mut() { + *byte = byte.not(); } + let num = BigInt::from_bytes_be(bigdecimal::num_bigint::Sign::Plus, &bytes); + num + 1 }, - other => panic!("unsupported binary operation: {:?}", other), + other => panic!("unsupported unary operation: {:?}", other), } } -fn rotate_left_big_int(inp: &BigInt, rot_by: u32) -> BigInt { - let mut new_num = inp.clone(); - let mut idx_vec = Vec::new(); - for bit in 0..inp.bits() { - idx_vec.push(bit); - } - idx_vec.rotate_left(rot_by as usize); - for bit in 0..inp.bits() { - new_num.set_bit(idx_vec[bit as usize], inp.bit(bit)); - } - new_num -} - -fn rotate_right_big_int(inp: &BigInt, rot_by: u32) -> BigInt { - let mut new_num = inp.clone(); - let mut idx_vec = Vec::new(); - for bit in 0..inp.bits() { - idx_vec.push(bit); - } - idx_vec.rotate_right(rot_by as usize); - for bit in 0..inp.bits() { - new_num.set_bit(idx_vec[bit as usize], inp.bit(bit)); - } - new_num -} - -#[test] -fn big_int_rotation() { - let the_int = BigInt::from(22); - let left_rot: u8 = rotate_left_big_int(&the_int, 1).try_into().unwrap(); - let right_rot: u8 = rotate_right_big_int(&the_int, 1).try_into().unwrap(); - assert_eq!(left_rot, 13); - assert_eq!(right_rot, 11); -} - fn compute_expected_binary_output( lhs: &BigInt, rhs: &BigInt, op: SupportedFheOperations, - bits: i32, ) -> BigInt { match op { SupportedFheOperations::FheEq => BigInt::from(lhs.eq(rhs)), @@ -837,74 +761,10 @@ fn compute_expected_binary_output( SupportedFheOperations::FheBitXor => lhs ^ rhs, SupportedFheOperations::FheShl => lhs << (TryInto::::try_into(rhs).unwrap()), SupportedFheOperations::FheShr => lhs >> (TryInto::::try_into(rhs).unwrap()), - SupportedFheOperations::FheRotl => match bits { - 8 => BigInt::from( - TryInto::::try_into(lhs) - .unwrap() - .rotate_left(TryInto::::try_into(rhs).unwrap()), - ), - 16 => BigInt::from( - TryInto::::try_into(lhs) - .unwrap() - .rotate_left(TryInto::::try_into(rhs).unwrap()), - ), - 32 => BigInt::from( - TryInto::::try_into(lhs) - .unwrap() - .rotate_left(TryInto::::try_into(rhs).unwrap()), - ), - 64 => BigInt::from( - TryInto::::try_into(lhs) - .unwrap() - .rotate_left(TryInto::::try_into(rhs).unwrap()), - ), - 128 => BigInt::from( - TryInto::::try_into(lhs) - .unwrap() - .rotate_left(TryInto::::try_into(rhs).unwrap()), - ), - 160 | 256 => { - let rot_by = TryInto::::try_into(rhs).unwrap(); - rotate_left_big_int(lhs, rot_by) - } - other => { - panic!("unsupported bits for rotl: {other}") - } - }, - SupportedFheOperations::FheRotr => match bits { - 8 => BigInt::from( - TryInto::::try_into(lhs) - .unwrap() - .rotate_right(TryInto::::try_into(rhs).unwrap()), - ), - 16 => BigInt::from( - TryInto::::try_into(lhs) - .unwrap() - .rotate_right(TryInto::::try_into(rhs).unwrap()), - ), - 32 => BigInt::from( - TryInto::::try_into(lhs) - .unwrap() - .rotate_right(TryInto::::try_into(rhs).unwrap()), - ), - 64 => BigInt::from( - TryInto::::try_into(lhs) - .unwrap() - .rotate_right(TryInto::::try_into(rhs).unwrap()), - ), - 128 => BigInt::from( - TryInto::::try_into(lhs) - .unwrap() - .rotate_left(TryInto::::try_into(rhs).unwrap()), - ), - 160 | 256 => { - let rot_by = TryInto::::try_into(rhs).unwrap(); - rotate_right_big_int(lhs, rot_by) - } - other => { - panic!("unsupported bits for rotr: {other}") - } - }, + // we don't shift by as much as to overlap the register + // in tests, so should be same as bit shifts + SupportedFheOperations::FheRotl => lhs << (TryInto::::try_into(rhs).unwrap()), + SupportedFheOperations::FheRotr => lhs >> (TryInto::::try_into(rhs).unwrap()), other => panic!("unsupported binary operation: {:?}", other), } } diff --git a/fhevm-engine/coprocessor/src/tests/utils.rs b/fhevm-engine/coprocessor/src/tests/utils.rs index c6ff6ec3..9ff9e392 100644 --- a/fhevm-engine/coprocessor/src/tests/utils.rs +++ b/fhevm-engine/coprocessor/src/tests/utils.rs @@ -4,9 +4,9 @@ use testcontainers::{core::WaitFor, runners::AsyncRunner, GenericImage, ImageExt pub struct TestInstance { // just to destroy container - _container: testcontainers::ContainerAsync, + _container: Option>, // send message to this on destruction to stop the app - app_close_channel: tokio::sync::watch::Sender, + app_close_channel: Option>, app_url: String, db_url: String, } @@ -14,7 +14,9 @@ pub struct TestInstance { impl Drop for TestInstance { fn drop(&mut self) { println!("Shutting down the app with signal"); - let _ = self.app_close_channel.send_replace(true); + if let Some(chan) = &self.app_close_channel { + let _ = chan.send_replace(true); + } } } @@ -37,6 +39,23 @@ pub fn default_tenant_id() -> i32 { } pub async fn setup_test_app() -> Result> { + if std::env::var("COPROCESSOR_TEST_LOCALHOST").is_ok() { + setup_test_app_existing_localhost().await + } else { + setup_test_app_custom_docker().await + } +} + +pub async fn setup_test_app_existing_localhost() -> Result> { + Ok(TestInstance { + _container: None, + app_close_channel: None, + app_url: "http://127.0.0.1:50051".to_string(), + db_url: "postgresql://postgres:postgres@127.0.0.1:5432/coprocessor".to_string(), + }) +} + +pub async fn setup_test_app_custom_docker() -> Result> { static PORT_COUNTER: AtomicU16 = AtomicU16::new(10000); let app_port = PORT_COUNTER.fetch_add(1, Ordering::SeqCst); @@ -103,8 +122,8 @@ pub async fn setup_test_app() -> Result tokio::time::sleep(tokio::time::Duration::from_millis(500)).await; Ok(TestInstance { - _container: container, - app_close_channel, + _container: Some(container), + app_close_channel: Some(app_close_channel), app_url: format!("http://127.0.0.1:{app_port}"), db_url, }) diff --git a/fhevm-engine/fhevm-engine-common/src/tfhe_ops.rs b/fhevm-engine/fhevm-engine-common/src/tfhe_ops.rs index f81893b6..18370136 100644 --- a/fhevm-engine/fhevm-engine-common/src/tfhe_ops.rs +++ b/fhevm-engine/fhevm-engine-common/src/tfhe_ops.rs @@ -433,7 +433,7 @@ pub fn validate_fhe_type(input_type: i32) -> Result<(), FhevmError> { .try_into() .or(Err(FhevmError::UnknownFheType(input_type)))?; match i16_type { - 0 | 2 | 3 | 4 | 5 => Ok(()), + 0 | 2 | 3 | 4 | 5 | 6 | 7 | 8 => Ok(()), _ => Err(FhevmError::UnknownFheType(input_type)), } }