Skip to content

fix: decode anonymous event logs - #5374

Closed
mortezashojaei wants to merge 2 commits into
wevm:mainfrom
mortezashojaei:fix/decode-anonymous-event-logs
Closed

mortezashojaei wants to merge 2 commits into
wevm:mainfrom
mortezashojaei:fix/decode-anonymous-event-logs

Conversation

@mortezashojaei

Copy link
Copy Markdown
Contributor

encodeEventTopics already omits the signature topic for anonymous events (#4613). decodeEventLog and parseEventLogs still treat topics[0] as that signature, so getLogs and watchEvent drop the logs (or decodeEventLog throws AbiEventSignatureNotFoundError for the first indexed argument).

Anonymous logs are decoded by using every topic as an indexed argument. A normal event signature still wins when the log has one. Several anonymous events with the same indexed arity are not guessed, because a dynamic payload can decode as a static type without throwing (string data reads as uint256 32). Pass eventName in that case (AbiEventAmbiguityError). parseEventLogs leaves that log out until eventName narrows it to one event.

Indexed string and bytes filters count every anonymous topic. The non-strict fallback does not invent an anonymous event when strict decoding fails.

pnpm exec vitest -c ./test/vitest.config.ts --run --project core \
  src/utils/abi/decodeEventLog.test.ts \
  src/utils/abi/parseEventLogs.test.ts \
  src/utils/abi/encodeEventTopics.test.ts \
  src/index.test.ts

95 event-log tests passed, plus the export snapshot. pnpm exec tsc -b passed.

Test plan

  • Anonymous log with an indexed address and non-indexed string decodes
  • Indexed-only anonymous log (data: 0x) and data-only anonymous log (topics: [])
  • Leading non-indexed argument, so the indexed value is not assumed to be input 0
  • Indexed string filter matches on the only topic (previously dropped by topics.length - 1)
  • Indexed and non-indexed bytes filters ignore hex case
  • Unnamed anonymous arguments
  • A normal event in the same ABI still matches its signature topic
  • Same indexed arity without eventName throws / is omitted; eventName selects the event
  • Non-strict mode does not fabricate an anonymous event for a log that fails to decode
  • Existing encodeEventTopics anonymous tests still pass

@vercel

vercel Bot commented Nov 1, 2026

Copy link
Copy Markdown

@mortezashojaei is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6ee966c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

jxom commented Nov 2, 2026

Copy link
Copy Markdown
Member

Thanks @mortezashojaei! Closing in favor of #5375, which keeps both of your commits and adds one on top.

The follow-up matches anonymous events only when they are requested: eventName names the event, or every event in abi is anonymous. Without that, an ABI that already holds an anonymous event (such as DSNote's LogNote) claimed unrelated logs from other contracts in a receipt whenever the topic count matched. A log carries nothing that rules that out.


Generated by Claude Code

This branch was successfully deployed

1 active deployment
Preview — 6ee966c1 Deployed Nov 2, 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.

2 participants