3

A friend and I were thinking about transaction costs, is there any attached cost to send a transfer to a new address that has not been stored on chain before? So we started digging.

First off we called transfer to a new address and another one that has been used before, as expected the cost was 21000 for both of them.

New address: https://ropsten.etherscan.io/tx/0xec05af75ec938aa1cc78612b13d8d2e3c8f4212f60173161450297c9a25ea5a3

Miner (used before) address: https://ropsten.etherscan.io/tx/0x7fe1c8c699901923d89e07a9b66e7d952c67064bcc9d86bf84bad07cac2391b1

Then we tried to made the transfer from an SC, this is the function we are using:

function test (address receiver) public payable { receiver.transfer(msg.value); }

Simple enough, we started testing, called the function to a new address:

https://ropsten.etherscan.io/tx/0x38dabd569350fa985e11f892f7175ad09a32a0c067b993f68152f34d7ca4dcb3

First surprising thing was the cost to execute this function, was 55356 gas, much higher then the 21000 we saw before, we called it again:

https://ropsten.etherscan.io/tx/0xa2d23ea51102cc98f92b6ef89ed452a5be0e0ebbc26c136fc43f9a5a67a99a52

To our surprise, now gas costs were 30356 much less than before, why??

We tried to call the function on a used address (that should be already stored on chain) to see if sending to a new address was the differential factor, we did it twice:

https://ropsten.etherscan.io/tx/0xf9eb2e6536db2ec933ac21fb5bd8c422b6ae3b811f4bd72be4a55e02a6aec227

https://ropsten.etherscan.io/tx/0x4ef30764af81df4dc0dcc98bd4db5424c0c2bea99257df829b1c347a8764048f

And it costed 30356 in both.

Why does this happen, why sending ether to a new address from a SC costs over 50% more than sending to a used address?

4
  • You'd have to share the code for the smart contract. The gas cost of a transfer call shouldn't depend on whether the recipient has been the recipient of earlier transfers, but it's hard to give you an explanation without seeing the code.
    – user19510
    Jun 24, 2018 at 20:29
  • (To clarify, I see the function you provided, but without the full code, it's hard to associate it with the bytecode and step through it.)
    – user19510
    Jun 24, 2018 at 20:29
  • the rest of the contract shouldn't matter right? anyways MathematicalRain got it, I learnt something new today :) btw I'm a fan of your cte game, thanks for that! Jun 25, 2018 at 1:40
  • In terms of gas cost, no, the rest of the contract shouldn't matter. I learned something new as well!
    – user19510
    Jun 25, 2018 at 2:02

1 Answer 1

5

Yes this is true. If you read the Ethereum Yellow paper you can see in Appendix H that you have to pay extra gas if you send Ether to a new account.

This is to discourage addresses sending a load of transactions to new addresses, blowing up the chain size like that.

3
  • 1
    makes sense, but why doesn't it apply with a regular address.transfer(amount) those are always 21000 no matter if the address is new or not Jun 25, 2018 at 1:37
  • 1
    FYI, I found this most accessible in Appendix G, the entry for Gnewaccount. The gas cost is 25000 for a "CALL or SUICIDE operation which creates a new account."
    – user19510
    Jun 25, 2018 at 2:04
  • @smarx You are correct, 25000 is the exact difference and a new account has been created. Digging some more I found this cost was set because of a gas calculation bug exploited at around block 2100000, still don't know why this doesn't apply for regular address.transfer Jun 25, 2018 at 8:38

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.