Infer modifier mutability per most derived contract - #16933
Draft
msooseth wants to merge 2 commits into
Draft
Conversation
The view/pure checker validated a function body only against the bases visible from the contract that declares it. But both `super` lookups and virtual modifier lookups are re-resolved per most-derived contract, so an inherited `pure`/`view` function could silently reach a more mutable target. For example, `B.f` declared `pure` type-checks against `A.f`, yet under the linearization `[D, B, X, A]` its `super.f()` resolves to the storage-writing `X.f`; likewise a `pure` function using a virtual modifier that a derived contract overrides with a storage-writing one passed unnoticed. `ViewPureChecker` now builds a map from each contract to the contracts that inherit it, and for every `super` function call and every modifier invocation re-resolves the target in each derived contract, reporting the new errors 7898 and 1614 when the resolved target is more mutable than the enclosing function. Three SMT checker modifier-overriding tests relied on the previously accepted behaviour and drop the now-invalid `view` marker from the affected functions.
A super call in a modifier body resolves over the most derived contract's linearization, so the mutability of such a modifier belongs to the (modifier, contract) pair rather than to the modifier alone. Key the inference cache on both and track the contract while inferring. The derived mutability now also feeds the best-mutability tracker, so the compiler no longer suggests restricting a function to a mutability the check would reject. Subsumes the modifier override case, which is the same comparison, so error 1614 loses its override-specific wording.
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.
A super call in a modifier body resolves over the most derived contract's
linearization, so the mutability of such a modifier belongs to the
(modifier, contract) pair rather than to the modifier alone. Key the
inference cache on both and track the contract while inferring.
Subsumes the modifier override case, which is the same comparison, so
error 1614 loses its override-specific wording.
Stacked on
#16932
Fixes
#16931