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

Added new PBT example with transaction auth #21

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Arkay92
Copy link
Contributor

@Arkay92 Arkay92 commented Oct 24, 2022

Many have been asking about transfer authorisation as an option to the PBT here is my proposed solution (open to any feedback on issues or improvements.

Gas Snapshot:

[PASS] testApprove() (gas:10677 -> 10677)
[PASS] testGetApproved() (gas:16241 -> 16241)
[PASS] testIsApprovedForAll() (gas:10051 -> 10051)
[PASS] testSetApprovalForAll() (gas:10714 -> 10714)
[PASS] testTransferFunctions() (gas:19077 -> 19077)

// PBT Simple Tests

[PASS] testGetTokenDataForChipSignature() (gas:127921 -> 127921)
[PASS] testGetTokenDataForChipSignatureBlockNumTooOld() (gas:122467 -> 122467)
[PASS] testGetTokenDataForChipSignatureInvalid() (gas:131763 -> 131763)
[PASS] testGetTokenDataForChipSignatureInvalidBlockNumber() (gas:122301 -> 122301)
[PASS] testIsChipSignatureForToken() (gas:216704 -> 216704)
[PASS] testMintTokenWithChip() (gas:176564 -> 176564)
[PASS] testSeedChipToTokenMapping() (gas:115247 -> 115247)
[PASS] testSeedChipToTokenMappingExistingToken() (gas:212100-> 212100)
[PASS] testSupportsInterface() (gas:7059 -> 7059)
[PASS] testTokenIdFor() (gas:117084 -> 116986)
[PASS] testTokenIdMappedFor() (gas:66778 -> 66680)
[PASS] testTransferTokenWithChip(bool) (runs: 256, μ: 211881, ~: 211785 -> runs: 256, μ: 211866, ~: 211785)
[PASS] testUpdateChips() (gas:171052 -> 171052)
[PASS] testUpdateChipsInvalidInput() (16433 -> gas: 16433)
[PASS] testUpdateChipsUnsetChip() (23430 -> gas: 23430)

// PBT With Auth Tests

[PASS] testActionTransferRequest() (gas: 57801)
[PASS] testGetTokenDataForChipSignature() (gas: 127771)
[PASS] testGetTokenDataForChipSignatureBlockNumTooOld() (gas: 122295)
[PASS] testGetTokenDataForChipSignatureInvalid() (gas: 131613)
[PASS] testGetTokenDataForChipSignatureInvalidBlockNumber() (gas: 122129)
[PASS] testIsChipSignatureForToken() (gas: 216515)
[PASS] testMintTokenWithChip() (gas: 176439)
[PASS] testRequestOwnership() (gas: 55251)
[PASS] testSeedChipToTokenMapping() (gas: 114990)
[PASS] testSeedChipToTokenMappingExistingToken() (gas: 212102)
[PASS] testSeedChipToTokenMappingInvalidInput() (gas: 17178)
[PASS] testSupportsInterface() (gas: 7105)
[PASS] testTokenIdFor() (gas: 116877)
[PASS] testTokenIdMappedFor() (gas: 66592)
[PASS] testTransferTokenWithChip(bool) (runs: 256, μ: 238545, ~: 238461)
[PASS] testUpdateChips() (gas: 170582)
[PASS] testUpdateChipsInvalidInput() (gas: 16433)
[PASS] testUpdateChipsUnsetChip() (gas: 23405)

Copy link
Collaborator

@2pmflow 2pmflow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution.

This seems like an opportunity to add a _beforeTokenTransfer hook, similar to , to PBTSimple, with all the new functionality in an extension (like https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721Pausable.sol).

mapping(address => TokenData) _tokenDatas;

/**
* Mapping from userAddress to TransactionRequests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tokenId

}

function actionTransferRequest(uint256 _tokenId, bool _decision) public {
if(msg.sender == owner) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ownerOf(_tokenId)

Also in the current design it seems like someone else could call requestTransfer to block an approved transfer.

For example, if Bob requests to buy Alice's jacket, and Alice approves, a third party Joe could overwrite Alice's approval.
We may need to model this so that each requester has their own space, similar to _operatorApprovals https://github.com/OpenZeppelin/openzeppelin-contracts/blob/a1948250ab8c441f6d327a65754cb20d2b1b4554/contracts/token/ERC721/ERC721.sol

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate that dude will get on the rework asap 👍🏻

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 👍

Also, it can get tricky because what if Alice is malicious and sells the item to Bob but revokes the approval after the physical is delivered, before Bob can scan?

A mechanism that forces Alice to keep the approval approved for a period of time could help here, but we can figure that out in a separate PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate the PR @Arkay92. Internally we want to structure these approval mechanisms as PBT extensions. I will put together a solution for "delegated receivers" which you can base your implementation off of.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cygaar & @2pmflow looking forward to making this happen the right way 👍🏻

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