VIP: Add private
Visibility
#4400
Labels
VIP: Discussion
Used to denote VIPs and more complex issues that are waiting discussion in a meeting
private
Visibility
#4400
Simple Summary
Support
private
visibility for functions, state variables as well asconstant
s andimmutable
s to restrict access exclusively to the declaring contract.Motivation
Adding
private
visibility for functions and state variables reinforces the principle of encapsulation within a module contract. Ok cool, but what does this exactly mean? Well, it prevents importing contracts (e.g. a contract using and implementing snekmate'serc20
contract) from directly altering critical variables (e.g.balances
orallowances
), safeguarding against unintended or harmful changes by the main contract implementoooor. By exposing controlled access through e.g. getters or internal setters when modification is appropriate, the module can retain both security and flexibility in this way. All these features are important to library writers.Something like that is currently possible:
Specification
Add the
private
visibility to state variable,immutable
,constant
definitions as well as to function declarations:Backwards Compatibility
This VIP introduces a new visibility decorator that is unavailable in older versions, making it inherently backward-incompatible.
Dependencies
N/A.
References
N/A.
Copyright
Copyright and related rights waived via CC0.
The text was updated successfully, but these errors were encountered: