Skip to content

Report error instead of ICE for deeply nested constant chains#16576

Open
tavian-dev wants to merge 1 commit intoargotorg:developfrom
tavian-dev:fix/deep-constant-chain-ice
Open

Report error instead of ICE for deeply nested constant chains#16576
tavian-dev wants to merge 1 commit intoargotorg:developfrom
tavian-dev:fix/deep-constant-chain-ice

Conversation

@tavian-dev
Copy link
Copy Markdown

Summary

Fixes #15739.

When inline assembly references a constant variable that sits at the end of a chain deeper than 256 levels, isConstantVariableRecursive would trigger a solAssert (ICE: "Recursion depth limit reached"). This replaces the assertion with graceful handling: when the depth limit is reached, the variable is signaled as cyclic so the caller reports a proper TypeError 3558: Constant variable is circular. instead of crashing.

Change

In libsolidity/ast/ASTUtils.cpp, the isConstantVariableRecursive visitor's solAssert(_depth < 256) is replaced with:

if (_depth >= 256)
{
    // Signal as cyclic so callers report a proper error instead of an ICE.
    _cycleDetector.run(_variable);
    return;
}

When depth reaches 256, calling _cycleDetector.run(_variable) on the currently-being-processed variable triggers cycle detection (the variable is already in the processing set), causing isConstantVariableRecursive to return true. The TypeChecker then reports the standard "Constant variable is circular" error.

Test plan

  • Added syntax test inlineAssembly/deep_constant_chain_err.sol with a 257-variable constant chain that previously triggered the ICE
  • All 193 inline assembly syntax tests pass
  • All 3552 syntax tests pass
  • All 1637 semantic tests pass
  • Full build + style check pass locally

When inline assembly references a constant variable at the end of
a chain deeper than 256 levels, isConstantVariableRecursive would
trigger a solAssert (ICE). Replace the assertion with graceful
handling: treat excessively deep chains as cyclic so the caller
reports "Constant variable is circular" instead of crashing.

Fixes argotorg#15739.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

Thank you for your contribution to the Solidity compiler! A team member will follow up shortly.

If you haven't read our contributing guidelines and our review checklist before, please do it now, this makes the reviewing process and accepting your contribution smoother.

If you have any questions or need our help, feel free to post them in the PR or talk to us directly on the #solidity-dev channel on Matrix.

Copy link
Copy Markdown
Contributor

@nikola-matic nikola-matic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a changelog entry (you can add it as a separate commit), but looks good otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE when inline assembly references a variable that shadows a contract and is nested >256 levels deep

2 participants