Skip to content

Commit

Permalink
feat(zk_toolbox): deploy legacy bridge (#2837)
Browse files Browse the repository at this point in the history
## What ❔

Support legacy bridges in zk toolbox 

## Why ❔

We still have some legacy bridges in production, so we have to have an
opportunity to test it

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.

---------

Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo authored Sep 12, 2024
1 parent 9218612 commit 93b4e08
Show file tree
Hide file tree
Showing 23 changed files with 251 additions and 29 deletions.
36 changes: 23 additions & 13 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
strategy:
fail-fast: false
matrix:
vm_mode: [ "old", "new" ]
vm_mode: [ "OLD", "NEW" ]

steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
Expand All @@ -87,13 +87,12 @@ jobs:
- name: Loadtest configuration
run: |
echo EXPECTED_TX_COUNT=${{ matrix.vm_mode == 'new' && 21000 || 16000 }} >> .env
echo EXPECTED_TX_COUNT=${{ matrix.vm_mode == 'NEW' && 21000 || 16000 }} >> .env
echo ACCOUNTS_AMOUNT="100" >> .env
echo MAX_INFLIGHT_TXS="10" >> .env
echo SYNC_API_REQUESTS_LIMIT="15" >> .env
echo FAIL_FAST=true >> .env
echo IN_DOCKER=1 >> .env
echo DATABASE_MERKLE_TREE_MODE=lightweight >> .env
- name: Start services
run: |
Expand All @@ -107,23 +106,34 @@ jobs:
ci_run git config --global --add safe.directory /usr/src/zksync/contracts/system-contracts
ci_run git config --global --add safe.directory /usr/src/zksync/contracts
ci_run zk
ci_run zk init --local-legacy-bridge-testing
ci_run ./bin/zkt
ci_run zk_inception chain create \
--chain-name legacy \
--chain-id sequential \
--prover-mode no-proofs \
--wallet-creation localhost \
--l1-batch-commit-data-generator-mode rollup \
--base-token-address 0x0000000000000000000000000000000000000001 \
--base-token-price-nominator 1 \
--base-token-price-denominator 1 \
--set-as-default false \
--ignore-prerequisites \
--legacy-bridge
ci_run zk_inception ecosystem init --dev --verbose
ci_run zk_supervisor contracts --test-contracts
# `sleep 60` because we need to wait until server added all the tokens
- name: Run server
run: |
EXPERIMENTAL_VM_STATE_KEEPER_FAST_VM_MODE=${{ matrix.vm_mode }} \
CHAIN_MEMPOOL_DELAY_INTERVAL=50 \
PASSED_ENV_VARS="EXPERIMENTAL_VM_STATE_KEEPER_FAST_VM_MODE,CHAIN_MEMPOOL_DELAY_INTERVAL" \
ci_run zk server --uring --components api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads &>server.log &
ci_run sed -i -e 's/mode: FULL/mode: LIGHTWEIGHT/' chains/legacy/configs/general.yaml
ci_run sed -i -e 's/state_keeper_fast_vm_mode:.*/state_keeper_fast_vm_mode: ${{ matrix.vm_mode }}/' chains/legacy/configs/general.yaml
ci_run sed -i -e 's/delay_interval:.*/delay_interval: 50/' chains/legacy/configs/general.yaml
ci_run zk_inception server --uring --chain=legacy --components api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads &>server.log &
ci_run sleep 60
- name: Deploy legacy era contracts
run: ci_run zk contract setup-legacy-bridge-era

- name: Perform loadtest
run: ci_run zk run loadtest
run: ci_run zk_supervisor t loadtest -v --chain=legacy

- name: Show server.log logs
if: always()
Expand Down
1 change: 1 addition & 0 deletions prover/crates/lib/keystore/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub fn calculate_snark_vk_hash(keystore: &Keystore) -> anyhow::Result<H256> {
#[cfg(test)]
mod tests {
use std::str::FromStr;

use zksync_utils::env::Workspace;

use super::*;
Expand Down
8 changes: 6 additions & 2 deletions zk_toolbox/crates/common/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::cmd::Cmd;
pub struct Server {
components: Option<Vec<String>>,
code_path: PathBuf,
uring: bool,
}

/// Possible server modes.
Expand All @@ -20,10 +21,11 @@ pub enum ServerMode {

impl Server {
/// Creates a new instance of the server.
pub fn new(components: Option<Vec<String>>, code_path: PathBuf) -> Self {
pub fn new(components: Option<Vec<String>>, code_path: PathBuf, uring: bool) -> Self {
Self {
components,
code_path,
uring,
}
}

Expand Down Expand Up @@ -52,10 +54,12 @@ impl Server {
additional_args.push("--genesis".to_string());
}

let uring = self.uring.then_some("--features=rocksdb/io-uring");

let mut cmd = Cmd::new(
cmd!(
shell,
"cargo run --release --bin zksync_server --
"cargo run --release --bin zksync_server {uring...} --
--genesis-path {genesis_path}
--wallets-path {wallets_path}
--config-path {general_path}
Expand Down
4 changes: 4 additions & 0 deletions zk_toolbox/crates/config/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct ChainConfigInternal {
pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode,
pub base_token: BaseToken,
pub wallet_creation: WalletCreation,
#[serde(skip_serializing_if = "Option::is_none")]
pub legacy_bridge: Option<bool>,
}

/// Chain configuration file. This file is created in the chain
Expand All @@ -58,6 +60,7 @@ pub struct ChainConfig {
pub base_token: BaseToken,
pub wallet_creation: WalletCreation,
pub shell: OnceCell<Shell>,
pub legacy_bridge: Option<bool>,
}

impl Serialize for ChainConfig {
Expand Down Expand Up @@ -153,6 +156,7 @@ impl ChainConfig {
l1_batch_commit_data_generator_mode: self.l1_batch_commit_data_generator_mode,
base_token: self.base_token.clone(),
wallet_creation: self.wallet_creation,
legacy_bridge: self.legacy_bridge,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions zk_toolbox/crates/config/src/ecosystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ impl EcosystemConfig {
artifacts: config
.artifacts_path
.unwrap_or_else(|| self.get_chain_artifacts_path(name)),
legacy_bridge: config.legacy_bridge,
})
}

Expand Down
1 change: 1 addition & 0 deletions zk_toolbox/crates/config/src/forge_interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pub mod deploy_l2_contracts;
pub mod paymaster;
pub mod register_chain;
pub mod script_params;
pub mod setup_legacy_bridge;
6 changes: 6 additions & 0 deletions zk_toolbox/crates/config/src/forge_interface/script_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ pub const ACCEPT_GOVERNANCE_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams
output: "script-out/output-accept-admin.toml",
script_path: "deploy-scripts/AcceptAdmin.s.sol",
};

pub const SETUP_LEGACY_BRIDGE: ForgeScriptParams = ForgeScriptParams {
input: "script-config/setup-legacy-bridge.toml",
output: "script-out/setup-legacy-bridge.toml",
script_path: "deploy-scripts/dev/SetupLegacyBridge.s.sol",
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use serde::{Deserialize, Serialize};
use zksync_basic_types::{Address, L2ChainId, H256};

use crate::traits::ZkToolboxConfig;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SetupLegacyBridgeInput {
pub bridgehub: Address,
pub diamond_proxy: Address,
pub shared_bridge_proxy: Address,
pub transparent_proxy_admin: Address,
pub erc20bridge_proxy: Address,
pub token_weth_address: Address,
pub chain_id: L2ChainId,
pub l2shared_bridge_address: Address,
pub create2factory_salt: H256,
pub create2factory_addr: Address,
}

impl ZkToolboxConfig for SetupLegacyBridgeInput {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};

use crate::messages::{
MSG_SERVER_ADDITIONAL_ARGS_HELP, MSG_SERVER_BUILD_HELP, MSG_SERVER_COMPONENTS_HELP,
MSG_SERVER_GENESIS_HELP,
MSG_SERVER_GENESIS_HELP, MSG_SERVER_URING_HELP,
};

#[derive(Debug, Serialize, Deserialize, Parser)]
Expand All @@ -17,4 +17,6 @@ pub struct RunServerArgs {
additional_args: Vec<String>,
#[clap(long, help = MSG_SERVER_BUILD_HELP)]
pub build: bool,
#[clap(help=MSG_SERVER_URING_HELP, long, default_missing_value = "true", num_args = 0..=1)]
pub uring: bool,
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub struct ChainCreateArgs {
base_token_price_denominator: Option<u64>,
#[clap(long, help = MSG_SET_AS_DEFAULT_HELP, default_missing_value = "true", num_args = 0..=1)]
pub(crate) set_as_default: Option<bool>,
#[clap(long, default_value = "false")]
pub(crate) legacy_bridge: bool,
}

impl ChainCreateArgs {
Expand Down Expand Up @@ -224,6 +226,7 @@ impl ChainCreateArgs {
wallet_path,
base_token,
set_as_default,
legacy_bridge: self.legacy_bridge,
})
}
}
Expand All @@ -238,6 +241,7 @@ pub struct ChainCreateArgsFinal {
pub wallet_path: Option<PathBuf>,
pub base_token: BaseToken,
pub set_as_default: bool,
pub legacy_bridge: bool,
}

#[derive(Debug, Clone, EnumIter, Display, PartialEq, Eq)]
Expand Down
18 changes: 14 additions & 4 deletions zk_toolbox/crates/zk_inception/src/commands/chain/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,24 @@ pub(crate) fn create_chain_inner(
ecosystem_config: &EcosystemConfig,
shell: &Shell,
) -> anyhow::Result<()> {
if args.legacy_bridge {
logger::warn("WARNING!!! You are creating a chain with legacy bridge, use it only for testing compatibility")
}
let default_chain_name = args.chain_name.clone();
let chain_path = ecosystem_config.chains.join(&default_chain_name);
let chain_configs_path = create_local_configs_dir(shell, &chain_path)?;
let chain_id = ecosystem_config.list_of_chains().len() as u32;
let (chain_id, legacy_bridge) = if args.legacy_bridge {
// Legacy bridge is distinguished by using the same chain id as ecosystem
(ecosystem_config.era_chain_id, Some(true))
} else {
(L2ChainId::from(args.chain_id), None)
};
let internal_id = ecosystem_config.list_of_chains().len() as u32;

let chain_config = ChainConfig {
id: chain_id,
id: internal_id,
name: default_chain_name.clone(),
chain_id: L2ChainId::from(args.chain_id),
chain_id,
prover_version: args.prover_version,
l1_network: ecosystem_config.l1_network,
link_to_code: ecosystem_config.link_to_code.clone(),
Expand All @@ -79,13 +88,14 @@ pub(crate) fn create_chain_inner(
base_token: args.base_token,
wallet_creation: args.wallet_creation,
shell: OnceCell::from(shell.clone()),
legacy_bridge,
};

create_wallets(
shell,
&chain_config.configs,
&ecosystem_config.link_to_code,
chain_id,
internal_id,
args.wallet_creation,
args.wallet_path,
)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,17 @@ pub async fn initialize_bridges(
contracts_config: &mut ContractsConfig,
forge_args: ForgeScriptArgs,
) -> anyhow::Result<()> {
let signature = if let Some(true) = chain_config.legacy_bridge {
Some("runDeployLegacySharedBridge")
} else {
Some("runDeploySharedBridge")
};
build_and_deploy(
shell,
chain_config,
ecosystem_config,
forge_args,
Some("runDeploySharedBridge"),
signature,
|shell, out| {
contracts_config.set_l2_shared_bridge(&InitializeBridgeOutput::read(shell, out)?)
},
Expand Down Expand Up @@ -185,12 +190,17 @@ pub async fn deploy_l2_contracts(
contracts_config: &mut ContractsConfig,
forge_args: ForgeScriptArgs,
) -> anyhow::Result<()> {
let signature = if let Some(true) = chain_config.legacy_bridge {
Some("runWithLegacyBridge")
} else {
None
};
build_and_deploy(
shell,
chain_config,
ecosystem_config,
forge_args,
None,
signature,
|shell, out| {
contracts_config.set_l2_shared_bridge(&InitializeBridgeOutput::read(shell, out)?)?;
contracts_config.set_default_l2_upgrade(&DefaultL2UpgradeOutput::read(shell, out)?)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async fn initialize_databases(
}

fn run_server_genesis(chain_config: &ChainConfig, shell: &Shell) -> anyhow::Result<()> {
let server = Server::new(None, chain_config.link_to_code.clone());
let server = Server::new(None, chain_config.link_to_code.clone(), false);
server
.run(
shell,
Expand Down
12 changes: 12 additions & 0 deletions zk_toolbox/crates/zk_inception/src/commands/chain/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::{
deploy_l2_contracts, deploy_paymaster,
genesis::genesis,
set_token_multiplier_setter::set_token_multiplier_setter,
setup_legacy_bridge::setup_legacy_bridge,
},
portal::update_portal_config,
},
Expand Down Expand Up @@ -142,6 +143,17 @@ pub async fn init(
.await?;
contracts_config.save_with_base_path(shell, &chain_config.configs)?;

if let Some(true) = chain_config.legacy_bridge {
setup_legacy_bridge(
shell,
chain_config,
ecosystem_config,
&contracts_config,
init_args.forge_args.clone(),
)
.await?;
}

if init_args.deploy_paymaster {
deploy_paymaster::deploy_paymaster(
shell,
Expand Down
1 change: 1 addition & 0 deletions zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod deploy_paymaster;
pub mod genesis;
pub(crate) mod init;
mod set_token_multiplier_setter;
mod setup_legacy_bridge;

#[derive(Subcommand, Debug)]
pub enum ChainCommands {
Expand Down
Loading

0 comments on commit 93b4e08

Please sign in to comment.