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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create an internal _approve function allowing extensions and EIPs to do approvals without check #427

Merged
merged 1 commit into from
Nov 9, 2022

Conversation

dievardump
Copy link
Contributor

@dievardump dievardump commented Sep 24, 2022

The current implementation of ERC721A have _tokenApprovals private and has all the approval management code in the public facing approve function.

This sadly means that there is no way, for a contract extending ERC721A, to internally do approvals without the ownership or isApprovedForAll check.

There are however some EIPs meant to improve ERC721 and tokens management that are in need of being able to approve internally without those checks.

An example is EIP-4494 that introduces Permits to ERC721, allowing to give approvals to accounts by only signing a message instead of having it done with a tx. Very similar to EIP-2612 for ERC20.
This EIP could totally change the way we work with marketplaces today, as we would be able to simply sign messages in order to sale items, instead of granting approvalForAll to contracts.

However, EIP-4494 requires the ability to set the approval internally, or at least to bypass the ownership/approvalForAll check, which is right now not possible with the current implementation.

Even if not to accommodate other EIPs and extensions, there can be a lot of reasons for children contracts to be able to do that, similar to the reasons for contracts to be able to burn items internally without that check.

So, as it was already done with the _burn() function, this pull request internalize the content of the _approve function with a version that has a 3rd parameter, to indicate if the ownership & isApprovalForAll needs to be checked or not before setting the approval.

Gas Report

Before

·-----------------------------------------------------|---------------------------|-------------|-----------------------------·
|  Methods                                                                                                                    │
····························|·························|·············|·············|·············|···············|··············
|  Contract                 ·  Method                 ·  Min        ·  Max        ·  Avg        ·  # calls      ·  usd (avg)  │
····························|·························|·············|·············|·············|···············|··············
|  ERC721AMock              ·  approve                ·      50497  ·      52834  ·      50607  ·           26  ·          -  │
····························|·························|·············|·············|·············|···············|··············
|  ERC721AStartTokenIdMock  ·  approve                ·      52713  ·      55050  ·      52814  ·           26  ·          -  │
····························|·························|·············|·············|·············|···············|··············
|  Deployments                                        ·                                         ·  % of limit   ·             │
······················································|·············|·············|·············|···············|··············
|  ERC721AMock                                        ·          -  ·          -  ·    1374803  ·        4.6 %  ·          -  │
······················································|·············|·············|·············|···············|··············
|  ERC721AStartTokenIdMock                            ·          -  ·          -  ·    1441224  ·        4.8 %  ·          -  │
······················································|·············|·············|·············|···············|··············
|  ERC721AWithERC2309Mock                             ·    1002042  ·    1002054  ·    1002043  ·        3.3 %  ·          -  │
·-----------------------------------------------------|-------------|-------------|-------------|---------------|-------------·

After

·-----------------------------------------------------|---------------------------|-------------|-----------------------------·
|  Methods                                                                                                                    │
····························|·························|·············|·············|·············|···············|··············
|  Contract                 ·  Method                 ·  Min        ·  Max        ·  Avg        ·  # calls      ·  usd (avg)  │
····························|·························|·············|·············|·············|···············|··············
|  ERC721AMock              ·  approve                ·      50567  ·      52904  ·      50677  ·           26  ·          -  │
····························|·························|·············|·············|·············|···············|··············
|  ERC721AStartTokenIdMock  ·  approve                ·      52783  ·      55120  ·      52884  ·           26  ·          -  │
····························|·························|·············|·············|·············|···············|··············
|  Deployments                                        ·                                         ·  % of limit   ·             │
······················································|·············|·············|·············|···············|··············
|  ERC721AMock                                        ·          -  ·          -  ·    1379994  ·        4.6 %  ·          -  │
······················································|·············|·············|·············|···············|··············
|  ERC721AStartTokenIdMock                            ·          -  ·          -  ·    1446463  ·        4.8 %  ·          -  │
······················································|·············|·············|·············|···············|··············
|  ERC721AWithERC2309Mock                             ·    1008085  ·    1008097  ·    1008086  ·        3.4 %  ·          -  │
·-----------------------------------------------------|-------------|-------------|-------------|---------------|-------------·

pros
allows internal approvals without any check of ownership nor weird hack on isApprovedForAll()

cons
slightly more expensive in gas at deployments (~5000gas) and approvals (~70gas)

@dievardump dievardump changed the title create an internal _approve function allowing extensions and EIPs to do approvals without check #426 create an internal _approve function allowing extensions and EIPs to do approvals without check Sep 24, 2022
@cygaar cygaar merged commit 44ab010 into chiru-labs:main Nov 9, 2022
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

Successfully merging this pull request may close these issues.

3 participants