fix: handle ternary expressions in state variable initializers#2974
Open
ep0chzer0 wants to merge 2 commits intocrytic:masterfrom
Open
fix: handle ternary expressions in state variable initializers#2974ep0chzer0 wants to merge 2 commits intocrytic:masterfrom
ep0chzer0 wants to merge 2 commits intocrytic:masterfrom
Conversation
State variable initializers are processed outside the normal function parsing pipeline via synthetic CONSTRUCTOR_VARIABLES functions. These synthetic functions were not going through _rewrite_ternary_as_if_else, causing ConditionalExpressions to reach SlithIR conversion unsplit, resulting in SlithIRError. Add _rewrite_ternary_in_constructor_variables to Contract that performs the equivalent IF/EXPRESSION/ENDIF node splitting for constructor variable nodes, called after node creation in add_constructor_variables. Fixes crytic#2836 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
e7f8721 to
82950eb
Compare
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
SlithIRError: Ternary operator are not convertible to SlithIRwhen ternary expressions are used in state variable initializersCONSTRUCTOR_VARIABLESfunctions created inadd_constructor_variables(), which runs after the normal function parsing pipeline. These synthetic functions never go through_rewrite_ternary_as_if_else(), soConditionalExpressionnodes reach SlithIR conversion unsplit_rewrite_ternary_in_constructor_variables()toContractthat performs the equivalent IF/EXPRESSION/ENDIF node splitting for constructor variable nodes, called after all nodes are created inadd_constructor_variables()Reproduction case (from issue)
Before this fix, analyzing contract B would crash with:
Test plan
test_ternary_in_state_variable_initializerverifies parsing succeeds🤖 Generated with Claude Code