Constants

Git Source

SYSTEM_CONTRACTS_OFFSET

All the system contracts introduced by ZKsync have their addresses started from 2^15 in order to avoid collision with Ethereum precompiles.

uint160 constant SYSTEM_CONTRACTS_OFFSET = 0x8000;

REAL_SYSTEM_CONTRACTS_OFFSET

Unlike the value above, it is not overridden for the purpose of testing and is identical to the constant value actually used as the system contracts offset on mainnet.

uint160 constant REAL_SYSTEM_CONTRACTS_OFFSET = 0x8000;

MAX_SYSTEM_CONTRACT_ADDRESS

All the system contracts must be located in the kernel space, i.e. their addresses must be below 2^16.

uint160 constant MAX_SYSTEM_CONTRACT_ADDRESS = 0xffff;

USER_CONTRACTS_OFFSET

The offset from which the built-in, but user space contracts are located.

uint160 constant USER_CONTRACTS_OFFSET = MAX_SYSTEM_CONTRACT_ADDRESS + 1;

ECRECOVER_SYSTEM_CONTRACT

address constant ECRECOVER_SYSTEM_CONTRACT = address(0x01);

SHA256_SYSTEM_CONTRACT

address constant SHA256_SYSTEM_CONTRACT = address(0x02);

IDENTITY_SYSTEM_CONTRACT

address constant IDENTITY_SYSTEM_CONTRACT = address(0x04);

MODEXP_SYSTEM_CONTRACT

address constant MODEXP_SYSTEM_CONTRACT = address(0x05);

ECADD_SYSTEM_CONTRACT

address constant ECADD_SYSTEM_CONTRACT = address(0x06);

ECMUL_SYSTEM_CONTRACT

address constant ECMUL_SYSTEM_CONTRACT = address(0x07);

ECPAIRING_SYSTEM_CONTRACT

address constant ECPAIRING_SYSTEM_CONTRACT = address(0x08);

COMPUTATIONAL_PRICE_FOR_PUBDATA

*The number of gas that need to be spent for a single byte of pubdata regardless of the pubdata price. This variable is used to ensure the following:

  • That the long-term storage of the operator is compensated properly.
  • That it is not possible that the pubdata counter grows too high without spending proportional amount of computation.*
uint256 constant COMPUTATIONAL_PRICE_FOR_PUBDATA = 80;

CURRENT_MAX_PRECOMPILE_ADDRESS

*The maximal possible address of an L1-like precompie. These precompiles maintain the following properties:

  • Their extcodehash is EMPTY_STRING_KECCAK
  • Their extcodesize is 0 despite having a bytecode formally deployed there.*
uint256 constant CURRENT_MAX_PRECOMPILE_ADDRESS = 0xff;

BOOTLOADER_FORMAL_ADDRESS

address payable constant BOOTLOADER_FORMAL_ADDRESS =
  payable(address(SYSTEM_CONTRACTS_OFFSET + 0x01));

ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT

IAccountCodeStorage constant ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT =
  IAccountCodeStorage(address(SYSTEM_CONTRACTS_OFFSET + 0x02));

NONCE_HOLDER_SYSTEM_CONTRACT

INonceHolder constant NONCE_HOLDER_SYSTEM_CONTRACT =
  INonceHolder(address(SYSTEM_CONTRACTS_OFFSET + 0x03));

KNOWN_CODE_STORAGE_CONTRACT

IKnownCodesStorage constant KNOWN_CODE_STORAGE_CONTRACT =
  IKnownCodesStorage(address(SYSTEM_CONTRACTS_OFFSET + 0x04));

IMMUTABLE_SIMULATOR_SYSTEM_CONTRACT

IImmutableSimulator constant IMMUTABLE_SIMULATOR_SYSTEM_CONTRACT =
  IImmutableSimulator(address(SYSTEM_CONTRACTS_OFFSET + 0x05));

DEPLOYER_SYSTEM_CONTRACT

IContractDeployer constant DEPLOYER_SYSTEM_CONTRACT =
  IContractDeployer(address(SYSTEM_CONTRACTS_OFFSET + 0x06));

REAL_DEPLOYER_SYSTEM_CONTRACT

IContractDeployer constant REAL_DEPLOYER_SYSTEM_CONTRACT =
  IContractDeployer(address(REAL_SYSTEM_CONTRACTS_OFFSET + 0x06));

FORCE_DEPLOYER

address constant FORCE_DEPLOYER = address(SYSTEM_CONTRACTS_OFFSET + 0x07);

L1_MESSENGER_CONTRACT

