# Understanding the formal description of a transaction and its associated refunds

Excerpt from page 8 of the yellow paper:

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?

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`?

• – eth Sep 24 '18 at 23:03

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

• 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
• 1. The amount refunded is 24000 gas, this is in the paper appendix G. 2. 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. 3. 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

## Definition 64

Rselfdestruct is NOT associated with block receipts. Instead, it's a constant defined in Appendix G of the yellow paper, having a value of 24,000 (as of the Byzantium version 69351d5).

The summation sigma sign Σ means that there is a refund worth of 24,000 gas for every self-destructed account i in As. Of course, the whole sum is added to the already existing refunding balance Ar.

## Definition 65

We have to put a cap on the refunded gas insofar we can ensure all transactions make sense from an economic point of view. In case the previous Ar' calculation yields a gas value higher than what the transaction owner paid, it wouldn't make sense for miners to run these transactions (they would have to pay for the extra refunded gas).

Consequently, the Ethereum protocol was designed in such a way that economically unfeasible scenarios are avoided - i.e. people who would delete a bunch of accounts just to make money, but these transactions wouldn't be processed and they would bloat the mempool with no purpose whatsoever.