Abstract
Add a new instruction that transfers ether to a destination address without handing over the flow of execution to it. It should work similarly to how SELFDESTRUCT
transfers ether to the destination without making a call to it.
Motivation
From an architectural point of view, execution flow should never be handed over to an untrusted contract. Ethereum currently does not have any ideal way to transfer ether without transferring the flow of execution. People have come up with reentrancy guards and similar solutions to prevent some types of attacks but it’s not an ideal solution. The only way to transfer ether from smart contracts without triggering a call is to create a dummy contract, send the precise amount of ether to it and then call SELFDESTRUCT
from it.
Specification
Introduce a new instruction, AIRDROP
that transfers ether to the destination without making a call to it.
Stack input
address: the account to send ether to.
value: value in wei to send to the account.
Gas
The total gas cost should be the sum of a static cost + address_access_cost + value_to_empty_account_cost.
- Static cost: 6700
- Dynamic cost:
- address_access_cost: If the target is not in
accessed_addresses
, chargeCOLD_ACCOUNT_ACCESS_COST
gas, and add the address toaccessed_addresses
. Otherwise, chargeWARM_STORAGE_READ_COST
gas. Currently,COLD_ACCOUNT_ACCESS_COST
is 2600 whileWARM_STORAGE_READ_COST
is 100. - value_to_empty_account_cost: If value is not 0 and the address given points to an empty account, then value_to_empty_account_cost is the account creation gas cost which currently is 25000. An account is empty if its balance is 0, its nonce is 0 and it has no code.
- address_access_cost: If the target is not in
Rationale
This behavior is already possible by deploying a new contract that does SELFDESTRUCT
but it is prohibitively expensive. In most scenarios, the contract author only wants to transfer ether rather than transferring control of the execution. ERC20 can be used as a case study for this where most users transfer funds without a post-transfer hook.
This instruction allows contracts to safely pass ether to an untrusted address without worrying about reentrancy or other malicious things an untrusted contract can do on.
The static gas cost is derived by subtracting the gas stipend (2300) from the positive_value_cost of CALL
opcode which is currently set to 9000.
Backwards Compatibility
No known issues as this is a new instruction that does not affect any old instructions and does not break any valid assumptions since it make not anything impossible possible.
Test Cases
TODO
Security Considerations
No known security risks.
Discussion points
- Gas costs - I would like them to be lower
- Should we allow EOA to transfer ether without triggering a call - Consensus is leaning towards NO. It adds an additional risk of locking mistakenly sent ether while there is no demand for the feature.
- Instruction name alternatives - REMIT/PAY/DISBURSE/GIFT/FORCESEND/BESTOW
FAQ
Q) Why not just repurpose SELFDESTRUCT
? It is already being planned to be used as just a force transfer.
A) SELFDESTRUCT
transfers all of your ether. We need a way to transfer a specific amount. Also, the repurposing of SELFDESTRUCT
might take a while longer to get into prod.
Q) Doesn’t this break the contracts that depend on the stipend?
A) Those contracts were already broken as bypassing stipend is already possible. Additionally, I do not think there are any practical contracts that get “broken” because of this. Sending money to a gnosis wallet, for example, does not break it even if you don’t end up executing its fallback function.
Q) What about the additional risk of locking ether mistakenly?
A) I agree that it does add some risk there but it’s negligible IMO. The existing contracts will work in the same old way. ERC20s have allowed and normalized forced transfers and it is a well-understood concept that I do not expect new devs to be mistakenly locking ether using this feature too often. This proposal does not recommend for EOAs to have this ability to reduce the risk of lock funds. Furthermore, tooling can warn users if a transaction force transfers ether to a contract that usually doesn’t accept ether. Considering everything, the benefits of this proposal outweigh the cons considerably IMO.
Q) Why not propose to remove stipends completely if you think they are broken?
A) Because that’s likely to have backward compatibility issues. If I was designing ETH from scratch, I would have advised against stipends but at this point, it might be too late to remove them. Well, too late to remove them without an thorough onchain analysis, at least.
Q) Why not adjust the gas given in a stipend?
A) That does not resolve the concern and promotes a bad habit of depending on gas costs. On one side, we recommend devs to not depend on gas costs and on the other, we give them a fixed gas cost to do stuff in certain scenarios. Very bad mixed messaging IMO.