Data Locations

<storage_pointer> ::= "&s" ;
<transient_storage_pointer> ::= "&t" ;
<memory_pointer> ::= "&m" ;
<calldata_pointer> ::= "&cd" ;
<returndata_pointer> ::= "&rd" ;
<internal_code_pointer> ::= "&ic" ;
<external_code_pointer> ::= "&ec" ;

<data_location> ::=
    | <storage_pointer>
    | <transient_storage_pointer>
    | <memory_pointer>
    | <calldata_pointer>
    | <returndata_pointer>
    | <internal_code_pointer>
    | <external_code_pointer> ;

The <location> is a data location annotation indicating to which data location a pointer's data exists. We define seven distinct annotations for data location pointers. This is a divergence from general purpose programming languages to more accurately represent the EVM execution environment.

  • &s persistent storage
  • &t transient storage
  • &m memory
  • &cd calldata
  • &rd returndata
  • &ic internal (local) code
  • &ec external code

Semantics

Data locations can be grouped into two broad categories, buffers and maps.

Maps

Persistent and transient storage are part of the map category, 256 bit keys map to 256 bit values. Both may be written or read one word at a time.

Buffers

Memory, calldata, returndata, internal code, and external code are all linear data buffers. All can be either read to the stack or copied into memory, but only memory can be written or copied to.

NameRead to StackCopy to MemoryWrite
memorytruetruetrue
calldatatruetruefalse
returndatafalsetruefalse
internal codefalsetruefalse
external codefalsetruefalse
Transitions

Transitioning from map to memory buffer is performed by loading each element from the map to the stack and storing each stack item in memory O(N).

Transitioning from memory buffer to a map is performed by loading each element from memory to the stack and storing each stack item in the map O(N).

Transitioning from any other buffer to a map is performed by copying the buffer's data into memory then transitioning the data from memory into the map O(N+1).

Pointer Bit Sizes

Pointers to different data locations consist of different sizes based on the properties of that data location. In depth semantics of each data location are specified in the type system documents.

LocationBit SizeReason
persistent storage256Storage is 256 bit key value hashmap
transient storage256Transient storage is 256 bit key value hashmap
memory32Theoretical maximum memory size does not grow to 0xffffffff
calldata32Theoretical maximum calldata size does not grow to 0xffffffff
returndata32Maximum returndata size is equal to maximum memory size
internal code16Code size is less than 0xffff
external code176Contains 160 bit address and 16 bit code pointer