Skip to content

fix: guard formatViemError structuredClone against non-cloneable errors (A-818) - #23919

Merged
spypsy merged 1 commit into
merge-train/spartan-v5from
phil/a-818-audit-163-formatviemerror-uses-structuredclone-on-non
Jun 8, 2026
Merged

fix: guard formatViemError structuredClone against non-cloneable errors (A-818)#23919
spypsy merged 1 commit into
merge-train/spartan-v5from
phil/a-818-audit-163-formatviemerror-uses-structuredclone-on-non

Conversation

@PhilWindle

Copy link
Copy Markdown
Contributor

Fixes A-818 (Audit #163).

Problem

formatViemError (yarn-project/ethereum/src/utils.ts) called structuredClone(error) unguarded, before the instanceof Error formatting fallback. structuredClone throws DataCloneError on 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 do throw formatViemError(...) (rollup.ts, l1_tx_utils.ts), the original L1 revert/RPC error was replaced by a DataCloneError and lost — degrading operator diagnostics.

Fix

Wrap the clone (and the stripAbis call that depends on it) in a try/catch. On clone failure, fall back to formatting the original error untouched (skipping stripAbis so we don't mutate the caller's object). The cause still carries the original error in all paths.

Test

Added a formatViemError test in utils.test.ts covering an error whose cause holds a function-valued request field. It throws DataCloneError without the fix and returns a FormattedViemError (preserving the message and cause) with it.

…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 PhilWindle added the ci-draft Run CI on draft PRs. label Jun 6, 2026
@PhilWindle
PhilWindle marked this pull request as ready for review June 7, 2026 18:42
@spypsy
spypsy merged commit 2cd0ffe into merge-train/spartan-v5 Jun 8, 2026
31 checks passed
@spypsy
spypsy deleted the phil/a-818-audit-163-formatviemerror-uses-structuredclone-on-non branch June 8, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-draft Run CI on draft PRs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants