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

ERC20 simplification with allowing _transfer() to perform _mint() and _burn() functionalities #3109

Closed
wants to merge 2 commits into from

Conversation

k06a
Copy link
Contributor

@k06a k06a commented Jan 14, 2022

Let's discuss this opportunity to minimize ERC20 source code.

PR Checklist

  • Tests
  • Documentation
  • Changelog entry

@Amxx
Copy link
Collaborator

Amxx commented Jan 14, 2022

Hello @k06a

I'm really not confortable with this change. In particular, it would allow a dev to call _transfer() internally, and do "mint" or "burn" operation that do not update the totalSupply.

Can you give more details about your usecase ?

I was not here when the decision was taken, but having the mint & burn be separate function from transfer is helping with multiple things:

  • its easy to override mint and burn, and that doesn't add any check in transfer, making sure no additional cost is introduced into the simple transfers (that are the most commonly used operations)
  • it forces the dev to clearly distinguish between these operations and avoid the risk of minting or burning "by mistake"

@k06a
Copy link
Contributor Author

k06a commented Jan 15, 2022

@Amxx I see, but this issue could be solved by moving totalSupply modification into the _transfer method. Your points makes sense for me, but what about extracting such a private __transfer method? This would reduce the code size (+compiled size).

@Amxx
Copy link
Collaborator

Amxx commented Jan 15, 2022

Having an additional __transfer function would just make everything more confusing. Also, I think we should avoid __ préfixes.

What about leaving everything as now, and adding a _arbitraryTransfer that would redirect to mint, burn or transfer depending on the parameters it receives?

@k06a
Copy link
Contributor Author

k06a commented Jan 15, 2022

@Amxx this would work and can be introduced as an extension. But I was thinking about reducing code size of the existing solution.

@Amxx
Copy link
Collaborator

Amxx commented Jan 15, 2022

I'm more concerned by the gas cost of executing transactions then by the cost of deployment.

Maybe we should produce number to check the impact of such a change on both

@k06a
Copy link
Contributor Author

k06a commented Jan 15, 2022

I agree that both gas impacts are important.

@frangio
Copy link
Contributor

frangio commented Feb 1, 2022

I'd like to see the numbers but I believe the bytecode size impact could be significant, and the runtime cost impact may be negligible. The additional cost contains no storage reads or writes as far as I can tell, it's just stack operations and jumps.

I think we have to consider this improvement, and a similar strategy could be valuable in other contracts.

_arbitraryTransfer could be a private function if we prefer to keep the current internal API, which is simpler as it has a single way to do each operation.

@frangio frangio added this to the 4.8 milestone Jun 27, 2022
@Amxx Amxx modified the milestones: 4.8, 5.0 Aug 16, 2022
@frangio
Copy link
Contributor

frangio commented Sep 19, 2022

We are probably going to move forward with this in 5.0 along with the removal of before and after hooks (replaced with "simple" overriding of _transfer). A PR with these changes for ERC721 in #3635.

@frangio
Copy link
Contributor

frangio commented Jan 23, 2023

This has been implemented in next-v5.0 in #3838 and #3921.

@frangio frangio closed this Jan 23, 2023
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