Skip to content

Commit

Permalink
feat: Kl split-asset-router-support (#2790)
Browse files Browse the repository at this point in the history
## What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## 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`.
  • Loading branch information
kelemeno authored Sep 17, 2024
1 parent 922dcba commit 22a3eef
Show file tree
Hide file tree
Showing 40 changed files with 374 additions and 136 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ jobs:
- name: Prepare the server to be the synclayer
run: |
ci_run zk dev2 supply-rich-wallets
ci_run zk contract build --zkSync
ci_run zk contract prepare-sync-layer
ci_run zk contract register-sync-layer-counterpart
Expand All @@ -258,10 +257,8 @@ jobs:
ci_run zk config prepare-l1-hyperchain --env-name test-chain --chain-id 320
ci_run zk env test-chain
ci_run zk config compile test-chain --diff 5
ci_run zk init hyper
ci_run zk server --time-to-live 120 &>server2.log
sleep 120
ci_run zk server --tx-aggregation-paused --time-to-live 60 &>server2.log
ci_run zk init hyper --skip-contract-compilation-override
ci_run zk contract migrate-to-sync-layer
ci_run zk contract prepare-sync-layer-validators
ci_run zk contract update-config-for-sync-layer
Expand Down
2 changes: 1 addition & 1 deletion contracts
Submodule contracts updated 451 files
8 changes: 8 additions & 0 deletions core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub(crate) struct RemoteENConfig {
// a different name, with names adapted only for consistency.
pub l1_shared_bridge_proxy_addr: Option<Address>,
pub l2_shared_bridge_addr: Option<Address>,
pub l2_legacy_shared_bridge_addr: Option<Address>,
pub l1_erc20_bridge_proxy_addr: Option<Address>,
pub l2_erc20_bridge_addr: Option<Address>,
pub l1_weth_bridge_addr: Option<Address>,
Expand Down Expand Up @@ -138,6 +139,10 @@ impl RemoteENConfig {
.get_native_token_vault_proxy_addr()
.rpc_context("get_native_token_vault")
.await?;
let l2_legacy_shared_bridge_addr = client
.get_legacy_shared_bridge()
.rpc_context("get_legacy_shared_bridge")
.await?;
let genesis = client.genesis_config().rpc_context("genesis").await.ok();
let ecosystem_contracts = client
.get_ecosystem_contracts()
Expand Down Expand Up @@ -203,6 +208,7 @@ impl RemoteENConfig {
l2_erc20_bridge_addr: l2_erc20_default_bridge,
l1_shared_bridge_proxy_addr: bridges.l1_shared_default_bridge,
l2_shared_bridge_addr: l2_erc20_shared_bridge,
l2_legacy_shared_bridge_addr,
l1_weth_bridge_addr: bridges.l1_weth_bridge,
l2_weth_bridge_addr: bridges.l2_weth_bridge,
base_token_addr,
Expand Down Expand Up @@ -234,6 +240,7 @@ impl RemoteENConfig {
l1_shared_bridge_proxy_addr: Some(Address::repeat_byte(5)),
l1_weth_bridge_addr: None,
l2_shared_bridge_addr: Some(Address::repeat_byte(6)),
l2_legacy_shared_bridge_addr: Some(Address::repeat_byte(7)),
l1_batch_commit_data_generator_mode: L1BatchCommitmentMode::Rollup,
dummy_verifier: true,
l2_native_token_vault_proxy_addr: Some(Address::repeat_byte(7)),
Expand Down Expand Up @@ -1421,6 +1428,7 @@ impl From<&ExternalNodeConfig> for InternalApiConfig {
dummy_verifier: config.remote.dummy_verifier,
l1_batch_commit_data_generator_mode: config.remote.l1_batch_commit_data_generator_mode,
l2_native_token_vault_proxy_addr: config.remote.l2_native_token_vault_proxy_addr,
l2_legacy_shared_bridge_addr: config.remote.l2_legacy_shared_bridge_addr,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions core/bin/external_node/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ impl ExternalNodeBuilder {
.remote
.l2_native_token_vault_proxy_addr
.expect("L2 native token vault proxy address is not set"),
self.config
.remote
.l2_legacy_shared_bridge_addr
.expect("L2 legacy shared bridge address is not set"),
self.config.optional.l2_block_seal_queue_capacity,
)
.with_pre_insert_txs(true) // EN requires txs to be pre-inserted.
Expand Down
3 changes: 3 additions & 0 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ impl MainNodeBuilder {
self.contracts_config
.l2_native_token_vault_proxy_addr
.context("L2 native token vault proxy address")?,
self.contracts_config
.l2_legacy_shared_bridge_addr
.context("L2 legacy shared bridge address")?,
sk_config.l2_block_seal_queue_capacity,
)
.with_protective_reads_persistence_enabled(sk_config.protective_reads_persistence_enabled);
Expand Down
4 changes: 4 additions & 0 deletions core/lib/basic_types/src/protocol_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ impl ProtocolVersionId {
self <= &Self::Version22
}

pub fn is_pre_gateway(&self) -> bool {
self <= &Self::Version24
}

pub fn is_1_4_0(&self) -> bool {
self >= &ProtocolVersionId::Version18 && self < &ProtocolVersionId::Version20
}
Expand Down
2 changes: 2 additions & 0 deletions core/lib/config/src/configs/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct ContractsConfig {
pub validator_timelock_addr: Address,
pub l1_shared_bridge_proxy_addr: Option<Address>,
pub l2_shared_bridge_addr: Option<Address>,
pub l2_legacy_shared_bridge_addr: Option<Address>,
pub l1_erc20_bridge_proxy_addr: Option<Address>,
pub l2_erc20_bridge_addr: Option<Address>,
pub l1_weth_bridge_proxy_addr: Option<Address>,
Expand Down Expand Up @@ -61,6 +62,7 @@ impl ContractsConfig {
l2_erc20_bridge_addr: Some(Address::repeat_byte(0x0c)),
l1_shared_bridge_proxy_addr: Some(Address::repeat_byte(0x0e)),
l2_shared_bridge_addr: Some(Address::repeat_byte(0x0f)),
l2_legacy_shared_bridge_addr: Some(Address::repeat_byte(0x10)),
l1_weth_bridge_proxy_addr: Some(Address::repeat_byte(0x0b)),
l2_weth_bridge_addr: Some(Address::repeat_byte(0x0c)),
l2_testnet_paymaster_addr: Some(Address::repeat_byte(0x11)),
Expand Down
1 change: 1 addition & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ impl Distribution<configs::ContractsConfig> for EncodeDist {
l2_erc20_bridge_addr: self.sample_opt(|| rng.gen()),
l1_shared_bridge_proxy_addr: self.sample_opt(|| rng.gen()),
l2_shared_bridge_addr: self.sample_opt(|| rng.gen()),
l2_legacy_shared_bridge_addr: self.sample_opt(|| rng.gen()),
l1_weth_bridge_proxy_addr: self.sample_opt(|| rng.gen()),
l2_weth_bridge_addr: self.sample_opt(|| rng.gen()),
l2_testnet_paymaster_addr: self.sample_opt(|| rng.gen()),
Expand Down
4 changes: 2 additions & 2 deletions core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ const FORGE_PATH_PREFIX: &str = "contracts/l1-contracts/out";
const BRIDGEHUB_CONTRACT_FILE: (&str, &str) = ("bridgehub", "IBridgehub.sol/IBridgehub.json");
const STATE_TRANSITION_CONTRACT_FILE: (&str, &str) = (
"state-transition",
"IStateTransitionManager.sol/IStateTransitionManager.json",
"IChainTypeManager.sol/IChainTypeManager.json",
);
const ZKSYNC_HYPERCHAIN_CONTRACT_FILE: (&str, &str) = (
"state-transition/chain-interfaces",
"IZkSyncHyperchain.sol/IZkSyncHyperchain.json",
"IZKChain.sol/IZKChain.json",
);
const DIAMOND_INIT_CONTRACT_FILE: (&str, &str) = (
"state-transition",
Expand Down
2 changes: 2 additions & 0 deletions core/lib/env_config/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ mod tests {
l2_native_token_vault_proxy_addr: Some(addr(
"0xfc073319977e314f251eae6ae6be76b0b3baeecf",
)),
l2_legacy_shared_bridge_addr: Some(addr("0x8656770FA78c830456B00B4fFCeE6b1De0e1b888")),
chain_admin_addr: Some(addr("0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347ff")),
l2_da_validator_addr: Some(addr("0xed6fa5c14e7550b4caf2aa2818d24c69cbc347ff")),
}
Expand Down Expand Up @@ -130,6 +131,7 @@ CONTRACTS_USER_FACING_DIAMOND_PROXY_ADDR="0xF00B988a98Ca742e7958DeF9F7823b590871
CONTRACTS_L2_NATIVE_TOKEN_VAULT_PROXY_ADDR="0xfc073319977e314f251eae6ae6be76b0b3baeecf"
CONTRACTS_L2_DA_VALIDATOR_ADDR="0xed6fa5c14e7550b4caf2aa2818d24c69cbc347ff"
CONTRACTS_CHAIN_ADMIN_ADDR="0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347ff"
CONTRACTS_L2_LEGACY_SHARED_BRIDGE_ADDR="0x8656770FA78c830456B00B4fFCeE6b1De0e1b888"
"#;
lock.set_env(config);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use zksync_types::{
commitment::{L1BatchCommitmentMode, L1BatchWithMetadata},
ethabi::Token,
ethabi::{encode, Token},
pubdata_da::PubdataDA,
};

use crate::{
i_executor::structures::{CommitBatchInfo, StoredBatchInfo},
Tokenizable, Tokenize,
i_executor::structures::{CommitBatchInfo, StoredBatchInfo, SUPPORTED_ENCODING_VERSION},
Tokenizable,
};

/// Input required to encode `commitBatches` call for a contract
#[derive(Debug)]
pub struct CommitBatches<'a> {
Expand All @@ -18,15 +17,33 @@ pub struct CommitBatches<'a> {
pub mode: L1BatchCommitmentMode,
}

impl Tokenize for CommitBatches<'_> {
fn into_tokens(self) -> Vec<Token> {
impl CommitBatches<'_> {
pub fn into_tokens(self, pre_gateway: bool) -> Vec<Token> {
let stored_batch_info = StoredBatchInfo::from(self.last_committed_l1_batch).into_token();
let l1_batches_to_commit = self
let l1_batches_to_commit: Vec<Token> = self
.l1_batches
.iter()
.map(|batch| CommitBatchInfo::new(self.mode, batch, self.pubdata_da).into_token())
.collect();

vec![stored_batch_info, Token::Array(l1_batches_to_commit)]
let encoded_data = encode(&[
stored_batch_info.clone(),
Token::Array(l1_batches_to_commit.clone()),
]);
let commit_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data]
.concat()
.to_vec();
if pre_gateway {
vec![stored_batch_info, Token::Array(l1_batches_to_commit)]
} else {
vec![
Token::Uint((self.last_committed_l1_batch.header.number.0 + 1).into()),
Token::Uint(
(self.last_committed_l1_batch.header.number.0 + self.l1_batches.len() as u32)
.into(),
),
Token::Bytes(commit_data),
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use zksync_types::{
commitment::{L1BatchWithMetadata, PriorityOpsMerkleProof},
ethabi::Token,
ethabi::{encode, Token},
};

use crate::{i_executor::structures::StoredBatchInfo, Tokenizable, Tokenize};
use crate::{
i_executor::structures::{StoredBatchInfo, SUPPORTED_ENCODING_VERSION},
Tokenizable, Tokenize,
};

/// Input required to encode `executeBatches` call.
#[derive(Debug, Clone)]
Expand All @@ -14,7 +17,7 @@ pub struct ExecuteBatches {

impl Tokenize for &ExecuteBatches {
fn into_tokens(self) -> Vec<Token> {
vec![
let encoded_data = encode(&[
Token::Array(
self.l1_batches
.iter()
Expand All @@ -27,6 +30,15 @@ impl Tokenize for &ExecuteBatches {
.map(|proof| proof.into_token())
.collect(),
),
]);
let commit_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data]
.concat()
.to_vec();

vec![
Token::Uint((self.l1_batches[0].header.number.0).into()),
Token::Uint((self.l1_batches[self.l1_batches.len() - 1].header.number.0).into()),
Token::Bytes(commit_data),
]
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
use crypto_codegen::serialize_proof;
use zksync_prover_interface::outputs::L1BatchProofForL1;
use zksync_types::{commitment::L1BatchWithMetadata, ethabi::Token, U256};
use zksync_types::{
commitment::L1BatchWithMetadata,
ethabi::{encode, Token},
U256,
};

use crate::{i_executor::structures::StoredBatchInfo, Tokenizable, Tokenize};
use crate::{
i_executor::structures::{StoredBatchInfo, SUPPORTED_ENCODING_VERSION},
Tokenizable, Tokenize,
};

/// Input required to encode `proveBatches` call.
#[derive(Debug, Clone)]
Expand All @@ -15,7 +22,7 @@ pub struct ProveBatches {

impl Tokenize for &ProveBatches {
fn into_tokens(self) -> Vec<Token> {
let prev_l1_batch = StoredBatchInfo::from(&self.prev_l1_batch).into_token();
let prev_l1_batch_info = StoredBatchInfo::from(&self.prev_l1_batch).into_token();
let batches_arg = self
.l1_batches
.iter()
Expand All @@ -42,26 +49,46 @@ impl Tokenize for &ProveBatches {
.unwrap()
.is_pre_boojum()
{
Token::Array(
aggregation_result_coords
.iter()
.map(|bytes| Token::Uint(U256::from_big_endian(bytes)))
.collect(),
)
aggregation_result_coords
.iter()
.map(|bytes| Token::Uint(U256::from_big_endian(bytes)))
.collect()
} else {
Token::Array(Vec::new())
Vec::new()
};
let proof_input = Token::Tuple(vec![
aggregation_result_coords,
Token::Array(proof.into_iter().map(Token::Uint).collect()),
]);
let proof_input = Token::Array(
[
aggregation_result_coords,
proof.into_iter().map(Token::Uint).collect(),
]
.concat()
.to_vec(),
); // todo this changed, might have to be debugged.

let encoded_data = encode(&[prev_l1_batch_info, batches_arg, proof_input]);
let commit_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data]
.concat()
.to_vec();

vec![prev_l1_batch, batches_arg, proof_input]
vec![
Token::Uint((self.prev_l1_batch.header.number.0 + 1).into()),
Token::Uint(
(self.prev_l1_batch.header.number.0 + self.l1_batches.len() as u32).into(),
),
Token::Bytes(commit_data),
]
} else {
let encoded_data = encode(&[prev_l1_batch_info, batches_arg, Token::Array(vec![])]);
let commit_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data]
.concat()
.to_vec();

vec![
prev_l1_batch,
batches_arg,
Token::Tuple(vec![Token::Array(vec![]), Token::Array(vec![])]),
Token::Uint((self.prev_l1_batch.header.number.0 + 1).into()),
Token::Uint(
(self.prev_l1_batch.header.number.0 + self.l1_batches.len() as u32).into(),
),
Token::Bytes(commit_data),
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use zksync_types::{
pre_boojum_serialize_commitments, serialize_commitments, L1BatchCommitmentMode,
L1BatchWithMetadata,
},
ethabi::Token,
ethabi::{ParamType, Token},
pubdata_da::PubdataDA,
web3::{contract::Error as ContractError, keccak256},
ProtocolVersionId, H256, U256,
Expand Down Expand Up @@ -42,6 +42,21 @@ impl<'a> CommitBatchInfo<'a> {
}
}

pub fn schema() -> ParamType {
ParamType::Tuple(vec![
ParamType::Uint(64), // `batch_number`
ParamType::Uint(64), // `timestamp`
ParamType::Uint(64), // `index_repeated_storage_changes`
ParamType::FixedBytes(32), // `new_state_root`
ParamType::Uint(256), // `numberOfLayer1Txs`
ParamType::FixedBytes(32), // `priorityOperationsHash`
ParamType::FixedBytes(32), // `bootloaderHeapInitialContentsHash`
ParamType::FixedBytes(32), // `eventsQueueStateHash`
ParamType::Bytes, // `systemLogs`
ParamType::Bytes, // `operatorDAInput`
])
}

fn base_tokens(&self) -> Vec<Token> {
if self
.l1_batch_with_metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
mod commit_batch_info;
mod stored_batch_info;
pub const SUPPORTED_ENCODING_VERSION: u8 = 0;

pub use self::{commit_batch_info::CommitBatchInfo, stored_batch_info::StoredBatchInfo};
Loading

0 comments on commit 22a3eef

Please sign in to comment.