1

I am trying to understand the following EVM call instruction generated from here: https://ethervm.io/decompile

 memory[temp3:temp3 + 0x00] = address(msg.sender).call.gas(0x00).value(var1)(memory[temp3:temp3 + memory[0x40:0x60] - temp3]);

So basically the gas is specified as how much gas the sender willing to pay to send the money to the "msg.sender", right? But I am quite confused about the gas(0x00). Wouldn't the contract be able to send anything, right?

1 Answer 1

3
+50

So basically the gas is specified as how much gas the sender willing to pay to send the money to the "msg.sender"

This claim is not correct.

To understand what's going on, you need to have a basic understanding of how a low-level call is executed (the yellow paper or this paper) are good starting points.

Essentially, when a call is performed (implicitly, but there are exceptions such as delegate call) the sender is the smart contract that is executing. It gives as input a copy of portion of its memory and along the message it sends an amount of money. Moreover the sender has the faculty to specify the amount of gas that the callee has at its disposal for a possible execution.

Finally, after the invocation, depending on the exit status, a flag is put on top of the stack.

ANSWER

In your case, the executing contract is simply sending var1 Wei to the msg.sender. The msg.sender has at its disposal 0 gas units and so, it is prevented to performing operations. This means that even if the recipient contains a fallback function no executions are allowed.

REPRODUCE CODE WITH 0 gas

A simple example that use the (not recommended low-level) call instruction:

int var1 = 12;
msg.sender.call.gas(0).value(var1)();

You can find more details about send and transfer function (that give a limited number of gas that is safe against re-entrancy but still allow code execution) in the answer to this question.

4
  • Hello, thank you for your answer. However, I am still a bit confused. So as you mentioned, "Moreover the sender has the faculty to specify the amount of gas that the callee has at its disposal for a possible execution.". Doesn't it mean that caller will provide certain amount of gas for the callee to execute its fallback function? So for this example, even if the call back function cannot be executed, the gas transfer would still be successful, right? Dec 4, 2018 at 14:32
  • Also, how I can actually write such code in Solidity to zero the gas to be used by the callee? Note that this instruction is decompiled from some real-world smart contract code.. Thanks. Dec 4, 2018 at 14:34
  • At the end of the first comment, do you mean "value/money" transfer and not gas transfer, it is right?
    – Briomkez
    Dec 4, 2018 at 17:10
  • Right! Sorry for the confusion. It means "money" transfer. Dec 4, 2018 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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