3

Transfer amount to any address always showing the re-entrancy vulnerability warning. How to avoid this warning?

function completeChallenge(address _challengerAddress,address _challengeAddress,uint _index) internal returns(bool) {
   _challengerAddress.transfer(safeMul(challengeList[_challengerAddress][_challengeAddress][_index].challengeChargeAmountWei,2));
   return true;
}

enter image description here

  • Don't avoid warnings, listen to warnings, find the problem and fix it. Smart contracts handle money as you know. – ferit May 22 '18 at 17:02
0

Unable to reproduce the warning in Solidity. What version are you using? pragma solidity ^0.4.17; is the latest.

You may want to try assigning the transferAmount separately. This will at least remove SafeMath's safeMul code from the .transfer method call.

function completeChallenge(address _challengerAddress,address _challengeAddress,uint _index) internal returns(bool) {
    uint transferAmount = safeMul(challengeList[_challengerAddress][_challengeAddress][_index].challengeChargeAmountWei, 2);
   _challengerAddress.transfer(transferAmount);
   return true;
}

Hope that helps.

  • latest one ^0.4.17 and after above change still showing the same warning. You will see this warning in analysis section in remix compiler. – comeback4you Oct 6 '17 at 8:42
0

You should to update state before calling the transfer method. Because if you don’t update state then if the receiver is a smart contract it can call back your contract method to transfer again and again until your contract balance become zero

  • share any realtime example – comeback4you Aug 26 '19 at 4:26
  • You can search the very wellknown DAO fork to undertsnad more about the re entry vulnerability – Ha ĐANG Aug 26 '19 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.