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

Wrong encoding output when using uint256[] #197

Closed
dynalz opened this issue Nov 23, 2022 · 1 comment
Closed

Wrong encoding output when using uint256[] #197

dynalz opened this issue Nov 23, 2022 · 1 comment

Comments

@dynalz
Copy link

dynalz commented Nov 23, 2022

If this is a bug report, please fill in the following sections.
If this is a feature request, delete and describe what you would like with examples.

What was wrong?

Issues encoding uint256[] property. Not sure what's wrong. I am currently on version 2.1.1 and this issue happens, updated to latest version to see if issue is fixed but still persists

Code that produced the error

from eth_abi import encode
args_types=["uint256[]","bool"]
args_list=[[0, 0, 1000000000000000, 0], False]
print(encode(args_types, args_list).hex())

Full error output (Not error, just wrong output)

0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000038d7ea4c680000000000000000000000000000000000000000000000000000000000000000000

Expected Result

This section may be deleted if the expectation is "don't crash".

0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000038d7ea4c680000000000000000000000000000000000000000000000000000000000000000000

Where I found the issue:

  1. https://scope.klaytn.com/account/0x5b4ed8321ea13047195104037798f29257eac28c?tabId=contractCode
  2. Click "Change ABI" tab
  3. Paste the following abi:
[{"name":"calculateTokenAmount", "inputs":[{"type":"uint256[]", "name":""}, {"type":"bool", "name":""}], "outputs": [{"type":"uint256", "name":""}], "stateMutability":"view","type":"function","gas":2220}]
  1. Click "Read Contract" tab
  2. Click "calculateTokenAmount" function
  3. Paste [0, 0, 1000000000000000, 0] and false to params
  4. You can see the query works and returns a valid value, while using eth_abi lib fails (RPC returns execution reverted) due to the enconding result above not matching the expected encoded value.
@fselmo
Copy link
Contributor

fselmo commented Nov 23, 2022

Hey @dynalz, I'm not seeing the same result. What eth-abi's encode returns is the same as Solidity. Please see this contract example:

contract Contract {
    uint256[] list_example = [0, 0, 1000000000000000, 0];

    function encodeExample() public view returns (bytes memory) {
        return abi.encode(list_example, false);
    }
}

If you deploy this contract in, say, remix, with the latest Solidity version, and run the encodeExample() method... you will get the same output as eth-abi.

I did not test out your steps to reproduce with scope.klaytn.com (not familiar with this), but since the Solidity matches it seems safe to say this isn't a bug with eth-abi. I'm going to close this but feel free to re-open if there's a misjudgement on my part.

@fselmo fselmo closed this as completed Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants