Skip to content

fix(AbiEvent): range-check narrow indexed int and bytes args in encode - #588

Merged
jxom merged 4 commits into
mainfrom
fix/abi-event-topic-range
Nov 8, 2026
Merged

jxom merged 4 commits into
mainfrom
fix/abi-event-topic-range

Conversation

@jxom

@jxom jxom commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Supersedes #502 by @watarus. Their two commits are kept as authored. A follow-up commit reworks the test.

AbiEvent.encode didn't check the declared width of indexed intN/uintN (N < 256) or bytesN arguments. The encodePrimitiveTopic fast path wrote every integer as a 32-byte word and right-padded every bytesN. As a result, values like int8 128, int8 -129, uint8 256, bytes4 0x0102030405 and a 31-byte bytes32 turned into filter topics that no log can ever match, so getLogs quietly returned nothing.

The fast path now covers only int256/uint256 and bytes32 values that are exactly 32 bytes. Every other value goes through AbiParameters.encode, which already range-checks integers and size-checks bytesN. In-range values encode the same as before.

Changes to #502:

  • The tests now follow the file's conventions. Errors are asserted with toThrowErrorMatchingInlineSnapshot under error: … names, and the in-range snapshot is its own behavior: test.
  • Added the signed lower bound (int8 -129), a too-short bytes4, and in-range values at both bounds (int8 -128/127, uint8 0/255).

The 0.x line never had the fast path, so it already validates these values. #589 pins that behavior there with the same tests.

Checks

  • On main's AbiEvent.ts, the two new error: tests fail, and they pass with this change.
  • AbiEvent.test.ts and AbiParameters.test.ts: 127 passed. Only behavior: network was excluded locally because it needs Anvil.
  • AbiEvent.fuzz.ts at FC_NUM_RUNS=1000, pnpm check:types and vp check on the changed files all pass.

@vercel

vercel Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ox Error Error Nov 8, 2026 7:57pm UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T19:56:01.809743Z 3ea4b04 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/core/AbiEvent.ts Outdated
Comment on lines +69 to +71
if (type !== 'bytes32' || Hex.size(value as Hex.Hex) !== 32)
return undefined
return value as Hex.Hex

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Published ox@0.0.0-pr-588-3ea4b04 under the pr-588 dist-tag, which follows this pull request until it closes.

pnpm add ox@pr-588
pnpm add ox@0.0.0-pr-588-3ea4b04

@jxom
jxom merged commit 816729d into main Nov 8, 2026
15 of 16 checks passed
@jxom
jxom deleted the fix/abi-event-topic-range branch November 8, 2026 20:04
@github-actions github-actions Bot mentioned this pull request Nov 8, 2026

This branch had an error being deployed

1 failed deployment
Preview — 3ea4b043 Deployed Nov 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants