EIP-7480 · Stagnant · Core · 2023-08-11
EIP-7480: EOF - Data section access instructions
Adds DATALOAD, DATALOADN, DATASIZE and DATACOPY so EOF contracts can read constants from their data section, replacing CODECOPY-style tricks that EOF forbids.
What problem does it solve?
The EVM Object Format (EOF, EIP-3540) splits a contract into separate code and data sections. Legacy contracts often stored constants or blobs in their bytecode and read them with CODECOPY / CODESIZE. EOF deliberately bans those code-introspection opcodes, so contracts need a new, explicit way to read their own data section.
EIP-7480 provides that: four instructions, modelled on the existing calldata and returndata opcodes, that read only from the data section.
How it works
The instructions are valid only inside EOF code. In legacy bytecode they cause an exceptional halt, which matches existing behaviour for undefined opcodes.
| Opcode | Name | Stack | Gas | Behaviour |
|---|---|---|---|---|
0xd0 |
DATALOAD |
offset → word |
4 | Load 32 bytes from data[offset:offset+32]; bytes past the end read as 0 |
0xd1 |
DATALOADN |
→ word |
3 | Same, but offset is a 16-bit big-endian immediate |
0xd2 |
DATASIZE |
→ size |
2 | Push the size of the data section |
0xd3 |
DATACOPY |
mem_offset, offset, size → |
3 + 3 per word + memory expansion | Copy a slice of data to memory; zero-pad past the end |
DATALOADN is cheaper because its offset is fixed at compile time and is checked once during code validation (EIP-3670 rules are extended):
- a
DATALOADNwhoseoffset + 32exceeds the data size declared in the container header makes the code invalid; - relative jumps (
RJUMP,RJUMPI,RJUMPV) may not land inside the two immediate bytes that followDATALOADN.
Out-of-bounds reads pad with zeros rather than failing, so compilers can safely remove unused copies without changing behaviour.
Sample code
Illustrative EOF code-section fragment (mnemonics with their encoding):
d1 0000 DATALOADN 0x0000 ; push data[0:32] (offset checked at deploy time)
d1 0020 DATALOADN 0x0020 ; push data[32:64]
01 ADD ; add the two constants
d2 DATASIZE ; push data section length
5f PUSH0 ; offset = 0 in data
5f PUSH0 ; mem_offset = 0
d3 DATACOPY ; copy data[0:size] to memory[0:]
; (stack before DATACOPY: mem_offset, offset, size)
Things to know
- Status: Stagnant. EIP-7480 was part of the EOF bundle tracked in EIP-7692, which is also Stagnant. EOF was not included in the Pectra or Fusaka upgrades, so these opcodes are not live on Ethereum mainnet.
- There is intentionally no
EXTDATACOPY: one contract cannot read another EOF contract's data section. "Data-only contracts" read viaEXTCODECOPYare therefore discouraged under EOF. - The opcode numbers above come from the spec and could change if EOF is revived in a different form.