Skip to content

Yul: dump source/target stacks when findStackTooDeep aborts#16705

Open
msooseth wants to merge 1 commit into
argotorg:developfrom
msooseth:dump-shuffle-failure
Open

Yul: dump source/target stacks when findStackTooDeep aborts#16705
msooseth wants to merge 1 commit into
argotorg:developfrom
msooseth:dump-shuffle-failure

Conversation

@msooseth
Copy link
Copy Markdown
Contributor

@msooseth msooseth commented May 12, 2026

Add an opt-in debug dump for the case described in #16704: when findStackTooDeep propagates a YulAssertion from createStackLayout (e.g. "Could not create stack layout after 1000 iterations"), the source and target stacks at that point are otherwise opaque to anyone debugging from a user-supplied .sol reproducer.

When the environment variable YUL_DEBUG_DUMP_SHUFFLE_FAILURE is set to a non-empty value, the source and target stacks (rendered via the existing stackToString(Stack, Dialect) helper) are printed to stderr in the StackShufflingTest .stack format (see test/libyul/yulStackShuffling/*.stack), so the failing input can be dropped into the test suite verbatim. Example:

// findStackTooDeep aborted (source.size=1, target.size=1237)
[ RET ]
[ RET RET[fun_double_27] RET[fun_double_27] ... ]
// ====
// maximumStackDepth: 16

Mechanically:

  • findStackTooDeep gains a Dialect const& parameter (needed by stackToString for resolving function names in RET[...] / TMP[...] slots). All four call sites already have m_evmDialect available and pass it through.
  • The ::createStackLayout invocation is wrapped in a try / catch (YulAssertion const&) that does the conditional stderr print and then throw;s — so when the env var is unset, behavior is byte-identical to before.

No Changelog entry: this is a developer-only debug aid and doesn't change any user-visible behavior.

Refs #16704.

Add an opt-in debug dump for the case described in
argotorg#16704: when `findStackTooDeep` propagates a
`YulAssertion` from `createStackLayout` (e.g. "Could not create stack
layout after 1000 iterations"), the source and target stacks at that
point are otherwise opaque to anyone debugging from a user-supplied
.sol reproducer.

When the environment variable `YUL_DEBUG_DUMP_SHUFFLE_FAILURE` is set
to a non-empty value, the source and target stacks (rendered via the
existing `stackToString(Stack, Dialect)` helper) are printed to stderr
in the StackShufflingTest `.stack` format (see
test/libyul/yulStackShuffling/*.stack), so the failing input can be
dropped into the test suite verbatim. Example:

    // findStackTooDeep aborted (source.size=1, target.size=1237)
    [ RET ]
    [ RET RET[fun_double_27] RET[fun_double_27] ... ]
    // ====
    // maximumStackDepth: 16

Mechanically:

* `findStackTooDeep` gains a `Dialect const&` parameter (needed by
  `stackToString` for resolving function names in `RET[...]` /
  `TMP[...]` slots). All four call sites already have `m_evmDialect`
  available and pass it through.
* The `::createStackLayout` invocation is wrapped in a `try` /
  `catch (YulAssertion const&)` that does the conditional stderr
  print and then `throw;`s -- so when the env var is unset, behavior
  is byte-identical to before.

No Changelog entry: this is a developer-only debug aid and doesn't
change any user-visible behavior.
@msooseth msooseth force-pushed the dump-shuffle-failure branch from d4b4c10 to 11214b1 Compare May 12, 2026 09:50
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.

1 participant