Skip to content

Commit

Permalink
inline nonReentrant call
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Wang committed Nov 8, 2023
1 parent b2f8d03 commit 2c72dff
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions contracts/Comet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,6 @@ contract Comet is CometMainInterface {
(asset14_a, asset14_b) = getPackedAssetInternal(config.assetConfigs, 14);
}

modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}

function _nonReentrantBefore() private {
bytes32 slot = COMET_REENTRANCY_GUARD_FLAG_SLOT;
uint256 status;
Expand Down Expand Up @@ -789,24 +783,28 @@ contract Comet is CometMainInterface {
* @dev Safe ERC20 transfer in and returns the final amount transferred (taking into account any fees)
* @dev Note: Safely handles non-standard ERC-20 tokens that do not return a value. See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
*/
function doTransferIn(address asset, address from, uint amount) nonReentrant internal returns (uint) {
function doTransferIn(address asset, address from, uint amount) internal returns (uint) {
_nonReentrantBefore();
uint256 preTransferBalance = ERC20(asset).balanceOf(address(this));
(bool success, bytes memory returndata) = asset.call(abi.encodeWithSelector(ERC20.transferFrom.selector, from, address(this), amount));

Check warning on line 789 in contracts/Comet.sol

View workflow job for this annotation

GitHub Actions / Contract linter

Avoid to use low level calls
if (!success || !(returndata.length == 0 || abi.decode(returndata, (bool)))) {
revert TransferInFailed();
}
_nonReentrantAfter();
return ERC20(asset).balanceOf(address(this)) - preTransferBalance;
}

/**
* @dev Safe ERC20 transfer out
* @dev Note: Safely handles non-standard ERC-20 tokens that do not return a value. See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
*/
function doTransferOut(address asset, address to, uint amount) nonReentrant internal {
function doTransferOut(address asset, address to, uint amount) internal {
_nonReentrantBefore();
(bool success, bytes memory returndata) = asset.call(abi.encodeWithSelector(ERC20.transfer.selector, to, amount));

Check warning on line 803 in contracts/Comet.sol

View workflow job for this annotation

GitHub Actions / Contract linter

Avoid to use low level calls
if (!success || !(returndata.length == 0 || abi.decode(returndata, (bool)))) {
revert TransferOutFailed();
}
_nonReentrantAfter();
}

/**
Expand Down

0 comments on commit 2c72dff

Please sign in to comment.