mhw0 / libethc

Open-source Ethereum C library
https://mhw0.github.io/libethc/
MIT License
48 stars 9 forks source link

ABI generated is not correct #14

Closed DerXanRam closed 1 year ago

DerXanRam commented 1 year ago

Hello bro.... To day i was testing the ABI encoder using this code

char *ABIFunction()
{
    struct eth_abi abi;
    char *fn = "allPairs(uint)", *hex;
    uint64_t num = 2;
    size_t hexlen;
    uint64_t amount_out_min = 0, deadline = 346744838;
    //////////////////
    eth_abi_init(&abi, ETH_ABI_ENCODE);
    eth_abi_call(&abi, &fn, NULL);
    eth_abi_uint64(&abi,&num);
    eth_abi_call_end(&abi);

    ok(eth_abi_to_hex(&abi, &hex, &hexlen));
    ok(eth_abi_free(&abi));
    return hex;
}

The generated hex is

0xe9e0f23f0000000000000000000000000000000000000000000000000000000000000002

when i send this to eth_call RPC, the generated RPC response is

{"error":{"code":-32000,"message":"execution reverted"},"id":0,"jsonrpc":"2.0"}

But when i use https://abi.hashex.org/ to generate the ABI, the ABI hex is

0x1e3dd18b0000000000000000000000000000000000000000000000000000000000000002

and when i send it to The RPC, the same way i sent the above ABI data, The RPC response is

{"id":0,"jsonrpc":"2.0","result":"0x00000000000000000000000012ede161c702d1494612d19f05992f43aa6a26fb"}

which is success. As u can see the ABI generated by the code and by the website, The difference is found only in the first 10 digits. Can u look at it please? Thanks :pray:

mhw0 commented 1 year ago

Hey @DerXanRam. uint is just alias for uint256. I think the ABI expects the int types to not be aliases. Try this signature instead: allPairs(uint256)

References:

DerXanRam commented 1 year ago

Hey @DerXanRam. uint is just alias for uint256. I think the ABI expects the int types to not be aliases. Try this signature instead: allPairs(uint256)

References:

so when i incode ABI i always need to replace uint by uint256. right?

mhw0 commented 1 year ago

so when i incode ABI i always need to replace uint by uint256. right?

Correct, uint -> uint256 and int -> int256