Skip to content

Conversation

@shoenseiwaso
Copy link
Contributor

Resolves #20266

This PR fixes bugs in parseTopics() and parseTopicsIntoMap() which incorrectly decoded negative integer values and fixed bytes values.

Added tests, now passing, which fail on master:

--- FAIL: TestParseTopics (0.00s)
    --- PASS: TestParseTopics/support_fixed_byte_types,_right_padded_to_32_bytes (0.00s)
    --- FAIL: TestParseTopics/int8_with_negative_value (0.00s)
        topics_test.go:142: parseTopics() = &{115792089237316195423570985008687907853269984665640564039457584007913129639934}, want &{-1}
    --- FAIL: TestParseTopics/int256_with_negative_value (0.00s)
        topics_test.go:142: parseTopics() = &{115792089237316195423570985008687907853269984665640564039457584007913129639934}, want &{-1}
--- FAIL: TestParseTopicsIntoMap (0.00s)
    --- FAIL: TestParseTopicsIntoMap/support_fixed_byte_types,_right_padded_to_32_bytes (0.00s)
        topics_test.go:181: parseTopicsIntoMap() = map[staticBytes:[1 2 3 4 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]], want map[staticBytes:[1 2 3 4 5]]
    --- FAIL: TestParseTopicsIntoMap/int8_with_negative_value (0.00s)
        topics_test.go:181: parseTopicsIntoMap() = map[int8Value:115792089237316195423570985008687907853269984665640564039457584007913129639935], want map[int8Value:-1]
    --- FAIL: TestParseTopicsIntoMap/int256_with_negative_value (0.00s)
        topics_test.go:181: parseTopicsIntoMap() = map[int256Value:115792089237316195423570985008687907853269984665640564039457584007913129639935], want map[int256Value:-1]

This PR promotes a few functions and variables to public, all inaccounts/abi/unpack.go, to help reduce duplication in decoding fields: MaxUint256, MaxInt256, ReadInteger() and ReadFixedBytes().

Future enhancement, not addressed in this PR, could further reduce the duplication of functionality between parseTopics(), parseTopicsIntoMap() and toGoType().

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@holiman
Copy link
Contributor

holiman commented Nov 12, 2019

Thanks! Please take a look at and fix the lint failures on travis

@shoenseiwaso
Copy link
Contributor Author

Thanks for the quick turnaround! Linter issues fixed and linting and tests passed in CI.

Copy link
Member

@gballet gballet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once updated

@gballet gballet merged commit 6ae9dc1 into ethereum:master Dec 18, 2019
@shoenseiwaso shoenseiwaso deleted the 20266-indexed-signed-integers branch December 18, 2019 15:23
enriquefynn pushed a commit to enriquefynn/go-ethereum that referenced this pull request 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 added a commit to gzliudan/XDPoSChain that referenced this pull request Jan 24, 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 this pull request may close these issues.

Negative signed integers as indexed event inputs are not decoded correctly

4 participants