Repository navigation
fix: decode anonymous event logs in AbiEvent.decodeLog and extractLogs - #564
Conversation
`decodeLog` and `extractLogs` only matched logs by their selector topic, so anonymous event logs were never decoded. An anonymous log carries nothing that identifies its event, so anonymous events are now matched only when requested: every event in the ABI is anonymous, or (for `extractLogs`) `eventName` names the event. A selector match still wins, and a log that fits several anonymous events is not guessed: `decodeLog` throws `AbiEvent.AnonymousEventAmbiguityError` and `extractLogs` skips it. Also add `AbiEvent.fuzz.ts`, with properties over random events (anonymous or not, any ABI type, named, unnamed, or mixed inputs) and random logs: `decode` and `extractLogs` round-trip, `encode` produces the topics a contract emits, `decode` returns or throws an ox error for any log, `decodeLog` decodes a selector match the same way in any ABI, and `extractLogs` matches a model of its matching rules with and without `eventName`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D3nmWga38V3yjkJET3UZeh
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review SummaryThis 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: da652b2780
ℹ️ 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 (!event && !strict) { | ||
| // An anonymous event that fails to decode is not identified, so the | ||
| // non-strict fallback only applies to a signature match. | ||
| if (!event && !strict && items[0]!.anonymous !== true) { |
There was a problem hiding this comment.
Honor non-strict decoding for selected anonymous events
When eventName explicitly selects a single anonymous event, a log with the expected topic count but missing or truncated data is rejected by the initial strict decode, and this condition then suppresses the non-strict fallback solely because the event is anonymous. Consequently, extractLogs(..., { eventName: 'Ping', strict: false }) returns [] instead of the partial arguments that the same strict: false option provides for named events; once the caller has selected an unambiguous anonymous candidate, it should proceed through the existing non-strict path.
Useful? React with 👍 / 👎.
|
Published pnpm add ox@pr-564
pnpm add ox@0.0.0-pr-564-da652b2 |
Port of wevm/viem#5375.
AbiEvent.decodeandencodealready handle anonymous events, butdecodeLogandextractLogsmatch logs only by selector topic, so anonymous logs were never decoded.An anonymous log has no selector topic, so nothing in it identifies the event: any log with the same topic count fits. Matching anonymous events unconditionally would label logs from other contracts in a receipt as the anonymous event. So anonymous events are matched only when they are requested:
decodeLog: when every event in the ABI is anonymous. For a mixed ABI, decode with the event itself throughAbiEvent.decode.extractLogs: wheneventNamenames the event, or every event in the ABI is anonymous.A selector match still wins. A log that fits several anonymous events isn't guessed, because dynamic data can decode as a static type without throwing:
decodeLogthrows the newAbiEvent.AnonymousEventAmbiguityError, andextractLogsskips the log. The non-strict fallback inextractLogsapplies only to a selector match.Also adds
src/core/_test/AbiEvent.fuzz.ts, with properties over random events (anonymous or not, any ABI type, named, unnamed, or mixed inputs) and random logs:decodeandextractLogsdecode the arguments a log was encoded from.encodeproduces the topics a contract emits.decodereturns or throws an ox error for any log.decodeLogdecodes a selector match the same way whatever else the ABI holds.extractLogsmatches a model of its matching rules, with and withouteventName, and doesn't throw in non-strict mode.Against unmodified
main, the 4 anonymous-event properties fail and the 6 compatibility properties pass. Unit tests cover the same cases deterministically.Validation:
FC_NUM_RUNS=2000 pnpm test:fuzz src/core/_test/AbiEvent.fuzz.tspasses (about 17 s). TheAbiEventunit tests pass except the 2networktests, which need anvil (not available locally).pnpm check:typesandvp checkpass.zile examples:checkcouldn't run locally, becausezile devfails in this environment, so CI will check the new TSDoc examples.Backport of
decode/encodeanonymous support to0.x: #565.🤖 Generated with Claude Code
https://claude.ai/code/session_01D3nmWga38V3yjkJET3UZeh