1
   function transferFunds(uint _value) private {
        uint _fee = (3*_value)/(2*100);

        //Perform Ether transfer method
        merchant.transfer(_value - _fee);
        admin.transfer(_fee);
        emit LogForwardedEther(_value, merchant, _value - _fee, admin, _fee);
    }

   function transferFunds(address _token) private {
        uint _value = ERC20(_token).balanceOf(address(this));
        uint _fee = (3*_value)/(2*100);

        //Perform Token transfer method
        ERC20(_token).transfer(merchant, _value - _fee);
        ERC20(_token).transfer(admin, _fee);
        emit LogForwardedToken(_value, merchant, _value - _fee, admin, _fee, _token);
    }

Noticed that there's two separate "Potential Violation of Checks-Effects-Interaction pattern" in the above two functions, but i can't seem to find a better way of handling the state before executing transfer.

Hope someone out there could advise on this.

Thanks!

3
  • i can't seem to find a better way of handling the state - where exactly are you handling any state here? – goodvibration Feb 3 '20 at 11:18
  • @goodvibration sorry, i may have mistaken the check for balance as a state. Still new to Solidity. :/ – Zinxer Feb 3 '20 at 11:27
  • Changing state = changing a contract variable. – goodvibration Feb 3 '20 at 11:30
2

I guess it depends on how paranoid you are. These two functions are private and so the rest of your code may prevent reentrancy. However if you really want to be safe you could introduce a mutex of some sort, like:

bool isTransferring = false;

function transferFunds(uint _value) private {
    require(isTransferring == false, "Rentrancy Detected");
    isTransferring = true;

    uint _fee = (3*_value)/(2*100);

    //Perform Ether transfer method
    merchant.transfer(_value - _fee);
    admin.transfer(_fee);

    isTransferring = false;

    emit LogForwardedEther(_value, merchant, _value - _fee, admin, _fee);
}

This approach is also a lot cheaper after the last hard fork with the changes to how SSTORE is priced.

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.