Skip to content

Infer modifier mutability per most derived contract - #16933

Draft
msooseth wants to merge 2 commits into
fix-view-pure-super-derivedfrom
fix-modifier-mutability-per-contract
Draft

Infer modifier mutability per most derived contract#16933
msooseth wants to merge 2 commits into
fix-view-pure-super-derivedfrom
fix-modifier-mutability-per-contract

Conversation

@msooseth

Copy link
Copy Markdown
Contributor

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

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.
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