Skip to content

fix(rpc): Missing boundary check in GetTransactionReceipt#861

Merged
thomas-nguy merged 4 commits intocrypto-org-chain:developfrom
JayT106:jt/fix-get-tx-receipt
Mar 16, 2026
Merged

fix(rpc): Missing boundary check in GetTransactionReceipt#861
thomas-nguy merged 4 commits intocrypto-org-chain:developfrom
JayT106:jt/fix-get-tx-receipt

Conversation

@JayT106
Copy link
Copy Markdown

@JayT106 JayT106 commented Mar 2, 2026

Closes: #XXX

Description


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@JayT106 JayT106 requested a review from a team as a code owner March 2, 2026 16:27
@JayT106 JayT106 requested review from randy-cro and thomas-nguy and removed request for a team March 2, 2026 16:27
@github-actions

This comment has been minimized.

@JayT106 JayT106 changed the title fix(rpc): Missing boundary check fix(rpc): Missing boundary check in GetTransactionReceipt Mar 2, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 2, 2026

Codecov Report

❌ Patch coverage is 21.87500% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.66%. Comparing base (a55a578) to head (47170d8).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
rpc/backend/tx_info.go 21.87% 17 Missing and 8 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #861      +/-   ##
===========================================
- Coverage    40.69%   40.66%   -0.04%     
===========================================
  Files          190      190              
  Lines        15452    15471      +19     
===========================================
+ Hits          6288     6291       +3     
- Misses        8491     8499       +8     
- Partials       673      681       +8     
Files with missing lines Coverage Δ
rpc/backend/tx_info.go 54.19% <21.87%> (-2.51%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread rpc/backend/tx_info.go Outdated
@songgaoye
Copy link
Copy Markdown

songgaoye commented Mar 4, 2026

I think we should also check other code in tx_info.go like GetTransactionByHash and GetTransactionByBlockAndIndex, they use tx.GetMsgs()[res.MsgIndex] and block.Block.Txs[res.TxIndex] in similar ways.

Comment thread rpc/backend/tx_info.go
@JayT106
Copy link
Copy Markdown
Author

JayT106 commented Mar 4, 2026

I think we should also check other code in tx_info.go like GetTransactionByHash and GetTransactionByBlockAndIndex, they use tx.GetMsgs()[res.MsgIndex] and block.Block.Txs[res.TxIndex] in similar ways.

check added.

@songgaoye songgaoye self-requested a review March 5, 2026 02:18
Copy link
Copy Markdown

@songgaoye songgaoye left a comment

Choose a reason for hiding this comment

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

lgtm

@thomas-nguy thomas-nguy merged commit 351aaba into crypto-org-chain:develop Mar 16, 2026
40 of 43 checks passed
JayT106 added a commit that referenced this pull request Mar 19, 2026
* missing boundary check

* update changelog

* apply checks to other functions

* unity the error log format
thomas-nguy pushed a commit that referenced this pull request Mar 27, 2026
* fix(rpc): Missing boundary check in GetTransactionReceipt (#861)

* missing boundary check

* update changelog

* apply checks to other functions

* unity the error log format

* fix(rpc): scope block receipts when eth tx hash index is overwritten

- Rebuild TxResult from block data when resBlock is set and indexer
  points to a different height (same hash re-included later).
- Prefer indexer when height matches target block for unchanged paths.
- Add unit test proving KV overwrite + eth_getBlockReceipts still
  returns correct blockNumber for the requested block.

Made-with: Cursor

* perf(rpc): eliminate N redundant BlockResults RPC calls in GetBlockReceipts

Pass the already-fetched blockRes from GetBlockReceipts into
GetTransactionReceipt so it is not re-fetched for every transaction
in the block. For a block with N txs this removes N uncached
CometBFT BlockResults RPCs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(lint): break long GetTransactionReceipt signature to satisfy lll

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor(rpc): extract ethMsgAtTxResult helper, split GetTransactionReceipt

Address PR #870 review feedback:
- Extract ethMsgAtTxResult helper to deduplicate decode+bounds-check
  logic across GetTransactionByHash, GetTransactionByBlockAndIndex,
  and GetTransactionReceipt.
- Split GetTransactionReceipt into prepareTransactionReceipt and
  transactionReceiptToJSON for better readability.
- Add txIndex >= len(txResults) bounds check in txResultFromBlockHash.
- Update CHANGELOG to reference PR #870.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* update changelog

* return empty receipt when index height is different to request height

* lint

* revert(rpc): undo ethMsgAtTxResult helper and receipt function split

Revert the structural refactoring from d3cf0a1:
- Remove ethMsgAtTxResult helper; inline decode+bounds-check logic back
  into GetTransactionByHash, GetTransactionByBlockAndIndex, and
  GetTransactionReceipt.
- Merge prepareTransactionReceipt and transactionReceiptToJSON back into
  a single GetTransactionReceipt function.

Functional changes from subsequent commits are preserved:
- txResultFromBlockHash bounds check (txIndex >= len(txResults)).
- Return nil receipt when tx indexer points to a different block height.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* update changelog

* remove txreceipt reconstruct logic when indexer is missing receipt

* cleanup

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
thomas-nguy pushed a commit that referenced this pull request Apr 8, 2026
* fix(rpc): Missing boundary check in GetTransactionReceipt (#861)

* missing boundary check

* update changelog

* apply checks to other functions

* unity the error log format

* fix(rpc): scope block receipts when eth tx hash index is overwritten

- Rebuild TxResult from block data when resBlock is set and indexer
  points to a different height (same hash re-included later).
- Prefer indexer when height matches target block for unchanged paths.
- Add unit test proving KV overwrite + eth_getBlockReceipts still
  returns correct blockNumber for the requested block.

Made-with: Cursor

* perf(rpc): eliminate N redundant BlockResults RPC calls in GetBlockReceipts

Pass the already-fetched blockRes from GetBlockReceipts into
GetTransactionReceipt so it is not re-fetched for every transaction
in the block. For a block with N txs this removes N uncached
CometBFT BlockResults RPCs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(lint): break long GetTransactionReceipt signature to satisfy lll

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor(rpc): extract ethMsgAtTxResult helper, split GetTransactionReceipt

Address PR #870 review feedback:
- Extract ethMsgAtTxResult helper to deduplicate decode+bounds-check
  logic across GetTransactionByHash, GetTransactionByBlockAndIndex,
  and GetTransactionReceipt.
- Split GetTransactionReceipt into prepareTransactionReceipt and
  transactionReceiptToJSON for better readability.
- Add txIndex >= len(txResults) bounds check in txResultFromBlockHash.
- Update CHANGELOG to reference PR #870.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* update changelog

* return empty receipt when index height is different to request height

* lint

* revert(rpc): undo ethMsgAtTxResult helper and receipt function split

Revert the structural refactoring from d3cf0a1:
- Remove ethMsgAtTxResult helper; inline decode+bounds-check logic back
  into GetTransactionByHash, GetTransactionByBlockAndIndex, and
  GetTransactionReceipt.
- Merge prepareTransactionReceipt and transactionReceiptToJSON back into
  a single GetTransactionReceipt function.

Functional changes from subsequent commits are preserved:
- txResultFromBlockHash bounds check (txIndex >= len(txResults)).
- Return nil receipt when tx indexer points to a different block height.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* update changelog

* remove txreceipt reconstruct logic when indexer is missing receipt

* cleanup

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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.

3 participants