EIP-2330 - EXTSLOAD opcode

Created 2019-10-29
Status Stagnant
Category Core
Type Standards Track
Authors
Requires

Abstract

This proposal adds a new opcode EXTSLOAD at 0x5c which pops two items from the stack: <account address> <storage key> and pushes one item: <storage value>. The gas cost is sum of account access cost and storage read based on EIP-2929 Access Lists.

Motivation

While any off-chain application can read all contract storage data of all contracts, this is not possible for deployed smart contracts themselves. These are bound to use contract calls for any interaction including reading data from other contracts. This EIP adds an EVM opcode to directly read external contract storage.

The gas cost when reading from registry style contract such as EIP-20s, ENS and other data contracts is very high, because they incur cross contract call cost, cost for ABI encoding, decoding and dispatching and finally loading the data. In many cases the underlying storage that is being queried is though just a simple mapping. On top of that, the view function may SLOAD many other slots which caller may not be interested in, which further adds to the gas costs. In these cases a new EXTSLOAD call directly accessing the mapping in storage could not only reduce the gas cost of the interaction more than 10x, but also it would make the gas cost predictable for the reading contract.

Specification

A new EVM instruction EXTSLOAD (0x5c) that works like SLOAD (0x54) but an additional parameter representing the contract that is to be read from.

EXTSLOAD (0x5c)

The EXTSLOAD instruction pops 2 values from the stack, first contract a contract address and then second slot a storage address within contract. As result EXTSLOAD pushes on the stack the value from the contract storage of contract at the storage slot address or 0 in case the account contract does not exist.

Gas cost pre-verkle

Gas to be charged before Verkle Tree change is specified as ACCOUNT_ACCESS_COST + STORAGE_READ_COST where:

Gas cost post-verkle

It is important to consider that post Verkle tree change, ACCOUNT_ACCESS_COST will not be needed since a single account's storage would be spread across the entire global trie. Hence gas to be charged post Verkle Tree change is just STORAGE_READ_COST, which is as specified in Gas cost pre-verkle.

Rationale

Backwards Compatibility

This change is fully backwards compatible since it adds a new instruction.

Security Considerations

Copyright

Copyright and related rights waived via CC0.