0

Is only modifier nonReentrant enought to protect against reetrancy or we still need to check success inside function

function withdraw() external nonReentrant {
 5        uint256 amount = balanceOf[msg.sender];
 6        balanceOf[msg.sender] = 0;
 7        (bool success, ) = msg.sender.call.value(amount)("");
 8        require(success, "Transfer failed.");
 9    }

or this is enough?:

function withdraw() external nonReentrant {
 5        uint256 amount = balanceOf[msg.sender];
 6        balanceOf[msg.sender] = 0;
 7        
 9    }
kasper
  • 161
  • 1
  • 3
  • 14
  • This question is unanswerable without the larger context of the whole smart contract and how it interacts with other smart contracts. – Mikko Ohtamaa Jan 21 '21 at 09:48

1 Answers1

0

The second function is fine. As long as you set the sender's balance to 0 before you call msg.sender.call reentrancy won't be an issue.

BrvarG
  • 199
  • 2
  • 4