Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/sync-layer-stable' into lyova-in…
Browse files Browse the repository at this point in the history
…tegrate-priority-merkle-tree_
  • Loading branch information
ly0va committed Jun 27, 2024
2 parents 7e192d8 + e820f90 commit 9fa2799
Show file tree
Hide file tree
Showing 22 changed files with 174 additions and 86 deletions.
98 changes: 49 additions & 49 deletions .github/workflows/vm-perf-comparison.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,61 +18,61 @@ jobs:
fetch-depth: 0
ref: ${{ github.base_ref }}

- name: fetch PR branch
run: |
git remote add pr_repo ${{ github.event.pull_request.head.repo.clone_url }}
git fetch pr_repo ${{ github.event.pull_request.head.ref }}
# - name: fetch PR branch
# run: |
# git remote add pr_repo ${{ github.event.pull_request.head.repo.clone_url }}
# git fetch pr_repo ${{ github.event.pull_request.head.ref }}

- name: fetch merge-base SHA
id: merge_base
run: echo "sha=$(git merge-base HEAD FETCH_HEAD)" >> $GITHUB_OUTPUT
# - name: fetch merge-base SHA
# id: merge_base
# run: echo "sha=$(git merge-base HEAD FETCH_HEAD)" >> $GITHUB_OUTPUT

- name: checkout divergence point
run: git checkout ${{ steps.merge_base.outputs.sha }} --recurse-submodules
# - name: checkout divergence point
# run: git checkout ${{ steps.merge_base.outputs.sha }} --recurse-submodules

- name: setup-env
run: |
touch .env
echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV
echo $(pwd)/bin >> $GITHUB_PATH
# - name: setup-env
# run: |
# touch .env
# echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV
# echo $(pwd)/bin >> $GITHUB_PATH

- name: init
run: |
run_retried docker compose pull zk
docker compose up -d zk
# - name: init
# run: |
# run_retried docker compose pull zk
# docker compose up -d zk

- name: run benchmarks on base branch
shell: bash
run: |
ci_run zk
ci_run zk compiler system-contracts
ci_run cargo bench --package vm-benchmark --bench iai | tee base-iai
ci_run cargo run --package vm-benchmark --release --bin instruction-counts | tee base-opcodes || touch base-opcodes
ci_run yarn workspace system-contracts clean
# - name: run benchmarks on base branch
# shell: bash
# run: |
# ci_run zk
# ci_run zk compiler system-contracts
# ci_run cargo bench --package vm-benchmark --bench iai | tee base-iai
# ci_run cargo run --package vm-benchmark --release --bin instruction-counts | tee base-opcodes || touch base-opcodes
# ci_run yarn workspace system-contracts clean

- name: checkout PR
run: git checkout --force FETCH_HEAD --recurse-submodules
# - name: checkout PR
# run: git checkout --force FETCH_HEAD --recurse-submodules

- name: run benchmarks on PR
shell: bash
run: |
ci_run zk
ci_run zk compiler system-contracts
ci_run cargo bench --package vm-benchmark --bench iai | tee pr-iai
ci_run cargo run --package vm-benchmark --release --bin instruction-counts | tee pr-opcodes || touch pr-opcodes
# - name: run benchmarks on PR
# shell: bash
# run: |
# ci_run zk
# ci_run zk compiler system-contracts
# ci_run cargo bench --package vm-benchmark --bench iai | tee pr-iai
# ci_run cargo run --package vm-benchmark --release --bin instruction-counts | tee pr-opcodes || touch pr-opcodes

EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "speedup<<$EOF" >> $GITHUB_OUTPUT
ci_run cargo run --package vm-benchmark --release --bin compare_iai_results base-iai pr-iai base-opcodes pr-opcodes >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
id: comparison
# EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
# echo "speedup<<$EOF" >> $GITHUB_OUTPUT
# ci_run cargo run --package vm-benchmark --release --bin compare_iai_results base-iai pr-iai base-opcodes pr-opcodes >> $GITHUB_OUTPUT
# echo "$EOF" >> $GITHUB_OUTPUT
# id: comparison

- name: Comment on PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
${{ steps.comparison.outputs.speedup == '' && '## No performance difference detected (anymore)' || '## Detected VM performance changes' }}
${{ steps.comparison.outputs.speedup }}
comment_tag: vm-performance-changes
mode: recreate
create_if_not_exists: ${{ steps.comparison.outputs.speedup != '' }}
# - name: Comment on PR
# uses: thollander/actions-comment-pull-request@v2
# with:
# message: |
# ${{ steps.comparison.outputs.speedup == '' && '## No performance difference detected (anymore)' || '## Detected VM performance changes' }}
# ${{ steps.comparison.outputs.speedup }}
# comment_tag: vm-performance-changes
# mode: recreate
# create_if_not_exists: ${{ steps.comparison.outputs.speedup != '' }}
2 changes: 1 addition & 1 deletion core/bin/zksync_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ async fn main() -> anyhow::Result<()> {
&database_secrets,
)
.await
.context("Failed to save SetChainId upgrade transaction")?;
.context("Failed to save Genesis upgrade transaction")?;
}

if opt.genesis {
Expand Down
14 changes: 13 additions & 1 deletion core/lib/constants/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,26 @@ pub const CREATE2_FACTORY_ADDRESS: Address = H160([
0x00, 0x01, 0x00, 0x00,
]);

pub const GENESIS_UPGRADE_ADDRESS: Address = H160([
pub const L2_GENESIS_UPGRADE_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x01,
]);
pub const L2_BRIDGEHUB_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x02,
]);
pub const L2_ASSET_ROUTER_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03,
]);
pub const L2_NATIVE_TOKEN_VAULT_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x04,
]);
pub const L2_MESSAGE_ROOT_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x05,
]);

