@openzeppelin/confidential-contracts 0.2.0-rc.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/build/contracts/Checkpoints.json +2 -2
  2. package/build/contracts/CheckpointsConfidential.json +3 -9
  3. package/build/contracts/ConfidentialFungibleTokenUtils.json +2 -2
  4. package/build/contracts/ConfidentialFungibleTokenVotes.json +23 -0
  5. package/build/contracts/{TFHESafeMath.json → FHESafeMath.json} +4 -4
  6. package/build/contracts/HandleAccessManager.json +34 -0
  7. package/build/contracts/VestingWalletCliffConfidential.json +3 -3
  8. package/build/contracts/VestingWalletConfidential.json +3 -3
  9. package/build/contracts/VestingWalletConfidentialFactory.json +16 -151
  10. package/build/contracts/VotesConfidential.json +23 -0
  11. package/finance/ERC7821WithExecutor.sol +2 -2
  12. package/finance/VestingWalletCliffConfidential.sol +15 -4
  13. package/finance/VestingWalletConfidential.sol +28 -13
  14. package/finance/VestingWalletConfidentialFactory.sol +32 -116
  15. package/governance/utils/VotesConfidential.sol +18 -4
  16. package/interfaces/IConfidentialFungibleToken.sol +2 -2
  17. package/interfaces/IConfidentialFungibleTokenReceiver.sol +1 -1
  18. package/package.json +1 -1
  19. package/token/ConfidentialFungibleToken.sol +9 -12
  20. package/token/extensions/ConfidentialFungibleTokenERC20Wrapper.sol +19 -8
  21. package/token/extensions/ConfidentialFungibleTokenVotes.sol +9 -1
  22. package/token/utils/ConfidentialFungibleTokenUtils.sol +1 -1
  23. package/utils/{TFHESafeMath.sol → FHESafeMath.sol} +2 -2
  24. package/utils/HandleAccessManager.sol +29 -0
  25. package/utils/structs/CheckpointsConfidential.sol +1 -6
  26. package/utils/structs/temporary-Checkpoints.sol +1 -1
@@ -9,8 +9,8 @@
9
9
  "type": "error"
10
10
  }
11
11
  ],
12
- "bytecode": "0x60556032600b8282823980515f1a607314602657634e487b7160e01b5f525f60045260245ffd5b305f52607381538281f3fe730000000000000000000000000000000000000000301460806040525f5ffdfea2646970667358221220fae0bfd796eb509c298d3dbe84db66209673e90a0fef5e9327e8cc01bfdb512364736f6c634300081d0033",
13
- "deployedBytecode": "0x730000000000000000000000000000000000000000301460806040525f5ffdfea2646970667358221220fae0bfd796eb509c298d3dbe84db66209673e90a0fef5e9327e8cc01bfdb512364736f6c634300081d0033",
12
+ "bytecode": "0x60556032600b8282823980515f1a607314602657634e487b7160e01b5f525f60045260245ffd5b305f52607381538281f3fe730000000000000000000000000000000000000000301460806040525f5ffdfea2646970667358221220a82f4123dc620a523cf32b417d00b9472eafbc138490892aba0950faef876e5f64736f6c634300081d0033",
13
+ "deployedBytecode": "0x730000000000000000000000000000000000000000301460806040525f5ffdfea2646970667358221220a82f4123dc620a523cf32b417d00b9472eafbc138490892aba0950faef876e5f64736f6c634300081d0033",
14
14
  "linkReferences": {},
15
15
  "deployedLinkReferences": {}
16
16
  }
@@ -2,15 +2,9 @@
2
2
  "_format": "hh-sol-artifact-1",
3
3
  "contractName": "CheckpointsConfidential",
4
4
  "sourceName": "contracts/utils/structs/CheckpointsConfidential.sol",
5
- "abi": [
6
- {
7
- "inputs": [],
8
- "name": "CheckpointUnorderedInsertion",
9
- "type": "error"
10
- }
11
- ],
12
- "bytecode": "0x60556032600b8282823980515f1a607314602657634e487b7160e01b5f525f60045260245ffd5b305f52607381538281f3fe730000000000000000000000000000000000000000301460806040525f5ffdfea26469706673582212208d10bbb6df7f7649514536955adf1972a6b98a5041d01dae6110903bae3bd54264736f6c634300081d0033",
13
- "deployedBytecode": "0x730000000000000000000000000000000000000000301460806040525f5ffdfea26469706673582212208d10bbb6df7f7649514536955adf1972a6b98a5041d01dae6110903bae3bd54264736f6c634300081d0033",
5
+ "abi": [],
6
+ "bytecode": "0x60556032600b8282823980515f1a607314602657634e487b7160e01b5f525f60045260245ffd5b305f52607381538281f3fe730000000000000000000000000000000000000000301460806040525f5ffdfea264697066735822122057a94665aa47e1eee66c46039103adce039864c0979c586fd3fca3eb7ee1340764736f6c634300081d0033",
7
+ "deployedBytecode": "0x730000000000000000000000000000000000000000301460806040525f5ffdfea264697066735822122057a94665aa47e1eee66c46039103adce039864c0979c586fd3fca3eb7ee1340764736f6c634300081d0033",
14
8
  "linkReferences": {},
15
9
  "deployedLinkReferences": {}
16
10
  }
@@ -3,8 +3,8 @@
3
3
  "contractName": "ConfidentialFungibleTokenUtils",
4
4
  "sourceName": "contracts/token/utils/ConfidentialFungibleTokenUtils.sol",
5
5
  "abi": [],
6
- "bytecode": "0x60556032600b8282823980515f1a607314602657634e487b7160e01b5f525f60045260245ffd5b305f52607381538281f3fe730000000000000000000000000000000000000000301460806040525f5ffdfea26469706673582212205cc35163a526cc9f1c44e34cb185c44eb4c490f59215936ad87fe3140963d2bb64736f6c634300081d0033",
7
- "deployedBytecode": "0x730000000000000000000000000000000000000000301460806040525f5ffdfea26469706673582212205cc35163a526cc9f1c44e34cb185c44eb4c490f59215936ad87fe3140963d2bb64736f6c634300081d0033",
6
+ "bytecode": "0x60556032600b8282823980515f1a607314602657634e487b7160e01b5f525f60045260245ffd5b305f52607381538281f3fe730000000000000000000000000000000000000000301460806040525f5ffdfea2646970667358221220b16578e84785381452ea9c7ec4dfc058f69cc926edb04fddadfe0ed26ee6f7d264736f6c634300081d0033",
7
+ "deployedBytecode": "0x730000000000000000000000000000000000000000301460806040525f5ffdfea2646970667358221220b16578e84785381452ea9c7ec4dfc058f69cc926edb04fddadfe0ed26ee6f7d264736f6c634300081d0033",
8
8
  "linkReferences": {},
9
9
  "deployedLinkReferences": {}
10
10
  }
@@ -832,6 +832,29 @@
832
832
  "stateMutability": "nonpayable",
833
833
  "type": "function"
834
834
  },
835
+ {
836
+ "inputs": [
837
+ {
838
+ "internalType": "bytes32",
839
+ "name": "handle",
840
+ "type": "bytes32"
841
+ },
842
+ {
843
+ "internalType": "address",
844
+ "name": "account",
845
+ "type": "address"
846
+ },
847
+ {
848
+ "internalType": "bool",
849
+ "name": "persistent",
850
+ "type": "bool"
851
+ }
852
+ ],
853
+ "name": "getHandleAllowance",
854
+ "outputs": [],
855
+ "stateMutability": "nonpayable",
856
+ "type": "function"
857
+ },
835
858
  {
836
859
  "inputs": [
837
860
  {
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "_format": "hh-sol-artifact-1",
3
- "contractName": "TFHESafeMath",
4
- "sourceName": "contracts/utils/TFHESafeMath.sol",
3
+ "contractName": "FHESafeMath",
4
+ "sourceName": "contracts/utils/FHESafeMath.sol",
5
5
  "abi": [],
6
- "bytecode": "0x60556032600b8282823980515f1a607314602657634e487b7160e01b5f525f60045260245ffd5b305f52607381538281f3fe730000000000000000000000000000000000000000301460806040525f5ffdfea26469706673582212202db981d102d3bd3880b704612058ffa3febefb18c1373c66a5feb1a1993637a564736f6c634300081d0033",
7
- "deployedBytecode": "0x730000000000000000000000000000000000000000301460806040525f5ffdfea26469706673582212202db981d102d3bd3880b704612058ffa3febefb18c1373c66a5feb1a1993637a564736f6c634300081d0033",
6
+ "bytecode": "0x60556032600b8282823980515f1a607314602657634e487b7160e01b5f525f60045260245ffd5b305f52607381538281f3fe730000000000000000000000000000000000000000301460806040525f5ffdfea2646970667358221220169c9cbdfb2791e1d96b54361ac4446969846b7a58a8da1f7dba5af4fa757c7564736f6c634300081d0033",
7
+ "deployedBytecode": "0x730000000000000000000000000000000000000000301460806040525f5ffdfea2646970667358221220169c9cbdfb2791e1d96b54361ac4446969846b7a58a8da1f7dba5af4fa757c7564736f6c634300081d0033",
8
8
  "linkReferences": {},
9
9
  "deployedLinkReferences": {}
10
10
  }
@@ -0,0 +1,34 @@
1
+ {
2
+ "_format": "hh-sol-artifact-1",
3
+ "contractName": "HandleAccessManager",
4
+ "sourceName": "contracts/utils/HandleAccessManager.sol",
5
+ "abi": [
6
+ {
7
+ "inputs": [
8
+ {
9
+ "internalType": "bytes32",
10
+ "name": "handle",
11
+ "type": "bytes32"
12
+ },
13
+ {
14
+ "internalType": "address",
15
+ "name": "account",
16
+ "type": "address"
17
+ },
18
+ {
19
+ "internalType": "bool",
20
+ "name": "persistent",
21
+ "type": "bool"
22
+ }
23
+ ],
24
+ "name": "getHandleAllowance",
25
+ "outputs": [],
26
+ "stateMutability": "nonpayable",
27
+ "type": "function"
28
+ }
29
+ ],
30
+ "bytecode": "0x",
31
+ "deployedBytecode": "0x",
32
+ "linkReferences": {},
33
+ "deployedLinkReferences": {}
34
+ }
@@ -202,7 +202,7 @@
202
202
  "name": "released",
203
203
  "outputs": [
204
204
  {
205
- "internalType": "euint64",
205
+ "internalType": "euint128",
206
206
  "name": "",
207
207
  "type": "bytes32"
208
208
  }
@@ -251,9 +251,9 @@
251
251
  "type": "address"
252
252
  },
253
253
  {
254
- "internalType": "uint64",
254
+ "internalType": "uint48",
255
255
  "name": "timestamp",
256
- "type": "uint64"
256
+ "type": "uint48"
257
257
  }
258
258
  ],
259
259
  "name": "vestedAmount",
@@ -173,7 +173,7 @@
173
173
  "name": "released",
174
174
  "outputs": [
175
175
  {
176
- "internalType": "euint64",
176
+ "internalType": "euint128",
177
177
  "name": "",
178
178
  "type": "bytes32"
179
179
  }
@@ -222,9 +222,9 @@
222
222
  "type": "address"
223
223
  },
224
224
  {
225
- "internalType": "uint64",
225
+ "internalType": "uint48",
226
226
  "name": "timestamp",
227
- "type": "uint64"
227
+ "type": "uint48"
228
228
  }
229
229
  ],
230
230
  "name": "vestedAmount",
@@ -24,33 +24,6 @@
24
24
  "name": "InsufficientBalance",
25
25
  "type": "error"
26
26
  },
27
- {
28
- "inputs": [
29
- {
30
- "internalType": "address",
31
- "name": "owner",
32
- "type": "address"
33
- }
34
- ],
35
- "name": "OwnableInvalidOwner",
36
- "type": "error"
37
- },
38
- {
39
- "inputs": [
40
- {
41
- "internalType": "uint64",
42
- "name": "cliffSeconds",
43
- "type": "uint64"
44
- },
45
- {
46
- "internalType": "uint64",
47
- "name": "durationSeconds",
48
- "type": "uint64"
49
- }
50
- ],
51
- "name": "VestingWalletCliffConfidentialInvalidCliffDuration",
52
- "type": "error"
53
- },
54
27
  {
55
28
  "anonymous": false,
56
29
  "inputs": [
@@ -60,35 +33,11 @@
60
33
  "name": "vestingWalletConfidential",
61
34
  "type": "address"
62
35
  },
63
- {
64
- "indexed": true,
65
- "internalType": "address",
66
- "name": "beneficiary",
67
- "type": "address"
68
- },
69
36
  {
70
37
  "indexed": false,
71
- "internalType": "uint48",
72
- "name": "startTimestamp",
73
- "type": "uint48"
74
- },
75
- {
76
- "indexed": false,
77
- "internalType": "uint48",
78
- "name": "durationSeconds",
79
- "type": "uint48"
80
- },
81
- {
82
- "indexed": false,
83
- "internalType": "uint48",
84
- "name": "cliffSeconds",
85
- "type": "uint48"
86
- },
87
- {
88
- "indexed": true,
89
- "internalType": "address",
90
- "name": "executor",
91
- "type": "address"
38
+ "internalType": "bytes",
39
+ "name": "initArgs",
40
+ "type": "bytes"
92
41
  }
93
42
  ],
94
43
  "name": "VestingWalletConfidentialCreated",
@@ -103,12 +52,6 @@
103
52
  "name": "vestingWalletConfidential",
104
53
  "type": "address"
105
54
  },
106
- {
107
- "indexed": true,
108
- "internalType": "address",
109
- "name": "beneficiary",
110
- "type": "address"
111
- },
112
55
  {
113
56
  "indexed": true,
114
57
  "internalType": "address",
@@ -118,32 +61,14 @@
118
61
  {
119
62
  "indexed": false,
120
63
  "internalType": "euint64",
121
- "name": "encryptedAmount",
64
+ "name": "transferredAmount",
122
65
  "type": "bytes32"
123
66
  },
124
67
  {
125
68
  "indexed": false,
126
- "internalType": "uint48",
127
- "name": "startTimestamp",
128
- "type": "uint48"
129
- },
130
- {
131
- "indexed": false,
132
- "internalType": "uint48",
133
- "name": "durationSeconds",
134
- "type": "uint48"
135
- },
136
- {
137
- "indexed": false,
138
- "internalType": "uint48",
139
- "name": "cliffSeconds",
140
- "type": "uint48"
141
- },
142
- {
143
- "indexed": false,
144
- "internalType": "address",
145
- "name": "executor",
146
- "type": "address"
69
+ "internalType": "bytes",
70
+ "name": "initArgs",
71
+ "type": "bytes"
147
72
  }
148
73
  ],
149
74
  "name": "VestingWalletConfidentialFunded",
@@ -158,41 +83,21 @@
158
83
  },
159
84
  {
160
85
  "components": [
161
- {
162
- "internalType": "address",
163
- "name": "beneficiary",
164
- "type": "address"
165
- },
166
86
  {
167
87
  "internalType": "externalEuint64",
168
88
  "name": "encryptedAmount",
169
89
  "type": "bytes32"
170
90
  },
171
91
  {
172
- "internalType": "uint48",
173
- "name": "startTimestamp",
174
- "type": "uint48"
175
- },
176
- {
177
- "internalType": "uint48",
178
- "name": "durationSeconds",
179
- "type": "uint48"
180
- },
181
- {
182
- "internalType": "uint48",
183
- "name": "cliffSeconds",
184
- "type": "uint48"
92
+ "internalType": "bytes",
93
+ "name": "initArgs",
94
+ "type": "bytes"
185
95
  }
186
96
  ],
187
97
  "internalType": "struct VestingWalletConfidentialFactory.VestingPlan[]",
188
98
  "name": "vestingPlans",
189
99
  "type": "tuple[]"
190
100
  },
191
- {
192
- "internalType": "address",
193
- "name": "executor",
194
- "type": "address"
195
- },
196
101
  {
197
102
  "internalType": "bytes",
198
103
  "name": "inputProof",
@@ -207,29 +112,9 @@
207
112
  {
208
113
  "inputs": [
209
114
  {
210
- "internalType": "address",
211
- "name": "beneficiary",
212
- "type": "address"
213
- },
214
- {
215
- "internalType": "uint48",
216
- "name": "startTimestamp",
217
- "type": "uint48"
218
- },
219
- {
220
- "internalType": "uint48",
221
- "name": "durationSeconds",
222
- "type": "uint48"
223
- },
224
- {
225
- "internalType": "uint48",
226
- "name": "cliffSeconds",
227
- "type": "uint48"
228
- },
229
- {
230
- "internalType": "address",
231
- "name": "executor",
232
- "type": "address"
115
+ "internalType": "bytes",
116
+ "name": "initArgs",
117
+ "type": "bytes"
233
118
  }
234
119
  ],
235
120
  "name": "createVestingWalletConfidential",
@@ -246,29 +131,9 @@
246
131
  {
247
132
  "inputs": [
248
133
  {
249
- "internalType": "address",
250
- "name": "beneficiary",
251
- "type": "address"
252
- },
253
- {
254
- "internalType": "uint48",
255
- "name": "startTimestamp",
256
- "type": "uint48"
257
- },
258
- {
259
- "internalType": "uint48",
260
- "name": "durationSeconds",
261
- "type": "uint48"
262
- },
263
- {
264
- "internalType": "uint48",
265
- "name": "cliffSeconds",
266
- "type": "uint48"
267
- },
268
- {
269
- "internalType": "address",
270
- "name": "executor",
271
- "type": "address"
134
+ "internalType": "bytes",
135
+ "name": "initArgs",
136
+ "type": "bytes"
272
137
  }
273
138
  ],
274
139
  "name": "predictVestingWalletConfidential",
@@ -323,6 +323,29 @@
323
323
  "stateMutability": "view",
324
324
  "type": "function"
325
325
  },
326
+ {
327
+ "inputs": [
328
+ {
329
+ "internalType": "bytes32",
330
+ "name": "handle",
331
+ "type": "bytes32"
332
+ },
333
+ {
334
+ "internalType": "address",
335
+ "name": "account",
336
+ "type": "address"
337
+ },
338
+ {
339
+ "internalType": "bool",
340
+ "name": "persistent",
341
+ "type": "bool"
342
+ }
343
+ ],
344
+ "name": "getHandleAllowance",
345
+ "outputs": [],
346
+ "stateMutability": "nonpayable",
347
+ "type": "function"
348
+ },
326
349
  {
327
350
  "inputs": [
328
351
  {
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.2) (finance/ERC7821WithExecutor.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (finance/ERC7821WithExecutor.sol)
3
3
  pragma solidity ^0.8.20;
4
4
 
5
5
  import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
@@ -39,7 +39,7 @@ abstract contract ERC7821WithExecutor is Initializable, ERC7821 {
39
39
  }
40
40
 
41
41
  function _getERC7821WithExecutorStorage() private pure returns (ERC7821WithExecutorStorage storage $) {
42
- assembly {
42
+ assembly ("memory-safe") {
43
43
  $.slot := ERC7821WithExecutorStorageLocation
44
44
  }
45
45
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.2) (finance/VestingWalletCliffConfidential.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (finance/VestingWalletCliffConfidential.sol)
3
3
  pragma solidity ^0.8.27;
4
4
 
5
5
  import {euint128} from "@fhevm/solidity/lib/FHE.sol";
@@ -33,7 +33,18 @@ abstract contract VestingWalletCliffConfidential is VestingWalletConfidential {
33
33
  * start timestamp (see {VestingWalletConfidential-start}) and ends `cliffSeconds` later.
34
34
  */
35
35
  // solhint-disable-next-line func-name-mixedcase
36
- function __VestingWalletCliffConfidential_init(uint48 cliffSeconds) internal onlyInitializing {
36
+ function __VestingWalletCliffConfidential_init(
37
+ address beneficiary,
38
+ uint48 startTimestamp,
39
+ uint48 durationSeconds,
40
+ uint48 cliffSeconds
41
+ ) internal onlyInitializing {
42
+ __VestingWalletConfidential_init(beneficiary, startTimestamp, durationSeconds);
43
+ __VestingWalletCliffConfidential_init_unchained(cliffSeconds);
44
+ }
45
+
46
+ // solhint-disable-next-line func-name-mixedcase
47
+ function __VestingWalletCliffConfidential_init_unchained(uint48 cliffSeconds) internal onlyInitializing {
37
48
  require(
38
49
  cliffSeconds <= duration(),
39
50
  VestingWalletCliffConfidentialInvalidCliffDuration(cliffSeconds, duration())
@@ -50,12 +61,12 @@ abstract contract VestingWalletCliffConfidential is VestingWalletConfidential {
50
61
  * effect from calling the inherited implementation (i.e. `super._vestingSchedule`). Carefully consider
51
62
  * this caveat if the overridden implementation of this function has any (e.g. writing to memory or reverting).
52
63
  */
53
- function _vestingSchedule(euint128 totalAllocation, uint64 timestamp) internal virtual override returns (euint128) {
64
+ function _vestingSchedule(euint128 totalAllocation, uint48 timestamp) internal virtual override returns (euint128) {
54
65
  return timestamp < cliff() ? euint128.wrap(0) : super._vestingSchedule(totalAllocation, timestamp);
55
66
  }
56
67
 
57
68
  function _getVestingWalletCliffStorage() private pure returns (VestingWalletCliffStorage storage $) {
58
- assembly {
69
+ assembly ("memory-safe") {
59
70
  $.slot := VestingWalletCliffStorageLocation
60
71
  }
61
72
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.2) (finance/VestingWalletConfidential.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (finance/VestingWalletConfidential.sol)
3
3
  pragma solidity ^0.8.24;
4
4
 
5
5
  import {FHE, ebool, euint64, euint128} from "@fhevm/solidity/lib/FHE.sol";
@@ -22,11 +22,13 @@ import {IConfidentialFungibleToken} from "./../interfaces/IConfidentialFungibleT
22
22
  *
23
23
  * NOTE: When using this contract with any token whose balance is adjusted automatically (i.e. a rebase token), make
24
24
  * sure to account the supply/balance adjustment in the vesting schedule to ensure the vested amount is as intended.
25
+ *
26
+ * Confidential vesting wallet contracts can be deployed (as clones) using the {VestingWalletConfidentialFactory}.
25
27
  */
26
28
  abstract contract VestingWalletConfidential is OwnableUpgradeable, ReentrancyGuardTransient {
27
29
  /// @custom:storage-location erc7201:openzeppelin.storage.VestingWalletConfidential
28
30
  struct VestingWalletStorage {
29
- mapping(address token => euint64) _tokenReleased;
31
+ mapping(address token => euint128) _tokenReleased;
30
32
  uint64 _start;
31
33
  uint64 _duration;
32
34
  }
@@ -36,6 +38,7 @@ abstract contract VestingWalletConfidential is OwnableUpgradeable, ReentrancyGua
36
38
  bytes32 private constant VestingWalletStorageLocation =
37
39
  0x78ce9ee9eb65fa0cf5bf10e861c3a95cb7c3c713c96ab1e5323a21e846796800;
38
40
 
41
+ /// @dev Emitted when releasable vested tokens are released.
39
42
  event VestingWalletConfidentialTokenReleased(address indexed token, euint64 amount);
40
43
 
41
44
  /// @dev Timestamp at which the vesting starts.
@@ -54,7 +57,7 @@ abstract contract VestingWalletConfidential is OwnableUpgradeable, ReentrancyGua
54
57
  }
55
58
 
56
59
  /// @dev Amount of token already released
57
- function released(address token) public view virtual returns (euint64) {
60
+ function released(address token) public view virtual returns (euint128) {
58
61
  return _getVestingWalletStorage()._tokenReleased[token];
59
62
  }
60
63
 
@@ -63,7 +66,10 @@ abstract contract VestingWalletConfidential is OwnableUpgradeable, ReentrancyGua
63
66
  * {IConfidentialFungibleToken} contract.
64
67
  */
65
68
  function releasable(address token) public virtual returns (euint64) {
66
- return FHE.asEuint64(FHE.sub(vestedAmount(token, uint64(block.timestamp)), released(token)));
69
+ euint128 vestedAmount_ = vestedAmount(token, uint48(block.timestamp));
70
+ euint128 releasedAmount = released(token);
71
+ ebool success = FHE.ge(vestedAmount_, releasedAmount);
72
+ return FHE.select(success, FHE.asEuint64(FHE.sub(vestedAmount_, releasedAmount)), FHE.asEuint64(0));
67
73
  }
68
74
 
69
75
  /**
@@ -76,21 +82,22 @@ abstract contract VestingWalletConfidential is OwnableUpgradeable, ReentrancyGua
76
82
  FHE.allowTransient(amount, token);
77
83
  euint64 amountSent = IConfidentialFungibleToken(token).confidentialTransfer(owner(), amount);
78
84
 
79
- euint64 newReleasedAmount = FHE.add(released(token), amountSent);
85
+ // This could overflow if the total supply is resent `type(uint128).max/type(uint64).max` times. This is an accepted risk.
86
+ euint128 newReleasedAmount = FHE.add(released(token), amountSent);
80
87
  FHE.allow(newReleasedAmount, owner());
81
88
  FHE.allowThis(newReleasedAmount);
82
89
  _getVestingWalletStorage()._tokenReleased[token] = newReleasedAmount;
83
90
  emit VestingWalletConfidentialTokenReleased(token, amountSent);
84
91
  }
85
92
 
86
- /// @dev Calculates the amount of tokens that have already vested. Default implementation is a linear vesting curve.
87
- function vestedAmount(address token, uint64 timestamp) public virtual returns (euint128) {
93
+ /**
94
+ * @dev Calculates the amount of tokens that have been vested at the given timestamp.
95
+ * Default implementation is a linear vesting curve.
96
+ */
97
+ function vestedAmount(address token, uint48 timestamp) public virtual returns (euint128) {
88
98
  return
89
99
  _vestingSchedule(
90
- FHE.add(
91
- FHE.asEuint128(IConfidentialFungibleToken(token).confidentialBalanceOf(address(this))),
92
- released(token)
93
- ),
100
+ FHE.add(released(token), IConfidentialFungibleToken(token).confidentialBalanceOf(address(this))),
94
101
  timestamp
95
102
  );
96
103
  }
@@ -106,13 +113,21 @@ abstract contract VestingWalletConfidential is OwnableUpgradeable, ReentrancyGua
106
113
  uint48 durationSeconds
107
114
  ) internal onlyInitializing {
108
115
  __Ownable_init(beneficiary);
116
+ __VestingWalletConfidential_init_unchained(startTimestamp, durationSeconds);
117
+ }
118
+
119
+ // solhint-disable-next-line func-name-mixedcase
120
+ function __VestingWalletConfidential_init_unchained(
121
+ uint48 startTimestamp,
122
+ uint48 durationSeconds
123
+ ) internal onlyInitializing {
109
124
  VestingWalletStorage storage $ = _getVestingWalletStorage();
110
125
  $._start = startTimestamp;
111
126
  $._duration = durationSeconds;
112
127
  }
113
128
 
114
129
  /// @dev This returns the amount vested, as a function of time, for an asset given its total historical allocation.
115
- function _vestingSchedule(euint128 totalAllocation, uint64 timestamp) internal virtual returns (euint128) {
130
+ function _vestingSchedule(euint128 totalAllocation, uint48 timestamp) internal virtual returns (euint128) {
116
131
  if (timestamp < start()) {
117
132
  return euint128.wrap(0);
118
133
  } else if (timestamp >= end()) {
@@ -123,7 +138,7 @@ abstract contract VestingWalletConfidential is OwnableUpgradeable, ReentrancyGua
123
138
  }
124
139
 
125
140
  function _getVestingWalletStorage() private pure returns (VestingWalletStorage storage $) {
126
- assembly {
141
+ assembly ("memory-safe") {
127
142
  $.slot := VestingWalletStorageLocation
128
143
  }
129
144
  }
@@ -1,48 +1,34 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.2) (finance/VestingWalletConfidentialFactory.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (finance/VestingWalletConfidentialFactory.sol)
3
3
  pragma solidity ^0.8.27;
4
4
 
5
- import {FHE, euint64, externalEuint64, euint128} from "@fhevm/solidity/lib/FHE.sol";
6
- import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
5
+ import {FHE, euint64, externalEuint64} from "@fhevm/solidity/lib/FHE.sol";
7
6
  import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
8
7
  import {IConfidentialFungibleToken} from "./../interfaces/IConfidentialFungibleToken.sol";
9
- import {VestingWalletCliffConfidential} from "./VestingWalletCliffConfidential.sol";
10
8
 
11
9
  /**
12
10
  * @dev A factory which enables batch funding of vesting wallets.
13
11
  *
14
- * The {_deployVestingWalletImplementation} and {_initializeVestingWallet} functions remain unimplemented
15
- * to allow for custom implementations of the vesting wallet to be used.
12
+ * The {_deployVestingWalletImplementation}, {_initializeVestingWallet}, and {_validateVestingWalletInitArgs}
13
+ * functions remain unimplemented to allow for custom implementations of the vesting wallet to be used.
16
14
  */
17
15
  abstract contract VestingWalletConfidentialFactory {
18
16
  struct VestingPlan {
19
- address beneficiary;
20
17
  externalEuint64 encryptedAmount;
21
- uint48 startTimestamp;
22
- uint48 durationSeconds;
23
- uint48 cliffSeconds;
18
+ bytes initArgs;
24
19
  }
25
20
 
26
21
  address private immutable _vestingImplementation;
27
22
 
23
+ /// @dev Emitted for each vesting wallet funded within a batch.
28
24
  event VestingWalletConfidentialFunded(
29
25
  address indexed vestingWalletConfidential,
30
- address indexed beneficiary,
31
26
  address indexed confidentialFungibleToken,
32
- euint64 encryptedAmount,
33
- uint48 startTimestamp,
34
- uint48 durationSeconds,
35
- uint48 cliffSeconds,
36
- address executor
37
- );
38
- event VestingWalletConfidentialCreated(
39
- address indexed vestingWalletConfidential,
40
- address indexed beneficiary,
41
- uint48 startTimestamp,
42
- uint48 durationSeconds,
43
- uint48 cliffSeconds,
44
- address indexed executor
27
+ euint64 transferredAmount,
28
+ bytes initArgs
45
29
  );
30
+ /// @dev Emitted when a vesting wallet is deployed.
31
+ event VestingWalletConfidentialCreated(address indexed vestingWalletConfidential, bytes initArgs);
46
32
 
47
33
  constructor() {
48
34
  _vestingImplementation = _deployVestingWalletImplementation();
@@ -59,50 +45,28 @@ abstract contract VestingWalletConfidentialFactory {
59
45
  function batchFundVestingWalletConfidential(
60
46
  address confidentialFungibleToken,
61
47
  VestingPlan[] calldata vestingPlans,
62
- address executor,
63
48
  bytes calldata inputProof
64
49
  ) public virtual {
65
50
  uint256 vestingPlansLength = vestingPlans.length;
66
51
  for (uint256 i = 0; i < vestingPlansLength; i++) {
67
52
  VestingPlan memory vestingPlan = vestingPlans[i];
68
- require(
69
- vestingPlan.cliffSeconds <= vestingPlan.durationSeconds,
70
- VestingWalletCliffConfidential.VestingWalletCliffConfidentialInvalidCliffDuration(
71
- vestingPlan.cliffSeconds,
72
- vestingPlan.durationSeconds
73
- )
74
- );
53
+ _validateVestingWalletInitArgs(vestingPlan.initArgs);
75
54
 
76
- require(vestingPlan.beneficiary != address(0), OwnableUpgradeable.OwnableInvalidOwner(address(0)));
77
- address vestingWalletAddress = predictVestingWalletConfidential(
78
- vestingPlan.beneficiary,
79
- vestingPlan.startTimestamp,
80
- vestingPlan.durationSeconds,
81
- vestingPlan.cliffSeconds,
82
- executor
83
- );
55
+ address vestingWalletAddress = predictVestingWalletConfidential(vestingPlan.initArgs);
84
56
 
85
- euint64 transferredAmount;
86
- {
87
- // avoiding stack too deep with scope
88
- euint64 encryptedAmount = FHE.fromExternal(vestingPlan.encryptedAmount, inputProof);
89
- FHE.allowTransient(encryptedAmount, confidentialFungibleToken);
90
- transferredAmount = IConfidentialFungibleToken(confidentialFungibleToken).confidentialTransferFrom(
91
- msg.sender,
92
- vestingWalletAddress,
93
- encryptedAmount
94
- );
95
- }
57
+ euint64 encryptedAmount = FHE.fromExternal(vestingPlan.encryptedAmount, inputProof);
58
+ FHE.allowTransient(encryptedAmount, confidentialFungibleToken);
59
+ euint64 transferredAmount = IConfidentialFungibleToken(confidentialFungibleToken).confidentialTransferFrom(
60
+ msg.sender,
61
+ vestingWalletAddress,
62
+ encryptedAmount
63
+ );
96
64
 
97
65
  emit VestingWalletConfidentialFunded(
98
66
  vestingWalletAddress,
99
- vestingPlan.beneficiary,
100
67
  confidentialFungibleToken,
101
68
  transferredAmount,
102
- vestingPlan.startTimestamp,
103
- vestingPlan.durationSeconds,
104
- vestingPlan.cliffSeconds,
105
- executor
69
+ vestingPlan.initArgs
106
70
  );
107
71
  }
108
72
  }
@@ -112,75 +76,33 @@ abstract contract VestingWalletConfidentialFactory {
112
76
  *
113
77
  * Emits a {VestingWalletConfidentialCreated}.
114
78
  */
115
- function createVestingWalletConfidential(
116
- address beneficiary,
117
- uint48 startTimestamp,
118
- uint48 durationSeconds,
119
- uint48 cliffSeconds,
120
- address executor
121
- ) public virtual returns (address) {
79
+ function createVestingWalletConfidential(bytes calldata initArgs) public virtual returns (address) {
122
80
  // Will revert if clone already created
123
81
  address vestingWalletConfidentialAddress = Clones.cloneDeterministic(
124
82
  _vestingImplementation,
125
- _getCreate2VestingWalletConfidentialSalt(
126
- beneficiary,
127
- startTimestamp,
128
- durationSeconds,
129
- cliffSeconds,
130
- executor
131
- )
132
- );
133
- _initializeVestingWallet(
134
- vestingWalletConfidentialAddress,
135
- beneficiary,
136
- startTimestamp,
137
- durationSeconds,
138
- cliffSeconds,
139
- executor
140
- );
141
- emit VestingWalletConfidentialCreated(
142
- beneficiary,
143
- vestingWalletConfidentialAddress,
144
- startTimestamp,
145
- durationSeconds,
146
- cliffSeconds,
147
- executor
83
+ _getCreate2VestingWalletConfidentialSalt(initArgs)
148
84
  );
85
+ _initializeVestingWallet(vestingWalletConfidentialAddress, initArgs);
86
+ emit VestingWalletConfidentialCreated(vestingWalletConfidentialAddress, initArgs);
149
87
  return vestingWalletConfidentialAddress;
150
88
  }
151
89
 
152
90
  /**
153
91
  * @dev Predicts the deterministic address for a confidential vesting wallet.
154
92
  */
155
- function predictVestingWalletConfidential(
156
- address beneficiary,
157
- uint48 startTimestamp,
158
- uint48 durationSeconds,
159
- uint48 cliffSeconds,
160
- address executor
161
- ) public view virtual returns (address) {
93
+ function predictVestingWalletConfidential(bytes memory initArgs) public view virtual returns (address) {
162
94
  return
163
95
  Clones.predictDeterministicAddress(
164
96
  _vestingImplementation,
165
- _getCreate2VestingWalletConfidentialSalt(
166
- beneficiary,
167
- startTimestamp,
168
- durationSeconds,
169
- cliffSeconds,
170
- executor
171
- )
97
+ _getCreate2VestingWalletConfidentialSalt(initArgs)
172
98
  );
173
99
  }
174
100
 
101
+ /// @dev Virtual function that must be implemented to validate the initArgs bytes.
102
+ function _validateVestingWalletInitArgs(bytes memory initArgs) internal virtual;
103
+
175
104
  /// @dev Virtual function that must be implemented to initialize the vesting wallet at `vestingWalletAddress`.
176
- function _initializeVestingWallet(
177
- address vestingWalletAddress,
178
- address beneficiary,
179
- uint48 startTimestamp,
180
- uint48 durationSeconds,
181
- uint48 cliffSeconds,
182
- address executor
183
- ) internal virtual;
105
+ function _initializeVestingWallet(address vestingWalletAddress, bytes calldata initArgs) internal virtual;
184
106
 
185
107
  /**
186
108
  * @dev Internal function that is called once to deploy the vesting wallet implementation.
@@ -192,13 +114,7 @@ abstract contract VestingWalletConfidentialFactory {
192
114
  /**
193
115
  * @dev Gets create2 salt for a confidential vesting wallet.
194
116
  */
195
- function _getCreate2VestingWalletConfidentialSalt(
196
- address beneficiary,
197
- uint48 startTimestamp,
198
- uint48 durationSeconds,
199
- uint48 cliffSeconds,
200
- address executor
201
- ) internal pure virtual returns (bytes32) {
202
- return keccak256(abi.encodePacked(beneficiary, startTimestamp, durationSeconds, cliffSeconds, executor));
117
+ function _getCreate2VestingWalletConfidentialSalt(bytes memory initArgs) internal pure virtual returns (bytes32) {
118
+ return keccak256(initArgs);
203
119
  }
204
120
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.2) (governance/utils/VotesConfidential.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (governance/utils/VotesConfidential.sol)
3
3
  pragma solidity ^0.8.24;
4
4
 
5
5
  import {FHE, ebool, euint64} from "@fhevm/solidity/lib/FHE.sol";
@@ -9,9 +9,25 @@ import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
9
9
  import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
10
10
  import {Nonces} from "@openzeppelin/contracts/utils/Nonces.sol";
11
11
  import {Time} from "@openzeppelin/contracts/utils/types/Time.sol";
12
+ import {HandleAccessManager} from "./../../utils/HandleAccessManager.sol";
12
13
  import {CheckpointsConfidential} from "./../../utils/structs/CheckpointsConfidential.sol";
13
14
 
14
- abstract contract VotesConfidential is Nonces, EIP712, IERC6372 {
15
+ /**
16
+ * @dev A confidential votes contract tracking confidential voting power of accounts over time.
17
+ * It features vote delegation to delegators.
18
+
19
+ * This contract keeps a history (checkpoints) of each account's confidential vote power. Confidential
20
+ * voting power can be delegated either by calling the {delegate} function directly, or by providing
21
+ * a signature to be used with {delegateBySig}. Confidential voting power handles can be queried
22
+ * through the public accessors {getVotes} and {getPastVotes} but can only be decrypted by accounts
23
+ * allowed to access them. Ensure that {HandleAccessManager-_validateHandleAllowance} is implemented properly, allowing all
24
+ * necessary addresses to access voting power handles.
25
+ *
26
+ * By default, voting units does not account for voting power. This makes transfers of underlying
27
+ * voting units cheaper. The downside is that it requires users to delegate to themselves in order
28
+ * to activate checkpoints and have their voting power tracked.
29
+ */
30
+ abstract contract VotesConfidential is Nonces, EIP712, IERC6372, HandleAccessManager {
15
31
  using FHE for *;
16
32
  using CheckpointsConfidential for CheckpointsConfidential.TraceEuint64;
17
33
 
@@ -168,7 +184,6 @@ abstract contract VotesConfidential is Nonces, EIP712, IERC6372 {
168
184
  store = _delegateCheckpoints[from];
169
185
  euint64 newValue = store.latest().sub(amount);
170
186
  newValue.allowThis();
171
- newValue.allow(from);
172
187
  euint64 oldValue = _push(store, newValue);
173
188
  emit DelegateVotesChanged(from, oldValue, newValue);
174
189
  }
@@ -176,7 +191,6 @@ abstract contract VotesConfidential is Nonces, EIP712, IERC6372 {
176
191
  store = _delegateCheckpoints[to];
177
192
  euint64 newValue = store.latest().add(amount);
178
193
  newValue.allowThis();
179
- newValue.allow(to);
180
194
  euint64 oldValue = _push(store, newValue);
181
195
  emit DelegateVotesChanged(to, oldValue, newValue);
182
196
  }
@@ -1,10 +1,10 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.2) (interfaces/IConfidentialFungibleToken.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (interfaces/IConfidentialFungibleToken.sol)
3
3
  pragma solidity ^0.8.24;
4
4
 
5
5
  import {euint64, externalEuint64} from "@fhevm/solidity/lib/FHE.sol";
6
6
 
7
- /// @dev Draft interface for a confidential fungible token standard utilizing the Zama TFHE library.
7
+ /// @dev Draft interface for a confidential fungible token standard utilizing the Zama FHE library.
8
8
  interface IConfidentialFungibleToken {
9
9
  /**
10
10
  * @dev Emitted when the expiration timestamp for an operator `operator` is updated for a given `holder`.
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.2) (interfaces/IConfidentialFungibleTokenReceiver.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (interfaces/IConfidentialFungibleTokenReceiver.sol)
3
3
  pragma solidity ^0.8.24;
4
4
 
5
5
  import {ebool, euint64} from "@fhevm/solidity/lib/FHE.sol";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openzeppelin/confidential-contracts",
3
3
  "description": "Smart Contract library for use with confidential coprocessors",
4
- "version": "0.2.0-rc.2",
4
+ "version": "0.2.0",
5
5
  "files": [
6
6
  "**/*.sol",
7
7
  "/build/contracts/*.json",
@@ -1,10 +1,10 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.2) (token/ConfidentialFungibleToken.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (token/ConfidentialFungibleToken.sol)
3
3
  pragma solidity ^0.8.27;
4
4
 
5
5
  import {FHE, externalEuint64, ebool, euint64} from "@fhevm/solidity/lib/FHE.sol";
6
6
  import {IConfidentialFungibleToken} from "./../interfaces/IConfidentialFungibleToken.sol";
7
- import {TFHESafeMath} from "./../utils/TFHESafeMath.sol";
7
+ import {FHESafeMath} from "./../utils/FHESafeMath.sol";
8
8
  import {ConfidentialFungibleTokenUtils} from "./utils/ConfidentialFungibleTokenUtils.sol";
9
9
 
10
10
  /**
@@ -220,7 +220,7 @@ abstract contract ConfidentialFungibleToken is IConfidentialFungibleToken {
220
220
  _requestHandles[requestID] = encryptedAmount;
221
221
  }
222
222
 
223
- /// @dev May only be called by the gateway contract. Finalizes a disclose encrypted amount request.
223
+ /// @dev Finalizes a disclose encrypted amount request.
224
224
  function finalizeDiscloseEncryptedAmount(
225
225
  uint256 requestId,
226
226
  uint64 amount,
@@ -266,14 +266,11 @@ abstract contract ConfidentialFungibleToken is IConfidentialFungibleToken {
266
266
  euint64 sent = _transfer(from, to, amount);
267
267
 
268
268
  // Perform callback
269
- transferred = FHE.select(
270
- ConfidentialFungibleTokenUtils.checkOnTransferReceived(msg.sender, from, to, sent, data),
271
- sent,
272
- FHE.asEuint64(0)
273
- );
269
+ ebool success = ConfidentialFungibleTokenUtils.checkOnTransferReceived(msg.sender, from, to, sent, data);
274
270
 
275
- // Refund if success fails. refund should never fail
276
- _update(to, from, FHE.sub(sent, transferred));
271
+ // Try to refund if callback fails
272
+ euint64 refund = _update(to, from, FHE.select(success, FHE.asEuint64(0), sent));
273
+ transferred = FHE.sub(sent, refund);
277
274
  }
278
275
 
279
276
  function _update(address from, address to, euint64 amount) internal virtual returns (euint64 transferred) {
@@ -281,13 +278,13 @@ abstract contract ConfidentialFungibleToken is IConfidentialFungibleToken {
281
278
  euint64 ptr;
282
279
 
283
280
  if (from == address(0)) {
284
- (success, ptr) = TFHESafeMath.tryIncrease(_totalSupply, amount);
281
+ (success, ptr) = FHESafeMath.tryIncrease(_totalSupply, amount);
285
282
  FHE.allowThis(ptr);
286
283
  _totalSupply = ptr;
287
284
  } else {
288
285
  euint64 fromBalance = _balances[from];
289
286
  require(FHE.isInitialized(fromBalance), ConfidentialFungibleTokenZeroBalance(from));
290
- (success, ptr) = TFHESafeMath.tryDecrease(fromBalance, amount);
287
+ (success, ptr) = FHESafeMath.tryDecrease(fromBalance, amount);
291
288
  FHE.allowThis(ptr);
292
289
  FHE.allow(ptr, from);
293
290
  _balances[from] = ptr;
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.2) (token/extensions/ConfidentialFungibleTokenERC20Wrapper.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (token/extensions/ConfidentialFungibleTokenERC20Wrapper.sol)
3
3
 
4
4
  pragma solidity ^0.8.27;
5
5
 
@@ -15,6 +15,9 @@ import {ConfidentialFungibleToken} from "./../ConfidentialFungibleToken.sol";
15
15
  * @dev A wrapper contract built on top of {ConfidentialFungibleToken} that allows wrapping an `ERC20` token
16
16
  * into a confidential fungible token. The wrapper contract implements the `IERC1363Receiver` interface
17
17
  * which allows users to transfer `ERC1363` tokens directly to the wrapper with a callback to wrap the tokens.
18
+ *
19
+ * WARNING: Minting assumes the full amount of the underlying token transfer has been received, hence some non-standard
20
+ * tokens such as fee-on-transfer or other deflationary-type tokens are not supported by this wrapper.
18
21
  */
19
22
  abstract contract ConfidentialFungibleTokenERC20Wrapper is ConfidentialFungibleToken, IERC1363Receiver {
20
23
  IERC20 private immutable _underlying;
@@ -70,14 +73,14 @@ abstract contract ConfidentialFungibleTokenERC20Wrapper is ConfidentialFungibleT
70
73
  // check caller is the token contract
71
74
  require(address(underlying()) == msg.sender, ConfidentialFungibleTokenUnauthorizedCaller(msg.sender));
72
75
 
73
- // transfer excess back to the sender
74
- uint256 excess = amount % rate();
75
- if (excess > 0) SafeERC20.safeTransfer(underlying(), from, excess);
76
-
77
76
  // mint confidential token
78
77
  address to = data.length < 20 ? from : address(bytes20(data));
79
78
  _mint(to, FHE.asEuint64(SafeCast.toUint64(amount / rate())));
80
79
 
80
+ // transfer excess back to the sender
81
+ uint256 excess = amount % rate();
82
+ if (excess > 0) SafeERC20.safeTransfer(underlying(), from, excess);
83
+
81
84
  // return magic value
82
85
  return IERC1363Receiver.onTransferReceived.selector;
83
86
  }
@@ -125,8 +128,7 @@ abstract contract ConfidentialFungibleTokenERC20Wrapper is ConfidentialFungibleT
125
128
  }
126
129
 
127
130
  /**
128
- * @dev Called by the fhEVM gateway with the decrypted amount `amount` for a request id `requestId`.
129
- * Fills unwrap requests.
131
+ * @dev Fills an unwrap request for a given request id related to a decrypted unwrap amount.
130
132
  */
131
133
  function finalizeUnwrap(uint256 requestID, uint64 amount, bytes[] memory signatures) public virtual {
132
134
  FHE.checkSignatures(requestID, signatures);
@@ -156,6 +158,15 @@ abstract contract ConfidentialFungibleTokenERC20Wrapper is ConfidentialFungibleT
156
158
  _receivers[requestID] = to;
157
159
  }
158
160
 
161
+ /**
162
+ * @dev Returns the default number of decimals of the underlying ERC-20 token that is being wrapped.
163
+ * Used as a default fallback when {_tryGetAssetDecimals} fails to fetch decimals of the underlying
164
+ * ERC-20 token.
165
+ */
166
+ function _fallbackUnderlyingDecimals() internal pure virtual returns (uint8) {
167
+ return 18;
168
+ }
169
+
159
170
  /**
160
171
  * @dev Returns the maximum number that will be used for {decimals} by the wrapper.
161
172
  */
@@ -170,6 +181,6 @@ abstract contract ConfidentialFungibleTokenERC20Wrapper is ConfidentialFungibleT
170
181
  if (success && encodedDecimals.length == 32) {
171
182
  return abi.decode(encodedDecimals, (uint8));
172
183
  }
173
- return 18;
184
+ return _fallbackUnderlyingDecimals();
174
185
  }
175
186
  }
@@ -1,12 +1,20 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.2) (token/extensions/ConfidentialFungibleTokenVotes.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (token/extensions/ConfidentialFungibleTokenVotes.sol)
3
3
  pragma solidity ^0.8.27;
4
4
 
5
5
  import {euint64} from "@fhevm/solidity/lib/FHE.sol";
6
6
  import {VotesConfidential} from "./../../governance/utils/VotesConfidential.sol";
7
7
  import {ConfidentialFungibleToken} from "./../ConfidentialFungibleToken.sol";
8
8
 
9
+ /**
10
+ * @dev Extension of {ConfidentialFungibleToken} supporting confidential votes tracking and delegation.
11
+ *
12
+ * The amount of confidential voting units an account has is equal to the confidential token balance of
13
+ * that account. Voing power is taken into account when an account delegates votes to itself or to another
14
+ * account.
15
+ */
9
16
  abstract contract ConfidentialFungibleTokenVotes is ConfidentialFungibleToken, VotesConfidential {
17
+ /// @inheritdoc ConfidentialFungibleToken
10
18
  function confidentialTotalSupply()
11
19
  public
12
20
  view
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.2) (token/utils/ConfidentialFungibleTokenUtils.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (token/utils/ConfidentialFungibleTokenUtils.sol)
3
3
  pragma solidity ^0.8.24;
4
4
 
5
5
  import {FHE, ebool, euint64} from "@fhevm/solidity/lib/FHE.sol";
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.2) (utils/TFHESafeMath.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (utils/FHESafeMath.sol)
3
3
  pragma solidity ^0.8.24;
4
4
 
5
5
  import {FHE, ebool, euint64} from "@fhevm/solidity/lib/FHE.sol";
@@ -8,7 +8,7 @@ import {FHE, ebool, euint64} from "@fhevm/solidity/lib/FHE.sol";
8
8
  * @dev Library providing safe arithmetic operations for encrypted values
9
9
  * to handle potential overflows in FHE operations.
10
10
  */
11
- library TFHESafeMath {
11
+ library FHESafeMath {
12
12
  /**
13
13
  * @dev Try to increase the encrypted value `oldValue` by `delta`. If the operation is successful,
14
14
  * `success` will be true and `updated` will be the new value. Otherwise, `success` will be false
@@ -0,0 +1,29 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (utils/HandleAccessManager.sol)
3
+ pragma solidity ^0.8.24;
4
+
5
+ import {Impl} from "@fhevm/solidity/lib/Impl.sol";
6
+
7
+ abstract contract HandleAccessManager {
8
+ /**
9
+ * @dev Get handle access for the given handle `handle`. Access will be given to the
10
+ * account `account` with the given persistence flag.
11
+ *
12
+ * NOTE: This function call is gated by `msg.sender` and validated by the
13
+ * {_validateHandleAllowance} function.
14
+ */
15
+ function getHandleAllowance(bytes32 handle, address account, bool persistent) public virtual {
16
+ _validateHandleAllowance(handle);
17
+ if (persistent) {
18
+ Impl.allow(handle, account);
19
+ } else {
20
+ Impl.allowTransient(handle, account);
21
+ }
22
+ }
23
+
24
+ /**
25
+ * @dev Unimplemented function that must revert if the message sender is not allowed to call
26
+ * {getHandleAllowance} for the given handle.
27
+ */
28
+ function _validateHandleAllowance(bytes32 handle) internal view virtual;
29
+ }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.2) (utils/structs/CheckpointsConfidential.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (utils/structs/CheckpointsConfidential.sol)
3
3
  // This file was procedurally generated from scripts/generate/templates/CheckpointsConfidential.js.
4
4
 
5
5
  pragma solidity ^0.8.24;
@@ -18,11 +18,6 @@ import {Checkpoints} from "./temporary-Checkpoints.sol";
18
18
  library CheckpointsConfidential {
19
19
  using Checkpoints for Checkpoints.Trace256;
20
20
 
21
- /**
22
- * @dev A value was attempted to be inserted on a past checkpoint.
23
- */
24
- error CheckpointUnorderedInsertion();
25
-
26
21
  struct TraceEuint32 {
27
22
  Checkpoints.Trace256 _inner;
28
23
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.2) (utils/structs/temporary-Checkpoints.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0) (utils/structs/temporary-Checkpoints.sol)
3
3
  // OpenZeppelin Contracts (last updated v5.3.0) (utils/structs/Checkpoints.sol)
4
4
  // This file was procedurally generated from scripts/generate/templates/Checkpoints.js.
5
5
  // WARNING: This file is temporary and will be deleted once the latest version of the file is released in v5.5.0 of @openzeppelin/contracts.