OpenZeppelin Contracts has quite a strict policy of never allowing zero addresses, by placing checks like
require(receiver != address(0)) everywhere.
For the upcoming 3.0 release I would like us to discuss the possibility of removing these checks.
One of the reasons that they were put there in the first place was that initially Solidity didn’t verify the length of
msg.data, and thus it was possible for a function to be called with missing arguments. If an address argument was missing it would be read as the zero address, and these checks served the purpose of protecting from that kind of accident. Nowadays Solidity inserts checks that
msg.data is big enough, so this kind of error is not really possible anymore.
A different reason why these checks were put in place was to track situations where an asset was burnt or some capacity was being renounced. For example, it’s not possible to transfer ERC20 tokens to the zero address because we want people to use
burn so that we can update the
totalSupply variable. On the other hand, transfering to the address
0x00...01 is also effectively burning the asset, and we don’t update the total supply in that scenario.
Another example is
Ownable, where we disallow transfering ownership to the zero address. This is meant more as a sanity check that you intend to renounce ownership, so we force you to use
renounceOwnership. It can be argued though that transfering to the address
0x00...01 is just as dangerous, yet we don’t do anything about that.
All in all, I’m not sure it makes sense to keep these checks in place. If we want to protect accidentally renouncing a capacity we should make transfering it more difficult by making it a two-step procedure, or something else. Keeping track of total supply in ERC20
transfer is not required by the spec and it’s not that important (since people can burn through other means).
What do we gain by removing the checks? Mostly saving some gas. It may not be that much, but if this is only cruft from the past then there is also no reason to keep it.
Let me know your thoughts!