internal/ethapi: return InvalidParams for malformed sendRawTransaction RLP - #35129
Open
manusw7 wants to merge 3 commits into
Open
internal/ethapi: return InvalidParams for malformed sendRawTransaction RLP#35129manusw7 wants to merge 3 commits into
manusw7 wants to merge 3 commits into
Conversation
…n RLP SendRawTransaction and SendRawTransactionSync currently return the bare UnmarshalBinary error to the JSON-RPC layer. Because the underlying decode errors don't implement rpc.Error.ErrorCode(), rpc/json.go:errorMessage falls back to errcodeDefault = -32000. Per JSON-RPC 2.0, malformed method parameters should use -32602 (InvalidParams), which is what Reth and Besu emit for the same input. internal/ethapi/errors.go already defines invalidParamsError with ErrorCode() = errCodeInvalidParams. Wire it into the two decode paths and add a parameterised test covering 5 distinct RLP-decode failure shapes against both entry points.
…nsaction_InvalidParams
Contributor
|
IMO we should wait for the dust on error codes on execution-apis repo to settle before making changes. Nothing is decided there afaik. |
Contributor
|
Please remove the tests. |
Author
|
@s1na do you have some updates on how this PR should progress? I think this change is independent of the catalog work in #817. Also right now for RLP/decode errors, there are some incongruences between clients.
Maybe I'm missing some changes discussed in execution-apis repo that will covered the scenario in this PR. |
This was referenced Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SendRawTransactionandSendRawTransactionSyncreturn the bareUnmarshalBinaryerror. Since RLP/decode errors don't implementrpc.Error.ErrorCode(), the dispatcher falls back toerrcodeDefault = -32000. Per JSON-RPC 2.0, malformed params should be-32602.This wires the existing
invalidParamsErrorwrapper (internal/ethapi/errors.go) into both decode paths. Decoder messages pass through unchanged — only the wire code changes.Changes
// internal/ethapi/api.go — SendRawTransaction if err := tx.UnmarshalBinary(input); err != nil { - return common.Hash{}, err + return common.Hash{}, &invalidParamsError{message: err.Error()} } // SendRawTransactionSync — same one-line changeWhy -32602
The
-32000today is a fallback accident, not a deliberate choice. This matches where the spec is heading: execution-apis#817 (fjl: input-validation conditions on submit methods are just "invalid parameters") and #818 (drops the-32000 "Invalid input"group frometh_sendRawTransaction). Reth and Besu already return-32602for RLP-decode failures; geth and Erigon default to-32000.Test plan
Added
TestSendRawTransaction_InvalidParams_OnMalformedRLP(internal/ethapi/api_test.go): 5 decode-failure shapes (0xc0,0xd4,0x09c0,0x03c0,0x04c0) × both methods, assertingErrorCode() == -32602viaerrors.As. All 10 subtests pass.Out of scope
SubmitTransaction, blob conversion): node-state/operational, not param validation —-32000stays.UnmarshalBinaryfrom user-facing JSON-RPC only exists in these two functions.Related