fix(evm/rpc): prevent panic and fallback null responses in GetTransactionReceipt - #42
fix(evm/rpc): prevent panic and fallback null responses in GetTransactionReceipt#42heejekim12 wants to merge 1 commit into
Conversation
|
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 |
There was a problem hiding this comment.
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/MsgIndexaccess 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
GetTransactionByHashreturns an error whenres.MsgIndexis out of range. Foreth_getTransactionByHash, treating this as “not found” (returningnil, 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.
| if int(res.TxIndex) >= len(block.Block.Txs) { | ||
| return nil, errors.New("tx index out of range") | ||
| } |
| // 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) | ||
| } |
|
@maxim-inj Thank you for responding. Please update testnet binary source code and tagging. |
Summary
This PR addresses several critical issues in the eth_getTransactionReceipt RPC method where calls frequently returned "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
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.
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.