bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 41쪽
nd users to verify results cryptographically.
### Key lifecycle management
The KMS adheres to a formal key lifecycle, as per NIST SP 800-57:
| State | Description |
| -------------- | ------------------------------------------------------------------ |
| Pre-activation | Key is created but not in use. |
| Active | Key is used for encryption and decryption. |
| Suspended | Temporarily replaced during rotation. Still usable for decryption. |
| Deactivated | Archived; only used for decryption. |
| Compromised | Flagged for misuse; only decryption allowed. |
| Destroyed | Key material is deleted permanently. |
The KMS supports key switching using FHE, allowing ciphertexts to be securely transferred between keys during rotation. This maintains interoperability across key updates.
### Backup & recovery
In addition to robustness through MPC, the KMS also offers a custodial backup system:
* Each MPC node splits its key share into encrypted fragments, distributing them to independent custodians.
* If a share is lost, a quorum of custodians can collaboratively restore it, ensuring recovery even if several MPC nodes are offline.
* This approach guarantees business continuity and resilience against outages.
* All recovery operations require a quorum of operators and are fully auditable on-chain.
### Workflow example: Public decryption
1. A smart contract requests decryption via an oracle.
2. The Gateway verifies permissions (i.e. that the contract is allowed to decrypt the ciphertext) and emits an event.
3. KMS parties retrieve the ciphertext, verify it, and run the MPC decryption protocol to jointly compute the plaintext and sign their result.
4. Once a quorum agrees on the plaintext result, it is published (with signatures).
5. The oracle posts the plaintext back on-chain and contracts can verify the authenticity using the KMS signatures.
# FHE library
This document offers a high-level overview of the **FHEVM library**, helping you understand how it fits into the broader Zama Protocol. To learn how to use it in practice, see the [Solidity Guides](https://docs.zama.ai/protocol/solidity-guides).
## What is FHEVM library?
The FHEVM library enables developers to build smart contracts that operate on encrypted data—without requiring any knowledge of cryptography.
It extends the standard Solidity development flow with:
* Encrypted data types
* Arithmetic, logical, and conditional operations on encrypted values
* Fine-grained access control
* Secure input handling and attestation support
This library serves as an **abstraction layer** over Fully Homomorphic Encryption (FHE) and interacts seamlessly with off-chain components such as the **Coprocessors** and the **Gateway**.
## Key features
### Encrypted data types
The library introduces encrypted variants of common Solidity types, implemented as user-defined value types. Internally, these are represented as `bytes32` handles that point to encrypted values stored off-chain.
| Category | Types |
| ----------------- | ------------------------------------ |
| Booleans | `ebool` |
| Unsigned integers | `euint8`, `euint16`, ..., `euint256` |
| Signed integers | `eint8`, `eint16,` ..., `eint256` |
| Addresses | `eaddress` |
→ See the full guide of [Encrypted data types](https://docs.zama.ai/protocol/solidity-guides/smart-contract/types).
### FHE operations
Each encrypted type supports operations similar to its plaintext counterpart:
* Arithmetic: `add`, `sub`, `mul`, `div`, `rem`, `neg`
* Logic: `and`, `or`, `xor`, `not`
* Comparison: `lt`, `gt`, `le`, `ge`, `eq`, `ne`, `min`, `max`
* Bit manipulation: `shl`, `shr`, `rotl`, `rotr`
These operations are symbolically executed on-chain by generating new handles and emitting events for coprocessors to process the actual FHE computation off-chain.
Example:
```solidity
function compute(euint64 x, euint64 y, euint64 z) public returns (euint64) {
euint64 result = FHE.mul(FHE.add(x, y), z);
return result;
}
```
→ See the full guide of [Operations on encrypted types](https://docs.zama.ai/protocol/solidity-guides/smart-contract/operations).
### Branching with encrypted Conditions
Direct if or require statements are not compatible with encrypted booleans. Instead, the library provides a `select`operator to emulate conditional logic without revealing which branch was taken:
```solidity
ebool condition = FHE.lte(x, y);
euint64 result = FHE.select(condition, valueIfTrue, valueIfFalse);
```
This preserves confidentiality even in conditional logic.
→ See the full guide of [Branching](https://docs.zama.ai/protocol/solidity-guides/smart-contract/logics/conditions).
### Handling external encrypted inputs
When users want to pass encrypted inputs (e.g., values they’ve encrypted off-chain or bridged from another chain), they provide:
* external values
* A list of coprocessor signatures (attestation)
The function `fromExternal` is used to validate the attestation and extract a usable encrypted handle:
```solidity
function handleInput(externalEuint64 param1, externalEbool param2, bytes calldata attestation) public {
euint64 val = FHE.fromExternal(param1, attestation);
ebool flag = FHE.fromExternal(param2, attestation);
}
```
This ensures that only authorized, well-formed ciphertexts are accepted by smart contracts.
→ See the full guide of [Encrypted input](https://docs.zama.ai/protocol/solidity-guides/smart-contract/inputs).
### Access control
The FHE library also exposes methods for managing access to encrypted values using the ACL maintained by host contracts:
* `allow(handle, address)`: Grant persistent access
* `allowTransient(handle, address)`: Grant access for the current transaction only
* `allowForDecryption(handle)`: Make handle publicly decryptable
* `isAllowed(handle, address)`: Check if address has access
* `isSenderAllowed(handle)`: Shortcut for checking msg.sender permissions
These `allow` methods emit events consumed by the coprocessors to replicate the ACL state in the Gateway.
→ See the full guide of [ACL](https://docs.zama.ai/protocol/solidity-guides/smart-contract/acl).
### Pseudo-random encrypted values
The library allows generation of pseudo-random encrypted integers, useful for games, lotteries, or randomized logic:
* `randEuintXX()`
* `randEuintXXBounded`(uint bound)
These are deterministic across coprocessors and indistinguishable to external observers.
→ See the full guide of [Generate random number](https://docs.zama.ai/protocol/solidity-guides/smart-contract/operations/random).
# FHE on Blockchain
This section explains in depth the Zama Confidential Blockchain Protocol (Zama Protocol) and demonstrates how it can bring encrypted computation to smart contracts using Fully Homomorphic Encryption (FHE).
FHEVM is the core technology that powers the Zama Protocol. It is composed of the following key components.
<figure><img src="https://2354183879-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHSoe8yNdsakWMG6E3ITL%2Fuploads%2Fgit-blob-64b4536b1a1605b9ccd2d0293a7df06aa358b8d3%2FFHEVM.png?alt=media" alt=""><figcaption></figcaption></figure>
* [**FHEVM Solidity library**](/protocol/solidity-guides/v0.10/docs/protocol/architecture/library): Enables developers to write confidential smart contracts in plain Solidity using encrypted data types and operations.
* [**Host contracts**](/protocol/solidity-guides/v0.10/docs/protocol/architecture/hostchain) : Trusted on-chain contracts deployed on EVM-compatible blockchains. They manage access control and trigger off-chain encrypted computation.
* [**Coprocessors**](/protocol/solidity-guides/v0.10/docs/protocol/architecture/coprocessor) – Decentralized services that verify encrypted inputs, run FHE computations, and commit results.
* [**Gateway**](/protocol/solidity-guides/v0.10/docs/protocol/architecture/gateway) **–** The central orchestrator of the protocol. It validates encrypted inputs, manages access control lists (ACLs), bridges ciphertexts across chains, and coordinates coprocessors and the KMS.
* [**Key Management Service (KMS)**](/protocol/solidity-guides/v0.10/docs/protocol/architecture/kms) – A threshold MPC network that generates and rotates FHE keys, and handles secure, verifiable decryption.
* [**Relayer & oracle**](/protocol/solidity-guides/v0.10/docs/protocol/architecture/relayer_oracle) – A lightweight off-chain service that helps users interact with the Gateway by forwarding encryption or decryption requests.
# Relayer & Oracle
This document explains the service interface of the Zama Protocol - Relayer & Oracle.
## What is the Oracle?
The Oracle is an off-chain service that acts on behalf of smart contracts to retrieve decrypted values from the FHEVM protocol.
While the FHEVM protocol’s core components handle encryption, computation, and key management, Oracles and Relayers provide the necessary connectivity between users, smart contracts, and the off-chain infrastructure. They act as lightweight services that interface with the Gateway, enabling smooth interaction with encrypted values—without requiring users or contracts to handle complex integration logic.
These components are not part of the trusted base of the protocol; their actions are fully verifiable, and their misbehavior does not compromise confidentiality or correctness.
## Responsibilities of the Oracle
* Listen for on-chain decryption requests from contracts.
* Forward decryption requests to the Gateway on behalf of the contract.
* Wait for the KMS to produce signed plaintexts via the Gateway.
* Call back the contract on the host chain, passing the decrypted result.
Since the decrypted values are signed by the KMS, the receiving smart contract can verify the result, removing any needto trust the oracle itself.
## Security model of the Oracle
* Oracles are **untrusted**: they can only delay a request, not falsify it.
* All results are signed and verifiable on-chain.
If one oracle fails to respond, another can take over.
Goal: Enable contracts to access decrypted values asynchronously and securely, without embedding decryption logic.
## What is the Relayer?
The Relayer is a user-facing service that simplifies interaction with the Gateway, particularly for encryption and decryption operations that need to happen off-chain.
## Responsibilities of the Relayer
* Send encrypted inputs from the user to the Gateway for registration.
* Initiate user-side decryption requests, including EIP-712 authentication.
* Collect the response from the KMS, re-encrypted under the user’s public key.
* Deliver the ciphertext back to the user, who decrypts it locally in their browser/app.
This allows users to interact with encrypted smart contracts without having to run their own Gateway interface,\
validator, or FHE tooling.
## Security model of the Relayer
* Relayers are stateless and **untrusted**.
* All data flows are signed and auditable by the user.
* Users can always run their own relayer or interact with the Gateway directly if needed.
Goal: Make it easy for users to submit encrypted inputs and retrieve private decrypted results without managing infrastructure.
## How they fit in
* Smart contracts use the Oracle to receive plaintext results of encrypted computations via callbacks.
* Users rely on the Relayer to push encrypted values into the system and fetch personal decrypted results, all backed by EIP-712 signatures and FHE key re-encryption.
Together, Oracles and Relayers help bridge the gap between encrypted execution and application usability—without compromising security or decentralization.
# sdk-guides
# SUMMARY
* [Overview](/protocol/solidity-guides/v0.10/docs/sdk-guides/sdk-overview)
### FHEVM Relayer
* [Initialization](/protocol/solidity-guides/v0.10/docs/sdk-guides/initialization)
* [Input](/protocol/solidity-guides/v0.10/docs/sdk-guides/input)
* Decryption
* [User decryption](/protocol/solidity-guides/v0.10/docs/sdk-guides/user-decryption)
* [Public decryption](/protocol/solidity-guides/v0.10/docs/sdk-guides/public-decryption)
### Development Guide
* [Web applications](/protocol/solidity-guides/v0.10/docs/sdk-guides/webapp)
* [Debugging](/protocol/solidity-guides/v0.10/docs/sdk-guides/webpack)
* [CLI](/protocol/solidity-guides/v0.10/docs/sdk-guides/cli)
# Using the CLI
The `fhevm` Command-Line Interface (CLI) tool provides a simple and efficient way to encrypt data for use with the blockchain's Fully Homomorphic Encryption (FHE) system. This guide explains how to install and use the CLI to encrypt integers and booleans for confidential smart contracts.
## Installation
Ensure you have [Node.js](https://nodejs.org/) installed on your system before proceeding. Then, globally install the `@zama-fhe/relayer-sdk` package to enable the CLI tool:
```bash
npm install -g @zama-fhe/relayer-sdk
```
Once installed, you can access the CLI using the `relayer` command. Verify the installation and explore available commands using:
```bash
relayer help
```
## Encrypting Data
The CLI allows you to encrypt integers and booleans for use in smart contracts. Encryption is performed using the blockchain's FHE public key, ensuring the confidentiality of your data.
### Syntax
```bash
relayer encrypt --node <NODE_URL> <CONTRACT_ADDRESS> <USER_ADDRESS> <DATA:TYPE>...
```
* **`--node`**: Specifies the RPC URL of the blockchain node (e.g., `http://localhost:8545`).
* **`<CONTRACT_ADDRESS>`**: The address of the contract interacting with the encrypted data.
* **`<USER_ADDRESS>`**: The address of the user associated with the encrypted data.
* **`<DATA:TYPE>`**: The data to encrypt, followed by its type:
* `:64` for 64-bit integers
* `:1` for booleans
### Example Usage
Encrypt the integer `71721075` (64-bit) and the boolean `1` for the contract at `0x8Fdb26641d14a80FCCBE87BF455338Dd9C539a50` and the user at `0xa5e1defb98EFe38EBb2D958CEe052410247F4c80`:
```bash
relayer encrypt 0x8Fdb26641d14a80FCCBE87BF455338Dd9C539a50 0xa5e1defb98EFe38EBb2D958CEe052410247F4c80 71721075:64 1:1
```
# Setup
The use of `@zama-fhe/relayer-sdk` requires a setup phase. This consists of the instantiation of the `FhevmInstance`. This object holds all the configuration and methods needed to interact with an FHEVM using a Relayer. It can be created using the following code snippet:
```ts
import { createInstance } from "@zama-fhe/relayer-sdk";
const instance = await createInstance({
// ACL_CONTRACT_ADDRESS (FHEVM Host chain)
aclContractAddress: "0x687820221192C5B662b25367F70076A37bc79b6c",
// KMS_VERIFIER_CONTRACT_ADDRESS (FHEVM Host chain)
kmsContractAddress: "0x1364cBBf2cDF5032C47d8226a6f6FBD2AFCDacAC",
// INPUT_VERIFIER_CONTRACT_ADDRESS (FHEVM Host chain)
inputVerifierContractAddress: "0xbc91f3daD1A5F19F8390c400196e58073B6a0BC4",
// DECRYPTION_ADDRESS (Gateway chain)
verifyingContractAddressDecryption: "0xb6E160B1ff80D67Bfe90A85eE06Ce0A2613607D1",
// INPUT_VERIFICATION_ADDRESS (Gateway chain)
verifyingContractAddressInputVerification: "0x7048C39f048125eDa9d678AEbaDfB22F7900a29F",
// FHEVM Host chain id
chainId: 11155111,
// Gateway chain id
gatewayChainId: 55815,
// Optional RPC provider to host chain
network: "https://eth-sepolia.public.blastapi.io",
// Relayer URL
relayerUrl: "https://relayer.testnet.zama.cloud",
});
```
or the even simpler:
```ts
import { createInstance, SepoliaConfig } from "@zama-fhe/relayer-sdk";
const instance = await createInstance(SepoliaConfig);
```
The information regarding the configuration of Sepolia's FHEVM and associated Relayer maintained by Zama can be found in the `SepoliaConfig` object or in the [contract addresses page](https://docs.zama.ai/protocol/solidity-guides/smart-contract/configure/contract_addresses). The `gatewayChainId` is `55815`. The `chainId` is the chain-id of the FHEVM chain, so for Sepolia it would be `11155111`.
{% hint style="info" %}
For more information on the Relayer's part in the overall architecture please refer to [the Relayer's page in the architecture documentation](https://docs.zama.ai/protocol/protocol/overview/relayer_oracle).
{% endhint %}
# Input registration
This document explains how to register ciphertexts to the FHEVM. Registering ciphertexts to the FHEVM allows for future use on-chain using the `FHE.fromExternal` solidity function. All values encrypted for use with the FHEVM are encrypted under a public key of the protocol.
```ts
// We first create a buffer for values to encrypt and register to the fhevm
const buffer = instance.createEncryptedInput(
// The address of the contract allowed to interact with the "fresh" ciphertexts
contractAddress,
// The address of the entity allowed to import ciphertexts to the contract at `contractAddress`
userAddress,
);
// We add the values with associated data-type method
buffer.add64(BigInt(23393893233));
buffer.add64(BigInt(1));
// buffer.addBool(false);
// buffer.add8(BigInt(43));
// buffer.add16(BigInt(87));
// buffer.add32(BigInt(2339389323));
// buffer.add128(BigInt(233938932390));
// buffer.addAddress('0xa5e1defb98EFe38EBb2D958CEe052410247F4c80');
// buffer.add256(BigInt('2339389323922393930'));
// This will encrypt the values, generate a proof of knowledge for it, and then upload the ciphertexts using the relayer.
// This action will return the list of ciphertext handles.
const ciphertexts = await buffer.encrypt();
```
With a contract `MyContract` that implements the following it is possible to add two "fresh" ciphertexts.
```solidity
contract MyContract {
...
function add(
externalEuint64 a,
externalEuint64 b,
bytes calldata proof
) public virtual returns (euint64) {
return FHE.add(FHE.fromExternal(a, proof), FHE.fromExternal(b, proof))
}
}
```
With `my_contract` the contract in question using `ethers` it is possible to call the add function as following.
```js
my_contract.add(ciphertexts.handles[0], ciphertexts.handles[1], ciphertexts.inputProof);
```
# Public Decryption
This document explains how to perform public decryption of FHEVM ciphertexts. Public decryption is required when you want everyone to see the value in a ciphertext, for example the result of private auction. Public decryption can be done with either the Relayer HTTP endpoint or calling the on-chain decryption oracle.
## HTTP Public Decrypt
Calling the public decryption endpoint of the Relayer can be done easily using the following code snippet.
```ts
// A list of ciphertexts handles to decrypt
const handles = [
"0x830a61b343d2f3de67ec59cb18961fd086085c1c73ff0000000000aa36a70000",
"0x98ee526413903d4613feedb9c8fa44fe3f4ed0dd00ff0000000000aa36a70400",
"0xb837a645c9672e7588d49c5c43f4759a63447ea581ff0000000000aa36a70700",
];
// The list of decrypted values
// {
// '0x830a61b343d2f3de67ec59cb18961fd086085c1c73ff0000000000aa36a70000': true,
// '0x98ee526413903d4613feedb9c8fa44fe3f4ed0dd00ff0000000000aa36a70400': 242n,
// '0xb837a645c9672e7588d49c5c43f4759a63447ea581ff0000000000aa36a70700': '0xfC4382C084fCA3f4fB07c3BCDA906C01797595a8'
// }
const values = instance.publicDecrypt(handles);
```
## Onchain Public Decrypt
For more details please refer to the on [onchain Oracle public decryption page](https://docs.zama.ai/protocol/solidity-guides/smart-contract/oracle).
# Relayer SDK
**Welcome to the Relayer SDK Docs.**
This section provides an overview of the key features of Zama’s FHEVM Relayer JavaScript SDK. The SDK lets you interact with FHEVM smart contracts without dealing directly with the [Gateway Chain](https://docs.zama.ai/protocol/protocol/overview/gateway).
With the Relayer, FHEVM clients only need a wallet on the FHEVM host chain. All interactions with the Gateway chain are handled through HTTP calls to Zama's Relayer, which pays for it on the Gateway chain.
## Where to go next
If you’re new to the Zama Protocol, start with the [Litepaper](https://docs.zama.ai/protocol/zama-protocol-litepaper) or the [Protocol Overview](https://docs.zama.ai/protocol) to understand the foundations.
Otherwise:
🟨 Go to [**Setup 프로젝트로 돌아가기