-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Impossible to use modifiers defined in libraries #2467
![:rage4: :rage4:](https://github.githubassets.com/images/icons/emoji/rage4.png)
Comments
Would a modifier placed in a library act as an internal library function and thus be inlined or would be called remotely via delegatecall? |
I was thinking of them as internal. |
Modifiers in libraries are really useful thing. I was working on the state machine library, and function modifiers are good companions to it allowing aspect-oriented applications.
This useful solution is not working for now since there is no way to import modifiers from a library. |
I would like to work on this. Let's take an overall look. From documentation:
There is no way to use modifiers from libraries directly because there is no such objects in EVM. Of course we can translate them to some kind of library functions and then emulate modifiers substitution, but this is not good as different approach and behaviour introduced for "normal modifiers" and "library modifiers". So inlining is the only/best option. Now let's look at the libraries in Solidity. Why not to inline everything? Why we need DELEGATECALL at all? I understand that some gas saving during deployment can be reached, but is it enough? Maybe it is time to introduce a new concept? Here is the first sight proposal:
Could you provide a clear point of view on a way how to resolve this issue? I'm ready to code when you make a decision about implementation approach. |
@limexp thanks! Modifiers work like internal functions, they are just inlined. The first step of this PR is actually enhancing the parser to support fully qualified names in function definitions, i.e. it doesn't accept the dot currently in: |
For modifiers there is no difference if they are defined in a library or in another contract. As I understand the
|
I need a small guidance where is a right place to add tests for this issue? |
There are several ways this issue could be resolved. I am new to this project, so please help to select the best approach according to spirit of ethereum/solidity.
P.S. I personally prefer the most general approach nr.4, or the minimum code change nr.1. |
I just ran into this myself. Kind of shocked they aren't already added into the functionality of the language. Modifiers in libraries definitely enable reusable safety features and I really think this should be added in. |
@limexp i don't mind option 2. |
Be aware that modifiers are polymorphic. If you reference a modifier through a base class name, it should be exactly that modifier. If you reference it through a library, this should be the same. Probably it is best to change This is basically like 3 but a little more generic. |
Comment to show support for this features, especially since it might help contracts that run out of gas during deployment (i.e. - by splitting out code to different contracts). |
@roschler sorry to disappoint you, but I don't see a way how to call modifiers defined in libraries using delegatecall. |
This issue has been marked as stale due to inactivity for the last 90 days. |
Hi everyone! This issue has been automatically closed due to inactivity. |
![:rage4: :rage4:](https://github.githubassets.com/images/icons/emoji/rage4.png)
Modifier invocations only work when the modifier is an identifier. A modifier
m
defined in libraryL
can only be referred to as the member accessL.m
. There's no way to use it.The text was updated successfully, but these errors were encountered: