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/inputs.md
+22-39Lines changed: 22 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,10 +28,7 @@ When a function in a smart contract is called, it may accept two types of parame
28
28
Here’s an example of a Solidity function accepting multiple encrypted parameters:
29
29
30
30
```solidity
31
-
function myExample(
32
-
address account,
33
-
uint id,
34
-
bool isAllowed,
31
+
function exampleFunction(
35
32
externalEbool param1,
36
33
externalEuint64 param2,
37
34
externalEuint8 param3,
@@ -43,56 +40,43 @@ function myExample(
43
40
44
41
In this example, `param1`, `param2`, and `param3` are encrypted inputs for `ebool`, `euint64`, and `euint8` while `inputProof` contains the corresponding ZKPoK to validate their authenticity.
45
42
46
-
##Client-Side implementation
43
+
### Input Generation using Hardhat
47
44
48
-
To interact with such a function, developers can use the [@fhevm/sdk](https://github.com/zama-ai/fhevmjs) library to create and manage encrypted inputs. Below is an example implementation:
45
+
In the below example, we use Alice's address to create the encrypted inputs and submits the transaction.
-**`add64`, `addBool`, and `add8`**: Specify the types and values of inputs to encrypt.
77
-
-**`encrypt`**: Generates the encrypted inputs and the zero-knowledge proof.
78
-
79
63
## Validating encrypted inputs
80
64
81
65
Smart contracts process encrypted inputs by verifying them against the associated zero-knowledge proof. This is done using the `FHE.asEuintXX`, `FHE.asEbool`, or `FHE.asEaddress` functions, which validate the input and convert it into the appropriate encrypted type.
82
66
83
-
### Example validation that goes along the client-Side implementation
67
+
### Example validation
84
68
85
69
This example demonstrates a function that performs multiple encrypted operations, such as updating a user's encrypted balance and toggling an encrypted boolean flag:
@@ -110,10 +94,9 @@ This example demonstrates a function that performs multiple encrypted operations
110
94
function getEncryptedFlag() public view returns (ebool) {
111
95
return userFlags[msg.sender];
112
96
}
113
-
}
114
97
```
115
98
116
-
### Example validation in the `encryptedERC20.sol` smart contract
99
+
### Example validation in the `ConfidentialERC20.sol` smart contract
117
100
118
101
Here’s an example of a smart contract function that verifies an encrypted input before proceeding:
119
102
@@ -134,7 +117,7 @@ function transfer(
134
117
### How validation works
135
118
136
119
1.**Input verification**:\
137
-
The `FHE.asEuintXX` function ensures that the input is a valid ciphertext with a corresponding ZKPoK.
120
+
The `FHE.fromExternal` function ensures that the input is a valid ciphertext with a corresponding ZKPoK.
138
121
2.**Type conversion**:\
139
122
The function transforms `externalEbool`, `externalEaddress`, `externalEuintXX` into the appropriate encrypted type (`ebool`, `eaddress`, `euintXX`) for further operations within the contract.
0 commit comments