Repository navigation
Fix fromRlp accepting non-canonical RLP - #5506
Closed
gomesalexandre wants to merge 1 commit into
Closed
gomesalexandre wants to merge 1 commit into
gomesalexandre wants to merge 1 commit into
Conversation
`fromRlp` accepted a single byte below `0x80` behind a length prefix and long-form lengths that fit a shorter prefix, so `parseTransaction` and `recoverTransactionAddress` returned the same fields and signer for a malleated payload whose hash differs from the canonical one and which nodes reject. Throw `RlpNonCanonicalError` for both, matching ox's `Rlp.NonCanonicalError` and geth's RLP decoder. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gomesalexandre is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: e43258a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Member
|
Thanks @gomesalexandre! Superseded by #5513, which cherry-picks your commit unchanged (you remain the author) and adds TSDoc to the new error. |
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.
fromRlpdecodes several non-canonical encodings as if they were canonical. A single byte below0x80wrapped in a length prefix (fromRlp('0x8100')returns'0x00'), a short string or list using the long form ('0xb800'returns'0x','0xf800'returns[]), and a long-form length with a leading zero byte ('0xb90038' + '00'.repeat(56)) are all accepted. RLP gives every value exactly one encoding (Yellow Paper, Appendix B), and geth,@ethereumjs/rlpand ox'sRlp.toHexreject all of these.Because
parseTransactiongoes throughfromRlp, viem accepts a malleated transaction that nodes reject. A signed EIP-1559 transfer with its outer list header rewritten fromf8 69tof9 00 69(same payload, against anvil):So viem reports a valid transaction signed by
0xf39F...2266, whilekeccak256of the input differs from the canonical transaction hash and anvil (like geth, whose RLP decoder rejects non-minimal sizes) refuses it. Anything that keys onkeccak256(serializedTransaction)after validating with viem (relayers, dedup, indexers) can be handed a second encoding of the same signed transaction.fromRlpnow throwsRlpNonCanonicalErrorfor a prefixed single byte below0x80and for a long-form length that fits a shorter prefix. These are the same checks ox already makes inRlp.NonCanonicalError. The error class follows the shape ofRlpTrailingBytesErrorfrom #4790. Canonical boundary encodings (0x7f,0x8180, 55 and 56 byte strings, a 256 byte string, a 56 item list) still decode, and the new tests cover both cases, including the malleated transaction throughparseTransaction. This only covers RLP-level encoding: a transaction integer field with leading zero bytes (0x820001for nonce 1) is still valid RLP and is left to a separate change.🤖 Generated with Claude Code