@openzeppelin/confidential-contracts 0.5.0-rc.0 → 0.5.1

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 (30) hide show
  1. package/build/contracts/BatcherConfidential.json +11 -0
  2. package/build/contracts/CheckpointsConfidential.json +2 -2
  3. package/build/contracts/ERC7984BalanceCapHookModule.json +2 -37
  4. package/build/contracts/ERC7984HolderCapHookModule.json +2 -37
  5. package/build/contracts/ERC7984HookModule.json +0 -35
  6. package/build/contracts/ERC7984Hooked.json +0 -5
  7. package/build/contracts/ERC7984Utils.json +2 -2
  8. package/build/contracts/FHESafeMath.json +2 -2
  9. package/build/contracts/IERC7984HookModule.json +0 -13
  10. package/finance/BatcherConfidential.sol +17 -3
  11. package/governance/utils/VotesConfidential.sol +1 -1
  12. package/interfaces/IERC7984HookModule.sol +1 -8
  13. package/interfaces/IERC7984Receiver.sol +1 -1
  14. package/interfaces/IERC7984Rwa.sol +1 -1
  15. package/package.json +1 -1
  16. package/token/ERC7984/ERC7984.sol +5 -2
  17. package/token/ERC7984/extensions/ERC7984ERC20Wrapper.sol +1 -1
  18. package/token/ERC7984/extensions/ERC7984Freezable.sol +2 -2
  19. package/token/ERC7984/extensions/ERC7984Hooked.sol +7 -8
  20. package/token/ERC7984/extensions/ERC7984Restricted.sol +1 -1
  21. package/token/ERC7984/extensions/ERC7984Rwa.sol +20 -2
  22. package/token/ERC7984/utils/ERC7984BalanceCapHookModule.sol +12 -17
  23. package/token/ERC7984/utils/ERC7984HolderCapHookModule.sol +27 -31
  24. package/token/ERC7984/utils/ERC7984HookModule.sol +3 -42
  25. package/utils/FHESafeMath.sol +1 -1
  26. package/utils/HandleAccessManager.sol +1 -1
  27. package/utils/structs/CheckpointsConfidential.sol +1 -1
  28. package/build/contracts/ERC7984IdentityCheck.json +0 -691
  29. package/build/contracts/IIdentityRegistry.json +0 -30
  30. package/token/ERC7984/extensions/ERC7984IdentityCheck.sol +0 -58
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.5.0-rc.0) (token/ERC7984/extensions/ERC7984Restricted.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.5.0) (token/ERC7984/extensions/ERC7984Restricted.sol)
3
3
 
4
4
  pragma solidity ^0.8.27;
5
5
 
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.5.0-rc.0) (token/ERC7984/extensions/ERC7984Rwa.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.5.0) (token/ERC7984/extensions/ERC7984Rwa.sol)
3
3
 
4
4
  pragma solidity ^0.8.27;
5
5
 
@@ -257,7 +257,7 @@ abstract contract ERC7984Rwa is IERC7984Rwa, ERC7984Freezable, ERC7984Restricted
257
257
  return super._update(from, to, encryptedAmount);
258
258
  }
259
259
 
