Skip to content

fix(evm/rpc): prevent panic and fallback null responses in GetTransactionReceipt - #42

Open
heejekim12 wants to merge 1 commit into
InjectiveFoundation:release/v1.20.xfrom
heejekim12:tx_info
Open

fix(evm/rpc): prevent panic and fallback null responses in GetTransactionReceipt#42
heejekim12 wants to merge 1 commit into
InjectiveFoundation:release/v1.20.xfrom
heejekim12:tx_info

Conversation

@heejekim12

@heejekim12 heejekim12 commented Jul 23, 2026

Copy link
Copy Markdown

Summary
This PR addresses several critical issues in the eth_getTransactionReceipt RPC method where calls frequently returned "result": null.

curl --location https://injectiveevm-testnet-rpc.polkachu.com \
--header 'Content-Type: application/json' \
--data '{
  "jsonrpc": "2.0",
  "method": "eth_getTransactionReceipt",
  "params": [
    "0x655d4fe0c8a06ea59b9e02cea4b9b5d245c26b6c30ce2d984f89b907bbccc011"
  ],
  "id": 1
}'

{"jsonrpc":"2.0","id":1,"result":null}

By improving array index bounds checking, adding error absorption during log decoding, enabling dynamic EVM index fallback, and enriching log metadata, this change enhances overall RPC stability and ensures full compliance with the standard Ethereum JSON-RPC specification.

Key Improvements & Fixes

  1. Runtime Panic Prevention (Slice Out-of-Bounds Fix)
  • Problem: Slicing blockRes.TxResults[0:res.TxIndex] directly caused index out of range panics when the number of TxResults in Tendermint was smaller than res.TxIndex.

  • Fix: Introduced pre-checks and capped maxTxIndex against len(blockRes.TxResults) to guarantee safe slice access during cumulativeGasUsed calculation.

  1. Graceful Handling of Log Decoding Failures
  • Problem: When evmtypes.DecodeMsgLogs(...) failed due to malformed or incompatible Cosmos-SDK event logs, the error escalated immediately, aborting the entire request and returning null.

  • Fix: Wrapped log decoding in an error-absorption block. Decoding failures are now safely logged as warnings, falling back to empty logs (logs: []) so that the core receipt payload is still returned successfully.

  1. Complete Log Metadata Injection
  • Problem: Successfully decoded log objects lacked critical Ethereum metadata fields (blockHash, txHash, txIndex, logIndex).
  • Fix: Explicitly populated missing metadata fields onto each log object prior to constructing the final response payload.
  1. Automatic EVM Index Recovery Fallback
  • Problem: If the indexer DB failed to record EthTxIndex in time (EthTxIndex == -1), the call was aborted early with an error.
  • Fix: Added a fallback mechanism (EthMsgsFromTendermintBlock) that dynamically inspects the block to recover the correct EVM transaction index on the fly.
  1. Strict RPC Spec Alignment (contractAddress)
  • Problem: Standard non-contract creation transactions omitted the contractAddress key entirely from the JSON response.
  • Fix: Refactored payload construction to explicitly output "contractAddress": null when no contract is deployed, matching standard Ethereum JSON-RPC behavior.

@maxim-inj

maxim-inj commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Hello, thanks for your contribution. I should note however that we are deprecating the built-in evm indexer, it's only for development purposes and not supported for production usage.

Please check https://github.com/InjectiveLabs/evm-gateway for the new way of serving the EVM endpoint backed by a node.

P.s. I will try to assess these improvements over evm-gateway, as it copied most of the old code..

@maxim-inj maxim-inj self-assigned this Jul 23, 2026
@maxim-inj maxim-inj added the bug Something isn't working label Jul 23, 2026
@maxim-inj
maxim-inj requested a review from Copilot July 23, 2026 15:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the EVM JSON-RPC transaction lookup path—especially eth_getTransactionReceipt—to avoid panics and reduce result: null responses by adding bounds checks, introducing indexer fallbacks, and improving receipt/log formatting.

Changes:

  • Added defensive bounds checks for TxIndex/MsgIndex access when decoding transactions and receipts.
  • Implemented fallback behavior when the EVM index (EthTxIndex) is missing and made log decoding failures non-fatal.
  • Enriched receipt output to better match Ethereum JSON-RPC conventions (e.g., contractAddress: null, log metadata population).
Comments suppressed due to low confidence (1)

injective-chain/modules/evm/rpc/backend/tx_info.go:71

  • GetTransactionByHash returns an error when res.MsgIndex is out of range. For eth_getTransactionByHash, treating this as “not found” (returning nil, nil) is usually preferable to returning a JSON-RPC error due to indexer/event inconsistencies.
	msgs := tx.GetMsgs()
	if int(res.MsgIndex) >= len(msgs) {
		return nil, errors.New("msg index out of range")
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +59 to +61
if int(res.TxIndex) >= len(block.Block.Txs) {
return nil, errors.New("tx index out of range")
}
Comment on lines +265 to +271
// Enrich log fields (blockHash, transactionHash, transactionIndex, etc.)
for i, log := range logs {
log.BlockHash = blockHash
log.TxHash = hash
log.TxIndex = uint(res.EthTxIndex)
log.Index = uint(i)
}
@heejekim12

Copy link
Copy Markdown
Author

@maxim-inj Thank you for responding. Please update testnet binary source code and tagging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants