fix(ERC6909): fail when from
is msg.sender
with no approval on transferFrom
#411
+11
−1
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.
Description
Currently, when you call
transferFrom
wherefrom
ismsg.sender
wheremsg.sender
is neither operator nor has any allowance, it succeeds. This should not be the case.Here's a quote below taken directly from the EIP (https://eips.ethereum.org/EIPS/eip-6909):
As we can see from above, the standard does not state that a
transferFrom
should be approved whenfrom = msg.sender
. You strictly need an operator or approval for the function to go through, according to the EIP.We also take note that for the ERC20.sol file's
transferFrom
call, the call will fail if there are no approvals, even iffrom
ismsg.sender
(so same call fails for ERC20, but not for ERC6909 - wording is the same for both EIPs, afaik). So I would argue that need an approve for ERC6909 regardless (not for consistency per se, but because of how the EIP was written/worded).The fuzzing error that caught this:
There's another fuzzing error that surfaces from
testTransferFromWithApproval
, that stems from the same issue. The problem with this error is that we don't decrease the allowance, even if the allowance value is nottype(uint256).max
and the caller is not an operator. The one-liner also amends this problem.To quote that this is indeed an error, w.r.t. the EIP's wording:
We read that the caller's allowance must decrease (we only do not increase in case of infinite allowance or the caller is an operator). But, it does not, due to the
msg.sender != sender
condition insidetransferFrom
.The fuzzing error:
Checklist
Ensure you completed all of the steps below before submitting your pull request:
forge snapshot
?npm run lint
?forge test
?Pull requests with an incomplete checklist will be thrown out.