4

Excerpt from page 8 of the yellow paper:

enter image description here

I fully understand that contracts can self-destruct and, when that happens, according to this thread, all the balance is refunded to the address specified as a parameter.

In equation 64, is that what happens? Are all balances of accounts destroyed in a state transition added up? The only prior reference to a function named R is within the context of transaction receipts and I'm skeptical that is what is added up here.

If yes, what is the rationale behind the next equation, no. 65, to set a limit on the refund?

enter image description here

Scenario:

  1. Gas limit is 60,000 and gas price 5 gwei
  2. Transaction uses only 20,000
  3. An account holding 1,000,000 gwei or ㆔0,01 is destroyed in the process
  4. As Tg is 60,000 and g' is 40,000, ((Tg - g') / 2) is 10,000 which, at the rate of 5 gwei, means 50,000 gwei or ㆔0,00005

Would the caller be refunded only g' + ㆔0,00005 instead of g' + ㆔0,01?

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143
  • 1
    Related: https://ethereum.stackexchange.com/questions/594/what-are-the-limits-to-gas-refunds – eth Sep 24 '18 at 23:03

2 Answers2

1

The equations that you show refer exclusively to gas refund. The execution of selfdestruct(address) implies sending the ether in the contract to address, Aad then destroy the contract. The operation of destruction refund gas and this is what is added to the counter. the first equation (63) is just showing that the refund counter is updated after a selfdestruct.

The second equation shows that the total gas to be refunded is the gas left, (unused gas) plus the minimum between the half of the consumed gas [(Tg-g')/2] and the amount in the refund counter. this means that if your transaction consumes 30000 gas the most it will be refunded is 15000.

So the caller will be refunded the corresponding gas and the 0.01 ether will go to the address used when in selfdestruct(address)

Hope this helps

Jaime
  • 8,340
  • 1
  • 12
  • 20
  • I commend you for your help but there are still many things unclear: (1) exactly much gas is refunded when the operation of destruction is executed? then (2) why is it called a counter when it doesn't actually count or increment things? then (3) still, why is the maximum gas refunded half of what was consumed? – Paul Razvan Berg Sep 24 '18 at 22:05
  • The amount refunded is 24000 gas, this is in the paper appendix G.
  • It dows increment, the equation says Ar = Ar + selfdestruct refund, that is the new value is the current values plus the refund for self-destructing a contract.
  • That is what the equations state. If this were not the case, the network may end up paying you if the amount of refund is more than the gas that the transaction cost.
  • – Jaime Sep 24 '18 at 22:17