Repository navigation
Conversation
`fromRlp` decoded a single item via `fromRlpCursor` and returned without
checking that the cursor consumed all input, so any bytes after the first
RLP item were silently dropped.
RLP is a bijection (Ethereum Yellow Paper, Appendix B): a payload encodes
exactly one item with no leftover bytes. geth rejects over-long input with
`rlp: input contains more than one value` and ethers with `unexpected junk
after rlp payload`. viem instead returned a value:
fromRlp('0x80deadbeef','hex') // before: '0x' after: throws
fromRlp('0xc2010203','hex') // before: ['0x01','0x02'] after: throws
fromRlp('0xc000','hex') // before: [] after: throws
Assert in the public `fromRlp` wrapper (not in the `fromRlpCursor`
recursion, so nested lists are unaffected) that the cursor reached the end
of the input. Valid single-item inputs (`0x80`, `0xc0`, nested lists) and
the transaction-decode path (parseTransaction) are unchanged.
Separate root cause from the abi-encode zero-width fix on
fix/abi-encode-zero-width-static-aggregate.
|
@spokodev is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
|
Contributor
Author
|
Sibling PR for a separate root cause: #4777 (abi zero-width static aggregates). |
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
fromRlpdecodes a single item viafromRlpCursor(cursor, to)and returns without asserting that the cursor consumed all input. Any bytes after the first RLP item are silently dropped.RLP is a bijection (Ethereum Yellow Paper, Appendix B): a payload encodes exactly one item, with no leftover bytes. Both geth and ethers reject over-long input; viem instead returns a partial value, which is unsafe in the transaction-decode path (
parseTransaction).Reproduction
Oracle
rlp: input contains more than one valuedecodeRlp:unexpected junk after rlp payloadBoth reject all three inputs above.
Fix
In the public
fromRlpwrapper (not in thefromRlpCursorrecursion, so nested lists are unaffected), after decoding assert that the cursor reached the end of the input, otherwise throw aBaseErrornaming the count of leftover bytes.Valid single-item inputs (
0x80, the empty list0xc0, nested lists0xc1c0, byte strings) keep decoding unchanged, and the fullparseTransactionsuite still passes (well-formed transactions consume all bytes).Added tests cover all three trailing-byte cases plus a control that valid single items still decode.
This is a separate root cause from #4770 (Infinity
recursiveReadLimit/ deep-nesting stack overflow) and from the ABI zero-width encode fix in a sibling PR.