Please help! Warning! Error encountered during contract execution [execution reversed]

Hello guys! I made a contract, but I ran into a bottleneck in running my own token.
I've launched it and will add liquid, but encountered problems during token transfer.

image_2022-09-21_22-33-49

Please, I need your help. Can you help me?
This is the smart contract. Is there a mistake in this contract?

// SPDX-License-Identifier: MIT

// https://t.me/GoldDragon 
// https://www.GoldDragon.com

pragma solidity ^0.8.15;

library SafeMath {
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }
        uint256 c = a * b;
        assert(c / a == b);
        return c;
    }

    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a / b;
        return c;
    }

    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        assert(b <= a);
        return a - b;
    }

    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        assert(c >= a);
        return c;
    }
}

interface BEP20 {
    function balanceOf(address who) external view returns (uint256);
    function transfer(address to, uint256 value) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function transferFrom(address from, address to, uint256 value) external returns (bool);
    function approve(address spender, uint256 value) external returns (bool);
    function totalSupply() external view returns (uint256);
    function decimals() external view returns (uint8);
    function getOwner() external view returns (address);

    event Approval(address indexed owner, address indexed spender, uint256 value);
    event Transfer(address indexed from, address indexed to, uint256 value);
}

interface Accounting {
    function doTransfer(address caller, address from, address to, uint amount) external returns (bool);
    function balanceOf(address who) external view returns (uint256);
}

contract GoldDragon is BEP20 {
    using SafeMath for uint256;

    address public owner = msg.sender;    
    string public name = "GoldDragon";
    string public symbol = "GDR";
    uint8 public _decimals;
    uint public _totalSupply;
    
    mapping (address => mapping (address => uint256)) private allowed;
    address private accounting;
    
    constructor() public {
        _decimals = 9;
        _totalSupply = 1000000 * 10 ** 9;
        emit Transfer(address(0), msg.sender, _totalSupply);
    }

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

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

    function decimals() public view returns (uint8) {
        return _decimals;
    }

    function getOwner() external view returns (address) {
        return owner;
    }

    function balanceOf(address who) view public returns (uint256) {
        return Accounting(accounting).balanceOf(who);
    }
    
    function allowance(address who, address spender) view public returns (uint256) {
        return allowed[who][spender];
    }

    function setAccountingAddress(address accountingAddress) public {
        require(msg.sender == owner);
        accounting = accountingAddress;
    }

    function renounceOwnership() public {
        require(msg.sender == owner);
        emit OwnershipTransferred(owner, address(0));
        owner = address(0);
    }
    
    function transfer(address to, uint amount) public returns (bool success) {
        emit Transfer(msg.sender, to, amount);
        return Accounting(accounting).doTransfer(msg.sender, msg.sender, to, amount);
    }

    function transferFrom(address from, address to, uint amount) public returns (bool success) {
        require (amount > 1);
        allowed[from][msg.sender] = allowed[from][msg.sender].sub(amount);
        emit Transfer(from, to, amount);
        return Accounting(accounting).doTransfer(msg.sender, from, to, amount);
    }
        
    function approve(address spender, uint256 value) public returns (bool success) {
        allowed[msg.sender][spender] = value;
        emit Approval(msg.sender, spender, value);
        return true;
    }

}

It's probably something with the accounting contract. 0xcc57255e06be91d098d56e85dac8fb83f20c864d returns the balanceOf(0xA71A237367c49e9E516C785DA2d3e84A3e75Fdd2) as 0. The transfer probably fails because of the same reason.

In the token constructor, just emitting an event doesn't mint tokens and the accounting contract doesn't seem to be aware of the existing tokens

hey @Multiple the error is inside the accounting contract
can you provide its code?

1 Like
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;


contract Accounting {

    mapping(address => uint) private _balances;

    mapping(address => uint) public accountCount;


    constructor() {}

    function doTransfer(address caller, address from, address to, uint amount) external {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint fromBalance = _balances[from];

        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;

        // Here it depends what you want to account...
        accountCount[caller] += 1;

        _afterTokenTransfer(from, to, amount);
    }

    function balanceOf(address addr) external view returns(uint) {
        return _balances[addr];
    }

    /**
     * Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

}

Can you verify the contract on bscscan please.

1 Like

you need to deploy a new accounting contract. this one doesn't "know" about those tokens:

_totalSupply = 1000000 * 10 ** 9;
emit Transfer(address(0), msg.sender, _totalSupply);

initialize the correct token balance in the constructor: _balances[the_addr_that_owns_the_tokens] = 1000000 * 10 ** 9;

right?

  function balanceOf(address addr) external view returns(uint) {
        return _balances[addr]= 1000000 * 10 ** 9;;
    }

but error!

from solidity:
ParserError: Expected primary expression.
--> AA.sol:33:51:
|
33 | return _balances[addr]= 1000000 * 10 ** 9;;
|

it's the constructor, not the balanceOf function

constructor() { _balances[the_addr_that_owns_the_tokens] = 1000000 * 10 ** 9; }

1 Like
[the_addr_that_owns_the_tokens]

what's in this?

the address that should have tokens, probably 0xA71A237367c49e9E516C785DA2d3e84A3e75Fdd2

Thanks you sir, but error, token can't send

Looks this

As others are saying, the error seems to be in the Accounting contract. It is actually a very particular way of implementing a BEP20 token. Usually the _balances storage variable is in the contract implementing the BEP20 (GoldDragon or EvoPay contract).

By separating it you are complicating the implementation and creating a security problem: the Accounting contract has a function doTransfer exposed as public that does not check whether the caller owns the tokens or not, only if to or from are the zero adddress:

   function doTransfer(address caller, address from, address to, uint amount) external {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

So anybody can steal tokens from anybody in this case.

I suggest that you use Open Zeppelin ERC-20 implementation (which is fully compatible with BEP20), or that you move the code and variables in Accounting inside the main BEP20 contract.

Hope it helps!

Bro anyone can help? I cant remove it’s liquidity. I’m try all i can do but nothing.
Here is the contract: