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

ERC-721 example: fix panic re: approve_for with nonexistent token #2092

Merged
merged 4 commits into from
Feb 6, 2024

Conversation

zgrannan
Copy link
Contributor

@zgrannan zgrannan commented Feb 2, 2024

Summary

  • [n] y/n | Does it introduce breaking changes?
  • [n] y/n | Is it dependant on the specific version of cargo-contract or pallet-contracts?

In the current ERC-721 example used in integration tests (which is the source of the erc-721 example in ink-examples), the approve_for function will panic with the text '"Error with AccountId"' if the token id does not exist. This PR changes the function to return an Error::TokenNotFound in this case instead.

I am using Prusti to verify correctness properties of the contract; the presence of this bug prevents the verification of a "panic-freedom" property.

Description

Updated the logic and added a corresponding test.

Checklist before requesting a review

  • My code follows the style guidelines of this project
  • I have added an entry to CHANGELOG.md
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules No dependent changes

ascjones
ascjones previously approved these changes Feb 5, 2024
Copy link
Collaborator

@ascjones ascjones left a comment

Choose a reason for hiding this comment

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

LGTM

@ascjones ascjones enabled auto-merge (squash) February 5, 2024 16:47
@ascjones
Copy link
Collaborator

ascjones commented Feb 5, 2024

Need to run cargo fmt to fix CI

@ascjones ascjones dismissed their stale review February 5, 2024 17:05

Other instances of the bug

Copy link
Collaborator

@ascjones ascjones left a comment

Choose a reason for hiding this comment

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

There are a couple of other instances of calling self.owner_of which panic when None, could you fix those here too?

@zgrannan
Copy link
Contributor Author

zgrannan commented Feb 6, 2024

@ascjones done

@ascjones ascjones merged commit 22b686f into use-ink:master Feb 6, 2024
22 of 23 checks passed
@SkymanOne SkymanOne mentioned this pull request Feb 8, 2024
@SkymanOne SkymanOne mentioned this pull request Mar 4, 2024
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.

2 participants