Solidity: [abi coder v2] mismatch between coded and actual value

Created on 25 Jun 2019  路  3Comments  路  Source: ethereum/solidity

Description

pragma solidity >=0.0;
pragma experimental ABIEncoderV2;

contract C {

    bytes x_0 = "0";
    function f() public returns (bool) {

        return (this.g_public(x_0) && this.g_external(x_0));
    }

    function stringCompare(string memory a, string memory b) internal pure returns (bool) {
        if(bytes(a).length != bytes(b).length)
            return false;
        else
            return keccak256(bytes(a)) == keccak256(bytes(b));
    }

    function bytesCompare(bytes memory a, bytes memory b) internal pure returns (bool) {
        if(a.length != b.length)
            return false;
        for (uint i = 0; i < a.length; i++)
            if (a[i] != b[i])
                return false;
        return true;
    }

    function g_public(bytes memory g_0) public view returns (bool) {

        if (!bytesCompare(g_0, "0")) return false;

        return true;
    }

    function g_external(bytes calldata g_0) external view returns (bool) {

        if (!bytesCompare(g_0, "0")) return false;

        return true;
    }

}

returns false (0x000...00) when it should return true (0x00...01)

Environment

  • Compiler version: latest develop
  • Target EVM version (as per compiler settings): st petersburg
  • Framework/IDE (e.g. Truffle or Remix): NA
  • EVM execution environment / backend / blockchain client: geth evm interpreter
  • Operating system: Ubuntu 18.04

Steps to Reproduce

  • Install geth
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository -y ppa:ethereum/ethereum
$ sudo apt-get update
$ sudo apt-get install ethereum
  • Compile and run contract on evm interpreter
$ solc --bin-runtime contract.sol 2>/dev/null | grep -A1 "Binary of the runtime" | grep -v Binary > bytecode
$ evm --prestate genesis.json --codefile bytecode --input 26121ff0 run
0x0000000000000000000000000000000000000000000000000000000000000000

where genesis.json is

{
  "nonce": "0x0000000000000000",
  "difficulty": "0x01",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "timestamp": "0x00",
  "number": "0x7D0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x3D0900",
  "alloc": {},
  "config": {
    "eip150Block": 0,
    "eip158Block": 0,
    "eip155Block": 0,
    "homesteadBlock": 0,
    "daoForkBlock": 0,
    "byzantiumBlock": 2000,
    "constantinopleBlock": 2000,
    "petersburgBlock": 2000
  }
}
bug

All 3 comments

Did you actually run the constructor code or just the runtime code? Without the constructor code, the initialization of x_0 = "0" does not happen.

I see, I ran just the runtime code. Closing this issue as a false positive.

Maybe it is best to just add a second contract of the form

contract Factory {
function() public { C c = new C(); c.f(); }
}

Then you do not even need to care about function signatures and can just execute the runtime code of the Factory function without any additional data.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chriseth picture chriseth  路  4Comments

ddeclerck picture ddeclerck  路  3Comments

axic picture axic  路  3Comments

chriseth picture chriseth  路  3Comments

area picture area  路  3Comments