1

I am creating a burnable token and I am analyzing the code for my smart contract based on OpenZeppelin. Two parts caught my attention:

  function totalSupply() public view returns (uint256) {
    return totalSupply_;
  }

This one shows the total supply, but since I'm burning token, I changed it to:

return totalSupply_ - balances[address(0)];

The second one is:

function transfer(address _to, uint256 _value) public returns (bool) {
    require(_to != address(0)); // I commented this line
    ...

This line prevents that the users mistakenly burn the token by sending them to address(0), so, since I want to be able to burn some tokens, I commented this line out.

I'm new to Solidity. Are these changes ok? Would they have any drawbacks? Is there anything I should be aware of?

0

OpenZeppelin has a BurnableToken that provides a special burn() function that will update the totalSupply.

Unless you have a very good reason I'd recommend to use the BurnableToken. The zero address is not special for Ethereum, if someone find a private key that map to that address it will be possible to access their funds.

  • 1
    This is not the problem. No one will ever find a private key for the 0 address, it's just too unlikely. The issue is that people commonly accidentally send funds to the 0 address without meaning to and this prevents that – Tjaden Hess May 23 '18 at 1:49
1

This is addressed in the original implementation of the burn():

https://github.com/TokenMarketNet/ico/blob/master/contracts/BurnableToken.sol#L23

The only reason to send tokens to 0x0 address is to inform blockchain explorers that token balances have changed. This is mostly because there is no Ethereum Improvement Proposals to address burnable tokens in a manner that would be implemented across blockchain explorers (EtheScan, others). This may change in the future. Currently blockchain explorers only implement Transfer event of EIP-20 proposal.

The use cases implement inform blockchain explorers about the new token supply after the token sale is over, so that CoinMarketCap and others can confirm the amount of circulating tokens.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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