-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Remove payable
modifier for functions
#12539
![:rage4: :rage4:](https://github.githubassets.com/images/icons/emoji/rage4.png)
Comments
![:rage4: :rage4:](https://github.githubassets.com/images/icons/emoji/rage4.png)
As an alternative, what if The behaviour would become consistent between internal/external calls. Additionally, you could ban |
For the record: Also I see no reason to consider the check any more or less relevant than it used to be. It still solves an actual problem - you can still send and lock in ether without the check, so it is still the safe default behaviour, especially if you're always free to choose the unsafe alternative. Given all that I don't think this proposal will get majority support. |
We discussed it on the call today:
|
can add |
I can speak for myself: it is absolutely not representative of my opinion. Opt-in This is 24 gas we're talking about. In the context of a 50000 gas ERC20 transfer, this is 0.05% of the entire transaction, and this is not an optimization that scales with the complexity of the code, so in many cases it will be even lower than that. |
To put it in a different perspective. ~1M transactions * 24 gas = ~1.2 Ethers saved each day (considering the gas price is 50 gwei) |
A compiler flag would be ideal IMO.
Another major reason (why I originally did this and realized what's going on) is the batch call functionality that is being adopted more and more in the real world. eg Uniswap's multicall. Here, if you want to send ether to a batch call, all functions must be declared payable, not just the function that uses the ether. Like if I want to batch the hypothetical functions
Twitter is all about polarizing opinions so don't mind the aggressive behavior. However, I still believe that this protection does not really do much. I stand by my point that it is super hard to transfer ether to a contract while calling a function. Even harder to do it mistakenly :). I agree that the fallback should be non-payable by default so if someone just sends ether to it, it reverts. I have not come across a case where someone mistakenly sent ether to a contract while calling a function that should not be taking ether. |
Don't forget if someone would mistakenly send some ETH by pressing the wrong button in MetaMask, this ether will not only be stuck on the contract, but this person will also pay 9000 of gas extra for the call with |
This issue has been marked as stale due to inactivity for the last 90 days. |
Hi everyone! This issue has been automatically closed due to inactivity. |
![:rage4: :rage4:](https://github.githubassets.com/images/icons/emoji/rage4.png)
Specification
payable
modifier for functions.0.9.0
, can receive ETH by default (i.e., the current semantics of payable functions).nonPayable
modifier to make functions revert when ETH is attached to the call.nonPayable
modifier and the current (< 0.9.0) functions without payable. See following section.Context
The
payable
modifier is getting less relevant nowadays and is being used to save gas (some context from twitter).The default
payable
modifier has subtle semantic difference with modifiers.For example, if a public function
f
has the modifierm
, calling it externally and internally will use the modifier. However, for functions that are notpayable
, the check is only relevant when calling externally. In the following example:This can introduce subtle bugs. For example,
callvalue
in inline assembly (same asmsg.value
) is typically used to save1
gas, when compared topush 0
. It is false that you can replace0
bycallvalue
in inline assembly for public non-payable functions, as one can call it internally from a payable function.The text was updated successfully, but these errors were encountered: