Repository navigation
fix(AbiEvent): range-check narrow indexed int and bytes args in encode - #588
Conversation
Co-authored-by: jxom <jake@tempo.xyz>
…meters.encode Co-authored-by: jxom <jake@tempo.xyz>
…lower bound Amp-Thread-ID: https://ampcode.com/threads/T-01a1bc8e-d1c9-702d-86cc-68140700196a 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e5ba48e9ab
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (type !== 'bytes32' || Hex.size(value as Hex.Hex) !== 32) | ||
| return undefined | ||
| return value as Hex.Hex |
There was a problem hiding this comment.
Require exactly 64 hex digits before returning a bytes32 topic
For an indexed bytes32 argument containing 63 hex digits (for example, '0x' + '1'.repeat(63)), Hex.size rounds up to 32, so this fast path returns the odd-length value unchanged. Previously, Hex.padRight(value, 32) padded it to a complete 64-digit topic. This introduces malformed filter topics that JSON-RPC nodes can reject instead of preserving the previous encoding. Check the exact string length before returning directly, or retain the padding step.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed: a 63-digit bytes32 came back unpadded. Fixed in 3ea4b04. The fast path now requires exactly 66 characters, so odd-length values go through AbiParameters.encode and are padded to 64 digits, as on main. Added behavior: odd-length indexed bytes32 arg, which fails without the fix.
…ng them as is Amp-Thread-ID: https://ampcode.com/threads/T-01a1bc8e-d1c9-702d-86cc-68140700196a Co-authored-by: jxom <jake@tempo.xyz>
|
Published pnpm add ox@pr-588
pnpm add ox@0.0.0-pr-588-3ea4b04 |
Supersedes #502 by @watarus. Their two commits are kept as authored. A follow-up commit reworks the test.
AbiEvent.encodedidn't check the declared width of indexedintN/uintN(N < 256) orbytesNarguments. TheencodePrimitiveTopicfast path wrote every integer as a 32-byte word and right-padded everybytesN. As a result, values likeint8 128,int8 -129,uint8 256,bytes4 0x0102030405and a 31-bytebytes32turned into filter topics that no log can ever match, sogetLogsquietly returned nothing.The fast path now covers only
int256/uint256andbytes32values that are exactly 32 bytes. Every other value goes throughAbiParameters.encode, which already range-checks integers and size-checksbytesN. In-range values encode the same as before.Changes to #502:
toThrowErrorMatchingInlineSnapshotundererror: …names, and the in-range snapshot is its ownbehavior:test.int8 -129), a too-shortbytes4, and in-range values at both bounds (int8 -128/127,uint8 0/255).The
0.xline never had the fast path, so it already validates these values. #589 pins that behavior there with the same tests.Checks
main'sAbiEvent.ts, the two newerror:tests fail, and they pass with this change.AbiEvent.test.tsandAbiParameters.test.ts: 127 passed. Onlybehavior: networkwas excluded locally because it needs Anvil.AbiEvent.fuzz.tsatFC_NUM_RUNS=1000,pnpm check:typesandvp checkon the changed files all pass.