EIPs Explained

EIP-5065 · Stagnant · Core · 2022-04-30

EIP-5065: Instruction for transferring ether

Proposed a new EVM instruction that sends ETH to an address without calling it, so contracts can pay untrusted recipients with no re-entrancy risk.

What problem does it solve?

In today's EVM, sending ETH from a contract (CALL with value, Solidity's transfer, send or .call{value: ...}) also hands execution to the recipient. If the recipient is a contract, its code runs, and it can re-enter the sender. That is the root of many re-entrancy bugs, and the reason contracts use re-entrancy guards and the checks-effects-interactions pattern.

The only way to move ETH without triggering any code is a hack: deploy a throwaway contract, fund it, and have it SELFDESTRUCT to the recipient. That works but is expensive. Most of the time the sender just wants to pay, not to call.

How it works

EIP-5065 adds an instruction, AIRDROP, that transfers ETH and does nothing else, much as SELFDESTRUCT credits its beneficiary without calling it.

  • Stack inputs: address (recipient) and value (wei).
  • Effect: move value wei from the current contract to address. No code runs at the destination.
  • Opcode: the spec writes 0xFG, a placeholder; no byte was assigned.

Gas = static cost + address access cost + new-account cost:

Part Cost
Static 6700
Address access (EIP-2929) 2600 if cold, 100 if warm
Value to an empty account 25000 if value > 0 and the target has zero balance, zero nonce and no code

The static 6700 comes from CALL's 9000 charge for a non-zero value transfer minus the 2300 stipend that CALL passes to the recipient; with no call, there is no stipend.

Sample code

Today, without the opcode, the safest pattern is checks-effects-interactions plus a pull-payment design:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract Payouts {
    mapping(address => uint256) public owed;

    function withdraw() external {
        uint256 amount = owed[msg.sender];
        owed[msg.sender] = 0;                         // effect before interaction
        (bool ok, ) = msg.sender.call{value: amount}(""); // recipient code runs here
        require(ok, "send failed");
    }
}

With EIP-5065 the interaction would carry no control-flow risk (hypothetical; no compiler supports it):

PUSH32 <amount>     ; value
PUSH20 <recipient>  ; address (top of stack)
AIRDROP             ; credit balance, no call, no re-entrancy

Things to know

  • Status: Stagnant. No opcode number was assigned, and the spec's test cases are still TODO.
  • A recipient contract cannot reject or react to the payment, the same as with SELFDESTRUCT or validator withdrawals today. Contracts already must not assume their balance only changes via receive.
  • The spec says the stack inputs are address and value but does not fix their order; the snippet above is only illustrative.
  • After EIP-6780, SELFDESTRUCT outside the creating transaction only sends ETH, but it still requires deploying a helper contract per payment, so the motivation for a cheap native opcode remains.

#evm #opcodes #eth-transfer #reentrancy #core

Details

Authors
Mudit Gupta (@maxsam4)
Status
Stagnant
Type
Standards Track / Core
Created
2022-04-30
Requires

Machine-readable: Markdown · JSON