8

I have seen many contract addresses being created using vanity address generators to have many 0s in the begginning and even method sighashes having all 0s in them and have come to the conclusion that they do save gas. If yes, then how much gas do they really save?

1
  • I would think that they have no function at all (and no gas saving). It's only for vanity and looking cool. But I am not sure so I will let someone else answer...
    – Undead8
    Commented Jun 6, 2021 at 23:03

2 Answers 2

8

Following the rules of the yellow paper, it costs 4 gas for every zero bytes of transaction data (msg.data). Compare that to the cost of 68 gas, or 17 times as expensive for a non-zero byte. The hamming weight of msg.sender makes no difference tho. The only bytes we are interested in are in msg.data, which includes the function selector.

For example, if you're using the transfer(_to, _amount) method on an ERC20 token, if the receiver address _to contains a lot of zeroes, it will save you gas executing the transaction.

Using OpenZeppelin’s StandardToken as a reference implementation, a standard transfer to an address with non-zero bytes costs 51,486 gas. However, a transfer to an address with eight zero bytes only costs 50,974 gas, a difference of 51486 — 50974 = 512 gas, which can be expressed as 64 * 8 (the number of zero bytes).

I suggest you read this article On Efficient Ethereum Addresses for a detailed explanation.

4

One of the projects using such 'short' addresses is the Gas Token. From https://gastoken.io/#GST2 :

The address of our GST2 GasToken, 0x0000000000b3F879cb30FE243b4Dfee438691c04, is hardcoded. Note that this address is very short (only 15 non-zero bytes instead of 20). We generated our GasToken contract at such an address on purpose, so as to save some gas when creating contracts. The above child contract uses 22 bytes of code, and thus costs roughly 32000 + 22 * 200 = 36400 gas to create (the additional overhead of calling mint is only about 150 gas). If we could make use of address 0x0 for GasToken, we could save an extra 3000 gas or so for every created contract!

So there are gas savings. And the cost savings really depend on the usage. In this case, the usage is when new contracts are created which reference to another (short addressed) contract. Basically less bytes need to be stored.

I'm not sure if having zeros in method signature hashes help, but I guess it might. Haven't really encountered such. Anyway, in my opinion, modifying function names to get a desired hash for them is bad idea, since it makes the contract harder for humans to understand.

2
  • 1
    Thanks for the answer. My question is "HOW" much gas does it save Commented Jun 7, 2021 at 11:46
  • There is no generic answer to that question. It depends on the implementation. I just gave you one example which states how much is saved Commented Jun 7, 2021 at 12:06

Your Answer

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

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