Browse Source

Use a staticcall to fetch ERC20.decimals in ERC4626 (#3943)

Co-authored-by: Francisco <frangio.1@gmail.com>
(cherry picked from commit 6b17b334300f8268acdfc88b77b87395f6aa5174)
Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Hadrien Croubois 2 years ago
parent
commit
cd50a86a90
2 changed files with 6 additions and 2 deletions
  1. 4 0
      CHANGELOG.md
  2. 2 2
      contracts/token/ERC20/extensions/ERC4626.sol

+ 4 - 0
CHANGELOG.md

@@ -1,5 +1,9 @@
 # Changelog
 
+## 4.8.1
+
+ * `ERC4626`: Use staticcall instead of call when fetching underlying ERC-20 decimals. ([#3943](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3943))
+
 ## 4.8.0 (2022-11-08)
 
  * `TimelockController`: Added a new `admin` constructor parameter that is assigned the admin role instead of the deployer account. ([#3722](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3722))

+ 2 - 2
contracts/token/ERC20/extensions/ERC4626.sol

@@ -45,8 +45,8 @@ abstract contract ERC4626 is ERC20, IERC4626 {
     /**
      * @dev Attempts to fetch the asset decimals. A return value of false indicates that the attempt failed in some way.
      */
-    function _tryGetAssetDecimals(IERC20 asset_) private returns (bool, uint8) {
-        (bool success, bytes memory encodedDecimals) = address(asset_).call(
+    function _tryGetAssetDecimals(IERC20 asset_) private view returns (bool, uint8) {
+        (bool success, bytes memory encodedDecimals) = address(asset_).staticcall(
             abi.encodeWithSelector(IERC20Metadata.decimals.selector)
         );
         if (success && encodedDecimals.length >= 32) {