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:

  1. High-level source code compilers: solc and vyper.
  2. IR compilers, front ends to LLVM: zksolc and zkvyper.
  3. The LLVM framework with EraVM and EVM back ends.

Compiler Toolchain Visualization

High-level Source Code Compilers

High-level source code is processed by third-party compilers. These compilers do the following:

  1. Process and validate the high-level source code.
  2. Translate the source code to artifacts, namely IR and metadata.
  3. 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:

Security and best practices:
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:

These IR compilers perform the following steps:

  1. Receive the input, which is usually standard or combined JSON passed by a tool such as Foundry or Hardhat via standard input.
  2. Save the relevant data, modify the input, and pass it to the underlying high-level source code compiler called as a child process.
  3. Receive the IR and metadata from the underlying compiler.
  4. Translate the IR into LLVM IR, resolving dependencies with the help of metadata.
  5. Optimize the LLVM IR with the powerful LLVM framework optimizer and emit bytecode.
  6. 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.


Made with ❤️ by the ZKsync Community