-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Rename some ERC20 parameters to match the standard document. #3167
Conversation
The naming variable was incorrect. The source of the funds is *not* necessarily (and in most cases isn't) the sender of the transaction. Also, this code has a `msgSender` which further adds confusion.
Hello @MicahZoltu I'm not sure that has any impact at all, but if we should rename them then I'd suggest we use the
|
Updated PR to use |
I love the Looks like the mini-docs above the function need to be updated. I've sent you a PR to your PR, Micah. :D |
Function documentation matches new names
For consistency, it would also make sense to do the same changes to transfer, approve, and all the standard functions. |
Also changed `msgSender` to `owner` in the approval related methods.
Updated the PR to improve consistency across methods. This includes both renaming sender/recipient to from/to and ALSO renaming
|
@MicahZoltu I 100% approve caching _msgSender. This function is not expected to write/change state, and in case it would return different results when called from the same context, that would be breaking. Caching not only fixes that, but it also might save some gas! @frangio Can you double-check before we merge? |
sender
to source
.uint256 amount | ||
) public virtual override returns (bool) { | ||
uint256 currentAllowance = _allowances[sender][_msgSender()]; | ||
address spender = _msgSender(); | ||
uint256 currentAllowance = allowance(from, spender); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This line contains an unrelated change, the allowance is now read through an (overrideable) function instead of directly from storage. We were planning to make this change and it's small enough that I think it's ok to include here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I included it for that reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you @MicahZoltu for the suggestion.
I'd love to clarify one thing though. I don't believe that argument names in EIPs are normative, even in events, so this was more about improving code clarity than fixing something that was incorrect. Do we disagree on this?
@frangio, Yes, code clarity is the reason. The original kick off for this was a project (not using OZ) getting rekt by switching the order of their allowance lookups in one function. The OZ code for allowances prior to this change was:
Which is a bit confusing to look at (sender vs sender) and could easily lead to errors when someone was copying and modifying it. The rest of the PR just grew from there. :) |
The name of event's arguments are important in terms of backward compatibility. Changing that could break things like the openzeppelin subgraphs |
Daniel was correct, this PR was about improving clarity only. The choice of to/from wasn't even my original suggestion. 😄 |
* Renames `sender` to `source`. The naming variable was incorrect. The source of the funds is *not* necessarily (and in most cases isn't) the sender of the transaction. Also, this code has a `msgSender` which further adds confusion. * Changes to `from/to` instead of `source`. * Function documentation matches new names * Changed other instances of sender/recipient to from/to. Also changed `msgSender` to `owner` in the approval related methods. * apply changes to IERC20.sol + minor renaming in ERC20.sol Co-authored-by: Daniel Von Fange <daniel@leancoder.com> Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> (cherry picked from commit 63b4669)
The variable naming was incorrect. The source of the funds is not necessarily (and in most cases isn't) the sender of the transaction. Also, this code has a
msgSender
which further adds confusion.PR Checklist