Zama 백서

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 40쪽

tract emits a decryption request. 2. The Gateway validates it and forwards it to the KMS. 3. The plaintext is returned via a callback to the smart contract. 2. User Decryption used when a user needs to privately access a decrypted value. 1. User generates a key pair locally. 2. Signs their public key and submits a request to the Gateway. 3. The Gateway verifies the request and forwards it to the KMS. 4. The KMS decrypts the ciphertext and encrypts it with the user’s public key. 5. The user receives the ciphertext and decrypts it locally. <figure><img src="https://2354183879-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHSoe8yNdsakWMG6E3ITL%2Fuploads%2Fgit-blob-34230922dec139f7d3d02a334d74538e4f9307d1%2Fdecryption.png?alt=media" alt="decryption"><figcaption></figcaption></figure> <figure><img src="https://2354183879-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHSoe8yNdsakWMG6E3ITL%2Fuploads%2Fgit-blob-6658c0482a3f2f8329eb01b1938491ed402d35c5%2FasyncDecrypt.png?alt=media" alt="decryption"><figcaption><p>decryption</p></figcaption></figure> You can read about the implementation details in \[our decryption guide]\(solidity-guides/decryption/decrypt.md). #### What is “User Decryption”? User Decryption is the mechanism that allows users or applications to request private access to decrypted data — without exposing the plaintext on-chain. Instead of simply decrypting, the KMS securely decrypts the result with the user’s public key, allowing the user to decrypt it client-side only. This guarantees: * Only the requesting user can see the plaintext * The KMS never reveals the decrypted value * The decrypted result is not written to the blockchain <figure><img src="https://2354183879-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHSoe8yNdsakWMG6E3ITL%2Fuploads%2Fgit-blob-616b66e3634d4f40af6249e3d02a599b99a683ae%2Freencryption.png?alt=media" alt="decryption"><figcaption><p>decryption process</p></figcaption></figure> #### Client-side implementation User decryption is initiated on the client side using the [`@zama-ai/relayer-sdk`](https://github.com/zama-ai/relayer-sdk/) library. Here’s the general workflow: 1. **Retrieve the ciphertext**: * The dApp calls a view function (e.g., `balanceOf`) on the smart contract to get the handle of the ciphertext to be decrypted. 2. **Generate and sign a keypair**: * The dApp generates a keypair for the user. * The user signs the public key to ensure authenticity. 3. **Submit user encryption request**: * The dApp emits a transaction to the Gateway, providing the following information: * The ciphertext handle. * The user’s public key. * The user’s address. * The smart contract address. * The user’s signature. * The transaction can be sent directly to the Gateway chain from the client application, or routed through a Relayer, which exposes an HTTP endpoint to abstract the transaction handling. 4. **Decrypt the encrypted ciphertext**: * The dApp receives the encrypted ciphertext under the user's public key from the Gateway/Relayer. * The dApp decrypts the ciphertext locally using the user's private key. You can read [our user decryption guide explaining how to use it](https://github.com/zama-ai/fhevm/blob/release/0.10.x/docs/protocol/solidity-guides/decryption/user-decryption.md). ## **Tying It All Together** The flow of information across the FHEVM components during these operations highlights how the system ensures privacy while maintaining usability: | Operation | | | | ------------------- | ----------------------- | --------------------------------------------------------------------------------------------------- | | **Encryption** | Public Key | Frontend encrypts data → ciphertext sent to blockchain or coprocessor | | **Computation** | Evaluation Key | Coprocessor executes operations from smart contract events → updated ciphertexts | | **Decryption** | Private Key | Smart contract requests plaintext → Gateway forwards to KMS → result returned on-chain | | **User decryption** | Private and Target Keys | User requests result → KMS decrypts and encrypts with user’s public key → frontend decrypts locally | This architecture ensures that sensitive data remains encrypted throughout its lifecycle, with decryption only occurring in controlled, secure environments. By separating key roles and processing responsibilities, FHEVM provides a scalable and robust framework for private smart contracts. # Roadmap This document gives a preview of the upcoming features of FHEVM. In addition to what's listed here, you can [submit your feature request](https://github.com/zama-ai/fhevm/issues/new) on GitHub. ## Features | Name | Description | ETA | | ---------------- | --------------------------------------------------------- | ------ | | Foundry template | [Forge](https://book.getfoundry.sh/reference/forge/forge) | Q1 '25 | ## Operations | Name | Function name | Type | ETA | | --------------------- | ----------------- | ------------------ | ----------- | | Signed Integers | `eintX` | | Coming soon | | Add w/ overflow check | `FHE.safeAdd` | Binary, Decryption | Coming soon | | Sub w/ overflow check | `FHE.safeSub` | Binary, Decryption | Coming soon | | Mul w/ overflow check | `FHE.safeMul` | Binary, Decryption | Coming soon | | Random signed int | `FHE.randEintX()` | Random | - | | Div | `FHE.div` | Binary | - | | Rem | `FHE.rem` | Binary | - | | Set inclusion | `FHE.isIn()` | Binary | - | {% hint style="info" %} Random encrypted integers that are generated fully on-chain. Currently, implemented as a mockup by using a PRNG in the plain. Not for use in production! {% endhint %} # architecture # Coprocessor This document explains one of the key components of the Zama Protocol - Coprocessor, the Zama Protocol’s off-chain computation engine. ## What is the Coprocessor? Coprocessor performs the heavy cryptographic operations—specifically, fully homomorphic encryption (FHE) computations—on behalf of smart contracts that operate on encrypted data. Acting as a decentralized compute layer, the coprocessor bridges symbolic on-chain logic with real-world encrypted execution. Coprocessor works together with the Gateway, verifying encrypted inputs, executing FHE instructions, and maintaining synchronization of access permissions, in particular: * Listens to events emitted by host chains and the Gateway. * Executes FHE computations (`add`, `mul`, `div`, `cmp`, etc.) on ciphertexts. * Validates encrypted inputs and ZK proofs of correctness. * Maintains and updates a replica of the host chain’s Access Control Lists (ACLs). * Stores and serves encrypted data for decryption or bridging. Each coprocessor independently executes tasks and publishes verifiable results, enabling a publicly auditable and horizontally scalable confidential compute infrastructure . ## Responsibilities of the Coprocessor ### Encrypted input verification When users submit encrypted values to the Gateway, each coprocessor: * Verifies the associated Zero-Knowledge Proof of Knowledge (ZKPoK). * Extracts and unpacks individual ciphertexts from a packed submission. * Stores the ciphertexts under derived handles. * Signs the verified handles, embedding user and contract metadata. * Sends the signed data back to the Gateway for consensus. This ensures only valid, well-formed encrypted values enter the system . ### FHE computation execution When a smart contract executes a function over encrypted values, the on-chain logic emits symbolic computation events.\ Each coprocessor: * Reads these events from the host chain node it runs. * Fetches associated ciphertexts from its storage. * Executes the required FHE operations using the TFHE-rs library (e.g., add, mul, select). * Stores the resulting ciphertext under a deterministically derived handle. * Optionally publishes a commitment (digest) of the ciphertext to the Gateway for verifiability. This offloads expensive computation from the host chain while maintaining full determinism and auditability . ### ACL replication Coprocessors replicate the Access Control List (ACL) logic from host contracts. They: * Listen to Allowed and AllowedForDecryption events. * Push updates to the Gateway. This ensures decentralized enforcement of access rights, enabling proper handling of decryptions, bridges, and contract interactions . ### Ciphertext commitment To ensure verifiability and mitigate misbehavior, each coprocessor: * Commits to ciphertext digests (via hash) when processing Allowed events. * Publishes these commitments to the Gateway. * Enables external verification of FHE computations. This is essential for fraud-proof mechanisms and eventual slashing of malicious or faulty operators . ### Bridging & decryption support Coprocessors assist in: * Bridging encrypted values between host chains by generating new handles and signatures. * Preparing ciphertexts for public and user decryption using operations like Switch-n-Squash to normalize ciphertexts for the KMS. These roles help maintain cross-chain interoperability and enable privacy-preserving data access for users and smart contracts . ## Security and trust assumptions Coprocessors are designed to be minimally trusted and publicly verifiable. Every FHE computation or input verification they perform is accompanied by a cryptographic commitment (hash digest) and a signature, allowing anyone to independently verify correctness. The protocol relies on a majority-honest assumption: as long as more than 50% of coprocessors are honest, results are valid. The Gateway aggregates responses and accepts outputs only when a majority consensus is reached. To enforce honest behavior, coprocessors must stake $ZAMA tokens and are subject to slashing if caught misbehaving—either through automated checks or governance-based fraud proofs. This model ensures correctness through transparency, resilience through decentralization, and integrity through economic incentives. ## Architecture & Scalability The coprocessor architecture includes: * Event listeners for host chains and the Gateway * A task queue for FHE and ACL update jobs * Worker threads that process tasks in parallel * A public storage layer (e.g., S3) for ciphertext availability This modular setup supports horizontal scaling: adding more workers or machines increases throughput. Symbolic computation and delayed execution also ensure low gas costs on-chain . # Gateway This document explains one of the key components of the Zama Protocol - Gateway, the central orchestrator within Zama’s FHEVM protocol, coordinates interactions between users, host chains, coprocessors, and the Key Management Service (KMS), ensuring that encrypted data flows securely and correctly through the system. ## What is the Gateway? The Gateway is a specialized blockchain component (implemented as an Arbitrum rollup) responsible for managing: * Validation of encrypted inputs from users and applications. * Bridging of encrypted ciphertexts across different blockchains. * Decryption orchestration via KMS nodes. * Consensus enforcement among decentralized coprocessors. * Staking and reward distribution to operators participating in FHE computations. It is designed to be trust-minimized: computations are independently verifiable, and no sensitive data or decryption keys are stored on the Gateway itself. ## Responsibilities of the Gateway ### Encrypted input validation The Gateway ensures that encrypted values provided by users are well-formed and valid. It does this by: * Accepting encrypted inputs along with Zero-Knowledge Proofs of Knowledge (ZKPoKs). * Emitting verification events for coprocessors to validate. * Aggregating signatures from a majority of coprocessors to generate attestations, which can then be used on-chain as trusted external values. ### Access Control coordination The Gateway maintains a synchronized copy of Access Control Lists (ACLs) from host chains, enabling it to independently determine if decryption or computation rights should be granted for a ciphertext. This helps enforce: * Access permissions (allow) * Public decryption permissions (allowForDecryption) These ACL updates are replicated by coprocessors and pushed to the Gateway for verification and enforcement. ### Decryption orchestration When a smart contract or user requests the decryption of an encrypted value: 1. The Gateway verifies ACL permissions. 2. It then triggers the KMS to decrypt (either publicly or privately). 3. Once the KMS returns signed results, the Gateway emits events that can be picked up by an oracle (for smart contract decryption) or returned to the user (for private decryption). This ensures asynchronous, secure, and auditable decryption without the Gateway itself knowing the plaintext. ### Cross-chain bridging The Gateway also handles bridging of encrypted handles between host chains. It: * Verifies access rights on the source chain using its ACL copy. * Requests the coprocessors to compute new handles for the target chain. * Collects signatures from coprocessors. Issues attestations allowing these handles to be used on the destination chain. ### Consensus and slashing enforcement The Gateway enforces consensus across decentralized coprocessors and KMS nodes. If discrepancies occur: * Coprocessors must provide commitments to ciphertexts. * Fraudulent or incorrect behavior can be challenged and slashed. * Governance mechanisms can be triggered for off-chain verification when necessary. ### Protocol administration The Gateway runs smart contracts that administer: * Operator and participant registration (coprocessors, KMS nodes, host chains) * Key management and rotation * Bridging logic * Input validation and decryption workflows ## Security and trust assumptions The Gateway is designed to operate without requiring trust: * It does not perform any computation itself—it merely orchestrates and validates. * All actions are signed, and cryptographic verification is built into every step. The protocol assumes no trust in the Gateway for security guarantees—it can be fully audited and replaced if necessary. # Host contracts This document explains one of the key components of the Zama Protocol - Host contracts. ## What are host contracts? Host contracts are smart contracts deployed on any supported blockchain (EVM or non-EVM) that act as trusted bridges between on-chain applications and the FHEVM protocol. They serve as the minimal and foundational interface that confidential smart contracts use to: * Interact with encrypted data (handles) * Perform access control operations * Emit events for the off-chain components (coprocessors, Gateway) These host contracts are used indirectly by developers via the FHEVM Solidity library, abstracting away complexity and integrating smoothly into existing workflows. ## Responsibilities of host contracts ### Trusted interface layer Host contracts are the only on-chain components that: * Maintain and enforce Access Control Lists (ACLs) for ciphertexts. * Emit events that trigger coprocessor execution. * Validate access permissions (persistent, transient, or decryption-related). They are effectively the on-chain authority for: * Who is allowed to access a ciphertext * When and how they can use it * These ACLs are mirrored on the Gateway for off-chain enforcement and bridging. ### Access Control API Host contracts expose access control logic via standardized function calls (wrapped by the FHEVM library): * `allow(handle, address)`: Grants persistent access. * `allowTransient(handle, address)`: Grants temporary access for a single transaction. * `allowForDecryption(handle)`: Marks a handle as publicly decryptable. * `isAllowed(handle, address)`: Returns whether a given address has access. * `isSenderAllowed(handle)`: Checks if msg.sender is allowed to use a handle. They also emit: * `Allowed(handle, address)` * `AllowedForDecryption(handle)` These events are crucial for triggering coprocessor state updates and ensuring proper ACL replication to the Gateway. → See the full guide of [ACL](https://docs.zama.ai/protocol/solidity-guides/smart-contract/acl). ### Security role Although the FHE computation happens off-chain, host contracts play a critical role in protocol security by: * Enforcing ACL-based gating * Ensuring only authorized contracts and users can decrypt or use a handle * Preventing misuse of encrypted data (e.g., computation without access) Access attempts without proper authorization are rejected at the smart contract level, protecting both the integrity of confidential operations and user privacy. # KMS This document explains one of the key components of the Zama Protocol - The Key Management Service (KMS), responsible for the secure generation, management, and usage of FHE keys needed to enable confidential smart contracts. ## What is the KMS? The KMS is a decentralized network of several nodes (also called "parties") that run an MPC (Multi-Party Computation) protocol: * Securely generate global FHE keys * Decrypt ciphertexts securely for public and user-targeted decryptions * Support zero-knowledge proof infrastructure * Manage key lifecycles with NIST compliance It works entirely off-chain, but is orchestrated through the Gateway, which initiates and tracks all key-related operations. This separation of powers ensures strong decentralization and auditability. ## Key responsibilities ### FHE threshold key generation * The KMS securely generates a global public/private key pair used across all host chains. * This key enables composability — encrypted data can be shared between contracts and chains. * The private FHE key is never directly accessible by a single party; instead, it is secret-shared among the MPC nodes. The system follows the NIST SP 800-57 key lifecycle model, managing key states such as Active, Suspended, Deactivated,and Destroyed to ensure proper rotation and forward security. ### Threshold Decryption via MPC The KMS performs decryption using a threshold decryption protocol — at least a minimum number of MPC parties (e.g., 9 out of 13) must participate in the protocol to robustly decrypt a value. * This protects against compromise: no individual party has access to the full key. And adversary would need to control more than the threshold of KMS nodes to influence the system. * The protocol supports both: * Public decryption (e.g., for smart contracts) * User decryption (privately returned, re-encrypted only for the user to access) All decryption operation outputs are signed by each node and the output can be verified on-chain for full auditability. ### ZK Proof support The KMS generates Common Reference Strings (CRS) needed to validate Zero-Knowledge Proofs of Knowledge (ZKPoK) when users submit encrypted values. This ensures encrypted inputs are valid and well-formed, and that a user has knowledge of the plaintext contained in the submitted input ciphertext. ## Security architecture ### MPC-based key sharing * The KMS currently uses 13 MPC nodes, operated by different reputable organizations. * Private keys are split using threshold secret sharing. * Communication between nodes are secured using mTLS with gRPC. ### Honest majority assumption * The protocol is robust against malicious actors as long as at most 1/3 of the nodes act maliciously. * It supports guaranteed output delivery even if some nodes are offline or misbehaving. ### Secure execution environments Each MPC node runs by default inside an AWS Nitro Enclave, a secure execution environment that prevents even node operators from accessing their own key shares. This design mitigates insider risks, such as unauthorized key reconstruction or selling of shares. ### Auditable via gateway * All operations are broadcast through the Gateway and recorded as blockchain events. * KMS responses are signed, allowing smart contracts a
프로젝트로 돌아가기