5

Does address.send(0) makes an actual message call forwarding some small amount of gas(2300?) to fallback function or does it simply return false without making a message call to another contract? It wouldn't be unreasonable to assume that EVM detects 0 value and simply returns false, because what's the point of making a call in this case if there's nothing to send?

I'm asking this, because I want to understand how this example from a post on security works

contract auction {
  address highestBidder;
  uint highestBid;
  mapping(address => uint) refunds;
  function bid() {
    if (msg.value < highestBid) throw;
    if (highestBidder != 0)
      refunds[highestBidder] += highestBid;
    highestBidder = msg.sender;
    highestBid = msg.value;
  }
  function withdrawRefund() {
    uint refund = refunds[msg.sender];
    refunds[msg.sender] = 0;
    if (!msg.sender.send(refund))
     refunds[msg.sender] = refund;
  }
}
4

Update on 09 December 2019:

As of today, address.send(0) returns true if call didn't run out of gas. Also it executes the target contract supplying min(gasleft - 700, 2300) gas.

Original answer below:

So, when you do address.send(0) the return is always false. The code inside the fallback function of the called contract doesn't run at all. In the example below I couldn't log a value from inside the fallback function even though there was enough gas to do it.

contract A {
    event myLog(bool indexed success);
    function mySend(address B, uint y){
        var success = B.send(y);
        myLog(success);
    }
}

contract B {
    event myLog(bool indexed here);
    function() {
        myLog(true);
    }
}

From JS side I did:

  • A.mySend(addressB, 0, {gas: 50000, value: 1}); // [success: false]

  • A.mySend(addressB, 0, {gas: 50000, value: 0}); // [success: false]

  • A.mySend(addressB, 1, {gas: 50000, value: 1}); // [success: true, here: true]

  • A.mySend(addressB, 1, {gas: 50000, value: 0}); // [success: true, here: true]

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.