Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Echidna won't start if the ERC20 name or symbol begins with 0x #909

Closed
ChmielewskiKamil opened this issue Jan 18, 2023 · 4 comments · Fixed by #958
Closed

Echidna won't start if the ERC20 name or symbol begins with 0x #909

ChmielewskiKamil opened this issue Jan 18, 2023 · 4 comments · Fixed by #958
Labels

Comments

@ChmielewskiKamil
Copy link
Contributor

The contract below is taken from the NaughtCoin level 15 of the Ethernaut wargame.

// ...
contract NaughtCoin is ERC20 {
    // string public constant name = 'NaughtCoin';
    // string public constant symbol = '0x0';
    // uint public constant decimals = 18;
    uint256 public timeLock = block.timestamp + 10 * 365 days;
    uint256 public INITIAL_SUPPLY;
    address public player;

    constructor(address _player) ERC20("NaughtCoin", "0x0") {
        player = _player;
        INITIAL_SUPPLY = 1000000 * (10**uint256(decimals()));
        _mint(player, INITIAL_SUPPLY);
        emit Transfer(address(0), player, INITIAL_SUPPLY);
    }
// ...

If you import this contract into any Echidna test file, Echidna will freeze with the Starting up, please wait... log (similar to the [#889]).

When run with the --format text flag it returns:

echidna-test: invalid b16 decoding of: "0x0"
CallStack (from HasCallStack):
  error, called at lib/Echidna/Processor.hs:123:31 in echidna-2.0.4-IHy1AKktzUiCzJpHK85UVS:Echidna.Processor

Steps to reproduce the issue

I've prepared an example repository.

  1. Clone the repo and cd into it: git clone https://github.com/ChmielewskiKamil/naught-coin.git && cd naught-coin
  2. Run Echidna: echidna-test src/TestNaughtCoin.sol --contract TestNaughtCoin --config src/config.yaml
  3. This results in: echidna-test: invalid b16 decoding of: "0x0"

As soon as you change the symbol to something different, like so:

// change this
constructor(address _player) ERC20("NaughtCoin", "0x0")

// into this
constructor(address _player) ERC20("NaughtCoin", "ABC")

It starts fuzzing correctly.

If the token's name starts with 0x, it does not work either.

// this won't work
constructor(address _player) ERC20("0xNaughtCoin", "ABC")

This results in the same issue: echidna-test: invalid b16 decoding of: "0xNaughtCoin".

Additional info

This was a bit of a headache to debug as I had no idea about the --format text flag or the format = text option in the config.

This option is mentioned at the end of the FAQ section of the building secure contracts repo. I had this "freezing" problem a couple of times in the past and didn't know how to solve it. Adding the information about this format text debug option in a couple more places would be great for newer users to solve problems on their own.

I would be happy to help update the documentation. I had a couple of ideas where such info could be present:

Let me know what you think

Thanks!

@ChmielewskiKamil
Copy link
Contributor Author

ChmielewskiKamil commented Jan 18, 2023

This is a pretty niche use case (symbols and names with 0x) but there are a couple of tokens that use this:

name symbol
ZRX 0x
0xBTC 0xBitcoin
0XMR 0xMonero
ZXC 0xcert

As I am not entirely sure how the Processor.hs work, the scope of the issue might be bigger than the ERC20 construction.

@ggrieco-tob
Copy link
Member

This looks like a legitimate issue and I think I know why it fails. Thanks a lot for the report, we will try to fix it for the next release 😄

@ChmielewskiKamil
Copy link
Contributor Author

@ggrieco-tob Awesome, thank you!

@ggrieco-tob
Copy link
Member

Small reproducer:

contract A {
  string public x = "0xa";
  function f() public returns(string) { return x; }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants