Does calling burn externally revert on failure?

When sending a token you can set a require to return true on ERC20 transfer to make sure the tx went through.

What about burning? Is this necessary?

if i call
someContractToken.burn(from, amount) in my contract, can the burn fail - but the transaction still go through?

If there is

someContractToken.burn(from, amount)
mint(to, amount)

Is this safe, or could the burn somehow fail and the code still continue to execute the mint?

This question is missing relevant details.

For starters, please share the details of the contract (?) pointed by someContractToken.

Assuming your contract is (or inheriting from) openzeppelin's ERC20 contract and you didn't make change in the _burn function:

The code will execute the burn function first, and if it executes successfully, only then the mint function will execute. If the burn function fails, the transaction will revert and the mint function will not execute. Therefore, this code is safe and will not execute the mint function if the burn function fails.

XEN Crypto: XEN Token | Address 0x06450dEe7FD2Fb8E39061434BAbCFC05599a6Fb8 | Etherscan

Directly from the link that you provided (starting line 414 in XENCrypto.sol):

function burn(address user, uint256 amount) public {

As you can see, the function doesn't return anything, so the only type of "failure indication" that you can receive here is a revert of your entire transaction, which means that the general answer to your question:

can the burn fail - but the transaction still go through?

Is no.

The contract makes the callback on the succesful burn... That's why i am in doubts whether is it necessary to confirm through callback or is it safe after the call to burn.

Is it still good?

function burn(address user, uint256 amount) public {
        require(amount > XEN_MIN_BURN, "Burn: Below min limit");
            "Burn: not a supported contract"

        _spendAllowance(user, _msgSender(), amount);
        _burn(user, amount);
        userBurns[user] += amount;
        IBurnRedeemable(_msgSender()).onTokenBurned(user, amount);

The callback which you are referring to is executed at:

IBurnRedeemable(_msgSender()).onTokenBurned(user, amount);

In other words, your code:

someContractToken.burn(from, amount)

Ultimately triggers:

someContractToken.onTokenBurned(from, amount)

Depending on your product definition. you can add some "confirmation code" inside that callback.
But from the details that you have provided here, it doesn't sound like you actually need to do so.

1 Like