fix: guard formatViemError structuredClone against non-cloneable errors (A-818) - #23919
Merged
spypsy merged 1 commit intoJun 8, 2026
Conversation
…rs (A-818) structuredClone throws DataCloneError on viem error objects that carry non-cloneable fields (e.g. function-valued request context on RPC errors). Because the call was unguarded and runs before the instanceof Error fallback, the formatter itself threw, masking the original L1 revert/RPC error at the call sites that throw formatViemError(...). Wrap the clone in try/catch and fall back to formatting the original error untouched when cloning fails.
PhilWindle
marked this pull request as ready for review
June 7, 2026 18:42
spypsy
approved these changes
Jun 8, 2026
spypsy
deleted the
phil/a-818-audit-163-formatviemerror-uses-structuredclone-on-non
branch
June 8, 2026 08:29
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.
Fixes A-818 (Audit #163).
Problem
formatViemError(yarn-project/ethereum/src/utils.ts) calledstructuredClone(error)unguarded, before theinstanceof Errorformatting fallback.structuredClonethrowsDataCloneErroron values it cannot clone — and viem RPC/contract errors routinely attach plain-object context holding functions (e.g. transport request methods). When that happened, the formatter itself threw, and since several call sites dothrow formatViemError(...)(rollup.ts,l1_tx_utils.ts), the original L1 revert/RPC error was replaced by aDataCloneErrorand lost — degrading operator diagnostics.Fix
Wrap the clone (and the
stripAbiscall that depends on it) in atry/catch. On clone failure, fall back to formatting the original error untouched (skippingstripAbisso we don't mutate the caller's object). Thecausestill carries the original error in all paths.Test
Added a
formatViemErrortest inutils.test.tscovering an error whosecauseholds a function-valuedrequestfield. It throwsDataCloneErrorwithout the fix and returns aFormattedViemError(preserving the message andcause) with it.