EIPs Explained

EIP-2970 · Stagnant · Core · 2020-09-13

EIP-2970: IS_STATIC opcode

Proposed an IS_STATIC opcode that tells a contract whether it is running inside a STATICCALL, so it can allow read-only calls while blocking state changes.

What problem does it solve?

EIP-214 added STATICCALL, which runs code in a context where any state change (storage writes, logs, value transfers, contract creation) causes a failure. Code running inside it, however, has no direct way to ask "am I static right now?".

That matters for account abstraction. Under EIP-2938, a contract account might want to let outsiders make harmless read-only calls into it while rejecting anything that changes state. To do that, it needs to know whether the current context is static.

How it works

The proposal adds one opcode:

  • IS_STATIC at 0x4A pushes 1 if the current execution is inside a STATICCALL (or anything called from one), and 0 otherwise.

Today the only way to find out is a hack: make a small CALL to code that emits a LOG and exits. In a static context the LOG fails, so the call returns 0. The spec calls this fragile, because it depends on gas costs, and wasteful.

Sample code

Illustrative only. IS_STATIC was never activated, so this is pseudocode for the proposed behaviour:

def op_is_static(evm):
    evm.stack.push(1 if evm.message.is_static else 0)

The workaround the EIP wants to replace, in Solidity:

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

contract StaticProbe {
    function emitLog() external {
        require(msg.sender == address(this));
        emit Probe();
    }
    event Probe();

    // Returns true if called inside a STATICCALL. Costs gas and relies on
    // LOG being forbidden in static context.
    function isStatic() public returns (bool) {
        (bool ok, ) = address(this).call{gas: 5000}(abi.encodeCall(this.emitLog, ()));
        return !ok;
    }
}

Things to know

  • Status is Stagnant. The abstract, backwards-compatibility and security sections were never filled in.
  • Opcode 0x4A was later assigned to BLOBBASEFEE by EIP-7516, so if this idea were revived it would need a different opcode number.
  • Its driving use case, EIP-2938 account abstraction, also did not ship; later account-abstraction work took other routes.
  • The probe workaround above is sensitive to gas schedule changes; treat it as a demonstration, not production code.

#evm #opcode #staticcall #account-abstraction #core

Details

Authors
Vitalik Buterin (@vbuterin)
Status
Stagnant
Type
Standards Track / Core
Created
2020-09-13

Machine-readable: Markdown · JSON