Skip to content

Some issues with modifier depth #8842

Open
@haltman-at

Description

@haltman-at

Description

Modifier depth in source maps is difficult to use due to several issues. Mostly these issues take the form of, it stays the same when it shouldn't.

Specifically:

  1. Modifier depth only changes on entering a modifier beyond the first one on a function. (The same applies to base constructors.) Modifier depth does not provide a way to distinguish whether you are in a modifier at all. Ideally, modifier depth would increment to 1 on the first modifier, then 2 on the second; rather than staying at 0 on the first, and then only incrementing to 1 on the second.

  2. Modifier depth works differently with base constructors than with actual modifiers. (I'm not clear how it works if you mix the two.) With actual modifiers, the depth starts at 0, increments on each modifier beyond the first, until you reach the main function body at which point it increments again (rather than resetting to 0); it then decrements as the main function body exits and as each modifier exits (not going below 0, of course).

With base constructors, however... well, I'm unclear. One thing that seems clear is that the modifier depth doesn't go above 1. Another is that it may be 1 even in the main function body? But it's 0 when it's on a constructor declaration. Like it seems basically like it's "1 when in a constructor body, 0 when on a constructor declaration", except that's not always true -- sometimes it's 0 in a constructor body and I don't know why. It seems like having fewer base constructors leads to this, as does invoking those base constructors via an inheritance specifier on the contract rather than invoking it on the constructor. But I'm unclear on the details here.

I'm also not clear with how this interacts if you mix it with actual modifiers on the constructors; it looks like the modifier depth increments separately for each base constructor, except that sometimes it starts at 1 and sometimes it starts at 0? It's quite confusing.

It's not clear how much of this should be changed, to be honest. Doing so could potentially be breaking. (It wouldn't break anything Truffle's doing, I don't think, but it could be.) But ideally everything should work in a consistent manner and useful manner.

Most particularly:

  1. Modifier depth should increment to 1 on the first modifer, not the second; and
  2. Whether base constructors affect the modifier depth should not depend on how many of them there are or how they're invoked.

Beyond that it's hard to say what should be changed, but if those two were changed I could see how workable the result is. I don't know if base constructors vs modifiers really need to be made consistent with each other.

Basically, my real end goal here is to be able to tell when we are entering a given modifier, and the current system isn't much good for that due to the above issues.

Environment

  • Compiler version: 0.6.6
  • Target EVM version (as per compiler settings): default
  • Framework/IDE (e.g. Truffle or Remix): Truffle

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions