Compiler toolchain overview
This section introduces an LLVM-based compiler toolchain for Solidity and Vyper. 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 EraVM and EVM back ends.
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 to artifacts, namely IR and metadata.
- Pass the IR and metadata to our IR compilers via stdout using standard JSON I/O.
We are using two high-level source code compilers:
- 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. The front ends 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 a tool such as Foundry or Hardhat via standard input.
- Save the relevant data, modify the input, and pass it to the underlying high-level source code compiler 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 bytecode.
- 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 ZKsync EraVM, and remove unsupported feature artifacts.