zksync-era
zksync-era copied to clipboard
feat: Validium mode
NOTE: This PR is the Validium base working branch.
Changes
The commits are self-explanatory, so I'll list them and briefly describe what has been made on them.
- Add Validium mode example. This is a binary that implements an example that will be used for testing things out in both modes.
- Use Ethereum's L1 gas price. To have more precise results, we're altering the gas costs for mainnet ones, Ethereum's L1 gas cost is between ~35-47 Gwei, and in zkSync mainnet the L2 fair gas price si 0.1 Gwei (the latter is untouched as it is already set).
-
Add --validium-mode flag to zk init command. This changes allow the system to run in Validium mode, spreading out the flag thought the codebase where it is necessary, and also setting the environmental variable for later
era-contracts
andzksync_server
use. -
Do not construct the pubdata in Validium mode. In Validium mode we do not want to send the pubdata to L1, our workaround on this for the PoC is to not construct it. For that, we read the
VALIDIUM_MODE
env set by theinit.ts
step. -
Do not charge for pubdata in Validium mode. In Validium mode we also do not want to charge the user for pubdata, for that, thanks to the new fee model (V2) most of the changes can be done in the
chain.toml
file but one, this isl1_pubdata_price
, which when set to 0 gives a huge gas use improvement in addition to the said config (yes, said config impacts the gas used by its own, settingl1_pubdata_price
to 0 lowers more the gas usage).
Testing scenario
For comparing results between Rollup and Validium mode we are running the validium_mode_example
binary with the system initialized both with zk init
and zk init --validium-mode
and running the server with zk server
.
The validium_mode_example
binary deposits some ETH to an account which will be used to deploy an ERC20 contract that is going to be called twice, for minting and transferring. For every mentioned action, some useful data like the transaction hash gas used will be printed to the stdout for later analysis.
In parallel, we are also using a debugging tool developed by Marcin that displays batch info. It is very useful to see data like L2 -> L1 messages, Large L2 -> L1 messages, Published bytecodes, and writes to the storage. As a TLDR, it is a server from which you can query batches by number and analyze said data. It's easy to know in which batch a transaction has been added with the eth_getTransactionByHash
method.
In the section below you'll find a step-by-step guide to run said test scenario and see the results by yourself
Step-by-step
For running the example in Rollup mode
- Run
zk && zk clean --all && zk init
to initialize the system in Rollup mode in a clear environment. - Run
zk server
to run the server in one console. - Run
cargo run --release --bin validium_mode_example
to run the Validium mode example in another console. - To run the Batch Status app
- Clone https://github.com/mm-zk/zksync_tools and
cd
into it. - Run
python3 operator/app.py
. - Go to
http://127.0.0.1:5000
in your browser. - Query by
/batch/<batch_number>
- Clone https://github.com/mm-zk/zksync_tools and
For running the example in Validium mode
- Run
zk && zk clean --all && zk init --validium-mode
to initialize the system in Validium mode in a clear environment. - Run
zk server
to run the server in one console. - Run
cargo run --release --bin validium_mode_example
to run the Validium mode example in another console. - To run the Batch Status app
- Clone https://github.com/mm-zk/zksync_tools and
cd
into it. - Run
python3 operator/app.py
. - Go to
http://127.0.0.1:5000
in your browser. - Query by
/batch/<batch_number>
- Clone https://github.com/mm-zk/zksync_tools and
Results
Config:
Rollup | Validium | |
---|---|---|
max_pubdata_per_batch |
120.000 | 1.000.000.000.000 |
pubdata_overhead_part |
0.7 | 0 |
compute_overhead_part |
0.5 | 1 |
batch_overhead_l1_gas |
1.000.000 | 1.000.000 |
internal_enforced_l1_gas_price |
45.000.000.000 | 45.000.000.000 |
Fee Model | Gas Used | Ratio | Gas used Improvement | ||
---|---|---|---|---|---|
V1 | Transaction | Rollup Mode | Validium Mode | Validium gasUsed / Rollup gasUsed | Gas Difference / Rollup gasUsed |
ERC20 Transfer | 581.716 | 130.366 | |||
ERC20 Mint | 810.134 | 129.284 | |||
ERC20 Second Deploy | 1.884.480 | 163.230 | |||
ERC20 First Deploy | 71.551.780 | 490.930 | |||
V2 | |||||
ERC20 Transfer | 794.116 | 140.431 | |||
ERC20 Mint | 1.130.534 | 139.349 | |||
ERC20 Second Deploy | 2.705.730 | 173.295 | |||
ERC20 First Deploy | TODO | 500.995 |