1

I was reviewing some of the smart contracts on Fantom and came across this function in ZOO:

https://github.com/ZooEcosystem/ZooCoin/blob/main/contracts/ZOO.sol

Whilst they have an internal burn function which I assume can only be used by the contract creators but there is also use of a public burn function? Does this mean in this Smart contract users are can just burn their own coins or others?

The public Burn function:


abstract contract ERC20Burnable is Context, ERC20 {
    /**
     * @dev Destroys `amount` tokens from the caller.
     *
     * See {ERC20-_burn}.
     */
    function burn(uint256 amount) public virtual {
        _burn(_msgSender(), amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, deducting from the caller's
     * allowance.
     *
     * See {ERC20-_burn} and {ERC20-allowance}.
     *
     * Requirements:
     *
     * - the caller must have allowance for ``accounts``'s tokens of at least
     * `amount`.
     */
    function burnFrom(address account, uint256 amount) public virtual {
        uint256 currentAllowance = allowance(account, _msgSender());
        require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance");
        _approve(account, _msgSender(), currentAllowance - amount);
        _burn(account, amount);
    }
}

1 Answer 1

0

The first burn function is the internal _burn function which is belong to Openzeppelin's ERC20 token. Since this function is internal, it should be called from contracts own function burn. What public burn function does is it simply calls the internal _burn function.

And for the burnFrom function, it is simply a more secure way to do burn.

So yes, users burn their own tokens. And no, users cant burn others tokens.

1
  • Oh I see, so even if the public burn or burnFrom functions are called they still need access to the internal functions of the contract. so they'll just fail if used externally? Something I don't quite understand though, why would these functions ever need to be public?
    – ozftm
    Commented Aug 19, 2022 at 8:27

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.