Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

name and symbol as immutable in ERC20 / ERC721 #2958

Closed
gnarvaja opened this issue Nov 9, 2021 · 2 comments
Closed

name and symbol as immutable in ERC20 / ERC721 #2958

gnarvaja opened this issue Nov 9, 2021 · 2 comments

Comments

@gnarvaja
Copy link

gnarvaja commented Nov 9, 2021

馃摑 Details
I think immutable attributes should be used much more in OZ contracts for attributes that aren't meant to be changed. One example is _name and _symbol in ERC20 / ERC721.

Using immutable is much more clear from a semantic point of view, making clear those attributes are set in the constructor and don't change anymore.

Also, my understanding is immutable attributes are better than storage ones in terms of gas consumption.

@Amxx
Copy link
Collaborator

Amxx commented Nov 10, 2021

Hello @gnarvaja

You are right in saying that making name and symbol immutable would somehow be cleaner. There are however many reasons we don't do it.

  • We don't expect these variables to be read by other contracts, so the storage read cost is small.
  • Making immutable would change the storage layout, and cause issues when upgrading from current implementations.
  • Strings are non-value type, and CANNOT be marked as immutable. We could store them as bytes32, and cast that to string, but that would be messy and would lose generality as it would limit the length to 31 bytes.

@gnarvaja
Copy link
Author

Thanks, very clear your answer.

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

No branches or pull requests

2 participants