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

Mint restriction: Signature-based minting #3

Open
Tracked by #1
NicolasMahe opened this issue Nov 1, 2021 · 8 comments · May be fixed by #7
Open
Tracked by #1

Mint restriction: Signature-based minting #3

NicolasMahe opened this issue Nov 1, 2021 · 8 comments · May be fixed by #7
Assignees
Labels

Comments

@NicolasMahe
Copy link
Member

Implement a signature-based minting so any backend can sign a specific authorization to their users.

@NicolasMahe
Copy link
Member Author

After discussion with Hadrien, we decide to implement it the following way:

  • Reuse MinterAccessControl smart contract. It already implement the enable/disable and a list of authorized minters.
  • Add the operator signature at the end of the MintXXXData.signatures
  • If there is one more signatures than the number of creators
    • then check this signature is signed by a minter from MinterAccessControl
    • bypass check previously done by MinterAccessControl.isValidMinter
    • Remove the signature from the signatures payload so the contract checks can continue to work
  • Else, execute the existing logic from MinterAccessControl.isValidMinter

@NicolasMahe
Copy link
Member Author

NicolasMahe commented Nov 18, 2021

Not to do in the same PR but nice to have:
The function to validate the signature is not optimised for the use we are going to do. Would be nice to check how much less gas we would get with like 3 creators and 5 minters

@Hadrienlc
Copy link

  • If there is one more signatures than the number of creators
    • then check this signature is signed by a minter from MinterAccessControl

Unfortunately, it's not possible to iterate mapping (address => bool) private _minters;
Should we go back to a separate class implementation than MinterAccessControl with only 1 address operator to check the signature against ?

@NicolasMahe
Copy link
Member Author

NicolasMahe commented Nov 18, 2021

Should we go back to a separate class implementation than MinterAccessControl with only 1 address operator to check the signature against ?

What about using an iterable map? Open zeppelin has one.
The new pr could change the structure in MinterAccessControl

@NicolasMahe
Copy link
Member Author

NicolasMahe commented Nov 18, 2021

Another idea: use directly hash.recover to return signer address:

signerFromSig = hash.recover(signature);

source: https://github.com/rarible/protocol-contracts/blob/master/tokens/contracts/erc-1271/ERC1271Validator.sol

Less code reusability, but much simpler and gas-efficient

@Hadrienlc
Copy link

signerFromSig = hash.recover(signature);

won't work for a contract, see https://github.com/rarible/protocol-contracts/blob/b1b1593686fc78ceecab123124059acd908fafe1/tokens/contracts/erc-1271/ERC1271Validator.sol#L24 requires the signer to be passed as parameter.

EnumerableMap can be a good idea but is a breaking change that will be hard to handle if the first PR is deployed before this one. It will be almost impossible to migrate the configuration from the mapping since we can't enumerate the values.
Can we block the first PR to switch to an EnumerableMap on MinterAccessControl before the first release ?

@NicolasMahe
Copy link
Member Author

NicolasMahe commented Nov 18, 2021

EnumerableMap can be a good idea but is a breaking change that will be hard to handle if the first PR is deployed before this one. It will be almost impossible to migrate the configuration from the mapping since we can't enumerate the values. Can we block the first PR to switch to an EnumerableMap on MinterAccessControl before the first release ?

Good point.
I think the first PR will not be merged or review before you finish this new PR.
Implement it in a new PR with a nice dedicated commit that changes the structure and I will push it back to the PR later

@NicolasMahe
Copy link
Member Author

Waiting for #2 to be done first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants