Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Validium mode + Fee Model V2 #66

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

ilitteri
Copy link
Collaborator

@ilitteri ilitteri commented Jan 25, 2024

DISCLAIMER: This branch is supposed to be merged to #21, it is pointing to main for the moment to see the main changes easily.

Description

This PR merges the Validium mode that is working with the old fee model with the feature of the new fee model.

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 and zksync_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 the init.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 is l1_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, setting l1_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

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

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

@ilitteri ilitteri marked this pull request as ready for review January 30, 2024 21:09
@ilitteri ilitteri marked this pull request as draft January 30, 2024 21:09
Comment on lines 67 to 75
FeeModelConfig::V2(config) => {
let validium_mode = std::env::var("VALIDIUM_MODE") == Ok("true".to_owned());
FeeParams::V2(FeeParamsV2 {
config,
l1_gas_price: self.provider.estimate_effective_gas_price(),
l1_pubdata_price: self.provider.estimate_effective_pubdata_price()
* !validium_mode as u64,
})
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be left untouched. The provider's estimate_effective_pubdata_price should return 0 instead in validium mode.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC that's a configuration flag in chain.toml.

Once the server is running, run this command in other terminal:

```sh
cargo run --release --bin zksync_full_stack
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is outdated I think. Shouldn't this be the example now?

Oppen pushed a commit that referenced this pull request Feb 9, 2024
Oppen pushed a commit that referenced this pull request Feb 9, 2024
…bel-external-contributions

ci: add workflow to label external-contributions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants