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(zkstack): Add chain registrar for registering new chains #3278

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ab87f6d
update contacts
Deniallugo Nov 12, 2024
43f695d
Introduce propose registration
Deniallugo Nov 12, 2024
c803c75
Chain registar inside registrarion process
Deniallugo Nov 12, 2024
2429e60
Initialize config from l1
Deniallugo Nov 13, 2024
f5799ac
Make correct chain admin registartion
Deniallugo Nov 14, 2024
61f584e
Small refactor
Deniallugo Nov 14, 2024
9ff62c0
Merge branch 'main' into deniallugo-chain-registrar
Deniallugo Nov 14, 2024
5971b41
Set token multiplier in contracts
Deniallugo Nov 16, 2024
549f5fd
Add propose chain step
Deniallugo Nov 16, 2024
fce03df
Use custom argument for proposing chain
Deniallugo Nov 16, 2024
c4ceed0
Fix dev mode
Deniallugo Nov 16, 2024
b92fede
Set custom gas limit
Deniallugo Nov 16, 2024
87f95ab
Use different default wallet for propose chains
Deniallugo Nov 16, 2024
181f009
Move register chain
Deniallugo Nov 16, 2024
58150a8
Fix building chain
Deniallugo Nov 16, 2024
61b3961
Fix dev mode
Deniallugo Nov 16, 2024
aaf209a
Merge branch 'main' into deniallugo-chain-registrar
Deniallugo Nov 18, 2024
ff64d74
Print panics
Deniallugo Nov 18, 2024
2068d46
Fix print panics
Deniallugo Nov 18, 2024
ff18621
Propose chain
Deniallugo Nov 18, 2024
5ad42f9
Update params
Deniallugo Nov 18, 2024
e01d1cd
fix lints
Deniallugo Nov 18, 2024
ed14e9d
fix e2e test
Deniallugo Nov 18, 2024
06b373f
Merge branch 'main' into deniallugo-chain-registrar
Deniallugo Nov 19, 2024
68925bd
chore(main): release core 25.2.0 (#3228)
zksync-era-bot Nov 19, 2024
dc304f1
ci: fix tags processing in core reusable template (#3310)
otani88 Nov 20, 2024
11d0b51
fix: Add prometheus exporter to circut prover (#3311)
EmilLuta Nov 20, 2024
7f9a999
docs(consensus): Minor fixes to decentralization docs (#3307)
brunoffranca Nov 20, 2024
a6f57cb
Use function
Deniallugo Nov 21, 2024
e6ab358
update contracts
Deniallugo Nov 22, 2024
c5cae70
Update contracts
Deniallugo Nov 25, 2024
2f9d788
Move contracts to dev
Deniallugo Nov 27, 2024
d4f117b
Remove redundant events
Deniallugo Nov 27, 2024
619e96c
Merge branch 'main' into deniallugo-chain-registrar
Deniallugo Nov 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ jobs:
run: |
ci_run ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup || true
ci_run zkstackup -g --local


- name: Create and initialize legacy chain
run: |
Expand Down Expand Up @@ -298,7 +298,7 @@ jobs:
run: |
ci_run zkstack chain create \
--chain-name offline_chain \
--chain-id sequential \
--chain-id 384 \
--prover-mode no-proofs \
--wallet-creation localhost \
--l1-batch-commit-data-generator-mode rollup \
Expand All @@ -309,12 +309,13 @@ jobs:
--ignore-prerequisites \
--evm-emulator false

ci_run zkstack chain build-transactions --chain offline_chain --l1-rpc-url http://127.0.0.1:8545
ci_run zkstack chain propose-chain --chain offline_chain --dev
ci_run zkstack ecosystem register-chain --no-broadcast --chain offline_chain --dev

governor_pk=$(awk '/governor:/ {flag=1} flag && /private_key:/ {print $2; exit}' ./configs/wallets.yaml)

ci_run zkstack dev send-transactions \
--file ./transactions/chain/offline_chain/register-hyperchain-txns.json \
--file ./transactions/chain/384/register-hyperchain-txns.json \
--l1-rpc-url http://127.0.0.1:8545 \
--private-key $governor_pk

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci-prover-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ jobs:
ci_run zkstack prover run --component=compressor --docker=false &>prover_logs/compressor.log &
- name: Wait for batch to be executed on L1
env:
DATABASE_URL: postgres://postgres:notsecurepassword@localhost:5432/zksync_prover_localhost_proving_chain
BATCH_NUMBER: 1
INTERVAL: 30
TIMEOUT: 600
DATABASE_URL: postgres://postgres:notsecurepassword@localhost:5432/zksync_prover_localhost_proving_chain
BATCH_NUMBER: 1
INTERVAL: 30
TIMEOUT: 600
run: |
PASSED_ENV_VARS="BATCH_NUMBER,DATABASE_URL,URL,INTERVAL,TIMEOUT" \
ci_run ./bin/prover_checkers/batch_l1_status_checker
Expand Down
Empty file removed configs/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion contracts
Submodule contracts updated 72 files
+35 −1 .github/workflows/system-contracts-ci.yaml
+2 −0 .gitignore
+2 −0 .solhintignore
+16 −6 l1-contracts/contracts/bridge/L1SharedBridge.sol
+212 −0 l1-contracts/contracts/chain-registrar/ChainRegistrar.sol
+26 −0 l1-contracts/contracts/common/L1ContractErrors.sol
+13 −0 l1-contracts/contracts/dev-contracts/test/DummyHyperchain.sol
+3 −2 l1-contracts/contracts/dev-contracts/test/ReenterGovernance.sol
+13 −0 l1-contracts/contracts/governance/Common.sol
+1 −0 l1-contracts/contracts/governance/Governance.sol
+2 −10 l1-contracts/contracts/governance/IGovernance.sol
+5 −0 l1-contracts/contracts/state-transition/chain-deps/facets/Getters.sol
+3 −0 l1-contracts/contracts/state-transition/chain-interfaces/IGetters.sol
+36 −2 l1-contracts/deploy-scripts/DeployL1.s.sol
+7 −1 l1-contracts/deploy-scripts/DeployL2Contracts.sol
+16 −19 l1-contracts/deploy-scripts/PrepareZKChainRegistrationCalldata.s.sol
+82 −0 l1-contracts/deploy-scripts/ProposeChainRegistration.s.sol
+35 −70 l1-contracts/deploy-scripts/RegisterHyperchain.s.sol
+3 −9 l1-contracts/deploy-scripts/Utils.sol
+6 −1 l1-contracts/scripts/utils.ts
+1 −2 l1-contracts/src.ts/deploy-process.ts
+2 −0 l1-contracts/src.ts/deploy.ts
+2 −1 l1-contracts/test/foundry/unit/concrete/Utils/Utils.sol
+267 −0 l1-contracts/test/foundry/unit/concrete/chain-registrator/ChainRegistrar.t.sol
+0 −0 l1-contracts/test/foundry/unit/concrete/governance/Governance/Authorization.t.sol
+93 −0 l1-contracts/test/foundry/unit/concrete/governance/Governance/ChainAdmin.t.sol
+1 −1 l1-contracts/test/foundry/unit/concrete/governance/Governance/Executing.t.sol
+0 −0 l1-contracts/test/foundry/unit/concrete/governance/Governance/Fallback.t.sol
+1 −1 l1-contracts/test/foundry/unit/concrete/governance/Governance/OperationStatus.t.sol
+0 −0 l1-contracts/test/foundry/unit/concrete/governance/Governance/Reentrancy.t.sol
+1 −1 l1-contracts/test/foundry/unit/concrete/governance/Governance/SelfUpgrades.t.sol
+3 −2 l1-contracts/test/foundry/unit/concrete/governance/Governance/_Governance_Shared.t.sol
+4 −0 l1-contracts/test/foundry/unit/concrete/state-transition/StateTransitionManager/CreateNewChain.t.sol
+4 −0 l1-contracts/test/foundry/unit/concrete/state-transition/StateTransitionManager/FreezeChain.t.sol
+4 −0 l1-contracts/test/foundry/unit/concrete/state-transition/StateTransitionManager/RevertBatches.t.sol
+4 −0 l1-contracts/test/foundry/unit/concrete/state-transition/StateTransitionManager/SetChainCreationParams.t.sol
+4 −0 l1-contracts/test/foundry/unit/concrete/state-transition/StateTransitionManager/SetNewVersionUpgrade.t.sol
+4 −0 l1-contracts/test/foundry/unit/concrete/state-transition/StateTransitionManager/SetUpgradeDiamondCut.t.sol
+4 −0 l1-contracts/test/foundry/unit/concrete/state-transition/StateTransitionManager/SetValidatorTimelock.t.sol
+4 −0 l1-contracts/test/foundry/unit/concrete/state-transition/StateTransitionManager/StateTransitionOwnerZero.t.sol
+7 −6 ...cts/test/foundry/unit/concrete/state-transition/StateTransitionManager/_StateTransitionManager_Shared.t.sol
+16 −16 l1-contracts/test/test_config/constant/hardhat.json
+2 −1 l1-contracts/test/unit_tests/custom_base_token.spec.ts
+3 −3 l1-contracts/test/unit_tests/l1_shared_bridge_test.spec.ts
+1 −1 l1-contracts/test/unit_tests/l2-upgrade.test.spec.ts
+1 −1 l1-contracts/test/unit_tests/legacy_era_test.spec.ts
+1 −1 l1-contracts/test/unit_tests/mailbox_test.spec.ts
+3 −3 l1-contracts/test/unit_tests/proxy_test.spec.ts
+2 −2 l2-contracts/contracts/interfaces/IConsensusRegistry.sol
+1 −1 l2-contracts/foundry.toml
+1 −1 l2-contracts/hardhat.config.ts
+75 −61 system-contracts/SystemContractsHashes.json
+2,281 −1,551 system-contracts/bootloader/test_infra/Cargo.lock
+6 −6 system-contracts/bootloader/test_infra/Cargo.toml
+1 −1 system-contracts/bootloader/test_infra/rust-toolchain
+3 −3 system-contracts/bootloader/test_infra/src/hook.rs
+33 −20 system-contracts/bootloader/test_infra/src/main.rs
+4 −4 system-contracts/bootloader/test_infra/src/test_count_tracer.rs
+7 −6 system-contracts/bootloader/test_infra/src/tracer.rs
+0 −18 system-contracts/contracts/L2BaseToken.sol
+0 −6 system-contracts/contracts/interfaces/IBaseToken.sol
+28 −26 system-contracts/contracts/test-contracts/ExtraAbiCaller.zasm
+2 −1 system-contracts/foundry.toml
+3 −18 system-contracts/hardhat.config.ts
+2 −2 system-contracts/package.json
+11 −5 system-contracts/scripts/calculate-hashes.ts
+4 −13 system-contracts/scripts/compile-yul.ts
+3 −3 system-contracts/scripts/compile-zasm.ts
+9 −2 system-contracts/scripts/deploy-preimages.ts
+8 −4 system-contracts/scripts/utils.ts
+0 −21 system-contracts/test/L2BaseToken.spec.ts
+99 −14 yarn.lock
9 changes: 9 additions & 0 deletions core/lib/basic_types/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ impl Detokenize for L1BatchCommitmentMode {
}
}

impl From<L1BatchCommitmentMode> for u8 {
fn from(val: L1BatchCommitmentMode) -> Self {
match val {
L1BatchCommitmentMode::Rollup => 0,
L1BatchCommitmentMode::Validium => 1,
}
}
}

impl FromStr for L1BatchCommitmentMode {
type Err = &'static str;

Expand Down
40 changes: 40 additions & 0 deletions zkstack_cli/crates/common/src/ethereum/chain_registrar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use std::sync::Arc;

use ethers::{
abi::Address,
contract::abigen,
prelude::{Http, Provider},
};

abigen!(
ChainRegistar,
r"[
struct RegisteredChainConfig {address pendingChainAdmin;address chainAdmin;address diamondProxy;address l2BridgeAddress;}
function getRegisteredChainConfig(uint256 chainId) public view returns (RegisteredChainConfig memory)
]"
);

#[derive(Clone, Copy)]
pub struct ChainRegistrationResult {
pub diamond_proxy: Address,
pub chain_admin: Address,
pub l2_shared_bridge: Address,
}

pub async fn load_contracts_for_chain(
chain_registrar: Address,
l1_rpc: String,
l2_chain_id: u64,
) -> anyhow::Result<ChainRegistrationResult> {
let client = Arc::new(Provider::<Http>::try_from(l1_rpc)?);
let contract = ChainRegistar::new(chain_registrar, client);
let (pending_chain_admin, _chain_admin, diamond_proxy, l2_bridge_address) = contract
.get_registered_chain_config(l2_chain_id.into())
.await?;

Ok(ChainRegistrationResult {
diamond_proxy,
chain_admin: pending_chain_admin,
l2_shared_bridge: l2_bridge_address,
})
}
58 changes: 58 additions & 0 deletions zkstack_cli/crates/common/src/ethereum/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
pub mod chain_registrar;
pub mod token;

use std::{ops::Add, time::Duration};

use ethers::{
core::k256::ecdsa::SigningKey,
middleware::MiddlewareBuilder,
prelude::{Http, LocalWallet, Provider, Signer, SignerMiddleware},
providers::Middleware,
types::{Address, TransactionRequest},
};
pub use token::{get_token_info, mint_token};

use crate::wallets::Wallet;

pub fn create_ethers_client(
mut wallet: LocalWallet,
l1_rpc: String,
chain_id: Option<u64>,
) -> anyhow::Result<SignerMiddleware<Provider<Http>, ethers::prelude::Wallet<SigningKey>>> {
if let Some(chain_id) = chain_id {
wallet = wallet.with_chain_id(chain_id);
}
let client = Provider::<Http>::try_from(l1_rpc)?.with_signer(wallet);
Ok(client)
}

pub async fn distribute_eth(
main_wallet: Wallet,
addresses: Vec<Address>,
l1_rpc: String,
chain_id: u64,
amount: u128,
) -> anyhow::Result<()> {
let client = create_ethers_client(main_wallet.private_key.unwrap(), l1_rpc, Some(chain_id))?;
let mut pending_txs = vec![];
let mut nonce = client.get_transaction_count(client.address(), None).await?;
for address in addresses {
let tx = TransactionRequest::new()
.to(address)
.value(amount)
.nonce(nonce)
.chain_id(chain_id);
nonce = nonce.add(1);
pending_txs.push(
client
.send_transaction(tx, None)
.await?
// It's safe to set such low number of confirmations and low interval for localhost
.confirmations(1)
.interval(Duration::from_millis(30)),
);
}

futures::future::join_all(pending_txs).await;
Ok(())
}
Original file line number Diff line number Diff line change
@@ -1,60 +1,14 @@
use std::{ops::Add, sync::Arc, time::Duration};
use std::{sync::Arc, time::Duration};

use ethers::{
abi::Address,
contract::abigen,
core::k256::ecdsa::SigningKey,
middleware::MiddlewareBuilder,
prelude::{Http, LocalWallet, Provider, Signer, SignerMiddleware},
providers::Middleware,
types::{Address, TransactionRequest},
prelude::{Http, Provider},
};
use types::TokenInfo;

use crate::{logger, wallets::Wallet};

pub fn create_ethers_client(
mut wallet: LocalWallet,
l1_rpc: String,
chain_id: Option<u64>,
) -> anyhow::Result<SignerMiddleware<Provider<Http>, ethers::prelude::Wallet<SigningKey>>> {
if let Some(chain_id) = chain_id {
wallet = wallet.with_chain_id(chain_id);
}
let client = Provider::<Http>::try_from(l1_rpc)?.with_signer(wallet);
Ok(client)
}

pub async fn distribute_eth(
main_wallet: Wallet,
addresses: Vec<Address>,
l1_rpc: String,
chain_id: u64,
amount: u128,
) -> anyhow::Result<()> {
let client = create_ethers_client(main_wallet.private_key.unwrap(), l1_rpc, Some(chain_id))?;
let mut pending_txs = vec![];
let mut nonce = client.get_transaction_count(client.address(), None).await?;
for address in addresses {
let tx = TransactionRequest::new()
.to(address)
.value(amount)
.nonce(nonce)
.chain_id(chain_id);
nonce = nonce.add(1);
pending_txs.push(
client
.send_transaction(tx, None)
.await?
// It's safe to set such low number of confirmations and low interval for localhost
.confirmations(1)
.interval(Duration::from_millis(30)),
);
}

futures::future::join_all(pending_txs).await;
Ok(())
}

use crate::{ethereum::create_ethers_client, logger, wallets::Wallet};
abigen!(
TokenContract,
r"[
Expand Down
4 changes: 3 additions & 1 deletion zkstack_cli/crates/config/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ impl ContractsConfig {
.diamond_cut_data
.clone_from(&deploy_l1_output.contracts_config.diamond_cut_data);
self.l1.chain_admin_addr = deploy_l1_output.deployed_addresses.chain_admin;
self.ecosystem_contracts.chain_registrar =
deploy_l1_output.deployed_addresses.chain_registrar;
}

pub fn set_chain_contracts(&mut self, register_chain_output: &RegisterChainOutput) {
self.l1.diamond_proxy_addr = register_chain_output.diamond_proxy_addr;
self.l1.governance_addr = register_chain_output.governance_addr;
self.l1.chain_admin_addr = register_chain_output.chain_admin_addr;
}

Expand Down Expand Up @@ -132,6 +133,7 @@ pub struct EcosystemContracts {
pub transparent_proxy_admin_addr: Address,
pub validator_timelock_addr: Address,
pub diamond_cut_data: String,
pub chain_registrar: Address,
}

impl ZkStackConfig for EcosystemContracts {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub struct DeployL1Config {
pub era_chain_id: L2ChainId,
pub owner_address: Address,
pub testnet_verifier: bool,
pub l2_deployer: Address,
pub contracts: ContractsDeployL1Config,
pub tokens: TokensDeployL1Config,
}
Expand Down Expand Up @@ -166,6 +167,7 @@ impl DeployL1Config {
tokens: TokensDeployL1Config {
token_weth_address: initial_deployment_config.token_weth_address,
},
l2_deployer: wallets_config.governor.address,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct DeployL1DeployedAddressesOutput {
pub bridgehub: L1BridgehubOutput,
pub bridges: L1BridgesOutput,
pub state_transition: L1StateTransitionOutput,
pub chain_registrar: Address,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub struct DeployL2ContractsInput {
pub governance: Address,
pub erc20_bridge: Address,
pub consensus_registry_owner: Address,
pub chain_registrar: Address,
pub proposal_author: Address,
}

impl DeployL2ContractsInput {
Expand All @@ -31,6 +33,8 @@ impl DeployL2ContractsInput {
governance: wallets.governor.address,
erc20_bridge: contracts.bridges.erc20.l1_address,
consensus_registry_owner: wallets.governor.address,
chain_registrar: contracts.ecosystem_contracts.chain_registrar,
proposal_author: wallets.governor.address,
})
}
}
1 change: 1 addition & 0 deletions zkstack_cli/crates/config/src/forge_interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod accept_ownership;
pub mod deploy_ecosystem;
pub mod deploy_l2_contracts;
pub mod paymaster;
pub mod propose_registration;
pub mod register_chain;
pub mod script_params;
pub mod setup_legacy_bridge;
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use ethers::types::Address;
use serde::{Deserialize, Serialize};
use types::BaseToken;
use zksync_basic_types::commitment::L1BatchCommitmentMode;

use crate::traits::ZkStackConfig;

#[derive(Debug, Deserialize, Serialize, Clone)]

struct ChainConfig {
chain_id: u64,
blob_operator: Address,
operator: Address,
governor: Address,
base_token: BaseTokenInt,
pubdata_pricing_mode: u8,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
struct BaseTokenInt {
pub token_multiplier_setter: Option<Address>,
pub address: Address,
pub nominator: u64,
pub denominator: u64,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ProposeRegistrationInputConfig {
chain_registrar: Address,
chain: ChainConfig,
}

impl ProposeRegistrationInputConfig {
#[allow(clippy::too_many_arguments)]
pub fn new(
chain_registrar: Address,
chain_id: u64,
blob_operator: Address,
operator: Address,
governor: Address,
token: BaseToken,
token_multiplier_setter: Option<Address>,
l1batch_commitment_mode: L1BatchCommitmentMode,
) -> Self {
ProposeRegistrationInputConfig {
chain_registrar,
chain: ChainConfig {
chain_id,
blob_operator,
operator,
governor,
base_token: BaseTokenInt {
token_multiplier_setter,
address: token.address,
nominator: token.nominator,
denominator: token.denominator,
},
pubdata_pricing_mode: l1batch_commitment_mode as u8,
},
}
}
}

impl ZkStackConfig for ProposeRegistrationInputConfig {}
Loading
Loading