-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Unlimited ERC20 token allowance #717
Comments
Are there any example scenarios where approving 2^256 once is not enough to (pragmatically) last forever? For any token with a total supply on the order of 10^26 (like Ethereum) you would have to transfer the entire token supply (through one account) ~2^169 times. Are there tokens with such a large supply that it is realistic for a single account to see 2^256 tokens flow through it over some sane period of time? |
@MicahZoltu the issue is not that 2^256 is too small. The issue is that Basically, 2^256 is so large that it might as well be treated as unlimited. |
Ah, I see. I'm on board then. Basically UINT_MAX is considered a sentinel value for token approval and any token approvals of UINT_MAX SHOULD be interpreted as unlimited approval (to save on gas costs). |
Does the standard have anything at all to say about the implementation behind the interface? Isn't it true that one can have the transferFrom function do anything it likes. |
|
It appears that the spec doesn't actually say that |
That's why people have to read the source code. |
Would it be better to just add another method to StandardToken like Internally, StandardToken/Token could have another field
|
2^256 tokens is effectively unlimited anyway; I don't see much value in introducing a new API call and storage slot for an extra Boolean, personally. |
Ok -- maybe I'm not clear on the use cases. Is this something a non-technical user might use through MyEtherWallet or another auto-generated UI? Will they have to enter the amount as:
I would advise against piggy-backing on an existing API and giving particular values special meaning in general. However, if you want to go that route and you don't want to add the extra storage, then at least add the following function with its own documentation:
Also, I wonder if a better option would be a standard "JointAccount" contract (probably exists already) that would allow a primary user to add authorized users. The JointAccount could hold the tokens and authorized users could spend them. To me, it seems better than putting this special logic in the StandardToken and a JointAccount approach would actually be backward compatible with tokens that have already been deployed. Again, maybe I'm just not clear on the use cases. |
This will save a lot of gas for a lot of people, I think approving an account to take out as much as they want is a very common use case of |
@phiferd if someone wanted to set an unlimited allowance with MEW then yes, they would have to enter that amount. Realistically, users will be able to set an unlimited allowance through dApps that abstract this logic away with a simple toggle. Here is a simplified example used by 0x protocol: traders approve a single proxy contract to transfer funds on their behalf. Traders create an "order" that is signed with their private key. When another trader fills that order, the signature is validated and the proxy contract swaps the tokens of both parties using |
My first thought is that I like this. It preserves the existing API (unless the Here's my paraphrasing, let me know if inaccurate:
So really the net benefit is a savings of gas, which IMO is worthwhile. |
Setting the approval to max value might not be enough. Imagine of an exchange account, it might want allowance unlimited, because if it set to max value in some years it might end up consuming all allowance. |
Has anybody done an empirical amortized analysis of the gas savings? Indeed, you do save gas when you want to approve some account without limitation, but on the other hand you spend gas to evaluate the unnecessary |
I supporting this proposal to go forward as a standard. This is in widespread use already. |
The standard has been adopted by TrueUSD. trusttoken/contracts-pre22#118 |
Check in the basic contract code for WCHI as a simple ERC-20 token without any extra features, plus some basic configuration scripts for Truffle. No unit tests are included yet.
There has been no activity on this issue for two months. It will be closed in a week if no further activity occurs. If you would like to move this EIP forward, please respond to any outstanding feedback or add a comment indicating that you have addressed all required feedback and are ready for a review. |
This issue was closed due to inactivity. If you are still pursuing it, feel free to reopen it and respond to any feedback or request a review in a comment. |
Summary
ERC20 provides a standard API for Ethereum smart contracts implementing tokens. While all ERC20 tokens share the same API, different implementations of the standard functions have been released by various teams. This proposal slightly modifies the implementation of the
transferFrom
function in a way that allows a user to provide an unlimited allowance, which can provide significant gas savings.Specification
With this proposal,
transferFrom
only modifies theallowed
mapping ifallowed[_from][_spender]
is less than the maximum unsigned integer (2 ** 256 - 1).Rationale
There are cases where a token owner is willing to give another address an unlimited allowance. With the current accepted implementation of
transferFrom
,_value
is subtracted from theallowed
mapping every single time the function is called. This is an unnecessary (and annoying) state change in the case the token owner wishes to grant an address an unlimited allowance, wasting 5K gas per call oftransferFrom
. This change is a huge long run efficiency gain and is completely backwards compatible.I would also like to acknowledge @recmo, who initially proposed this solution.
The text was updated successfully, but these errors were encountered: