openzeppelin-contracts icon indicating copy to clipboard operation
openzeppelin-contracts copied to clipboard

Make ERC20Votes independent of ERC20Permit

Open k06a opened this issue 3 years ago • 4 comments

🧐 Motivation

We need a more clear and independent structure of ERC20 extensions.

📝 Details

Now ERC20Votes inherits ERC20Permit to use EIP712 inheritance and moreover to abuse its permit nonces. I believe we can remove the ERC20Permit constructor to keep it abstract and make ERC20Votes have its own nonces for delegation and direct inheritance from EIP712.

Moreover, I see you have Votes implementation since 4.5, so hopefully, you are going to use this implementation in ERC20Votes.

k06a avatar Feb 02 '22 13:02 k06a

Moreover, I see you have Votes implementation since 4.5, so hopefully, you are going to use this implementation in ERC20Votes.

We would love to, but that would change the storage layout, which is a big breaking change for the upgradeable version of the contract :/

Amxx avatar Feb 02 '22 15:02 Amxx

The storage layout is incompatible because of the nonces mapping in Votes, which in ERC20Votes is reused from ERC20Permit as pointed out here. Other than that, some variables were wrapped in structs which should be soon supported by the Upgrades Plugins as a valid upgrade.

The nonces are an issue but interestingly it's part of @k06a's proposa to change that as well. However:

make ERC20Votes have its own nonces

How would this work? The Votes interface is not standardized but the EIP712 signatures for voting by sig should use the value returned by the nonces() function so I don't see how we could change this without affecting clients that rely on this.

remove the ERC20Permit constructor to keep it abstract

This is a breaking change but we agree, we will have to do it in the next major release.

@k06a Is there something in particular that motivates these suggestions?

frangio avatar Feb 02 '22 22:02 frangio

@frangio was just browsing library code and wondered when saw code duplications and unexpected dependencies.

k06a avatar Feb 05 '22 02:02 k06a

Changed the title to make it clearer but as the description says this also implies changing ERC20Permit so it doesn't invoke the constructor of EIP712.

frangio avatar Sep 16 '22 00:09 frangio

Fixed by https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3816 for future 5.0 release.

frangio avatar Dec 02 '22 00:12 frangio