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

Negative large numbers throw exceptions when passed to encodeFunctionCall #5890

Closed
1 task done
zdenkolini opened this issue Mar 6, 2023 · 4 comments · Fixed by #6221 or #6239
Closed
1 task done

Negative large numbers throw exceptions when passed to encodeFunctionCall #5890

zdenkolini opened this issue Mar 6, 2023 · 4 comments · Fixed by #6221 or #6239
Assignees
Labels
1.x 1.0 related issues 4.x 4.0 related Bug Addressing a bug

Comments

@zdenkolini
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When I pass a string representing a large number that is negative, for instance in the case of a int128:
2^128 / 2 - 1 = 170141183460469231731687303715884105727 * -1 = -170141183460469231731687303715884105727

I get this error:
Encode function call failed: invalid BigNumber string (argument="value", value="0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000-170141183460469231731687303715884105727", code=INVALID_ARGUMENT, version=bignumber/5.7.0)

After snooping through the repo, I found that you padStart int/uint values, which is okay for uints, but not for ints. (source: https://github.com/web3/web3.js/blob/1.x/packages/web3-eth-abi/src/index.js#L266-L274)

This behaviour doesn't occur for small ints, for instance -2, only large ones.

Expected Behavior

Should be able to pass large negative numbers such as -170141183460469231731687303715884105727

Steps to Reproduce

import Web3Abi from 'web3-eth-abi`;

const types = {
    "type": "function",
    "name": "pour",
    "inputs": [
        {
            "type": "bytes12",
            "name": "vaultId_"
        },
        {
            "type": "address",
            "name": "to"
        },
        {
            "type": "int128",
            "name": "ink"
        },
        {
            "type": "int128",
            "name": "art"
        }
    ]
};

const params = [
    "0x",
    "0x0000000000000000000000000000000000000000",
    "170141183460469231731687303715884105727",
    "-170141183460469231731687303715884105727"
]

const result = Web3Abi.encodeFunctionCall(types, params);

Web3.js Version

1.8.2

Environment

  • Operating System: macOS Ventura 13.1
  • Browser: Google Chrome 110.0.5481.177 (Official Build) (arm64)
  • Node.js Version: 14.19.-
  • NPM Version: 6.14.16

Anything Else?

No response

@zdenkolini zdenkolini added the Bug Addressing a bug label Mar 6, 2023
@mconnelly8 mconnelly8 added the 1.x 1.0 related issues label Mar 6, 2023
@mconnelly8 mconnelly8 added Investigate 4.x 4.0 related and removed Discussion labels May 30, 2023
@mconnelly8
Copy link

From 5/30/23 meeting, need to try and reproduce on 1.x/4.x.

@spacesailor24
Copy link
Contributor

@zdenkolini To give you an update, as shown in #6221, this doesn't seem to be an issue in 4.x, and I will be investigating a fix for this in 1.x today. Thank you for brining this issue to our attention!

spacesailor24 added a commit that referenced this issue Jun 27, 2023
…abi`'s `encodeFunctionCall` (#6221)

* Init contract NegativeNumbers tests

* Add encodeFunctionCall test cases from #5890

* Init NegativeNumbers.sol

* Refactor test to work with cypress

* Fix tests to work with cypress

* Fix tests
@spacesailor24 spacesailor24 reopened this Jun 27, 2023
@spacesailor24
Copy link
Contributor

As an update, #6239 applies a fix for this in 1.x. Thank you for your patience

@spacesailor24
Copy link
Contributor

Fix has been merged, will be apart of next release - I'll get back to you with an eta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues 4.x 4.0 related Bug Addressing a bug
Projects
None yet
4 participants