260
- /// @dev Bypasses {ERC7984Restricted} `from` restriction check when performing a {forceConfidentialTransferFrom}.
260
+ /// @dev Bypasses {ERC7984Restricted} `from` restriction check when performing a forced transfer or token recovery.
261
261
  function _checkSenderRestriction(address account) internal view override {
262
262
  if (_isForceTransfer(msg.sig)) {
263
263
  return;
@@ -265,6 +265,14 @@ abstract contract ERC7984Rwa is IERC7984Rwa, ERC7984Freezable, ERC7984Restricted
265
265
  super._checkSenderRestriction(account);
266
266
  }
267
267
 
268
+ /// @dev Bypasses {ERC7984Restricted} `to` restriction check when performing a forced transfer or token recovery.
269
+ function _checkRecipientRestriction(address account) internal view override {
270
+ if (_isForceTransfer(msg.sig)) {
271
+ return;
272
+ }
273
+ super._checkRecipientRestriction(account);
274
+ }
275
+
268
276
  /// @dev Bypasses {Pausable} check when performing a {forceConfidentialTransferFrom}.
269
277
  function _requireNotPaused() internal view override {
270
278
  if (_isForceTransfer(msg.sig)) {
@@ -280,4 +288,14 @@ abstract contract ERC7984Rwa is IERC7984Rwa, ERC7984Freezable, ERC7984Restricted
280
288
  selector == 0x44fd6e40 || // bytes4(keccak256("forceConfidentialTransferFrom(address,address,bytes32)"))
281
289
  selector == this.recoverAddress.selector;
282
290
  }
291
+
292
+ /// @dev Restrict overrides of {Context._msgSender}. Please use other account abstraction methods instead.
293
+ function _msgSender() internal view override returns (address) {
294
+ return super._msgSender();
295
+ }
296
+
297
+ /// @dev Restrict overrides of {Context._msgData}. Please use other account abstraction methods instead.
298
+ function _msgData() internal view override returns (bytes calldata) {
299
+ return super._msgData();
300
+ }
283
301
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.5.0-rc.0) (token/ERC7984/utils/ERC7984BalanceCapHookModule.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.5.0) (token/ERC7984/utils/ERC7984BalanceCapHookModule.sol)
3
3
 
4
4
  pragma solidity ^0.8.27;
5
5
 
@@ -56,22 +56,23 @@ contract ERC7984BalanceCapHookModule is ERC7984HookModule {
56
56
  address from,
57
57
  address to,
58
58
  euint64 encryptedAmount
59
- ) internal override returns (ebool) {
60
- ebool compliant;
61
- if (to == address(0) || from == to || !FHE.isInitialized(maxBalance(token))) {
62
- compliant = FHE.asEbool(true);
63
- } else {
59
+ ) internal override returns (ebool result) {
60
+ // super call
61
+ result = super._preTransfer(token, from, to, encryptedAmount);
62
+
63
+ // in non trivial cases, check (and document) compliance.
64
+ if (to != address(0) && to != from && FHE.isInitialized(maxBalance(token))) {
64
65
  euint64 balance = IERC7984Rwa(token).confidentialBalanceOf(to);
65
66
  _accessHandle(token, balance);
66
67
 
67
68
  // Note, if the balance would result in an overflow, transfer will fail due to total supply overflow.
68
69
  (, euint64 futureBalance) = FHESafeMath.tryIncrease(balance, encryptedAmount);
69
- compliant = FHE.le(futureBalance, maxBalance(token));
70
- }
70
+ ebool compliant = FHE.le(futureBalance, maxBalance(token));
71
+ _emitPreTransferResults(token, from, to, encryptedAmount, compliant, bytes32(0));
71
72
 
72
- _emitPreTransferResults(token, from, to, encryptedAmount, compliant, bytes32(0));
73
-
74
- return FHE.and(compliant, super._preTransfer(token, from, to, encryptedAmount));
73
+ // integrate this module compliance result into the super result.
74
+ result = FHE.and(result, compliant);
75
+ }
75
76
  }
76
77
 
77
78
  /**
@@ -83,10 +84,4 @@ contract ERC7984BalanceCapHookModule is ERC7984HookModule {
83
84
  (externalEuint64 maxBalance_, bytes memory inputProof) = abi.decode(initData, (externalEuint64, bytes));
84
85
  _setMaxBalance(token, FHE.fromExternal(maxBalance_, inputProof));
85
86
  }
86
-
87
- /// @inheritdoc ERC7984HookModule
88
- function _onUninstall(address token, bytes calldata deinitData) internal virtual override {
89
- super._onUninstall(token, deinitData);
90
- _maxBalances[token] = euint64.wrap(0);
91
- }
92
87
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.5.0-rc.0) (token/ERC7984/utils/ERC7984HolderCapHookModule.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.5.0) (token/ERC7984/utils/ERC7984HolderCapHookModule.sol)
3
3
 
4
4
  pragma solidity ^0.8.27;
5
5
 
@@ -64,31 +64,32 @@ contract ERC7984HolderCapHookModule is ERC7984HookModule {
64
64
  address from,
65
65
  address to,
66
66
  euint64 encryptedAmount
67
- ) internal override returns (ebool) {
68
- if (to == address(0) || to == from) {
69
- return FHE.asEbool(true);
67
+ ) internal override returns (ebool result) {
68
+ result = super._preTransfer(token, from, to, encryptedAmount);
69
+
70
+ // in non trivial cases, check compliance.
71
+ if (to != address(0) && to != from) {
72
+ euint64 fromBalance = IERC7984Rwa(token).confidentialBalanceOf(from);
73
+ euint64 toBalance = IERC7984Rwa(token).confidentialBalanceOf(to);
74
+
75
+ _accessHandle(token, fromBalance);
76
+ _accessHandle(token, toBalance);
77
+
78
+ euint64 encryptedZero = FHE.asEuint64(0);
79
+
80
+ // note, if from is address(0):
81
+ // - fromBalance is an encrypted zero
82
+ // - from will be (erroneously) removed from the holder count only encryptedAmount is a zero
83
+ // that is fine because if encryptedAmount is a zero, then this value is dropped anyway.
84
+ euint64 adjustedHolderCount = FHE.add(
85
+ FHE.sub(holderCount(token), FHE.asEuint64(FHE.eq(fromBalance, encryptedAmount))),
86
+ FHE.asEuint64(FHE.and(FHE.eq(toBalance, encryptedZero), FHE.ne(encryptedAmount, encryptedZero)))
87
+ );
88
+ ebool compliant = FHE.le(adjustedHolderCount, maxHolderCount(token));
89
+
90
+ // integrate this module compliance result into the super result.
91
+ result = FHE.and(result, compliant);
70
92
  }
71
-
72
- euint64 fromBalance = IERC7984Rwa(token).confidentialBalanceOf(from);
73
- euint64 toBalance = IERC7984Rwa(token).confidentialBalanceOf(to);
74
-
75
- _accessHandle(token, fromBalance);
76
- _accessHandle(token, toBalance);
77
-
78
- euint64 encryptedZero = FHE.asEuint64(0);
79
-
80
- // note, if from is address(0):
81
- // - fromBalance is an encrypted zero
82
- // - from will be (erroneously) removed from the holder count only encryptedAmount is a zero
83
- // that is fine because if encryptedAmount is a zero, then this value is dropped anyway.
84
- euint64 adjustedHolderCount = FHE.add(
85
- FHE.sub(holderCount(token), FHE.asEuint64(FHE.eq(fromBalance, encryptedAmount))),
86
- FHE.asEuint64(FHE.and(FHE.eq(toBalance, encryptedZero), FHE.ne(encryptedAmount, encryptedZero)))
87
- );
88
-
89
- ebool compliant = FHE.le(adjustedHolderCount, maxHolderCount(token));
90
-
91
- return FHE.and(compliant, super._preTransfer(token, from, to, encryptedAmount));
92
93
  }
93
94
 
94
95
  /// @inheritdoc ERC7984HookModule
@@ -130,16 +131,11 @@ contract ERC7984HolderCapHookModule is ERC7984HookModule {
130
131
  !FHE.isInitialized(IERC7984Rwa(token).confidentialTotalSupply()),
131
132
  ERC7984HolderCapHookModuleTotalSupplyInitialized()
132
133
  );
134
+ _holderCounts[token] = euint64.wrap(0);
133
135
 
134
136
  super._onInstall(token, initData);
135
137
 
136
138
  uint64 maxHolderCount_ = abi.decode(initData, (uint64));
137
139
  _setMaxHolderCount(token, maxHolderCount_);
138
140
  }
139
-
140
- function _onUninstall(address token, bytes calldata deinitData) internal virtual override {
141
- super._onUninstall(token, deinitData);
142
- delete _maxHolderCounts[token];
143
- _holderCounts[token] = euint64.wrap(0);
144
- }
145
141
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.5.0-rc.0) (token/ERC7984/utils/ERC7984HookModule.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.5.0) (token/ERC7984/utils/ERC7984HookModule.sol)
3
3
 
4
4
  pragma solidity ^0.8.27;
5
5
 
@@ -18,14 +18,6 @@ abstract contract ERC7984HookModule is IERC7984HookModule, ERC165 {
18
18
  /// @dev The caller `user` does not have access to the encrypted amount `amount`.
19
19
  error ERC7984HookModuleUnauthorizedUseOfEncryptedAmount(euint64 amount, address user);
20
20
 
21
- /// @dev The module is already installed for the given token.
22
- error ERC7984HookModuleAlreadyInstalled(address token);
23
-
24
- /// @dev The module is not installed for the given token.
25
- error ERC7984HookModuleNotInstalled(address token);
26
-
27
- mapping(address token => bool) private _installed;
28
-
29
21
  /// @inheritdoc IERC7984HookModule
30
22
  function preTransfer(address from, address to, euint64 encryptedAmount) public virtual returns (ebool) {
31
23
  require(
@@ -48,18 +40,9 @@ abstract contract ERC7984HookModule is IERC7984HookModule, ERC165 {
48
40
 
49
41
  /// @inheritdoc IERC7984HookModule
50
42
  function onInstall(bytes calldata initData) public virtual {
51
- require(!_isModuleInstalled(msg.sender), ERC7984HookModuleAlreadyInstalled(msg.sender));
52
-
53
43
  _onInstall(msg.sender, initData);
54
44
  }
55
45
 
56
- /// @inheritdoc IERC7984HookModule
57
- function onUninstall(bytes calldata deinitData) public virtual {
58
- require(_isModuleInstalled(msg.sender), ERC7984HookModuleNotInstalled(msg.sender));
59
-
60
- _onUninstall(msg.sender, deinitData);
61
- }
62
-
63
46
  /// @inheritdoc ERC165
64
47
  function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
65
48
  return interfaceId == type(IERC7984HookModule).interfaceId || super.supportsInterface(interfaceId);
@@ -67,19 +50,9 @@ abstract contract ERC7984HookModule is IERC7984HookModule, ERC165 {
67
50
 
68
51
  /**
69
52
  * @dev Internal function which may be overridden by the derived contract to perform actions
70
- * when the module is installed.
53
+ * when the module is installed. Should clean up dirty state from possible previous installations.
71
54
  */
72
- function _onInstall(address token, bytes calldata /* initData */) internal virtual {
73
- _installed[token] = true;
74
- }
75
-
76
- /**
77
- * @dev Internal function which may be overridden by the derived contract to perform actions
78
- * when the module is uninstalled.
79
- */
80
- function _onUninstall(address token, bytes calldata /* deinitData */) internal virtual {
81
- delete _installed[token];
82
- }
55
+ function _onInstall(address /* token */, bytes calldata /* initData */) internal virtual {}
83
56
 
84
57
  /**
85
58
  * @dev Internal function which runs before a transfer. Transient access is already granted to the module
@@ -111,18 +84,6 @@ abstract contract ERC7984HookModule is IERC7984HookModule, ERC165 {
111
84
  // default to no-op
112
85
  }
113
86
 
114
- /**
115
- * @dev Check if the module is installed for the given token. The default implementation reads from
116
- * an internal storage flag maintained by {onInstall} and {onUninstall}. Derived contracts may override
117
- * to extend the check, but should typically rely on the default behavior.
118
- *
119
- * NOTE: This function should use internal storage to check if the module is installed for the given token.
120
- * Do not use external storage like {ERC7984Hooked-isModuleInstalled}.
121
- */
122
- function _isModuleInstalled(address token) internal view virtual returns (bool) {
123
- return _installed[token];
124
- }
125
-
126
87
  /// @dev Allow modules to get access to token handles during transaction.
127
88
  function _getTokenHandleAllowance(address token, euint64 handle) internal virtual {
128
89
  _getTokenHandleAllowance(token, handle, false);
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.5.0-rc.0) (utils/FHESafeMath.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.5.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";
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.5.0-rc.0) (utils/HandleAccessManager.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.5.0) (utils/HandleAccessManager.sol)
3
3
  pragma solidity ^0.8.26;
4
4
 
5
5
  import {Impl} from "@fhevm/solidity/lib/Impl.sol";
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Confidential Contracts (last updated v0.5.0-rc.0) (utils/structs/CheckpointsConfidential.sol)
2
+ // OpenZeppelin Confidential Contracts (last updated v0.5.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;