-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Improve encapsulation in the Heritable contract #692
Comments
Should the getters be accessible only to the owner of the contract, or should they be publicly accessible? |
The getter should be public, imo. |
Reducing the public API of the contracts minimizes the number of guarantees we have to make to the code using our contract (thus reducing the places where we have to watch out for compatibility issues), giving us more freedom to change -private- implementation details. Also, being a framework focused on security, it makes sense to try and avoid having developers extending a contract in an unintended way. But to be honest, I'm not sure making members private provides you that much safety in the face of a inheriting contracts making an unintended use. Explicitly overriding a method/variable is a conscious decision. I guess it makes sense if you add logic to the setter to check an invariant. The cost you pay is extendability. We are restricting the library only to the intended use cases, i.e. the ones we can imagine right now. IMHO, given OZ is an open source library, if there's doubts about the appropiate visibility, we should choose the less strict approach if we want to promote people using and extending OZ. This way we wont promote people copy-pasting a contract just because they had a slightly different use case we couldn't think of.
@ajsantander what do you think? |
* Modified Gitignore for Sublime * Added getter functions for public variables * Added encapsulation to Heritable public variables. * Added encapsulation to Heritable public variables. * Added encapsulation to Heritable public variables. * Updated tests to use getter methods instead of, now, private variables. * Conformed variable names to current conventions. * Requested changes * revert package-lock.json changes
Fixed in #702. |
We agree that there's a trade-off between extensibility and security.
Yeah, in fact, this is aligned with the reasoning behind this issue. In this case it was not checking an invariant that we wanted to enforce, but emitting the event
I disagree with this as an argument, because we aim to provide APIs which are hard to use insecurely. This includes external APIs, as well as internal APIs for contracts that extend via inheritance. If one of our contracts has a There is still something a little bit weird: a contract could override the |
I definitely see where you're going with this and I share a similar concern. I think that we want to promote people extending OZ in secure ways, and we have to set the library up for being securely extended. I hope the reasoning was made clearer now. Let me know if you have any other thoughts about it. :-) |
* Modified Gitignore for Sublime * Added getter functions for public variables * Added encapsulation to Heritable public variables. * Added encapsulation to Heritable public variables. * Added encapsulation to Heritable public variables. * Updated tests to use getter methods instead of, now, private variables. * Conformed variable names to current conventions. * Requested changes * revert package-lock.json changes
heir
is public and has a settersetHeir
Since we are providing a setter, we should also provide a getter and make
heir
private. It ensures that inheriting contracts cannot modify theheir
in an unintended way.This is a general practice we are starting to adopt in all OpenZeppelin, i.e. more extensive use of private contract variables.
We may want to consider this for
heartbeatTimeout
andtimeOfDeath
as well.@azavalla something that might interest you?
The text was updated successfully, but these errors were encountered: