Validium Docs
  • Overview
  • Connect to Validium
  • Start Coding 🚀
    • Quickstart
      • Overview
      • Deploy using Validium CLI
      • Deploy using Quickstart Repository
      • Deploy your first contract
      • Create an ERC20 token
  • Tooling
    • Block Explorers
    • Hardhat-Validium
      • Overview
      • Installation
      • Guides
        • Getting started
        • Migrating Hardhat project to Validium
        • Compiling non-inlinable libraries
      • Plugins
        • hardhat-zksync
        • hardhat-zksync-solc
        • hardhat-zksync-vyper
        • hardhat-zksync-deploy
        • hardhat-zksync-upgradable
        • hardhat-zksync-verify
        • hardhat-zksync-verify-vyper
        • hardhat-zksync-ethers
        • hardhat-zksync-node
        • Hardhat Community Plugins
    • Foundary
      • Overview
      • Installation
      • Getting Started
      • Migration Guide
        • Overview
        • Compilation
        • Deployment
        • Testing
  • Test and Debug
    • Getting Started
    • Docker L1 - L2 Nodes
    • In-Memory Node
    • Continuous Integration
    • Hardhat
    • Foundry
  • API Reference
    • Overview
    • Conventions
    • ZKs JSON-RPC API
    • Debug JSON-RPC API
    • Ethereum JSON-RPC API
    • PubSub JSON-RPC API
  • Concepts
    • Transaction Lifecycle
    • Blocks and Batches
    • Validium Network Fee Mechanism
    • Finality
    • System Upgrades
    • ZK Chains
    • Data Availability
      • Overview
      • Recreating L2 state from L1 pubdata
      • Validiums
    • Account Abstraction
    • L1 <-> L2 Communication
  • Components
    • Overview
    • Smart & System Contracts
      • Smart Contracts
      • System Contracts
    • Shared Bridges
    • Sequencer / Server
    • Validium Network EVM
      • Overview
      • Bootloader
      • Precompiles
      • Virtual Machine Specification
        • ZKsync Virtual Machine primer
        • VM Formal Specification
    • Prover
      • Overview
      • ZK Terminology
      • Running the Prover
      • Circuits
        • Overview
        • Circuit Testing
        • CodeDecommitter
        • DemuxLogQueue
        • ECRecover
        • KeccakRoundFunction
        • L1MessagesHasher
        • LogSorter
        • Main VM
        • RAMPermutation
        • Sha256RoundFunction
        • StorageApplication
        • Sorting and Deduplicating
          • Overview
          • SortDecommitments
          • StorageSorter
          • LogSorter
      • Boojum Gadgets
      • Boojum Function - `check_if_satisfied`
    • Compiler
      • Compiler Toolchain Overview
        • Compiler Toolchain Overview
        • Solidity Compiler
        • Vyper Compiler
        • LLVM Framework
      • Specification
        • Overview
        • Code Separation
        • System Contracts
        • Exception Handling
        • EVM Legacy Assembly Translator
        • Instructions
          • Instruction Reference
          • EVM
            • Native EVM Instructions
            • Arithmetic
            • Bitwise
            • Block
            • Call
            • Create
            • Environment
            • Logging
            • Logical
            • Memory
            • Return
            • Sha3
            • Stack
          • Extensions
            • Overview
            • Validium Network Extension Simulation (call)
            • Validium Network Extension Simulation (verbatim)
          • EVM Legacy Assembly
          • Yul
        • EraVM Binary Layout
    • Fee Withdrawer
    • Portal - Wallet + Bridge
    • Block Explorer
    • Transaction filtering
Powered by GitBook
On this page
  • Environmental Data Storage
  • KECCAK256 Hash Function
  • Contract Deployer
  • Ether Value Simulator
  • Simulator of Immutables
  • Event Handler
  • Auxiliary Heap
  1. Components
  2. Compiler
  3. Specification

System Contracts

PreviousCode SeparationNextException Handling

Last updated 7 months ago


Many EVM instructions require special handling by the System Contracts. Among them are: ORIGIN, CALLVALUE, BALANCE, CREATE, SHA3, and others. To see the full detailed list of instructions that require special handling, see .

There are several types of System Contracts from the perspective of how they are handled by the Validium Network Era compilers:

  1. .

  2. .

  3. .

  4. .

  5. .

  6. .

Environmental Data Storage

Such storage contracts are accessed with static calls in order to retrieve values for the block, transaction, and other environmental entities: CHAINID, DIFFICULTY, BLOCKHASH, etc.

One good example of such contract is that provides the majority of the environmental data.

Since EVM is not using external calls for these instructions, we must use for their calldata.

Steps to handle such instructions:

  1. Store the calldata for the System Contract call on the auxiliary heap.

  2. Call the System Contract with a static call.

  3. Check the return status code of the call.

  4. if the status code is zero.

  5. Read the ABI data and extract the result. All such System Contracts return a single 256-bit value.

  6. Return the value as the result of the original instruction.

KECCAK256 Hash Function

Contract Deployer

Ether Value Simulator

An external call is redirected through the simulator if the following conditions are met:

  1. The Ether value is non-zero.

Calls to the simulator require extra data passed via ABI using registers:

  1. Ether value.

  2. The address of the contract to call.

Passing Ether value in EraVM is implemented by using a combination of:

Simulator of Immutables

Event Handler

  1. The topics with a length-prefix are passed via ABI using registers.

  2. The data is passed via the default heap, like on EVM.

Auxiliary Heap

However, there are several cases where EraVM needs to allocate memory on the heap and EVM does not. The auxiliary heap is used for these cases:

  1. Returning immutables from the constructor.

  2. Allocating calldata and return data for calling the System Contracts.

While the ordinary heap contains calldata and return data for calls to user contracts, auxiliary heap contains calldata and return data for calls to System Contracts. This ensures better compatibility with EVM as users should be able to call EraVM-specific System Contracts in a transparent way, without System Contracts affecting calldata or return data. This prevents situations where calling System Contracts interferes with the heap layout expected by the contract developer.

For reference, see .

Handling of this function is similar to with one difference:

Since EVM also uses heap to store the calldata for KECCAK256, the required memory chunk is allocated by the IR generator, and Validium Network Era compiler does not need to use .

For reference, see .

See and on Validium Network Era documentation.

For reference, see LLVM IR codegen for and .

EraVM does not support passing Ether natively, so this is handled by a special System Contract called .

The has the Ether value parameter.

The , which is only set if a call to the is being redirected, that is CREATE or CREATE2 is called with non-zero Ether.

a special 128-bit register which is a part of the EraVM ;

an captured in the stack frame in a moment of a call.

The process of setting up a value and capturing it is described in details in the section .

For reference, see .

See on Validium Network Era documentation.

For reference, see LLVM IR codegen for and .

Event payloads are sent to a special System Contract called . Like on EVM, the payload consists of topics and data:

For reference, see .

Both and compilers for EraVM operate on , so they cannot control the heap memory allocator which remains a responsibility of emitting the IRs.

For more details on the heaps, refer to the EraVM specification, which describes , their connections to the , and their role in .

the EVM instructions reference
Environmental data storage
KECCAK256 hash function
Contract deployer
Ether value simulator
Simulator of immutables
Event handler
SystemContext
the auxiliary heap
Revert or throw
the LLVM IR codegen source code
Environmental Data Storage
the auxiliary heap
the LLVM IR codegen source code
handling CREATE
dependency code substitution instructions
the deployer call
CREATE-related instructions
MsgValueSimulator
call
system call bit
ContractDeployer
context_u128
transient state
immutable value of context_u128
Context Register of the EraVM specification
the LLVM IR codegen source code
handling immutables
instructions for immutables
RETURN from the deploy code
EventWriter
the LLVM IR codegen source code
zksolc
zkvyper
the IR level
the high-level source code compilers
Returning immutables
types of heaps
stack frames and memory growth
communication between contracts