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 signed integers as indexed event inputs are not decoded correctly #20266

Closed
shoenseiwaso opened this issue Nov 12, 2019 · 0 comments · Fixed by #20269
Closed

Negative signed integers as indexed event inputs are not decoded correctly #20266

shoenseiwaso opened this issue Nov 12, 2019 · 0 comments · Fixed by #20269

Comments

@shoenseiwaso
Copy link
Contributor

shoenseiwaso commented Nov 12, 2019

System information

Geth version:

$ geth version
Geth
Version: 1.9.6-stable
Git Commit: bd05968077f27f7eb083404dd8448157996a8788
Architecture: amd64
Protocol Versions: [63]
Network Id: 1
Go Version: go1.13.1
Operating System: darwin

OS & Version: macOS 10.14.6

Expected behaviour

Events which emit negative signed integers with size >64 bits are decoded correctly.

Actual behaviour

They are treated as unsigned integers and not decoded correctly.

Steps to reproduce the behaviour

The problem is here:

case abi.IntTy, abi.UintTy:
num := new(big.Int).SetBytes(topics[0][:])

For integers with size >64 bits, negative values will be encoded by the EVM with a size larger than max(int256). For example, -1 for an int256 (or int192, etc.) is 2^256-1, -2 is 2^256-2, etc.

Non-indexed inputs are decoded correctly via readInteger() in accounts/abi/unpack.go:

default:
// the only case lefts for integer is int256/uint256.
// big.SetBytes can't tell if a number is negative, positive on itself.
// On EVM, if the returned number > max int256, it is negative.
ret := new(big.Int).SetBytes(b)
if typ == UintTy {
return ret
}
if ret.Cmp(maxInt256) > 0 {
ret.Add(maxUint256, big.NewInt(0).Neg(ret))
ret.Add(ret, big.NewInt(1))
ret.Neg(ret)
}
return ret
}

To reproduce:

  1. Deploy the following smart contract:
pragma solidity >=0.0.0;

contract TestIntEvents {
    event Int192Event(int192 x);
    event Int192EventIndexed(int192 indexed x);


    function send192(int192 x) public {
        emit Int192Event(x);
    }

    function send192Indexed(int192 x) public {
        emit Int192EventIndexed(x);
    }
}
  1. Try calling send192(-1) and send192Indexed(-1).
  2. Observe the values returned from both events via go-ethereum:
Int192Event(-1)
// Ok

Int192EventIndexed(115792089237316195423570985008687907853269984665640564039457584007913129639935)
// Not Ok! Expected -1
gballet pushed a commit that referenced this issue Dec 18, 2019
…fields (#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
enriquefynn pushed a commit to enriquefynn/go-ethereum that referenced this issue Mar 10, 2021
…d event fields (ethereum#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
gzliudan pushed a commit to gzliudan/XDPoSChain that referenced this issue Jan 3, 2025
…d event fields (ethereum#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
gzliudan added a commit to gzliudan/XDPoSChain that referenced this issue Jan 3, 2025
…d event fields (ethereum#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
gzliudan added a commit to gzliudan/XDPoSChain that referenced this issue Jan 4, 2025
…d event fields (ethereum#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
gzliudan added a commit to gzliudan/XDPoSChain that referenced this issue Jan 6, 2025
…d event fields (ethereum#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
gzliudan added a commit to gzliudan/XDPoSChain that referenced this issue Jan 7, 2025
…d event fields (ethereum#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
gzliudan added a commit to gzliudan/XDPoSChain that referenced this issue Jan 7, 2025
…d event fields (ethereum#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
gzliudan added a commit to gzliudan/XDPoSChain that referenced this issue Jan 7, 2025
…d event fields (ethereum#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
gzliudan added a commit to gzliudan/XDPoSChain that referenced this issue Jan 9, 2025
…d event fields (ethereum#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
gzliudan added a commit to gzliudan/XDPoSChain that referenced this issue Jan 10, 2025
…d event fields (ethereum#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
gzliudan added a commit to gzliudan/XDPoSChain that referenced this issue Jan 10, 2025
…d event fields (ethereum#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
gzliudan added a commit to gzliudan/XDPoSChain that referenced this issue Jan 10, 2025
…d event fields (ethereum#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
gzliudan added a commit to gzliudan/XDPoSChain that referenced this issue Jan 10, 2025
…d event fields (ethereum#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
gzliudan added a commit to gzliudan/XDPoSChain that referenced this issue Jan 14, 2025
…d event fields (ethereum#20269)

* fix parseTopics() and add tests

* remove printf

* add ParseTopicsIntoMap() tests

* fix FixedBytesTy

* fix int and fixed bytes

* golint topics_test.go
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

Successfully merging a pull request may close this issue.

1 participant