Report error instead of ICE for deeply nested constant chains#16576
Open
tavian-dev wants to merge 1 commit intoargotorg:developfrom
Open
Report error instead of ICE for deeply nested constant chains#16576tavian-dev wants to merge 1 commit intoargotorg:developfrom
tavian-dev wants to merge 1 commit intoargotorg:developfrom
Conversation
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.
|
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. |
nikola-matic
reviewed
Apr 8, 2026
Contributor
nikola-matic
left a comment
There was a problem hiding this comment.
This needs a changelog entry (you can add it as a separate commit), but looks good otherwise.
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.
Summary
Fixes #15739.
When inline assembly references a constant variable that sits at the end of a chain deeper than 256 levels,
isConstantVariableRecursivewould trigger asolAssert(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 properTypeError 3558: Constant variable is circular.instead of crashing.Change
In
libsolidity/ast/ASTUtils.cpp, theisConstantVariableRecursivevisitor'ssolAssert(_depth < 256)is replaced with: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), causingisConstantVariableRecursiveto returntrue. The TypeChecker then reports the standard "Constant variable is circular" error.Test plan
inlineAssembly/deep_constant_chain_err.solwith a 257-variable constant chain that previously triggered the ICE