From f2707f2f614efb80a98eea54b87251c4458abd7b Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 9 Nov 2023 00:49:18 -0800 Subject: [PATCH] add low level support to approveThis as well --- contracts/Comet.sol | 9 ++++++--- contracts/CometMainInterface.sol | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/contracts/Comet.sol b/contracts/Comet.sol index 2aa12bc2f..4173101e7 100644 --- a/contracts/Comet.sol +++ b/contracts/Comet.sol @@ -783,7 +783,7 @@ contract Comet is CometMainInterface { function doTransferIn(address asset, address from, uint amount) nonReentrant internal returns (uint) { uint256 preTransferBalance = ERC20(asset).balanceOf(address(this)); (bool success, bytes memory returndata) = asset.call(abi.encodeWithSelector(ERC20.transferFrom.selector, from, address(this), amount)); - if (!success || !(returndata.length == 0 || abi.decode(returndata, (bool)))) { + if (!success || (returndata.length != 0 && !abi.decode(returndata, (bool)))) { revert TransferInFailed(); } return ERC20(asset).balanceOf(address(this)) - preTransferBalance; @@ -795,7 +795,7 @@ contract Comet is CometMainInterface { */ function doTransferOut(address asset, address to, uint amount) nonReentrant internal { (bool success, bytes memory returndata) = asset.call(abi.encodeWithSelector(ERC20.transfer.selector, to, amount)); - if (!success || !(returndata.length == 0 || abi.decode(returndata, (bool)))) { + if (!success || (returndata.length != 0 && !abi.decode(returndata, (bool)))) { revert TransferOutFailed(); } } @@ -1287,7 +1287,10 @@ contract Comet is CometMainInterface { function approveThis(address manager, address asset, uint amount) override external { if (msg.sender != governor) revert Unauthorized(); - ERC20(asset).approve(manager, amount); + (bool success, bytes memory returndata) = asset.call(abi.encodeWithSelector(ERC20.approve.selector, manager, amount)); + if (!success || (returndata.length != 0 && !abi.decode(returndata, (bool)))) { + revert ApproveFailed(); + } } /** diff --git a/contracts/CometMainInterface.sol b/contracts/CometMainInterface.sol index b0f67b867..610dfd826 100644 --- a/contracts/CometMainInterface.sol +++ b/contracts/CometMainInterface.sol @@ -11,6 +11,7 @@ import "./CometCore.sol"; abstract contract CometMainInterface is CometCore { error Absurd(); error AlreadyInitialized(); + error ApproveFailed(); error BadAsset(); error BadDecimals(); error BadDiscount(); @@ -25,6 +26,7 @@ abstract contract CometMainInterface is CometCore { error NotForSale(); error NotLiquidatable(); error Paused(); + error ReentrantCallBlocked(); error SupplyCapExceeded(); error TimestampTooLarge(); error TooManyAssets(); @@ -32,7 +34,6 @@ abstract contract CometMainInterface is CometCore { error TransferInFailed(); error TransferOutFailed(); error Unauthorized(); - error ReentrantCallBlocked(); event Supply(address indexed from, address indexed dst, uint amount); event Transfer(address indexed from, address indexed to, uint amount);