pub const ERC20_TRANSFER_TOPIC: H256 = H256([
221, 242, 82, 173, 27, 226, 200, 155, 105, 194, 176, 104, 252, 55, 141, 170, 149, 43, 167, 241,
Expand Down
17 changes: 12 additions & 5 deletions core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ impl BaseSystemContracts {

pub fn playground_sync_layer() -> Self {
let bootloader_bytecode = read_zbin_bytecode(
"etc/multivm_bootloaders/vm_sync_layer/playground_batch.yul/playground_batch.yul.zbin",
"contracts/system-contracts/bootloader/build/artifacts/playground_batch.yul.zbin",
// "etc/multivm_bootloaders/vm_sync_layer/playground_batch.yul/playground_batch.yul.zbin",
);
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}
Expand Down Expand Up @@ -469,7 +470,8 @@ impl BaseSystemContracts {

pub fn estimate_gas_sync_layer() -> Self {
let bootloader_bytecode = read_zbin_bytecode(
"etc/multivm_bootloaders/vm_sync_layer/fee_estimate.yul/fee_estimate.yul.zbin",
"contracts/system-contracts/bootloader/build/artifacts/fee_estimate.yul.zbin",
// "etc/multivm_bootloaders/vm_sync_layer/fee_estimate.yul/fee_estimate.yul.zbin",
);
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}
Expand Down Expand Up @@ -609,14 +611,14 @@ pub static PRE_BOOJUM_COMMIT_FUNCTION: Lazy<Function> = Lazy::new(|| {
serde_json::from_str(abi).unwrap()
});

pub static SET_CHAIN_ID_EVENT: Lazy<Event> = Lazy::new(|| {
pub static GENESIS_UPGRADE_EVENT: Lazy<Event> = Lazy::new(|| {
let abi = r#"
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_stateTransitionChain",
"name": "_hyperchain",
"type": "address"
},
{
Expand Down Expand Up @@ -694,9 +696,14 @@ pub static SET_CHAIN_ID_EVENT: Lazy<Event> = Lazy::new(|| {
"indexed": true,
"name": "_protocolVersion",
"type": "uint256"
},
{
"indexed": false,
"name": "_factoryDeps",
"type": "bytes[]"
}
],
"name": "SetChainIdUpgrade",
"name": "GenesisUpgrade",
"type": "event"
}"#;
serde_json::from_str(abi).unwrap()
Expand Down
2 changes: 1 addition & 1 deletion core/lib/types/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl L2CanonicalTransaction {
pub fn decode(token: Token) -> anyhow::Result<Self> {
let tokens = token.into_tuple().context("not a tuple")?;
anyhow::ensure!(tokens.len() == 16);
let mut t = tokens.into_iter();
let mut t: std::vec::IntoIter<Token> = tokens.into_iter();
let mut next = || t.next().unwrap();
Ok(Self {
tx_type: next().into_uint().context("tx_type")?,
Expand Down
37 changes: 30 additions & 7 deletions core/lib/types/src/protocol_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ use zksync_contracts::{
use zksync_utils::h256_to_u256;

use crate::{
abi, ethabi::ParamType, web3::Log, Address, Execute, ExecuteTransactionCommon, Transaction,
TransactionType, H256, U256,
abi,
ethabi::{ParamType, Token},
web3::Log,
Address, Execute, ExecuteTransactionCommon, Transaction, TransactionType, H256, U256,
};

/// Represents a call to be made during governance operation.
Expand Down Expand Up @@ -135,12 +137,33 @@ impl ProtocolUpgrade {
}
}

pub fn decode_set_chain_id_event(
pub fn decode_genesis_upgrade_event(
event: Log,
) -> Result<(ProtocolVersionId, ProtocolUpgradeTx), ethabi::Error> {
let tx = ethabi::decode(&[abi::L2CanonicalTransaction::schema()], &event.data.0)?;
let tx = abi::L2CanonicalTransaction::decode(tx.into_iter().next().unwrap()).unwrap();

let tokens = ethabi::decode(
&[
abi::L2CanonicalTransaction::schema(),
ParamType::Array(Box::new(ParamType::Bytes)),
],
&event.data.0,
)?;
let mut t: std::vec::IntoIter<Token> = tokens.into_iter();
let mut next = || t.next().unwrap();

let tx = abi::L2CanonicalTransaction::decode(next()).unwrap();
let factory_deps = next()
.into_array()
.context("factory_deps")
.unwrap()
// todo proper error
// .map_err(|e| ethabi::Error::Other(&e.to_sting().as_ref().into()))?
.into_iter()
.enumerate()
.map(|(i, t)| t.into_bytes().context(i))
.collect::<Result<Vec<Vec<u8>>, _>>()
.context("factory_deps")
.unwrap();
// .map_err(|e| ethabi::Error::Other(e.to_string()))?;
let full_version_id = h256_to_u256(event.topics[2]);
let protocol_version = ProtocolVersionId::try_from_packed_semver(full_version_id)
.unwrap_or_else(|_| panic!("Version is not supported, packed version: {full_version_id}"));
Expand All @@ -152,7 +175,7 @@ pub fn decode_set_chain_id_event(
.block_number
.expect("Event block number is missing")
.as_u64(),
factory_deps: vec![],
factory_deps,
})
.unwrap()
.try_into()
Expand Down
35 changes: 30 additions & 5 deletions core/lib/types/src/system_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use zksync_basic_types::{AccountTreeId, Address, U256};
use zksync_contracts::{read_sys_contract_bytecode, ContractLanguage, SystemContractsRepo};
use zksync_system_constants::{
BOOTLOADER_UTILITIES_ADDRESS, CODE_ORACLE_ADDRESS, COMPRESSOR_ADDRESS, CREATE2_FACTORY_ADDRESS,
EVENT_WRITER_ADDRESS, GENESIS_UPGRADE_ADDRESS, P256VERIFY_PRECOMPILE_ADDRESS,
PUBDATA_CHUNK_PUBLISHER_ADDRESS,
EVENT_WRITER_ADDRESS, L2_ASSET_ROUTER_ADDRESS, L2_BRIDGEHUB_ADDRESS,
L2_GENESIS_UPGRADE_ADDRESS, L2_MESSAGE_ROOT_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS,
P256VERIFY_PRECOMPILE_ADDRESS, PUBDATA_CHUNK_PUBLISHER_ADDRESS,
};

use crate::{
Expand All @@ -26,7 +27,7 @@ use crate::{
pub const TX_NONCE_INCREMENT: U256 = U256([1, 0, 0, 0]); // 1
pub const DEPLOYMENT_NONCE_INCREMENT: U256 = U256([0, 0, 1, 0]); // 2^128

static SYSTEM_CONTRACT_LIST: [(&str, &str, Address, ContractLanguage); 26] = [
static SYSTEM_CONTRACT_LIST: [(&str, &str, Address, ContractLanguage); 30] = [
(
"",
"AccountCodeStorage",
Expand Down Expand Up @@ -171,8 +172,32 @@ static SYSTEM_CONTRACT_LIST: [(&str, &str, Address, ContractLanguage); 26] = [
),
(
"",
"GenesisUpgrade",
GENESIS_UPGRADE_ADDRESS,
"L2GenesisUpgrade",
L2_GENESIS_UPGRADE_ADDRESS,
ContractLanguage::Sol,
),
(
"../../../l1-contracts/artifacts-zk/contracts/bridgehub/",
"Bridgehub",
L2_BRIDGEHUB_ADDRESS,
ContractLanguage::Sol,
),
(
"../../../l1-contracts/artifacts-zk/contracts/bridgehub/",
"MessageRoot",
L2_MESSAGE_ROOT_ADDRESS,
ContractLanguage::Sol,
),
(
"../../../l2-contracts/artifacts-zk/contracts/bridge/",
"L2AssetRouter",
L2_ASSET_ROUTER_ADDRESS,
ContractLanguage::Sol,
),
(
"../../../l2-contracts/artifacts-zk/contracts/bridge/",
"L2NativeTokenVault",
L2_NATIVE_TOKEN_VAULT_ADDRESS,
ContractLanguage::Sol,
),
];
Expand Down
27 changes: 22 additions & 5 deletions core/node/genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::fmt::Formatter;
use anyhow::Context as _;
use multivm::utils::get_max_gas_per_pubdata_byte;
use zksync_config::{configs::DatabaseSecrets, GenesisConfig};
use zksync_contracts::{BaseSystemContracts, BaseSystemContractsHashes, SET_CHAIN_ID_EVENT};
use zksync_contracts::{BaseSystemContracts, BaseSystemContractsHashes, GENESIS_UPGRADE_EVENT};
use zksync_dal::{Connection, ConnectionPool, Core, CoreDal, DalError};
use zksync_eth_client::EthInterface;
use zksync_merkle_tree::{domain::ZkSyncTree, TreeInstruction};
Expand All @@ -16,7 +16,7 @@ use zksync_types::{
block::{BlockGasCount, DeployedContract, L1BatchHeader, L2BlockHasher, L2BlockHeader},
commitment::{CommitmentInput, L1BatchCommitment},
fee_model::BatchFeeInput,
protocol_upgrade::decode_set_chain_id_event,
protocol_upgrade::decode_genesis_upgrade_event,
protocol_version::{L1VerifierConfig, ProtocolSemanticVersion, VerifierParams},
system_contracts::get_system_smart_contracts,
web3::{BlockNumber, FilterBuilder},
Expand Down Expand Up @@ -94,6 +94,16 @@ impl GenesisParams {
base_system_contracts: BaseSystemContracts,
system_contracts: Vec<DeployedContract>,
) -> Result<GenesisParams, GenesisError> {
println!(
"
bootloader_hash = \"{:?}\"
default_aa_hash = \"{:?}\"
GENESIS_PROTOCOL_SEMANTIC_VERSION = \"{:?}\"
",
base_system_contracts.hashes().bootloader,
base_system_contracts.hashes().default_aa,
config.protocol_version.unwrap(),
);
let base_system_contracts_hashes = BaseSystemContractsHashes {
bootloader: config
.bootloader_hash
Expand Down Expand Up @@ -290,7 +300,14 @@ pub async fn ensure_genesis_state(
commitment,
rollup_last_leaf_index,
} = insert_genesis_batch(&mut transaction, genesis_params).await?;

println!(
"
GENESIS_ROOT = \"{:?}\"
GENESIS_BATCH_COMMITMENT = \"{:?}\"
GENESIS_ROLLUP_LEAF_INDEX = \"{:?}\"
",
root_hash, commitment, rollup_last_leaf_index
);
let expected_root_hash = genesis_params
.config
.genesis_root_hash
Expand Down Expand Up @@ -424,7 +441,7 @@ pub async fn save_set_chain_id_tx(
let filter = FilterBuilder::default()
.address(vec![diamond_proxy_address])
.topics(
Some(vec![SET_CHAIN_ID_EVENT.signature()]),
Some(vec![GENESIS_UPGRADE_EVENT.signature()]),
Some(vec![diamond_proxy_address.into()]),
None,
None,
Expand All @@ -440,7 +457,7 @@ pub async fn save_set_chain_id_tx(
logs
);
let (version_id, upgrade_tx) =
decode_set_chain_id_event(logs.remove(0)).context("Chain id event is incorrect")?;
decode_genesis_upgrade_event(logs.remove(0)).context("Chain id event is incorrect")?;

tracing::info!("New version id {:?}", version_id);
storage
Expand Down
Loading

0 comments on commit 9fa2799

Please sign in to comment.