EIP-1380 Reducing gas cost for self-calls (Reduced gas cost for call to self)

No call decision · Fees & gas · EIP status Stagnant · created 2018-08-31

A proposal to lower the gas cost of a smart contract calling itself via CALL, DELEGATECALL, CALLCODE, or STATICCALL from 700 to 40.

Why it is needed

Ethereum raised the gas cost of CALL-family instructions from 40 to 700 in EIP-150, to account for the I/O cost of loading code from disk when calling another contract. However, when a contract calls itself, the code is already loaded in memory and does not need to be loaded again, yet the same 700 cost is charged. Because of this, compilers for languages such as Solidity and Vyper use JUMP instead of the costly CALL when calling internal functions. Using JUMP requires the compiler to manually swap the stack and memory context on every call, which complicates implementation and makes it difficult to build pure functions that never touch memory at all. It also creates a risk of hitting the stack depth limit sooner when nesting calls to functions with many arguments.

What changes

Today

After EIP-1380

Who is affected

In depth

Applicable instructions and conditions

When block.number is at or above FORK_BLKNUM, the gas cost of CALL, DELEGATECALL, CALLCODE, and STATICCALL is lowered from 700 to 40. This applies only when the call destination address equals the caller's own address. In other words, calls to other contracts remain at 700, while only calls to the contract itself become 40.

Relationship with EIP-150

EIP-150 raised the gas cost of CALL-family instructions from 40 to 700, to account for the I/O work of loading another contract's code from disk. This proposal treats the difference, 660, as the disk loading cost, and assumes that the original cost of creating a new VM instance with code already loaded in memory is 40. Since no disk loading occurs when calling oneself, the logic is that charging only 40 is justified.

Motivation: why encourage CALL over JUMP

Because of the 700 cost, compilers for languages such as Solidity and Vyper implement internal function calls with JUMP instead of CALL. Using JUMP requires the compiler to manually swap the stack and memory context on every call, complicating implementation and making it difficult to build pure functions that never touch memory. CALL, by contrast, guarantees that the context is cleanly reset on every call, reducing the risk of hidden bugs caused by memory contamination. There is also the problem that nesting JUMP-based calls to functions with many input and output arguments reaches the stack depth limit sooner.

Backward compatibility

Existing contracts are not affected other than seeing their execution cost drop. Contract and language developers learned from EIP-150 that gas costs are not fixed and can change, and since this proposal lowers rather than raises a cost, it is described as having a smaller impact than EIP-150.

Test cases and implementation status

The original text's Test Cases and Implementation sections are both marked TBA (to be announced), so no concrete tests or reference implementation have been provided yet. The current status is Stagnant, meaning this is not an actively progressing proposal.

Original EIP · ← EIPs