Compiler toolchain overview
This section introduces the zkEVM LLVM-based compiler toolchain for smart contract languages with Ethereum Virtual Machine (EVM) support. The toolchain works on top of existing compilers and requires their output, which typically includes intermediate representations (IRs), abstract syntax trees (ASTs), and auxiliary contract metadata and documentation.
The toolchain consists of the following:
- High-level source code compilers:
solc
andvyper
. - IR compilers, front ends to LLVM:
zksolc
andzkvyper
. - The LLVM framework with a zkEVM back end which emits zkEVM text assembly.
- The assembler which produces the zkEVM bytecode from text assembly.
- Hardhat plugins which set up the environment.
High-level Source Code Compilers
High-level source code is processed by third-party compilers. These compilers do the following:
- Process and validate the high-level source code.
- Translate the source code into IR and metadata.
- Pass the IR and metadata to our IR compilers via the standard I/O streams.
We are using two high-level source code compilers at the time of writing:
- solc: the official Solidity compiler. For more info, see the latest Solidity documentation.
- vyper: the official Vyper compiler. For more info, see the latest Vyper documentation.
Follow the security considerations and best practices to build smart contracts on ZKsync Era.
IR Compilers
Our toolchain includes LLVM front ends, written in Rust, that process the output of high-level source code compilers:
- zksolc which calls
solc
as a child process. For more info, see the latest zksolc documentation. - zkvyper: which calls
vyper
as a child process. For more info, see the latest zkvyper documentation.
These IR compilers perform the following steps:
- Receive the input, which is usually standard or combined JSON passed by the Hardhat plugin via standard input.
- Save the relevant data, modify the input with zkEVM settings, and pass it to the underlying high-level source code compiler which is called as a child process.
- Receive the IR and metadata from the underlying compiler.
- Translate the IR into LLVM IR, resolving dependencies with the help of metadata.
- Optimize the LLVM IR with the powerful LLVM framework optimizer and emit zkEVM text assembly.
- Print the output matching the format of the input method the IR compiler is called with.
Our IR compilers leverage I/O mechanisms which already exist in the high-level source code compilers. They may modify the input and output to some extent, add data for features unique to zkEVM, and remove unsupported feature artifacts.
Assembler
The assembler, which is written in Rust, compiles zkEVM assembly to zkEVM bytecode. This tool is not a part of our LLVM back end as it uses several cryptographic libraries which are easier to maintain outside of the framework.
Hardhat Plugins
We recommend using our IR compilers via their corresponding Hardhat plugins. Add these plugins to the Hardhat's config file to compile new projects or migrate existing ones to ZKsync Era. For a lower-level approach, download our compiler binaries via the links above and use their CLI interfaces.
Installing and configuring plugins
Add the plugins below to the Hardhat's config file to compile new projects or migrate existing ones to ZKsync Era. For a lower-level approach, download our compiler binaries links above and use their CLI interfaces.