Skip to content

Commit

Permalink
feat: adds system contract addresses (#240)
Browse files Browse the repository at this point in the history
<!--

Thank you for contributing to the ZKsync Docs!

Before submitting the PR, please make sure you do the following:

- Update your PR title to follow [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/)
- Read the [Contributing
Guide](https://github.com/matter-labs/zksync-docs/blob/main/CONTRIBUTING.md).
- Understand our [Code of
Conduct](https://github.com/matter-labs/zksync-docs/blob/main/CODE_OF_CONDUCT.md)
- Please delete any unused parts of the template when submitting your PR

-->

# Description
- adds system contract addresses to docs 
- 
<!-- Please describe what are the changes and what they are solving for
in this PR. -->

## Linked Issues
- Closes #140 
<!-- If you have any issues this PR is related to, link them here. -->
<!--
Check out
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
on how to automate linking a GitHub Issue to a PR.
-->

## Additional context

---------

Co-authored-by: Sarah Schwartz <[email protected]>
  • Loading branch information
dutterbutter and sarahschwartz authored Oct 11, 2024
1 parent 348e161 commit 89b8073
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ system upgrade through L1.
The addresses and the interfaces of the L2 system contracts can be found [here](https://github.com/matter-labs/era-contracts/blob/main/system-contracts/contracts/Constants.sol).

## SystemContext
**Address:** <a href="https://explorer.zksync.io/address/0x000000000000000000000000000000000000800b" target="_blank">0x000000000000000000000000000000000000800b</a>

This contract is used to support various system parameters not included in the VM by default, i.e. `chainId`, `origin`,
`ergsPrice`, `blockErgsLimit`, `coinbase`, `difficulty`, `baseFee`, `blockhash`, `block.number`, `block.timestamp.`
Expand All @@ -33,6 +34,7 @@ implementation itself is rather straightforward, but to better understand this c
about the [block processing](/build/developer-reference/batches-and-l2-blocks) on ZKsync.

## AccountCodeStorage
**Address:** <a href="https://explorer.zksync.io/address/0x0000000000000000000000000000000000008002" target="_blank">0x0000000000000000000000000000000000008002</a>

The code hashes of accounts are stored inside the storage of this contract. Whenever a VM calls a contract with address
`address` it retrieves the value under storage slot `address` of this system contract, if this value is non-zero, it
Expand All @@ -49,6 +51,7 @@ without the `isConstructor` flag, the bytecode of the default account (i.e. EOA
original bytecode.

## BootloaderUtilities
**Address:** <a href="https://explorer.zksync.io/address/0x000000000000000000000000000000000000800c" target="_blank">0x000000000000000000000000000000000000800c</a>

This contract contains some of the methods which are needed purely for the bootloader functionality but were moved out
from the bootloader itself for the convenience of not writing this logic in Yul.
Expand All @@ -65,6 +68,7 @@ wallet users and contracts that call it, i.e. it should not be distinguishable
Ethereum.

## Ecrecover
**Address:** <a href="https://explorer.zksync.io/address/0x0000000000000000000000000000000000000001" target="_blank">0x0000000000000000000000000000000000000001</a>

The implementation of the ecrecover precompile. It is expected to be used frequently, so written in pure yul with a
custom memory layout.
Expand All @@ -80,6 +84,7 @@ It also validates the input by the same rules as the EVM precompile:
After that, it makes a precompile call and returns empty bytes if the call failed, and the recovered address otherwise.

## Empty contracts
**Address:** <a href="https://explorer.zksync.io/address/0x0000000000000000000000000000000000000000" target="_blank">0x0000000000000000000000000000000000000000</a>

Some of the contracts are relied upon to have EOA-like behaviour, i.e. they can be always called and get the success
value in return. An example of such address is 0 address. We also require the bootloader to be callable so that the
Expand All @@ -89,6 +94,9 @@ For these contracts, we insert the `EmptyContract` code upon genesis. It is basi
and returns `success=1`.

## SHA256 & Keccak256
**SHA256 Address:** <a href="https://explorer.zksync.io/address/0x0000000000000000000000000000000000000002" target="_blank">0x0000000000000000000000000000000000000002</a>

**Keccak256 Address:** <a href="https://explorer.zksync.io/address/0x0000000000000000000000000000000000008010" target="_blank">0x0000000000000000000000000000000000008010</a>

Note that, unlike Ethereum, keccak256 is a precompile (_not an opcode_) on ZKsync.

Expand All @@ -105,6 +113,9 @@ the crypto part of the precompiles expects to work with padded data. This means
to an unprovable transaction.

## L2BaseToken & MsgValueSimulator
**L2BaseToken Address:** <a href="https://explorer.zksync.io/address/0x000000000000000000000000000000000000800a" target="_blank">0x000000000000000000000000000000000000800a</a>

**MsgValueSimulator Address:** <a href="https://explorer.zksync.io/address/0x0000000000000000000000000000000000008009" target="_blank">0x0000000000000000000000000000000000008009</a>

Unlike Ethereum, zkEVM does not have any notion of any special native token. That’s why we have to simulate operations
with Ether via two contracts: `L2BaseToken` & `MsgValueSimulator`.
Expand All @@ -121,6 +132,7 @@ Whenever anyone wants to do a non-zero value call, they need to call `MsgValueSi
- Pass the address of the callee in the second extraAbiParam.

## KnownCodeStorage
**Address:** <a href="https://explorer.zksync.io/address/0x0000000000000000000000000000000000008004" target="_blank">0x0000000000000000000000000000000000008004</a>

This contract is used to store whether a certain code hash is “known”, i.e. can be used to deploy contracts. On ZKsync,
the L2 stores the contract’s code _hashes_ and not the codes themselves. Therefore, it must be part of the protocol to
Expand All @@ -143,6 +155,7 @@ those code hashes that are known.
The KnownCodesStorage contract is also responsible for ensuring that all the “known” bytecode hashes are also valid.

## ContractDeployer & ImmutableSimulator
**Address:** <a href="https://explorer.zksync.io/address/0x0000000000000000000000000000000000008006" target="_blank">0x0000000000000000000000000000000000008006</a>

`ContractDeployer` is a system contract responsible for deploying contracts on ZKsync. It is better to understand how it
works in the context of how the contract deployment works on ZKsync. Unlike Ethereum, where `create`/`create2` are
Expand Down Expand Up @@ -216,6 +229,7 @@ struct ImmutableData {
basically denoting an array of immutables passed to the contract.

### **Immutables**
**Address:** <a href="https://explorer.zksync.io/address/0x0000000000000000000000000000000000008005" target="_blank">0x0000000000000000000000000000000000008005</a>

Immutables are stored in the `ImmutableSimulator` system contract. The way how `index` of each immutable is defined is
part of the compiler specification. This contract treats it simply as mapping from index to value for each particular
Expand All @@ -240,6 +254,7 @@ are not in kernel space and have no contract deployed on them. This address:
`success = 1, returndatasize = 0` for calls from anyone except for the bootloader.

## L1Messenger
**Address:** <a href="https://explorer.zksync.io/address/0x0000000000000000000000000000000000008008" target="_blank">0x0000000000000000000000000000000000008008</a>

A contract used for sending arbitrary length L2→L1 messages from ZKsync to L1. While ZKsync natively supports a rather
limited number of L1→L2 logs, which can transfer only roughly 64 bytes of data a time, we allowed sending
Expand All @@ -255,6 +270,7 @@ The `L1Messenger` is also responsible for validating the total pubdata to be sen
- L1Messenger [Interface](https://github.com/matter-labs/era-contracts/blob/main/system-contracts/contracts/interfaces/IL1Messenger.sol)

## NonceHolder
**Address:** [0x0000000000000000000000000000000000008003](https://explorer.zksync.io/address/0x0000000000000000000000000000000000008003)

Serves as storage for nonces for our accounts. Besides making it easier for operator to order transactions (i.e. by
reading the current nonces of account), it also serves a separate purpose: making sure that the pair (address, nonce) is
Expand Down Expand Up @@ -282,6 +298,7 @@ transactions in the mempool.
- NonceHolder [Interface](https://github.com/matter-labs/era-contracts/blob/main/system-contracts/contracts/interfaces/INonceHolder.sol)

## EventWriter
**Address:** [0x000000000000000000000000000000000000800d](https://explorer.zksync.io/address/0x000000000000000000000000000000000000800d)

A system contract responsible for emitting events.

Expand All @@ -291,6 +308,7 @@ Generally, the users should not interact with this contract directly, but only t
events.

## Compressor
**Address:** [0x000000000000000000000000000000000000800e](https://explorer.zksync.io/address/0x000000000000000000000000000000000000800e)

One of the most expensive resource for a rollup is data availability, so in order to reduce costs for the users we
compress the published pubdata in several ways:
Expand Down

0 comments on commit 89b8073

Please sign in to comment.