-
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
ERC721: static call for ownerOf function #2784
Comments
Please see #2154 for extensive prior discussion, in particular #2154 (comment):
The reason it's built this way is that it's otherwise impossible for us to assure internal consistency of our contract if
Can you please give detail about this? |
I agree that providing this power is useful. And at the same time, of course, we are making a risk of somebody doing something wrong. Maybe a nice way to handle this is to provide "subclassing" notes everywhere we allow subclassing. A good example of developer subclassing notes for an object-oriented language is the documentation for Swift. Please search the web with Of course. I sent detail to you by email. I can create a new issue for that when needed. |
Closing this issue for reasons explained in my previous comment: "The burden of guaranteeing internal consistency [when ownerOf is overriden] is moved to the developer who wishes to override in these niche cases." The specific case of |
I came upon this issue when dealing with the following: I'd like to have an ERC721 contract where initially a fixed number (100+) of tokens are assigned to the contract owner. To do this in a gas-efficient way, the idea is to override Now this does not work because the OZC What's the purpose of making |
@matthiasgeihs Thank you for checking in. There are some implementations you can study which are doing that approach:
You can use both of those ideas while still employing OpenZeppelin Contracts, it's just nice to see how others have done it. Specifically regarding OZC and your proposed implementation, please ensure you are testing that If you would like to review your work together live, you can join my weekly call, please see https://phor.net/#hour, follow, and add yourself into the schedule. Based on what we learn, if we find anything that affects OZC and specifically the |
@matthiasgeihs For efficient batch minting please see our new ERC721Consecutive contract. It is included in 4.8, to be released next week, but already available in a release candidate. It will allow you to mint 100+ tokens in the constructor. |
Looks good. Thank you @frangio for restricting it to the constructor not just documenting that caveat! |
In the ERC721 contract, the
ownerOf
function is defined asvirtual
which allows implementations to change this function.But invocations of this function do NOT call with virtual dispatch (i.e. they use
ERC721.ownerOf
).This creates the possibility somebody will override it and it will stop working.
Proposed solutions:
virtual
—because the ownership is tightly coupled with other implementation details. This is a "breaking change", whatever, file this under "Will say's it's okay".s/ERC721\.//g
)—this might be inconsistent and confusingP.S., in the past, other ERC721 functions were called without virtual dispatch and it created a security problem risk. This affects past versions of OZC. I'm not sure if those versions are still supported (see #2759). I have seen an implementation in the wild that is vulnerable as a result of this.
The text was updated successfully, but these errors were encountered: