You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/solidity-guides/configure.md
+15-17Lines changed: 15 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,12 +4,12 @@ This document explains how to enable encrypted computations in your smart contra
4
4
5
5
## Core configuration setup
6
6
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.
8
8
9
9
## Key components configured automatically
10
10
11
11
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.
13
13
3.**Network-specific settings**: Adapts to local testing, testnets (Sepolia for example), or mainnet deployment.
14
14
15
15
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
22
22
23
23
```solidity
24
24
// For Ethereum Sepolia
25
-
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
25
+
import { SepoliaZamaFHEVMConfig } from "@fhevm/solidity/config/ZamaFHEVMConfig.sol";
26
26
```
27
27
28
28
**Purpose:**
@@ -36,7 +36,7 @@ import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
36
36
// SPDX-License-Identifier: BSD-3-Clause-Clear
37
37
pragma solidity ^0.8.24;
38
38
39
-
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
39
+
import { SepoliaZamaFHEVMConfig } from "@fhevm/solidity/config/ZamaFHEVMConfig.sol";
40
40
41
41
contract MyERC20 is SepoliaZamaFHEVMConfig {
42
42
constructor() {
@@ -45,33 +45,31 @@ contract MyERC20 is SepoliaZamaFHEVMConfig {
45
45
}
46
46
```
47
47
48
-
## ZamaGatewayConfig.sol
48
+
## ZamaRela.sol
49
49
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).
51
51
52
52
**Import based on your environment**
53
53
54
54
```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";
57
57
```
58
58
59
59
**Purpose**
60
60
61
-
- Configures the Gateway for secure cryptographic operations.
61
+
- Configures the relayer for secure cryptographic operations.
62
62
- Facilitates reencryption and decryption requests.
63
63
64
-
**Example: Configuring the gateway with Sepolia settings**
64
+
**Example: Configuring the relayer with Sepolia settings**
65
65
66
66
```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";
71
69
72
-
contract Test is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayCaller {
70
+
contract Test is SepoliaConfig {
73
71
constructor() {
74
-
// Gateway and FHEVM environment initialized automatically
72
+
// Relayer and FHEVM environment initialized automatically
75
73
}
76
74
}
77
75
```
@@ -99,4 +97,4 @@ require(FHE.isInitialized(counter), "Counter not initialized!");
99
97
100
98
## Summary
101
99
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.
Copy file name to clipboardExpand all lines: docs/solidity-guides/debug_decrypt.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ The `debug.decrypt[XX]` functions allow you to decrypt encrypted handles into pl
13
13
### Key points
14
14
15
15
-**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.
17
17
-**Encrypted types**: The `debug.decrypt[XX]` functions supports various encrypted types, including integers, and booleans.
18
18
-**Bypass ACL authorization**: The `debug.decrypt[XX]` functions allow decryption without ACL authorization, useful for verifying encrypted operations during development and testing.
19
19
@@ -106,4 +106,4 @@ if (network.name !== "hardhat") {
106
106
## **Best practices**
107
107
108
108
-**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.
Copy file name to clipboardExpand all lines: docs/solidity-guides/decryption/decrypt.md
+19-27Lines changed: 19 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,57 +15,49 @@ To learn how decryption works see [Encryption, Decryption, Re-encryption, and Co
15
15
16
16
## Overview
17
17
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.
21
20
22
21
### Example: asynchronous decryption in a contract
23
22
24
23
```solidity
25
24
pragma solidity ^0.8.24;
26
25
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";
31
28
32
-
contract TestAsyncDecrypt is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayCaller {
29
+
contract TestAsyncDecrypt is SepoliaConfig {
33
30
ebool xBool;
34
31
bool public yBool;
32
+
bool isDecryptionPending;
33
+
uint256 latestRequestId;
35
34
36
35
constructor() {
37
36
xBool = FHE.asEbool(true);
38
37
FHE.allowThis(xBool);
39
38
}
40
39
41
40
function requestBool() public {
41
+
require(!isDecryptionPending, "Decryption is in progress");
Copy file name to clipboardExpand all lines: docs/solidity-guides/decryption/decrypt_details.md
+7-10Lines changed: 7 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ This document provides a detailed guide on implementing decryption in your smart
4
4
5
5
## `DecryptionOracle` setup
6
6
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.
8
8
9
9
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.
10
10
@@ -15,21 +15,19 @@ There are two functions to consider: `requestDecryption` and `checkSignatures`.
15
15
You can call the function `FHE.requestDecryption` as such:
16
16
17
17
```solidity
18
-
function requestDecryption(uint256 requestID, bytes32[] calldata ctsHandles, bytes4 callbackSelector) external payable;
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`. 
26
24
27
25
`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.
28
26
29
27
`callbackSelector` is the function selector of the callback function, which will be called once the relayer fulfils the decryption request.
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:
61
59
62
60
#### Function arguments
63
61
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.
67
64
68
-
If
65
+
This function reverts if the signatures are invalid.
Copy file name to clipboardExpand all lines: docs/solidity-guides/decryption/reencryption.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ The re-encryption process involves retrieving ciphertext from the blockchain and
18
18
19
19
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.
20
20
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:
22
22
23
23
1. Retrieving the ciphertext from the blockchain using a contract’s view function.
24
24
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
28
28
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:
Copy file name to clipboardExpand all lines: docs/solidity-guides/foundry.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,4 +4,4 @@ This guide explains how to use Foundry with FHEVM for developing smart contracts
4
4
5
5
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.
6
6
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