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
  • ADDRESS
  • BALANCE
  • ORIGIN
  • CALLER
  • CALLVALUE
  • CALLDATALOAD
  • CALLDATASIZE
  • CALLDATACOPY
  • CODECOPY
  • CODESIZE
  • GASPRICE
  • EXTCODESIZE
  • EXTCODECOPY
  • RETURNDATASIZE
  • RETURNDATACOPY
  • EXTCODEHASH
  1. Components
  2. Compiler
  3. Specification
  4. Instructions
  5. EVM

Environment

PreviousCreateNextLogging

Last updated 8 months ago


ADDRESS

Original instruction.

This value is fetched with a native .

LLVM IR

is common for Yul and EVMLA representations.

BALANCE

Original instruction.

System Contract

This information is requested a System Contract called .

On how the System Contract is called, see .

LLVM IR

is common for Yul and EVMLA representations.

The request to the System Contract is done via the runtime function.

ORIGIN

System Contract

LLVM IR

CALLER

LLVM IR

CALLVALUE

LLVM IR

CALLDATALOAD

Calldata is accessed with a generic memory access instruction, but the memory chunk itself is a reference to the calling contract's heap. A fat pointer to the parent contract is passed via ABI using registers.

LLVM IR

@ptr_calldata = private unnamed_addr global ptr addrspace(3) null                   ; global variable declaration
...
store ptr addrspace(3) %0, ptr @ptr_calldata, align 32                              ; saving the pointer from `r1` to the global variable
...
%calldata_pointer = load ptr addrspace(3), ptr @ptr_calldata, align 32              ; loading the pointer from the global variable to `calldata_pointer`
%calldata_value = load i256, ptr addrspace(3) %calldata_pointer, align 32           ; loading the value from the calldata pointer

EraVM Assembly

ptr.add r1, r0, stack[@ptr_calldata]                                                ; saving the pointer from `r1` to the global variable
...
ptr.add stack[@ptr_calldata], r0, r1                                                ; loading the pointer from the global variable to `r1`
ld      r1, r1                                                                      ; loading the value to `r1`

CALLDATASIZE

The size value can be extracted with bitwise operations as illustrated below.

LLVM IR

@calldatasize = private unnamed_addr global i256 0                                  ; global variable declaration
...
%abi_pointer_value = ptrtoint ptr addrspace(3) %0 to i256                           ; converting the pointer to an integer
%abi_pointer_value_shifted = lshr i256 %abi_pointer_value, 96                       ; shifting the integer right 96 bits
%abi_length_value = and i256 %abi_pointer_value_shifted, 4294967295                 ; keeping the lowest 32 bits of the integer
store i256 %abi_length_value, ptr @calldatasize, align 32                           ; saving the value to the global variable

EraVM Assembly

ptr.add r1, r0, stack[@ptr_calldata]                                                ; saving the pointer from `r1` to the global variable
shr.s   96, r1, r1                                                                  ; shifting the integer right 96 bits
and     @CPI0_0[0], r1, stack[@calldatasize]                                        ; keeping the lowest 32 bits of the integer, saving the value to the global variable
...
CPI0_0:
    .cell 4294967295

CALLDATACOPY

LLVM IR

; loading the pointer from the global variable to `calldata_pointer`
%calldata_pointer = load ptr addrspace(3), ptr @ptr_calldata, align 32
; shifting the pointer by 122 bytes
%calldata_source_pointer = getelementptr i8, ptr addrspace(3) %calldata_pointer, i256 122
; copying 64 bytes from calldata at offset 122 to the heap at offset 128
call void @llvm.memcpy.p1.p3.i256(ptr addrspace(1) align 1 inttoptr (i256 128 to ptr addrspace(1)), ptr addrspace(3) align 1 %calldata_source_pointer, i256 64, i1 false)

EraVM Assembly

.BB0_3:
    shl.s   5, r2, r3           ; shifting the offset by 32
    ptr.add r1, r3, r4          ; adding the offset to the calldata pointer
    ld      r4, r4              ; reading the calldata value
    add     128, r3, r3         ; adding the offset to the heap pointer
    st.1    r3, r4              ; writing the calldata value to the heap
    add     1, r2, r2           ; incrementing the offset
    sub.s!  2, r2, r3           ; checking the bounds
    jump.lt @.BB0_3             ; loop continuation branching

CODECOPY

CODESIZE

GASPRICE

System Contract

LLVM IR

EXTCODESIZE

System Contract

LLVM IR

EXTCODECOPY

Not supported. Triggers a compile-time error.

RETURNDATASIZE

Return data size is read from the fat pointer returned from the child contract.

The size value can be extracted with bitwise operations as illustrated below.

LLVM IR

%contract_call_external = tail call { ptr addrspace(3), i1 } @__farcall(i256 0, i256 0, i256 undef, i256 undef, i256 undef, i256 undef, i256 undef, i256 undef, i256 undef, i256 undef, i256 undef, i256 undef)
%contract_call_external_result_abi_data = extractvalue { ptr addrspace(3), i1 } %contract_call_external, 0
%contract_call_memcpy_from_child_pointer_casted = ptrtoint ptr addrspace(3) %contract_call_external_result_abi_data to i256
%contract_call_memcpy_from_child_return_data_size_shifted = lshr i256 %contract_call_memcpy_from_child_pointer_casted, 96
%contract_call_memcpy_from_child_return_data_size_truncated = and i256 %contract_call_memcpy_from_child_return_data_size_shifted, 4294967295

EraVM Assembly

near_call       r0, @__farcall, @DEFAULT_UNWIND                 ; calling a child contract
shr.s   96, r1, r1                                              ; shifting the pointer value right 96 bits
and     @CPI0_1[0], r1, r1                                      ; keeping the lowest 32 bits of the pointer value
...
CPI0_1:
    .cell 4294967295

RETURNDATACOPY

Unlike on EVM, on EraVM it is a simple loop over memory operations on 256-bit values.

LLVM IR

; loading the pointer from the global variable to `return_data_pointer`
%return_data_pointer = load ptr addrspace(3), ptr @ptr_return_data, align 32
; shifting the pointer by 122 bytes
%return_data_source_pointer = getelementptr i8, ptr addrspace(3) %return_data_pointer, i256 122
; copying 64 bytes from return data at offset 122 to the heap at offset 128
call void @llvm.memcpy.p1.p3.i256(ptr addrspace(1) align 1 inttoptr (i256 128 to ptr addrspace(1)), ptr addrspace(3) align 1 %return_data_source_pointer, i256 64, i1 false)

EraVM Assembly

.BB0_3:
    shl.s   5, r2, r3           ; shifting the offset by 32
    ptr.add r1, r3, r4          ; adding the offset to the return data pointer
    ld      r4, r4              ; reading the return data value
    add     128, r3, r3         ; adding the offset to the heap pointer
    st.1    r3, r4              ; writing the return data value to the heap
    add     1, r2, r2           ; incrementing the offset
    sub.s!  2, r2, r3           ; checking the bounds
    jump.lt @.BB0_3             ; loop continuation branching

EXTCODEHASH

System Contract

LLVM IR

Original instruction.

This information is requested a System Contract called .

On how the System Contract is called, see .

is common for Yul and EVMLA representations.

The request to the System Contract is done via the runtime function.

Original instruction.

This value is fetched with a native .

is common for Yul and EVMLA representations.

Original instruction.

This value is fetched with a native .

is common for Yul and EVMLA representations.

Original instruction.

Then, the pointer accessible from anywhere in the contract.

is common for Yul and EVMLA representations.

Original instruction.

Calldata size is stored in the fat pointer passed from the parent contract (see ).

is common for Yul and EVMLA representations.

Original instruction.

Unlike on EVM, on EraVM it is a simple loop over ).

is common for Yul and EVMLA representations.

Original instruction.

See .

.

Original instruction.

See .

.

Original instruction.

This information is requested a System Contract called .

On how the System Contract is called, see .

is common for Yul and EVMLA representations.

The request to the System Contract is done via the runtime function.

Original instruction.

This information is requested a System Contract called .

On how the System Contract is called, see .

is common for Yul and EVMLA representations.

The request to the System Contract is done via the runtime function.

Original instruction.

Original instruction.

is common for Yul and EVMLA representations.

Original instruction.

is common for Yul and EVMLA representations.

Original instruction.

This information is requested a System Contract called .

On how the System Contract is called, see .

is common for Yul and EVMLA representations.

The request to the System Contract is done via the runtime function.

EVM
EraVM instruction: context.this
The LLVM IR generator code
EVM
L2BaseToken
this section
The LLVM IR generator code
SystemRequest
EVM
SystemContext
this section
The LLVM IR generator code
SystemRequest
EVM
EraVM instruction: context.caller
The LLVM IR generator code
EVM
EraVM instruction: context.get_context_u128
The LLVM IR generator code
EVM
is saved to a global stack variable
The LLVM IR generator code
EraVM instruction: ptr.add
EraVM fat pointers
EraVM memory forwarding mechanism
EVM
CALLDATALOAD
The LLVM IR generator code
EraVM instruction: ptr.add
EraVM fat pointers
EraVM memory forwarding mechanism
EVM
CALLDATALOAD
The LLVM IR generator code
EraVM instruction: ptr.add
EraVM fat pointers
EraVM memory forwarding mechanism
EVM
the EraVM docs
The LLVM IR generator code
EVM
the EraVM docs
The LLVM IR generator code
EVM
SystemContext
this section
The LLVM IR generator code
SystemRequest
EVM
AccountCodeStorage
this section
The LLVM IR generator code
SystemRequest
EVM
EVM
The LLVM IR generator code
EraVM instruction: call
EVM
The LLVM IR generator code
EraVM instruction: jump
EraVM instruction predication
EVM
AccountCodeStorage
this section
The LLVM IR generator code
SystemRequest