|
1 | 1 | # Coprocessor |
2 | 2 |
|
3 | | -The Coprocessor is the FHEVM protocol’s off-chain computation engine. It performs the heavy cryptographic |
4 | | -operations—specifically, fully homomorphic encryption (FHE) computations—on behalf of smart contracts that operate on |
5 | | -encrypted data. Acting as a decentralized compute layer, the coprocessor bridges symbolic on-chain logic with real-world |
6 | | -encrypted execution. |
7 | | - |
8 | | -It works in tandem with the Gateway, verifying encrypted inputs, executing FHE instructions, and maintaining |
9 | | -synchronization of access permissions. |
| 3 | +This document explains one of the key components of the Zama Protocol - Coprocessor, the Zama Protocol’s off-chain computation engine. |
10 | 4 |
|
11 | 5 | ## What is the Coprocessor? |
12 | 6 |
|
13 | | -The Coprocessor is an off-chain service that: |
| 7 | +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. |
| 8 | + |
| 9 | +Coprocessor works together with the Gateway, verifying encrypted inputs, executing FHE instructions, and maintaining synchronization of access permissions, in particula |
14 | 10 |
|
15 | | -- Listens to events emitted by host chains and the Gateway. |
16 | | -- Executes FHE computations (`add`, `mul`, `div`, `cmp`, etc.) on ciphertexts. |
17 | | -- Validates encrypted inputs and ZK proofs of correctness. |
18 | | -- Maintains and updates a replica of the host chain’s Access Control Lists (ACLs). |
19 | | -- Stores and serves encrypted data for decryption or bridging. |
| 11 | +* Listens to events emitted by host chains and the Gateway. |
| 12 | +* Executes FHE computations (`add`, `mul`, `div`, `cmp`, etc.) on ciphertexts. |
| 13 | +* Validates encrypted inputs and ZK proofs of correctness. |
| 14 | +* Maintains and updates a replica of the host chain’s Access Control Lists (ACLs). |
| 15 | +* Stores and serves encrypted data for decryption or bridging. |
20 | 16 |
|
21 | | -Each coprocessor independently executes tasks and publishes verifiable results, enabling a publicly auditable and |
22 | | -horizontally scalable confidential compute infrastructure . |
| 17 | +Each coprocessor independently executes tasks and publishes verifiable results, enabling a publicly auditable and horizontally scalable confidential compute infrastructure . |
23 | 18 |
|
24 | 19 | ## Responsibilities of the Coprocessor |
25 | 20 |
|
26 | | -### Encrypted Input Verification |
| 21 | +### Encrypted input verification |
27 | 22 |
|
28 | 23 | When users submit encrypted values to the Gateway, each coprocessor: |
29 | 24 |
|
30 | | -- Verifies the associated Zero-Knowledge Proof of Knowledge (ZKPoK). |
31 | | -- Extracts and unpacks individual ciphertexts from a packed submission. |
32 | | -- Stores the ciphertexts under derived handles. |
33 | | -- Signs the verified handles, embedding user and contract metadata. |
34 | | -- Sends the signed data back to the Gateway for consensus. |
| 25 | +* Verifies the associated Zero-Knowledge Proof of Knowledge (ZKPoK). |
| 26 | +* Extracts and unpacks individual ciphertexts from a packed submission. |
| 27 | +* Stores the ciphertexts under derived handles. |
| 28 | +* Signs the verified handles, embedding user and contract metadata. |
| 29 | +* Sends the signed data back to the Gateway for consensus. |
35 | 30 |
|
36 | 31 | This ensures only valid, well-formed encrypted values enter the system . |
37 | 32 |
|
38 | | -### FHE Computation Execution |
| 33 | +### FHE computation execution |
39 | 34 |
|
40 | | -When a smart contract executes a function over encrypted values, the on-chain logic emits symbolic computation events. |
| 35 | +When a smart contract executes a function over encrypted values, the on-chain logic emits symbolic computation events.\ |
41 | 36 | Each coprocessor: |
42 | 37 |
|
43 | | -- Reads these events from the host chain node it runs. |
44 | | -- Fetches associated ciphertexts from its storage. |
45 | | -- Executes the required FHE operations using the TFHE-rs library (e.g., add, mul, select). |
46 | | -- Stores the resulting ciphertext under a deterministically derived handle. |
47 | | -- Optionally publishes a commitment (digest) of the ciphertext to the Gateway for verifiability. |
| 38 | +* Reads these events from the host chain node it runs. |
| 39 | +* Fetches associated ciphertexts from its storage. |
| 40 | +* Executes the required FHE operations using the TFHE-rs library (e.g., add, mul, select). |
| 41 | +* Stores the resulting ciphertext under a deterministically derived handle. |
| 42 | +* Optionally publishes a commitment (digest) of the ciphertext to the Gateway for verifiability. |
48 | 43 |
|
49 | 44 | This offloads expensive computation from the host chain while maintaining full determinism and auditability . |
50 | 45 |
|
51 | | -### ACL Replication |
| 46 | +### ACL replication |
52 | 47 |
|
53 | 48 | Coprocessors replicate the Access Control List (ACL) logic from host contracts. They: |
54 | 49 |
|
55 | | -- Listen to Allowed and AllowedForDecryption events. |
56 | | -- Push updates to the Gateway. |
| 50 | +* Listen to Allowed and AllowedForDecryption events. |
| 51 | +* Push updates to the Gateway. |
57 | 52 |
|
58 | | -This ensures decentralized enforcement of access rights, enabling proper handling of decryptions, bridges, and contract |
59 | | -interactions . |
| 53 | +This ensures decentralized enforcement of access rights, enabling proper handling of decryptions, bridges, and contract interactions . |
60 | 54 |
|
61 | | -### Ciphertext Commitment |
| 55 | +### Ciphertext commitment |
62 | 56 |
|
63 | 57 | To ensure verifiability and mitigate misbehavior, each coprocessor: |
64 | 58 |
|
65 | | -- Commits to ciphertext digests (via hash) when processing Allowed events. |
66 | | -- Publishes these commitments to the Gateway. |
67 | | -- Enables external verification of FHE computations. |
| 59 | +* Commits to ciphertext digests (via hash) when processing Allowed events. |
| 60 | +* Publishes these commitments to the Gateway. |
| 61 | +* Enables external verification of FHE computations. |
68 | 62 |
|
69 | 63 | This is essential for fraud-proof mechanisms and eventual slashing of malicious or faulty operators . |
70 | 64 |
|
71 | | -### Bridging & Decryption Support |
| 65 | +### Bridging & decryption support |
72 | 66 |
|
73 | 67 | Coprocessors assist in: |
74 | 68 |
|
75 | | -- Bridging encrypted values between host chains by generating new handles and signatures. |
76 | | -- Preparing ciphertexts for public and user decryption using operations like Switch-n-Squash to normalize ciphertexts |
| 69 | +* Bridging encrypted values between host chains by generating new handles and signatures. |
| 70 | +* Preparing ciphertexts for public and user decryption using operations like Switch-n-Squash to normalize ciphertexts\ |
77 | 71 | for the KMS. |
78 | 72 |
|
79 | | -These roles help maintain cross-chain interoperability and enable privacy-preserving data access for users and smart |
80 | | -contracts . |
| 73 | +These roles help maintain cross-chain interoperability and enable privacy-preserving data access for users and smart contracts . |
81 | 74 |
|
82 | | -## Security and Trust Assumptions |
| 75 | +## Security and trust assumptions |
83 | 76 |
|
84 | | -Coprocessors are designed to be minimally trusted and publicly verifiable. Every FHE computation or input verification |
85 | | -they perform is accompanied by a cryptographic commitment (hash digest) and a signature, allowing anyone to |
86 | | -independently verify correctness. |
| 77 | +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. |
87 | 78 |
|
88 | | -The protocol relies on a majority-honest assumption: as long as more than 50% of coprocessors are honest, results are |
89 | | -valid. The Gateway aggregates responses and accepts outputs only when a majority consensus is reached. |
| 79 | +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. |
90 | 80 |
|
91 | | -To enforce honest behavior, coprocessors must stake $ZAMA tokens and are subject to slashing if caught |
92 | | -misbehaving—either through automated checks or governance-based fraud proofs. |
| 81 | +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. |
93 | 82 |
|
94 | | -This model ensures correctness through transparency, resilience through decentralization, and integrity through economic |
95 | | -incentives. |
| 83 | +This model ensures correctness through transparency, resilience through decentralization, and integrity through economic incentives. |
96 | 84 |
|
97 | 85 | ## Architecture & Scalability |
98 | 86 |
|
99 | 87 | The coprocessor architecture includes: |
100 | 88 |
|
101 | | -- Event listeners for host chains and the Gateway |
102 | | -- A task queue for FHE and ACL update jobs |
103 | | -- Worker threads that process tasks in parallel |
104 | | -- A public storage layer (e.g., S3) for ciphertext availability |
| 89 | +* Event listeners for host chains and the Gateway |
| 90 | +* A task queue for FHE and ACL update jobs |
| 91 | +* Worker threads that process tasks in parallel |
| 92 | +* A public storage layer (e.g., S3) for ciphertext availability |
105 | 93 |
|
106 | | -This modular setup supports horizontal scaling: adding more workers or machines increases throughput. Symbolic |
| 94 | +This modular setup supports horizontal scaling: adding more workers or machines increases throughput. Symbolic\ |
107 | 95 | computation and delayed execution also ensure low gas costs on-chain . |
0 commit comments