IL1Messenger constant L1_MESSENGER_CONTRACT =
  IL1Messenger(address(SYSTEM_CONTRACTS_OFFSET + 0x08));

MSG_VALUE_SYSTEM_CONTRACT

address constant MSG_VALUE_SYSTEM_CONTRACT =
  address(SYSTEM_CONTRACTS_OFFSET + 0x09);

BASE_TOKEN_SYSTEM_CONTRACT

IBaseToken constant BASE_TOKEN_SYSTEM_CONTRACT =
  IBaseToken(address(SYSTEM_CONTRACTS_OFFSET + 0x0a));

REAL_BASE_TOKEN_SYSTEM_CONTRACT

IBaseToken constant REAL_BASE_TOKEN_SYSTEM_CONTRACT =
  IBaseToken(address(REAL_SYSTEM_CONTRACTS_OFFSET + 0x0a));

SYSTEM_CONTEXT_CONTRACT

ISystemContext constant SYSTEM_CONTEXT_CONTRACT =
  ISystemContext(payable(address(SYSTEM_CONTRACTS_OFFSET + 0x0b)));

REAL_SYSTEM_CONTEXT_CONTRACT

ISystemContext constant REAL_SYSTEM_CONTEXT_CONTRACT =
  ISystemContext(payable(address(REAL_SYSTEM_CONTRACTS_OFFSET + 0x0b)));

BOOTLOADER_UTILITIES

IBootloaderUtilities constant BOOTLOADER_UTILITIES =
  IBootloaderUtilities(address(SYSTEM_CONTRACTS_OFFSET + 0x0c));

EVENT_WRITER_CONTRACT

address constant EVENT_WRITER_CONTRACT = address(SYSTEM_CONTRACTS_OFFSET + 0x0d);

COMPRESSOR_CONTRACT

ICompressor constant COMPRESSOR_CONTRACT =
  ICompressor(address(SYSTEM_CONTRACTS_OFFSET + 0x0e));

COMPLEX_UPGRADER_CONTRACT

IComplexUpgrader constant COMPLEX_UPGRADER_CONTRACT =
  IComplexUpgrader(address(SYSTEM_CONTRACTS_OFFSET + 0x0f));

KECCAK256_SYSTEM_CONTRACT

address constant KECCAK256_SYSTEM_CONTRACT = address(0x8010);

PUBDATA_CHUNK_PUBLISHER

IPubdataChunkPublisher constant PUBDATA_CHUNK_PUBLISHER =
  IPubdataChunkPublisher(address(SYSTEM_CONTRACTS_OFFSET + 0x11));

CODE_ORACLE_SYSTEM_CONTRACT

address constant CODE_ORACLE_SYSTEM_CONTRACT =
  address(SYSTEM_CONTRACTS_OFFSET + 0x12);

EVM_GAS_MANAGER

address constant EVM_GAS_MANAGER = address(SYSTEM_CONTRACTS_OFFSET + 0x13);

EVM_PREDEPLOYS_MANAGER

address constant EVM_PREDEPLOYS_MANAGER =
  address(SYSTEM_CONTRACTS_OFFSET + 0x14);

EVM_HASHES_STORAGE

IEvmHashesStorage constant EVM_HASHES_STORAGE =
  IEvmHashesStorage(address(SYSTEM_CONTRACTS_OFFSET + 0x15));

L2_CREATE2_FACTORY

ICreate2Factory constant L2_CREATE2_FACTORY =
  ICreate2Factory(address(USER_CONTRACTS_OFFSET));

L2_ASSET_ROUTER

address constant L2_ASSET_ROUTER = address(USER_CONTRACTS_OFFSET + 0x03);

L2_BRIDGE_HUB

IBridgehub constant L2_BRIDGE_HUB =
  IBridgehub(address(USER_CONTRACTS_OFFSET + 0x02));

L2_NATIVE_TOKEN_VAULT_ADDR

address constant L2_NATIVE_TOKEN_VAULT_ADDR =
  address(USER_CONTRACTS_OFFSET + 0x04);

L2_MESSAGE_ROOT

IMessageRoot constant L2_MESSAGE_ROOT =
  IMessageRoot(address(USER_CONTRACTS_OFFSET + 0x05));

SLOAD_CONTRACT_ADDRESS

address constant SLOAD_CONTRACT_ADDRESS = address(USER_CONTRACTS_OFFSET + 0x06);

WRAPPED_BASE_TOKEN_IMPL_ADDRESS

address constant WRAPPED_BASE_TOKEN_IMPL_ADDRESS =
  address(USER_CONTRACTS_OFFSET + 0x07);

