Repository navigation
fix: reject non-canonical RLP length encodings - #596
Merged
Merged
Conversation
RLP is defined as a bijection (Yellow Paper, Appendix B): every value has exactly one valid encoding. The decoder previously accepted alternate, non-canonical encodings of the same value: - a single byte < 0x80 wrapped in an explicit one-byte length prefix (e.g. `0x8100` decoding to the same value as the canonical `0x00`) - a long-form length that fits the short form, or that uses more length-bytes than necessary (e.g. `0xb800`, `0xb9000141`) Accepting these means two different byte strings decode to the same value, and decoding then re-encoding a non-canonical input produces different bytes than the input -- a hash/identity malleability issue for any code that hashes or compares raw RLP bytes assuming a 1:1 mapping to decoded values. Adds `Rlp.NonCanonicalError` and validates both cases in `readLength`/`decodeRlpCursor`. Verified against all 14,640 official RLP test vectors (`bun test vectors/src/rlp.vectors.test.ts`) with no regressions, plus new unit tests for the non-canonical cases and the 55/56 and 255/256 byte-count boundaries. Co-authored-by: jxom <jake@tempo.xyz>
Co-authored-by: jxom <jake@tempo.xyz>
Adds NonCanonicalError to the readLength and decodeRlpCursor error unions, updates the AccountSimulation snapshot that now fails at the RLP layer, and tightens the changeset to one sentence. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bc8f-0483-70f9-9462-97c636407bca Co-authored-by: jxom <jake@tempo.xyz>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Contributor
|
Published pnpm add ox@pr-596
pnpm add ox@0.0.0-pr-596-caaff64 |
This was referenced Nov 8, 2026
Merged
This branch had an error being deployed
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.
Supersedes #444 by @gomesalexandre: same fix, rebased onto
main, plus review follow-ups. Their commits are kept with original authorship.Rlp.toBytes/Rlp.toHexnow throwRlp.NonCanonicalErrorinstead of accepting alternate encodings of the same value, matching geth's canonical-size rules (ErrCanonSize):0x80wrapped in a length-1 string prefix (0x8100,0x817f)0xb800,0xb80141,0xf8020102)0xb9000141,0xba0000ff…)Follow-ups on top of #444:
MultisigSimulation.test.tsedit (renamed onmain) and updated the matchingAccountSimulation.test.tssnapshot, which now fails at the RLP layer.NonCanonicalErrorto thereadLengthanddecodeRlpCursorerror unions.Tests:
RLPTests/invalidRLPTest.json:mainaccepts 16/26 invalid vectors, this branch accepts 1/26 (emptyEncoding, the empty0xinput, left for a follow-up).Rlp.test.tscases fail againstmain'sRlp.tsand pass here;bun test vectors/src/rlp.vectors.test.tspasses 14640/14640.tempo-unitpasses;corepasses apart from Anvil/network tests that fail identically on a cleanmainin this environment;tsc -bandvp checkpass.