EraVM Target Compilation Specification

This is a technical deep dive into the specifics of compiling for the EraVM target.

The deep dive outlines concepts, modules, and terms used in the EraVM target compilation process, such as:

The following sections provide a detailed specification of compilation of each individual instruction:

Finally, this document describes the binary layout of EraVM bytecode:

Glossary

TermDefinition
zksolcSolidity compiler developed by Matter Labs.
solcHigh-level Solidity compiler developed by the Ethereum community. Called by zksolc to get IRs and other auxiliary data.
LLVMThe world's most popular and powerful compiler framework, used for optimizations and assembly generation.
AssemblerTool that translates assembly to bytecode.
LinkerTool that links dependencies, such as libraries, before final bytecode can be emitted.
Virtual MachineZKsync Era virtual machine with a custom instruction set.
EraVM SpecificationA combination of human readable documentation and formal description of EraVM, including its structure, semantics, and encoding.
IRIntermediate representation used by the compiler internally to represent source code.
YulOne of two Solidity IRs. A superset of assembly available in Solidity. Used by default for contracts written in Solidity ≥0.8.
EVM AssemblyOne of two Solidity IRs. A predecessor of Yul that is closer to EVM bytecode. Used by default for contracts written in Solidity <0.8.
LLVM IRIR native to the LLVM framework.
EraVM AssemblyText representation of EraVM bytecode. Emitted by the LLVM framework. Translated into EraVM bytecode by the EraVM assembler.
EraVM BytecodeContract bytecode executed by EraVM.
StackSegment of non-persistent contract memory. Consists of two parts: global data and function stack frame.
HeapSegment of non-persistent contract memory. Allocation is handled by the solc’s allocator only.
Auxiliary heapSegment of non-persistent contract memory. Introduced to avoid conflicts with the solc’s allocator.
CalldataSegment of non-persistent contract memory. Heap or auxiliary heap of the parent/caller contract.
Return dataSegment of non-persistent contract memory. Heap or auxiliary heap of the child/callee contract.
StoragePersistent contract memory with no important differences from that of EVM.
Transient storageTransient contract memory with no important differences from that of EVM.
System contractsSet of ZKsync kernel contracts written in Solidity by Matter Labs.
Contract contextStorage of the VM keeping data such as current address, caller’s address, block timestamp, etc.