From e7879b0f99a0d3dbdca9e7f3ed58c492e9839148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cperekopskiy=E2=80=9D?= Date: Mon, 6 Nov 2023 14:34:43 +0200 Subject: [PATCH] Some fixes --- Cargo.lock | 1 - core/lib/contracts/src/lib.rs | 172 ++++++ ...m_logs_and_compressed_state_diffs.down.sql | 5 - ...tem_logs_and_compressed_state_diffs.up.sql | 6 - core/lib/dal/sqlx-data.json | 503 +++++++++--------- core/lib/dal/src/blocks_dal.rs | 9 +- core/lib/state/src/rocksdb/mod.rs | 16 +- core/lib/types/src/commitment.rs | 2 +- core/lib/types/src/fee.rs | 3 +- core/lib/types/src/l2_to_l1_log.rs | 5 +- core/lib/types/src/tx/tx_execution_info.rs | 19 +- core/lib/zksync_core/Cargo.toml | 2 - .../src/api_server/tx_sender/mod.rs | 2 +- .../src/api_server/web3/namespaces/zks.rs | 2 +- .../lib/zksync_core/src/block_reverter/mod.rs | 6 +- .../src/eth_sender/eth_tx_aggregator.rs | 2 +- .../src/eth_sender/zksync_functions.rs | 7 +- .../eth_watch/event_processors/upgrades.rs | 205 +------ core/lib/zksync_core/src/eth_watch/tests.rs | 7 +- core/lib/zksync_core/src/gas_tracker/mod.rs | 16 +- .../zksync_core/src/state_keeper/keeper.rs | 8 +- .../seal_criteria/criteria/pubdata_bytes.rs | 7 +- .../src/state_keeper/seal_criteria/mod.rs | 3 +- .../cross-external-nodes-checker/Dockerfile | 4 - 24 files changed, 495 insertions(+), 517 deletions(-) delete mode 100644 core/lib/dal/migrations/20230807204005_add_fields_for_system_logs_and_compressed_state_diffs.down.sql delete mode 100644 core/lib/dal/migrations/20230807204005_add_fields_for_system_logs_and_compressed_state_diffs.up.sql diff --git a/Cargo.lock b/Cargo.lock index caace59cdda3..066196eac133 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8033,7 +8033,6 @@ dependencies = [ "tracing", "vise", "vlog", - "zkevm_test_harness 1.4.0", "zksync_circuit_breaker", "zksync_commitment_utils", "zksync_config", diff --git a/core/lib/contracts/src/lib.rs b/core/lib/contracts/src/lib.rs index 9e629b271b8c..01dce6a98f9f 100644 --- a/core/lib/contracts/src/lib.rs +++ b/core/lib/contracts/src/lib.rs @@ -716,3 +716,175 @@ pub static PRE_BOOJUM_EXECUTE_FUNCTION: Lazy = Lazy::new(|| { }"#; serde_json::from_str(abi).unwrap() }); + +pub static PRE_BOOJUM_GET_VK_FUNCTION: Lazy = Lazy::new(|| { + let abi = r#"{ + "inputs": [], + "name": "get_verification_key", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "domain_size", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "num_inputs", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "internalType": "struct PairingsBn254.Fr", + "name": "omega", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "X", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "Y", + "type": "uint256" + } + ], + "internalType": "struct PairingsBn254.G1Point[2]", + "name": "gate_selectors_commitments", + "type": "tuple[2]" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "X", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "Y", + "type": "uint256" + } + ], + "internalType": "struct PairingsBn254.G1Point[8]", + "name": "gate_setup_commitments", + "type": "tuple[8]" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "X", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "Y", + "type": "uint256" + } + ], + "internalType": "struct PairingsBn254.G1Point[4]", + "name": "permutation_commitments", + "type": "tuple[4]" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "X", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "Y", + "type": "uint256" + } + ], + "internalType": "struct PairingsBn254.G1Point", + "name": "lookup_selector_commitment", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "X", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "Y", + "type": "uint256" + } + ], + "internalType": "struct PairingsBn254.G1Point[4]", + "name": "lookup_tables_commitments", + "type": "tuple[4]" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "X", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "Y", + "type": "uint256" + } + ], + "internalType": "struct PairingsBn254.G1Point", + "name": "lookup_table_type_commitment", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "internalType": "struct PairingsBn254.Fr[3]", + "name": "non_residues", + "type": "tuple[3]" + }, + { + "components": [ + { + "internalType": "uint256[2]", + "name": "X", + "type": "uint256[2]" + }, + { + "internalType": "uint256[2]", + "name": "Y", + "type": "uint256[2]" + } + ], + "internalType": "struct PairingsBn254.G2Point[2]", + "name": "g2_elements", + "type": "tuple[2]" + } + ], + "internalType": "struct VerificationKey", + "name": "vk", + "type": "tuple" + } + ], + "stateMutability": "pure", + "type": "function" + }"#; + serde_json::from_str(abi).unwrap() +}); diff --git a/core/lib/dal/migrations/20230807204005_add_fields_for_system_logs_and_compressed_state_diffs.down.sql b/core/lib/dal/migrations/20230807204005_add_fields_for_system_logs_and_compressed_state_diffs.down.sql deleted file mode 100644 index 69df17ae9a73..000000000000 --- a/core/lib/dal/migrations/20230807204005_add_fields_for_system_logs_and_compressed_state_diffs.down.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE l1_batches - DROP COLUMN IF EXISTS system_logs; - -ALTER TABLE l1_batches - DROP COLUMN IF EXISTS compressed_state_diffs; diff --git a/core/lib/dal/migrations/20230807204005_add_fields_for_system_logs_and_compressed_state_diffs.up.sql b/core/lib/dal/migrations/20230807204005_add_fields_for_system_logs_and_compressed_state_diffs.up.sql deleted file mode 100644 index d9b782b6f4df..000000000000 --- a/core/lib/dal/migrations/20230807204005_add_fields_for_system_logs_and_compressed_state_diffs.up.sql +++ /dev/null @@ -1,6 +0,0 @@ -ALTER TABLE l1_batches - ADD COLUMN IF NOT EXISTS system_logs BYTEA[] - NOT NULL DEFAULT '{}'; - -ALTER TABLE l1_batches - ADD COLUMN IF NOT EXISTS compressed_state_diffs BYTEA; diff --git a/core/lib/dal/sqlx-data.json b/core/lib/dal/sqlx-data.json index b8430e752170..bcd9a6ccf7de 100644 --- a/core/lib/dal/sqlx-data.json +++ b/core/lib/dal/sqlx-data.json @@ -692,6 +692,258 @@ }, "query": "SELECT l1_address FROM tokens WHERE market_volume > $1" }, + "15fa7f79b062dc622bbbcdb2a63f752dbd57cc0bf13b6c8452eb8914dc723d4b": { + "describe": { + "columns": [ + { + "name": "number", + "ordinal": 0, + "type_info": "Int8" + }, + { + "name": "timestamp", + "ordinal": 1, + "type_info": "Int8" + }, + { + "name": "is_finished", + "ordinal": 2, + "type_info": "Bool" + }, + { + "name": "l1_tx_count", + "ordinal": 3, + "type_info": "Int4" + }, + { + "name": "l2_tx_count", + "ordinal": 4, + "type_info": "Int4" + }, + { + "name": "fee_account_address", + "ordinal": 5, + "type_info": "Bytea" + }, + { + "name": "bloom", + "ordinal": 6, + "type_info": "Bytea" + }, + { + "name": "priority_ops_onchain_data", + "ordinal": 7, + "type_info": "ByteaArray" + }, + { + "name": "hash", + "ordinal": 8, + "type_info": "Bytea" + }, + { + "name": "parent_hash", + "ordinal": 9, + "type_info": "Bytea" + }, + { + "name": "commitment", + "ordinal": 10, + "type_info": "Bytea" + }, + { + "name": "compressed_write_logs", + "ordinal": 11, + "type_info": "Bytea" + }, + { + "name": "compressed_contracts", + "ordinal": 12, + "type_info": "Bytea" + }, + { + "name": "eth_prove_tx_id", + "ordinal": 13, + "type_info": "Int4" + }, + { + "name": "eth_commit_tx_id", + "ordinal": 14, + "type_info": "Int4" + }, + { + "name": "eth_execute_tx_id", + "ordinal": 15, + "type_info": "Int4" + }, + { + "name": "merkle_root_hash", + "ordinal": 16, + "type_info": "Bytea" + }, + { + "name": "l2_to_l1_logs", + "ordinal": 17, + "type_info": "ByteaArray" + }, + { + "name": "l2_to_l1_messages", + "ordinal": 18, + "type_info": "ByteaArray" + }, + { + "name": "used_contract_hashes", + "ordinal": 19, + "type_info": "Jsonb" + }, + { + "name": "compressed_initial_writes", + "ordinal": 20, + "type_info": "Bytea" + }, + { + "name": "compressed_repeated_writes", + "ordinal": 21, + "type_info": "Bytea" + }, + { + "name": "l2_l1_compressed_messages", + "ordinal": 22, + "type_info": "Bytea" + }, + { + "name": "l2_l1_merkle_root", + "ordinal": 23, + "type_info": "Bytea" + }, + { + "name": "l1_gas_price", + "ordinal": 24, + "type_info": "Int8" + }, + { + "name": "l2_fair_gas_price", + "ordinal": 25, + "type_info": "Int8" + }, + { + "name": "rollup_last_leaf_index", + "ordinal": 26, + "type_info": "Int8" + }, + { + "name": "zkporter_is_available", + "ordinal": 27, + "type_info": "Bool" + }, + { + "name": "bootloader_code_hash", + "ordinal": 28, + "type_info": "Bytea" + }, + { + "name": "default_aa_code_hash", + "ordinal": 29, + "type_info": "Bytea" + }, + { + "name": "base_fee_per_gas", + "ordinal": 30, + "type_info": "Numeric" + }, + { + "name": "aux_data_hash", + "ordinal": 31, + "type_info": "Bytea" + }, + { + "name": "pass_through_data_hash", + "ordinal": 32, + "type_info": "Bytea" + }, + { + "name": "meta_parameters_hash", + "ordinal": 33, + "type_info": "Bytea" + }, + { + "name": "protocol_version", + "ordinal": 34, + "type_info": "Int4" + }, + { + "name": "compressed_state_diffs", + "ordinal": 35, + "type_info": "Bytea" + }, + { + "name": "system_logs", + "ordinal": 36, + "type_info": "ByteaArray" + }, + { + "name": "events_queue_commitment", + "ordinal": 37, + "type_info": "Bytea" + }, + { + "name": "bootloader_initial_content_commitment", + "ordinal": 38, + "type_info": "Bytea" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + false, + false, + true, + true, + true, + true, + true, + true, + true, + true, + true, + false, + false, + false, + true, + true, + true, + true, + false, + false, + true, + true, + true, + true, + false, + true, + true, + true, + true, + true, + false, + true, + true + ], + "parameters": { + "Left": [ + "Bytea", + "Bytea", + "Int4", + "Bool", + "Int8" + ] + } + }, + "query": "SELECT number, l1_batches.timestamp, is_finished, l1_tx_count, l2_tx_count, fee_account_address, bloom, priority_ops_onchain_data, hash, parent_hash, commitment, compressed_write_logs, compressed_contracts, eth_prove_tx_id, eth_commit_tx_id, eth_execute_tx_id, merkle_root_hash, l2_to_l1_logs, l2_to_l1_messages, used_contract_hashes, compressed_initial_writes, compressed_repeated_writes, l2_l1_compressed_messages, l2_l1_merkle_root, l1_gas_price, l2_fair_gas_price, rollup_last_leaf_index, zkporter_is_available, l1_batches.bootloader_code_hash, l1_batches.default_aa_code_hash, base_fee_per_gas, aux_data_hash, pass_through_data_hash, meta_parameters_hash, protocol_version, compressed_state_diffs, system_logs, events_queue_commitment, bootloader_initial_content_commitment FROM l1_batches LEFT JOIN commitments ON commitments.l1_batch_number = l1_batches.number JOIN protocol_versions ON protocol_versions.id = l1_batches.protocol_version WHERE eth_commit_tx_id IS NULL AND number != 0 AND protocol_versions.bootloader_code_hash = $1 AND protocol_versions.default_account_code_hash = $2 AND commitment IS NOT NULL AND (protocol_versions.id = $3 OR protocol_versions.upgrade_tx_hash IS NULL) AND (events_queue_commitment IS NOT NULL AND bootloader_initial_content_commitment IS NOT NULL\n OR $4 = FALSE\n )\n ORDER BY number LIMIT $5" + }, "17a42a97e87a675bd465103ebedc63d6d091e5bb093c7905de70aed3dc71d823": { "describe": { "columns": [], @@ -7065,257 +7317,6 @@ }, "query": "\n SELECT value\n FROM storage_logs\n WHERE storage_logs.hashed_key = $1 AND storage_logs.miniblock_number <= $2\n ORDER BY storage_logs.miniblock_number DESC, storage_logs.operation_number DESC\n LIMIT 1\n " }, - "93e9e761f41bc67a91702cefdd8245c15f64aa5ebe550581418aeba8b70632e9": { - "describe": { - "columns": [ - { - "name": "number", - "ordinal": 0, - "type_info": "Int8" - }, - { - "name": "timestamp", - "ordinal": 1, - "type_info": "Int8" - }, - { - "name": "is_finished", - "ordinal": 2, - "type_info": "Bool" - }, - { - "name": "l1_tx_count", - "ordinal": 3, - "type_info": "Int4" - }, - { - "name": "l2_tx_count", - "ordinal": 4, - "type_info": "Int4" - }, - { - "name": "fee_account_address", - "ordinal": 5, - "type_info": "Bytea" - }, - { - "name": "bloom", - "ordinal": 6, - "type_info": "Bytea" - }, - { - "name": "priority_ops_onchain_data", - "ordinal": 7, - "type_info": "ByteaArray" - }, - { - "name": "hash", - "ordinal": 8, - "type_info": "Bytea" - }, - { - "name": "parent_hash", - "ordinal": 9, - "type_info": "Bytea" - }, - { - "name": "commitment", - "ordinal": 10, - "type_info": "Bytea" - }, - { - "name": "compressed_write_logs", - "ordinal": 11, - "type_info": "Bytea" - }, - { - "name": "compressed_contracts", - "ordinal": 12, - "type_info": "Bytea" - }, - { - "name": "eth_prove_tx_id", - "ordinal": 13, - "type_info": "Int4" - }, - { - "name": "eth_commit_tx_id", - "ordinal": 14, - "type_info": "Int4" - }, - { - "name": "eth_execute_tx_id", - "ordinal": 15, - "type_info": "Int4" - }, - { - "name": "merkle_root_hash", - "ordinal": 16, - "type_info": "Bytea" - }, - { - "name": "l2_to_l1_logs", - "ordinal": 17, - "type_info": "ByteaArray" - }, - { - "name": "l2_to_l1_messages", - "ordinal": 18, - "type_info": "ByteaArray" - }, - { - "name": "used_contract_hashes", - "ordinal": 19, - "type_info": "Jsonb" - }, - { - "name": "compressed_initial_writes", - "ordinal": 20, - "type_info": "Bytea" - }, - { - "name": "compressed_repeated_writes", - "ordinal": 21, - "type_info": "Bytea" - }, - { - "name": "l2_l1_compressed_messages", - "ordinal": 22, - "type_info": "Bytea" - }, - { - "name": "l2_l1_merkle_root", - "ordinal": 23, - "type_info": "Bytea" - }, - { - "name": "l1_gas_price", - "ordinal": 24, - "type_info": "Int8" - }, - { - "name": "l2_fair_gas_price", - "ordinal": 25, - "type_info": "Int8" - }, - { - "name": "rollup_last_leaf_index", - "ordinal": 26, - "type_info": "Int8" - }, - { - "name": "zkporter_is_available", - "ordinal": 27, - "type_info": "Bool" - }, - { - "name": "bootloader_code_hash", - "ordinal": 28, - "type_info": "Bytea" - }, - { - "name": "default_aa_code_hash", - "ordinal": 29, - "type_info": "Bytea" - }, - { - "name": "base_fee_per_gas", - "ordinal": 30, - "type_info": "Numeric" - }, - { - "name": "aux_data_hash", - "ordinal": 31, - "type_info": "Bytea" - }, - { - "name": "pass_through_data_hash", - "ordinal": 32, - "type_info": "Bytea" - }, - { - "name": "meta_parameters_hash", - "ordinal": 33, - "type_info": "Bytea" - }, - { - "name": "protocol_version", - "ordinal": 34, - "type_info": "Int4" - }, - { - "name": "compressed_state_diffs", - "ordinal": 35, - "type_info": "Bytea" - }, - { - "name": "system_logs", - "ordinal": 36, - "type_info": "ByteaArray" - }, - { - "name": "events_queue_commitment", - "ordinal": 37, - "type_info": "Bytea" - }, - { - "name": "bootloader_initial_content_commitment", - "ordinal": 38, - "type_info": "Bytea" - } - ], - "nullable": [ - false, - false, - false, - false, - false, - false, - false, - false, - true, - true, - true, - true, - true, - true, - true, - true, - true, - false, - false, - false, - true, - true, - true, - true, - false, - false, - true, - true, - true, - true, - false, - true, - true, - true, - true, - true, - false, - true, - true - ], - "parameters": { - "Left": [ - "Bytea", - "Bytea", - "Int4", - "Int8" - ] - } - }, - "query": "SELECT number, l1_batches.timestamp, is_finished, l1_tx_count, l2_tx_count, fee_account_address, bloom, priority_ops_onchain_data, hash, parent_hash, commitment, compressed_write_logs, compressed_contracts, eth_prove_tx_id, eth_commit_tx_id, eth_execute_tx_id, merkle_root_hash, l2_to_l1_logs, l2_to_l1_messages, used_contract_hashes, compressed_initial_writes, compressed_repeated_writes, l2_l1_compressed_messages, l2_l1_merkle_root, l1_gas_price, l2_fair_gas_price, rollup_last_leaf_index, zkporter_is_available, l1_batches.bootloader_code_hash, l1_batches.default_aa_code_hash, base_fee_per_gas, aux_data_hash, pass_through_data_hash, meta_parameters_hash, protocol_version, compressed_state_diffs, system_logs, events_queue_commitment, bootloader_initial_content_commitment FROM l1_batches LEFT JOIN commitments ON commitments.l1_batch_number = l1_batches.number JOIN protocol_versions ON protocol_versions.id = l1_batches.protocol_version WHERE eth_commit_tx_id IS NULL AND number != 0 AND protocol_versions.bootloader_code_hash = $1 AND protocol_versions.default_account_code_hash = $2 AND commitment IS NOT NULL AND (protocol_versions.id = $3 OR protocol_versions.upgrade_tx_hash IS NULL) AND events_queue_commitment IS NOT NULL AND bootloader_initial_content_commitment IS NOT NULL\n ORDER BY number LIMIT $4" - }, "957ceda740ffb36740acf1e3fbacf76a2ea7422dd9d76a38d745113359e4b7a6": { "describe": { "columns": [ diff --git a/core/lib/dal/src/blocks_dal.rs b/core/lib/dal/src/blocks_dal.rs index d2ea5f6741e9..13e2ebee52ec 100644 --- a/core/lib/dal/src/blocks_dal.rs +++ b/core/lib/dal/src/blocks_dal.rs @@ -1001,6 +1001,7 @@ impl BlocksDal<'_, '_> { default_aa_hash: H256, protocol_version_id: ProtocolVersionId, ) -> anyhow::Result> { + let is_pre_boojum = protocol_version_id.is_pre_boojum(); let raw_batches = sqlx::query_as!( StorageL1Batch, "SELECT number, l1_batches.timestamp, is_finished, l1_tx_count, l2_tx_count, fee_account_address, \ @@ -1021,12 +1022,14 @@ impl BlocksDal<'_, '_> { AND protocol_versions.bootloader_code_hash = $1 AND protocol_versions.default_account_code_hash = $2 \ AND commitment IS NOT NULL \ AND (protocol_versions.id = $3 OR protocol_versions.upgrade_tx_hash IS NULL) \ - AND events_queue_commitment IS NOT NULL \ - AND bootloader_initial_content_commitment IS NOT NULL - ORDER BY number LIMIT $4", + AND (events_queue_commitment IS NOT NULL AND bootloader_initial_content_commitment IS NOT NULL + OR $4 = FALSE + ) + ORDER BY number LIMIT $5", bootloader_hash.as_bytes(), default_aa_hash.as_bytes(), protocol_version_id as i32, + is_pre_boojum, limit as i64, ) .instrument("get_ready_for_commit_l1_batches") diff --git a/core/lib/state/src/rocksdb/mod.rs b/core/lib/state/src/rocksdb/mod.rs index 7cfa9489d9e3..e3748f3acfdf 100644 --- a/core/lib/state/src/rocksdb/mod.rs +++ b/core/lib/state/src/rocksdb/mod.rs @@ -122,14 +122,6 @@ impl RocksdbStorage { } } - #[cfg(test)] - pub fn new_testing(path: &Path) -> Self { - let mut new_self = Self::new(path); - new_self.enable_enum_index_migration(100); - - new_self - } - /// Enables enum indices migration. pub fn enable_enum_index_migration(&mut self, chunk_size: usize) { self.enum_index_migration_chunk_size = chunk_size; @@ -525,7 +517,7 @@ mod tests { #[tokio::test] async fn rocksdb_storage_basics() { let dir = TempDir::new().expect("cannot create temporary dir for state keeper"); - let mut storage = RocksdbStorage::new_testing(dir.path()); + let mut storage = RocksdbStorage::new(dir.path()); let mut storage_logs: HashMap<_, _> = gen_storage_logs(0..20) .into_iter() .map(|log| (log.key, log.value)) @@ -568,7 +560,7 @@ mod tests { create_l1_batch(&mut conn, L1BatchNumber(1), &storage_logs).await; let dir = TempDir::new().expect("cannot create temporary dir for state keeper"); - let mut storage = RocksdbStorage::new_testing(dir.path()); + let mut storage = RocksdbStorage::new(dir.path()); storage.update_from_postgres(&mut conn).await; assert_eq!(storage.l1_batch_number(), L1BatchNumber(2)); @@ -619,7 +611,7 @@ mod tests { create_l1_batch(&mut conn, L1BatchNumber(2), &inserted_storage_logs).await; let dir = TempDir::new().expect("cannot create temporary dir for state keeper"); - let mut storage = RocksdbStorage::new_testing(dir.path()); + let mut storage = RocksdbStorage::new(dir.path()); storage.update_from_postgres(&mut conn).await; // Perform some sanity checks before the revert. @@ -679,7 +671,7 @@ mod tests { .collect(); let dir = TempDir::new().expect("cannot create temporary dir for state keeper"); - let mut storage = RocksdbStorage::new_testing(dir.path()); + let mut storage = RocksdbStorage::new(dir.path()); storage.update_from_postgres(&mut conn).await; assert_eq!(storage.l1_batch_number(), L1BatchNumber(2)); diff --git a/core/lib/types/src/commitment.rs b/core/lib/types/src/commitment.rs index 61dc9bf421c7..6e4ee07d30ef 100644 --- a/core/lib/types/src/commitment.rs +++ b/core/lib/types/src/commitment.rs @@ -338,7 +338,7 @@ impl L1BatchAuxiliaryOutput { .chunks(L2ToL1Log::SERIALIZED_SIZE) .map(|chunk| <[u8; L2ToL1Log::SERIALIZED_SIZE]>::try_from(chunk).unwrap()); // ^ Skip first 4 bytes of the serialized logs (i.e., the number of logs). - let min_tree_size = Some(L2ToL1Log::LEGACY_LIMIT_PER_L1_BATCH); + let min_tree_size = Some(L2ToL1Log::MIN_L2_L1_LOGS_TREE_SIZE); let l2_l1_logs_merkle_root = MiniMerkleTree::new(merkle_tree_leaves, min_tree_size).merkle_root(); diff --git a/core/lib/types/src/fee.rs b/core/lib/types/src/fee.rs index 2de0f031a838..53e05fbb59a9 100644 --- a/core/lib/types/src/fee.rs +++ b/core/lib/types/src/fee.rs @@ -3,7 +3,8 @@ use zksync_utils::ceil_div; use crate::U256; -#[derive(Debug, Default, Clone, Copy)] +#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)] +#[serde(rename_all = "camelCase", tag = "result")] pub struct TransactionExecutionMetrics { pub initial_storage_writes: usize, pub repeated_storage_writes: usize, diff --git a/core/lib/types/src/l2_to_l1_log.rs b/core/lib/types/src/l2_to_l1_log.rs index 13aa5c559fd0..af626ad373a5 100644 --- a/core/lib/types/src/l2_to_l1_log.rs +++ b/core/lib/types/src/l2_to_l1_log.rs @@ -16,10 +16,9 @@ pub struct L2ToL1Log { } impl L2ToL1Log { - /// Legacy upper bound of L2-to-L1 logs per single L1 batch. This is not used as a limit now, - /// but still determines the minimum number of items in the Merkle tree built from L2-to-L1 logs + /// Determines the minimum number of items in the Merkle tree built from L2-to-L1 logs /// for a certain batch. - pub const LEGACY_LIMIT_PER_L1_BATCH: usize = 2048; + pub const MIN_L2_L1_LOGS_TREE_SIZE: usize = 2048; pub fn from_slice(data: &[u8]) -> Self { assert_eq!(data.len(), Self::SERIALIZED_SIZE); diff --git a/core/lib/types/src/tx/tx_execution_info.rs b/core/lib/types/src/tx/tx_execution_info.rs index 206f0d8c43bc..545017bcc918 100644 --- a/core/lib/types/src/tx/tx_execution_info.rs +++ b/core/lib/types/src/tx/tx_execution_info.rs @@ -2,7 +2,11 @@ use crate::fee::TransactionExecutionMetrics; use crate::l2_to_l1_log::L2ToL1Log; use crate::{ commitment::SerializeCommitment, - writes::{BYTES_PER_DERIVED_KEY, BYTES_PER_ENUMERATION_INDEX}, + writes::{ + InitialStorageWrite, RepeatedStorageWrite, BYTES_PER_DERIVED_KEY, + BYTES_PER_ENUMERATION_INDEX, + }, + ProtocolVersionId, }; use std::ops::{Add, AddAssign}; @@ -38,10 +42,15 @@ impl DeduplicatedWritesMetrics { } } - pub fn size(&self) -> usize { - self.total_updated_values_size - + (BYTES_PER_DERIVED_KEY as usize) * self.initial_storage_writes - + (BYTES_PER_ENUMERATION_INDEX as usize) * self.repeated_storage_writes + pub fn size(&self, protocol_version: ProtocolVersionId) -> usize { + if protocol_version.is_pre_boojum() { + self.initial_storage_writes * InitialStorageWrite::SERIALIZED_SIZE + + self.repeated_storage_writes * RepeatedStorageWrite::SERIALIZED_SIZE + } else { + self.total_updated_values_size + + (BYTES_PER_DERIVED_KEY as usize) * self.initial_storage_writes + + (BYTES_PER_ENUMERATION_INDEX as usize) * self.repeated_storage_writes + } } } diff --git a/core/lib/zksync_core/Cargo.toml b/core/lib/zksync_core/Cargo.toml index 7e8b83a5d248..4d84757b6fa1 100644 --- a/core/lib/zksync_core/Cargo.toml +++ b/core/lib/zksync_core/Cargo.toml @@ -83,8 +83,6 @@ actix-web = "4.0.0-beta.8" tracing = "0.1.26" -zkevm_test_harness = { git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.4.0" } - [dev-dependencies] assert_matches = "1.5" diff --git a/core/lib/zksync_core/src/api_server/tx_sender/mod.rs b/core/lib/zksync_core/src/api_server/tx_sender/mod.rs index 2552770c22c0..fd9c2cad99af 100644 --- a/core/lib/zksync_core/src/api_server/tx_sender/mod.rs +++ b/core/lib/zksync_core/src/api_server/tx_sender/mod.rs @@ -911,11 +911,11 @@ impl TxSender { H256::zero() }; - let seal_data = SealData::for_transaction(transaction, tx_metrics); // Using `ProtocolVersionId::latest()` for a short period we might end up in a scenario where the StateKeeper is still pre-boojum // but the API assumes we are post boojum. In this situation we will determine a tx as being executable but the StateKeeper will // still reject them as it's not. let protocol_version = ProtocolVersionId::latest(); + let seal_data = SealData::for_transaction(transaction, tx_metrics, protocol_version); if let Some(reason) = ConditionalSealer::find_unexecutable_reason(sk_config, &seal_data, protocol_version) { diff --git a/core/lib/zksync_core/src/api_server/web3/namespaces/zks.rs b/core/lib/zksync_core/src/api_server/web3/namespaces/zks.rs index c7cfbe4b7a10..3e31ea6bb062 100644 --- a/core/lib/zksync_core/src/api_server/web3/namespaces/zks.rs +++ b/core/lib/zksync_core/src/api_server/web3/namespaces/zks.rs @@ -343,7 +343,7 @@ impl ZksNamespace { }; let merkle_tree_leaves = all_l1_logs_in_batch.iter().map(L2ToL1Log::to_bytes); - let min_tree_size = Some(L2ToL1Log::LEGACY_LIMIT_PER_L1_BATCH); + let min_tree_size = Some(L2ToL1Log::MIN_L2_L1_LOGS_TREE_SIZE); let (root, proof) = MiniMerkleTree::new(merkle_tree_leaves, min_tree_size) .merkle_root_and_path(l1_log_index); Ok(Some(L2ToL1LogProof { diff --git a/core/lib/zksync_core/src/block_reverter/mod.rs b/core/lib/zksync_core/src/block_reverter/mod.rs index 8fbafec4135f..a2b716ad5502 100644 --- a/core/lib/zksync_core/src/block_reverter/mod.rs +++ b/core/lib/zksync_core/src/block_reverter/mod.rs @@ -351,9 +351,9 @@ impl BlockReverter { async fn get_l1_batch_number_from_contract(&self, op: AggregatedActionType) -> L1BatchNumber { let function_name = match op { - AggregatedActionType::Commit => "getTotalBatchesCommitted", - AggregatedActionType::PublishProofOnchain => "getTotalBatchesVerified", - AggregatedActionType::Execute => "getTotalBatchesExecuted", + AggregatedActionType::Commit => "getTotalBlocksCommitted", + AggregatedActionType::PublishProofOnchain => "getTotalBlocksVerified", + AggregatedActionType::Execute => "getTotalBlocksExecuted", }; let eth_config = self .eth_config diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs index c9f49aaab9d4..9e55de888a15 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs @@ -313,7 +313,7 @@ impl EthTxAggregator { if contracts_are_pre_boojum { let vk = eth_client .call_contract_function( - &self.functions.get_verification_key.as_ref().unwrap().name, + &self.functions.get_verification_key.name, (), None, Default::default(), diff --git a/core/lib/zksync_core/src/eth_sender/zksync_functions.rs b/core/lib/zksync_core/src/eth_sender/zksync_functions.rs index 6b89e6e1627a..8e27af5b628d 100644 --- a/core/lib/zksync_core/src/eth_sender/zksync_functions.rs +++ b/core/lib/zksync_core/src/eth_sender/zksync_functions.rs @@ -1,6 +1,6 @@ use zksync_contracts::{ multicall_contract, verifier_contract, zksync_contract, PRE_BOOJUM_COMMIT_FUNCTION, - PRE_BOOJUM_EXECUTE_FUNCTION, PRE_BOOJUM_PROVE_FUNCTION, + PRE_BOOJUM_EXECUTE_FUNCTION, PRE_BOOJUM_GET_VK_FUNCTION, PRE_BOOJUM_PROVE_FUNCTION, }; use zksync_types::ethabi::{Contract, Function}; @@ -19,7 +19,7 @@ pub(super) struct ZkSyncFunctions { pub(super) get_protocol_version: Function, pub(super) verifier_contract: Contract, - pub(super) get_verification_key: Option, + pub(super) get_verification_key: Function, pub(super) verification_key_hash: Option, pub(super) multicall_contract: Contract, @@ -63,8 +63,7 @@ impl Default for ZkSyncFunctions { let get_verifier = get_function(&zksync_contract, "getVerifier"); let get_verifier_params = get_function(&zksync_contract, "getVerifierParams"); let get_protocol_version = get_function(&zksync_contract, "getProtocolVersion"); - let get_verification_key = - get_optional_function(&verifier_contract, "get_verification_key"); + let get_verification_key = PRE_BOOJUM_GET_VK_FUNCTION.clone(); let aggregate3 = get_function(&multicall_contract, "aggregate3"); let verification_key_hash = get_optional_function(&verifier_contract, "verificationKeyHash"); diff --git a/core/lib/zksync_core/src/eth_watch/event_processors/upgrades.rs b/core/lib/zksync_core/src/eth_watch/event_processors/upgrades.rs index 58fda990920d..210b540c48e4 100644 --- a/core/lib/zksync_core/src/eth_watch/event_processors/upgrades.rs +++ b/core/lib/zksync_core/src/eth_watch/event_processors/upgrades.rs @@ -1,6 +1,6 @@ use std::convert::TryFrom; use zksync_dal::StorageProcessor; -use zksync_types::{ethabi::Contract, web3::types::Log, ProtocolUpgrade, ProtocolVersionId, H256}; +use zksync_types::{web3::types::Log, ProtocolUpgrade, ProtocolVersionId, H256}; use crate::eth_watch::{ client::{Error, EthClient}, @@ -8,21 +8,21 @@ use crate::eth_watch::{ metrics::{PollStage, METRICS}, }; +pub(crate) const UPGRADE_PROPOSAL_SIGNATURE: H256 = H256([ + 105, 17, 91, 73, 175, 231, 166, 16, 26, 46, 122, 241, 125, 66, 30, 218, 29, 193, 83, 189, 38, + 214, 153, 240, 19, 196, 255, 240, 64, 70, 70, 166, +]); + /// Responsible for saving new protocol upgrade proposals to the database. #[derive(Debug)] pub struct UpgradesEventProcessor { last_seen_version_id: ProtocolVersionId, - upgrade_proposal_signature: H256, } impl UpgradesEventProcessor { pub fn new(last_seen_version_id: ProtocolVersionId) -> Self { Self { last_seen_version_id, - upgrade_proposal_signature: old_zksync_contract() - .event("ProposeTransparentUpgrade") - .expect("ProposeTransparentUpgrade event is missing in abi") - .signature(), } } } @@ -38,7 +38,7 @@ impl EventProcessor for UpgradesEventProcessor { let mut upgrades = Vec::new(); for event in events .into_iter() - .filter(|event| event.topics[0] == self.upgrade_proposal_signature) + .filter(|event| event.topics[0] == UPGRADE_PROPOSAL_SIGNATURE) { let upgrade = ProtocolUpgrade::try_from(event) .map_err(|err| Error::LogParse(format!("{:?}", err)))?; @@ -89,195 +89,6 @@ impl EventProcessor for UpgradesEventProcessor { } fn relevant_topic(&self) -> H256 { - self.upgrade_proposal_signature + UPGRADE_PROPOSAL_SIGNATURE } } - -pub fn old_zksync_contract() -> Contract { - let json = r#"[ - { - "anonymous": false, - "inputs": [ - { - "components": [ - { - "components": [ - { - "internalType": "address", - "name": "facet", - "type": "address" - }, - { - "internalType": "enum Diamond.Action", - "name": "action", - "type": "uint8" - }, - { - "internalType": "bool", - "name": "isFreezable", - "type": "bool" - }, - { - "internalType": "bytes4[]", - "name": "selectors", - "type": "bytes4[]" - } - ], - "internalType": "struct Diamond.FacetCut[]", - "name": "facetCuts", - "type": "tuple[]" - }, - { - "internalType": "address", - "name": "initAddress", - "type": "address" - }, - { - "internalType": "bytes", - "name": "initCalldata", - "type": "bytes" - } - ], - "indexed": false, - "internalType": "struct Diamond.DiamondCutData", - "name": "diamondCut", - "type": "tuple" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "proposalId", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "bytes32", - "name": "proposalSalt", - "type": "bytes32" - } - ], - "name": "ProposeTransparentUpgrade", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "txId", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "bytes32", - "name": "txHash", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "uint64", - "name": "expirationTimestamp", - "type": "uint64" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "txType", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "from", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "to", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "gasLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "gasPerPubdataByteLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxFeePerGas", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxPriorityFeePerGas", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "paymaster", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "value", - "type": "uint256" - }, - { - "internalType": "uint256[4]", - "name": "reserved", - "type": "uint256[4]" - }, - { - "internalType": "bytes", - "name": "data", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "signature", - "type": "bytes" - }, - { - "internalType": "uint256[]", - "name": "factoryDeps", - "type": "uint256[]" - }, - { - "internalType": "bytes", - "name": "paymasterInput", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "reservedDynamic", - "type": "bytes" - } - ], - "indexed": false, - "internalType": "struct IMailbox.L2CanonicalTransaction", - "name": "transaction", - "type": "tuple" - }, - { - "indexed": false, - "internalType": "bytes[]", - "name": "factoryDeps", - "type": "bytes[]" - } - ], - "name": "NewPriorityRequest", - "type": "event" - } - ]"#; - serde_json::from_str(json).unwrap() -} diff --git a/core/lib/zksync_core/src/eth_watch/tests.rs b/core/lib/zksync_core/src/eth_watch/tests.rs index fdabe3a8defe..d7627a56c136 100644 --- a/core/lib/zksync_core/src/eth_watch/tests.rs +++ b/core/lib/zksync_core/src/eth_watch/tests.rs @@ -18,7 +18,7 @@ use zksync_types::{ use super::client::Error; use crate::eth_watch::{ - client::EthClient, event_processors::upgrades::old_zksync_contract, EthWatch, + client::EthClient, event_processors::upgrades::UPGRADE_PROPOSAL_SIGNATURE, EthWatch, }; struct FakeEthClientData { @@ -593,10 +593,7 @@ fn upgrade_into_diamond_proxy_log(upgrade: ProtocolUpgrade, eth_block: u64) -> L let data = encode(&[diamond_cut, Token::FixedBytes(vec![0u8; 32])]); Log { address: Address::repeat_byte(0x1), - topics: vec![old_zksync_contract() - .event("ProposeTransparentUpgrade") - .expect("ProposeTransparentUpgrade event is missing in abi") - .signature()], + topics: vec![UPGRADE_PROPOSAL_SIGNATURE], data: data.into(), block_hash: Some(H256::repeat_byte(0x11)), block_number: Some(eth_block.into()), diff --git a/core/lib/zksync_core/src/gas_tracker/mod.rs b/core/lib/zksync_core/src/gas_tracker/mod.rs index 7988a5bc01a8..c27d4fb11739 100644 --- a/core/lib/zksync_core/src/gas_tracker/mod.rs +++ b/core/lib/zksync_core/src/gas_tracker/mod.rs @@ -7,7 +7,7 @@ use zksync_types::{ block::{BlockGasCount, L1BatchHeader}, commitment::{L1BatchMetadata, L1BatchWithMetadata}, tx::tx_execution_info::{DeduplicatedWritesMetrics, ExecutionMetrics}, - ExecuteTransactionCommon, Transaction, H256, + ExecuteTransactionCommon, ProtocolVersionId, Transaction, H256, }; mod constants; @@ -46,8 +46,11 @@ fn additional_pubdata_commit_cost(execution_metrics: &ExecutionMetrics) -> u32 { (execution_metrics.size() as u32) * GAS_PER_BYTE } -fn additional_writes_commit_cost(writes_metrics: &DeduplicatedWritesMetrics) -> u32 { - (writes_metrics.size() as u32) * GAS_PER_BYTE +fn additional_writes_commit_cost( + writes_metrics: &DeduplicatedWritesMetrics, + protocol_version: ProtocolVersionId, +) -> u32 { + (writes_metrics.size(protocol_version) as u32) * GAS_PER_BYTE } pub fn new_block_gas_count() -> BlockGasCount { @@ -79,9 +82,12 @@ pub fn gas_count_from_metrics(execution_metrics: &ExecutionMetrics) -> BlockGasC } } -pub fn gas_count_from_writes(writes_metrics: &DeduplicatedWritesMetrics) -> BlockGasCount { +pub fn gas_count_from_writes( + writes_metrics: &DeduplicatedWritesMetrics, + protocol_version: ProtocolVersionId, +) -> BlockGasCount { BlockGasCount { - commit: additional_writes_commit_cost(writes_metrics), + commit: additional_writes_commit_cost(writes_metrics, protocol_version), prove: 0, execute: 0, } diff --git a/core/lib/zksync_core/src/state_keeper/keeper.rs b/core/lib/zksync_core/src/state_keeper/keeper.rs index 73fb2e3ea4df..761e186e7aec 100644 --- a/core/lib/zksync_core/src/state_keeper/keeper.rs +++ b/core/lib/zksync_core/src/state_keeper/keeper.rs @@ -622,11 +622,15 @@ impl ZkSyncStateKeeper { let block_writes_metrics = updates_manager .storage_writes_deduplicator .apply_and_rollback(logs_to_apply_iter.clone()); - let block_writes_l1_gas = gas_count_from_writes(&block_writes_metrics); + let block_writes_l1_gas = gas_count_from_writes( + &block_writes_metrics, + updates_manager.protocol_version(), + ); let tx_writes_metrics = StorageWritesDeduplicator::apply_on_empty_state(logs_to_apply_iter); - let tx_writes_l1_gas = gas_count_from_writes(&tx_writes_metrics); + let tx_writes_l1_gas = + gas_count_from_writes(&tx_writes_metrics, updates_manager.protocol_version()); let tx_gas_excluding_writes = tx_l1_gas_this_tx + finish_block_l1_gas; let tx_data = SealData { diff --git a/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/pubdata_bytes.rs b/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/pubdata_bytes.rs index 0cea0954065b..143104d5ae53 100644 --- a/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/pubdata_bytes.rs +++ b/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/pubdata_bytes.rs @@ -15,7 +15,7 @@ impl SealCriterion for PubDataBytesCriterion { _tx_count: usize, block_data: &SealData, tx_data: &SealData, - _protocol_version: ProtocolVersionId, + protocol_version: ProtocolVersionId, ) -> SealResolution { let max_pubdata_per_l1_batch = MAX_PUBDATA_PER_L1_BATCH as usize; let reject_bound = @@ -23,12 +23,13 @@ impl SealCriterion for PubDataBytesCriterion { let include_and_seal_bound = (max_pubdata_per_l1_batch as f64 * config.close_block_at_eth_params_percentage).round(); - let block_size = block_data.execution_metrics.size() + block_data.writes_metrics.size(); + let block_size = + block_data.execution_metrics.size() + block_data.writes_metrics.size(protocol_version); // For backward compatibility, we need to keep calculating the size of the pubdata based // StorageDeduplication metrics. All vm versions // after vm with virtual blocks will provide the size of the pubdata in the execution metrics. let tx_size = if tx_data.execution_metrics.pubdata_published == 0 { - tx_data.execution_metrics.size() + tx_data.writes_metrics.size() + tx_data.execution_metrics.size() + tx_data.writes_metrics.size(protocol_version) } else { tx_data.execution_metrics.pubdata_published as usize }; diff --git a/core/lib/zksync_core/src/state_keeper/seal_criteria/mod.rs b/core/lib/zksync_core/src/state_keeper/seal_criteria/mod.rs index 19cd5b87da50..99cb25c654d8 100644 --- a/core/lib/zksync_core/src/state_keeper/seal_criteria/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/seal_criteria/mod.rs @@ -89,11 +89,12 @@ impl SealData { pub(crate) fn for_transaction( transaction: Transaction, tx_metrics: &TransactionExecutionMetrics, + protocol_version: ProtocolVersionId, ) -> Self { let execution_metrics = ExecutionMetrics::from_tx_metrics(tx_metrics); let writes_metrics = DeduplicatedWritesMetrics::from_tx_metrics(tx_metrics); let gas_count = gas_count_from_tx_and_metrics(&transaction, &execution_metrics) - + gas_count_from_writes(&writes_metrics); + + gas_count_from_writes(&writes_metrics, protocol_version); Self { execution_metrics, gas_count, diff --git a/docker/cross-external-nodes-checker/Dockerfile b/docker/cross-external-nodes-checker/Dockerfile index 0467000d01df..40837169402f 100644 --- a/docker/cross-external-nodes-checker/Dockerfile +++ b/docker/cross-external-nodes-checker/Dockerfile @@ -1,7 +1,3 @@ -# For using private GitHub dependencies, CI downdloads all crates outside of the contatiner -# Not expected to work locally - -# BUILDING STAGE # syntax=docker/dockerfile:experimental FROM debian:bookworm-slim as builder