Skip to content

Commit acfa977

Browse files
dartdart26obatirou
andauthored
refactor(coprocessor): remove tenants notion from DB and related code (#1856)
Replace with: * keys table - containing FHE keys * crs table - containing the CRS * host_chains table - containing host chain info Rationale is: * the fact that we now have only one FHE keychain (that can have multiple FHE keys) * CRS and keys can be changed independently via events from the GW * we want to support multiple host chains * we want to remove remains of previous design with tenants, IDs, tenant API keys, etc. We also simplify code where it no longer needs tenants, chain IDs, etc. Co-authored-by: Oba <obatirou@gmail.com>
1 parent ca9e6eb commit acfa977

File tree

181 files changed

+3267
-3933
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+3267
-3933
lines changed

.devcontainer/post_create_command.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -euo pipefail
44

55
# Package manager dependencies.
66
sudo apt update
7-
sudo apt install -y protobuf-compiler build-essential libssl-dev pkg-config openssl vim git-lfs
7+
sudo apt install -y protobuf-compiler build-essential libssl-dev pkg-config openssl vim git-lfs postgresql-client cmake
88

99
# Cargo dependencies.
1010
cargo install sqlx-cli

.github/workflows/test-suite-e2e-tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ jobs:
241241
echo "::group::Gateway Listener"
242242
./fhevm-cli logs coprocessor-gw-listener
243243
echo "::endgroup::"
244+
echo "::group::ZKProof Worker"
245+
./fhevm-cli logs coprocessor-zkproof-worker
246+
echo "::endgroup::"
247+
echo "::group::TFHE Worker"
248+
./fhevm-cli logs coprocessor-tfhe-worker
249+
echo "::endgroup::"
244250
245251
- name: Cleanup
246252
working-directory: test-suite/fhevm

charts/coprocessor/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: coprocessor
22
description: A helm chart to distribute and deploy Zama fhevm Co-Processor services
3-
version: 0.7.13
3+
version: 0.8.0
44
apiVersion: v2
55
keywords:
66
- fhevm

charts/coprocessor/templates/coprocessor-init-config.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ data:
1212
create-secrets.sh: |
1313
#!/bin/sh
1414
set -e
15-
API_KEY_SECRET_NAME="{{ .Values.config.apiKey.secret.name }}"
16-
API_KEY_SECRET_KEY="{{ .Values.config.apiKey.secret.key }}"
17-
if ! kubectl get secret ${API_KEY_SECRET_NAME}; then
18-
COPROCESSOR_API_KEY_VALUE=$(uuidgen)
19-
kubectl create secret generic ${API_KEY_SECRET_NAME} --from-literal ${API_KEY_SECRET_KEY}=${COPROCESSOR_API_KEY_VALUE}
20-
else
21-
echo "skipping: secret ${API_KEY_SECRET_NAME} already exists" 2>&1
22-
fi
2315
apk update && apk add openssl
2416
COPROCESSOR_KEY_SECRET_NAME="{{ .Values.config.coprocessorKey.secret.name }}"
2517
COPROCESSOR_KEY_SECRET_KEY="{{ .Values.config.coprocessorKey.secret.key }}"

charts/coprocessor/values.yaml

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ config:
3030
name: coprocessor-key
3131
key: coprocessor.hex
3232

33-
# API key for tenant authentication
34-
apiKey:
35-
secret:
36-
name: coprocessor-api-key
37-
key: coprocessor-api-key
38-
3933
# Database connection configuration
4034
database:
4135
secret:
@@ -82,11 +76,6 @@ dbMigration:
8276
secretKeyRef:
8377
name: coprocessor-db-url
8478
key: coprocessor-db-url
85-
- name: TENANT_API_KEY
86-
valueFrom:
87-
secretKeyRef:
88-
name: coprocessor-api-key
89-
key: coprocessor-api-key
9079

9180
serviceAccountName:
9281

@@ -130,16 +119,10 @@ hostListener:
130119
secretKeyRef:
131120
name: coprocessor-db-url
132121
key: coprocessor-db-url
133-
- name: TENANT_API_KEY
134-
valueFrom:
135-
secretKeyRef:
136-
name: coprocessor-api-key
137-
key: coprocessor-api-key
138122

139123
# Command line arguments for the host listener
140124
args:
141125
- --database-url=$(DATABASE_URL)
142-
- --coprocessor-api-key=$(TENANT_API_KEY)
143126
- --url=$(ETHEREUM_RPC_URL)
144127
- --acl-contract-address=$(ACL_CONTRACT_ADDRESS)
145128
- --tfhe-contract-address=$(FHEVM_EXECUTOR_CONTRACT_ADDRESS)
@@ -235,17 +218,11 @@ hostListenerPoller:
235218
secretKeyRef:
236219
name: coprocessor-db-url
237220
key: coprocessor-db-url
238-
- name: TENANT_API_KEY
239-
valueFrom:
240-
secretKeyRef:
241-
name: coprocessor-api-key
242-
key: coprocessor-api-key
243221

244222
# Command line arguments for the host listener poller
245223
args:
246224
### Required parameters
247225
- --database-url=$(DATABASE_URL)
248-
- --coprocessor-api-key=$(TENANT_API_KEY)
249226
- --url=$(ETHEREUM_RPC_HTTP_URL)
250227
- --acl-contract-address=$(ACL_CONTRACT_ADDRESS)
251228
- --tfhe-contract-address=$(FHEVM_EXECUTOR_CONTRACT_ADDRESS)
@@ -340,17 +317,11 @@ hostListenerCatchupOnly:
340317
secretKeyRef:
341318
name: coprocessor-db-url
342319
key: coprocessor-db-url
343-
- name: TENANT_API_KEY
344-
valueFrom:
345-
secretKeyRef:
346-
name: coprocessor-api-key
347-
key: coprocessor-api-key
348320

349321
# Command line arguments for the host listener catchup only mode
350322
# NOTE: --only-catchup-loop requires --end-at-block to be set
351323
args:
352324
- --database-url=$(DATABASE_URL)
353-
- --coprocessor-api-key=$(TENANT_API_KEY)
354325
- --url=$(ETHEREUM_RPC_URL)
355326
- --acl-contract-address=$(ACL_CONTRACT_ADDRESS)
356327
- --tfhe-contract-address=$(FHEVM_EXECUTOR_CONTRACT_ADDRESS)
@@ -535,15 +506,8 @@ tfheWorker:
535506
secretKeyRef:
536507
name: coprocessor-db-url
537508
key: coprocessor-db-url
538-
- name: TENANT_API_KEY
539-
valueFrom:
540-
secretKeyRef:
541-
name: coprocessor-api-key
542-
key: coprocessor-api-key
543509
- name: ACL_CONTRACT_ADDRESS
544510
value: "0x05fD9B5EFE0a996095f42Ed7e77c390810CF660c"
545-
- name: INPUT_VERIFIER_ADDRESS
546-
value: "0xa1880e99d86F081E8D3868A8C4732C8f65dfdB11"
547511

548512
# Command line arguments for TFHE worker
549513
args:
@@ -552,7 +516,7 @@ tfheWorker:
552516
- --worker-polling-interval-ms=10000
553517
- --work-items-batch-size=100 # scheduling changed
554518
- --dependence-chains-per-batch=100 # Deprecated. To be removed in a future release.
555-
- --tenant-key-cache-size=32
519+
- --key-cache-size=32
556520
- --coprocessor-fhe-threads=64 # scheduling changed
557521
- --tokio-threads=16 # scheduling changed
558522
- --pg-pool-max-connections=10
@@ -794,16 +758,10 @@ snsWorker:
794758
secretKeyRef:
795759
name: coprocessor-db-url
796760
key: coprocessor-db-url
797-
- name: TENANT_API_KEY
798-
valueFrom:
799-
secretKeyRef:
800-
name: coprocessor-api-key
801-
key: coprocessor-api-key
802761

803762
# Command line arguments for SNS worker
804763
args:
805764
- --database-url=$(DATABASE_URL)
806-
- --tenant-api-key=$(TENANT_API_KEY)
807765
- --pg-listen-channels
808766
- event_pbs_computations
809767
- event_ciphertext_computed

coprocessor/docs/getting_started/fhevm/coprocessor/configuration.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,6 @@
22

33
## Coprocessor Backend
44

5-
### Database
6-
Some settings of the Coprocessor backend are configured by inserting entries in the PostgreSQL DB.
7-
8-
At the time of writing, we don't have a tool or automation for doing the configuration. The DB schema can be used as a reference, though: [schema](../../../../fhevm-engine/coprocessor/migrations/20240722111257_coprocessor.sql).
9-
10-
The `tenants` table contains a list of tenants that are using the Coprocessor backend. A tenant could be thought of as a separate blockchain (or a separate FHE key, i.e. using multiple FHE keys on a blockchain). The fields in `tenants` are:
11-
12-
| Field | Description |
13-
| -------------------------- | -------------------------------------------------- |
14-
| tenant_id | unique tenant identifier |
15-
| tenant_api_key | an API key that authenticates access to the server |
16-
| chain_id | the chain ID of the chain this tenant operates on |
17-
| verifying_contract_address | address of the InputVerifier contract |
18-
| acl_contract_address | address of the ACL contract |
19-
| pks_key | a serialization of the FHE public key |
20-
| sks_key | a serialization of the FHE server key |
21-
| public_params | a serialization of the CRS public params |
22-
| cks_key | optional secret FHE key, for debugging only |
23-
| is_admin | if tenant is an administrator |
24-
25-
265
### Command Line
276

287
You can use the `--help` command line switch on the coprocessor to get a help screen as follows:

coprocessor/fhevm-engine/.sqlx/query-10c2430d797e96b0b2a7a0f314b33b8b10e9cc8fd0422de69916674216b42f30.json renamed to coprocessor/fhevm-engine/.sqlx/query-010fa361eaab3fcabb474adf8f2514f2fed77910cf3b29ffe9d73536425c9853.json

Lines changed: 6 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coprocessor/fhevm-engine/.sqlx/query-040ce7f040af75604989d052ab8ee348bd56ac4513659a03d52557e4a188f2f6.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coprocessor/fhevm-engine/.sqlx/query-048212909e0bbe46633e404235d2c5cffb5284903adb757b4fda59b7fbe81d57.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coprocessor/fhevm-engine/.sqlx/query-06757014537fbb4ab31dcfed5c16d384585a31bac9856aad1be27f3170535731.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)