bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 25쪽
ervices.
Furthermore we observe that it is possible to implement payment to a Gateway service through the KMS blockchain, thus incentivizing such a service to be honest and reliable.
The Gateway Service consists of two different Connectors in order to decouple a specific FHEVM from a specific KMS. This will make it simpler to roll new blockchain protocols on either the FHEVM or KMS side without requiring modifications to the Gateway, but instead only require the writing of new Connectors.
# getting\_started
# Quick start
For FHEVM-native, to start the setup, you can use our [demo repository](https://github.com/zama-ai/fhevm-L1-demo). Note that, at the time of writing, the demo repository doesn't yet use the FHEVM-native model that is implemented here - instead, it uses the FHEVM-native implementation that uses precompiles (instead of symbolic execution) and FHE computation is done inside geth (as opposed to an external Executor we have here).
For FHEVM-coprocessor, please look at the coprocessor section of the getting started guide.
# gateway
# Configuration
The gateway acts as a bridge between the execution layer and the Threshold Key Management System (TKMS). Due to its central role, it needs to be properly configured. This document details all the environment variables and gives an example of docker compose to run the gateway.
## Dependencies
* **Zama Gateway**: Depends on **FHEVM** and **Gateway KV Store**, which is initialized with the **Zama KMS** Docker Compose command. Therefore, this is the *last* Docker Compose command that should be run.
## Prerequisites
* **Docker 26+** installed on your system.
* **FHEVM** validator running and configured.
* **TKMS** running and configured.
## Configuring Docker Compose Environment Variables
### Example Docker Compose for Zama Gateway
```yaml
name: zama-gateway
services:
gateway:
image: ghcr.io/zama-ai/kms-blockchain-gateway-dev:latest
command:
- "gateway"
environment:
- GATEWAY__ETHEREUM__CHAIN_ID=9000
- GATEWAY__ETHEREUM__LISTENER_TYPE=FHEVM_V1_1
- GATEWAY__ETHEREUM__WSS_URL=ws://fhevm-validator:8546
- GATEWAY__ETHEREUM__HTTP_URL=http://fhevm-validator:8545
- GATEWAY__ETHEREUM__FHE_LIB_ADDRESS=000000000000000000000000000000000000005d
- GATEWAY__ETHEREUM__ORACLE_PREDEPLOY_ADDRESS=c8c9303Cd7F337fab769686B593B87DC3403E0ce
- GATEWAY__KMS__ADDRESS=http://kms-validator:9090
- GATEWAY__KMS__KEY_ID=408d8cbaa51dece7f782fe04ba0b1c1d017b1088
- GATEWAY__STORAGE__URL=http://gateway-store:8088
- ASC_CONN__BLOCKCHAIN__ADDRESSES=http://kms-validator:9090
- GATEWAY__ETHEREUM__RELAYER_KEY=7ec931411ad75a7c201469a385d6f18a325d4923f9f213bd882bbea87e160b67
```
**Zama Gateway** requires several specific configurations as shown in the provided `docker-compose-gateway.yml` file.
| Variable | Description | Default Value |
| ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| GATEWAY\_\_ETHEREUM\_\_CHAIN\_ID | Chain ID for FHEVM | 9000 |
| GATEWAY\_\_ETHEREUM\_\_LISTENER\_TYPE | Listener type for Ethereum gateway | FHEVM\_V1\_1 |
| GATEWAY\_\_ETHEREUM\_\_WSS\_URL | WebSocket URL for FHEVM Ethereum. You need to run FHEVM first and set this data | ws\://localhost:9090 |
| GATEWAY\_\_ETHEREUM\_\_FHE\_LIB\_ADDRESS | FHE library address for Ethereum gateway. This should be obtained from FHEVM once it is running and configured | 000000000000000000000000000000000000005d |
| GATEWAY\_\_ETHEREUM\_\_ORACLE\_PREDEPLOY\_ADDRESS | Oracle predeploy contract address for FHEVM gateway | c8c9303Cd7F337fab769686B593B87DC3403E0cd |
| GATEWAY\_\_KMS\_\_ADDRESS | Address for KMS gateway | <http://localhost:9090> |
| GATEWAY\_\_KMS\_\_KEY\_ID | Key ID for KMS gateway. Refer to the [How to Obtain KMS Key ID](#kms-key-id) section | 04a1aa8ba5e95fb4dc42e06add00b0c2ce3ea424 |
| GATEWAY\_\_STORAGE\_\_URL | URL for storage gateway | <http://localhost:8088> |
| ASC\_CONN\_\_BLOCKCHAIN\_\_ADDRESSES | Blockchain addresses for ASC connection. Same as `GATEWAY__KMS__ADDRESS` | <http://localhost:9090> |
| GATEWAY\_\_ETHEREUM\_\_RELAYER\_KEY | Private key of the relayer | 7ec931411ad75a7c201469a385d6f18a325d4923f9f213bd882bbea87e160b67 |
## Steps for Running
1. Run the **Zama Gateway** Docker Compose:
```bash
docker compose -f docker-compose-gateway.yml up -d
```
> :warning: **Requirement**: At start, the Gateway will try to connect to the websocker URL `GATEWAY__ETHEREUM__WSS_URL`. Ensure it is running and the port is opened.
## KMS Key ID
To obtain the `Key ID` for the `GATEWAY__KMS__KEY_ID` environment variable, run the following command:
```bash
> docker run -ti ghcr.io/zama-ai/kms-service-dev:latest ls keys/PUB/PublicKey
04a1aa8ba5e95fb4dc42e06add00b0c2ce3ea424 8e917efb2fe00ebbe8f73b2ba2ed80e7e28970de
```
# tkms
# Application Smart Contract
# Request the creation of a new private key
Generating a new set of keys and crs is necessary when creating a new FHE Co-processor.
To do so one can use the TKMS cli tool packaged in the following [docker image](https://github.com/orgs/zama-ai/packages/container/package/kms-blockchain-simulator).
The configuration file of the CLI will need to be modified or mounted to a volume accessible within the Docker container. The accessible/modified file must include:
```{toml}
s3_endpoint = ""
object_folder = ["","","",""]
validator_addresses = [""]
http_validator_endpoints = [""]
kv_store_address = ""
faucet_address = ""
asc_address = ""
csc_address = ""
mnemonic = ""
```
## Key generation
### "Insecure"
Insecure key generation is the fastest way to generate a new key. The key is generated by a single party and shared with the other parties. Hence it is not directly insecure, but instead only generated with a centralized trust assumption.
```{bash}
cargo run -- -f <path-to-toml-config-file> insecure-key-gen
```
### "Secure"
Secure key generation takes a lot longer and is a two step process. For development purposes insecure key generation is the recommended way since it is much faster.
This will do some pre-processing needed for key-generation. The pre-processing id will be needed to then launch a distributed key generation.
```{bash}
cargo run -- -f <path-to-toml-config-file> preproc-key-gen
cargo run -- -f <path-to-toml-config-file> key-gen --preproc-id <preprocessing-id>
```
## Common-Reference-String (CRS) generation
The CRS is a public object used to generate zero-knowledge-proofs of plaintext knowledge (required to add a new ciphertext). The `max-num-bits` argument specifies the maximum number of bits provable with a given CRS, usually 2048 is used, since this is the size of the largest data-type currently supported.
### "Insecure"
As for the insecure key-generation this operation will be done by a single party.
```{bash}
cargo run -- -f <path-to-toml-config-file> insecure-crs-gen --max-num-bits <max-num-bits>
```
### "Secure"
This will launch a distributed CRS generation.
```{bash}
cargo run -- -f <path-to-toml-config-file> crs-gen --max-num-bits <max-num-bits>
```
# Run a KMS
# Use Zama's TKMS
# fhevm
# coprocessor
# Configuration
## Coprocessor Backend
### Database
Some settings of the Coprocessor backend are configured by inserting entries in the PostgreSQL DB.
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](https://github.com/zama-ai/fhevm/blob/release/0.10.x/coprocessor/fhevm-engine/coprocessor/migrations/20240722111257_coprocessor.sql).
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:
| Field | Description |
| ---------------------------- | -------------------------------------------------- |
| tenant\_id | unique tenant identifier |
| tenant\_api\_key | an API key that authenticates access to the server |
| chain\_id | the chain ID of the chain this tenant operates on |
| verifying\_contract\_address | address of the InputVerifier contract |
| acl\_contract\_address | address of the ACL contract |
| pks\_key | a serialization of the FHE public key |
| sks\_key | a serialization of the FHE server key |
| public\_params | a serialization of the CRS public params |
| cks\_key | optional secret FHE key, for debugging only |
| is\_admin | if tenant is an administrator |
### Command Line
You can use the `--help` command line switch on the coprocessor to get a help screen as follows:
```
coprocessor --help
Usage: coprocessor [OPTIONS]
Options:
--run-server
Run the API server
--run-bg-worker
Run the background worker
--generate-fhe-keys
Generate fhe keys and exit
--server-maximum-ciphertexts-to-schedule <SERVER_MAXIMUM_CIPHERTEXTS_TO_SCHEDULE>
Server maximum ciphertexts to schedule per batch [default: 5000]
--server-maximum-ciphertexts-to-get <SERVER_MAXIMUM_CIPHERTEXTS_TO_GET>
Server maximum ciphertexts to serve on get_cihpertexts endpoint [default: 5000]
--work-items-batch-size <WORK_ITEMS_BATCH_SIZE>
Work items batch size [default: 10]
--tenant-key-cache-size <TENANT_KEY_CACHE_SIZE>
Tenant key cache size [default: 32]
--maximimum-compact-inputs-upload <MAXIMIMUM_COMPACT_INPUTS_UPLOAD>
Maximum compact inputs to upload [default: 10]
--maximum-handles-per-input <MAXIMUM_HANDLES_PER_INPUT>
Maximum compact inputs to upload [default: 255]
--coprocessor-fhe-threads <COPROCESSOR_FHE_THREADS>
Coprocessor FHE processing threads [default: 8]
--tokio-threads <TOKIO_THREADS>
Tokio Async IO threads [default: 4]
--pg-pool-max-connections <PG_POOL_MAX_CONNECTIONS>
Postgres pool max connections [default: 10]
--server-addr <SERVER_ADDR>
Server socket address [default: 127.0.0.1:50051]
--metrics-addr <METRICS_ADDR>
Prometheus metrics server address [default: 0.0.0.0:9100]
--database-url <DATABASE_URL>
Postgres database url. If unspecified DATABASE_URL environment variable is used
--coprocessor-private-key <COPROCESSOR_PRIVATE_KEY>
Coprocessor private key file path. Private key is in plain text 0x1234.. format [default: ./coprocessor.key]
--service-name <SERVICE_NAME>
Coprocessor service name in OTLP traces [default: coprocessor]
-h, --help
Print help
-V, --version
Print version
```
#### Threads
Note that there are two thread pools in the Coprocessor backend:
* tokio
* FHE compute
The tokio one (set via `--tokio-threads`) determines how many tokio threads are spawned. These threads are used for async tasks and should not be blocked.
The FHE compute threads are the ones that actually run the FHE computation (set via `--coprocessor-fhe-threads`).
#### Secret Signing Key
A secret signing key is needed to allow the Coprocessor backend sign input insertion requests. A `coprocessor.key` file can be given on the command line for the **server** as:
```
coprocessor --help
Usage: coprocessor [OPTIONS]
Options:
...
--coprocessor-private-key <COPROCESSOR_PRIVATE_KEY>
Coprocessor private key file path. Private key is in plain text 0x1234.. format [default: ./coprocessor.key]
```
The secret signing key must be kept safe when operating the Coprocessor.
# Coprocessor Backend
A Coprocesor backend is needed to run alongside the geth node. The Coprocessor backend executes the actual FHE computation. Please look at [FHE Computation](/protocol/solidity-guides/v0.10/coprocessor/docs/fundamentals/fhevm/coprocessor/fhe_computation) for more info.
The coprocessor backend is implemented in the [Coprocessor](https://github.com/zama-ai/fhevm/blob/release/0.10.x/coprocessor/fhevm-engine/coprocessor/README.md) directory of `fhevm-engine`.
It consists of the following components:
* **listeners** that propagate events to the DB and Gateway,
* **server** that handles:
* input insertion requests to the DB from the Gateway
* FHE ciphertext read requests from the Gateway
* **PostgreSQL DB** for storing computation requests and FHE ciphertexts
* **worker** that reads comoutation requests from the DB, does the FHE computation and inserts result FHE ciphertexts into the DB
The server and the worker can be run as separate processes or as a single process. In both cases they communicate with one another through the DB.
The Coprocessor backend supports **multi-tenancy** in the sense that it can perform FHE computation for separate host blockchains, under different FHE keys.
You can use pre-generated Docker images for the Coprocessor backend node or build them yourself as described in the [README](https://github.com/zama-ai/fhevm/blob/release/0.10.x/coprocessor/fhevm-engine/coprocessor/README.md).
# native
# Configuration
At the time of writing, FHEVM-native is still not fully implemented, namely the geth integration is not done. Configuration settings will be listed here when they are implemented.
## Executor
The Executor is configured via command line switches and environment variables, e.g.:
```
executor --help
Usage: executor [OPTIONS]
Options:
--tokio-threads <TOKIO_THREADS> [default: 4]
--fhe-compute-threads <FHE_COMPUTE_THREADS> [default: 8]
--policy-fhe-compute-threads <POLICY_FHE_COMPUTE_THREADS> [default: 8]
--server-addr <SERVER_ADDR> [default: 127.0.0.1:50051]
-h, --help Print help
-V, --version
```
### Threads
Note that there are three thread pools in the Executor:
* tokio
* FHE compute
* policy FHE compute
The tokio one (set via `--tokio-threads`) determines how many tokio threads are spawned. These threads are used for async tasks and should not be blocked.
The FHE compute threads are the ones that actually run the FHE computation by default (set via `--fhe-compute-threads`).
If an non-default scheduling policy is being used, the policy FHE compute threads are being used (set via `--policy-fhe-compute-threads`).
### Scheduling Policies
Different scheduling policies can be set for FHE computation via the `FHEVM_DF_SCHEDULE` environment variable with possible choices: **LOOP**, **FINE\_GRAIN**, **MAX\_PARALLELISM**, **MAX\_LOCALITY**.
# Executor
An FHEVM-native node consists of the following components:
* full node/validator node
* Executor service
More detailed description of the architecture and FHE execution can be found in [Architecture](/protocol/solidity-guides/v0.10/coprocessor/docs/fundamentals/fhevm/native/architecture) and [FHE Computation](/protocol/solidity-guides/v0.10/coprocessor/docs/fundamentals/fhevm/native/fhe_computation).
The Executor service is a gRPC server that accepts FHE computation requests from the full node/validator node and executes them. It is implemented in the [executor](https://github.com/zama-ai/fhevm/blob/release/0.10.x/coprocessor/fhevm-engine/executor/README.md) directory of `fhevm-engine`.
At the time of writing, the [geth](/protocol/solidity-guides/v0.10/coprocessor/docs/getting_started/fhevm/native/geth) implementation is not yet implemented.
The Executor is almost fully functional. We don't yet provide Docker images for it, but it can be built as a normal Rust project.
# Integration
This document is a guide listing detailed steps to integrate `FHEVM-backend` into [go-ethereum](https://github.com/ethereum/go-ethereum) or any other implementations that follow the same architecture.
{% hint style="info" %}
This document is based on go-ethereum v1.13.5
{% endhint %}
An FHEVM-native node consists of the following components:
* full node/validator node
* Executor service
At the time of writing, the geth full node/validator node is not yet implemented. The [Executor](/protocol/solidity-guides/v0.10/coprocessor/docs/getting_started/fhevm/native/executor) is almost fully functional.
# guides
# Run a benchmark
# Node and gateway hardware
## FHEVM validator
Validators perform all operations on ciphertext, which requires powerful machines. FHE computations benefit from multi-threading, so we recommend using [hpc7a](https://aws.amazon.com/fr/ec2/instance-types/hpc7a/) instances or equivalent, with at least 48 physical cores.
## Gateway
The gateway can run on a medium machine with 4 cores and 8 GB of RAM, such as a [t3.xlarge](https://aws.amazon.com/ec2/instance-types/t3/).
## TKMS
The TKMS needs to carry out heavy cryptographic operations on the ciphertexts. We recommend using at least a [c5.4xlarge](https://aws.amazon.com/ec2/instance-types/c5/) instance or equivalent, with at least 16 physical cores.
# references
# FHEVM API specifications
# Gateway API Specifications
## Endpoints
<details>
<summary>GET /keyurl ---- Retrieve links for retrieving the public keys and CRS' in the system.</summary>
**Description**
This endpoint returns a JSON object containing URLs from an S3 bucket, allowing the client to download key files such as the blockchain public key, CRS files for input proof generation, the bootstrap key, and the address and public verification keys for each of the MPC servers running the TKMS.
For each file (with the exception of the verification key and address), a list of cryptographic signatures is provided to ensure the integrity and authenticity of the downloaded content. These signatures should be considered as a multi-sig. This means that instead of needing all the signatures to validate the content, only a subset, specifically >1/3 of the total signatures (if n nodes are signing), is required to verify that the content is legitimate.
No query parameters are required, as the gateway is already preconfigured for a specific blockchain.
**Query Parameters**
No parameters.
**Headers**
None.
**Response**
**Success (200 OK)**
The request is successful, and the response will include a JSON object with a `status` and a `response`. The response again consists of the following elements:
* `crs`: A map of containing information on the different CRS'. The key of the map is the max amount of bits the CRS can support proofs for. The value is an object of the following elements for the given CRS:
* `data_id`: The 20 byte (lower-case) hex encoded handle/ID identifying the CRS.
* `param_choice`: An integer representing the choice of parameters for the public key to be used with the CRS.
* `signatures`: A list of signatures (one from each MPC party constituting the TKMS backend). Each signature is a hex (lower-case) encoded EIP712 signature on the `safe_serialization` of `PublicParam<Bls12_446>`.
* `urls`: A list of URLs where the data can be fetched. The data at the end-point is a `safe_serialization` of `PublicParam<Bls12_446>`.
* `fhe_key_info`: A list of objects, each representing information on a key-set in the system. More specifically each element consists of the following:
* `fhe_public_key`: An element which contains information about the public encryption key of a FHE key set. More specifically it consists of the following elements:
* `data_id`: The 20 byte (lower-case) hex encoded handle/ID identifying the key.
* `param_choice`: An integer representing the choice of parameters used to generate the key.
* `signatures`: A list of signatures (one from each MPC party constituting the TKMS backend). Each signature is a hex (lower-case) encoded EIP712 signature on the `safe_serialization` of `CompactPublicKey`.
* `urls`: A list of URLs where the data can be fetched. The data at the end-point is a `safe_serialization` of `CompactPublicKey`.
* `fhe_server_key`: An element which contains information about the server key (the key used to perform FHE operations on ciphertexts) of a FHE key set. More specifically it consists of the following elements:
* `data_id`: The 20 byte (lower-case) hex encoded handle/ID identifying the key.
* `param_choice`: An integer representing the choice of parameters used to generate the key.
* `signatures`: A list of signatures (one from each MPC party constituting the TKMS backend). Each signature 프로젝트로 돌아가기