Skip to content

Commit 7786daa

Browse files
committed
chore(protocol-contracts): take reviews into account
1 parent d39f59a commit 7786daa

File tree

5 files changed

+42
-42
lines changed

5 files changed

+42
-42
lines changed

protocol-contracts/confidential-wrapper-upgradeable/.env.example

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ REPORT_GAS=false
1919
NUM_CONFIDENTIAL_WRAPPERS=1
2020

2121
# Confidential Wrapper 1
22-
CONFIDENTIAL_WRAPPER_NAME_0="Wrapper 1" # (string)
23-
CONFIDENTIAL_WRAPPER_SYMBOL_0="cTKN1" # (string)
24-
CONFIDENTIAL_WRAPPER_CONTRACT_URI_0="https://confidential-wrapper-1.com" # (string)
22+
CONFIDENTIAL_WRAPPER_NAME_0="Confidential Token Test 1" # (string)
23+
CONFIDENTIAL_WRAPPER_SYMBOL_0="cTEST1" # (string)
24+
CONFIDENTIAL_WRAPPER_CONTRACT_URI_0='data:application/json;utf8,{"name":"Confidential Token Test 1","symbol":"cTEST1","description":"Confidential wrapper of TEST1 shielding it into a confidential token"}' # (string)
2525
CONFIDENTIAL_WRAPPER_UNDERLYING_ADDRESS_0=0x0000111122223333444455556666777788889999 # (address)
2626
CONFIDENTIAL_WRAPPER_OWNER_ADDRESS_0=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 # accounts[1] (address)
2727

28-
# Confidential Wrapper 1
29-
CONFIDENTIAL_WRAPPER_NAME_0="Wrapper 2" # (string)
30-
CONFIDENTIAL_WRAPPER_SYMBOL_0="cTKN2" # (string)
31-
CONFIDENTIAL_WRAPPER_CONTRACT_URI_0="https://confidential-wrapper-2.com" # (string)
28+
# Confidential Wrapper 2
29+
CONFIDENTIAL_WRAPPER_NAME_0="Confidential Token Test 2" # (string)
30+
CONFIDENTIAL_WRAPPER_SYMBOL_0="cTEST2" # (string)
31+
CONFIDENTIAL_WRAPPER_CONTRACT_URI_0='data:application/json;utf8,{"name":"Confidential Token Test 2","symbol":"cTEST2","description":"Confidential wrapper of TEST2 shielding it into a confidential token"}' # (string)
3232
CONFIDENTIAL_WRAPPER_UNDERLYING_ADDRESS_0=0x0000111122223333444455556666777788889999 # (address)
3333
CONFIDENTIAL_WRAPPER_OWNER_ADDRESS_0=0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC # accounts[2] (address)

protocol-contracts/confidential-wrapper-upgradeable/contracts/extensions/ERC7984ERC20WrapperUpgradeable.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
pragma solidity ^0.8.27;
55

66
import {FHE, externalEuint64, euint64} from "@fhevm/solidity/lib/FHE.sol";
7+
import {IERC1363Receiver} from "@openzeppelin/contracts/interfaces/IERC1363Receiver.sol";
78
import {ContextUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol";
89
import {IERC1363Receiver} from "@openzeppelin/contracts/interfaces/IERC1363Receiver.sol";
910
import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
@@ -18,12 +19,13 @@ import {IERC7984ERC20Wrapper} from "../interfaces/IERC7984ERC20Wrapper.sol";
1819
/**
1920
* @title ERC7984ERC20WrapperUpgradeable
2021
* @dev An upgradeable wrapper contract built on top of {ERC7984Upgradeable} that allows wrapping an `ERC20` token
21-
* into an `ERC7984` token.
22+
* into an `ERC7984` token. The wrapper contract implements the `IERC1363Receiver` interface
23+
* which allows users to transfer `ERC1363` tokens directly to the wrapper with a callback to wrap the tokens.
2224
*
2325
* WARNING: Minting assumes the full amount of the underlying token transfer has been received, hence some non-standard
2426
* tokens such as fee-on-transfer or other deflationary-type tokens are not supported by this wrapper.
2527
*/
26-
abstract contract ERC7984ERC20WrapperUpgradeable is ERC7984Upgradeable, IERC7984ERC20Wrapper {
28+
abstract contract ERC7984ERC20WrapperUpgradeable is ERC7984Upgradeable, IERC7984ERC20Wrapper, IERC1363Receiver {
2729
/// @custom:storage-location erc7201:fhevm_protocol.storage.ERC7984ERC20WrapperUpgradeable
2830
struct ERC7984ERC20WrapperStorage {
2931
IERC20 _underlying;

protocol-contracts/confidential-wrapper-upgradeable/contracts/token/ERC7984Upgradeable.sol

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import {FHE, externalEuint64, ebool, euint64} from "@fhevm/solidity/lib/FHE.sol"
77
import {FHESafeMath} from "@openzeppelin/confidential-contracts/utils/FHESafeMath.sol";
88
import {ERC7984Utils} from "@openzeppelin/confidential-contracts/token/ERC7984/utils/ERC7984Utils.sol";
99
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
10-
import {ContextUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol";
1110
import {IERC7984} from "@openzeppelin/confidential-contracts/interfaces/IERC7984.sol";
1211
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
13-
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
12+
import {ERC165Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol";
1413

1514
/**
1615
* @dev Reference implementation for {IERC7984}.
@@ -30,11 +29,11 @@ import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
3029
* - Transfer and call pattern
3130
* - Safe overflow/underflow handling for FHE operations
3231
*/
33-
abstract contract ERC7984Upgradeable is Initializable, ContextUpgradeable, IERC7984, ERC165 {
32+
abstract contract ERC7984Upgradeable is Initializable, IERC7984, ERC165Upgradeable {
3433
/// @custom:storage-location erc7201:fhevm_protocol.storage.ERC7984Upgradeable
3534
struct ERC7984Storage {
3635
mapping(address holder => euint64 balance) _balances;
37-
mapping(address holder => mapping(address operator => uint48 validUntilTimestamp)) _operators;
36+
mapping(address holder => mapping(address spender => uint48 validUntilTimestamp)) _operators;
3837
euint64 _totalSupply;
3938
string _name;
4039
string _symbol;
@@ -146,7 +145,7 @@ abstract contract ERC7984Upgradeable is Initializable, ContextUpgradeable, IERC7
146145

147146
/// @inheritdoc IERC7984
148147
function setOperator(address operator, uint48 until) public virtual {
149-
_setOperator(_msgSender(), operator, until);
148+
_setOperator(msg.sender, operator, until);
150149
}
151150

152151
/// @inheritdoc IERC7984
@@ -155,13 +154,13 @@ abstract contract ERC7984Upgradeable is Initializable, ContextUpgradeable, IERC7
155154
externalEuint64 encryptedAmount,
156155
bytes calldata inputProof
157156
) public virtual returns (euint64) {
158-
return _transfer(_msgSender(), to, FHE.fromExternal(encryptedAmount, inputProof));
157+
return _transfer(msg.sender, to, FHE.fromExternal(encryptedAmount, inputProof));
159158
}
160159

161160
/// @inheritdoc IERC7984
162161
function confidentialTransfer(address to, euint64 amount) public virtual returns (euint64) {
163-
require(FHE.isAllowed(amount, _msgSender()), ERC7984UnauthorizedUseOfEncryptedAmount(amount, _msgSender()));
164-
return _transfer(_msgSender(), to, amount);
162+
require(FHE.isAllowed(amount, msg.sender), ERC7984UnauthorizedUseOfEncryptedAmount(amount, msg.sender));
163+
return _transfer(msg.sender, to, amount);
165164
}
166165

167166
/// @inheritdoc IERC7984
@@ -171,9 +170,9 @@ abstract contract ERC7984Upgradeable is Initializable, ContextUpgradeable, IERC7
171170
externalEuint64 encryptedAmount,
172171
bytes calldata inputProof
173172
) public virtual returns (euint64 transferred) {
174-
require(isOperator(from, _msgSender()), ERC7984UnauthorizedSpender(from, _msgSender()));
173+
require(isOperator(from, msg.sender), ERC7984UnauthorizedSpender(from, msg.sender));
175174
transferred = _transfer(from, to, FHE.fromExternal(encryptedAmount, inputProof));
176-
FHE.allowTransient(transferred, _msgSender());
175+
FHE.allowTransient(transferred, msg.sender);
177176
}
178177

179178
/// @inheritdoc IERC7984
@@ -182,10 +181,10 @@ abstract contract ERC7984Upgradeable is Initializable, ContextUpgradeable, IERC7
182181
address to,
183182
euint64 amount
184183
) public virtual returns (euint64 transferred) {
185-
require(FHE.isAllowed(amount, _msgSender()), ERC7984UnauthorizedUseOfEncryptedAmount(amount, _msgSender()));
186-
require(isOperator(from, _msgSender()), ERC7984UnauthorizedSpender(from, _msgSender()));
184+
require(FHE.isAllowed(amount, msg.sender), ERC7984UnauthorizedUseOfEncryptedAmount(amount, msg.sender));
185+
require(isOperator(from, msg.sender), ERC7984UnauthorizedSpender(from, msg.sender));
187186
transferred = _transfer(from, to, amount);
188-
FHE.allowTransient(transferred, _msgSender());
187+
FHE.allowTransient(transferred, msg.sender);
189188
}
190189

191190
/// @inheritdoc IERC7984
@@ -195,8 +194,8 @@ abstract contract ERC7984Upgradeable is Initializable, ContextUpgradeable, IERC7
195194
bytes calldata inputProof,
196195
bytes calldata data
197196
) public virtual returns (euint64 transferred) {
198-
transferred = _transferAndCall(_msgSender(), to, FHE.fromExternal(encryptedAmount, inputProof), data);
199-
FHE.allowTransient(transferred, _msgSender());
197+
transferred = _transferAndCall(msg.sender, to, FHE.fromExternal(encryptedAmount, inputProof), data);
198+
FHE.allowTransient(transferred, msg.sender);
200199
}
201200

202201
/// @inheritdoc IERC7984
@@ -205,9 +204,9 @@ abstract contract ERC7984Upgradeable is Initializable, ContextUpgradeable, IERC7
205204
euint64 amount,
206205
bytes calldata data
207206
) public virtual returns (euint64 transferred) {
208-
require(FHE.isAllowed(amount, _msgSender()), ERC7984UnauthorizedUseOfEncryptedAmount(amount, _msgSender()));
209-
transferred = _transferAndCall(_msgSender(), to, amount, data);
210-
FHE.allowTransient(transferred, _msgSender());
207+
require(FHE.isAllowed(amount, msg.sender), ERC7984UnauthorizedUseOfEncryptedAmount(amount, msg.sender));
208+
transferred = _transferAndCall(msg.sender, to, amount, data);
209+
FHE.allowTransient(transferred, msg.sender);
211210
}
212211

213212
/// @inheritdoc IERC7984
@@ -218,9 +217,9 @@ abstract contract ERC7984Upgradeable is Initializable, ContextUpgradeable, IERC7
218217
bytes calldata inputProof,
219218
bytes calldata data
220219
) public virtual returns (euint64 transferred) {
221-
require(isOperator(from, _msgSender()), ERC7984UnauthorizedSpender(from, _msgSender()));
220+
require(isOperator(from, msg.sender), ERC7984UnauthorizedSpender(from, msg.sender));
222221
transferred = _transferAndCall(from, to, FHE.fromExternal(encryptedAmount, inputProof), data);
223-
FHE.allowTransient(transferred, _msgSender());
222+
FHE.allowTransient(transferred, msg.sender);
224223
}
225224

226225
/// @inheritdoc IERC7984
@@ -230,10 +229,10 @@ abstract contract ERC7984Upgradeable is Initializable, ContextUpgradeable, IERC7
230229
euint64 amount,
231230
bytes calldata data
232231
) public virtual returns (euint64 transferred) {
233-
require(FHE.isAllowed(amount, _msgSender()), ERC7984UnauthorizedUseOfEncryptedAmount(amount, _msgSender()));
234-
require(isOperator(from, _msgSender()), ERC7984UnauthorizedSpender(from, _msgSender()));
232+
require(FHE.isAllowed(amount, msg.sender), ERC7984UnauthorizedUseOfEncryptedAmount(amount, msg.sender));
233+
require(isOperator(from, msg.sender), ERC7984UnauthorizedSpender(from, msg.sender));
235234
transferred = _transferAndCall(from, to, amount, data);
236-
FHE.allowTransient(transferred, _msgSender());
235+
FHE.allowTransient(transferred, msg.sender);
237236
}
238237

239238
/**
@@ -245,12 +244,12 @@ abstract contract ERC7984Upgradeable is Initializable, ContextUpgradeable, IERC7
245244
*/
246245
function requestDiscloseEncryptedAmount(euint64 encryptedAmount) public virtual {
247246
require(
248-
FHE.isAllowed(encryptedAmount, _msgSender()),
249-
ERC7984UnauthorizedUseOfEncryptedAmount(encryptedAmount, _msgSender())
247+
FHE.isAllowed(encryptedAmount, msg.sender),
248+
ERC7984UnauthorizedUseOfEncryptedAmount(encryptedAmount, msg.sender)
250249
);
251250

252251
FHE.makePubliclyDecryptable(encryptedAmount);
253-
emit AmountDiscloseRequested(encryptedAmount, _msgSender());
252+
emit AmountDiscloseRequested(encryptedAmount, msg.sender);
254253
}
255254

256255
/**
@@ -304,7 +303,7 @@ abstract contract ERC7984Upgradeable is Initializable, ContextUpgradeable, IERC7
304303
euint64 sent = _transfer(from, to, amount);
305304

306305
// Perform callback
307-
ebool success = ERC7984Utils.checkOnTransferReceived(_msgSender(), from, to, sent, data);
306+
ebool success = ERC7984Utils.checkOnTransferReceived(msg.sender, from, to, sent, data);
308307

309308
// Try to refund if callback fails
310309
euint64 refund = _update(to, from, FHE.select(success, FHE.asEuint64(0), sent));
@@ -349,8 +348,10 @@ abstract contract ERC7984Upgradeable is Initializable, ContextUpgradeable, IERC7
349348
emit ConfidentialTransfer(from, to, transferred);
350349
}
351350

352-
/// @inheritdoc ERC165
353-
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
351+
/// @inheritdoc ERC165Upgradeable
352+
function supportsInterface(
353+
bytes4 interfaceId
354+
) public view virtual override(IERC165, ERC165Upgradeable) returns (bool) {
354355
return interfaceId == type(IERC7984).interfaceId || super.supportsInterface(interfaceId);
355356
}
356357
}

protocol-contracts/confidential-wrapper-upgradeable/hardhat.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const config: HardhatUserConfig = {
6363
settings: {
6464
optimizer: {
6565
enabled: true,
66-
runs: 200,
66+
runs: 800,
6767
},
6868
evmVersion: 'cancun',
6969
},

protocol-contracts/confidential-wrapper/contracts/token/ERC7984Upgradeable.sol

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ abstract contract ERC7984Upgradeable is Initializable, ContextUpgradeable, IERC7
6161
*/
6262
error ERC7984UnauthorizedUseOfEncryptedAmount(euint64 amount, address user);
6363

64-
/// @dev The given caller `caller` is not authorized for the current operation.
65-
error ERC7984UnauthorizedCaller(address caller);
66-
6764
/// @dev The given gateway request ID `requestId` is invalid.
6865
error ERC7984InvalidGatewayRequest(uint256 requestId);
6966

0 commit comments

Comments
 (0)