Open
Conversation
For our specified use cases, this should help in preventing honest mistakes of users of the contract. I may invoke transferFrom(A, B, Z) and be the owner of Z, but if A is not my correct address, the code will reduce someone else's zombieCount and also emit a Transfer event that's not accurate in what it says.
|
👍 I noticed this bug as well while completing the lesson. |
BrandonNoad
reviewed
Jan 2, 2022
|
|
||
| function transferFrom(address _from, address _to, uint256 _tokenId) external payable { | ||
| require (zombieToOwner[_tokenId] == msg.sender || zombieApprovals[_tokenId] == msg.sender); | ||
| require ((zombieToOwner[_tokenId] == msg.sender && _from == msg.sender) || (zombieApprovals[_tokenId] == msg.sender && _to == msg.sender)); |
There was a problem hiding this comment.
I think in both cases you need to check zombieToOwner[_tokenId] == _from.
So the fix would be:
require (zombieToOwner[_tokenId] == _from && (msg.sender == _from || (msg.sender == _to && zombieApprovals[_tokenId] == msg.sender)));
|
I noticed this also and came to see if it was discussed. I think the best place to verify the ownership is in the _transfer function, that way developers don't have to remember to check before calling it: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For our specified use cases, this should help in preventing honest mistakes of users of the contract.
I may invoke transferFrom(A, B, Z) and be the owner of Z, but if A is not my correct address, the code will reduce someone else's zombieCount and also emit a Transfer event that's not accurate in what it says.