EIP2330 - EXTSLOAD opcode

# Simple Summary

A new EXTSLOAD <contract> <slot> EVM opcode to read external contract storage data and corresponding allowing to build registry and token contracts that use less gas.

# Abstract

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.

# Motivation

The gas cost when reading from registry style contract such as ERC-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. 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. Furthermore with the use of the existing EXTCODEHASH an external contracts implementation can be verified and allows EXTSLOAD to make deterministic reads even from third-party smart contracts.

# Specification

Proposal

A new EVM instruction EXTSLOAD (0x5c) that works like SLOAD (0x54) but an additional parameter representing the contract that is to be read from. The gas cost of EXTSLOAD would be the sum of the fee schedule G (opens new window) for G[EXTCODE](700) + G[SLOAD](800) = 1500 gas

EXTSLOAD (0x5c)
1

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.

Example

An example assuming further Solidity changes (opens new window) for illustration:

interface MemberList {
  public fixed(@5) mapping(address => bool) members;
}
1
2
3

And a corresponding contract function that uses this member list. Similarly tokens or other registries could be implemented.

function membersOnly(address list, address member) {
  MemberList ml = MemberList(list);
  if (ml.members[client] == false) revert("Nonmember!");
}
1
2
3
4

The call ml.members[client] here could let the Solidity compiler generate the normal map access logic but using the new EXTSLOAD <contract> <slot> instructions to read from the ml contract storage instead of the local contract storage.

# Backwards Compatibility

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

# Test Cases

Not started yet.

# Implementation

Aleth Pull Request (opens new window)

Copyright and related rights waived via CC0 (opens new window).

▲ Powered by Vercel