Skip to content

Commit de48614

Browse files
committed
docs(common): updates Gateway to Relayer
1 parent 1528f83 commit de48614

File tree

12 files changed

+55
-68
lines changed

12 files changed

+55
-68
lines changed

docs/introductions/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ like this:
5050
pragma solidity ^0.8.24;
5151
5252
import { FHE } from "@fhevm/solidity/lib/FHE.sol";
53-
import { SepoliaZamaFHEVMConfig } from "@fhevm/solidity/config/ZamaFHEVMConfig.sol";
53+
import { SepoliaConfig } from "@fhevm/solidity/config/ZamaConfig.sol";
5454
5555
contract MyCounter is SepoliaZamaFHEVMConfig {
5656
euint64 counter;

docs/introductions/architecture_overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ compatibility:
1717
- **On-chain smart contracts** describe encrypted logic symbolically, managing access control and state via FHE handles.
1818
- **Off-chain coprocessors** listen to emitted events, reconstruct the compute graph, and perform the actual encrypted
1919
computation.
20-
- **The Gateway** acts as the protocol coordinator — verifying proofs, relaying requests, and managing data flow between
20+
- **The Relayer** acts as the protocol coordinator — verifying proofs, relaying requests, and managing data flow between
2121
the blockchain, the coprocessors, and the KMS.
2222
- **The KMS** is a decentralized, threshold-secure network that handles private key operations like decryption and
2323
signing, without ever reconstructing the full key.

docs/introductions/fhe-on-blockchain.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ To overcome these challenges, Zama introduced a hybrid architecture for FHEVM th
7474
- **Off-chain**
7575
- Coprocessors execute FHE operations using the evaluation key.
7676
- Results are stored off-chain, and only references (handles) are returned on-chain.
77-
- **Gateway & KMS**
77+
- **Relayer & KMS**
7878

79-
- The Gateway coordinates between the blockchain, users, and the KMS.
79+
- The relayer coordinates between the blockchain, users, and the KMS.
8080
- The Key Management System securely handles decryption via threshold MPC, supporting both smart contract and user
8181
decryption.
8282

docs/introductions/introduction-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Otherwise, pick your path:
1515
integrate the SDK, and run your first confidential app.
1616

1717
⚙️ Go to [Architecture](./architecture_overview.md) – Explore how the protocol works under the hood: smart contracts,
18-
coprocessors, the Gateway, and the KMS.
18+
coprocessors, the relayer, and the KMS.
1919

2020
🧰 Go to [Tooling](../solidity-guides/solidity-overview.md) – Discover how to use the Hardhat plugin and debugging tools
2121
designed to make FHE development seamless.

docs/solidity-guides/configure.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ This document explains how to enable encrypted computations in your smart contra
44

55
## Core configuration setup
66

7-
To utilize encrypted computations in Solidity contracts, you must configure the **FHE library** and **Gateway addresses**. The `fhevm` package simplifies this process with prebuilt configuration contracts, allowing you to focus on developing your contract’s logic without handling the underlying cryptographic setup.
7+
To utilize encrypted computations in Solidity contracts, you must configure the **FHE library** and **Relayer addresses**. The `fhevm` package simplifies this process with prebuilt configuration contracts, allowing you to focus on developing your contract’s logic without handling the underlying cryptographic setup.
88

99
## Key components configured automatically
1010

1111
1. **FHE library**: Sets up encryption parameters and cryptographic keys.
12-
2. **Gateway**: Manages secure cryptographic operations, including reencryption and decryption.
12+
2. **Relayer**: Manages secure cryptographic operations, including reencryption and decryption.
1313
3. **Network-specific settings**: Adapts to local testing, testnets (Sepolia for example), or mainnet deployment.
1414

1515
By inheriting these configuration contracts, you ensure seamless initialization and functionality across environments.
@@ -22,7 +22,7 @@ This configuration contract initializes the **fhevm environment** with required
2222

2323
```solidity
2424
// For Ethereum Sepolia
25-
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
25+
import { SepoliaZamaFHEVMConfig } from "@fhevm/solidity/config/ZamaFHEVMConfig.sol";
2626
```
2727

2828
**Purpose:**
@@ -36,7 +36,7 @@ import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
3636
// SPDX-License-Identifier: BSD-3-Clause-Clear
3737
pragma solidity ^0.8.24;
3838
39-
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
39+
import { SepoliaZamaFHEVMConfig } from "@fhevm/solidity/config/ZamaFHEVMConfig.sol";
4040
4141
contract MyERC20 is SepoliaZamaFHEVMConfig {
4242
constructor() {
@@ -45,33 +45,31 @@ contract MyERC20 is SepoliaZamaFHEVMConfig {
4545
}
4646
```
4747

48-
## ZamaGatewayConfig.sol
48+
## ZamaRela.sol
4949

50-
To perform decryption or reencryption, your contract must interact with the **Gateway**, which acts as a secure bridge between the blockchain, coprocessor, and Key Management System (KMS).
50+
To perform decryption or reencryption, your contract must interact with the **Relayer**, which acts as a secure bridge between the blockchain, coprocessor, and Key Management System (KMS).
5151

5252
**Import based on your environment**
5353

5454
```solidity
55-
// For Ethereum Sepolia
56-
import { SepoliaZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
55+
// For Sepolia
56+
import { SepoliaConfig } from "@fhevm/solidity/config/ZamaConfig.sol";
5757
```
5858

5959
**Purpose**
6060

61-
- Configures the Gateway for secure cryptographic operations.
61+
- Configures the relayer for secure cryptographic operations.
6262
- Facilitates reencryption and decryption requests.
6363

64-
**Example: Configuring the gateway with Sepolia settings**
64+
**Example: Configuring the relayer with Sepolia settings**
6565

6666
```solidity
67-
import "fhevm/lib/FHE.sol";
68-
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
69-
import { SepoliaZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
70-
import "fhevm/gateway/GatewayCaller.sol";
67+
import "@fhevm/solidity/lib/FHE.sol";
68+
import { SepoliaConfig } from "@fhevm/solidity/config/ZamaConfig.sol";
7169
72-
contract Test is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayCaller {
70+
contract Test is SepoliaConfig {
7371
constructor() {
74-
// Gateway and FHEVM environment initialized automatically
72+
// Relayer and FHEVM environment initialized automatically
7573
}
7674
}
7775
```
@@ -99,4 +97,4 @@ require(FHE.isInitialized(counter), "Counter not initialized!");
9997

10098
## Summary
10199

102-
By leveraging prebuilt configuration contracts like `ZamaFHEVMConfig.sol` and `ZamaGatewayConfig.sol`, you can efficiently set up your smart contract for encrypted computations. These tools abstract the complexity of cryptographic initialization, allowing you to focus on building secure, confidential smart contracts.
100+
By leveraging prebuilt a configuration contract like `ZamaConfig.sol`, you can efficiently set up your smart contract for encrypted computations. These tools abstract the complexity of cryptographic initialization, allowing you to focus on building secure, confidential smart contracts.

docs/solidity-guides/debug_decrypt.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The `debug.decrypt[XX]` functions allow you to decrypt encrypted handles into pl
1313
### Key points
1414

1515
- **Environment**: The `debug.decrypt[XX]` functions work **only in mocked environments** (e.g., `hardhat` network).
16-
- **Production limitation**: In production, decryption is performed asynchronously via the Gateway and requires an authorized onchain request.
16+
- **Production limitation**: In production, decryption is performed asynchronously via the relayer and requires an authorized onchain request.
1717
- **Encrypted types**: The `debug.decrypt[XX]` functions supports various encrypted types, including integers, and booleans.
1818
- **Bypass ACL authorization**: The `debug.decrypt[XX]` functions allow decryption without ACL authorization, useful for verifying encrypted operations during development and testing.
1919

@@ -106,4 +106,4 @@ if (network.name !== "hardhat") {
106106
## **Best practices**
107107

108108
- **Use only for debugging**: These functions require access to private keys and are meant exclusively for local testing and debugging.
109-
- **Production decryption**: For production, always use the asynchronous Gateway-based decryption.
109+
- **Production decryption**: For production, always use the asynchronous relayer-based decryption.

docs/solidity-guides/decryption/decrypt.md

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,57 +15,49 @@ To learn how decryption works see [Encryption, Decryption, Re-encryption, and Co
1515

1616
## Overview
1717

18-
Decryption in FHEVM is an asynchronous process that involves the Gateway and Key Management System (KMS). Contracts requiring decryption must extend the GatewayCaller contract, which imports the necessary libraries and provides access to the Gateway.
19-
20-
Here’s an example of how to request decryption in a contract:
18+
Decryption in FHEVM is an asynchronous process that involves the Relayer and Key Management System (KMS).
19+
Here’s an example of how to safely request decryption in a contract.
2120

2221
### Example: asynchronous decryption in a contract
2322

2423
```solidity
2524
pragma solidity ^0.8.24;
2625
27-
import "fhevm/lib/FHE.sol";
28-
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
29-
import { SepoliaZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
30-
import "fhevm/gateway/GatewayCaller.sol";
26+
import "@fhevm/solidity/lib/FHE.sol";
27+
import { SepoliaConfig } from "@fhevm/solidity/config/ZamaConfig.sol";
3128
32-
contract TestAsyncDecrypt is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayCaller {
29+
contract TestAsyncDecrypt is SepoliaConfig {
3330
ebool xBool;
3431
bool public yBool;
32+
bool isDecryptionPending;
33+
uint256 latestRequestId;
3534
3635
constructor() {
3736
xBool = FHE.asEbool(true);
3837
FHE.allowThis(xBool);
3938
}
4039
4140
function requestBool() public {
41+
require(!isDecryptionPending, "Decryption is in progress");
4242
uint256[] memory cts = new uint256[](1);
43-
cts[0] = Gateway.toUint256(xBool);
44-
Gateway.requestDecryption(cts, this.myCustomCallback.selector, 0, block.timestamp + 100, false);
43+
cts[0] = FHE.toUint256(xBool);
44+
uint256 latestRequestId = FHE.requestDecryption(cts, this.myCustomCallback.selector);
45+
46+
/// @dev This prevents sending multiple requests before the first callback was sent.
47+
isDecryptionPending = true;
4548
}
4649
47-
function myCustomCallback(uint256 /*requestID*/, bool decryptedInput) public onlyGateway returns (bool) {
50+
function myCustomCallback(uint256 requestId, bool decryptedInput, bytes[] memory signatures) public returns (bool) {
51+
/// @dev This check is used to verify that the request id is the expected one.
52+
require(requestId == latestRequestId, "Invalid requestId");
53+
FHE.checkSignatures(requestId, signatures);
4854
yBool = decryptedInput;
55+
isDecryptionPending = false;
4956
return yBool;
5057
}
58+
}
5159
```
5260

53-
#### Key additions to the code
54-
55-
1. **Configuration imports**: The configuration contracts are imported to set up the FHEVM environment and Gateway.
56-
57-
```solidity
58-
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
59-
import { SepoliaZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
60-
```
61-
62-
2. **`GatewayCaller` import**:\
63-
The `GatewayCaller` contract is imported to enable decryption requests.
64-
65-
```solidity
66-
import "fhevm/gateway/GatewayCaller.sol";
67-
```
68-
6961
### Next steps
7062

7163
Explore advanced decryption techniques and learn more about re-encryption:

docs/solidity-guides/decryption/decrypt_details.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This document provides a detailed guide on implementing decryption in your smart
44

55
## `DecryptionOracle` setup
66

7-
The `DecryptionOracle` is pre-deployed on the FHEVM testnet. It uses a default relayer account specified in the `PRIVATE_KEY_GATEWAY_RELAYER` or `ADDRESS_GATEWAY_RELAYER` environment variable in the `.env` file.
7+
The `DecryptionOracle` is pre-deployed on the FHEVM testnet. It uses a default relayer account specified in the `.env` file.
88

99
Anyone can fulfill decryption requests but it is essential to add signature verification (and to include a logic to invalidate the replay of decryption requests). The role of the `DecryptionOracle` contract is to independently verify the KMS signature during execution. This ensures that the relayers cannot manipulate or send fraudulent decryption results, even if compromised.
1010

@@ -15,21 +15,19 @@ There are two functions to consider: `requestDecryption` and `checkSignatures`.
1515
You can call the function `FHE.requestDecryption` as such:
1616

1717
```solidity
18-
function requestDecryption(uint256 requestID, bytes32[] calldata ctsHandles, bytes4 callbackSelector) external payable;
18+
function requestDecryption(bytes32[] calldata ctsHandles, bytes4 callbackSelector) external payable returns (uint256 requestId);
1919
```
2020

2121
#### Function arguments
2222

23-
The first argument, `requestID`, is a counter that is incremented at the smart contract level after each decryption request.
24-
25-
The second argument, `ctsHandles`, should be an array of ciphertexts handles which could be of different types, i.e `uint256` values coming from unwrapping handles of type either `ebool`, `euint8`, `euint16`, `euint32`, `euint64` or `eaddress`. 
23+
The first argument, `ctsHandles`, should be an array of ciphertexts handles which could be of different types, i.e `uint256` values coming from unwrapping handles of type either `ebool`, `euint8`, `euint16`, `euint32`, `euint64` or `eaddress`. 
2624

2725
`ctsHandles` is the array of ciphertexts that are requested to be decrypted. Tthe relayer will send the corresponding ciphertexts to the KMS for decryption before fulfilling the request.
2826

2927
`callbackSelector` is the function selector of the callback function, which will be called once the relayer fulfils the decryption request.
3028

3129
```solidity
32-
function [callbackName](uint256 requestID, XXX x_0, XXX x_1, ..., XXX x_N-1) external;
30+
function [callbackName](uint256 requestID, XXX x_0, XXX x_1, ..., XXX x_N-1, bytes[] memory signatures) external;
3331
```
3432

3533
Notice that `XXX` should be the decrypted type, which is a native Solidity type corresponding to the original ciphertext type, following this table of conventions:
@@ -61,8 +59,7 @@ You can call the function `FHE.checkSignatures` as such:
6159

6260
#### Function arguments
6361

64-
The first argument, `requestID`, is the value used as an argument in the `requestDecryption`function.
65-
66-
The second argument, `signatures`, is an array of signatures from the KMS.
62+
The first argument, `requestID`, is the value that was returned in the `requestDecryption`function.
63+
The second argument, `signatures`, is an array of signatures from the KMS signers.
6764

68-
If
65+
This function reverts if the signatures are invalid.

docs/solidity-guides/decryption/reencryption.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The re-encryption process involves retrieving ciphertext from the blockchain and
1818

1919
This ensures that the data remains encrypted under the blockchain’s FHE key but can be securely shared with a user by re-encrypting it under the user’s NaCl public key.
2020

21-
Re-encryption is facilitated by the **Gateway** and the **Key Management System (KMS)**. The workflow consists of the following:
21+
Re-encryption is facilitated by the **Relayer** and the **Key Management System (KMS)**. The workflow consists of the following:
2222

2323
1. Retrieving the ciphertext from the blockchain using a contract’s view function.
2424
2. Re-encrypting the ciphertext client-side with the user’s public key, ensuring only the user can decrypt it.
@@ -28,7 +28,7 @@ Re-encryption is facilitated by the **Gateway** and the **Key Management System
2828
To retrieve the ciphertext that needs to be re-encrypted, you can implement a view function in your smart contract. Below is an example implementation:
2929

3030
```solidity
31-
import "fhevm/lib/FHE.sol";
31+
import "@fhevm/solidity/lib/FHE.sol";
3232
3333
contract ConfidentialERC20 {
3434
...
@@ -77,7 +77,7 @@ const signature = await window.ethereum.request({ method: "eth_signTypedData_v4"
7777
const ConfidentialERC20 = new Contract(CONTRACT_ADDRESS, abi, signer).connect(provider);
7878
const encryptedBalance = ConfidentialERC20.balanceOf(userAddress);
7979

80-
// This function will call the gateway and decrypt the received value with the provided private key
80+
// This function will call the relayer and decrypt the received value with the provided private key
8181
const userBalance = instance.reencrypt(
8282
encryptedBalance, // the encrypted balance
8383
privateKey, // the private key generated by the dApp
@@ -96,4 +96,4 @@ This code retrieves the user’s encrypted balance, re-encrypts it with their pu
9696

9797
- **`instance.generateKeypair()`**: Generates a public-private keypair for the user.
9898
- **`instance.createEIP712(publicKey, CONTRACT_ADDRESS)`**: Creates an EIP712 object for signing the user’s public key.
99-
- **`instance.reencrypt()`**: Facilitates the re-encryption process by contacting the Gateway and decrypting the data locally with the private key.
99+
- **`instance.reencrypt()`**: Facilitates the re-encryption process by contacting the relayer and decrypting the data locally with the private key.

docs/solidity-guides/foundry.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ This guide explains how to use Foundry with FHEVM for developing smart contracts
44

55
While a Foundry template is currently in development, we strongly recommend using the [Hardhat template](https://github.com/zama-ai/fhevm-hardhat-template) for now, as it provides a fully tested and supported development environment for FHEVM smart contracts.
66

7-
However, you could still use Foundry with the mocked version of the fhevm, but please be aware that this approach is **NOT** recommended, since the mocked version is not fully equivalent to the real FHEVM node's implementation (see warning in hardhat). In order to do this, you will need to rename your `FHE.sol` imports from `fhevm/lib/FHE.sol` to `fhevm/mocks/FHE.sol` in your solidity source files.
7+
However, you could still use Foundry with the mocked version of the fhevm, but please be aware that this approach is **NOT** recommended, since the mocked version is not fully equivalent to the real FHEVM node's implementation (see warning in hardhat). In order to do this, you will need to rename your `FHE.sol` imports from `@fhevm/solidity/lib/FHE.sol` to `fhevm/mocks/FHE.sol` in your solidity source files.

0 commit comments

Comments
 (0)