MSG_VALUE_SIMULATOR_IS_SYSTEM_BIT

If the bitwise AND of the extraAbi[2] param when calling the MSG_VALUE_SIMULATOR is non-zero, the call will be assumed to be a system one.

uint256 constant MSG_VALUE_SIMULATOR_IS_SYSTEM_BIT = 1;

MAX_MSG_VALUE

The maximal msg.value that context can have

uint256 constant MAX_MSG_VALUE = type(uint128).max;

CREATE2_PREFIX

Prefix used during derivation of account addresses using CREATE2

keccak256("zksyncCreate2")

bytes32 constant CREATE2_PREFIX =
  0x2020dba91b30cc0006188af794c2fb30dd8520db7e2c088b7fc7c103c00ca494;

CREATE_PREFIX

Prefix used during derivation of account addresses using CREATE

keccak256("zksyncCreate")

bytes32 constant CREATE_PREFIX =
  0x63bae3a9951d38e8a3fbb7b70909afc1200610fc5bc55ade242f815974674f23;

CREATE2_EVM_PREFIX

Prefix used during derivation of account addresses using CREATE2 within the EVM

bytes1 constant CREATE2_EVM_PREFIX = 0xff;

STATE_DIFF_ENTRY_SIZE

Each state diff consists of 156 bytes of actual data and 116 bytes of unused padding, needed for circuit efficiency.

uint256 constant STATE_DIFF_ENTRY_SIZE = 272;

L2_TO_L1_LOGS_MERKLE_TREE_LEAVES

The number of leaves in the L2->L1 log Merkle tree. While formally a tree of any length is acceptable, the node supports only a constant length of 16384 leaves.

uint256 constant L2_TO_L1_LOGS_MERKLE_TREE_LEAVES = 16_384;

DERIVED_KEY_LENGTH

The length of the derived key in bytes inside compressed state diffs.

uint256 constant DERIVED_KEY_LENGTH = 32;

ENUM_INDEX_LENGTH

The length of the enum index in bytes inside compressed state diffs.

uint256 constant ENUM_INDEX_LENGTH = 8;

VALUE_LENGTH

The length of value in bytes inside compressed state diffs.

uint256 constant VALUE_LENGTH = 32;

COMPRESSED_INITIAL_WRITE_SIZE

The length of the compressed initial storage write in bytes.

uint256 constant COMPRESSED_INITIAL_WRITE_SIZE =
  DERIVED_KEY_LENGTH + VALUE_LENGTH;

COMPRESSED_REPEATED_WRITE_SIZE

The length of the compressed repeated storage write in bytes.

uint256 constant COMPRESSED_REPEATED_WRITE_SIZE =
  ENUM_INDEX_LENGTH + VALUE_LENGTH;

INITIAL_WRITE_STARTING_POSITION

The position from which the initial writes start in the compressed state diffs.

uint256 constant INITIAL_WRITE_STARTING_POSITION = 4;

STATE_DIFF_DERIVED_KEY_OFFSET

Each storage diffs consists of the following elements: [20bytes address][32bytes key][32bytes derived key][8bytes enum index][32bytes initial value][32bytes final value]

The offset of the derived key in a storage diff.

uint256 constant STATE_DIFF_DERIVED_KEY_OFFSET = 52;

STATE_DIFF_ENUM_INDEX_OFFSET

The offset of the enum index in a storage diff.

uint256 constant STATE_DIFF_ENUM_INDEX_OFFSET = 84;

STATE_DIFF_FINAL_VALUE_OFFSET

The offset of the final value in a storage diff.

uint256 constant STATE_DIFF_FINAL_VALUE_OFFSET = 124;

BLOB_SIZE_BYTES

Total number of bytes in a blob. Blob = 4096 field elements * 31 bytes per field element

EIP-4844 defines it as 131_072 but we use 4096 * 31 within our circuits to always fit within a field element

Our circuits will prove that a EIP-4844 blob and our internal blob are the same.

uint256 constant BLOB_SIZE_BYTES = 126_976;

MAX_NUMBER_OF_BLOBS

Max number of blobs currently supported

uint256 constant MAX_NUMBER_OF_BLOBS = 6;

ERA_VM_BYTECODE_FLAG

Marker of EraVM bytecode

uint8 constant ERA_VM_BYTECODE_FLAG = 1;

EVM_BYTECODE_FLAG

Marker of EVM bytecode

uint8 constant EVM_BYTECODE_FLAG = 2;

SERVICE_CALL_PSEUDO_CALLER

address constant SERVICE_CALL_PSEUDO_CALLER =
  0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF;