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

encodeFilterTopics does not support negative values #4535

Open
ceyonur opened this issue Jan 11, 2024 · 0 comments
Open

encodeFilterTopics does not support negative values #4535

ceyonur opened this issue Jan 11, 2024 · 0 comments
Assignees
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6

Comments

@ceyonur
Copy link

ceyonur commented Jan 11, 2024

Ethers Version

6.8.1

Search Terms

abi, topics, int256

Describe the Problem

I added a Test interface with int256 indexed topic as follow:

            function encodeTopics(name, value) {
            	var iface = new ethers.Interface([
            		"event Test(int256 indexed test)"
            	]);
            	var filter = iface.encodeFilterTopics("Test", [ value ]);
            	return filter[1];
            }

and run it with encodeTopics("-1"), I got this:

 RangeError: unsigned value cannot be negative (fault="overflow", operation="getUint", value="-1", code=NUMERIC_FAULT, version=6.8.1)

This should be able to take negative integers, but toBeHex and getUint function does not allow negative values here. I was expecting -1 to be encoded successfully to (ffffffffff...ffff)

Code Snippet

function encodeTopics(value) {
            	var iface = new utils.Interface([
            		"event Test(int256 indexed test)"
            	]);
            	var filter = iface.encodeFilterTopics("Test", [ value ]);
            	return filter[1];
            }
            encodeTopics("-1")


### Contract ABI

_No response_

### Errors

```shell
RangeError: unsigned value cannot be negative (fault="overflow", operation="getUint", value="-1", code=NUMERIC_FAULT, version=6.8.1)

Environment

No response

Environment (Other)

No response

@ceyonur ceyonur added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

2 participants