Skip to content

Commit 3b240d7

Browse files
authored
Use the asset getter in totalAssets, _deposit and _withdraw in ERC4626 (#5322)
1 parent e8f24d6 commit 3b240d7

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

.changeset/thin-eels-cross.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openzeppelin-solidity': patch
3+
---
4+
5+
`ERC4626`: Use the `asset` getter in `totalAssets`, `_deposit` and `_withdraw`.

contracts/token/ERC20/extensions/ERC4626.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ abstract contract ERC4626 is ERC20, IERC4626 {
114114

115115
/** @dev See {IERC4626-totalAssets}. */
116116
function totalAssets() public view virtual returns (uint256) {
117-
return _asset.balanceOf(address(this));
117+
return IERC20(asset()).balanceOf(address(this));
118118
}
119119

120120
/** @dev See {IERC4626-convertToShares}. */
@@ -237,14 +237,14 @@ abstract contract ERC4626 is ERC20, IERC4626 {
237237
* @dev Deposit/mint common workflow.
238238
*/
239239
function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual {
240-
// If _asset is ERC-777, `transferFrom` can trigger a reentrancy BEFORE the transfer happens through the
240+
// If asset() is ERC-777, `transferFrom` can trigger a reentrancy BEFORE the transfer happens through the
241241
// `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer,
242242
// calls the vault, which is assumed not malicious.
243243
//
244244
// Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the
245245
// assets are transferred and before the shares are minted, which is a valid state.
246246
// slither-disable-next-line reentrancy-no-eth
247-
SafeERC20.safeTransferFrom(_asset, caller, address(this), assets);
247+
SafeERC20.safeTransferFrom(IERC20(asset()), caller, address(this), assets);
248248
_mint(receiver, shares);
249249

250250
emit Deposit(caller, receiver, assets, shares);
@@ -264,14 +264,14 @@ abstract contract ERC4626 is ERC20, IERC4626 {
264264
_spendAllowance(owner, caller, shares);
265265
}
266266

267-
// If _asset is ERC-777, `transfer` can trigger a reentrancy AFTER the transfer happens through the
267+
// If asset() is ERC-777, `transfer` can trigger a reentrancy AFTER the transfer happens through the
268268
// `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer,
269269
// calls the vault, which is assumed not malicious.
270270
//
271271
// Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the
272272
// shares are burned and after the assets are transferred, which is a valid state.
273273
_burn(owner, shares);
274-
SafeERC20.safeTransfer(_asset, receiver, assets);
274+
SafeERC20.safeTransfer(IERC20(asset()), receiver, assets);
275275

276276
emit Withdraw(caller, receiver, owner, assets, shares);
277277
}

0 commit comments

Comments
 (0)