fix(parseEventLogs): normalize RpcLog inputs before decoding#4346
Merged
fix(parseEventLogs): normalize RpcLog inputs before decoding#4346
Conversation
parseEventLogs accepts (Log | RpcLog)[] but never called formatLog on RpcLog entries, causing hex-encoded QUANTITY fields (blockNumber, logIndex, transactionIndex, blockTimestamp) to propagate into the returned Log objects as raw strings instead of bigint/number. This is a runtime type violation: the TypeScript signature promises Log<bigint, number> but the actual values are hex strings when logs come directly from an RPC response (e.g. eth_getLogs). Detect RpcLog inputs via typeof blockNumber === 'string' and normalize them through formatLog before processing. Already-formatted Log inputs pass through unchanged. Fixes wevm#4340
|
@Kropiunig is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 53579db The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Contributor
Author
|
Hi @jxom — pinging for visibility. This PR normalizes |
Amp-Thread-ID: https://ampcode.com/threads/T-019c886f-c262-7006-8da6-f79582ed6449 Co-authored-by: Amp <amp@ampcode.com>
Merged
ajhodges
pushed a commit
to ajhodges/viem
that referenced
this pull request
Mar 4, 2026
* fix(parseEventLogs): normalize RpcLog inputs before decoding parseEventLogs accepts (Log | RpcLog)[] but never called formatLog on RpcLog entries, causing hex-encoded QUANTITY fields (blockNumber, logIndex, transactionIndex, blockTimestamp) to propagate into the returned Log objects as raw strings instead of bigint/number. This is a runtime type violation: the TypeScript signature promises Log<bigint, number> but the actual values are hex strings when logs come directly from an RPC response (e.g. eth_getLogs). Detect RpcLog inputs via typeof blockNumber === 'string' and normalize them through formatLog before processing. Already-formatted Log inputs pass through unchanged. Fixes wevm#4340 * add changeset Amp-Thread-ID: https://ampcode.com/threads/T-019c886f-c262-7006-8da6-f79582ed6449 Co-authored-by: Amp <amp@ampcode.com> --------- Co-authored-by: jxom <7336481+jxom@users.noreply.github.com> Co-authored-by: Amp <amp@ampcode.com>
Merged
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.
Problem
parseEventLogsaccepts(Log | RpcLog)[]in its type signature, but never normalizesRpcLogentries before processing them. When logs come directly from a JSON-RPC response (e.g.eth_getLogs), QUANTITY fields likeblockNumber,logIndex,transactionIndex, andblockTimestampare hex-encoded strings (0x...) per the Ethereum JSON-RPC spec.These raw hex strings propagate into the returned
Logobjects, causing a runtime type violation: the TypeScript signature promisesLog<bigint, number>but consumers receive hex strings at runtime. This can silently break downstream comparisons, arithmetic, and serialization that assumes native types.Reproduction
Solution
Detect
RpcLoginputs viatypeof log.blockNumber === 'string'and normalize them through the existingformatLogutility before decoding. This converts hex-encoded QUANTITY fields to their native types (bigintfor block numbers/timestamps,numberfor indices). Already-formattedLoginputs pass through unchanged.This is the same normalization pattern used throughout viem's action layer (e.g.
getBlock,getTransactionReceipt) but was missing fromparseEventLogs.Changes
src/utils/abi/parseEventLogs.ts: AddedformatLogimport and RpcLog detection/normalization at the start of the.map()callback. All subsequent references use the normalized log.src/utils/abi/parseEventLogs.test.ts: Added test suite covering:RpcLogfields are correctly formatted to native typesLoginputs pass through unchanged (no double-formatting)RpcLogandLoginputs in the same arrayFixes #4340