Repository navigation
fix(event): decode uint event parameters as unsigned - #24
0xbigapple wants to merge 1 commit into
Conversation
Split uint and trcToken out of INT_NUMBER and decode them with the new DataWord.bigUIntValue so values with bit 255 set are no longer published as negative numbers.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
No issues found across 3 files
Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack
View guided diff | Turn on auto-fix | Re-trigger cubic
What does this PR do?
ContractEventParserclassifiedint,uintandtrcTokentogether asINT_NUMBERand decoded all of them as signed two's complement. Anyuint256event parameter with bit 255 set was therefore published as a negative number, in bothtopicMap(indexed) anddataMap(non-indexed).This PR adds a
UINT_NUMBERtype foruint*andtrcTokenand decodes it with a newDataWord.bigUIntValuehelper (new BigInteger(1, bytes)), mirroring the existingDataWord.bigIntValue. Signed decoding is unchanged.Why are these changes required?
Unlimited TRC20 approvals hit this every day. Mainnet USDT transaction f2e9b6cc2df49316122f28e974b28d1e160bcf49db84a04827b1b49cea38cfb4 (block 87664803) emits
Approval(owner, spender, type(uint256).max); the event plugin publishesdataMap.value = "-1"instead of115792089237316195423570985008687907853269984665640564039457584007913129639935. Every other decoder in the ecosystem, including TronGrid, trident, web3.js and ethers, treatsuint256as unsigned; the java-tron event plugin is the only producer emitting negative values.A fix for the same defect was proposed in tronprotocol#2297 (2019) but was closed unmerged.
This PR has been tested by:
EventParserTestcovers2^255-1,2^255and2^256-1foruint256,uintandtrcTokenthrough bothparseDataBytesandparseTopic, withint256(-1)as the control, plus an end-to-endContractEventParserAbicase fortopicMapanddataMap. The new tests fail on the currentrelease_v4.8.3head.Approvallog above through a contract that emits the sameowner,spenderandvalue; the private-chain logtopicsanddataare byte-identical to the mainnet log. With therelease_v4.8.3build the native-queuecontractEventTriggermessage carriedvalue = "-1"; with this build the same transaction decoded to the positive value on both the realtime path and theversion = 1history replay path, and the two indexed addresses decoded identically on both builds. A second probe contract covering2^255-1,2^255,2^256-1andint256(-1)gave the same picture.Follow up
None.
Extra details
Breaking changes (release-note items):
uint256event parameters at or above2^255are published as positive decimal strings intopicMapanddataMap. Consumers that compare the decoded value to"-1"to detect an unlimited approval must compare to115792089237316195423570985008687907853269984665640564039457584007913129639935instead.event.subscribe.filter.contractTopicmatchescontracteventtriggers against decoded indexed values. A filter written as"-1"for such a parameter must be rewritten as the positive value.Raw
topicsanddata,contractlogtriggers, and all JSON-RPC, HTTP and gRPC responses are unchanged.Summary by cubic
Fixes
uint*andtrcTokenevent parameters being decoded as signed values, publishinguint256values at or above2^255as negative numbers intopicMapanddataMap.Breaking changes
uint256parameters at or above2^255are now published as positive decimal strings, so consumers matching an unlimited approval against"-1"must compare against115792089237316195423570985008687907853269984665640564039457584007913129639935instead.event.subscribe.filter.contractTopicfilters written for such parameters must use the positive value.Raw event data and all JSON-RPC, HTTP, and gRPC responses are unchanged.
Written for commit f89f6bc. Summary will update on new commits.