From 53a6bcf8d4f51aa3363665fc93bdbd4dceb6041a Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Thu, 7 Dec 2023 10:50:04 +0200 Subject: [PATCH] chore: Enforce uniform import structure (#617) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ ...using `zk fmt` command by suppling relevant command-line args to rustfmt. These args work on stable Rust (at least for now) despite being unstable. ## Why ❔ More structured imports are easier to read. ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Code has been formatted via `zk fmt` and `zk lint`. - [x] Spellcheck has been run via `cargo spellcheck --cfg=./spellcheck/era.cfg --code 1`. --- core/bin/block_reverter/src/main.rs | 8 +- core/bin/contract-verifier/src/main.rs | 5 +- core/bin/contract-verifier/src/verifier.rs | 19 +-- .../bin/contract-verifier/src/zksolc_utils.rs | 6 +- .../contract-verifier/src/zkvyper_utils.rs | 6 +- core/bin/external_node/src/config/mod.rs | 8 +- core/bin/external_node/src/main.rs | 7 +- .../src/main.rs | 5 +- core/bin/rocksdb_util/src/main.rs | 4 +- .../src/consistency.rs | 1 - .../storage_logs_dedup_migration/src/main.rs | 1 - .../src/intrinsic_costs.rs | 8 +- .../system-constants-generator/src/main.rs | 21 +-- .../system-constants-generator/src/utils.rs | 25 ++-- .../src/json_to_binary_vk_converter.rs | 4 +- .../src/lib.rs | 44 +++--- .../src/main.rs | 15 +- .../src/tests.rs | 14 +- core/bin/verified_sources_fetcher/src/main.rs | 1 + core/bin/zksync_server/src/main.rs | 11 +- core/lib/basic_types/src/lib.rs | 31 +++-- core/lib/circuit_breaker/src/l1_txs.rs | 3 +- core/lib/circuit_breaker/src/lib.rs | 1 - core/lib/config/src/configs/api.rs | 6 +- core/lib/config/src/configs/chain.rs | 10 +- .../config/src/configs/contract_verifier.rs | 3 +- core/lib/config/src/configs/database.rs | 4 +- core/lib/config/src/configs/eth_sender.rs | 4 +- core/lib/config/src/configs/eth_watch.rs | 3 +- core/lib/config/src/configs/fetcher.rs | 3 +- .../src/configs/fri_proof_compressor.rs | 3 +- core/lib/config/src/configs/fri_prover.rs | 3 +- .../config/src/configs/fri_prover_gateway.rs | 3 +- .../config/src/configs/fri_prover_group.rs | 2 +- core/lib/config/src/configs/mod.rs | 31 +++-- .../config/src/configs/proof_data_handler.rs | 3 +- core/lib/config/src/configs/utils.rs | 4 +- core/lib/contracts/src/lib.rs | 11 +- core/lib/contracts/src/test_contracts.rs | 6 +- core/lib/crypto/src/hasher/blake2.rs | 2 +- core/lib/crypto/src/hasher/keccak.rs | 3 +- core/lib/crypto/src/hasher/sha256.rs | 2 +- .../src/basic_witness_input_producer_dal.rs | 12 +- core/lib/dal/src/blocks_dal.rs | 1 - core/lib/dal/src/blocks_web3_dal.rs | 16 ++- core/lib/dal/src/connection/holder.rs | 5 +- core/lib/dal/src/connection/mod.rs | 10 +- core/lib/dal/src/contract_verification_dal.rs | 14 +- core/lib/dal/src/eth_sender_dal.rs | 23 ++-- core/lib/dal/src/events_dal.rs | 9 +- core/lib/dal/src/events_web3_dal.rs | 1 - core/lib/dal/src/fri_gpu_prover_queue_dal.rs | 4 +- core/lib/dal/src/fri_proof_compressor_dal.rs | 20 +-- core/lib/dal/src/fri_protocol_versions_dal.rs | 3 +- .../fri_scheduler_dependency_tracker_dal.rs | 3 +- core/lib/dal/src/fri_witness_generator_dal.rs | 8 +- core/lib/dal/src/gpu_prover_queue_dal.rs | 7 +- core/lib/dal/src/healthcheck.rs | 1 - core/lib/dal/src/instrument.rs | 4 +- core/lib/dal/src/lib.rs | 60 +++----- core/lib/dal/src/metrics.rs | 4 +- core/lib/dal/src/models/storage_block.rs | 1 - core/lib/dal/src/models/storage_eth_tx.rs | 11 +- .../src/models/storage_protocol_version.rs | 4 +- .../dal/src/models/storage_prover_job_info.rs | 15 +- core/lib/dal/src/models/storage_sync.rs | 6 +- core/lib/dal/src/models/storage_token.rs | 1 - .../lib/dal/src/models/storage_transaction.rs | 31 +++-- .../models/storage_verification_request.rs | 10 +- .../src/models/storage_witness_job_info.rs | 14 +- core/lib/dal/src/proof_generation_dal.rs | 5 +- core/lib/dal/src/protocol_versions_dal.rs | 7 +- .../lib/dal/src/protocol_versions_web3_dal.rs | 3 +- core/lib/dal/src/prover_dal.rs | 3 +- core/lib/dal/src/storage_dal.rs | 6 +- core/lib/dal/src/storage_logs_dal.rs | 12 +- core/lib/dal/src/storage_logs_dedup_dal.rs | 6 +- core/lib/dal/src/tests/mod.rs | 20 +-- core/lib/dal/src/time_utils.rs | 4 +- core/lib/dal/src/tokens_dal.rs | 3 +- core/lib/dal/src/tokens_web3_dal.rs | 5 +- core/lib/dal/src/transactions_dal.rs | 7 +- core/lib/dal/src/transactions_web3_dal.rs | 18 +-- core/lib/dal/src/witness_generator_dal.rs | 21 ++- core/lib/env_config/src/alerts.rs | 3 +- core/lib/env_config/src/api.rs | 4 +- core/lib/env_config/src/chain.rs | 3 +- core/lib/env_config/src/contracts.rs | 3 +- core/lib/env_config/src/database.rs | 3 +- .../env_config/src/fri_proof_compressor.rs | 3 +- core/lib/env_config/src/test_utils.rs | 3 +- core/lib/env_config/src/utils.rs | 3 +- core/lib/eth_client/src/clients/http/mod.rs | 10 +- core/lib/eth_client/src/clients/http/query.rs | 14 +- .../eth_client/src/clients/http/signing.rs | 29 ++-- core/lib/eth_client/src/clients/mock.rs | 13 +- core/lib/eth_client/src/lib.rs | 9 +- core/lib/eth_signer/src/json_rpc_signer.rs | 25 ++-- core/lib/eth_signer/src/lib.rs | 9 +- core/lib/eth_signer/src/pk_signer.rs | 14 +- core/lib/eth_signer/src/raw_ethereum_tx.rs | 12 +- core/lib/health_check/src/lib.rs | 9 +- core/lib/mempool/src/mempool_store.rs | 3 +- core/lib/mempool/src/tests.rs | 22 +-- core/lib/mempool/src/types.rs | 8 +- .../lib/merkle_tree/examples/loadtest/main.rs | 13 +- core/lib/merkle_tree/examples/recovery.rs | 5 +- core/lib/merkle_tree/src/consistency.rs | 10 +- core/lib/merkle_tree/src/domain.rs | 14 +- core/lib/merkle_tree/src/errors.rs | 3 +- core/lib/merkle_tree/src/hasher/mod.rs | 13 +- core/lib/merkle_tree/src/hasher/nodes.rs | 3 +- core/lib/merkle_tree/src/lib.rs | 34 ++--- core/lib/merkle_tree/src/metrics.rs | 3 +- core/lib/merkle_tree/src/recovery.rs | 3 +- core/lib/merkle_tree/src/storage/mod.rs | 17 ++- core/lib/merkle_tree/src/storage/patch.rs | 4 +- core/lib/merkle_tree/src/storage/rocksdb.rs | 10 +- .../merkle_tree/src/storage/serialization.rs | 3 +- core/lib/merkle_tree/src/storage/tests.rs | 8 +- core/lib/merkle_tree/src/types/internal.rs | 3 +- core/lib/merkle_tree/src/types/mod.rs | 4 +- .../merkle_tree/tests/integration/common.rs | 3 +- .../tests/integration/consistency.rs | 2 +- .../merkle_tree/tests/integration/domain.rs | 5 +- .../tests/integration/merkle_tree.rs | 13 +- .../merkle_tree/tests/integration/recovery.rs | 3 +- core/lib/mini_merkle_tree/benches/tree.rs | 1 - core/lib/mini_merkle_tree/src/lib.rs | 4 +- core/lib/multivm/src/glue/tracers/mod.rs | 5 +- .../src/glue/types/vm/block_context_mode.rs | 3 +- .../src/glue/types/vm/vm_block_result.rs | 10 +- .../glue/types/vm/vm_tx_execution_result.rs | 7 +- .../traits/tracers/dyn_tracers/vm_1_3_3.rs | 6 +- .../traits/tracers/dyn_tracers/vm_1_4_0.rs | 6 +- core/lib/multivm/src/interface/traits/vm.rs | 24 ++-- .../src/interface/types/errors/halt.rs | 3 +- .../types/errors/tx_revert_reason.rs | 4 +- .../interface/types/inputs/l1_batch_env.rs | 2 +- .../types/outputs/execution_result.rs | 13 +- .../types/outputs/execution_state.rs | 6 +- .../src/interface/types/outputs/mod.rs | 15 +- core/lib/multivm/src/lib.rs | 23 ++-- .../multivm/src/tracers/call_tracer/mod.rs | 6 +- .../src/tracers/call_tracer/vm_latest/mod.rs | 19 +-- .../call_tracer/vm_refunds_enhancement/mod.rs | 21 +-- .../call_tracer/vm_virtual_blocks/mod.rs | 29 ++-- .../multivm/src/tracers/multivm_dispatcher.rs | 3 +- .../storage_invocation/vm_latest/mod.rs | 17 ++- .../vm_refunds_enhancement/mod.rs | 15 +- .../vm_virtual_blocks/mod.rs | 15 +- core/lib/multivm/src/tracers/validator/mod.rs | 15 +- .../multivm/src/tracers/validator/types.rs | 8 +- .../src/tracers/validator/vm_latest/mod.rs | 34 ++--- .../validator/vm_refunds_enhancement/mod.rs | 33 +++-- .../validator/vm_virtual_blocks/mod.rs | 30 ++-- .../vm_1_3_2/errors/vm_revert_reason.rs | 6 +- .../src/versions/vm_1_3_2/event_sink.rs | 10 +- .../src/versions/vm_1_3_2/history_recorder.rs | 6 +- .../multivm/src/versions/vm_1_3_2/memory.rs | 22 +-- core/lib/multivm/src/versions/vm_1_3_2/mod.rs | 31 +++-- .../src/versions/vm_1_3_2/oracle_tools.rs | 17 ++- .../versions/vm_1_3_2/oracles/decommitter.rs | 18 ++- .../src/versions/vm_1_3_2/oracles/mod.rs | 7 +- .../versions/vm_1_3_2/oracles/precompile.rs | 7 +- .../src/versions/vm_1_3_2/oracles/storage.rs | 19 ++- .../vm_1_3_2/oracles/tracer/bootloader.rs | 16 ++- .../versions/vm_1_3_2/oracles/tracer/call.rs | 36 ++--- .../versions/vm_1_3_2/oracles/tracer/mod.rs | 26 ++-- .../vm_1_3_2/oracles/tracer/one_tx.rs | 20 +-- .../oracles/tracer/transaction_result.rs | 18 +-- .../versions/vm_1_3_2/oracles/tracer/utils.rs | 21 +-- .../vm_1_3_2/oracles/tracer/validation.rs | 24 ++-- .../src/versions/vm_1_3_2/pubdata_utils.rs | 16 ++- .../multivm/src/versions/vm_1_3_2/refunds.rs | 11 +- .../src/versions/vm_1_3_2/test_utils.rs | 6 +- .../src/versions/vm_1_3_2/transaction_data.rs | 14 +- .../multivm/src/versions/vm_1_3_2/utils.rs | 13 +- core/lib/multivm/src/versions/vm_1_3_2/vm.rs | 33 +++-- .../src/versions/vm_1_3_2/vm_instance.rs | 81 ++++++----- .../versions/vm_1_3_2/vm_with_bootloader.rs | 6 +- .../vm_latest/bootloader_state/l2_block.rs | 12 +- .../vm_latest/bootloader_state/state.rs | 26 ++-- .../versions/vm_latest/bootloader_state/tx.rs | 3 +- .../vm_latest/bootloader_state/utils.rs | 27 ++-- .../src/versions/vm_latest/constants.rs | 8 +- .../vm_latest/implementation/bytecode.rs | 11 +- .../vm_latest/implementation/execution.rs | 22 +-- .../versions/vm_latest/implementation/gas.rs | 7 +- .../versions/vm_latest/implementation/logs.rs | 20 +-- .../vm_latest/implementation/snapshots.rs | 3 +- .../vm_latest/implementation/statistics.rs | 10 +- .../versions/vm_latest/implementation/tx.rs | 17 ++- .../lib/multivm/src/versions/vm_latest/mod.rs | 41 +++--- .../versions/vm_latest/old_vm/event_sink.rs | 12 +- .../vm_latest/old_vm/history_recorder.rs | 8 +- .../src/versions/vm_latest/old_vm/memory.rs | 24 ++-- .../vm_latest/old_vm/oracles/decommitter.rs | 22 ++- .../vm_latest/old_vm/oracles/precompile.rs | 7 +- .../src/versions/vm_latest/old_vm/utils.rs | 19 ++- .../src/versions/vm_latest/oracles/storage.rs | 28 ++-- .../versions/vm_latest/tests/bootloader.rs | 18 +-- .../vm_latest/tests/bytecode_publishing.rs | 14 +- .../versions/vm_latest/tests/call_tracer.rs | 22 ++- .../versions/vm_latest/tests/default_aa.rs | 22 ++- .../src/versions/vm_latest/tests/gas_limit.rs | 16 +-- .../vm_latest/tests/get_used_contracts.rs | 22 +-- .../vm_latest/tests/is_write_initial.rs | 14 +- .../vm_latest/tests/l1_tx_execution.rs | 25 ++-- .../src/versions/vm_latest/tests/l2_blocks.rs | 28 ++-- .../versions/vm_latest/tests/nonce_holder.rs | 21 ++- .../src/versions/vm_latest/tests/refunds.rs | 17 ++- .../vm_latest/tests/require_eip712.rs | 26 ++-- .../src/versions/vm_latest/tests/rollbacks.rs | 29 ++-- .../vm_latest/tests/simple_execution.rs | 10 +- .../vm_latest/tests/tester/inner_state.rs | 18 ++- .../tests/tester/transaction_test_info.rs | 12 +- .../vm_latest/tests/tester/vm_tester.rs | 41 +++--- .../tests/tracing_execution_error.rs | 15 +- .../src/versions/vm_latest/tests/upgrade.rs | 36 ++--- .../src/versions/vm_latest/tests/utils.rs | 15 +- .../vm_latest/tracers/default_tracers.rs | 47 ++++--- .../versions/vm_latest/tracers/dispatcher.rs | 15 +- .../vm_latest/tracers/pubdata_tracer.rs | 34 ++--- .../src/versions/vm_latest/tracers/refunds.rs | 44 +++--- .../vm_latest/tracers/result_tracer.rs | 30 ++-- .../src/versions/vm_latest/tracers/traits.rs | 17 ++- .../src/versions/vm_latest/tracers/utils.rs | 22 +-- .../vm_latest/types/internals/pubdata.rs | 2 +- .../types/internals/transaction_data.rs | 21 +-- .../vm_latest/types/internals/vm_state.rs | 42 +++--- .../src/versions/vm_latest/types/l1_batch.rs | 3 +- .../src/versions/vm_latest/utils/l2_blocks.rs | 10 +- .../src/versions/vm_latest/utils/logs.rs | 7 +- .../src/versions/vm_latest/utils/overhead.rs | 10 +- .../vm_latest/utils/transaction_encoding.rs | 3 +- core/lib/multivm/src/versions/vm_latest/vm.rs | 32 +++-- .../versions/vm_m5/errors/vm_revert_reason.rs | 6 +- .../multivm/src/versions/vm_m5/event_sink.rs | 7 +- .../src/versions/vm_m5/history_recorder.rs | 5 +- core/lib/multivm/src/versions/vm_m5/memory.rs | 18 ++- core/lib/multivm/src/versions/vm_m5/mod.rs | 27 ++-- .../src/versions/vm_m5/oracle_tools.rs | 19 +-- .../src/versions/vm_m5/oracles/decommitter.rs | 19 ++- .../multivm/src/versions/vm_m5/oracles/mod.rs | 7 +- .../src/versions/vm_m5/oracles/precompile.rs | 7 +- .../src/versions/vm_m5/oracles/storage.rs | 29 ++-- .../src/versions/vm_m5/oracles/tracer.rs | 23 ++-- .../src/versions/vm_m5/pubdata_utils.rs | 23 ++-- .../lib/multivm/src/versions/vm_m5/refunds.rs | 12 +- .../lib/multivm/src/versions/vm_m5/storage.rs | 5 +- .../multivm/src/versions/vm_m5/test_utils.rs | 11 +- .../src/versions/vm_m5/transaction_data.rs | 15 +- core/lib/multivm/src/versions/vm_m5/utils.rs | 10 +- core/lib/multivm/src/versions/vm_m5/vm.rs | 36 ++--- .../multivm/src/versions/vm_m5/vm_instance.rs | 83 ++++++----- .../src/versions/vm_m5/vm_with_bootloader.rs | 6 +- .../versions/vm_m6/errors/vm_revert_reason.rs | 6 +- .../multivm/src/versions/vm_m6/event_sink.rs | 12 +- .../src/versions/vm_m6/history_recorder.rs | 5 +- core/lib/multivm/src/versions/vm_m6/memory.rs | 22 +-- .../src/versions/vm_m6/oracle_tools.rs | 20 +-- .../src/versions/vm_m6/oracles/decommitter.rs | 18 +-- .../multivm/src/versions/vm_m6/oracles/mod.rs | 7 +- .../src/versions/vm_m6/oracles/precompile.rs | 7 +- .../src/versions/vm_m6/oracles/storage.rs | 28 ++-- .../vm_m6/oracles/tracer/bootloader.rs | 16 ++- .../src/versions/vm_m6/oracles/tracer/call.rs | 42 +++--- .../src/versions/vm_m6/oracles/tracer/mod.rs | 26 ++-- .../versions/vm_m6/oracles/tracer/one_tx.rs | 20 +-- .../oracles/tracer/transaction_result.rs | 18 +-- .../versions/vm_m6/oracles/tracer/utils.rs | 21 +-- .../vm_m6/oracles/tracer/validation.rs | 31 ++--- .../src/versions/vm_m6/pubdata_utils.rs | 23 ++-- .../lib/multivm/src/versions/vm_m6/refunds.rs | 13 +- .../lib/multivm/src/versions/vm_m6/storage.rs | 5 +- .../multivm/src/versions/vm_m6/test_utils.rs | 9 +- .../src/versions/vm_m6/transaction_data.rs | 17 ++- core/lib/multivm/src/versions/vm_m6/utils.rs | 18 +-- core/lib/multivm/src/versions/vm_m6/vm.rs | 33 ++--- .../multivm/src/versions/vm_m6/vm_instance.rs | 87 ++++++------ .../src/versions/vm_m6/vm_with_bootloader.rs | 3 +- .../bootloader_state/l2_block.rs | 12 +- .../bootloader_state/state.rs | 23 ++-- .../bootloader_state/tx.rs | 3 +- .../bootloader_state/utils.rs | 23 ++-- .../vm_refunds_enhancement/constants.rs | 8 +- .../implementation/bytecode.rs | 11 +- .../implementation/execution.rs | 21 +-- .../implementation/gas.rs | 7 +- .../implementation/logs.rs | 20 +-- .../implementation/snapshots.rs | 11 +- .../implementation/statistics.rs | 10 +- .../implementation/tx.rs | 19 +-- .../versions/vm_refunds_enhancement/mod.rs | 37 +++-- .../old_vm/event_sink.rs | 10 +- .../old_vm/history_recorder.rs | 8 +- .../vm_refunds_enhancement/old_vm/memory.rs | 24 ++-- .../old_vm/oracles/decommitter.rs | 22 ++- .../old_vm/oracles/precompile.rs | 7 +- .../vm_refunds_enhancement/old_vm/utils.rs | 19 ++- .../vm_refunds_enhancement/oracles/storage.rs | 25 ++-- .../tracers/default_tracers.rs | 38 ++--- .../tracers/dispatcher.rs | 15 +- .../vm_refunds_enhancement/tracers/refunds.rs | 37 +++-- .../tracers/result_tracer.rs | 32 +++-- .../vm_refunds_enhancement/tracers/traits.rs | 17 ++- .../vm_refunds_enhancement/tracers/utils.rs | 17 +-- .../types/internals/transaction_data.rs | 21 +-- .../types/internals/vm_state.rs | 42 +++--- .../vm_refunds_enhancement/types/l1_batch.rs | 3 +- .../vm_refunds_enhancement/utils/l2_blocks.rs | 10 +- .../vm_refunds_enhancement/utils/overhead.rs | 10 +- .../utils/transaction_encoding.rs | 3 +- .../src/versions/vm_refunds_enhancement/vm.rs | 28 ++-- .../bootloader_state/l2_block.rs | 12 +- .../bootloader_state/state.rs | 25 ++-- .../vm_virtual_blocks/bootloader_state/tx.rs | 3 +- .../bootloader_state/utils.rs | 23 ++-- .../versions/vm_virtual_blocks/constants.rs | 8 +- .../implementation/bytecode.rs | 11 +- .../implementation/execution.rs | 24 ++-- .../vm_virtual_blocks/implementation/gas.rs | 7 +- .../vm_virtual_blocks/implementation/logs.rs | 20 +-- .../implementation/snapshots.rs | 9 +- .../implementation/statistics.rs | 10 +- .../vm_virtual_blocks/implementation/tx.rs | 19 +-- .../src/versions/vm_virtual_blocks/mod.rs | 38 +++-- .../vm_virtual_blocks/old_vm/event_sink.rs | 10 +- .../old_vm/history_recorder.rs | 8 +- .../vm_virtual_blocks/old_vm/memory.rs | 24 ++-- .../old_vm/oracles/decommitter.rs | 22 ++- .../old_vm/oracles/precompile.rs | 7 +- .../old_vm/oracles/storage.rs | 20 ++- .../vm_virtual_blocks/old_vm/utils.rs | 19 ++- .../tracers/default_tracers.rs | 42 +++--- .../vm_virtual_blocks/tracers/dispatcher.rs | 19 +-- .../vm_virtual_blocks/tracers/refunds.rs | 40 +++--- .../tracers/result_tracer.rs | 38 ++--- .../vm_virtual_blocks/tracers/traits.rs | 17 ++- .../vm_virtual_blocks/tracers/utils.rs | 22 +-- .../types/internals/transaction_data.rs | 21 +-- .../types/internals/vm_state.rs | 42 +++--- .../vm_virtual_blocks/types/l1_batch_env.rs | 3 +- .../vm_virtual_blocks/utils/l2_blocks.rs | 10 +- .../vm_virtual_blocks/utils/overhead.rs | 10 +- .../utils/transaction_encoding.rs | 3 +- .../src/versions/vm_virtual_blocks/vm.rs | 31 +++-- core/lib/multivm/src/vm_instance.rs | 17 +-- core/lib/object_store/src/file.rs | 4 +- core/lib/object_store/src/gcs.rs | 18 +-- core/lib/object_store/src/metrics.rs | 4 +- core/lib/object_store/src/mock.rs | 4 +- core/lib/object_store/src/objects.rs | 8 +- core/lib/object_store/src/raw.rs | 6 +- core/lib/object_store/tests/integration.rs | 1 - core/lib/prometheus_exporter/src/lib.rs | 4 +- .../lib/prover_utils/src/gcs_proof_fetcher.rs | 3 +- core/lib/prover_utils/src/region_fetcher.rs | 7 +- .../prover_utils/src/vk_commitment_helper.rs | 3 +- core/lib/queued_job_processor/src/lib.rs | 14 +- core/lib/state/src/cache/metrics.rs | 4 +- core/lib/state/src/in_memory.rs | 3 +- core/lib/state/src/postgres/metrics.rs | 4 +- core/lib/state/src/postgres/mod.rs | 11 +- core/lib/state/src/postgres/tests.rs | 7 +- core/lib/state/src/rocksdb/metrics.rs | 4 +- core/lib/state/src/rocksdb/mod.rs | 10 +- core/lib/state/src/shadow_storage.rs | 2 +- core/lib/state/src/storage_view.rs | 10 +- core/lib/state/src/test_utils.rs | 4 +- core/lib/state/src/witness.rs | 3 +- core/lib/storage/src/db.rs | 10 +- core/lib/storage/src/metrics.rs | 6 +- core/lib/test_account/src/lib.rs | 18 +-- core/lib/types/src/aggregated_operations.rs | 12 +- core/lib/types/src/api/mod.rs | 11 +- core/lib/types/src/block.rs | 5 +- core/lib/types/src/circuit.rs | 3 +- core/lib/types/src/commitment.rs | 18 +-- .../types/src/contract_verification_api.rs | 3 +- core/lib/types/src/eth_sender.rs | 3 +- core/lib/types/src/event.rs | 15 +- core/lib/types/src/l1/mod.rs | 5 +- core/lib/types/src/l2/mod.rs | 28 ++-- core/lib/types/src/l2_to_l1_log.rs | 7 +- core/lib/types/src/lib.rs | 11 +- .../lib/types/src/priority_op_onchain_data.rs | 4 +- core/lib/types/src/proofs.rs | 28 ++-- core/lib/types/src/protocol_version.rs | 12 +- core/lib/types/src/prover_server_api/mod.rs | 9 +- core/lib/types/src/storage/log.rs | 3 +- .../types/src/storage/witness_block_state.rs | 6 +- .../types/src/storage/writes/compression.rs | 3 +- core/lib/types/src/storage/writes/mod.rs | 11 +- .../types/src/storage_writes_deduplicator.rs | 11 +- core/lib/types/src/system_contracts.rs | 2 +- core/lib/types/src/transaction_request.rs | 13 +- core/lib/types/src/tx/execute.rs | 3 +- core/lib/types/src/tx/mod.rs | 11 +- .../eip712_signature/member_types.rs | 9 +- .../eip712_signature/struct_builder.rs | 3 +- .../tx/primitives/eip712_signature/tests.rs | 21 ++- .../eip712_signature/typed_structure.rs | 8 +- .../tx/primitives/eip712_signature/utils.rs | 3 +- .../src/tx/primitives/packed_eth_signature.rs | 7 +- core/lib/types/src/tx/tx_execution_info.rs | 7 +- core/lib/types/src/utils.rs | 13 +- core/lib/types/src/vk_transform.rs | 4 +- core/lib/types/src/vm_trace.rs | 12 +- core/lib/utils/src/bytecode.rs | 10 +- core/lib/utils/src/convert.rs | 9 +- core/lib/utils/src/http_with_retries.rs | 3 +- core/lib/utils/src/misc.rs | 3 +- core/lib/vlog/src/lib.rs | 12 +- core/lib/web3_decl/src/namespaces/debug.rs | 8 +- core/lib/web3_decl/src/namespaces/eth.rs | 16 +-- core/lib/web3_decl/src/namespaces/mod.rs | 13 +- core/lib/web3_decl/src/namespaces/zks.rs | 1 - core/lib/web3_decl/src/types.rs | 10 +- .../contract_verification/api_decl.rs | 1 - .../contract_verification/api_impl.rs | 1 - .../contract_verification/metrics.rs | 4 +- .../api_server/contract_verification/mod.rs | 10 +- .../src/api_server/execution_sandbox/apply.rs | 10 +- .../src/api_server/execution_sandbox/error.rs | 3 +- .../api_server/execution_sandbox/execute.rs | 12 +- .../src/api_server/execution_sandbox/mod.rs | 23 ++-- .../api_server/execution_sandbox/tracers.rs | 8 +- .../api_server/execution_sandbox/validate.rs | 14 +- .../execution_sandbox/vm_metrics.rs | 11 +- .../zksync_core/src/api_server/healthcheck.rs | 5 +- .../src/api_server/tree/metrics.rs | 4 +- .../zksync_core/src/api_server/tree/mod.rs | 11 +- .../zksync_core/src/api_server/tree/tests.rs | 3 +- .../src/api_server/tx_sender/mod.rs | 48 +++---- .../src/api_server/tx_sender/proxy.rs | 2 +- .../src/api_server/tx_sender/result.rs | 11 +- .../batch_limiter_middleware.rs | 4 +- .../api_server/web3/backend_jsonrpc/error.rs | 4 +- .../web3/backend_jsonrpc/namespaces/debug.rs | 8 +- .../web3/backend_jsonrpc/namespaces/en.rs | 6 - .../web3/backend_jsonrpc/namespaces/eth.rs | 12 +- .../web3/backend_jsonrpc/namespaces/net.rs | 6 - .../web3/backend_jsonrpc/namespaces/zks.rs | 11 +- .../web3/backend_jsonrpc/pub_sub.rs | 4 +- .../api_server/web3/backend_jsonrpsee/mod.rs | 7 +- .../web3/backend_jsonrpsee/namespaces/zks.rs | 3 +- .../src/api_server/web3/metrics.rs | 12 +- .../zksync_core/src/api_server/web3/mod.rs | 46 ++++--- .../src/api_server/web3/namespaces/debug.rs | 30 ++-- .../src/api_server/web3/namespaces/en.rs | 2 +- .../src/api_server/web3/namespaces/zks.rs | 11 +- .../zksync_core/src/api_server/web3/pubsub.rs | 5 +- .../zksync_core/src/api_server/web3/state.rs | 5 +- .../src/api_server/web3/tests/mod.rs | 9 +- .../src/api_server/web3/tests/ws.rs | 1 - .../src/basic_witness_input_producer/mod.rs | 22 ++- .../vm_interactions.rs | 13 +- .../lib/zksync_core/src/block_reverter/mod.rs | 27 ++-- core/lib/zksync_core/src/consensus/payload.rs | 4 +- core/lib/zksync_core/src/data_fetchers/mod.rs | 3 +- .../src/data_fetchers/token_list/mock.rs | 6 +- .../src/data_fetchers/token_list/mod.rs | 4 +- .../src/data_fetchers/token_list/one_inch.rs | 4 +- .../data_fetchers/token_price/coingecko.rs | 4 +- .../src/data_fetchers/token_price/mock.rs | 3 +- .../src/data_fetchers/token_price/mod.rs | 7 +- .../src/eth_sender/eth_tx_aggregator.rs | 15 +- .../src/eth_sender/eth_tx_manager.rs | 9 +- .../lib/zksync_core/src/eth_sender/metrics.rs | 3 +- .../src/eth_sender/publish_criterion.rs | 5 +- core/lib/zksync_core/src/eth_sender/tests.rs | 11 +- .../event_processors/governance_upgrades.rs | 13 +- .../src/eth_watch/event_processors/mod.rs | 3 +- .../eth_watch/event_processors/upgrades.rs | 1 + core/lib/zksync_core/src/eth_watch/metrics.rs | 4 +- core/lib/zksync_core/src/eth_watch/mod.rs | 15 +- core/lib/zksync_core/src/eth_watch/tests.rs | 10 +- core/lib/zksync_core/src/genesis.rs | 10 +- .../src/house_keeper/blocks_state_reporter.rs | 1 - .../fri_proof_compressor_queue_monitor.rs | 3 +- .../fri_scheduler_circuit_queuer.rs | 1 - .../fri_witness_generator_queue_monitor.rs | 3 +- .../house_keeper/gpu_prover_queue_monitor.rs | 1 - .../house_keeper/prover_job_retry_manager.rs | 1 - .../src/house_keeper/prover_queue_monitor.rs | 4 +- ...waiting_to_queued_fri_witness_job_mover.rs | 1 - .../waiting_to_queued_witness_job_mover.rs | 1 - .../witness_generator_queue_monitor.rs | 3 +- .../src/l1_gas_price/gas_adjuster/mod.rs | 9 +- .../src/l1_gas_price/gas_adjuster/tests.rs | 7 +- .../src/l1_gas_price/main_node_fetcher.rs | 1 - core/lib/zksync_core/src/l1_gas_price/mod.rs | 3 +- .../zksync_core/src/l1_gas_price/singleton.rs | 12 +- core/lib/zksync_core/src/lib.rs | 89 ++++++------ .../src/metadata_calculator/helpers.rs | 8 +- .../src/metadata_calculator/metrics.rs | 5 +- .../src/metadata_calculator/mod.rs | 15 +- .../src/metadata_calculator/tests.rs | 5 +- .../src/metadata_calculator/updater.rs | 5 +- core/lib/zksync_core/src/metrics.rs | 3 +- .../zksync_core/src/proof_data_handler/mod.rs | 9 +- .../proof_data_handler/request_processor.rs | 23 ++-- .../lib/zksync_core/src/reorg_detector/mod.rs | 6 +- .../src/state_keeper/batch_executor/mod.rs | 22 ++- .../state_keeper/batch_executor/tests/mod.rs | 6 +- .../batch_executor/tests/tester.rs | 18 +-- .../src/state_keeper/extractors.rs | 3 +- .../zksync_core/src/state_keeper/io/common.rs | 6 +- .../src/state_keeper/io/mempool.rs | 11 +- .../zksync_core/src/state_keeper/io/mod.rs | 13 +- .../src/state_keeper/io/seal_logic.rs | 15 +- .../src/state_keeper/io/tests/mod.rs | 12 +- .../src/state_keeper/io/tests/tester.rs | 7 +- .../zksync_core/src/state_keeper/keeper.rs | 11 +- .../src/state_keeper/mempool_actor.rs | 3 +- .../zksync_core/src/state_keeper/metrics.rs | 9 +- core/lib/zksync_core/src/state_keeper/mod.rs | 28 ++-- .../criteria/geometry_seal_criteria.rs | 3 +- .../zksync_core/src/state_keeper/tests/mod.rs | 35 ++--- .../src/state_keeper/tests/tester.rs | 15 +- .../state_keeper/updates/l1_batch_updates.rs | 13 +- .../state_keeper/updates/miniblock_updates.rs | 20 +-- .../src/state_keeper/updates/mod.rs | 13 +- .../src/sync_layer/batch_status_updater.rs | 5 +- core/lib/zksync_core/src/sync_layer/client.rs | 5 +- .../zksync_core/src/sync_layer/external_io.rs | 5 +- .../lib/zksync_core/src/sync_layer/fetcher.rs | 5 +- .../lib/zksync_core/src/sync_layer/genesis.rs | 1 - .../src/sync_layer/gossip/buffered/mod.rs | 9 +- .../src/sync_layer/gossip/buffered/tests.rs | 5 +- .../src/sync_layer/gossip/conversions.rs | 2 +- .../src/sync_layer/gossip/metrics.rs | 4 +- .../zksync_core/src/sync_layer/gossip/mod.rs | 11 +- .../src/sync_layer/gossip/storage/mod.rs | 14 +- .../src/sync_layer/gossip/storage/tests.rs | 1 - .../src/sync_layer/gossip/tests.rs | 8 +- .../lib/zksync_core/src/sync_layer/metrics.rs | 4 +- core/lib/zksync_core/src/sync_layer/tests.rs | 5 +- .../src/witness_generator/basic_circuits.rs | 15 +- .../src/witness_generator/leaf_aggregation.rs | 13 +- .../zksync_core/src/witness_generator/mod.rs | 3 +- .../src/witness_generator/node_aggregation.rs | 6 +- .../precalculated_merkle_paths_provider.rs | 14 +- .../src/witness_generator/scheduler.rs | 3 +- .../src/witness_generator/storage_oracle.rs | 6 +- .../src/witness_generator/tests.rs | 10 +- .../src/witness_generator/utils.rs | 12 +- .../src/checker.rs | 9 +- .../src/config.rs | 3 +- .../src/divergence.rs | 1 + .../src/helpers.rs | 7 +- .../cross_external_nodes_checker/src/main.rs | 13 +- .../src/pubsub_checker.rs | 14 +- .../src/account/api_request_executor.rs | 1 - core/tests/loadnext/src/account/mod.rs | 9 +- .../loadnext/src/account/pubsub_executor.rs | 6 +- .../src/account/tx_command_executor.rs | 10 +- core/tests/loadnext/src/account_pool.rs | 1 - core/tests/loadnext/src/command/api.rs | 1 - core/tests/loadnext/src/command/tx_command.rs | 1 - core/tests/loadnext/src/config.rs | 9 +- core/tests/loadnext/src/corrupted_tx.rs | 20 +-- core/tests/loadnext/src/executor.rs | 21 +-- core/tests/loadnext/src/fs_utils.rs | 11 +- core/tests/loadnext/src/main.rs | 8 +- core/tests/loadnext/src/report.rs | 2 +- .../loadnext/src/report_collector/mod.rs | 4 +- .../operation_results_collector.rs | 4 +- core/tests/loadnext/src/rng.rs | 1 - core/tests/loadnext/src/utils.rs | 1 + .../vm-benchmark/benches/diy_benchmark.rs | 3 +- core/tests/vm-benchmark/harness/src/lib.rs | 14 +- .../vm-benchmark/src/compare_iai_results.rs | 5 +- core/tests/vm-benchmark/src/find_slowest.rs | 1 + .../src/iai_results_to_prometheus.rs | 1 + .../tests/vm-benchmark/src/with_prometheus.rs | 3 +- infrastructure/zk/src/fmt.ts | 7 +- prover/Cargo.lock | 130 +++--------------- .../src/circuit_synthesizer.rs | 42 +++--- prover/circuit_synthesizer/src/main.rs | 3 +- prover/circuit_synthesizer/src/metrics.rs | 1 + prover/proof_fri_compressor/src/compressor.rs | 39 +++--- prover/proof_fri_compressor/src/main.rs | 10 +- prover/proof_fri_compressor/src/metrics.rs | 1 + prover/prover/src/artifact_provider.rs | 8 +- prover/prover/src/metrics.rs | 1 + prover/prover/src/prover.rs | 14 +- prover/prover/src/prover_params.rs | 1 - prover/prover/src/run.rs | 18 ++- prover/prover/src/socket_listener.rs | 15 +- .../src/synthesized_circuit_provider.rs | 14 +- .../src/gpu_prover_job_processor.rs | 51 +++---- prover/prover_fri/src/main.rs | 33 +++-- prover/prover_fri/src/metrics.rs | 1 + prover/prover_fri/src/prover_job_processor.rs | 46 +++---- prover/prover_fri/src/socket_listener.rs | 27 ++-- prover/prover_fri/src/utils.rs | 36 ++--- prover/prover_fri/tests/basic_test.rs | 11 +- .../src/api_data_fetcher.rs | 6 +- prover/prover_fri_gateway/src/main.rs | 8 +- .../src/proof_gen_data_fetcher.rs | 1 - .../prover_fri_gateway/src/proof_submitter.rs | 7 +- prover/prover_fri_types/src/lib.rs | 32 ++--- prover/prover_fri_utils/src/lib.rs | 17 ++- prover/prover_fri_utils/src/metrics.rs | 1 + prover/prover_fri_utils/src/socket_utils.rs | 12 +- .../setup_key_generator_and_server/src/lib.rs | 26 ++-- .../src/main.rs | 11 +- .../src/commitment_utils.rs | 19 ++- .../src/lib.rs | 93 +++++++------ .../src/main.rs | 20 +-- .../src/setup_data_generator.rs | 40 +++--- .../src/tests.rs | 12 +- .../src/utils.rs | 113 ++++++++------- .../src/vk_generator.rs | 27 ++-- .../witness_generator/src/basic_circuits.rs | 65 +++++---- .../witness_generator/src/leaf_aggregation.rs | 56 ++++---- prover/witness_generator/src/main.rs | 26 ++-- prover/witness_generator/src/metrics.rs | 1 + .../witness_generator/src/node_aggregation.rs | 48 ++++--- .../precalculated_merkle_paths_provider.rs | 11 +- prover/witness_generator/src/scheduler.rs | 48 ++++--- .../witness_generator/src/storage_oracle.rs | 6 +- prover/witness_generator/src/tests.rs | 12 +- prover/witness_generator/src/utils.rs | 36 ++--- prover/witness_generator/tests/basic_test.rs | 22 +-- .../witness_vector_generator/src/generator.rs | 27 ++-- prover/witness_vector_generator/src/main.rs | 10 +- .../witness_vector_generator/src/metrics.rs | 1 + .../tests/basic_test.rs | 4 +- sdk/zksync-rs/src/ethereum/mod.rs | 24 ++-- sdk/zksync-rs/src/lib.rs | 21 ++- sdk/zksync-rs/src/operations/mod.rs | 4 +- sdk/zksync-rs/src/operations/transfer.rs | 15 +- sdk/zksync-rs/src/operations/withdraw.rs | 6 +- sdk/zksync-rs/src/signer.rs | 11 +- sdk/zksync-rs/src/utils.rs | 1 - sdk/zksync-rs/src/wallet.rs | 5 +- 640 files changed, 4414 insertions(+), 4176 deletions(-) diff --git a/core/bin/block_reverter/src/main.rs b/core/bin/block_reverter/src/main.rs index bc49b731d14..c1b02a1a120 100644 --- a/core/bin/block_reverter/src/main.rs +++ b/core/bin/block_reverter/src/main.rs @@ -1,15 +1,13 @@ use anyhow::Context as _; use clap::{Parser, Subcommand}; use tokio::io::{self, AsyncReadExt}; - use zksync_config::{ContractsConfig, DBConfig, ETHClientConfig, ETHSenderConfig, PostgresConfig}; -use zksync_dal::ConnectionPool; -use zksync_env_config::FromEnv; -use zksync_types::{L1BatchNumber, U256}; - use zksync_core::block_reverter::{ BlockReverter, BlockReverterEthConfig, BlockReverterFlags, L1ExecutedBatchesRevert, }; +use zksync_dal::ConnectionPool; +use zksync_env_config::FromEnv; +use zksync_types::{L1BatchNumber, U256}; #[derive(Debug, Parser)] #[command(author = "Matter Labs", version, about = "Block revert utility", long_about = None)] diff --git a/core/bin/contract-verifier/src/main.rs b/core/bin/contract-verifier/src/main.rs index 05ee51139dd..33090697c51 100644 --- a/core/bin/contract-verifier/src/main.rs +++ b/core/bin/contract-verifier/src/main.rs @@ -1,16 +1,15 @@ use std::cell::RefCell; use anyhow::Context as _; +use futures::{channel::mpsc, executor::block_on, SinkExt, StreamExt}; use prometheus_exporter::PrometheusExporterConfig; +use tokio::sync::watch; use zksync_config::{configs::PrometheusConfig, ApiConfig, ContractVerifierConfig, PostgresConfig}; use zksync_dal::ConnectionPool; use zksync_env_config::FromEnv; use zksync_queued_job_processor::JobProcessor; use zksync_utils::wait_for_tasks::wait_for_tasks; -use futures::{channel::mpsc, executor::block_on, SinkExt, StreamExt}; -use tokio::sync::watch; - use crate::verifier::ContractVerifier; pub mod error; diff --git a/core/bin/contract-verifier/src/verifier.rs b/core/bin/contract-verifier/src/verifier.rs index e34b4784c1c..63c46ed90f7 100644 --- a/core/bin/contract-verifier/src/verifier.rs +++ b/core/bin/contract-verifier/src/verifier.rs @@ -1,7 +1,9 @@ -use std::collections::HashMap; -use std::env; -use std::path::Path; -use std::time::{Duration, Instant}; +use std::{ + collections::HashMap, + env, + path::Path, + time::{Duration, Instant}, +}; use anyhow::Context as _; use chrono::Utc; @@ -9,7 +11,6 @@ use ethabi::{Contract, Token}; use lazy_static::lazy_static; use regex::Regex; use tokio::time; - use zksync_config::ContractVerifierConfig; use zksync_dal::{ConnectionPool, StorageProcessor}; use zksync_env_config::FromEnv; @@ -22,11 +23,11 @@ use zksync_types::{ Address, }; -use crate::error::ContractVerifierError; -use crate::zksolc_utils::{ - Optimizer, Settings, Source, StandardJson, ZkSolc, ZkSolcInput, ZkSolcOutput, +use crate::{ + error::ContractVerifierError, + zksolc_utils::{Optimizer, Settings, Source, StandardJson, ZkSolc, ZkSolcInput, ZkSolcOutput}, + zkvyper_utils::{ZkVyper, ZkVyperInput}, }; -use crate::zkvyper_utils::{ZkVyper, ZkVyperInput}; lazy_static! { static ref DEPLOYER_CONTRACT: Contract = zksync_contracts::deployer_contract(); diff --git a/core/bin/contract-verifier/src/zksolc_utils.rs b/core/bin/contract-verifier/src/zksolc_utils.rs index 4fba999453c..560bacb809f 100644 --- a/core/bin/contract-verifier/src/zksolc_utils.rs +++ b/core/bin/contract-verifier/src/zksolc_utils.rs @@ -1,8 +1,6 @@ +use std::{collections::HashMap, io::Write, path::PathBuf, process::Stdio}; + use serde::{Deserialize, Serialize}; -use std::collections::HashMap; -use std::io::Write; -use std::path::PathBuf; -use std::process::Stdio; use crate::error::ContractVerifierError; diff --git a/core/bin/contract-verifier/src/zkvyper_utils.rs b/core/bin/contract-verifier/src/zkvyper_utils.rs index 33a99f256f9..c597f78d458 100644 --- a/core/bin/contract-verifier/src/zkvyper_utils.rs +++ b/core/bin/contract-verifier/src/zkvyper_utils.rs @@ -1,8 +1,4 @@ -use std::collections::HashMap; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; -use std::process::Stdio; +use std::{collections::HashMap, fs::File, io::Write, path::PathBuf, process::Stdio}; use crate::error::ContractVerifierError; diff --git a/core/bin/external_node/src/config/mod.rs b/core/bin/external_node/src/config/mod.rs index c116201b91d..aea48bc0aeb 100644 --- a/core/bin/external_node/src/config/mod.rs +++ b/core/bin/external_node/src/config/mod.rs @@ -1,14 +1,14 @@ +use std::{env, time::Duration}; + use anyhow::Context; use serde::Deserialize; -use std::{env, time::Duration}; use url::Url; - use zksync_basic_types::{Address, L1ChainId, L2ChainId, MiniblockNumber}; use zksync_core::api_server::{ - tx_sender::TxSenderConfig, web3::state::InternalApiConfig, web3::Namespace, + tx_sender::TxSenderConfig, + web3::{state::InternalApiConfig, Namespace}, }; use zksync_types::api::BridgeAddresses; - use zksync_web3_decl::{ jsonrpsee::http_client::{HttpClient, HttpClientBuilder}, namespaces::{EnNamespaceClient, EthNamespaceClient, ZksNamespaceClient}, diff --git a/core/bin/external_node/src/main.rs b/core/bin/external_node/src/main.rs index 6324b0599a6..da28329c18f 100644 --- a/core/bin/external_node/src/main.rs +++ b/core/bin/external_node/src/main.rs @@ -1,11 +1,10 @@ -use anyhow::Context; -use clap::Parser; -use tokio::{sync::watch, task, time::sleep}; - use std::{sync::Arc, time::Duration}; +use anyhow::Context; +use clap::Parser; use futures::{future::FusedFuture, FutureExt}; use prometheus_exporter::PrometheusExporterConfig; +use tokio::{sync::watch, task, time::sleep}; use zksync_basic_types::{Address, L2ChainId}; use zksync_core::{ api_server::{ diff --git a/core/bin/merkle_tree_consistency_checker/src/main.rs b/core/bin/merkle_tree_consistency_checker/src/main.rs index b132bda87fa..8cac3d99724 100644 --- a/core/bin/merkle_tree_consistency_checker/src/main.rs +++ b/core/bin/merkle_tree_consistency_checker/src/main.rs @@ -1,8 +1,7 @@ -use anyhow::Context as _; -use clap::Parser; - use std::{path::Path, time::Instant}; +use anyhow::Context as _; +use clap::Parser; use zksync_config::DBConfig; use zksync_env_config::FromEnv; use zksync_merkle_tree::domain::ZkSyncTree; diff --git a/core/bin/rocksdb_util/src/main.rs b/core/bin/rocksdb_util/src/main.rs index 30d3d42e771..1fd60ca67c7 100644 --- a/core/bin/rocksdb_util/src/main.rs +++ b/core/bin/rocksdb_util/src/main.rs @@ -1,6 +1,5 @@ use anyhow::Context as _; use clap::{Parser, Subcommand}; - use zksync_config::DBConfig; use zksync_env_config::FromEnv; use zksync_storage::rocksdb::{ @@ -57,9 +56,10 @@ fn main() -> anyhow::Result<()> { #[cfg(test)] mod tests { - use super::*; use tempfile::TempDir; + use super::*; + #[test] fn backup_restore_workflow() { let backup_dir = TempDir::new().expect("failed to get temporary directory for RocksDB"); diff --git a/core/bin/storage_logs_dedup_migration/src/consistency.rs b/core/bin/storage_logs_dedup_migration/src/consistency.rs index 3c63c8c81a7..dc0b3da389c 100644 --- a/core/bin/storage_logs_dedup_migration/src/consistency.rs +++ b/core/bin/storage_logs_dedup_migration/src/consistency.rs @@ -1,5 +1,4 @@ use clap::Parser; - use zksync_config::PostgresConfig; use zksync_dal::ConnectionPool; use zksync_env_config::FromEnv; diff --git a/core/bin/storage_logs_dedup_migration/src/main.rs b/core/bin/storage_logs_dedup_migration/src/main.rs index 7277c231e43..733976b44e1 100644 --- a/core/bin/storage_logs_dedup_migration/src/main.rs +++ b/core/bin/storage_logs_dedup_migration/src/main.rs @@ -1,7 +1,6 @@ use std::collections::hash_map::{Entry, HashMap}; use clap::Parser; - use zksync_config::PostgresConfig; use zksync_dal::ConnectionPool; use zksync_env_config::FromEnv; diff --git a/core/bin/system-constants-generator/src/intrinsic_costs.rs b/core/bin/system-constants-generator/src/intrinsic_costs.rs index e15abf7d134..94cec591e00 100644 --- a/core/bin/system-constants-generator/src/intrinsic_costs.rs +++ b/core/bin/system-constants-generator/src/intrinsic_costs.rs @@ -4,13 +4,13 @@ //! as well as contracts/SystemConfig.json //! +use multivm::vm_latest::constants::BOOTLOADER_TX_ENCODING_SPACE; +use zksync_types::{ethabi::Address, IntrinsicSystemGasConstants, U256}; + use crate::utils::{ execute_internal_transfer_test, execute_user_txs_in_test_gas_vm, get_l1_tx, get_l1_txs, - get_l2_txs, + get_l2_txs, metrics_from_txs, TransactionGenerator, }; -use crate::utils::{metrics_from_txs, TransactionGenerator}; -use multivm::vm_latest::constants::BOOTLOADER_TX_ENCODING_SPACE; -use zksync_types::{ethabi::Address, IntrinsicSystemGasConstants, U256}; #[derive(Debug, Clone, Copy, PartialEq)] pub(crate) struct VmSpentResourcesResult { diff --git a/core/bin/system-constants-generator/src/main.rs b/core/bin/system-constants-generator/src/main.rs index ed906e1c9bb..44659d21781 100644 --- a/core/bin/system-constants-generator/src/main.rs +++ b/core/bin/system-constants-generator/src/main.rs @@ -1,7 +1,18 @@ use std::fs; +use codegen::{Block, Scope}; +use multivm::vm_latest::constants::{ + BLOCK_OVERHEAD_GAS, BLOCK_OVERHEAD_L1_GAS, BOOTLOADER_TX_ENCODING_SPACE, MAX_PUBDATA_PER_BLOCK, +}; use serde::{Deserialize, Serialize}; use zksync_types::{ + zkevm_test_harness::zk_evm::zkevm_opcode_defs::{ + circuit_prices::{ + ECRECOVER_CIRCUIT_COST_IN_ERGS, KECCAK256_CIRCUIT_COST_IN_ERGS, + SHA256_CIRCUIT_COST_IN_ERGS, + }, + system_params::MAX_TX_ERGS_LIMIT, + }, IntrinsicSystemGasConstants, GUARANTEED_PUBDATA_IN_TX, L1_GAS_PER_PUBDATA_BYTE, MAX_GAS_PER_PUBDATA_BYTE, MAX_NEW_FACTORY_DEPS, MAX_TXS_IN_BLOCK, }; @@ -9,16 +20,6 @@ use zksync_types::{ mod intrinsic_costs; mod utils; -use codegen::Block; -use codegen::Scope; -use multivm::vm_latest::constants::{ - BLOCK_OVERHEAD_GAS, BLOCK_OVERHEAD_L1_GAS, BOOTLOADER_TX_ENCODING_SPACE, MAX_PUBDATA_PER_BLOCK, -}; -use zksync_types::zkevm_test_harness::zk_evm::zkevm_opcode_defs::circuit_prices::{ - ECRECOVER_CIRCUIT_COST_IN_ERGS, KECCAK256_CIRCUIT_COST_IN_ERGS, SHA256_CIRCUIT_COST_IN_ERGS, -}; -use zksync_types::zkevm_test_harness::zk_evm::zkevm_opcode_defs::system_params::MAX_TX_ERGS_LIMIT; - // Params needed for L1 contracts #[derive(Copy, Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] diff --git a/core/bin/system-constants-generator/src/utils.rs b/core/bin/system-constants-generator/src/utils.rs index fc576ff44ee..b138c5261a8 100644 --- a/core/bin/system-constants-generator/src/utils.rs +++ b/core/bin/system-constants-generator/src/utils.rs @@ -1,16 +1,17 @@ -use once_cell::sync::Lazy; -use std::cell::RefCell; -use std::rc::Rc; - -use multivm::interface::{ - dyn_tracers::vm_1_4_0::DynTracer, tracer::VmExecutionStopReason, L1BatchEnv, L2BlockEnv, - SystemEnv, TxExecutionMode, VmExecutionMode, VmInterface, -}; -use multivm::vm_latest::{ - constants::{BLOCK_GAS_LIMIT, BOOTLOADER_HEAP_PAGE}, - BootloaderState, HistoryEnabled, HistoryMode, SimpleMemory, ToTracerPointer, Vm, VmTracer, - ZkSyncVmState, +use std::{cell::RefCell, rc::Rc}; + +use multivm::{ + interface::{ + dyn_tracers::vm_1_4_0::DynTracer, tracer::VmExecutionStopReason, L1BatchEnv, L2BlockEnv, + SystemEnv, TxExecutionMode, VmExecutionMode, VmInterface, + }, + vm_latest::{ + constants::{BLOCK_GAS_LIMIT, BOOTLOADER_HEAP_PAGE}, + BootloaderState, HistoryEnabled, HistoryMode, SimpleMemory, ToTracerPointer, Vm, VmTracer, + ZkSyncVmState, + }, }; +use once_cell::sync::Lazy; use zksync_contracts::{ load_sys_contract, read_bootloader_code, read_sys_contract_bytecode, read_zbin_bytecode, BaseSystemContracts, ContractLanguage, SystemContractCode, diff --git a/core/bin/verification_key_generator_and_server/src/json_to_binary_vk_converter.rs b/core/bin/verification_key_generator_and_server/src/json_to_binary_vk_converter.rs index 65a2e3361bf..c04a6712833 100644 --- a/core/bin/verification_key_generator_and_server/src/json_to_binary_vk_converter.rs +++ b/core/bin/verification_key_generator_and_server/src/json_to_binary_vk_converter.rs @@ -1,6 +1,6 @@ +use std::{fs::File, io::BufWriter}; + use bincode::serialize_into; -use std::fs::File; -use std::io::BufWriter; use structopt::StructOpt; use zksync_verification_key_server::get_vk_for_circuit_type; diff --git a/core/bin/verification_key_generator_and_server/src/lib.rs b/core/bin/verification_key_generator_and_server/src/lib.rs index 2b05363595b..20260a30b20 100644 --- a/core/bin/verification_key_generator_and_server/src/lib.rs +++ b/core/bin/verification_key_generator_and_server/src/lib.rs @@ -1,29 +1,29 @@ -use ff::to_hex; -use once_cell::sync::Lazy; -use std::collections::HashMap; -use std::path::Path; -use std::str::FromStr; -use zksync_types::zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit; -use zksync_types::zkevm_test_harness::bellman::bn256::Bn256; -use zksync_types::zkevm_test_harness::bellman::plonk::better_better_cs::setup::VerificationKey; -use zksync_types::zkevm_test_harness::witness::oracle::VmWitnessOracle; +use std::{collections::HashMap, path::Path, str::FromStr}; +use ff::to_hex; use itertools::Itertools; +use once_cell::sync::Lazy; use structopt::lazy_static::lazy_static; -use zksync_types::circuit::SCHEDULER_CIRCUIT_INDEX; -use zksync_types::circuit::{ - GEOMETRY_CONFIG, LEAF_CIRCUIT_INDEX, LEAF_SPLITTING_FACTOR, NODE_CIRCUIT_INDEX, - NODE_SPLITTING_FACTOR, SCHEDULER_UPPER_BOUND, -}; -use zksync_types::protocol_version::{L1VerifierConfig, VerifierParams}; -use zksync_types::vk_transform::generate_vk_commitment; -use zksync_types::zkevm_test_harness::witness; -use zksync_types::zkevm_test_harness::witness::full_block_artifact::BlockBasicCircuits; -use zksync_types::zkevm_test_harness::witness::recursive_aggregation::{ - erase_vk_type, padding_aggregations, +use zksync_types::{ + circuit::{ + GEOMETRY_CONFIG, LEAF_CIRCUIT_INDEX, LEAF_SPLITTING_FACTOR, NODE_CIRCUIT_INDEX, + NODE_SPLITTING_FACTOR, SCHEDULER_CIRCUIT_INDEX, SCHEDULER_UPPER_BOUND, + }, + protocol_version::{L1VerifierConfig, VerifierParams}, + vk_transform::generate_vk_commitment, + zkevm_test_harness::{ + abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, + bellman::{bn256::Bn256, plonk::better_better_cs::setup::VerificationKey}, + witness, + witness::{ + full_block_artifact::BlockBasicCircuits, + oracle::VmWitnessOracle, + recursive_aggregation::{erase_vk_type, padding_aggregations}, + vk_set_generator::circuits_for_vk_generation, + }, + }, + H256, }; -use zksync_types::zkevm_test_harness::witness::vk_set_generator::circuits_for_vk_generation; -use zksync_types::H256; #[cfg(test)] mod tests; diff --git a/core/bin/verification_key_generator_and_server/src/main.rs b/core/bin/verification_key_generator_and_server/src/main.rs index 30ffb0574d4..b64e5757fce 100644 --- a/core/bin/verification_key_generator_and_server/src/main.rs +++ b/core/bin/verification_key_generator_and_server/src/main.rs @@ -1,9 +1,12 @@ -use std::collections::HashSet; -use std::env; -use zksync_types::zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit; -use zksync_types::zkevm_test_harness::bellman::bn256::Bn256; -use zksync_types::zkevm_test_harness::bellman::plonk::better_better_cs::cs::PlonkCsWidth4WithNextStepAndCustomGatesParams; -use zksync_types::zkevm_test_harness::witness::oracle::VmWitnessOracle; +use std::{collections::HashSet, env}; + +use zksync_types::zkevm_test_harness::{ + abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, + bellman::{ + bn256::Bn256, plonk::better_better_cs::cs::PlonkCsWidth4WithNextStepAndCustomGatesParams, + }, + witness::oracle::VmWitnessOracle, +}; use zksync_verification_key_server::{get_circuits_for_vk, save_vk_for_circuit_type}; /// Creates verification keys for the given circuit. diff --git a/core/bin/verification_key_generator_and_server/src/tests.rs b/core/bin/verification_key_generator_and_server/src/tests.rs index 8f013bad200..f0fea866de6 100644 --- a/core/bin/verification_key_generator_and_server/src/tests.rs +++ b/core/bin/verification_key_generator_and_server/src/tests.rs @@ -1,12 +1,14 @@ -use crate::{get_vk_for_circuit_type, get_vks_for_basic_circuits, get_vks_for_commitment}; +use std::collections::HashMap; + use itertools::Itertools; use serde_json::Value; -use std::collections::HashMap; -use zksync_types::zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit; -use zksync_types::zkevm_test_harness::bellman::bn256::Bn256; -use zksync_types::zkevm_test_harness::bellman::plonk::better_better_cs::setup::VerificationKey; +use zksync_types::zkevm_test_harness::{ + abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, + bellman::{bn256::Bn256, plonk::better_better_cs::setup::VerificationKey}, + witness::oracle::VmWitnessOracle, +}; -use zksync_types::zkevm_test_harness::witness::oracle::VmWitnessOracle; +use crate::{get_vk_for_circuit_type, get_vks_for_basic_circuits, get_vks_for_commitment}; #[test] fn test_get_vk_for_circuit_type() { diff --git a/core/bin/verified_sources_fetcher/src/main.rs b/core/bin/verified_sources_fetcher/src/main.rs index 6bb6ee66cee..cc53229329f 100644 --- a/core/bin/verified_sources_fetcher/src/main.rs +++ b/core/bin/verified_sources_fetcher/src/main.rs @@ -1,4 +1,5 @@ use std::io::Write; + use zksync_config::PostgresConfig; use zksync_dal::ConnectionPool; use zksync_env_config::FromEnv; diff --git a/core/bin/zksync_server/src/main.rs b/core/bin/zksync_server/src/main.rs index f2aed9c75c2..9a5ccf8be60 100644 --- a/core/bin/zksync_server/src/main.rs +++ b/core/bin/zksync_server/src/main.rs @@ -1,8 +1,7 @@ -use anyhow::Context as _; -use clap::Parser; - use std::{str::FromStr, time::Duration}; +use anyhow::Context as _; +use clap::Parser; use zksync_config::{ configs::{ api::{HealthCheckConfig, MerkleTreeApiConfig, Web3JsonRpcConfig}, @@ -18,11 +17,9 @@ use zksync_config::{ ApiConfig, ContractsConfig, DBConfig, ETHClientConfig, ETHSenderConfig, ETHWatchConfig, FetcherConfig, GasAdjusterConfig, ObjectStoreConfig, PostgresConfig, ProverConfigs, }; - -use zksync_core::temp_config_store::TempConfigStore; use zksync_core::{ - genesis_init, initialize_components, is_genesis_needed, setup_sigint_handler, Component, - Components, + genesis_init, initialize_components, is_genesis_needed, setup_sigint_handler, + temp_config_store::TempConfigStore, Component, Components, }; use zksync_env_config::FromEnv; use zksync_storage::RocksDB; diff --git a/core/lib/basic_types/src/lib.rs b/core/lib/basic_types/src/lib.rs index 6c6223fbb17..aa9bf615c91 100644 --- a/core/lib/basic_types/src/lib.rs +++ b/core/lib/basic_types/src/lib.rs @@ -2,25 +2,25 @@ //! //! Most of them are just re-exported from the `web3` crate. +use std::{ + convert::{Infallible, TryFrom, TryInto}, + fmt, + num::ParseIntError, + ops::{Add, Deref, DerefMut, Sub}, + str::FromStr, +}; + +use serde::{de, Deserialize, Deserializer, Serialize}; +pub use web3::{ + self, ethabi, + types::{Address, Bytes, Log, TransactionRequest, H128, H160, H2048, H256, U128, U256, U64}, +}; + #[macro_use] mod macros; - pub mod basic_fri_types; pub mod network; -use serde::{de, Deserialize, Deserializer, Serialize}; -use std::convert::{Infallible, TryFrom, TryInto}; -use std::fmt; -use std::num::ParseIntError; -use std::ops::{Add, Deref, DerefMut, Sub}; -use std::str::FromStr; - -pub use web3; -pub use web3::ethabi; -pub use web3::types::{ - Address, Bytes, Log, TransactionRequest, H128, H160, H2048, H256, U128, U256, U64, -}; - /// Account place in the global state tree is uniquely identified by its address. /// Binary this type is represented by 160 bit big-endian representation of account address. #[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Hash, Ord, PartialOrd)] @@ -222,9 +222,10 @@ impl Default for PriorityOpId { #[cfg(test)] mod tests { - use super::*; use serde_json::from_str; + use super::*; + #[test] fn test_from_str_valid_decimal() { let input = "42"; diff --git a/core/lib/circuit_breaker/src/l1_txs.rs b/core/lib/circuit_breaker/src/l1_txs.rs index 5279106637e..5d3c4dc9ccf 100644 --- a/core/lib/circuit_breaker/src/l1_txs.rs +++ b/core/lib/circuit_breaker/src/l1_txs.rs @@ -1,6 +1,7 @@ -use crate::{CircuitBreaker, CircuitBreakerError}; use zksync_dal::ConnectionPool; +use crate::{CircuitBreaker, CircuitBreakerError}; + #[derive(Debug)] pub struct FailedL1TransactionChecker { pub pool: ConnectionPool, diff --git a/core/lib/circuit_breaker/src/lib.rs b/core/lib/circuit_breaker/src/lib.rs index 878114f0d04..4c84f857a29 100644 --- a/core/lib/circuit_breaker/src/lib.rs +++ b/core/lib/circuit_breaker/src/lib.rs @@ -4,7 +4,6 @@ use anyhow::Context as _; use futures::channel::oneshot; use thiserror::Error; use tokio::sync::watch; - use zksync_config::configs::chain::CircuitBreakerConfig; pub mod l1_txs; diff --git a/core/lib/config/src/configs/api.rs b/core/lib/config/src/configs/api.rs index 14b3d81520c..348c1c95e2d 100644 --- a/core/lib/config/src/configs/api.rs +++ b/core/lib/config/src/configs/api.rs @@ -1,10 +1,10 @@ -use serde::Deserialize; - use std::{net::SocketAddr, time::Duration}; -pub use crate::configs::PrometheusConfig; +use serde::Deserialize; use zksync_basic_types::H256; +pub use crate::configs::PrometheusConfig; + /// API configuration. #[derive(Debug, Deserialize, Clone, PartialEq)] pub struct ApiConfig { diff --git a/core/lib/config/src/configs/chain.rs b/core/lib/config/src/configs/chain.rs index f09b5bb292c..eb77467183f 100644 --- a/core/lib/config/src/configs/chain.rs +++ b/core/lib/config/src/configs/chain.rs @@ -1,11 +1,7 @@ -/// External uses +use std::{str::FromStr, time::Duration}; + use serde::Deserialize; -use std::str::FromStr; -/// Built-in uses -use std::time::Duration; -// Local uses -use zksync_basic_types::network::Network; -use zksync_basic_types::{Address, L2ChainId}; +use zksync_basic_types::{network::Network, Address, L2ChainId}; #[derive(Debug, Deserialize, Clone, PartialEq)] pub struct ChainConfig { diff --git a/core/lib/config/src/configs/contract_verifier.rs b/core/lib/config/src/configs/contract_verifier.rs index 5c2a1608c8f..db3c8fa1b52 100644 --- a/core/lib/config/src/configs/contract_verifier.rs +++ b/core/lib/config/src/configs/contract_verifier.rs @@ -1,6 +1,5 @@ -// Built-in uses use std::time::Duration; -// External uses + use serde::Deserialize; #[derive(Debug, Deserialize, Clone, PartialEq)] diff --git a/core/lib/config/src/configs/database.rs b/core/lib/config/src/configs/database.rs index d257e661eb3..dcff7d486a8 100644 --- a/core/lib/config/src/configs/database.rs +++ b/core/lib/config/src/configs/database.rs @@ -1,8 +1,8 @@ +use std::time::Duration; + use anyhow::Context as _; use serde::{Deserialize, Serialize}; -use std::time::Duration; - /// Mode of operation for the Merkle tree. /// /// The mode does not influence how tree data is stored; i.e., a mode can be switched on the fly. diff --git a/core/lib/config/src/configs/eth_sender.rs b/core/lib/config/src/configs/eth_sender.rs index 3d036483347..cd44daed17f 100644 --- a/core/lib/config/src/configs/eth_sender.rs +++ b/core/lib/config/src/configs/eth_sender.rs @@ -1,8 +1,6 @@ -// Built-in uses use std::time::Duration; -// External uses + use serde::Deserialize; -// Workspace uses use zksync_basic_types::H256; /// Configuration for the Ethereum sender crate. diff --git a/core/lib/config/src/configs/eth_watch.rs b/core/lib/config/src/configs/eth_watch.rs index 93d73ddf6bf..05afebf81c3 100644 --- a/core/lib/config/src/configs/eth_watch.rs +++ b/core/lib/config/src/configs/eth_watch.rs @@ -1,6 +1,5 @@ -// Built-in uses use std::time::Duration; -// External uses + use serde::Deserialize; /// Configuration for the Ethereum sender crate. diff --git a/core/lib/config/src/configs/fetcher.rs b/core/lib/config/src/configs/fetcher.rs index b1a5fca4b24..a1e63742e22 100644 --- a/core/lib/config/src/configs/fetcher.rs +++ b/core/lib/config/src/configs/fetcher.rs @@ -1,6 +1,7 @@ -use serde::Deserialize; use std::time::Duration; +use serde::Deserialize; + #[derive(Debug, Deserialize, Clone, Copy, PartialEq)] pub enum TokenListSource { OneInch, diff --git a/core/lib/config/src/configs/fri_proof_compressor.rs b/core/lib/config/src/configs/fri_proof_compressor.rs index bbf58f2d1c6..4b4e062dee2 100644 --- a/core/lib/config/src/configs/fri_proof_compressor.rs +++ b/core/lib/config/src/configs/fri_proof_compressor.rs @@ -1,6 +1,7 @@ -use serde::Deserialize; use std::time::Duration; +use serde::Deserialize; + /// Configuration for the fri proof compressor #[derive(Debug, Deserialize, Clone, PartialEq)] pub struct FriProofCompressorConfig { diff --git a/core/lib/config/src/configs/fri_prover.rs b/core/lib/config/src/configs/fri_prover.rs index aab358a4ada..44521ee3657 100644 --- a/core/lib/config/src/configs/fri_prover.rs +++ b/core/lib/config/src/configs/fri_prover.rs @@ -1,6 +1,7 @@ -use serde::Deserialize; use std::time::Duration; +use serde::Deserialize; + #[derive(Debug, Deserialize, Clone, PartialEq)] pub enum SetupLoadMode { FromDisk, diff --git a/core/lib/config/src/configs/fri_prover_gateway.rs b/core/lib/config/src/configs/fri_prover_gateway.rs index 652c7d1bc0f..86723ff3043 100644 --- a/core/lib/config/src/configs/fri_prover_gateway.rs +++ b/core/lib/config/src/configs/fri_prover_gateway.rs @@ -1,6 +1,7 @@ -use serde::Deserialize; use std::time::Duration; +use serde::Deserialize; + #[derive(Debug, Deserialize, Clone, PartialEq)] pub struct FriProverGatewayConfig { pub api_url: String, diff --git a/core/lib/config/src/configs/fri_prover_group.rs b/core/lib/config/src/configs/fri_prover_group.rs index 71ed5d1f7d9..856ff59809f 100644 --- a/core/lib/config/src/configs/fri_prover_group.rs +++ b/core/lib/config/src/configs/fri_prover_group.rs @@ -1,6 +1,6 @@ -use serde::Deserialize; use std::collections::HashSet; +use serde::Deserialize; use zksync_basic_types::basic_fri_types::CircuitIdRoundTuple; /// Configuration for the grouping of specialized provers. diff --git a/core/lib/config/src/configs/mod.rs b/core/lib/config/src/configs/mod.rs index 0c2ecc46103..710c128c951 100644 --- a/core/lib/config/src/configs/mod.rs +++ b/core/lib/config/src/configs/mod.rs @@ -1,15 +1,26 @@ // Public re-exports pub use self::{ - alerts::AlertsConfig, api::ApiConfig, chain::ChainConfig, - circuit_synthesizer::CircuitSynthesizerConfig, contract_verifier::ContractVerifierConfig, - contracts::ContractsConfig, database::DBConfig, database::PostgresConfig, - eth_client::ETHClientConfig, eth_sender::ETHSenderConfig, eth_sender::GasAdjusterConfig, - eth_watch::ETHWatchConfig, fetcher::FetcherConfig, - fri_proof_compressor::FriProofCompressorConfig, fri_prover::FriProverConfig, - fri_prover_gateway::FriProverGatewayConfig, fri_witness_generator::FriWitnessGeneratorConfig, - fri_witness_vector_generator::FriWitnessVectorGeneratorConfig, object_store::ObjectStoreConfig, - proof_data_handler::ProofDataHandlerConfig, prover::ProverConfig, prover::ProverConfigs, - prover_group::ProverGroupConfig, utils::PrometheusConfig, + alerts::AlertsConfig, + api::ApiConfig, + chain::ChainConfig, + circuit_synthesizer::CircuitSynthesizerConfig, + contract_verifier::ContractVerifierConfig, + contracts::ContractsConfig, + database::{DBConfig, PostgresConfig}, + eth_client::ETHClientConfig, + eth_sender::{ETHSenderConfig, GasAdjusterConfig}, + eth_watch::ETHWatchConfig, + fetcher::FetcherConfig, + fri_proof_compressor::FriProofCompressorConfig, + fri_prover::FriProverConfig, + fri_prover_gateway::FriProverGatewayConfig, + fri_witness_generator::FriWitnessGeneratorConfig, + fri_witness_vector_generator::FriWitnessVectorGeneratorConfig, + object_store::ObjectStoreConfig, + proof_data_handler::ProofDataHandlerConfig, + prover::{ProverConfig, ProverConfigs}, + prover_group::ProverGroupConfig, + utils::PrometheusConfig, witness_generator::WitnessGeneratorConfig, }; diff --git a/core/lib/config/src/configs/proof_data_handler.rs b/core/lib/config/src/configs/proof_data_handler.rs index e3efd6b7a4d..b773efbd7df 100644 --- a/core/lib/config/src/configs/proof_data_handler.rs +++ b/core/lib/config/src/configs/proof_data_handler.rs @@ -1,6 +1,7 @@ -use serde::Deserialize; use std::time::Duration; +use serde::Deserialize; + #[derive(Debug, Deserialize, Clone, Copy, PartialEq)] pub enum ProtocolVersionLoadingMode { FromDb, diff --git a/core/lib/config/src/configs/utils.rs b/core/lib/config/src/configs/utils.rs index bfa9e7e7f3e..977a48e82d2 100644 --- a/core/lib/config/src/configs/utils.rs +++ b/core/lib/config/src/configs/utils.rs @@ -1,7 +1,7 @@ -use serde::Deserialize; - use std::{env, time::Duration}; +use serde::Deserialize; + #[derive(Debug, Deserialize, Clone, PartialEq)] pub struct PrometheusConfig { /// Port to which the Prometheus exporter server is listening. diff --git a/core/lib/contracts/src/lib.rs b/core/lib/contracts/src/lib.rs index 766d2464d34..917bf7a6ffe 100644 --- a/core/lib/contracts/src/lib.rs +++ b/core/lib/contracts/src/lib.rs @@ -3,17 +3,18 @@ //! Careful: some of the methods are reading the contracts based on the ZKSYNC_HOME environment variable. #![allow(clippy::derive_partial_eq_without_eq)] + +use std::{ + fs::{self, File}, + path::{Path, PathBuf}, +}; + use ethabi::{ ethereum_types::{H256, U256}, Contract, Function, }; use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; -use std::{ - fs::{self, File}, - path::{Path, PathBuf}, -}; - use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words}; pub mod test_contracts; diff --git a/core/lib/contracts/src/test_contracts.rs b/core/lib/contracts/src/test_contracts.rs index 9db4051cfdb..eab1587f833 100644 --- a/core/lib/contracts/src/test_contracts.rs +++ b/core/lib/contracts/src/test_contracts.rs @@ -1,8 +1,8 @@ -use crate::get_loadnext_contract; -use ethabi::ethereum_types::U256; -use ethabi::{Bytes, Token}; +use ethabi::{ethereum_types::U256, Bytes, Token}; use serde::Deserialize; +use crate::get_loadnext_contract; + #[derive(Debug, Clone, Deserialize)] pub struct LoadnextContractExecutionParams { pub reads: usize, diff --git a/core/lib/crypto/src/hasher/blake2.rs b/core/lib/crypto/src/hasher/blake2.rs index 70d8c9797e8..97d3fbb8a1e 100644 --- a/core/lib/crypto/src/hasher/blake2.rs +++ b/core/lib/crypto/src/hasher/blake2.rs @@ -1,7 +1,7 @@ use blake2::{Blake2s256, Digest}; +use zksync_basic_types::H256; use crate::hasher::Hasher; -use zksync_basic_types::H256; #[derive(Default, Clone, Debug)] pub struct Blake2Hasher; diff --git a/core/lib/crypto/src/hasher/keccak.rs b/core/lib/crypto/src/hasher/keccak.rs index e4c441328de..d3baab873f9 100644 --- a/core/lib/crypto/src/hasher/keccak.rs +++ b/core/lib/crypto/src/hasher/keccak.rs @@ -1,6 +1,7 @@ -use crate::hasher::Hasher; use zksync_basic_types::{web3::signing::keccak256, H256}; +use crate::hasher::Hasher; + #[derive(Default, Clone, Debug)] pub struct KeccakHasher; diff --git a/core/lib/crypto/src/hasher/sha256.rs b/core/lib/crypto/src/hasher/sha256.rs index 73e593ead72..b976c79d210 100644 --- a/core/lib/crypto/src/hasher/sha256.rs +++ b/core/lib/crypto/src/hasher/sha256.rs @@ -1,7 +1,7 @@ use sha2::{Digest, Sha256}; +use zksync_basic_types::H256; use crate::hasher::Hasher; -use zksync_basic_types::H256; #[derive(Debug, Default, Clone, Copy)] pub struct Sha256Hasher; diff --git a/core/lib/dal/src/basic_witness_input_producer_dal.rs b/core/lib/dal/src/basic_witness_input_producer_dal.rs index ac0627a96a0..cae640e94b8 100644 --- a/core/lib/dal/src/basic_witness_input_producer_dal.rs +++ b/core/lib/dal/src/basic_witness_input_producer_dal.rs @@ -1,10 +1,14 @@ -use crate::instrument::InstrumentExt; -use crate::time_utils::{duration_to_naive_time, pg_interval_from_duration}; -use crate::StorageProcessor; -use sqlx::postgres::types::PgInterval; use std::time::{Duration, Instant}; + +use sqlx::postgres::types::PgInterval; use zksync_types::L1BatchNumber; +use crate::{ + instrument::InstrumentExt, + time_utils::{duration_to_naive_time, pg_interval_from_duration}, + StorageProcessor, +}; + #[derive(Debug)] pub struct BasicWitnessInputProducerDal<'a, 'c> { pub(crate) storage: &'a mut StorageProcessor<'c>, diff --git a/core/lib/dal/src/blocks_dal.rs b/core/lib/dal/src/blocks_dal.rs index c60d52e197b..16e926393fb 100644 --- a/core/lib/dal/src/blocks_dal.rs +++ b/core/lib/dal/src/blocks_dal.rs @@ -7,7 +7,6 @@ use std::{ use anyhow::Context as _; use bigdecimal::{BigDecimal, FromPrimitive, ToPrimitive}; use sqlx::Row; - use zksync_types::{ aggregated_operations::AggregatedActionType, block::{BlockGasCount, L1BatchHeader, MiniblockHeader}, diff --git a/core/lib/dal/src/blocks_web3_dal.rs b/core/lib/dal/src/blocks_web3_dal.rs index 0c2a8b4e188..87f6fca1eb2 100644 --- a/core/lib/dal/src/blocks_web3_dal.rs +++ b/core/lib/dal/src/blocks_web3_dal.rs @@ -1,6 +1,5 @@ use bigdecimal::BigDecimal; use sqlx::Row; - use zksync_system_constants::EMPTY_UNCLES_HASH; use zksync_types::{ api, @@ -13,14 +12,17 @@ use zksync_types::{ }; use zksync_utils::bigdecimal_to_u256; -use crate::models::{ - storage_block::{ - bind_block_where_sql_params, web3_block_number_to_sql, web3_block_where_sql, - StorageBlockDetails, StorageL1BatchDetails, +use crate::{ + instrument::InstrumentExt, + models::{ + storage_block::{ + bind_block_where_sql_params, web3_block_number_to_sql, web3_block_where_sql, + StorageBlockDetails, StorageL1BatchDetails, + }, + storage_transaction::{extract_web3_transaction, web3_transaction_select_sql, CallTrace}, }, - storage_transaction::{extract_web3_transaction, web3_transaction_select_sql, CallTrace}, + StorageProcessor, }; -use crate::{instrument::InstrumentExt, StorageProcessor}; const BLOCK_GAS_LIMIT: u32 = system_params::VM_INITIAL_FRAME_ERGS; diff --git a/core/lib/dal/src/connection/holder.rs b/core/lib/dal/src/connection/holder.rs index 265b892c089..1174f834ae8 100644 --- a/core/lib/dal/src/connection/holder.rs +++ b/core/lib/dal/src/connection/holder.rs @@ -1,8 +1,7 @@ -// Built-in deps -use sqlx::pool::PoolConnection; -use sqlx::{postgres::Postgres, Transaction}; use std::fmt; +use sqlx::{pool::PoolConnection, postgres::Postgres, Transaction}; + /// Connection holder unifies the type of underlying connection, which /// can be either pooled or direct. pub(crate) enum ConnectionHolder<'a> { diff --git a/core/lib/dal/src/connection/mod.rs b/core/lib/dal/src/connection/mod.rs index 845dbc64dc4..b7f82d619ff 100644 --- a/core/lib/dal/src/connection/mod.rs +++ b/core/lib/dal/src/connection/mod.rs @@ -1,17 +1,15 @@ +use std::{env, fmt, time::Duration}; + +use anyhow::Context as _; use sqlx::{ pool::PoolConnection, postgres::{PgConnectOptions, PgPool, PgPoolOptions, Postgres}, }; -use anyhow::Context as _; -use std::env; -use std::fmt; -use std::time::Duration; +use crate::{metrics::CONNECTION_METRICS, StorageProcessor}; pub mod holder; -use crate::{metrics::CONNECTION_METRICS, StorageProcessor}; - /// Obtains the test database URL from the environment variable. fn get_test_database_url() -> anyhow::Result { env::var("TEST_DATABASE_URL").context( diff --git a/core/lib/dal/src/contract_verification_dal.rs b/core/lib/dal/src/contract_verification_dal.rs index a6c549f482b..5466b0c11b2 100644 --- a/core/lib/dal/src/contract_verification_dal.rs +++ b/core/lib/dal/src/contract_verification_dal.rs @@ -1,7 +1,10 @@ -use anyhow::Context as _; -use std::fmt::{Display, Formatter}; -use std::time::Duration; +use std::{ + fmt::{Display, Formatter}, + time::Duration, +}; +use anyhow::Context as _; +use sqlx::postgres::types::PgInterval; use zksync_types::{ contract_verification_api::{ DeployContractCalldata, VerificationIncomingRequest, VerificationInfo, VerificationRequest, @@ -10,10 +13,7 @@ use zksync_types::{ get_code_key, Address, CONTRACT_DEPLOYER_ADDRESS, FAILED_CONTRACT_DEPLOYMENT_BYTECODE_HASH, }; -use sqlx::postgres::types::PgInterval; - -use crate::models::storage_verification_request::StorageVerificationRequest; -use crate::StorageProcessor; +use crate::{models::storage_verification_request::StorageVerificationRequest, StorageProcessor}; #[derive(Debug)] pub struct ContractVerificationDal<'a, 'c> { diff --git a/core/lib/dal/src/eth_sender_dal.rs b/core/lib/dal/src/eth_sender_dal.rs index 0d9d1da0dab..94d7adfe284 100644 --- a/core/lib/dal/src/eth_sender_dal.rs +++ b/core/lib/dal/src/eth_sender_dal.rs @@ -1,17 +1,22 @@ -use crate::models::storage_eth_tx::{ - L1BatchEthSenderStats, StorageEthTx, StorageTxHistory, StorageTxHistoryToSend, -}; -use crate::StorageProcessor; +use std::{convert::TryFrom, str::FromStr}; + use anyhow::Context as _; use sqlx::{ types::chrono::{DateTime, Utc}, Row, }; -use std::convert::TryFrom; -use std::str::FromStr; -use zksync_types::aggregated_operations::AggregatedActionType; -use zksync_types::eth_sender::{EthTx, TxHistory, TxHistoryToSend}; -use zksync_types::{Address, L1BatchNumber, H256, U256}; +use zksync_types::{ + aggregated_operations::AggregatedActionType, + eth_sender::{EthTx, TxHistory, TxHistoryToSend}, + Address, L1BatchNumber, H256, U256, +}; + +use crate::{ + models::storage_eth_tx::{ + L1BatchEthSenderStats, StorageEthTx, StorageTxHistory, StorageTxHistoryToSend, + }, + StorageProcessor, +}; #[derive(Debug)] pub struct EthSenderDal<'a, 'c> { diff --git a/core/lib/dal/src/events_dal.rs b/core/lib/dal/src/events_dal.rs index 6355deaf29a..22967982b3b 100644 --- a/core/lib/dal/src/events_dal.rs +++ b/core/lib/dal/src/events_dal.rs @@ -1,14 +1,14 @@ -use sqlx::types::chrono::Utc; - use std::fmt; -use crate::{models::storage_event::StorageL2ToL1Log, SqlxError, StorageProcessor}; +use sqlx::types::chrono::Utc; use zksync_types::{ l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}, tx::IncludedTxLocation, MiniblockNumber, VmEvent, H256, }; +use crate::{models::storage_event::StorageL2ToL1Log, SqlxError, StorageProcessor}; + /// Wrapper around an optional event topic allowing to hex-format it for `COPY` instructions. #[derive(Debug)] struct EventTopic<'a>(Option<&'a H256>); @@ -196,9 +196,10 @@ impl EventsDal<'_, '_> { #[cfg(test)] mod tests { + use zksync_types::{Address, L1BatchNumber, ProtocolVersion}; + use super::*; use crate::{tests::create_miniblock_header, ConnectionPool}; - use zksync_types::{Address, L1BatchNumber, ProtocolVersion}; fn create_vm_event(index: u8, topic_count: u8) -> VmEvent { assert!(topic_count <= 4); diff --git a/core/lib/dal/src/events_web3_dal.rs b/core/lib/dal/src/events_web3_dal.rs index 7cdf2dba646..e8b1c802446 100644 --- a/core/lib/dal/src/events_web3_dal.rs +++ b/core/lib/dal/src/events_web3_dal.rs @@ -1,5 +1,4 @@ use sqlx::Row; - use zksync_types::{ api::{GetLogsFilter, Log}, Address, MiniblockNumber, H256, diff --git a/core/lib/dal/src/fri_gpu_prover_queue_dal.rs b/core/lib/dal/src/fri_gpu_prover_queue_dal.rs index 46c46a15b73..141b2e0378e 100644 --- a/core/lib/dal/src/fri_gpu_prover_queue_dal.rs +++ b/core/lib/dal/src/fri_gpu_prover_queue_dal.rs @@ -1,8 +1,8 @@ use std::time::Duration; + use zksync_types::proofs::{GpuProverInstanceStatus, SocketAddress}; -use crate::time_utils::pg_interval_from_duration; -use crate::StorageProcessor; +use crate::{time_utils::pg_interval_from_duration, StorageProcessor}; #[derive(Debug)] pub struct FriGpuProverQueueDal<'a, 'c> { diff --git a/core/lib/dal/src/fri_proof_compressor_dal.rs b/core/lib/dal/src/fri_proof_compressor_dal.rs index b7f1d1921e9..6e6db0bb6d8 100644 --- a/core/lib/dal/src/fri_proof_compressor_dal.rs +++ b/core/lib/dal/src/fri_proof_compressor_dal.rs @@ -1,14 +1,16 @@ +use std::{collections::HashMap, str::FromStr, time::Duration}; + use sqlx::Row; -use std::collections::HashMap; -use std::str::FromStr; -use std::time::Duration; use strum::{Display, EnumString}; - -use zksync_types::proofs::{JobCountStatistics, StuckJobs}; -use zksync_types::L1BatchNumber; - -use crate::time_utils::{duration_to_naive_time, pg_interval_from_duration}; -use crate::StorageProcessor; +use zksync_types::{ + proofs::{JobCountStatistics, StuckJobs}, + L1BatchNumber, +}; + +use crate::{ + time_utils::{duration_to_naive_time, pg_interval_from_duration}, + StorageProcessor, +}; #[derive(Debug)] pub struct FriProofCompressorDal<'a, 'c> { diff --git a/core/lib/dal/src/fri_protocol_versions_dal.rs b/core/lib/dal/src/fri_protocol_versions_dal.rs index 8fbcf922d8b..7eac1190bb9 100644 --- a/core/lib/dal/src/fri_protocol_versions_dal.rs +++ b/core/lib/dal/src/fri_protocol_versions_dal.rs @@ -1,7 +1,6 @@ use std::convert::TryFrom; -use zksync_types::protocol_version::FriProtocolVersionId; -use zksync_types::protocol_version::L1VerifierConfig; +use zksync_types::protocol_version::{FriProtocolVersionId, L1VerifierConfig}; use crate::StorageProcessor; diff --git a/core/lib/dal/src/fri_scheduler_dependency_tracker_dal.rs b/core/lib/dal/src/fri_scheduler_dependency_tracker_dal.rs index 3844f5777ce..a9639dfe951 100644 --- a/core/lib/dal/src/fri_scheduler_dependency_tracker_dal.rs +++ b/core/lib/dal/src/fri_scheduler_dependency_tracker_dal.rs @@ -1,6 +1,7 @@ -use crate::StorageProcessor; use zksync_types::L1BatchNumber; +use crate::StorageProcessor; + #[derive(Debug)] pub struct FriSchedulerDependencyTrackerDal<'a, 'c> { pub storage: &'a mut StorageProcessor<'c>, diff --git a/core/lib/dal/src/fri_witness_generator_dal.rs b/core/lib/dal/src/fri_witness_generator_dal.rs index c05dd3b3d1a..c11f20adec5 100644 --- a/core/lib/dal/src/fri_witness_generator_dal.rs +++ b/core/lib/dal/src/fri_witness_generator_dal.rs @@ -1,14 +1,12 @@ -use sqlx::Row; - -use std::convert::TryFrom; -use std::{collections::HashMap, time::Duration}; +use std::{collections::HashMap, convert::TryFrom, time::Duration}; -use zksync_types::protocol_version::FriProtocolVersionId; +use sqlx::Row; use zksync_types::{ proofs::{ AggregationRound, JobCountStatistics, LeafAggregationJobMetadata, NodeAggregationJobMetadata, StuckJobs, }, + protocol_version::FriProtocolVersionId, L1BatchNumber, }; diff --git a/core/lib/dal/src/gpu_prover_queue_dal.rs b/core/lib/dal/src/gpu_prover_queue_dal.rs index cc769ff3008..b4c348ab3e7 100644 --- a/core/lib/dal/src/gpu_prover_queue_dal.rs +++ b/core/lib/dal/src/gpu_prover_queue_dal.rs @@ -1,10 +1,9 @@ -use std::time::Duration; +use std::{collections::HashMap, time::Duration}; -use crate::time_utils::pg_interval_from_duration; -use crate::StorageProcessor; -use std::collections::HashMap; use zksync_types::proofs::{GpuProverInstanceStatus, SocketAddress}; +use crate::{time_utils::pg_interval_from_duration, StorageProcessor}; + #[derive(Debug)] pub struct GpuProverQueueDal<'a, 'c> { pub(crate) storage: &'a mut StorageProcessor<'c>, diff --git a/core/lib/dal/src/healthcheck.rs b/core/lib/dal/src/healthcheck.rs index 902a235ce54..ec56f8ea931 100644 --- a/core/lib/dal/src/healthcheck.rs +++ b/core/lib/dal/src/healthcheck.rs @@ -1,6 +1,5 @@ use serde::Serialize; use sqlx::PgPool; - use zksync_health_check::{async_trait, CheckHealth, Health, HealthStatus}; use crate::ConnectionPool; diff --git a/core/lib/dal/src/instrument.rs b/core/lib/dal/src/instrument.rs index cd761fb3500..5d99b0729de 100644 --- a/core/lib/dal/src/instrument.rs +++ b/core/lib/dal/src/instrument.rs @@ -1,5 +1,7 @@ //! DAL query instrumentation. +use std::{fmt, future::Future, panic::Location}; + use sqlx::{ postgres::{PgConnection, PgQueryResult, PgRow}, query::{Map, Query, QueryAs}, @@ -7,8 +9,6 @@ use sqlx::{ }; use tokio::time::{Duration, Instant}; -use std::{fmt, future::Future, panic::Location}; - use crate::metrics::REQUEST_METRICS; type ThreadSafeDebug<'a> = dyn fmt::Debug + Send + Sync + 'a; diff --git a/core/lib/dal/src/lib.rs b/core/lib/dal/src/lib.rs index 9dfc9458202..68d19fe84b9 100644 --- a/core/lib/dal/src/lib.rs +++ b/core/lib/dal/src/lib.rs @@ -1,45 +1,27 @@ #![allow(clippy::derive_partial_eq_without_eq, clippy::format_push_string)] -// Built-in deps -pub use sqlx::Error as SqlxError; -use sqlx::{postgres::Postgres, Connection, PgConnection, Transaction}; -// External imports -use sqlx::pool::PoolConnection; -pub use sqlx::types::BigDecimal; - -// Local imports -use crate::accounts_dal::AccountsDal; -use crate::basic_witness_input_producer_dal::BasicWitnessInputProducerDal; -use crate::blocks_dal::BlocksDal; -use crate::blocks_web3_dal::BlocksWeb3Dal; -use crate::connection::holder::ConnectionHolder; +use sqlx::{pool::PoolConnection, postgres::Postgres, Connection, PgConnection, Transaction}; +pub use sqlx::{types::BigDecimal, Error as SqlxError}; + pub use crate::connection::ConnectionPool; -use crate::contract_verification_dal::ContractVerificationDal; -use crate::eth_sender_dal::EthSenderDal; -use crate::events_dal::EventsDal; -use crate::events_web3_dal::EventsWeb3Dal; -use crate::fri_gpu_prover_queue_dal::FriGpuProverQueueDal; -use crate::fri_proof_compressor_dal::FriProofCompressorDal; -use crate::fri_protocol_versions_dal::FriProtocolVersionsDal; -use crate::fri_prover_dal::FriProverDal; -use crate::fri_scheduler_dependency_tracker_dal::FriSchedulerDependencyTrackerDal; -use crate::fri_witness_generator_dal::FriWitnessGeneratorDal; -use crate::gpu_prover_queue_dal::GpuProverQueueDal; -use crate::proof_generation_dal::ProofGenerationDal; -use crate::protocol_versions_dal::ProtocolVersionsDal; -use crate::protocol_versions_web3_dal::ProtocolVersionsWeb3Dal; -use crate::prover_dal::ProverDal; -use crate::storage_dal::StorageDal; -use crate::storage_logs_dal::StorageLogsDal; -use crate::storage_logs_dedup_dal::StorageLogsDedupDal; -use crate::storage_web3_dal::StorageWeb3Dal; -use crate::sync_dal::SyncDal; -use crate::system_dal::SystemDal; -use crate::tokens_dal::TokensDal; -use crate::tokens_web3_dal::TokensWeb3Dal; -use crate::transactions_dal::TransactionsDal; -use crate::transactions_web3_dal::TransactionsWeb3Dal; -use crate::witness_generator_dal::WitnessGeneratorDal; +use crate::{ + accounts_dal::AccountsDal, basic_witness_input_producer_dal::BasicWitnessInputProducerDal, + blocks_dal::BlocksDal, blocks_web3_dal::BlocksWeb3Dal, connection::holder::ConnectionHolder, + contract_verification_dal::ContractVerificationDal, eth_sender_dal::EthSenderDal, + events_dal::EventsDal, events_web3_dal::EventsWeb3Dal, + fri_gpu_prover_queue_dal::FriGpuProverQueueDal, + fri_proof_compressor_dal::FriProofCompressorDal, + fri_protocol_versions_dal::FriProtocolVersionsDal, fri_prover_dal::FriProverDal, + fri_scheduler_dependency_tracker_dal::FriSchedulerDependencyTrackerDal, + fri_witness_generator_dal::FriWitnessGeneratorDal, gpu_prover_queue_dal::GpuProverQueueDal, + proof_generation_dal::ProofGenerationDal, protocol_versions_dal::ProtocolVersionsDal, + protocol_versions_web3_dal::ProtocolVersionsWeb3Dal, prover_dal::ProverDal, + storage_dal::StorageDal, storage_logs_dal::StorageLogsDal, + storage_logs_dedup_dal::StorageLogsDedupDal, storage_web3_dal::StorageWeb3Dal, + sync_dal::SyncDal, system_dal::SystemDal, tokens_dal::TokensDal, + tokens_web3_dal::TokensWeb3Dal, transactions_dal::TransactionsDal, + transactions_web3_dal::TransactionsWeb3Dal, witness_generator_dal::WitnessGeneratorDal, +}; #[macro_use] mod macro_utils; diff --git a/core/lib/dal/src/metrics.rs b/core/lib/dal/src/metrics.rs index 58e733acc90..4840d073f57 100644 --- a/core/lib/dal/src/metrics.rs +++ b/core/lib/dal/src/metrics.rs @@ -1,12 +1,12 @@ //! Metrics for the data access layer. +use std::{thread, time::Duration}; + use vise::{ Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Histogram, LabeledFamily, LatencyObserver, Metrics, }; -use std::{thread, time::Duration}; - /// Request-related DB metrics. #[derive(Debug, Metrics)] #[metrics(prefix = "sql")] diff --git a/core/lib/dal/src/models/storage_block.rs b/core/lib/dal/src/models/storage_block.rs index 390bd3b2fd8..5d3eeba2a68 100644 --- a/core/lib/dal/src/models/storage_block.rs +++ b/core/lib/dal/src/models/storage_block.rs @@ -7,7 +7,6 @@ use sqlx::{ types::chrono::{DateTime, NaiveDateTime, Utc}, }; use thiserror::Error; - use zksync_contracts::BaseSystemContractsHashes; use zksync_types::{ api, diff --git a/core/lib/dal/src/models/storage_eth_tx.rs b/core/lib/dal/src/models/storage_eth_tx.rs index ed5a732ff79..9026be8326d 100644 --- a/core/lib/dal/src/models/storage_eth_tx.rs +++ b/core/lib/dal/src/models/storage_eth_tx.rs @@ -1,8 +1,11 @@ -use sqlx::types::chrono::NaiveDateTime; use std::str::FromStr; -use zksync_types::aggregated_operations::AggregatedActionType; -use zksync_types::eth_sender::{EthTx, TxHistory, TxHistoryToSend}; -use zksync_types::{Address, L1BatchNumber, Nonce, H256}; + +use sqlx::types::chrono::NaiveDateTime; +use zksync_types::{ + aggregated_operations::AggregatedActionType, + eth_sender::{EthTx, TxHistory, TxHistoryToSend}, + Address, L1BatchNumber, Nonce, H256, +}; #[derive(Debug, Clone)] pub struct StorageEthTx { diff --git a/core/lib/dal/src/models/storage_protocol_version.rs b/core/lib/dal/src/models/storage_protocol_version.rs index 93010f1b814..6eb6e94b003 100644 --- a/core/lib/dal/src/models/storage_protocol_version.rs +++ b/core/lib/dal/src/models/storage_protocol_version.rs @@ -1,4 +1,6 @@ use std::convert::TryInto; + +use sqlx::types::chrono::NaiveDateTime; use zksync_contracts::BaseSystemContractsHashes; use zksync_types::{ api, @@ -6,8 +8,6 @@ use zksync_types::{ Address, H256, }; -use sqlx::types::chrono::NaiveDateTime; - #[derive(sqlx::FromRow)] pub struct StorageProtocolVersion { pub id: i32, diff --git a/core/lib/dal/src/models/storage_prover_job_info.rs b/core/lib/dal/src/models/storage_prover_job_info.rs index facec83e0c2..3242953b39d 100644 --- a/core/lib/dal/src/models/storage_prover_job_info.rs +++ b/core/lib/dal/src/models/storage_prover_job_info.rs @@ -1,14 +1,11 @@ -use core::panic; -use sqlx::types::chrono::{DateTime, NaiveDateTime, NaiveTime, Utc}; -use std::convert::TryFrom; -use std::str::FromStr; +use std::{convert::TryFrom, panic, str::FromStr}; -use zksync_types::proofs::{ - JobPosition, ProverJobStatus, ProverJobStatusFailed, ProverJobStatusInProgress, - ProverJobStatusSuccessful, -}; +use sqlx::types::chrono::{DateTime, NaiveDateTime, NaiveTime, Utc}; use zksync_types::{ - proofs::{AggregationRound, ProverJobInfo}, + proofs::{ + AggregationRound, JobPosition, ProverJobInfo, ProverJobStatus, ProverJobStatusFailed, + ProverJobStatusInProgress, ProverJobStatusSuccessful, + }, L1BatchNumber, }; diff --git a/core/lib/dal/src/models/storage_sync.rs b/core/lib/dal/src/models/storage_sync.rs index 3415cb9b264..dc15250671b 100644 --- a/core/lib/dal/src/models/storage_sync.rs +++ b/core/lib/dal/src/models/storage_sync.rs @@ -2,8 +2,7 @@ use anyhow::Context as _; use zksync_consensus_roles::validator; use zksync_contracts::BaseSystemContractsHashes; use zksync_protobuf::{read_required, ProtoFmt}; -use zksync_types::api::en; -use zksync_types::{Address, L1BatchNumber, MiniblockNumber, Transaction, H160, H256}; +use zksync_types::{api::en, Address, L1BatchNumber, MiniblockNumber, Transaction, H160, H256}; #[derive(Debug, Clone, sqlx::FromRow)] pub struct StorageSyncBlock { @@ -133,10 +132,11 @@ impl ProtoFmt for ConsensusBlockFields { #[cfg(test)] mod tests { - use super::ConsensusBlockFields; use rand::Rng; use zksync_consensus_roles::validator; + use super::ConsensusBlockFields; + #[tokio::test] async fn encode_decode() { let rng = &mut rand::thread_rng(); diff --git a/core/lib/dal/src/models/storage_token.rs b/core/lib/dal/src/models/storage_token.rs index 1cc42405fe2..3acd7e03bc9 100644 --- a/core/lib/dal/src/models/storage_token.rs +++ b/core/lib/dal/src/models/storage_token.rs @@ -2,7 +2,6 @@ use sqlx::types::{ chrono::{DateTime, NaiveDateTime, Utc}, BigDecimal, }; - use zksync_types::tokens::TokenPrice; use zksync_utils::big_decimal_to_ratio; diff --git a/core/lib/dal/src/models/storage_transaction.rs b/core/lib/dal/src/models/storage_transaction.rs index 40fd5aa692c..8e03590dcc5 100644 --- a/core/lib/dal/src/models/storage_transaction.rs +++ b/core/lib/dal/src/models/storage_transaction.rs @@ -1,29 +1,30 @@ use std::{convert::TryInto, str::FromStr}; -use crate::BigDecimal; use bigdecimal::Zero; - use serde::{Deserialize, Serialize}; -use sqlx::postgres::PgRow; -use sqlx::types::chrono::{DateTime, NaiveDateTime, Utc}; -use sqlx::{Error, FromRow, Row}; - -use zksync_types::l2::TransactionType; -use zksync_types::protocol_version::ProtocolUpgradeTxCommonData; -use zksync_types::transaction_request::PaymasterParams; -use zksync_types::vm_trace::Call; -use zksync_types::web3::types::U64; -use zksync_types::{api, Bytes, ExecuteTransactionCommon}; +use sqlx::{ + postgres::PgRow, + types::chrono::{DateTime, NaiveDateTime, Utc}, + Error, FromRow, Row, +}; use zksync_types::{ + api, api::{TransactionDetails, TransactionStatus}, fee::Fee, l1::{OpProcessingType, PriorityQueueType}, - Address, Execute, L1TxCommonData, L2ChainId, L2TxCommonData, Nonce, PackedEthSignature, - PriorityOpId, Transaction, EIP_1559_TX_TYPE, EIP_2930_TX_TYPE, EIP_712_TX_TYPE, H160, H256, - PRIORITY_OPERATION_L2_TX_TYPE, PROTOCOL_UPGRADE_TX_TYPE, U256, + l2::TransactionType, + protocol_version::ProtocolUpgradeTxCommonData, + transaction_request::PaymasterParams, + vm_trace::Call, + web3::types::U64, + Address, Bytes, Execute, ExecuteTransactionCommon, L1TxCommonData, L2ChainId, L2TxCommonData, + Nonce, PackedEthSignature, PriorityOpId, Transaction, EIP_1559_TX_TYPE, EIP_2930_TX_TYPE, + EIP_712_TX_TYPE, H160, H256, PRIORITY_OPERATION_L2_TX_TYPE, PROTOCOL_UPGRADE_TX_TYPE, U256, }; use zksync_utils::bigdecimal_to_u256; +use crate::BigDecimal; + #[derive(Debug, Clone, sqlx::FromRow)] pub struct StorageTransaction { pub priority_op_id: Option, diff --git a/core/lib/dal/src/models/storage_verification_request.rs b/core/lib/dal/src/models/storage_verification_request.rs index 47e9abd11db..e6c68ca16fd 100644 --- a/core/lib/dal/src/models/storage_verification_request.rs +++ b/core/lib/dal/src/models/storage_verification_request.rs @@ -1,8 +1,10 @@ -use zksync_types::contract_verification_api::{ - CompilerType, CompilerVersions, SourceCodeData, VerificationIncomingRequest, - VerificationRequest, +use zksync_types::{ + contract_verification_api::{ + CompilerType, CompilerVersions, SourceCodeData, VerificationIncomingRequest, + VerificationRequest, + }, + Address, }; -use zksync_types::Address; #[derive(Debug, Clone, sqlx::FromRow)] pub struct StorageVerificationRequest { diff --git a/core/lib/dal/src/models/storage_witness_job_info.rs b/core/lib/dal/src/models/storage_witness_job_info.rs index 1aa41032cfa..486b9f89681 100644 --- a/core/lib/dal/src/models/storage_witness_job_info.rs +++ b/core/lib/dal/src/models/storage_witness_job_info.rs @@ -1,11 +1,13 @@ +use std::{convert::TryFrom, str::FromStr}; + use sqlx::types::chrono::{DateTime, NaiveDateTime, NaiveTime, Utc}; -use std::convert::TryFrom; -use std::str::FromStr; -use zksync_types::proofs::{ - AggregationRound, JobPosition, WitnessJobInfo, WitnessJobStatus, WitnessJobStatusFailed, - WitnessJobStatusSuccessful, +use zksync_types::{ + proofs::{ + AggregationRound, JobPosition, WitnessJobInfo, WitnessJobStatus, WitnessJobStatusFailed, + WitnessJobStatusSuccessful, + }, + L1BatchNumber, }; -use zksync_types::L1BatchNumber; #[derive(sqlx::FromRow)] pub struct StorageWitnessJobInfo { diff --git a/core/lib/dal/src/proof_generation_dal.rs b/core/lib/dal/src/proof_generation_dal.rs index 22db4463469..684a3b08acb 100644 --- a/core/lib/dal/src/proof_generation_dal.rs +++ b/core/lib/dal/src/proof_generation_dal.rs @@ -1,10 +1,9 @@ use std::time::Duration; +use strum::{Display, EnumString}; use zksync_types::L1BatchNumber; -use crate::time_utils::pg_interval_from_duration; -use crate::{SqlxError, StorageProcessor}; -use strum::{Display, EnumString}; +use crate::{time_utils::pg_interval_from_duration, SqlxError, StorageProcessor}; #[derive(Debug)] pub struct ProofGenerationDal<'a, 'c> { diff --git a/core/lib/dal/src/protocol_versions_dal.rs b/core/lib/dal/src/protocol_versions_dal.rs index dde7574d390..6f62f3fb01b 100644 --- a/core/lib/dal/src/protocol_versions_dal.rs +++ b/core/lib/dal/src/protocol_versions_dal.rs @@ -1,14 +1,15 @@ use std::convert::{TryFrom, TryInto}; + use zksync_contracts::{BaseSystemContracts, BaseSystemContractsHashes}; use zksync_types::{ protocol_version::{L1VerifierConfig, ProtocolUpgradeTx, ProtocolVersion, VerifierParams}, Address, ProtocolVersionId, H256, }; -use crate::models::storage_protocol_version::{ - protocol_version_from_storage, StorageProtocolVersion, +use crate::{ + models::storage_protocol_version::{protocol_version_from_storage, StorageProtocolVersion}, + StorageProcessor, }; -use crate::StorageProcessor; #[derive(Debug)] pub struct ProtocolVersionsDal<'a, 'c> { diff --git a/core/lib/dal/src/protocol_versions_web3_dal.rs b/core/lib/dal/src/protocol_versions_web3_dal.rs index dc43dadbd22..2819d94f8d8 100644 --- a/core/lib/dal/src/protocol_versions_web3_dal.rs +++ b/core/lib/dal/src/protocol_versions_web3_dal.rs @@ -1,7 +1,6 @@ use zksync_types::api::ProtocolVersion; -use crate::models::storage_protocol_version::StorageProtocolVersion; -use crate::StorageProcessor; +use crate::{models::storage_protocol_version::StorageProtocolVersion, StorageProcessor}; #[derive(Debug)] pub struct ProtocolVersionsWeb3Dal<'a, 'c> { diff --git a/core/lib/dal/src/prover_dal.rs b/core/lib/dal/src/prover_dal.rs index d84d0628372..ea6eba5eda0 100644 --- a/core/lib/dal/src/prover_dal.rs +++ b/core/lib/dal/src/prover_dal.rs @@ -1,5 +1,3 @@ -use sqlx::Error; - use std::{ collections::HashMap, convert::{TryFrom, TryInto}, @@ -7,6 +5,7 @@ use std::{ time::Duration, }; +use sqlx::Error; use zksync_types::{ aggregated_operations::L1BatchProofForL1, proofs::{ diff --git a/core/lib/dal/src/storage_dal.rs b/core/lib/dal/src/storage_dal.rs index 8ec6d916493..4512d028488 100644 --- a/core/lib/dal/src/storage_dal.rs +++ b/core/lib/dal/src/storage_dal.rs @@ -1,7 +1,6 @@ -use itertools::Itertools; - use std::collections::{HashMap, HashSet}; +use itertools::Itertools; use zksync_contracts::{BaseSystemContracts, SystemContractCode}; use zksync_types::{MiniblockNumber, StorageKey, StorageLog, StorageValue, H256, U256}; use zksync_utils::{bytes_to_be_words, bytes_to_chunks}; @@ -210,9 +209,10 @@ impl StorageDal<'_, '_> { #[cfg(test)] mod tests { + use zksync_types::{AccountTreeId, Address}; + use super::*; use crate::ConnectionPool; - use zksync_types::{AccountTreeId, Address}; #[tokio::test] async fn applying_storage_logs() { diff --git a/core/lib/dal/src/storage_logs_dal.rs b/core/lib/dal/src/storage_logs_dal.rs index c368e5adc8d..dc23d29af5c 100644 --- a/core/lib/dal/src/storage_logs_dal.rs +++ b/core/lib/dal/src/storage_logs_dal.rs @@ -1,14 +1,13 @@ -use sqlx::types::chrono::Utc; -use sqlx::Row; - use std::{collections::HashMap, time::Instant}; -use crate::{instrument::InstrumentExt, StorageProcessor}; +use sqlx::{types::chrono::Utc, Row}; use zksync_types::{ get_code_key, AccountTreeId, Address, L1BatchNumber, MiniblockNumber, StorageKey, StorageLog, FAILED_CONTRACT_DEPLOYMENT_BYTECODE_HASH, H256, }; +use crate::{instrument::InstrumentExt, StorageProcessor}; + #[derive(Debug)] pub struct StorageLogsDal<'a, 'c> { pub(crate) storage: &'a mut StorageProcessor<'c>, @@ -529,14 +528,15 @@ impl StorageLogsDal<'_, '_> { #[cfg(test)] mod tests { - use super::*; - use crate::{tests::create_miniblock_header, ConnectionPool}; use zksync_contracts::BaseSystemContractsHashes; use zksync_types::{ block::{BlockGasCount, L1BatchHeader}, ProtocolVersion, ProtocolVersionId, }; + use super::*; + use crate::{tests::create_miniblock_header, ConnectionPool}; + async fn insert_miniblock(conn: &mut StorageProcessor<'_>, number: u32, logs: Vec) { let mut header = L1BatchHeader::new( L1BatchNumber(number), diff --git a/core/lib/dal/src/storage_logs_dedup_dal.rs b/core/lib/dal/src/storage_logs_dedup_dal.rs index 8a70ceb50fe..25e0a8f6eef 100644 --- a/core/lib/dal/src/storage_logs_dedup_dal.rs +++ b/core/lib/dal/src/storage_logs_dedup_dal.rs @@ -1,9 +1,11 @@ -use crate::StorageProcessor; -use sqlx::types::chrono::Utc; use std::collections::HashSet; + +use sqlx::types::chrono::Utc; use zksync_types::{AccountTreeId, Address, L1BatchNumber, LogQuery, StorageKey, H256}; use zksync_utils::u256_to_h256; +use crate::StorageProcessor; + #[derive(Debug)] pub struct StorageLogsDedupDal<'a, 'c> { pub(crate) storage: &'a mut StorageProcessor<'c>, diff --git a/core/lib/dal/src/tests/mod.rs b/core/lib/dal/src/tests/mod.rs index c383ea7f944..94fb6e9ebf6 100644 --- a/core/lib/dal/src/tests/mod.rs +++ b/core/lib/dal/src/tests/mod.rs @@ -1,5 +1,4 @@ -use std::fs; -use std::time::Duration; +use std::{fs, time::Duration}; use zksync_contracts::BaseSystemContractsHashes; use zksync_types::{ @@ -14,14 +13,15 @@ use zksync_types::{ PriorityOpId, ProtocolVersion, ProtocolVersionId, H160, H256, MAX_GAS_PER_PUBDATA_BYTE, U256, }; -use crate::blocks_dal::BlocksDal; -use crate::connection::ConnectionPool; -use crate::protocol_versions_dal::ProtocolVersionsDal; -use crate::prover_dal::{GetProverJobsParams, ProverDal}; -use crate::transactions_dal::L2TxSubmissionResult; -use crate::transactions_dal::TransactionsDal; -use crate::transactions_web3_dal::TransactionsWeb3Dal; -use crate::witness_generator_dal::WitnessGeneratorDal; +use crate::{ + blocks_dal::BlocksDal, + connection::ConnectionPool, + protocol_versions_dal::ProtocolVersionsDal, + prover_dal::{GetProverJobsParams, ProverDal}, + transactions_dal::{L2TxSubmissionResult, TransactionsDal}, + transactions_web3_dal::TransactionsWeb3Dal, + witness_generator_dal::WitnessGeneratorDal, +}; const DEFAULT_GAS_PER_PUBDATA: u32 = 100; diff --git a/core/lib/dal/src/time_utils.rs b/core/lib/dal/src/time_utils.rs index 45ff661a319..0ede5e6fc57 100644 --- a/core/lib/dal/src/time_utils.rs +++ b/core/lib/dal/src/time_utils.rs @@ -1,7 +1,7 @@ -use sqlx::postgres::types::PgInterval; -use sqlx::types::chrono::NaiveTime; use std::time::Duration; +use sqlx::{postgres::types::PgInterval, types::chrono::NaiveTime}; + pub fn duration_to_naive_time(duration: Duration) -> NaiveTime { let total_seconds = duration.as_secs() as u32; NaiveTime::from_hms_opt( diff --git a/core/lib/dal/src/tokens_dal.rs b/core/lib/dal/src/tokens_dal.rs index f7b64aed69e..5c0f306cc05 100644 --- a/core/lib/dal/src/tokens_dal.rs +++ b/core/lib/dal/src/tokens_dal.rs @@ -1,4 +1,3 @@ -use crate::StorageProcessor; use num::{rational::Ratio, BigUint}; use sqlx::types::chrono::Utc; use zksync_types::{ @@ -8,6 +7,8 @@ use zksync_types::{ }; use zksync_utils::ratio_to_big_decimal; +use crate::StorageProcessor; + // Precision of the USD price per token pub(crate) const STORED_USD_PRICE_PRECISION: usize = 6; diff --git a/core/lib/dal/src/tokens_web3_dal.rs b/core/lib/dal/src/tokens_web3_dal.rs index aa3674b6c3d..753f57c85c6 100644 --- a/core/lib/dal/src/tokens_web3_dal.rs +++ b/core/lib/dal/src/tokens_web3_dal.rs @@ -1,11 +1,10 @@ -use crate::models::storage_token::StorageTokenPrice; -use crate::SqlxError; -use crate::StorageProcessor; use zksync_types::{ tokens::{TokenInfo, TokenMetadata, TokenPrice}, Address, }; +use crate::{models::storage_token::StorageTokenPrice, SqlxError, StorageProcessor}; + #[derive(Debug)] pub struct TokensWeb3Dal<'a, 'c> { pub(crate) storage: &'a mut StorageProcessor<'c>, diff --git a/core/lib/dal/src/transactions_dal.rs b/core/lib/dal/src/transactions_dal.rs index cbca986b16c..78da3e0fc04 100644 --- a/core/lib/dal/src/transactions_dal.rs +++ b/core/lib/dal/src/transactions_dal.rs @@ -1,10 +1,9 @@ +use std::{collections::HashMap, fmt, time::Duration}; + +use anyhow::Context; use bigdecimal::BigDecimal; use itertools::Itertools; use sqlx::{error, types::chrono::NaiveDateTime}; - -use anyhow::Context; -use std::{collections::HashMap, fmt, time::Duration}; - use zksync_types::{ block::MiniblockExecutionData, fee::TransactionExecutionMetrics, diff --git a/core/lib/dal/src/transactions_web3_dal.rs b/core/lib/dal/src/transactions_web3_dal.rs index 5e2342d05b7..d87ddc9a517 100644 --- a/core/lib/dal/src/transactions_web3_dal.rs +++ b/core/lib/dal/src/transactions_web3_dal.rs @@ -1,20 +1,22 @@ use sqlx::types::chrono::NaiveDateTime; - use zksync_types::{ api, Address, L2ChainId, MiniblockNumber, Transaction, ACCOUNT_CODE_STORAGE_ADDRESS, FAILED_CONTRACT_DEPLOYMENT_BYTECODE_HASH, H160, H256, U256, U64, }; use zksync_utils::{bigdecimal_to_u256, h256_to_account_address}; -use crate::models::{ - storage_block::{bind_block_where_sql_params, web3_block_where_sql}, - storage_event::StorageWeb3Log, - storage_transaction::{ - extract_web3_transaction, web3_transaction_select_sql, StorageTransaction, - StorageTransactionDetails, +use crate::{ + instrument::InstrumentExt, + models::{ + storage_block::{bind_block_where_sql_params, web3_block_where_sql}, + storage_event::StorageWeb3Log, + storage_transaction::{ + extract_web3_transaction, web3_transaction_select_sql, StorageTransaction, + StorageTransactionDetails, + }, }, + SqlxError, StorageProcessor, }; -use crate::{instrument::InstrumentExt, SqlxError, StorageProcessor}; #[derive(Debug)] pub struct TransactionsWeb3Dal<'a, 'c> { diff --git a/core/lib/dal/src/witness_generator_dal.rs b/core/lib/dal/src/witness_generator_dal.rs index a8079a9dcce..b437c2ad34f 100644 --- a/core/lib/dal/src/witness_generator_dal.rs +++ b/core/lib/dal/src/witness_generator_dal.rs @@ -1,17 +1,16 @@ -use itertools::Itertools; -use sqlx::Row; - use std::{collections::HashMap, ops::Range, time::Duration}; -use zksync_types::proofs::{ - AggregationRound, JobCountStatistics, WitnessGeneratorJobMetadata, WitnessJobInfo, +use itertools::Itertools; +use sqlx::Row; +use zksync_types::{ + proofs::{AggregationRound, JobCountStatistics, WitnessGeneratorJobMetadata, WitnessJobInfo}, + zkevm_test_harness::{ + abstract_zksync_circuit::concrete_circuits::{ZkSyncCircuit, ZkSyncProof}, + bellman::{bn256::Bn256, plonk::better_better_cs::proof::Proof}, + witness::oracle::VmWitnessOracle, + }, + L1BatchNumber, ProtocolVersionId, }; -use zksync_types::zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit; -use zksync_types::zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncProof; -use zksync_types::zkevm_test_harness::bellman::bn256::Bn256; -use zksync_types::zkevm_test_harness::bellman::plonk::better_better_cs::proof::Proof; -use zksync_types::zkevm_test_harness::witness::oracle::VmWitnessOracle; -use zksync_types::{L1BatchNumber, ProtocolVersionId}; use crate::{ instrument::InstrumentExt, diff --git a/core/lib/env_config/src/alerts.rs b/core/lib/env_config/src/alerts.rs index c72b23bbd9f..63cbde48bdf 100644 --- a/core/lib/env_config/src/alerts.rs +++ b/core/lib/env_config/src/alerts.rs @@ -1,6 +1,7 @@ -use crate::{envy_load, FromEnv}; use zksync_config::configs::AlertsConfig; +use crate::{envy_load, FromEnv}; + impl FromEnv for AlertsConfig { fn from_env() -> anyhow::Result { envy_load("sporadic_crypto_errors_substrs", "ALERTS_") diff --git a/core/lib/env_config/src/api.rs b/core/lib/env_config/src/api.rs index 20ecfe41e21..d256e27ceca 100644 --- a/core/lib/env_config/src/api.rs +++ b/core/lib/env_config/src/api.rs @@ -1,6 +1,4 @@ use anyhow::Context as _; - -use crate::{envy_load, FromEnv}; use zksync_config::configs::{ api::{ ContractVerificationApiConfig, HealthCheckConfig, MerkleTreeApiConfig, Web3JsonRpcConfig, @@ -8,6 +6,8 @@ use zksync_config::configs::{ ApiConfig, PrometheusConfig, }; +use crate::{envy_load, FromEnv}; + impl FromEnv for ApiConfig { fn from_env() -> anyhow::Result { Ok(Self { diff --git a/core/lib/env_config/src/chain.rs b/core/lib/env_config/src/chain.rs index e64ba3c36b8..7c2aa7e5941 100644 --- a/core/lib/env_config/src/chain.rs +++ b/core/lib/env_config/src/chain.rs @@ -1,10 +1,11 @@ -use crate::{envy_load, FromEnv}; use anyhow::Context as _; use zksync_config::configs::chain::{ ChainConfig, CircuitBreakerConfig, MempoolConfig, NetworkConfig, OperationsManagerConfig, StateKeeperConfig, }; +use crate::{envy_load, FromEnv}; + impl FromEnv for ChainConfig { fn from_env() -> anyhow::Result { Ok(Self { diff --git a/core/lib/env_config/src/contracts.rs b/core/lib/env_config/src/contracts.rs index 8c58483db06..537b68414c6 100644 --- a/core/lib/env_config/src/contracts.rs +++ b/core/lib/env_config/src/contracts.rs @@ -10,9 +10,10 @@ impl FromEnv for ContractsConfig { #[cfg(test)] mod tests { + use zksync_config::configs::contracts::ProverAtGenesis; + use super::*; use crate::test_utils::{addr, hash, EnvMutex}; - use zksync_config::configs::contracts::ProverAtGenesis; static MUTEX: EnvMutex = EnvMutex::new(); diff --git a/core/lib/env_config/src/database.rs b/core/lib/env_config/src/database.rs index 939725d6773..e350c487662 100644 --- a/core/lib/env_config/src/database.rs +++ b/core/lib/env_config/src/database.rs @@ -1,5 +1,6 @@ -use anyhow::Context as _; use std::env; + +use anyhow::Context as _; use zksync_config::{DBConfig, PostgresConfig}; use crate::{envy_load, FromEnv}; diff --git a/core/lib/env_config/src/fri_proof_compressor.rs b/core/lib/env_config/src/fri_proof_compressor.rs index 2594433025e..777bdb03c58 100644 --- a/core/lib/env_config/src/fri_proof_compressor.rs +++ b/core/lib/env_config/src/fri_proof_compressor.rs @@ -10,9 +10,8 @@ impl FromEnv for FriProofCompressorConfig { #[cfg(test)] mod tests { - use crate::test_utils::EnvMutex; - use super::*; + use crate::test_utils::EnvMutex; static MUTEX: EnvMutex = EnvMutex::new(); diff --git a/core/lib/env_config/src/test_utils.rs b/core/lib/env_config/src/test_utils.rs index 013d12493ae..2909071df39 100644 --- a/core/lib/env_config/src/test_utils.rs +++ b/core/lib/env_config/src/test_utils.rs @@ -1,4 +1,3 @@ -// Built-in uses. use std::{ collections::HashMap, env, @@ -6,7 +5,7 @@ use std::{ mem, sync::{Mutex, MutexGuard, PoisonError}, }; -// Workspace uses + use zksync_basic_types::{Address, H256}; /// Mutex that allows to modify certain env variables and roll them back to initial values when diff --git a/core/lib/env_config/src/utils.rs b/core/lib/env_config/src/utils.rs index 655d3b2e6d5..211e73ae2b1 100644 --- a/core/lib/env_config/src/utils.rs +++ b/core/lib/env_config/src/utils.rs @@ -1,6 +1,7 @@ -use crate::{envy_load, FromEnv}; use zksync_config::configs::PrometheusConfig; +use crate::{envy_load, FromEnv}; + impl FromEnv for PrometheusConfig { fn from_env() -> anyhow::Result { envy_load("prometheus", "API_PROMETHEUS_") diff --git a/core/lib/eth_client/src/clients/http/mod.rs b/core/lib/eth_client/src/clients/http/mod.rs index 5d94a383171..e3295ee4b76 100644 --- a/core/lib/eth_client/src/clients/http/mod.rs +++ b/core/lib/eth_client/src/clients/http/mod.rs @@ -1,17 +1,17 @@ +use std::time::Duration; + use vise::{ Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Histogram, LabeledFamily, Metrics, }; -use std::time::Duration; - -mod query; -mod signing; - pub use self::{ query::QueryClient, signing::{PKSigningClient, SigningClient}, }; +mod query; +mod signing; + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "method", rename_all = "snake_case")] enum Method { diff --git a/core/lib/eth_client/src/clients/http/query.rs b/core/lib/eth_client/src/clients/http/query.rs index 0094c76f88a..3e88944ca0e 100644 --- a/core/lib/eth_client/src/clients/http/query.rs +++ b/core/lib/eth_client/src/clients/http/query.rs @@ -1,12 +1,6 @@ -use async_trait::async_trait; - use std::sync::Arc; -use crate::{ - clients::http::{Method, COUNTERS, LATENCIES}, - types::{Error, ExecutedTxStatus, FailureInfo}, - EthInterface, -}; +use async_trait::async_trait; use zksync_types::web3::{ self, contract::{ @@ -22,6 +16,12 @@ use zksync_types::web3::{ Web3, }; +use crate::{ + clients::http::{Method, COUNTERS, LATENCIES}, + types::{Error, ExecutedTxStatus, FailureInfo}, + EthInterface, +}; + /// An "anonymous" Ethereum client that can invoke read-only methods that aren't /// tied to a particular account. #[derive(Debug, Clone)] diff --git a/core/lib/eth_client/src/clients/http/signing.rs b/core/lib/eth_client/src/clients/http/signing.rs index a0a6647db5f..8b56dc1cfbd 100644 --- a/core/lib/eth_client/src/clients/http/signing.rs +++ b/core/lib/eth_client/src/clients/http/signing.rs @@ -1,24 +1,25 @@ -use async_trait::async_trait; - use std::{fmt, sync::Arc}; +use async_trait::async_trait; use zksync_config::{ContractsConfig, ETHClientConfig, ETHSenderConfig}; use zksync_contracts::zksync_contract; use zksync_eth_signer::{raw_ethereum_tx::TransactionParameters, EthereumSigner, PrivateKeySigner}; -use zksync_types::web3::{ - self, - contract::{ - tokens::{Detokenize, Tokenize}, - Options, - }, - ethabi, - transports::Http, - types::{ - Address, Block, BlockId, BlockNumber, Filter, Log, Transaction, TransactionReceipt, H160, - H256, U256, U64, +use zksync_types::{ + web3::{ + self, + contract::{ + tokens::{Detokenize, Tokenize}, + Options, + }, + ethabi, + transports::Http, + types::{ + Address, Block, BlockId, BlockNumber, Filter, Log, Transaction, TransactionReceipt, + H160, H256, U256, U64, + }, }, + L1ChainId, PackedEthSignature, EIP_1559_TX_TYPE, }; -use zksync_types::{L1ChainId, PackedEthSignature, EIP_1559_TX_TYPE}; use super::{query::QueryClient, Method, LATENCIES}; use crate::{ diff --git a/core/lib/eth_client/src/clients/mock.rs b/core/lib/eth_client/src/clients/mock.rs index 576fbac21a7..a8eceac75af 100644 --- a/core/lib/eth_client/src/clients/mock.rs +++ b/core/lib/eth_client/src/clients/mock.rs @@ -1,9 +1,13 @@ -use std::sync::atomic::{AtomicU64, Ordering}; +use std::{ + collections::{BTreeMap, HashMap}, + sync::{ + atomic::{AtomicU64, Ordering}, + RwLock, + }, +}; use async_trait::async_trait; use jsonrpc_core::types::error::Error as RpcError; -use std::collections::{BTreeMap, HashMap}; -use std::sync::RwLock; use zksync_types::{ web3::{ contract::{ @@ -92,8 +96,7 @@ impl MockEthereum { /// A fake `sha256` hasher, which calculates an `std::hash` instead. /// This is done for simplicity and it's also much faster. pub fn fake_sha256(data: &[u8]) -> H256 { - use std::collections::hash_map::DefaultHasher; - use std::hash::Hasher; + use std::{collections::hash_map::DefaultHasher, hash::Hasher}; let mut hasher = DefaultHasher::new(); hasher.write(data); diff --git a/core/lib/eth_client/src/lib.rs b/core/lib/eth_client/src/lib.rs index f61814893bb..5bb40f60a08 100644 --- a/core/lib/eth_client/src/lib.rs +++ b/core/lib/eth_client/src/lib.rs @@ -1,9 +1,5 @@ #![allow(clippy::upper_case_acronyms, clippy::derive_partial_eq_without_eq)] -pub mod clients; -pub mod types; - -use crate::types::{Error, ExecutedTxStatus, FailureInfo, SignedCallResult}; use async_trait::async_trait; use zksync_types::{ web3::{ @@ -20,6 +16,11 @@ use zksync_types::{ L1ChainId, }; +use crate::types::{Error, ExecutedTxStatus, FailureInfo, SignedCallResult}; + +pub mod clients; +pub mod types; + /// Common Web3 interface, as seen by the core applications. /// Encapsulates the raw Web3 interaction, providing a high-level interface. /// diff --git a/core/lib/eth_signer/src/json_rpc_signer.rs b/core/lib/eth_signer/src/json_rpc_signer.rs index b6619f5e831..66a7b33e989 100644 --- a/core/lib/eth_signer/src/json_rpc_signer.rs +++ b/core/lib/eth_signer/src/json_rpc_signer.rs @@ -1,13 +1,15 @@ -use crate::error::{RpcSignerError, SignerError}; -use crate::json_rpc_signer::messages::JsonRpcRequest; -use crate::raw_ethereum_tx::TransactionParameters; -use crate::EthereumSigner; - use jsonrpc_core::types::response::Output; -use zksync_types::tx::primitives::PackedEthSignature; -use zksync_types::{Address, EIP712TypedStructure, Eip712Domain, H256}; - use serde_json::Value; +use zksync_types::{ + tx::primitives::PackedEthSignature, Address, EIP712TypedStructure, Eip712Domain, H256, +}; + +use crate::{ + error::{RpcSignerError, SignerError}, + json_rpc_signer::messages::JsonRpcRequest, + raw_ethereum_tx::TransactionParameters, + EthereumSigner, +}; pub fn is_signature_from_address( signature: &PackedEthSignature, @@ -325,13 +327,14 @@ impl JsonRpcSigner { } mod messages { - use crate::raw_ethereum_tx::TransactionParameters; use hex::encode; use serde::{Deserialize, Serialize}; use zksync_types::{ eip712_signature::utils::get_eip712_json, Address, EIP712TypedStructure, Eip712Domain, }; + use crate::raw_ethereum_tx::TransactionParameters; + #[derive(Debug, Serialize, Deserialize)] pub struct JsonRpcRequest { pub id: String, @@ -429,7 +432,6 @@ mod messages { #[cfg(test)] mod tests { - use crate::raw_ethereum_tx::TransactionParameters; use actix_web::{ post, web::{self, Data}, @@ -439,11 +441,10 @@ mod tests { use jsonrpc_core::{Failure, Id, Output, Success, Version}; use parity_crypto::publickey::{Generator, KeyPair, Random}; use serde_json::json; - use zksync_types::{tx::primitives::PackedEthSignature, Address}; use super::{is_signature_from_address, messages::JsonRpcRequest}; - use crate::{EthereumSigner, JsonRpcSigner}; + use crate::{raw_ethereum_tx::TransactionParameters, EthereumSigner, JsonRpcSigner}; #[post("/")] async fn index(req: web::Json, state: web::Data) -> impl Responder { diff --git a/core/lib/eth_signer/src/lib.rs b/core/lib/eth_signer/src/lib.rs index ce4540c151b..164a124dbc9 100644 --- a/core/lib/eth_signer/src/lib.rs +++ b/core/lib/eth_signer/src/lib.rs @@ -1,11 +1,12 @@ use async_trait::async_trait; use error::SignerError; -use zksync_types::tx::primitives::PackedEthSignature; -use zksync_types::{Address, EIP712TypedStructure, Eip712Domain}; - -pub use crate::raw_ethereum_tx::TransactionParameters; pub use json_rpc_signer::JsonRpcSigner; pub use pk_signer::PrivateKeySigner; +use zksync_types::{ + tx::primitives::PackedEthSignature, Address, EIP712TypedStructure, Eip712Domain, +}; + +pub use crate::raw_ethereum_tx::TransactionParameters; pub mod error; pub mod json_rpc_signer; diff --git a/core/lib/eth_signer/src/pk_signer.rs b/core/lib/eth_signer/src/pk_signer.rs index 680d87d62d0..4f9795dca86 100644 --- a/core/lib/eth_signer/src/pk_signer.rs +++ b/core/lib/eth_signer/src/pk_signer.rs @@ -1,11 +1,11 @@ use secp256k1::SecretKey; - -use zksync_types::tx::primitives::PackedEthSignature; -use zksync_types::{Address, EIP712TypedStructure, Eip712Domain, H256}; +use zksync_types::{ + tx::primitives::PackedEthSignature, Address, EIP712TypedStructure, Eip712Domain, H256, +}; use crate::{ raw_ethereum_tx::{Transaction, TransactionParameters}, - {EthereumSigner, SignerError}, + EthereumSigner, SignerError, }; #[derive(Clone)] @@ -86,11 +86,11 @@ impl EthereumSigner for PrivateKeySigner { #[cfg(test)] mod test { - use super::PrivateKeySigner; - use crate::raw_ethereum_tx::TransactionParameters; - use crate::EthereumSigner; use zksync_types::{H160, H256, U256, U64}; + use super::PrivateKeySigner; + use crate::{raw_ethereum_tx::TransactionParameters, EthereumSigner}; + #[tokio::test] async fn test_generating_signed_raw_transaction() { let private_key = H256::from([5; 32]); diff --git a/core/lib/eth_signer/src/raw_ethereum_tx.rs b/core/lib/eth_signer/src/raw_ethereum_tx.rs index fcee1349445..124c09965de 100644 --- a/core/lib/eth_signer/src/raw_ethereum_tx.rs +++ b/core/lib/eth_signer/src/raw_ethereum_tx.rs @@ -8,12 +8,16 @@ //! We can refactor this code and adapt it for our needs better, but I prefer to reuse as much code as we can. //! In the case where it will be possible to use only the web3 library without copy-paste, the changes will be small and simple //! Link to @Deniallugo's PR to web3: https://github.com/tomusdrw/rust-web3/pull/630 + use rlp::RlpStream; -use zksync_types::web3::{ - signing::{self, Signature}, - types::{AccessList, SignedTransaction}, +use zksync_types::{ + ethabi::Address, + web3::{ + signing::{self, Signature}, + types::{AccessList, SignedTransaction}, + }, + U256, U64, }; -use zksync_types::{ethabi::Address, U256, U64}; const LEGACY_TX_ID: u64 = 0; const ACCESSLISTS_TX_ID: u64 = 1; diff --git a/core/lib/health_check/src/lib.rs b/core/lib/health_check/src/lib.rs index fac8ec46dbb..12bb292bc85 100644 --- a/core/lib/health_check/src/lib.rs +++ b/core/lib/health_check/src/lib.rs @@ -1,11 +1,10 @@ -use futures::{future, FutureExt}; -use serde::Serialize; -use tokio::sync::watch; - use std::{collections::HashMap, thread}; -/// Public re-export for other crates to be able to implement the interface. +// Public re-export for other crates to be able to implement the interface. pub use async_trait::async_trait; +use futures::{future, FutureExt}; +use serde::Serialize; +use tokio::sync::watch; /// Health status returned as a part of `Health`. #[derive(Debug, Clone, Copy, PartialEq, Serialize)] diff --git a/core/lib/mempool/src/mempool_store.rs b/core/lib/mempool/src/mempool_store.rs index a8b02bee0cb..51a8d708a74 100644 --- a/core/lib/mempool/src/mempool_store.rs +++ b/core/lib/mempool/src/mempool_store.rs @@ -1,10 +1,11 @@ use std::collections::{hash_map, BTreeSet, HashMap, HashSet}; -use crate::types::{AccountTransactions, L2TxFilter, MempoolScore}; use zksync_types::{ l1::L1Tx, l2::L2Tx, Address, ExecuteTransactionCommon, Nonce, PriorityOpId, Transaction, }; +use crate::types::{AccountTransactions, L2TxFilter, MempoolScore}; + #[derive(Debug)] pub struct MempoolInfo { pub stashed_accounts: Vec
, diff --git a/core/lib/mempool/src/tests.rs b/core/lib/mempool/src/tests.rs index cb149752e2d..cd595509ec5 100644 --- a/core/lib/mempool/src/tests.rs +++ b/core/lib/mempool/src/tests.rs @@ -1,12 +1,18 @@ +use std::{ + collections::{HashMap, HashSet}, + iter::FromIterator, +}; + +use zksync_types::{ + fee::Fee, + helpers::unix_timestamp_ms, + l1::{OpProcessingType, PriorityQueueType}, + l2::L2Tx, + Address, Execute, ExecuteTransactionCommon, L1TxCommonData, Nonce, PriorityOpId, Transaction, + H256, U256, +}; + use crate::{mempool_store::MempoolStore, types::L2TxFilter}; -use std::collections::{HashMap, HashSet}; -use std::iter::FromIterator; -use zksync_types::fee::Fee; -use zksync_types::helpers::unix_timestamp_ms; -use zksync_types::l1::{OpProcessingType, PriorityQueueType}; -use zksync_types::l2::L2Tx; -use zksync_types::{Address, ExecuteTransactionCommon, L1TxCommonData, PriorityOpId, H256, U256}; -use zksync_types::{Execute, Nonce, Transaction}; #[test] fn basic_flow() { diff --git a/core/lib/mempool/src/types.rs b/core/lib/mempool/src/types.rs index 130f8ad0016..9bc58a4e2ce 100644 --- a/core/lib/mempool/src/types.rs +++ b/core/lib/mempool/src/types.rs @@ -1,8 +1,6 @@ -use std::cmp::Ordering; -use std::collections::HashMap; -use zksync_types::fee::Fee; -use zksync_types::l2::L2Tx; -use zksync_types::{Address, Nonce, Transaction, U256}; +use std::{cmp::Ordering, collections::HashMap}; + +use zksync_types::{fee::Fee, l2::L2Tx, Address, Nonce, Transaction, U256}; /// Pending mempool transactions of account #[derive(Debug)] diff --git a/core/lib/merkle_tree/examples/loadtest/main.rs b/core/lib/merkle_tree/examples/loadtest/main.rs index 527daa87b37..185ae0543f9 100644 --- a/core/lib/merkle_tree/examples/loadtest/main.rs +++ b/core/lib/merkle_tree/examples/loadtest/main.rs @@ -3,16 +3,15 @@ //! Should be compiled with the release profile, otherwise hashing and other ops would be //! prohibitively slow. -use clap::Parser; -use rand::{rngs::StdRng, seq::IteratorRandom, SeedableRng}; -use tempfile::TempDir; -use tracing_subscriber::EnvFilter; - use std::{ thread, time::{Duration, Instant}, }; +use clap::Parser; +use rand::{rngs::StdRng, seq::IteratorRandom, SeedableRng}; +use tempfile::TempDir; +use tracing_subscriber::EnvFilter; use zksync_crypto::hasher::blake2::Blake2Hasher; use zksync_merkle_tree::{ Database, HashTree, MerkleTree, MerkleTreePruner, PatchSet, RocksDBWrapper, TreeEntry, @@ -21,10 +20,10 @@ use zksync_merkle_tree::{ use zksync_storage::{RocksDB, RocksDBOptions}; use zksync_types::{AccountTreeId, Address, StorageKey, H256, U256}; -mod batch; - use crate::batch::WithBatching; +mod batch; + /// CLI for load-testing for the Merkle tree implementation. #[derive(Debug, Parser)] #[command(author, version, about, long_about = None)] diff --git a/core/lib/merkle_tree/examples/recovery.rs b/core/lib/merkle_tree/examples/recovery.rs index 1a2aae236ea..603eb2ec4d7 100644 --- a/core/lib/merkle_tree/examples/recovery.rs +++ b/core/lib/merkle_tree/examples/recovery.rs @@ -1,12 +1,11 @@ //! Tree recovery load test. +use std::time::Instant; + use clap::Parser; use rand::{rngs::StdRng, Rng, SeedableRng}; use tempfile::TempDir; use tracing_subscriber::EnvFilter; - -use std::time::Instant; - use zksync_crypto::hasher::blake2::Blake2Hasher; use zksync_merkle_tree::{ recovery::MerkleTreeRecovery, HashTree, Key, PatchSet, PruneDatabase, RocksDBWrapper, diff --git a/core/lib/merkle_tree/src/consistency.rs b/core/lib/merkle_tree/src/consistency.rs index 2cc8996e64e..659befbe048 100644 --- a/core/lib/merkle_tree/src/consistency.rs +++ b/core/lib/merkle_tree/src/consistency.rs @@ -1,9 +1,9 @@ //! Consistency verification for the Merkle tree. -use rayon::prelude::*; - use std::sync::atomic::{AtomicU64, Ordering}; +use rayon::prelude::*; + use crate::{ errors::DeserializeError, hasher::{HashTree, HasherWithStats}, @@ -267,17 +267,17 @@ impl AtomicBitSet { #[cfg(test)] mod tests { + use std::num::NonZeroU64; + use assert_matches::assert_matches; use rayon::ThreadPoolBuilder; - - use std::num::NonZeroU64; + use zksync_types::{H256, U256}; use super::*; use crate::{ types::{InternalNode, TreeEntry}, PatchSet, }; - use zksync_types::{H256, U256}; const FIRST_KEY: Key = U256([0, 0, 0, 0x_dead_beef_0000_0000]); const SECOND_KEY: Key = U256([0, 0, 0, 0x_dead_beef_0100_0000]); diff --git a/core/lib/merkle_tree/src/domain.rs b/core/lib/merkle_tree/src/domain.rs index 0cd9a56a486..f21a5e09133 100644 --- a/core/lib/merkle_tree/src/domain.rs +++ b/core/lib/merkle_tree/src/domain.rs @@ -1,6 +1,13 @@ //! Tying the Merkle tree implementation to the problem domain. use rayon::{ThreadPool, ThreadPoolBuilder}; +use zksync_crypto::hasher::blake2::Blake2Hasher; +use zksync_storage::RocksDB; +use zksync_types::{ + proofs::{PrepareBasicCircuitsJob, StorageLogMetadata}, + writes::{InitialStorageWrite, RepeatedStorageWrite, StateDiffRecord}, + L1BatchNumber, StorageKey, U256, +}; use zksync_utils::h256_to_u256; use crate::{ @@ -11,13 +18,6 @@ use crate::{ }, BlockOutput, HashTree, MerkleTree, NoVersionError, }; -use zksync_crypto::hasher::blake2::Blake2Hasher; -use zksync_storage::RocksDB; -use zksync_types::{ - proofs::{PrepareBasicCircuitsJob, StorageLogMetadata}, - writes::{InitialStorageWrite, RepeatedStorageWrite, StateDiffRecord}, - L1BatchNumber, StorageKey, U256, -}; /// Metadata for the current tree state. #[derive(Debug, Clone)] diff --git a/core/lib/merkle_tree/src/errors.rs b/core/lib/merkle_tree/src/errors.rs index a30b0b98f5b..4afe8a2367c 100644 --- a/core/lib/merkle_tree/src/errors.rs +++ b/core/lib/merkle_tree/src/errors.rs @@ -166,9 +166,10 @@ impl error::Error for NoVersionError {} #[cfg(test)] mod tests { + use zksync_types::U256; + use super::*; use crate::{types::Nibbles, Key}; - use zksync_types::U256; const TEST_KEY: Key = U256([0, 0, 0, 0x_dead_beef_0000_0000]); diff --git a/core/lib/merkle_tree/src/hasher/mod.rs b/core/lib/merkle_tree/src/hasher/mod.rs index 9425a5836f0..fa700a68244 100644 --- a/core/lib/merkle_tree/src/hasher/mod.rs +++ b/core/lib/merkle_tree/src/hasher/mod.rs @@ -1,11 +1,9 @@ //! Hashing operations on the Merkle tree. -use once_cell::sync::Lazy; - use std::{fmt, iter}; -mod nodes; -mod proofs; +use once_cell::sync::Lazy; +use zksync_crypto::hasher::{blake2::Blake2Hasher, Hasher}; pub(crate) use self::nodes::{InternalNodeCache, MerklePath}; pub use self::proofs::TreeRangeDigest; @@ -13,7 +11,9 @@ use crate::{ metrics::HashingStats, types::{TreeEntry, ValueHash, TREE_DEPTH}, }; -use zksync_crypto::hasher::{blake2::Blake2Hasher, Hasher}; + +mod nodes; +mod proofs; /// Tree hashing functionality. pub trait HashTree: Send + Sync { @@ -222,9 +222,10 @@ impl HasherWithStats<'_> { #[cfg(test)] mod tests { + use zksync_types::{AccountTreeId, Address, StorageKey, H256}; + use super::*; use crate::types::LeafNode; - use zksync_types::{AccountTreeId, Address, StorageKey, H256}; #[test] fn empty_tree_hash_is_as_expected() { diff --git a/core/lib/merkle_tree/src/hasher/nodes.rs b/core/lib/merkle_tree/src/hasher/nodes.rs index d36c58c0ae1..6e1c007bc42 100644 --- a/core/lib/merkle_tree/src/hasher/nodes.rs +++ b/core/lib/merkle_tree/src/hasher/nodes.rs @@ -258,10 +258,11 @@ impl Node { #[cfg(test)] mod tests { - use super::*; use zksync_crypto::hasher::{blake2::Blake2Hasher, Hasher}; use zksync_types::H256; + use super::*; + fn test_internal_node_hashing(child_indexes: &[u8]) { println!("Testing indices: {child_indexes:?}"); diff --git a/core/lib/merkle_tree/src/lib.rs b/core/lib/merkle_tree/src/lib.rs index 85ace50aada..687e957f8ef 100644 --- a/core/lib/merkle_tree/src/lib.rs +++ b/core/lib/merkle_tree/src/lib.rs @@ -46,6 +46,23 @@ clippy::doc_markdown // frequent false positive: RocksDB )] +use zksync_crypto::hasher::blake2::Blake2Hasher; + +pub use crate::{ + errors::NoVersionError, + hasher::{HashTree, TreeRangeDigest}, + pruning::{MerkleTreePruner, MerkleTreePrunerHandle}, + storage::{ + Database, MerkleTreeColumnFamily, PatchSet, Patched, PruneDatabase, PrunePatchSet, + RocksDBWrapper, + }, + types::{ + BlockOutput, BlockOutputWithProofs, Key, TreeEntry, TreeEntryWithProof, TreeInstruction, + TreeLogEntry, TreeLogEntryWithProof, ValueHash, + }, +}; +use crate::{hasher::HasherWithStats, storage::Storage, types::Root}; + mod consistency; pub mod domain; mod errors; @@ -69,23 +86,6 @@ pub mod unstable { }; } -pub use crate::{ - errors::NoVersionError, - hasher::{HashTree, TreeRangeDigest}, - pruning::{MerkleTreePruner, MerkleTreePrunerHandle}, - storage::{ - Database, MerkleTreeColumnFamily, PatchSet, Patched, PruneDatabase, PrunePatchSet, - RocksDBWrapper, - }, - types::{ - BlockOutput, BlockOutputWithProofs, Key, TreeEntry, TreeEntryWithProof, TreeInstruction, - TreeLogEntry, TreeLogEntryWithProof, ValueHash, - }, -}; - -use crate::{hasher::HasherWithStats, storage::Storage, types::Root}; -use zksync_crypto::hasher::blake2::Blake2Hasher; - /// Binary Merkle tree implemented using AR16MT from Diem [Jellyfish Merkle tree] white paper. /// /// A tree is persistent and is backed by a key-value store (the `DB` type param). It is versioned, diff --git a/core/lib/merkle_tree/src/metrics.rs b/core/lib/merkle_tree/src/metrics.rs index 29bd58e599e..ef1e94f9b05 100644 --- a/core/lib/merkle_tree/src/metrics.rs +++ b/core/lib/merkle_tree/src/metrics.rs @@ -6,11 +6,12 @@ use std::{ time::Duration, }; -use crate::types::Nibbles; use vise::{ Buckets, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Global, Histogram, Metrics, Unit, }; +use crate::types::Nibbles; + #[derive(Debug, Metrics)] #[metrics(prefix = "merkle_tree")] pub(crate) struct GeneralMetrics { diff --git a/core/lib/merkle_tree/src/recovery.rs b/core/lib/merkle_tree/src/recovery.rs index d1f2618a5cd..fd1790d2b7c 100644 --- a/core/lib/merkle_tree/src/recovery.rs +++ b/core/lib/merkle_tree/src/recovery.rs @@ -37,13 +37,14 @@ use std::time::Instant; +use zksync_crypto::hasher::blake2::Blake2Hasher; + use crate::{ hasher::{HashTree, HasherWithStats}, storage::{PatchSet, PruneDatabase, PrunePatchSet, Storage}, types::{Key, Manifest, Root, TreeEntry, TreeTags, ValueHash}, MerkleTree, }; -use zksync_crypto::hasher::blake2::Blake2Hasher; /// Handle to a Merkle tree during its recovery. #[derive(Debug)] diff --git a/core/lib/merkle_tree/src/storage/mod.rs b/core/lib/merkle_tree/src/storage/mod.rs index ae273d22f32..d2b89da48cd 100644 --- a/core/lib/merkle_tree/src/storage/mod.rs +++ b/core/lib/merkle_tree/src/storage/mod.rs @@ -1,20 +1,11 @@ //! Storage-related logic. -mod database; -mod patch; -mod proofs; -mod rocksdb; -mod serialization; -#[cfg(test)] -mod tests; - pub(crate) use self::patch::{LoadAncestorsResult, WorkingPatchSet}; pub use self::{ database::{Database, NodeKeys, Patched, PruneDatabase, PrunePatchSet}, patch::PatchSet, rocksdb::{MerkleTreeColumnFamily, RocksDBWrapper}, }; - use crate::{ hasher::HashTree, metrics::{TreeUpdaterStats, BLOCK_TIMINGS, GENERAL_METRICS}, @@ -24,6 +15,14 @@ use crate::{ }, }; +mod database; +mod patch; +mod proofs; +mod rocksdb; +mod serialization; +#[cfg(test)] +mod tests; + /// Tree operation: either inserting a new version or updating an existing one (the latter is only /// used during tree recovery). #[derive(Debug, Clone, Copy)] diff --git a/core/lib/merkle_tree/src/storage/patch.rs b/core/lib/merkle_tree/src/storage/patch.rs index ff41fb2f6bf..f0b06c83bf2 100644 --- a/core/lib/merkle_tree/src/storage/patch.rs +++ b/core/lib/merkle_tree/src/storage/patch.rs @@ -1,13 +1,13 @@ //! Types related to DB patches: `PatchSet` and `WorkingPatchSet`. -use rayon::prelude::*; - use std::{ collections::{hash_map::Entry, HashMap}, iter, time::Instant, }; +use rayon::prelude::*; + use crate::{ hasher::{HashTree, HasherWithStats, MerklePath}, metrics::HashingStats, diff --git a/core/lib/merkle_tree/src/storage/rocksdb.rs b/core/lib/merkle_tree/src/storage/rocksdb.rs index 6c6a3a18105..7dd4d6083d7 100644 --- a/core/lib/merkle_tree/src/storage/rocksdb.rs +++ b/core/lib/merkle_tree/src/storage/rocksdb.rs @@ -1,9 +1,10 @@ //! RocksDB implementation of [`Database`]. -use rayon::prelude::*; - use std::path::Path; +use rayon::prelude::*; +use zksync_storage::{db::NamedColumnFamily, rocksdb::DBPinnableSlice, RocksDB}; + use crate::{ errors::{DeserializeError, ErrorContext}, metrics::ApplyPatchStats, @@ -13,7 +14,6 @@ use crate::{ }, types::{InternalNode, LeafNode, Manifest, Nibbles, Node, NodeKey, Root, StaleNodeKey}, }; -use zksync_storage::{db::NamedColumnFamily, rocksdb::DBPinnableSlice, RocksDB}; /// RocksDB column families used by the tree. #[derive(Debug, Clone, Copy)] @@ -285,10 +285,10 @@ impl PruneDatabase for RocksDBWrapper { #[cfg(test)] mod tests { - use tempfile::TempDir; - use std::collections::{HashMap, HashSet}; + use tempfile::TempDir; + use super::*; use crate::storage::tests::{create_patch, generate_nodes}; diff --git a/core/lib/merkle_tree/src/storage/serialization.rs b/core/lib/merkle_tree/src/storage/serialization.rs index 6a9216fa104..09a06a3630c 100644 --- a/core/lib/merkle_tree/src/storage/serialization.rs +++ b/core/lib/merkle_tree/src/storage/serialization.rs @@ -300,9 +300,10 @@ impl Manifest { #[cfg(test)] mod tests { + use zksync_types::H256; + use super::*; use crate::types::TreeEntry; - use zksync_types::H256; #[test] fn serializing_manifest() { diff --git a/core/lib/merkle_tree/src/storage/tests.rs b/core/lib/merkle_tree/src/storage/tests.rs index e70cb057280..a0c1ae4c949 100644 --- a/core/lib/merkle_tree/src/storage/tests.rs +++ b/core/lib/merkle_tree/src/storage/tests.rs @@ -1,3 +1,5 @@ +use std::collections::{HashMap, HashSet}; + use assert_matches::assert_matches; use rand::{ rngs::StdRng, @@ -5,16 +7,14 @@ use rand::{ Rng, SeedableRng, }; use test_casing::test_casing; - -use std::collections::{HashMap, HashSet}; +use zksync_crypto::hasher::blake2::Blake2Hasher; +use zksync_types::{H256, U256}; use super::*; use crate::{ hasher::{HasherWithStats, MerklePath}, types::{NodeKey, TreeInstruction, KEY_SIZE}, }; -use zksync_crypto::hasher::blake2::Blake2Hasher; -use zksync_types::{H256, U256}; pub(super) const FIRST_KEY: Key = U256([0, 0, 0, 0x_dead_beef_0000_0000]); const SECOND_KEY: Key = U256([0, 0, 0, 0x_dead_beef_0100_0000]); diff --git a/core/lib/merkle_tree/src/types/internal.rs b/core/lib/merkle_tree/src/types/internal.rs index cb35b0281c2..e983928c554 100644 --- a/core/lib/merkle_tree/src/types/internal.rs +++ b/core/lib/merkle_tree/src/types/internal.rs @@ -554,9 +554,10 @@ impl StaleNodeKey { #[cfg(test)] mod tests { - use super::*; use zksync_types::U256; + use super::*; + // `U256` uses little-endian `u64` ordering; i.e., this is // 0x_dead_beef_0000_0000_.._0000. const TEST_KEY: Key = U256([0, 0, 0, 0x_dead_beef_0000_0000]); diff --git a/core/lib/merkle_tree/src/types/mod.rs b/core/lib/merkle_tree/src/types/mod.rs index 15ab72b6911..43a3922da86 100644 --- a/core/lib/merkle_tree/src/types/mod.rs +++ b/core/lib/merkle_tree/src/types/mod.rs @@ -1,13 +1,13 @@ //! Basic storage types. -mod internal; +use zksync_types::{H256, U256}; pub(crate) use self::internal::{ ChildRef, Nibbles, NibblesBytes, StaleNodeKey, TreeTags, HASH_SIZE, KEY_SIZE, TREE_DEPTH, }; pub use self::internal::{InternalNode, LeafNode, Manifest, Node, NodeKey, Root}; -use zksync_types::{H256, U256}; +mod internal; /// Key stored in the tree. pub type Key = U256; diff --git a/core/lib/merkle_tree/tests/integration/common.rs b/core/lib/merkle_tree/tests/integration/common.rs index 096a54ce711..28c3827827a 100644 --- a/core/lib/merkle_tree/tests/integration/common.rs +++ b/core/lib/merkle_tree/tests/integration/common.rs @@ -1,9 +1,8 @@ //! Shared functionality. -use once_cell::sync::Lazy; - use std::collections::HashMap; +use once_cell::sync::Lazy; use zksync_crypto::hasher::{blake2::Blake2Hasher, Hasher}; use zksync_merkle_tree::{HashTree, TreeEntry, TreeInstruction}; use zksync_types::{AccountTreeId, Address, StorageKey, H256, U256}; diff --git a/core/lib/merkle_tree/tests/integration/consistency.rs b/core/lib/merkle_tree/tests/integration/consistency.rs index da3312d2002..b6b424e431a 100644 --- a/core/lib/merkle_tree/tests/integration/consistency.rs +++ b/core/lib/merkle_tree/tests/integration/consistency.rs @@ -3,9 +3,9 @@ use rand::{rngs::StdRng, seq::SliceRandom, Rng, SeedableRng}; use tempfile::TempDir; +use zksync_merkle_tree::{MerkleTree, MerkleTreeColumnFamily, RocksDBWrapper}; use crate::common::generate_key_value_pairs; -use zksync_merkle_tree::{MerkleTree, MerkleTreeColumnFamily, RocksDBWrapper}; // Something (maybe RocksDB) makes the test below work very slowly in the debug mode; // thus, the number of test cases is conditionally reduced. diff --git a/core/lib/merkle_tree/tests/integration/domain.rs b/core/lib/merkle_tree/tests/integration/domain.rs index f3febda5f06..45165067221 100644 --- a/core/lib/merkle_tree/tests/integration/domain.rs +++ b/core/lib/merkle_tree/tests/integration/domain.rs @@ -1,11 +1,10 @@ //! Domain-specific tests. Taken almost verbatim from the previous tree implementation. +use std::slice; + use serde::{Deserialize, Serialize}; use serde_with::{hex::Hex, serde_as}; use tempfile::TempDir; - -use std::slice; - use zksync_crypto::hasher::blake2::Blake2Hasher; use zksync_merkle_tree::{domain::ZkSyncTree, HashTree, TreeEntry, TreeInstruction}; use zksync_storage::RocksDB; diff --git a/core/lib/merkle_tree/tests/integration/merkle_tree.rs b/core/lib/merkle_tree/tests/integration/merkle_tree.rs index e4f052bb03c..117ea0db4d9 100644 --- a/core/lib/merkle_tree/tests/integration/merkle_tree.rs +++ b/core/lib/merkle_tree/tests/integration/merkle_tree.rs @@ -1,10 +1,9 @@ //! Tests not tied to the zksync domain. -use rand::{rngs::StdRng, seq::SliceRandom, Rng, SeedableRng}; -use test_casing::test_casing; - use std::{cmp, mem}; +use rand::{rngs::StdRng, seq::SliceRandom, Rng, SeedableRng}; +use test_casing::test_casing; use zksync_crypto::hasher::blake2::Blake2Hasher; use zksync_merkle_tree::{ Database, HashTree, MerkleTree, PatchSet, Patched, TreeEntry, TreeInstruction, TreeLogEntry, @@ -532,16 +531,16 @@ fn range_proofs_with_random_ranges() { /// RocksDB-specific tests. mod rocksdb { + use std::collections::BTreeMap; + use serde::{Deserialize, Serialize}; use serde_with::{hex::Hex, serde_as}; use tempfile::TempDir; - - use std::collections::BTreeMap; - - use super::*; use zksync_merkle_tree::{MerkleTreeColumnFamily, MerkleTreePruner, RocksDBWrapper}; use zksync_storage::RocksDB; + use super::*; + #[derive(Debug)] struct Harness { db: RocksDBWrapper, diff --git a/core/lib/merkle_tree/tests/integration/recovery.rs b/core/lib/merkle_tree/tests/integration/recovery.rs index 6739e4ffe02..399b214e3fe 100644 --- a/core/lib/merkle_tree/tests/integration/recovery.rs +++ b/core/lib/merkle_tree/tests/integration/recovery.rs @@ -2,7 +2,6 @@ use rand::{rngs::StdRng, seq::SliceRandom, SeedableRng}; use test_casing::test_casing; - use zksync_crypto::hasher::blake2::Blake2Hasher; use zksync_merkle_tree::{ recovery::MerkleTreeRecovery, Database, MerkleTree, PatchSet, PruneDatabase, ValueHash, @@ -125,9 +124,9 @@ fn recovery_in_chunks(kind: RecoveryKind, chunk_size: usize) { mod rocksdb { use tempfile::TempDir; + use zksync_merkle_tree::RocksDBWrapper; use super::*; - use zksync_merkle_tree::RocksDBWrapper; #[test_casing(8, test_casing::Product((RecoveryKind::ALL, [6, 10, 17, 42])))] fn recovery_in_chunks(kind: RecoveryKind, chunk_size: usize) { diff --git a/core/lib/mini_merkle_tree/benches/tree.rs b/core/lib/mini_merkle_tree/benches/tree.rs index a964456bfb4..8ea4128ac34 100644 --- a/core/lib/mini_merkle_tree/benches/tree.rs +++ b/core/lib/mini_merkle_tree/benches/tree.rs @@ -3,7 +3,6 @@ use criterion::{ criterion_group, criterion_main, BatchSize, Bencher, BenchmarkId, Criterion, Throughput, }; - use zksync_mini_merkle_tree::MiniMerkleTree; const TREE_SIZES: &[usize] = &[32, 64, 128, 256, 512, 1_024]; diff --git a/core/lib/mini_merkle_tree/src/lib.rs b/core/lib/mini_merkle_tree/src/lib.rs index a6cbf37213c..168e5d8dd09 100644 --- a/core/lib/mini_merkle_tree/src/lib.rs +++ b/core/lib/mini_merkle_tree/src/lib.rs @@ -5,10 +5,10 @@ #![warn(clippy::all, clippy::pedantic)] #![allow(clippy::must_use_candidate, clippy::similar_names)] -use once_cell::sync::Lazy; - use std::{iter, str::FromStr}; +use once_cell::sync::Lazy; + #[cfg(test)] mod tests; diff --git a/core/lib/multivm/src/glue/tracers/mod.rs b/core/lib/multivm/src/glue/tracers/mod.rs index a504d5d2c8f..c58e717a646 100644 --- a/core/lib/multivm/src/glue/tracers/mod.rs +++ b/core/lib/multivm/src/glue/tracers/mod.rs @@ -29,10 +29,11 @@ //! - Add this trait as a trait bound to the `MultiVMTracer`. //! - Add this trait as a trait bound for `T` in `MultiVMTracer` implementation. //! - Implement the trait for `T` with a bound to `VmTracer` for a specific version. -//! -use crate::HistoryMode; + use zksync_state::WriteStorage; +use crate::HistoryMode; + pub type MultiVmTracerPointer = Box>; pub trait MultiVMTracer: diff --git a/core/lib/multivm/src/glue/types/vm/block_context_mode.rs b/core/lib/multivm/src/glue/types/vm/block_context_mode.rs index eba3c503e06..0cbbcbf33e3 100644 --- a/core/lib/multivm/src/glue/types/vm/block_context_mode.rs +++ b/core/lib/multivm/src/glue/types/vm/block_context_mode.rs @@ -1,6 +1,7 @@ -use crate::glue::GlueFrom; use zksync_utils::h256_to_u256; +use crate::glue::GlueFrom; + impl GlueFrom for crate::vm_m5::vm_with_bootloader::BlockContextMode { fn glue_from(value: crate::interface::L1BatchEnv) -> Self { let derived = crate::vm_m5::vm_with_bootloader::DerivedBlockContext { diff --git a/core/lib/multivm/src/glue/types/vm/vm_block_result.rs b/core/lib/multivm/src/glue/types/vm/vm_block_result.rs index 827ac7fe82a..e63ab376bad 100644 --- a/core/lib/multivm/src/glue/types/vm/vm_block_result.rs +++ b/core/lib/multivm/src/glue/types/vm/vm_block_result.rs @@ -1,9 +1,11 @@ use zksync_types::l2_to_l1_log::UserL2ToL1Log; -use crate::glue::{GlueFrom, GlueInto}; -use crate::interface::{ - types::outputs::VmExecutionLogs, CurrentExecutionState, ExecutionResult, Refunds, - VmExecutionResultAndLogs, VmExecutionStatistics, +use crate::{ + glue::{GlueFrom, GlueInto}, + interface::{ + types::outputs::VmExecutionLogs, CurrentExecutionState, ExecutionResult, Refunds, + VmExecutionResultAndLogs, VmExecutionStatistics, + }, }; // Note: In version after vm VmVirtualBlocks the bootloader memory knowledge is encapsulated into the VM. diff --git a/core/lib/multivm/src/glue/types/vm/vm_tx_execution_result.rs b/core/lib/multivm/src/glue/types/vm/vm_tx_execution_result.rs index 10e422edbca..0c888cdda23 100644 --- a/core/lib/multivm/src/glue/types/vm/vm_tx_execution_result.rs +++ b/core/lib/multivm/src/glue/types/vm/vm_tx_execution_result.rs @@ -1,7 +1,10 @@ -use crate::glue::{GlueFrom, GlueInto}; -use crate::interface::{ExecutionResult, Refunds, TxRevertReason, VmExecutionResultAndLogs}; use zksync_types::tx::tx_execution_info::TxExecutionStatus; +use crate::{ + glue::{GlueFrom, GlueInto}, + interface::{ExecutionResult, Refunds, TxRevertReason, VmExecutionResultAndLogs}, +}; + impl GlueFrom for VmExecutionResultAndLogs { fn glue_from(value: crate::vm_m5::vm_instance::VmTxExecutionResult) -> Self { let mut result: VmExecutionResultAndLogs = value.result.glue_into(); diff --git a/core/lib/multivm/src/interface/traits/tracers/dyn_tracers/vm_1_3_3.rs b/core/lib/multivm/src/interface/traits/tracers/dyn_tracers/vm_1_3_3.rs index 2138dd086c0..c088889aa03 100644 --- a/core/lib/multivm/src/interface/traits/tracers/dyn_tracers/vm_1_3_3.rs +++ b/core/lib/multivm/src/interface/traits/tracers/dyn_tracers/vm_1_3_3.rs @@ -1,6 +1,6 @@ -use zk_evm_1_3_3::abstractions::Memory; -use zk_evm_1_3_3::tracing::{ - AfterDecodingData, AfterExecutionData, BeforeExecutionData, VmLocalStateData, +use zk_evm_1_3_3::{ + abstractions::Memory, + tracing::{AfterDecodingData, AfterExecutionData, BeforeExecutionData, VmLocalStateData}, }; use zksync_state::StoragePtr; diff --git a/core/lib/multivm/src/interface/traits/tracers/dyn_tracers/vm_1_4_0.rs b/core/lib/multivm/src/interface/traits/tracers/dyn_tracers/vm_1_4_0.rs index 61d7831393d..3ce69d02942 100644 --- a/core/lib/multivm/src/interface/traits/tracers/dyn_tracers/vm_1_4_0.rs +++ b/core/lib/multivm/src/interface/traits/tracers/dyn_tracers/vm_1_4_0.rs @@ -1,6 +1,6 @@ -use zk_evm_1_4_0::abstractions::Memory; -use zk_evm_1_4_0::tracing::{ - AfterDecodingData, AfterExecutionData, BeforeExecutionData, VmLocalStateData, +use zk_evm_1_4_0::{ + abstractions::Memory, + tracing::{AfterDecodingData, AfterExecutionData, BeforeExecutionData, VmLocalStateData}, }; use zksync_state::StoragePtr; diff --git a/core/lib/multivm/src/interface/traits/vm.rs b/core/lib/multivm/src/interface/traits/vm.rs index b4a9320bbc6..0dbacc9d1d9 100644 --- a/core/lib/multivm/src/interface/traits/vm.rs +++ b/core/lib/multivm/src/interface/traits/vm.rs @@ -47,20 +47,24 @@ //! let result = vm.execute(multivm::interface::VmExecutionMode::Batch); //! ``` -use crate::interface::types::errors::BytecodeCompressionError; -use crate::interface::types::inputs::{L1BatchEnv, L2BlockEnv, SystemEnv, VmExecutionMode}; -use crate::interface::types::outputs::{ - BootloaderMemory, CurrentExecutionState, VmExecutionResultAndLogs, -}; - -use crate::interface::{FinishedL1Batch, VmMemoryMetrics}; -use crate::tracers::TracerDispatcher; -use crate::vm_latest::HistoryEnabled; -use crate::HistoryMode; use zksync_state::StoragePtr; use zksync_types::Transaction; use zksync_utils::bytecode::CompressedBytecodeInfo; +use crate::{ + interface::{ + types::{ + errors::BytecodeCompressionError, + inputs::{L1BatchEnv, L2BlockEnv, SystemEnv, VmExecutionMode}, + outputs::{BootloaderMemory, CurrentExecutionState, VmExecutionResultAndLogs}, + }, + FinishedL1Batch, VmMemoryMetrics, + }, + tracers::TracerDispatcher, + vm_latest::HistoryEnabled, + HistoryMode, +}; + pub trait VmInterface { type TracerDispatcher: Default + From>; diff --git a/core/lib/multivm/src/interface/types/errors/halt.rs b/core/lib/multivm/src/interface/types/errors/halt.rs index 23bab7ee55e..3323a128c68 100644 --- a/core/lib/multivm/src/interface/types/errors/halt.rs +++ b/core/lib/multivm/src/interface/types/errors/halt.rs @@ -1,6 +1,7 @@ -use super::VmRevertReason; use std::fmt::{Display, Formatter}; +use super::VmRevertReason; + /// Structure for non-contract errors from the Virtual Machine (EVM). /// Differentiates VM-specific issues from contract-related errors. diff --git a/core/lib/multivm/src/interface/types/errors/tx_revert_reason.rs b/core/lib/multivm/src/interface/types/errors/tx_revert_reason.rs index f92a913fb8b..9578a06ea0a 100644 --- a/core/lib/multivm/src/interface/types/errors/tx_revert_reason.rs +++ b/core/lib/multivm/src/interface/types/errors/tx_revert_reason.rs @@ -1,8 +1,6 @@ -use super::halt::Halt; - use std::fmt::Display; -use super::{BootloaderErrorCode, VmRevertReason}; +use super::{halt::Halt, BootloaderErrorCode, VmRevertReason}; #[derive(Debug, Clone, PartialEq)] pub enum TxRevertReason { diff --git a/core/lib/multivm/src/interface/types/inputs/l1_batch_env.rs b/core/lib/multivm/src/interface/types/inputs/l1_batch_env.rs index ff239ec4266..b5cb0cbe5e8 100644 --- a/core/lib/multivm/src/interface/types/inputs/l1_batch_env.rs +++ b/core/lib/multivm/src/interface/types/inputs/l1_batch_env.rs @@ -1,6 +1,6 @@ -use super::L2BlockEnv; use zksync_types::{Address, L1BatchNumber, H256}; +use super::L2BlockEnv; use crate::vm_latest::utils::fee::derive_base_fee_and_gas_per_pubdata; /// Unique params for each block diff --git a/core/lib/multivm/src/interface/types/outputs/execution_result.rs b/core/lib/multivm/src/interface/types/outputs/execution_result.rs index 3181a94a9da..e177b630012 100644 --- a/core/lib/multivm/src/interface/types/outputs/execution_result.rs +++ b/core/lib/multivm/src/interface/types/outputs/execution_result.rs @@ -1,11 +1,14 @@ -use crate::interface::{Halt, VmExecutionStatistics, VmRevertReason}; use zksync_system_constants::PUBLISH_BYTECODE_OVERHEAD; -use zksync_types::event::{extract_long_l2_to_l1_messages, extract_published_bytecodes}; -use zksync_types::l2_to_l1_log::{SystemL2ToL1Log, UserL2ToL1Log}; -use zksync_types::tx::ExecutionMetrics; -use zksync_types::{StorageLogQuery, Transaction, VmEvent}; +use zksync_types::{ + event::{extract_long_l2_to_l1_messages, extract_published_bytecodes}, + l2_to_l1_log::{SystemL2ToL1Log, UserL2ToL1Log}, + tx::ExecutionMetrics, + StorageLogQuery, Transaction, VmEvent, +}; use zksync_utils::bytecode::bytecode_len_in_bytes; +use crate::interface::{Halt, VmExecutionStatistics, VmRevertReason}; + /// Refunds produced for the user. #[derive(Debug, Clone, Default)] pub struct Refunds { diff --git a/core/lib/multivm/src/interface/types/outputs/execution_state.rs b/core/lib/multivm/src/interface/types/outputs/execution_state.rs index 066de92ffbe..24034a96221 100644 --- a/core/lib/multivm/src/interface/types/outputs/execution_state.rs +++ b/core/lib/multivm/src/interface/types/outputs/execution_state.rs @@ -1,5 +1,7 @@ -use zksync_types::l2_to_l1_log::{SystemL2ToL1Log, UserL2ToL1Log}; -use zksync_types::{LogQuery, StorageLogQuery, VmEvent, U256}; +use zksync_types::{ + l2_to_l1_log::{SystemL2ToL1Log, UserL2ToL1Log}, + LogQuery, StorageLogQuery, VmEvent, U256, +}; /// State of the VM since the start of the batch execution. #[derive(Debug, Clone, PartialEq)] diff --git a/core/lib/multivm/src/interface/types/outputs/mod.rs b/core/lib/multivm/src/interface/types/outputs/mod.rs index 39fed3ad9cb..eec19826e0b 100644 --- a/core/lib/multivm/src/interface/types/outputs/mod.rs +++ b/core/lib/multivm/src/interface/types/outputs/mod.rs @@ -1,12 +1,13 @@ +pub use self::{ + execution_result::{ExecutionResult, Refunds, VmExecutionLogs, VmExecutionResultAndLogs}, + execution_state::{BootloaderMemory, CurrentExecutionState}, + finished_l1batch::FinishedL1Batch, + l2_block::L2Block, + statistic::{VmExecutionStatistics, VmMemoryMetrics}, +}; + mod execution_result; mod execution_state; mod finished_l1batch; mod l2_block; mod statistic; - -pub use execution_result::VmExecutionLogs; -pub use execution_result::{ExecutionResult, Refunds, VmExecutionResultAndLogs}; -pub use execution_state::{BootloaderMemory, CurrentExecutionState}; -pub use finished_l1batch::FinishedL1Batch; -pub use l2_block::L2Block; -pub use statistic::{VmExecutionStatistics, VmMemoryMetrics}; diff --git a/core/lib/multivm/src/lib.rs b/core/lib/multivm/src/lib.rs index 06d7a429130..23ea80a6860 100644 --- a/core/lib/multivm/src/lib.rs +++ b/core/lib/multivm/src/lib.rs @@ -3,6 +3,14 @@ #![warn(unused_extern_crates)] #![warn(unused_imports)] +pub use zk_evm_1_3_1; +pub use zk_evm_1_3_3; +pub use zk_evm_1_4_0; +pub use zksync_types::vm_version::VmVersion; + +pub use self::versions::{ + vm_1_3_2, vm_latest, vm_m5, vm_m6, vm_refunds_enhancement, vm_virtual_blocks, +}; pub use crate::{ glue::{ history_mode::HistoryMode, @@ -10,22 +18,9 @@ pub use crate::{ }, vm_instance::VmInstance, }; -pub use zksync_types::vm_version::VmVersion; mod glue; - -mod vm_instance; - pub mod interface; pub mod tracers; pub mod versions; - -pub use versions::vm_1_3_2; -pub use versions::vm_latest; -pub use versions::vm_m5; -pub use versions::vm_m6; -pub use versions::vm_refunds_enhancement; -pub use versions::vm_virtual_blocks; -pub use zk_evm_1_3_1; -pub use zk_evm_1_3_3; -pub use zk_evm_1_4_0; +mod vm_instance; diff --git a/core/lib/multivm/src/tracers/call_tracer/mod.rs b/core/lib/multivm/src/tracers/call_tracer/mod.rs index 90f15fb68d4..0c7e4d3c280 100644 --- a/core/lib/multivm/src/tracers/call_tracer/mod.rs +++ b/core/lib/multivm/src/tracers/call_tracer/mod.rs @@ -1,8 +1,10 @@ -use crate::tracers::call_tracer::metrics::CALL_METRICS; -use once_cell::sync::OnceCell; use std::sync::Arc; + +use once_cell::sync::OnceCell; use zksync_types::vm_trace::Call; +use crate::tracers::call_tracer::metrics::CALL_METRICS; + mod metrics; pub mod vm_latest; pub mod vm_refunds_enhancement; diff --git a/core/lib/multivm/src/tracers/call_tracer/vm_latest/mod.rs b/core/lib/multivm/src/tracers/call_tracer/vm_latest/mod.rs index f5f5c1077d3..09b5b828fc0 100644 --- a/core/lib/multivm/src/tracers/call_tracer/vm_latest/mod.rs +++ b/core/lib/multivm/src/tracers/call_tracer/vm_latest/mod.rs @@ -7,16 +7,19 @@ use zk_evm_1_4_0::{ }; use zksync_state::{StoragePtr, WriteStorage}; use zksync_system_constants::CONTRACT_DEPLOYER_ADDRESS; -use zksync_types::vm_trace::{Call, CallType}; -use zksync_types::FarCallOpcode; -use zksync_types::U256; +use zksync_types::{ + vm_trace::{Call, CallType}, + FarCallOpcode, U256, +}; -use crate::interface::{ - tracer::VmExecutionStopReason, traits::tracers::dyn_tracers::vm_1_4_0::DynTracer, - VmRevertReason, +use crate::{ + interface::{ + tracer::VmExecutionStopReason, traits::tracers::dyn_tracers::vm_1_4_0::DynTracer, + VmRevertReason, + }, + tracers::call_tracer::CallTracer, + vm_latest::{BootloaderState, HistoryMode, SimpleMemory, VmTracer, ZkSyncVmState}, }; -use crate::tracers::call_tracer::CallTracer; -use crate::vm_latest::{BootloaderState, HistoryMode, SimpleMemory, VmTracer, ZkSyncVmState}; impl DynTracer> for CallTracer { fn after_execution( diff --git a/core/lib/multivm/src/tracers/call_tracer/vm_refunds_enhancement/mod.rs b/core/lib/multivm/src/tracers/call_tracer/vm_refunds_enhancement/mod.rs index fab4ee0ff0f..3bc4426e8cc 100644 --- a/core/lib/multivm/src/tracers/call_tracer/vm_refunds_enhancement/mod.rs +++ b/core/lib/multivm/src/tracers/call_tracer/vm_refunds_enhancement/mod.rs @@ -7,17 +7,18 @@ use zk_evm_1_3_3::{ }; use zksync_state::{StoragePtr, WriteStorage}; use zksync_system_constants::CONTRACT_DEPLOYER_ADDRESS; -use zksync_types::vm_trace::{Call, CallType}; -use zksync_types::FarCallOpcode; -use zksync_types::U256; - -use crate::interface::{ - tracer::VmExecutionStopReason, traits::tracers::dyn_tracers::vm_1_3_3::DynTracer, - VmRevertReason, +use zksync_types::{ + vm_trace::{Call, CallType}, + FarCallOpcode, U256, }; -use crate::tracers::call_tracer::CallTracer; -use crate::vm_refunds_enhancement::{ - BootloaderState, HistoryMode, SimpleMemory, VmTracer, ZkSyncVmState, + +use crate::{ + interface::{ + tracer::VmExecutionStopReason, traits::tracers::dyn_tracers::vm_1_3_3::DynTracer, + VmRevertReason, + }, + tracers::call_tracer::CallTracer, + vm_refunds_enhancement::{BootloaderState, HistoryMode, SimpleMemory, VmTracer, ZkSyncVmState}, }; impl DynTracer> for CallTracer { diff --git a/core/lib/multivm/src/tracers/call_tracer/vm_virtual_blocks/mod.rs b/core/lib/multivm/src/tracers/call_tracer/vm_virtual_blocks/mod.rs index 631d4d2081c..f96b2cb0f58 100644 --- a/core/lib/multivm/src/tracers/call_tracer/vm_virtual_blocks/mod.rs +++ b/core/lib/multivm/src/tracers/call_tracer/vm_virtual_blocks/mod.rs @@ -1,20 +1,23 @@ -use zk_evm_1_3_3::tracing::{AfterExecutionData, VmLocalStateData}; -use zk_evm_1_3_3::zkevm_opcode_defs::{ - FarCallABI, FatPointer, Opcode, RetOpcode, CALL_IMPLICIT_CALLDATA_FAT_PTR_REGISTER, - RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER, +use zk_evm_1_3_3::{ + tracing::{AfterExecutionData, VmLocalStateData}, + zkevm_opcode_defs::{ + FarCallABI, FatPointer, Opcode, RetOpcode, CALL_IMPLICIT_CALLDATA_FAT_PTR_REGISTER, + RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER, + }, }; use zksync_state::{StoragePtr, WriteStorage}; use zksync_system_constants::CONTRACT_DEPLOYER_ADDRESS; -use zksync_types::vm_trace::{Call, CallType}; -use zksync_types::FarCallOpcode; -use zksync_types::U256; - -use crate::interface::{ - dyn_tracers::vm_1_3_3::DynTracer, VmExecutionResultAndLogs, VmRevertReason, +use zksync_types::{ + vm_trace::{Call, CallType}, + FarCallOpcode, U256, }; -use crate::tracers::call_tracer::CallTracer; -use crate::vm_virtual_blocks::{ - ExecutionEndTracer, ExecutionProcessing, HistoryMode, SimpleMemory, VmTracer, + +use crate::{ + interface::{dyn_tracers::vm_1_3_3::DynTracer, VmExecutionResultAndLogs, VmRevertReason}, + tracers::call_tracer::CallTracer, + vm_virtual_blocks::{ + ExecutionEndTracer, ExecutionProcessing, HistoryMode, SimpleMemory, VmTracer, + }, }; impl DynTracer> for CallTracer { diff --git a/core/lib/multivm/src/tracers/multivm_dispatcher.rs b/core/lib/multivm/src/tracers/multivm_dispatcher.rs index d4c7337ce65..8ee858a6110 100644 --- a/core/lib/multivm/src/tracers/multivm_dispatcher.rs +++ b/core/lib/multivm/src/tracers/multivm_dispatcher.rs @@ -1,6 +1,7 @@ -use crate::{HistoryMode, MultiVmTracerPointer}; use zksync_state::WriteStorage; +use crate::{HistoryMode, MultiVmTracerPointer}; + /// Tracer dispatcher is a tracer that can dispatch calls to multiple tracers. pub struct TracerDispatcher { tracers: Vec>, diff --git a/core/lib/multivm/src/tracers/storage_invocation/vm_latest/mod.rs b/core/lib/multivm/src/tracers/storage_invocation/vm_latest/mod.rs index 0490ec34107..46213ff54fc 100644 --- a/core/lib/multivm/src/tracers/storage_invocation/vm_latest/mod.rs +++ b/core/lib/multivm/src/tracers/storage_invocation/vm_latest/mod.rs @@ -1,12 +1,15 @@ -use crate::interface::{ - tracer::{TracerExecutionStatus, TracerExecutionStopReason}, - traits::tracers::dyn_tracers::vm_1_4_0::DynTracer, - Halt, -}; -use crate::tracers::storage_invocation::StorageInvocations; -use crate::vm_latest::{BootloaderState, HistoryMode, SimpleMemory, VmTracer, ZkSyncVmState}; use zksync_state::WriteStorage; +use crate::{ + interface::{ + tracer::{TracerExecutionStatus, TracerExecutionStopReason}, + traits::tracers::dyn_tracers::vm_1_4_0::DynTracer, + Halt, + }, + tracers::storage_invocation::StorageInvocations, + vm_latest::{BootloaderState, HistoryMode, SimpleMemory, VmTracer, ZkSyncVmState}, +}; + impl DynTracer> for StorageInvocations {} impl VmTracer for StorageInvocations { diff --git a/core/lib/multivm/src/tracers/storage_invocation/vm_refunds_enhancement/mod.rs b/core/lib/multivm/src/tracers/storage_invocation/vm_refunds_enhancement/mod.rs index fe4fc33418d..1e562374afd 100644 --- a/core/lib/multivm/src/tracers/storage_invocation/vm_refunds_enhancement/mod.rs +++ b/core/lib/multivm/src/tracers/storage_invocation/vm_refunds_enhancement/mod.rs @@ -1,10 +1,15 @@ -use crate::interface::tracer::{TracerExecutionStatus, TracerExecutionStopReason}; -use crate::interface::{traits::tracers::dyn_tracers::vm_1_3_3::DynTracer, Halt}; -use crate::tracers::storage_invocation::StorageInvocations; -use crate::vm_refunds_enhancement::VmTracer; -use crate::vm_refunds_enhancement::{BootloaderState, HistoryMode, SimpleMemory, ZkSyncVmState}; use zksync_state::WriteStorage; +use crate::{ + interface::{ + tracer::{TracerExecutionStatus, TracerExecutionStopReason}, + traits::tracers::dyn_tracers::vm_1_3_3::DynTracer, + Halt, + }, + tracers::storage_invocation::StorageInvocations, + vm_refunds_enhancement::{BootloaderState, HistoryMode, SimpleMemory, VmTracer, ZkSyncVmState}, +}; + impl DynTracer> for StorageInvocations {} impl VmTracer for StorageInvocations { diff --git a/core/lib/multivm/src/tracers/storage_invocation/vm_virtual_blocks/mod.rs b/core/lib/multivm/src/tracers/storage_invocation/vm_virtual_blocks/mod.rs index 023b6f376cd..cd0ab9f4bb5 100644 --- a/core/lib/multivm/src/tracers/storage_invocation/vm_virtual_blocks/mod.rs +++ b/core/lib/multivm/src/tracers/storage_invocation/vm_virtual_blocks/mod.rs @@ -1,11 +1,14 @@ -use crate::interface::dyn_tracers::vm_1_3_3::DynTracer; -use crate::tracers::storage_invocation::StorageInvocations; -use crate::vm_virtual_blocks::{ - BootloaderState, ExecutionEndTracer, ExecutionProcessing, HistoryMode, SimpleMemory, VmTracer, - ZkSyncVmState, -}; use zksync_state::WriteStorage; +use crate::{ + interface::dyn_tracers::vm_1_3_3::DynTracer, + tracers::storage_invocation::StorageInvocations, + vm_virtual_blocks::{ + BootloaderState, ExecutionEndTracer, ExecutionProcessing, HistoryMode, SimpleMemory, + VmTracer, ZkSyncVmState, + }, +}; + impl ExecutionEndTracer for StorageInvocations { fn should_stop_execution(&self) -> bool { self.current >= self.limit diff --git a/core/lib/multivm/src/tracers/validator/mod.rs b/core/lib/multivm/src/tracers/validator/mod.rs index 718edf1a964..0f43f235ade 100644 --- a/core/lib/multivm/src/tracers/validator/mod.rs +++ b/core/lib/multivm/src/tracers/validator/mod.rs @@ -1,19 +1,11 @@ -mod types; -mod vm_latest; -mod vm_refunds_enhancement; -mod vm_virtual_blocks; - -use std::sync::Arc; -use std::{collections::HashSet, marker::PhantomData}; +use std::{collections::HashSet, marker::PhantomData, sync::Arc}; use once_cell::sync::OnceCell; - use zksync_state::{StoragePtr, WriteStorage}; use zksync_system_constants::{ ACCOUNT_CODE_STORAGE_ADDRESS, BOOTLOADER_ADDRESS, CONTRACT_DEPLOYER_ADDRESS, L2_ETH_TOKEN_ADDRESS, MSG_VALUE_SIMULATOR_ADDRESS, SYSTEM_CONTEXT_ADDRESS, }; - use zksync_types::{ vm_trace::ViolatedValidationRule, web3::signing::keccak256, AccountTreeId, Address, StorageKey, H256, U256, @@ -23,6 +15,11 @@ use zksync_utils::{be_bytes_to_safe_address, u256_to_account_address, u256_to_h2 use crate::tracers::validator::types::{NewTrustedValidationItems, ValidationTracerMode}; pub use crate::tracers::validator::types::{ValidationError, ValidationTracerParams}; +mod types; +mod vm_latest; +mod vm_refunds_enhancement; +mod vm_virtual_blocks; + /// Tracer that is used to ensure that the validation adheres to all the rules /// to prevent DDoS attacks on the server. #[derive(Debug, Clone)] diff --git a/core/lib/multivm/src/tracers/validator/types.rs b/core/lib/multivm/src/tracers/validator/types.rs index eb80e6f1650..de6217c2988 100644 --- a/core/lib/multivm/src/tracers/validator/types.rs +++ b/core/lib/multivm/src/tracers/validator/types.rs @@ -1,8 +1,8 @@ +use std::{collections::HashSet, fmt::Display}; + +use zksync_types::{vm_trace::ViolatedValidationRule, Address, H256, U256}; + use crate::interface::Halt; -use std::collections::HashSet; -use std::fmt::Display; -use zksync_types::vm_trace::ViolatedValidationRule; -use zksync_types::{Address, H256, U256}; #[derive(Debug, Clone, Eq, PartialEq, Copy)] #[allow(clippy::enum_variant_names)] diff --git a/core/lib/multivm/src/tracers/validator/vm_latest/mod.rs b/core/lib/multivm/src/tracers/validator/vm_latest/mod.rs index 4d5ff43ec47..dbdc7253f75 100644 --- a/core/lib/multivm/src/tracers/validator/vm_latest/mod.rs +++ b/core/lib/multivm/src/tracers/validator/vm_latest/mod.rs @@ -2,32 +2,32 @@ use zk_evm_1_4_0::{ tracing::{BeforeExecutionData, VmLocalStateData}, zkevm_opcode_defs::{ContextOpcode, FarCallABI, LogOpcode, Opcode}, }; - use zksync_state::{StoragePtr, WriteStorage}; use zksync_system_constants::KECCAK256_PRECOMPILE_ADDRESS; - -use crate::HistoryMode; use zksync_types::{ get_code_key, vm_trace::ViolatedValidationRule, AccountTreeId, StorageKey, H256, }; use zksync_utils::{h256_to_account_address, u256_to_account_address, u256_to_h256}; -use crate::vm_latest::tracers::utils::{ - computational_gas_price, get_calldata_page_via_abi, print_debug_if_needed, VmHook, -}; - -use crate::interface::{ - traits::tracers::dyn_tracers::vm_1_4_0::DynTracer, - types::tracer::{TracerExecutionStatus, TracerExecutionStopReason}, - Halt, -}; -use crate::tracers::validator::{ - types::{NewTrustedValidationItems, ValidationTracerMode}, - {ValidationRoundResult, ValidationTracer}, +use crate::{ + interface::{ + traits::tracers::dyn_tracers::vm_1_4_0::DynTracer, + types::tracer::{TracerExecutionStatus, TracerExecutionStopReason}, + Halt, + }, + tracers::validator::{ + types::{NewTrustedValidationItems, ValidationTracerMode}, + ValidationRoundResult, ValidationTracer, + }, + vm_latest::{ + tracers::utils::{ + computational_gas_price, get_calldata_page_via_abi, print_debug_if_needed, VmHook, + }, + BootloaderState, SimpleMemory, VmTracer, ZkSyncVmState, + }, + HistoryMode, }; -use crate::vm_latest::{BootloaderState, SimpleMemory, VmTracer, ZkSyncVmState}; - impl ValidationTracer { fn check_user_restrictions_vm_latest( &mut self, diff --git a/core/lib/multivm/src/tracers/validator/vm_refunds_enhancement/mod.rs b/core/lib/multivm/src/tracers/validator/vm_refunds_enhancement/mod.rs index ec4e95e5630..ab3a16c4b90 100644 --- a/core/lib/multivm/src/tracers/validator/vm_refunds_enhancement/mod.rs +++ b/core/lib/multivm/src/tracers/validator/vm_refunds_enhancement/mod.rs @@ -2,31 +2,30 @@ use zk_evm_1_3_3::{ tracing::{BeforeExecutionData, VmLocalStateData}, zkevm_opcode_defs::{ContextOpcode, FarCallABI, LogOpcode, Opcode}, }; - use zksync_state::{StoragePtr, WriteStorage}; use zksync_system_constants::KECCAK256_PRECOMPILE_ADDRESS; - -use crate::HistoryMode; use zksync_types::{ get_code_key, vm_trace::ViolatedValidationRule, AccountTreeId, StorageKey, H256, }; use zksync_utils::{h256_to_account_address, u256_to_account_address, u256_to_h256}; -use crate::interface::{ - traits::tracers::dyn_tracers::vm_1_3_3::DynTracer, - types::tracer::{TracerExecutionStatus, TracerExecutionStopReason}, - Halt, -}; -use crate::tracers::validator::{ - types::{NewTrustedValidationItems, ValidationTracerMode}, - {ValidationRoundResult, ValidationTracer}, -}; - -use crate::vm_refunds_enhancement::{ - tracers::utils::{ - computational_gas_price, get_calldata_page_via_abi, print_debug_if_needed, VmHook, +use crate::{ + interface::{ + traits::tracers::dyn_tracers::vm_1_3_3::DynTracer, + types::tracer::{TracerExecutionStatus, TracerExecutionStopReason}, + Halt, + }, + tracers::validator::{ + types::{NewTrustedValidationItems, ValidationTracerMode}, + ValidationRoundResult, ValidationTracer, + }, + vm_refunds_enhancement::{ + tracers::utils::{ + computational_gas_price, get_calldata_page_via_abi, print_debug_if_needed, VmHook, + }, + BootloaderState, SimpleMemory, VmTracer, ZkSyncVmState, }, - BootloaderState, SimpleMemory, VmTracer, ZkSyncVmState, + HistoryMode, }; impl ValidationTracer { diff --git a/core/lib/multivm/src/tracers/validator/vm_virtual_blocks/mod.rs b/core/lib/multivm/src/tracers/validator/vm_virtual_blocks/mod.rs index d2155f4ecf8..6fd2955f60b 100644 --- a/core/lib/multivm/src/tracers/validator/vm_virtual_blocks/mod.rs +++ b/core/lib/multivm/src/tracers/validator/vm_virtual_blocks/mod.rs @@ -2,25 +2,27 @@ use zk_evm_1_3_3::{ tracing::{BeforeExecutionData, VmLocalStateData}, zkevm_opcode_defs::{ContextOpcode, FarCallABI, LogOpcode, Opcode}, }; - use zksync_state::{StoragePtr, WriteStorage}; use zksync_system_constants::KECCAK256_PRECOMPILE_ADDRESS; - -use crate::HistoryMode; -use zksync_types::vm_trace::ViolatedValidationRule; -use zksync_types::{get_code_key, AccountTreeId, StorageKey, H256}; +use zksync_types::{ + get_code_key, vm_trace::ViolatedValidationRule, AccountTreeId, StorageKey, H256, +}; use zksync_utils::{h256_to_account_address, u256_to_account_address, u256_to_h256}; -use crate::vm_virtual_blocks::tracers::utils::{ - computational_gas_price, get_calldata_page_via_abi, print_debug_if_needed, VmHook, +use crate::{ + interface::{dyn_tracers::vm_1_3_3::DynTracer, VmExecutionResultAndLogs}, + tracers::validator::{ + types::{NewTrustedValidationItems, ValidationTracerMode}, + ValidationRoundResult, ValidationTracer, + }, + vm_virtual_blocks::{ + tracers::utils::{ + computational_gas_price, get_calldata_page_via_abi, print_debug_if_needed, VmHook, + }, + ExecutionEndTracer, ExecutionProcessing, SimpleMemory, VmTracer, + }, + HistoryMode, }; -use crate::vm_virtual_blocks::SimpleMemory; -use crate::vm_virtual_blocks::{ExecutionEndTracer, ExecutionProcessing, VmTracer}; - -use crate::interface::dyn_tracers::vm_1_3_3::DynTracer; -use crate::interface::VmExecutionResultAndLogs; -use crate::tracers::validator::types::{NewTrustedValidationItems, ValidationTracerMode}; -use crate::tracers::validator::{ValidationRoundResult, ValidationTracer}; impl ValidationTracer { fn check_user_restrictions_vm_virtual_blocks( diff --git a/core/lib/multivm/src/versions/vm_1_3_2/errors/vm_revert_reason.rs b/core/lib/multivm/src/versions/vm_1_3_2/errors/vm_revert_reason.rs index c127a9e6f2d..70c954425f4 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/errors/vm_revert_reason.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/errors/vm_revert_reason.rs @@ -1,5 +1,7 @@ -use std::convert::TryFrom; -use std::fmt::{Debug, Display}; +use std::{ + convert::TryFrom, + fmt::{Debug, Display}, +}; use zksync_types::U256; diff --git a/core/lib/multivm/src/versions/vm_1_3_2/event_sink.rs b/core/lib/multivm/src/versions/vm_1_3_2/event_sink.rs index db6c5d11aee..cbf7c183d3a 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/event_sink.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/event_sink.rs @@ -1,8 +1,5 @@ -use crate::vm_1_3_2::{ - history_recorder::{AppDataFrameManagerWithHistory, HistoryEnabled, HistoryMode}, - oracles::OracleWithHistory, -}; use std::collections::HashMap; + use zk_evm_1_3_3::{ abstractions::EventSink, aux_structures::{LogQuery, Timestamp}, @@ -12,6 +9,11 @@ use zk_evm_1_3_3::{ }, }; +use crate::vm_1_3_2::{ + history_recorder::{AppDataFrameManagerWithHistory, HistoryEnabled, HistoryMode}, + oracles::OracleWithHistory, +}; + #[derive(Debug, Clone, PartialEq, Default)] pub struct InMemoryEventSink { frames_stack: AppDataFrameManagerWithHistory, H>, diff --git a/core/lib/multivm/src/versions/vm_1_3_2/history_recorder.rs b/core/lib/multivm/src/versions/vm_1_3_2/history_recorder.rs index 3c83b68e0a3..263c1f023dd 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/history_recorder.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/history_recorder.rs @@ -5,7 +5,6 @@ use zk_evm_1_3_3::{ vm_state::PrimitiveValue, zkevm_opcode_defs::{self}, }; - use zksync_state::{StoragePtr, WriteStorage}; use zksync_types::{StorageKey, U256}; use zksync_utils::{h256_to_u256, u256_to_h256}; @@ -765,12 +764,13 @@ impl HistoryRecorder, H> { #[cfg(test)] mod tests { + use zk_evm_1_3_3::{aux_structures::Timestamp, vm_state::PrimitiveValue}; + use zksync_types::U256; + use crate::vm_1_3_2::{ history_recorder::{HistoryRecorder, MemoryWrapper}, HistoryDisabled, }; - use zk_evm_1_3_3::{aux_structures::Timestamp, vm_state::PrimitiveValue}; - use zksync_types::U256; #[test] fn memory_equality() { diff --git a/core/lib/multivm/src/versions/vm_1_3_2/memory.rs b/core/lib/multivm/src/versions/vm_1_3_2/memory.rs index b269ba89b3c..91fdbe223d8 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/memory.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/memory.rs @@ -1,15 +1,19 @@ -use zk_evm_1_3_3::abstractions::{Memory, MemoryType}; -use zk_evm_1_3_3::aux_structures::{MemoryPage, MemoryQuery, Timestamp}; -use zk_evm_1_3_3::vm_state::PrimitiveValue; -use zk_evm_1_3_3::zkevm_opcode_defs::FatPointer; +use zk_evm_1_3_3::{ + abstractions::{Memory, MemoryType}, + aux_structures::{MemoryPage, MemoryQuery, Timestamp}, + vm_state::PrimitiveValue, + zkevm_opcode_defs::FatPointer, +}; use zksync_types::U256; -use crate::vm_1_3_2::history_recorder::{ - FramedStack, HistoryEnabled, HistoryMode, IntFrameManagerWithHistory, MemoryWithHistory, - MemoryWrapper, WithHistory, +use crate::vm_1_3_2::{ + history_recorder::{ + FramedStack, HistoryEnabled, HistoryMode, IntFrameManagerWithHistory, MemoryWithHistory, + MemoryWrapper, WithHistory, + }, + oracles::OracleWithHistory, + utils::{aux_heap_page_from_base, heap_page_from_base, stack_page_from_base}, }; -use crate::vm_1_3_2::oracles::OracleWithHistory; -use crate::vm_1_3_2::utils::{aux_heap_page_from_base, heap_page_from_base, stack_page_from_base}; #[derive(Debug, Clone, PartialEq)] pub struct SimpleMemory { diff --git a/core/lib/multivm/src/versions/vm_1_3_2/mod.rs b/core/lib/multivm/src/versions/vm_1_3_2/mod.rs index 24e433d9123..37c5f34ffd0 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/mod.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/mod.rs @@ -1,5 +1,18 @@ #![allow(clippy::derive_partial_eq_without_eq)] +pub use zk_evm_1_3_3::{self, block_properties::BlockProperties}; +pub use zksync_types::vm_trace::VmExecutionTrace; + +pub(crate) use self::vm_instance::VmInstance; +pub use self::{ + errors::TxRevertReason, + history_recorder::{HistoryDisabled, HistoryEnabled, HistoryMode}, + oracle_tools::OracleTools, + oracles::storage::StorageOracle, + vm::Vm, + vm_instance::{VmBlockResult, VmExecutionResult}, +}; + mod bootloader_state; pub mod errors; pub mod event_sink; @@ -11,25 +24,13 @@ pub mod oracles; mod pubdata_utils; mod refunds; pub mod test_utils; -pub mod transaction_data; -pub mod utils; -pub mod vm_with_bootloader; - #[cfg(test)] mod tests; +pub mod transaction_data; +pub mod utils; mod vm; pub mod vm_instance; - -pub use errors::TxRevertReason; -pub use history_recorder::{HistoryDisabled, HistoryEnabled, HistoryMode}; -pub use oracle_tools::OracleTools; -pub use oracles::storage::StorageOracle; -pub use vm::Vm; -pub(crate) use vm_instance::VmInstance; -pub use vm_instance::{VmBlockResult, VmExecutionResult}; -pub use zk_evm_1_3_3; -pub use zk_evm_1_3_3::block_properties::BlockProperties; -pub use zksync_types::vm_trace::VmExecutionTrace; +pub mod vm_with_bootloader; pub type Word = zksync_types::U256; diff --git a/core/lib/multivm/src/versions/vm_1_3_2/oracle_tools.rs b/core/lib/multivm/src/versions/vm_1_3_2/oracle_tools.rs index 9f0f2600c5b..f271d86474c 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/oracle_tools.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/oracle_tools.rs @@ -1,15 +1,18 @@ use std::fmt::Debug; -use crate::vm_1_3_2::event_sink::InMemoryEventSink; -use crate::vm_1_3_2::history_recorder::HistoryMode; -use crate::vm_1_3_2::memory::SimpleMemory; -use crate::vm_1_3_2::oracles::{ - decommitter::DecommitterOracle, precompile::PrecompilesProcessorWithHistory, - storage::StorageOracle, -}; use zk_evm_1_3_3::witness_trace::DummyTracer; use zksync_state::{StoragePtr, WriteStorage}; +use crate::vm_1_3_2::{ + event_sink::InMemoryEventSink, + history_recorder::HistoryMode, + memory::SimpleMemory, + oracles::{ + decommitter::DecommitterOracle, precompile::PrecompilesProcessorWithHistory, + storage::StorageOracle, + }, +}; + /// zkEVM requires a bunch of objects implementing given traits to work. /// For example: Storage, Memory, PrecompilerProcessor etc /// (you can find all these traits in zk_evm crate -> src/abstractions/mod.rs) diff --git a/core/lib/multivm/src/versions/vm_1_3_2/oracles/decommitter.rs b/core/lib/multivm/src/versions/vm_1_3_2/oracles/decommitter.rs index 17583b70dc9..d58b501b244 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/oracles/decommitter.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/oracles/decommitter.rs @@ -1,21 +1,19 @@ use std::collections::HashMap; -use crate::vm_1_3_2::history_recorder::{ - HistoryEnabled, HistoryMode, HistoryRecorder, WithHistory, -}; - -use zk_evm_1_3_3::abstractions::MemoryType; -use zk_evm_1_3_3::aux_structures::Timestamp; use zk_evm_1_3_3::{ - abstractions::{DecommittmentProcessor, Memory}, - aux_structures::{DecommittmentQuery, MemoryIndex, MemoryLocation, MemoryPage, MemoryQuery}, + abstractions::{DecommittmentProcessor, Memory, MemoryType}, + aux_structures::{ + DecommittmentQuery, MemoryIndex, MemoryLocation, MemoryPage, MemoryQuery, Timestamp, + }, }; use zksync_state::{StoragePtr, WriteStorage}; use zksync_types::U256; -use zksync_utils::bytecode::bytecode_len_in_words; -use zksync_utils::{bytes_to_be_words, u256_to_h256}; +use zksync_utils::{bytecode::bytecode_len_in_words, bytes_to_be_words, u256_to_h256}; use super::OracleWithHistory; +use crate::vm_1_3_2::history_recorder::{ + HistoryEnabled, HistoryMode, HistoryRecorder, WithHistory, +}; /// The main job of the DecommiterOracle is to implement the DecommittmentProcessor trait - that is /// used by the VM to 'load' bytecodes into memory. diff --git a/core/lib/multivm/src/versions/vm_1_3_2/oracles/mod.rs b/core/lib/multivm/src/versions/vm_1_3_2/oracles/mod.rs index 342fadb554a..08eb1c6e174 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/oracles/mod.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/oracles/mod.rs @@ -1,11 +1,10 @@ use zk_evm_1_3_3::aux_structures::Timestamp; -// We will discard RAM as soon as the execution of a tx ends, so -// it is ok for now to use SimpleMemory -pub use zk_evm_1_3_3::reference_impls::memory::SimpleMemory as RamOracle; // All the changes to the events in the DB will be applied after the tx is executed, // so fow now it is fine. pub use zk_evm_1_3_3::reference_impls::event_sink::InMemoryEventSink as EventSinkOracle; - +// We will discard RAM as soon as the execution of a tx ends, so +// it is ok for now to use SimpleMemory +pub use zk_evm_1_3_3::reference_impls::memory::SimpleMemory as RamOracle; pub use zk_evm_1_3_3::testing::simple_tracer::NoopTracer; pub mod decommitter; diff --git a/core/lib/multivm/src/versions/vm_1_3_2/oracles/precompile.rs b/core/lib/multivm/src/versions/vm_1_3_2/oracles/precompile.rs index 0693fac6d60..8089527183f 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/oracles/precompile.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/oracles/precompile.rs @@ -1,14 +1,11 @@ use zk_evm_1_3_3::{ - abstractions::Memory, - abstractions::PrecompileCyclesWitness, - abstractions::PrecompilesProcessor, + abstractions::{Memory, PrecompileCyclesWitness, PrecompilesProcessor}, aux_structures::{LogQuery, MemoryQuery, Timestamp}, precompiles::DefaultPrecompilesProcessor, }; -use crate::vm_1_3_2::history_recorder::{HistoryEnabled, HistoryMode, HistoryRecorder}; - use super::OracleWithHistory; +use crate::vm_1_3_2::history_recorder::{HistoryEnabled, HistoryMode, HistoryRecorder}; /// Wrap of DefaultPrecompilesProcessor that store queue /// of timestamp when precompiles are called to be executed. diff --git a/core/lib/multivm/src/versions/vm_1_3_2/oracles/storage.rs b/core/lib/multivm/src/versions/vm_1_3_2/oracles/storage.rs index 9a4873fe59a..ea2ecf83a3d 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/oracles/storage.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/oracles/storage.rs @@ -1,25 +1,22 @@ use std::collections::HashMap; -use crate::vm_1_3_2::history_recorder::{ - AppDataFrameManagerWithHistory, HashMapHistoryEvent, HistoryEnabled, HistoryMode, - HistoryRecorder, StorageWrapper, WithHistory, -}; - -use zk_evm_1_3_3::abstractions::RefundedAmounts; -use zk_evm_1_3_3::zkevm_opcode_defs::system_params::INITIAL_STORAGE_WRITE_PUBDATA_BYTES; use zk_evm_1_3_3::{ - abstractions::{RefundType, Storage as VmStorageOracle}, + abstractions::{RefundType, RefundedAmounts, Storage as VmStorageOracle}, aux_structures::{LogQuery, Timestamp}, + zkevm_opcode_defs::system_params::INITIAL_STORAGE_WRITE_PUBDATA_BYTES, }; use zksync_state::{StoragePtr, WriteStorage}; -use zksync_types::utils::storage_key_for_eth_balance; use zksync_types::{ - AccountTreeId, Address, StorageKey, StorageLogQuery, StorageLogQueryType, BOOTLOADER_ADDRESS, - U256, + utils::storage_key_for_eth_balance, AccountTreeId, Address, StorageKey, StorageLogQuery, + StorageLogQueryType, BOOTLOADER_ADDRESS, U256, }; use zksync_utils::u256_to_h256; use super::OracleWithHistory; +use crate::vm_1_3_2::history_recorder::{ + AppDataFrameManagerWithHistory, HashMapHistoryEvent, HistoryEnabled, HistoryMode, + HistoryRecorder, StorageWrapper, WithHistory, +}; // While the storage does not support different shards, it was decided to write the // code of the StorageOracle with the shard parameters in mind. diff --git a/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/bootloader.rs b/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/bootloader.rs index 16b1efdff54..3bc80f31119 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/bootloader.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/bootloader.rs @@ -1,12 +1,5 @@ use std::marker::PhantomData; -use crate::vm_1_3_2::history_recorder::HistoryMode; -use crate::vm_1_3_2::memory::SimpleMemory; -use crate::vm_1_3_2::oracles::tracer::{ - utils::gas_spent_on_bytecodes_and_long_messages_this_opcode, ExecutionEndTracer, - PendingRefundTracer, PubdataSpentTracer, StorageInvocationTracer, -}; - use zk_evm_1_3_3::{ tracing::{ AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, @@ -16,6 +9,15 @@ use zk_evm_1_3_3::{ zkevm_opcode_defs::{Opcode, RetOpcode}, }; +use crate::vm_1_3_2::{ + history_recorder::HistoryMode, + memory::SimpleMemory, + oracles::tracer::{ + utils::gas_spent_on_bytecodes_and_long_messages_this_opcode, ExecutionEndTracer, + PendingRefundTracer, PubdataSpentTracer, StorageInvocationTracer, + }, +}; + /// Tells the VM to end the execution before `ret` from the bootloader if there is no panic or revert. /// Also, saves the information if this `ret` was caused by "out of gas" panic. #[derive(Debug, Clone, Default)] diff --git a/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/call.rs b/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/call.rs index 72701f6e0f2..88b21818fc3 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/call.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/call.rs @@ -1,20 +1,23 @@ -use crate::vm_1_3_2::errors::VmRevertReason; -use crate::vm_1_3_2::history_recorder::HistoryMode; -use crate::vm_1_3_2::memory::SimpleMemory; -use std::convert::TryFrom; -use std::marker::PhantomData; -use std::mem; -use zk_evm_1_3_3::tracing::{ - AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, -}; -use zk_evm_1_3_3::zkevm_opcode_defs::FatPointer; -use zk_evm_1_3_3::zkevm_opcode_defs::{ - FarCallABI, FarCallOpcode, Opcode, RetOpcode, CALL_IMPLICIT_CALLDATA_FAT_PTR_REGISTER, - RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER, +use std::{convert::TryFrom, marker::PhantomData, mem}; + +use zk_evm_1_3_3::{ + tracing::{ + AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, + }, + zkevm_opcode_defs::{ + FarCallABI, FarCallOpcode, FatPointer, Opcode, RetOpcode, + CALL_IMPLICIT_CALLDATA_FAT_PTR_REGISTER, RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER, + }, }; use zksync_system_constants::CONTRACT_DEPLOYER_ADDRESS; -use zksync_types::vm_trace::{Call, CallType}; -use zksync_types::U256; +use zksync_types::{ + vm_trace::{Call, CallType}, + U256, +}; + +use crate::vm_1_3_2::{ + errors::VmRevertReason, history_recorder::HistoryMode, memory::SimpleMemory, +}; /// NOTE Auto implementing clone for this tracer can cause stack overflow. /// This is because of the stack field which is a Vec with nested vecs inside. @@ -282,9 +285,10 @@ fn filter_near_call(mut call: Call) -> Vec { #[cfg(test)] mod tests { - use crate::vm_1_3_2::oracles::tracer::call::{filter_near_call, Call, CallType}; use zk_evm_1_3_3::zkevm_opcode_defs::FarCallOpcode; + use crate::vm_1_3_2::oracles::tracer::call::{filter_near_call, Call, CallType}; + #[test] fn test_filter_near_calls() { let mut call = Call::default(); diff --git a/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/mod.rs b/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/mod.rs index 29121f35c5f..5395a0a9d7b 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/mod.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/mod.rs @@ -1,5 +1,15 @@ -use zk_evm_1_3_3::tracing::Tracer; -use zk_evm_1_3_3::vm_state::VmLocalState; +use zk_evm_1_3_3::{tracing::Tracer, vm_state::VmLocalState}; + +pub(crate) use self::transaction_result::TransactionResultTracer; +pub use self::{ + bootloader::BootloaderTracer, + call::CallTracer, + one_tx::OneTxTracer, + validation::{ + ValidationError, ValidationTracer, ValidationTracerParams, ViolatedValidationRule, + }, +}; +use crate::vm_1_3_2::{history_recorder::HistoryMode, memory::SimpleMemory}; mod bootloader; mod call; @@ -8,18 +18,6 @@ mod transaction_result; mod utils; mod validation; -pub use bootloader::BootloaderTracer; -pub use call::CallTracer; -pub use one_tx::OneTxTracer; -pub use validation::{ - ValidationError, ValidationTracer, ValidationTracerParams, ViolatedValidationRule, -}; - -pub(crate) use transaction_result::TransactionResultTracer; - -use crate::vm_1_3_2::history_recorder::HistoryMode; -use crate::vm_1_3_2::memory::SimpleMemory; - pub trait ExecutionEndTracer: Tracer> { // Returns whether the vm execution should stop. fn should_stop_execution(&self) -> bool; diff --git a/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/one_tx.rs b/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/one_tx.rs index a9349ea2035..896befb8abc 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/one_tx.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/one_tx.rs @@ -1,23 +1,23 @@ +use zk_evm_1_3_3::{ + tracing::{ + AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, + }, + vm_state::VmLocalState, +}; +use zksync_types::vm_trace::Call; + use super::utils::{computational_gas_price, print_debug_if_needed}; use crate::vm_1_3_2::{ history_recorder::HistoryMode, memory::SimpleMemory, oracles::tracer::{ utils::{gas_spent_on_bytecodes_and_long_messages_this_opcode, VmHook}, - BootloaderTracer, ExecutionEndTracer, PendingRefundTracer, PubdataSpentTracer, + BootloaderTracer, CallTracer, ExecutionEndTracer, PendingRefundTracer, PubdataSpentTracer, + StorageInvocationTracer, }, vm_instance::get_vm_hook_params, }; -use crate::vm_1_3_2::oracles::tracer::{CallTracer, StorageInvocationTracer}; -use zk_evm_1_3_3::{ - tracing::{ - AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, - }, - vm_state::VmLocalState, -}; -use zksync_types::vm_trace::Call; - /// Allows any opcodes, but tells the VM to end the execution once the tx is over. // Internally depeds on Bootloader's VMHooks to get the notification once the transaction is finished. #[derive(Debug)] diff --git a/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/transaction_result.rs b/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/transaction_result.rs index 215c66bfa74..c74e9bb862d 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/transaction_result.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/transaction_result.rs @@ -7,18 +7,18 @@ use zk_evm_1_3_3::{ }; use zksync_types::{vm_trace, U256}; -use crate::vm_1_3_2::memory::SimpleMemory; -use crate::vm_1_3_2::oracles::tracer::{ - CallTracer, ExecutionEndTracer, PendingRefundTracer, PubdataSpentTracer, - StorageInvocationTracer, -}; -use crate::vm_1_3_2::vm_instance::get_vm_hook_params; use crate::vm_1_3_2::{ history_recorder::HistoryMode, - oracles::tracer::utils::{ - gas_spent_on_bytecodes_and_long_messages_this_opcode, print_debug_if_needed, read_pointer, - VmHook, + memory::SimpleMemory, + oracles::tracer::{ + utils::{ + gas_spent_on_bytecodes_and_long_messages_this_opcode, print_debug_if_needed, + read_pointer, VmHook, + }, + CallTracer, ExecutionEndTracer, PendingRefundTracer, PubdataSpentTracer, + StorageInvocationTracer, }, + vm_instance::get_vm_hook_params, }; #[derive(Debug)] diff --git a/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/utils.rs b/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/utils.rs index 3b3b99991ed..76890b042de 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/utils.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/utils.rs @@ -1,14 +1,9 @@ -use crate::vm_1_3_2::history_recorder::HistoryMode; -use crate::vm_1_3_2::memory::SimpleMemory; -use crate::vm_1_3_2::utils::{aux_heap_page_from_base, heap_page_from_base}; -use crate::vm_1_3_2::vm_instance::{get_vm_hook_params, VM_HOOK_POSITION}; -use crate::vm_1_3_2::vm_with_bootloader::BOOTLOADER_HEAP_PAGE; - -use zk_evm_1_3_3::aux_structures::MemoryPage; -use zk_evm_1_3_3::zkevm_opcode_defs::{FarCallABI, FarCallForwardPageType}; use zk_evm_1_3_3::{ + aux_structures::MemoryPage, tracing::{BeforeExecutionData, VmLocalStateData}, - zkevm_opcode_defs::{FatPointer, LogOpcode, Opcode, UMAOpcode}, + zkevm_opcode_defs::{ + FarCallABI, FarCallForwardPageType, FatPointer, LogOpcode, Opcode, UMAOpcode, + }, }; use zksync_system_constants::{ ECRECOVER_PRECOMPILE_ADDRESS, KECCAK256_PRECOMPILE_ADDRESS, KNOWN_CODES_STORAGE_ADDRESS, @@ -17,6 +12,14 @@ use zksync_system_constants::{ use zksync_types::U256; use zksync_utils::u256_to_h256; +use crate::vm_1_3_2::{ + history_recorder::HistoryMode, + memory::SimpleMemory, + utils::{aux_heap_page_from_base, heap_page_from_base}, + vm_instance::{get_vm_hook_params, VM_HOOK_POSITION}, + vm_with_bootloader::BOOTLOADER_HEAP_PAGE, +}; + #[derive(Clone, Debug, Copy)] pub(crate) enum VmHook { AccountValidationEntered, diff --git a/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/validation.rs b/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/validation.rs index c9ee54f35ba..d3308c7ea2d 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/validation.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/oracles/tracer/validation.rs @@ -1,15 +1,5 @@ use std::{collections::HashSet, fmt::Display, marker::PhantomData}; -use crate::vm_1_3_2::{ - errors::VmRevertReasonParsingResult, - history_recorder::HistoryMode, - memory::SimpleMemory, - oracles::tracer::{ - utils::{computational_gas_price, print_debug_if_needed, VmHook}, - ExecutionEndTracer, PendingRefundTracer, PubdataSpentTracer, - }, -}; - use zk_evm_1_3_3::{ tracing::{ AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, @@ -17,8 +7,6 @@ use zk_evm_1_3_3::{ zkevm_opcode_defs::{ContextOpcode, FarCallABI, LogOpcode, Opcode}, }; use zksync_state::{StoragePtr, WriteStorage}; - -use crate::vm_1_3_2::oracles::tracer::{utils::get_calldata_page_via_abi, StorageInvocationTracer}; use zksync_system_constants::{ ACCOUNT_CODE_STORAGE_ADDRESS, BOOTLOADER_ADDRESS, CONTRACT_DEPLOYER_ADDRESS, KECCAK256_PRECOMPILE_ADDRESS, L2_ETH_TOKEN_ADDRESS, MSG_VALUE_SIMULATOR_ADDRESS, @@ -31,6 +19,18 @@ use zksync_utils::{ be_bytes_to_safe_address, h256_to_account_address, u256_to_account_address, u256_to_h256, }; +use crate::vm_1_3_2::{ + errors::VmRevertReasonParsingResult, + history_recorder::HistoryMode, + memory::SimpleMemory, + oracles::tracer::{ + utils::{ + computational_gas_price, get_calldata_page_via_abi, print_debug_if_needed, VmHook, + }, + ExecutionEndTracer, PendingRefundTracer, PubdataSpentTracer, StorageInvocationTracer, + }, +}; + #[derive(Debug, Clone, Eq, PartialEq, Copy)] #[allow(clippy::enum_variant_names)] pub enum ValidationTracerMode { diff --git a/core/lib/multivm/src/versions/vm_1_3_2/pubdata_utils.rs b/core/lib/multivm/src/versions/vm_1_3_2/pubdata_utils.rs index 936b85bfc09..23d42fc2b5a 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/pubdata_utils.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/pubdata_utils.rs @@ -1,14 +1,18 @@ -use crate::vm_1_3_2::history_recorder::HistoryMode; -use crate::vm_1_3_2::oracles::storage::storage_key_of_log; -use crate::vm_1_3_2::VmInstance; use std::collections::HashMap; + use zk_evm_1_3_3::aux_structures::Timestamp; use zksync_state::WriteStorage; -use zksync_types::event::{extract_long_l2_to_l1_messages, extract_published_bytecodes}; -use zksync_types::zkevm_test_harness::witness::sort_storage_access::sort_storage_access_queries; -use zksync_types::{StorageKey, PUBLISH_BYTECODE_OVERHEAD, SYSTEM_CONTEXT_ADDRESS}; +use zksync_types::{ + event::{extract_long_l2_to_l1_messages, extract_published_bytecodes}, + zkevm_test_harness::witness::sort_storage_access::sort_storage_access_queries, + StorageKey, PUBLISH_BYTECODE_OVERHEAD, SYSTEM_CONTEXT_ADDRESS, +}; use zksync_utils::bytecode::bytecode_len_in_bytes; +use crate::vm_1_3_2::{ + history_recorder::HistoryMode, oracles::storage::storage_key_of_log, VmInstance, +}; + impl VmInstance { pub fn pubdata_published(&self, from_timestamp: Timestamp) -> u32 { let storage_writes_pubdata_published = self.pubdata_published_for_writes(from_timestamp); diff --git a/core/lib/multivm/src/versions/vm_1_3_2/refunds.rs b/core/lib/multivm/src/versions/vm_1_3_2/refunds.rs index 0277379143b..9de2ee9676b 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/refunds.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/refunds.rs @@ -1,13 +1,14 @@ -use crate::vm_1_3_2::history_recorder::HistoryMode; -use crate::vm_1_3_2::vm_with_bootloader::{ - eth_price_per_pubdata_byte, BOOTLOADER_HEAP_PAGE, TX_GAS_LIMIT_OFFSET, -}; -use crate::vm_1_3_2::VmInstance; use zk_evm_1_3_3::aux_structures::Timestamp; use zksync_state::WriteStorage; use zksync_types::U256; use zksync_utils::ceil_div_u256; +use crate::vm_1_3_2::{ + history_recorder::HistoryMode, + vm_with_bootloader::{eth_price_per_pubdata_byte, BOOTLOADER_HEAP_PAGE, TX_GAS_LIMIT_OFFSET}, + VmInstance, +}; + impl VmInstance { pub(crate) fn tx_body_refund( &self, diff --git a/core/lib/multivm/src/versions/vm_1_3_2/test_utils.rs b/core/lib/multivm/src/versions/vm_1_3_2/test_utils.rs index e697e3b310d..c3aa161543a 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/test_utils.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/test_utils.rs @@ -10,8 +10,10 @@ use std::collections::HashMap; use itertools::Itertools; use zk_evm_1_3_3::{aux_structures::Timestamp, vm_state::VmLocalState}; -use zksync_contracts::test_contracts::LoadnextContractExecutionParams; -use zksync_contracts::{deployer_contract, get_loadnext_contract, load_contract}; +use zksync_contracts::{ + deployer_contract, get_loadnext_contract, load_contract, + test_contracts::LoadnextContractExecutionParams, +}; use zksync_state::WriteStorage; use zksync_types::{ ethabi::{Address, Token}, diff --git a/core/lib/multivm/src/versions/vm_1_3_2/transaction_data.rs b/core/lib/multivm/src/versions/vm_1_3_2/transaction_data.rs index d3a96dc06a7..f2c8f278f56 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/transaction_data.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/transaction_data.rs @@ -1,12 +1,14 @@ use zk_evm_1_3_3::zkevm_opcode_defs::system_params::MAX_TX_ERGS_LIMIT; -use zksync_types::ethabi::{encode, Address, Token}; -use zksync_types::fee::encoding_len; use zksync_types::{ - l1::is_l1_tx_type, l2::TransactionType, ExecuteTransactionCommon, Transaction, U256, + ethabi::{encode, Address, Token}, + fee::encoding_len, + l1::is_l1_tx_type, + l2::TransactionType, + ExecuteTransactionCommon, Transaction, MAX_L2_TX_GAS_LIMIT, MAX_TXS_IN_BLOCK, U256, +}; +use zksync_utils::{ + address_to_h256, bytecode::hash_bytecode, bytes_to_be_words, ceil_div_u256, h256_to_u256, }; -use zksync_types::{MAX_L2_TX_GAS_LIMIT, MAX_TXS_IN_BLOCK}; -use zksync_utils::{address_to_h256, ceil_div_u256}; -use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256}; use crate::vm_1_3_2::vm_with_bootloader::{ BLOCK_OVERHEAD_GAS, BLOCK_OVERHEAD_PUBDATA, BOOTLOADER_TX_ENCODING_SPACE, diff --git a/core/lib/multivm/src/versions/vm_1_3_2/utils.rs b/core/lib/multivm/src/versions/vm_1_3_2/utils.rs index 44be1b9c8b9..d0a51cde7fa 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/utils.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/utils.rs @@ -1,13 +1,7 @@ -use crate::vm_1_3_2::history_recorder::HistoryMode; -use crate::vm_1_3_2::{ - memory::SimpleMemory, oracles::tracer::PubdataSpentTracer, vm_with_bootloader::BlockContext, - VmInstance, -}; use once_cell::sync::Lazy; - -use zk_evm_1_3_3::block_properties::BlockProperties; use zk_evm_1_3_3::{ aux_structures::{MemoryPage, Timestamp}, + block_properties::BlockProperties, vm_state::PrimitiveValue, zkevm_opcode_defs::FatPointer, }; @@ -17,6 +11,11 @@ use zksync_system_constants::ZKPORTER_IS_AVAILABLE; use zksync_types::{Address, H160, MAX_L2_TX_GAS_LIMIT, U256}; use zksync_utils::h256_to_u256; +use crate::vm_1_3_2::{ + history_recorder::HistoryMode, memory::SimpleMemory, oracles::tracer::PubdataSpentTracer, + vm_with_bootloader::BlockContext, VmInstance, +}; + pub const INITIAL_TIMESTAMP: u32 = 1024; pub const INITIAL_MEMORY_COUNTER: u32 = 2048; pub const INITIAL_CALLDATA_PAGE: u32 = 7; diff --git a/core/lib/multivm/src/versions/vm_1_3_2/vm.rs b/core/lib/multivm/src/versions/vm_1_3_2/vm.rs index 84b84d3e31a..f0cf5d9c1aa 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/vm.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/vm.rs @@ -1,21 +1,24 @@ -use crate::interface::{ - BootloaderMemory, BytecodeCompressionError, CurrentExecutionState, FinishedL1Batch, L1BatchEnv, - L2BlockEnv, SystemEnv, TxExecutionMode, VmExecutionMode, VmExecutionResultAndLogs, VmInterface, - VmInterfaceHistoryEnabled, VmMemoryMetrics, -}; - use std::collections::HashSet; use zksync_state::{StoragePtr, WriteStorage}; -use zksync_types::l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}; -use zksync_types::Transaction; -use zksync_utils::bytecode::{hash_bytecode, CompressedBytecodeInfo}; -use zksync_utils::{h256_to_u256, u256_to_h256}; - -use crate::glue::history_mode::HistoryMode; -use crate::glue::GlueInto; -use crate::vm_1_3_2::events::merge_events; -use crate::vm_1_3_2::VmInstance; +use zksync_types::{ + l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}, + Transaction, +}; +use zksync_utils::{ + bytecode::{hash_bytecode, CompressedBytecodeInfo}, + h256_to_u256, u256_to_h256, +}; + +use crate::{ + glue::{history_mode::HistoryMode, GlueInto}, + interface::{ + BootloaderMemory, BytecodeCompressionError, CurrentExecutionState, FinishedL1Batch, + L1BatchEnv, L2BlockEnv, SystemEnv, TxExecutionMode, VmExecutionMode, + VmExecutionResultAndLogs, VmInterface, VmInterfaceHistoryEnabled, VmMemoryMetrics, + }, + vm_1_3_2::{events::merge_events, VmInstance}, +}; #[derive(Debug)] pub struct Vm { diff --git a/core/lib/multivm/src/versions/vm_1_3_2/vm_instance.rs b/core/lib/multivm/src/versions/vm_1_3_2/vm_instance.rs index 8b7c416522e..2217b4f50d6 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/vm_instance.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/vm_instance.rs @@ -1,43 +1,52 @@ -use std::convert::TryFrom; -use std::fmt::Debug; - -use zk_evm_1_3_3::aux_structures::Timestamp; -use zk_evm_1_3_3::vm_state::{PrimitiveValue, VmLocalState, VmState}; -use zk_evm_1_3_3::witness_trace::DummyTracer; -use zk_evm_1_3_3::zkevm_opcode_defs::decoding::{ - AllowedPcOrImm, EncodingModeProduction, VmEncodingMode, +use std::{convert::TryFrom, fmt::Debug}; + +use zk_evm_1_3_3::{ + aux_structures::Timestamp, + vm_state::{PrimitiveValue, VmLocalState, VmState}, + witness_trace::DummyTracer, + zkevm_opcode_defs::{ + decoding::{AllowedPcOrImm, EncodingModeProduction, VmEncodingMode}, + definitions::RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER, + }, }; -use zk_evm_1_3_3::zkevm_opcode_defs::definitions::RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER; use zksync_state::WriteStorage; use zksync_system_constants::MAX_TXS_IN_BLOCK; -use zksync_types::l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}; -use zksync_types::tx::tx_execution_info::TxExecutionStatus; -use zksync_types::vm_trace::{Call, VmExecutionTrace, VmTrace}; -use zksync_types::{L1BatchNumber, StorageLogQuery, VmEvent, H256, U256}; - -use crate::interface::types::outputs::VmExecutionLogs; -use crate::vm_1_3_2::bootloader_state::BootloaderState; -use crate::vm_1_3_2::errors::{TxRevertReason, VmRevertReason, VmRevertReasonParsingResult}; -use crate::vm_1_3_2::event_sink::InMemoryEventSink; -use crate::vm_1_3_2::events::merge_events; -use crate::vm_1_3_2::history_recorder::{HistoryEnabled, HistoryMode}; -use crate::vm_1_3_2::memory::SimpleMemory; -use crate::vm_1_3_2::oracles::decommitter::DecommitterOracle; -use crate::vm_1_3_2::oracles::precompile::PrecompilesProcessorWithHistory; -use crate::vm_1_3_2::oracles::storage::StorageOracle; -use crate::vm_1_3_2::oracles::tracer::{ - BootloaderTracer, ExecutionEndTracer, OneTxTracer, PendingRefundTracer, PubdataSpentTracer, - StorageInvocationTracer, TransactionResultTracer, ValidationError, ValidationTracer, - ValidationTracerParams, +use zksync_types::{ + l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}, + tx::tx_execution_info::TxExecutionStatus, + vm_trace::{Call, VmExecutionTrace, VmTrace}, + L1BatchNumber, StorageLogQuery, VmEvent, H256, U256, }; -use crate::vm_1_3_2::oracles::OracleWithHistory; -use crate::vm_1_3_2::utils::{ - calculate_computational_gas_used, dump_memory_page_using_primitive_value, - precompile_calls_count_after_timestamp, -}; -use crate::vm_1_3_2::vm_with_bootloader::{ - BootloaderJobType, DerivedBlockContext, TxExecutionMode, BOOTLOADER_HEAP_PAGE, - OPERATOR_REFUNDS_OFFSET, + +use crate::{ + interface::types::outputs::VmExecutionLogs, + vm_1_3_2::{ + bootloader_state::BootloaderState, + errors::{TxRevertReason, VmRevertReason, VmRevertReasonParsingResult}, + event_sink::InMemoryEventSink, + events::merge_events, + history_recorder::{HistoryEnabled, HistoryMode}, + memory::SimpleMemory, + oracles::{ + decommitter::DecommitterOracle, + precompile::PrecompilesProcessorWithHistory, + storage::StorageOracle, + tracer::{ + BootloaderTracer, ExecutionEndTracer, OneTxTracer, PendingRefundTracer, + PubdataSpentTracer, StorageInvocationTracer, TransactionResultTracer, + ValidationError, ValidationTracer, ValidationTracerParams, + }, + OracleWithHistory, + }, + utils::{ + calculate_computational_gas_used, dump_memory_page_using_primitive_value, + precompile_calls_count_after_timestamp, + }, + vm_with_bootloader::{ + BootloaderJobType, DerivedBlockContext, TxExecutionMode, BOOTLOADER_HEAP_PAGE, + OPERATOR_REFUNDS_OFFSET, + }, + }, }; pub type ZkSyncVmState = VmState< diff --git a/core/lib/multivm/src/versions/vm_1_3_2/vm_with_bootloader.rs b/core/lib/multivm/src/versions/vm_1_3_2/vm_with_bootloader.rs index c2ff035c669..71c108cae32 100644 --- a/core/lib/multivm/src/versions/vm_1_3_2/vm_with_bootloader.rs +++ b/core/lib/multivm/src/versions/vm_1_3_2/vm_with_bootloader.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; +use itertools::Itertools; use zk_evm_1_3_3::{ aux_structures::{MemoryPage, Timestamp}, block_properties::BlockProperties, @@ -11,8 +12,8 @@ use zk_evm_1_3_3::{ }, }; use zksync_contracts::BaseSystemContracts; +use zksync_state::WriteStorage; use zksync_system_constants::MAX_TXS_IN_BLOCK; - use zksync_types::{ l1::is_l1_tx_type, zkevm_test_harness::INITIAL_MONOTONIC_CYCLE_COUNTER, Address, Transaction, BOOTLOADER_ADDRESS, L1_GAS_PER_PUBDATA_BYTE, MAX_GAS_PER_PUBDATA_BYTE, MAX_NEW_FACTORY_DEPS, @@ -25,9 +26,6 @@ use zksync_utils::{ misc::ceil_div, }; -use itertools::Itertools; -use zksync_state::WriteStorage; - use crate::vm_1_3_2::{ bootloader_state::BootloaderState, history_recorder::HistoryMode, diff --git a/core/lib/multivm/src/versions/vm_latest/bootloader_state/l2_block.rs b/core/lib/multivm/src/versions/vm_latest/bootloader_state/l2_block.rs index 6da9b64673e..146e8713c69 100644 --- a/core/lib/multivm/src/versions/vm_latest/bootloader_state/l2_block.rs +++ b/core/lib/multivm/src/versions/vm_latest/bootloader_state/l2_block.rs @@ -1,11 +1,15 @@ use std::cmp::Ordering; + use zksync_types::{MiniblockNumber, H256}; use zksync_utils::concat_and_hash; -use crate::interface::{L2Block, L2BlockEnv}; -use crate::vm_latest::bootloader_state::snapshot::L2BlockSnapshot; -use crate::vm_latest::bootloader_state::tx::BootloaderTx; -use crate::vm_latest::utils::l2_blocks::l2_block_hash; +use crate::{ + interface::{L2Block, L2BlockEnv}, + vm_latest::{ + bootloader_state::{snapshot::L2BlockSnapshot, tx::BootloaderTx}, + utils::l2_blocks::l2_block_hash, + }, +}; const EMPTY_TXS_ROLLING_HASH: H256 = H256::zero(); diff --git a/core/lib/multivm/src/versions/vm_latest/bootloader_state/state.rs b/core/lib/multivm/src/versions/vm_latest/bootloader_state/state.rs index b4641d9bc64..14e693a1d2e 100644 --- a/core/lib/multivm/src/versions/vm_latest/bootloader_state/state.rs +++ b/core/lib/multivm/src/versions/vm_latest/bootloader_state/state.rs @@ -1,20 +1,24 @@ -use crate::vm_latest::bootloader_state::l2_block::BootloaderL2Block; -use crate::vm_latest::bootloader_state::snapshot::BootloaderStateSnapshot; -use crate::vm_latest::bootloader_state::utils::{apply_l2_block, apply_tx_to_memory}; -use once_cell::sync::OnceCell; use std::cmp::Ordering; + +use once_cell::sync::OnceCell; use zksync_types::{L2ChainId, U256}; use zksync_utils::bytecode::CompressedBytecodeInfo; -use crate::interface::{BootloaderMemory, L2BlockEnv, TxExecutionMode}; -use crate::vm_latest::types::internals::pubdata::PubdataInput; -use crate::vm_latest::{ - constants::TX_DESCRIPTION_OFFSET, types::internals::TransactionData, - utils::l2_blocks::assert_next_block, +use super::{tx::BootloaderTx, utils::apply_pubdata_to_memory}; +use crate::{ + interface::{BootloaderMemory, L2BlockEnv, TxExecutionMode}, + vm_latest::{ + bootloader_state::{ + l2_block::BootloaderL2Block, + snapshot::BootloaderStateSnapshot, + utils::{apply_l2_block, apply_tx_to_memory}, + }, + constants::TX_DESCRIPTION_OFFSET, + types::internals::{pubdata::PubdataInput, TransactionData}, + utils::l2_blocks::assert_next_block, + }, }; -use super::tx::BootloaderTx; -use super::utils::apply_pubdata_to_memory; /// Intermediate bootloader-related VM state. /// /// Required to process transactions one by one (since we intercept the VM execution to execute diff --git a/core/lib/multivm/src/versions/vm_latest/bootloader_state/tx.rs b/core/lib/multivm/src/versions/vm_latest/bootloader_state/tx.rs index dce0ecce3fb..21aee75b38b 100644 --- a/core/lib/multivm/src/versions/vm_latest/bootloader_state/tx.rs +++ b/core/lib/multivm/src/versions/vm_latest/bootloader_state/tx.rs @@ -1,7 +1,8 @@ -use crate::vm_latest::types::internals::TransactionData; use zksync_types::{L2ChainId, H256, U256}; use zksync_utils::bytecode::CompressedBytecodeInfo; +use crate::vm_latest::types::internals::TransactionData; + /// Information about tx necessary for execution in bootloader. #[derive(Debug, Clone)] pub(super) struct BootloaderTx { diff --git a/core/lib/multivm/src/versions/vm_latest/bootloader_state/utils.rs b/core/lib/multivm/src/versions/vm_latest/bootloader_state/utils.rs index 7e76f3faeff..16776be444e 100644 --- a/core/lib/multivm/src/versions/vm_latest/bootloader_state/utils.rs +++ b/core/lib/multivm/src/versions/vm_latest/bootloader_state/utils.rs @@ -1,18 +1,21 @@ use zksync_types::U256; -use zksync_utils::bytecode::CompressedBytecodeInfo; -use zksync_utils::{bytes_to_be_words, h256_to_u256}; - -use crate::interface::{BootloaderMemory, TxExecutionMode}; -use crate::vm_latest::bootloader_state::l2_block::BootloaderL2Block; -use crate::vm_latest::constants::{ - BOOTLOADER_TX_DESCRIPTION_OFFSET, BOOTLOADER_TX_DESCRIPTION_SIZE, COMPRESSED_BYTECODES_OFFSET, - OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_OFFSET, OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_SLOTS, - OPERATOR_REFUNDS_OFFSET, TX_DESCRIPTION_OFFSET, TX_OPERATOR_L2_BLOCK_INFO_OFFSET, - TX_OPERATOR_SLOTS_PER_L2_BLOCK_INFO, TX_OVERHEAD_OFFSET, TX_TRUSTED_GAS_LIMIT_OFFSET, -}; -use crate::vm_latest::types::internals::pubdata::PubdataInput; +use zksync_utils::{bytecode::CompressedBytecodeInfo, bytes_to_be_words, h256_to_u256}; use super::tx::BootloaderTx; +use crate::{ + interface::{BootloaderMemory, TxExecutionMode}, + vm_latest::{ + bootloader_state::l2_block::BootloaderL2Block, + constants::{ + BOOTLOADER_TX_DESCRIPTION_OFFSET, BOOTLOADER_TX_DESCRIPTION_SIZE, + COMPRESSED_BYTECODES_OFFSET, OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_OFFSET, + OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_SLOTS, OPERATOR_REFUNDS_OFFSET, + TX_DESCRIPTION_OFFSET, TX_OPERATOR_L2_BLOCK_INFO_OFFSET, + TX_OPERATOR_SLOTS_PER_L2_BLOCK_INFO, TX_OVERHEAD_OFFSET, TX_TRUSTED_GAS_LIMIT_OFFSET, + }, + types::internals::pubdata::PubdataInput, + }, +}; pub(super) fn get_memory_for_compressed_bytecodes( compressed_bytecodes: &[CompressedBytecodeInfo], diff --git a/core/lib/multivm/src/versions/vm_latest/constants.rs b/core/lib/multivm/src/versions/vm_latest/constants.rs index 4d1c7705423..44266344be6 100644 --- a/core/lib/multivm/src/versions/vm_latest/constants.rs +++ b/core/lib/multivm/src/versions/vm_latest/constants.rs @@ -1,14 +1,12 @@ use zk_evm_1_4_0::aux_structures::MemoryPage; - +pub use zk_evm_1_4_0::zkevm_opcode_defs::system_params::{ + ERGS_PER_CIRCUIT, INITIAL_STORAGE_WRITE_PUBDATA_BYTES, MAX_PUBDATA_PER_BLOCK, +}; use zksync_system_constants::{ L1_GAS_PER_PUBDATA_BYTE, MAX_L2_TX_GAS_LIMIT, MAX_NEW_FACTORY_DEPS, MAX_TXS_IN_BLOCK, USED_BOOTLOADER_MEMORY_WORDS, }; -pub use zk_evm_1_4_0::zkevm_opcode_defs::system_params::{ - ERGS_PER_CIRCUIT, INITIAL_STORAGE_WRITE_PUBDATA_BYTES, MAX_PUBDATA_PER_BLOCK, -}; - use crate::vm_latest::old_vm::utils::heap_page_from_base; /// Max cycles for a single transaction. diff --git a/core/lib/multivm/src/versions/vm_latest/implementation/bytecode.rs b/core/lib/multivm/src/versions/vm_latest/implementation/bytecode.rs index 83a7be74897..bda1803067f 100644 --- a/core/lib/multivm/src/versions/vm_latest/implementation/bytecode.rs +++ b/core/lib/multivm/src/versions/vm_latest/implementation/bytecode.rs @@ -1,13 +1,12 @@ use itertools::Itertools; - -use crate::interface::VmInterface; -use crate::HistoryMode; use zksync_state::{StoragePtr, WriteStorage}; use zksync_types::U256; -use zksync_utils::bytecode::{compress_bytecode, hash_bytecode, CompressedBytecodeInfo}; -use zksync_utils::bytes_to_be_words; +use zksync_utils::{ + bytecode::{compress_bytecode, hash_bytecode, CompressedBytecodeInfo}, + bytes_to_be_words, +}; -use crate::vm_latest::Vm; +use crate::{interface::VmInterface, vm_latest::Vm, HistoryMode}; impl Vm { /// Checks the last transaction has successfully published compressed bytecodes and returns `true` if there is at least one is still unknown. diff --git a/core/lib/multivm/src/versions/vm_latest/implementation/execution.rs b/core/lib/multivm/src/versions/vm_latest/implementation/execution.rs index 1b3197f57b9..a913ea3ed46 100644 --- a/core/lib/multivm/src/versions/vm_latest/implementation/execution.rs +++ b/core/lib/multivm/src/versions/vm_latest/implementation/execution.rs @@ -1,15 +1,19 @@ -use crate::HistoryMode; use zk_evm_1_4_0::aux_structures::Timestamp; use zksync_state::WriteStorage; -use crate::interface::{ - types::tracer::{TracerExecutionStatus, VmExecutionStopReason}, - VmExecutionMode, VmExecutionResultAndLogs, -}; -use crate::vm_latest::{ - old_vm::utils::{vm_may_have_ended_inner, VmExecutionResult}, - tracers::{dispatcher::TracerDispatcher, DefaultExecutionTracer, PubdataTracer, RefundsTracer}, - vm::Vm, +use crate::{ + interface::{ + types::tracer::{TracerExecutionStatus, VmExecutionStopReason}, + VmExecutionMode, VmExecutionResultAndLogs, + }, + vm_latest::{ + old_vm::utils::{vm_may_have_ended_inner, VmExecutionResult}, + tracers::{ + dispatcher::TracerDispatcher, DefaultExecutionTracer, PubdataTracer, RefundsTracer, + }, + vm::Vm, + }, + HistoryMode, }; impl Vm { diff --git a/core/lib/multivm/src/versions/vm_latest/implementation/gas.rs b/core/lib/multivm/src/versions/vm_latest/implementation/gas.rs index c970cd4e5d2..526eab76f07 100644 --- a/core/lib/multivm/src/versions/vm_latest/implementation/gas.rs +++ b/core/lib/multivm/src/versions/vm_latest/implementation/gas.rs @@ -1,8 +1,9 @@ -use crate::HistoryMode; use zksync_state::WriteStorage; -use crate::vm_latest::tracers::DefaultExecutionTracer; -use crate::vm_latest::vm::Vm; +use crate::{ + vm_latest::{tracers::DefaultExecutionTracer, vm::Vm}, + HistoryMode, +}; impl Vm { /// Returns the amount of gas remaining to the VM. diff --git a/core/lib/multivm/src/versions/vm_latest/implementation/logs.rs b/core/lib/multivm/src/versions/vm_latest/implementation/logs.rs index c468cf87817..9e0817aa939 100644 --- a/core/lib/multivm/src/versions/vm_latest/implementation/logs.rs +++ b/core/lib/multivm/src/versions/vm_latest/implementation/logs.rs @@ -1,16 +1,16 @@ use zk_evm_1_4_0::aux_structures::Timestamp; use zksync_state::WriteStorage; -use zksync_types::event::extract_l2tol1logs_from_l1_messenger; +use zksync_types::{ + event::extract_l2tol1logs_from_l1_messenger, + l2_to_l1_log::{L2ToL1Log, SystemL2ToL1Log, UserL2ToL1Log}, + VmEvent, +}; -use crate::HistoryMode; -use zksync_types::l2_to_l1_log::{L2ToL1Log, SystemL2ToL1Log, UserL2ToL1Log}; -use zksync_types::VmEvent; - -use crate::interface::types::outputs::VmExecutionLogs; - -use crate::vm_latest::old_vm::utils::precompile_calls_count_after_timestamp; -use crate::vm_latest::utils::logs; -use crate::vm_latest::vm::Vm; +use crate::{ + interface::types::outputs::VmExecutionLogs, + vm_latest::{old_vm::utils::precompile_calls_count_after_timestamp, utils::logs, vm::Vm}, + HistoryMode, +}; impl Vm { pub(crate) fn collect_execution_logs_after_timestamp( diff --git a/core/lib/multivm/src/versions/vm_latest/implementation/snapshots.rs b/core/lib/multivm/src/versions/vm_latest/implementation/snapshots.rs index 99d41a2aec6..b6b45283438 100644 --- a/core/lib/multivm/src/versions/vm_latest/implementation/snapshots.rs +++ b/core/lib/multivm/src/versions/vm_latest/implementation/snapshots.rs @@ -1,7 +1,6 @@ -use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; - use std::time::Duration; +use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; use zk_evm_1_4_0::aux_structures::Timestamp; use zksync_state::WriteStorage; diff --git a/core/lib/multivm/src/versions/vm_latest/implementation/statistics.rs b/core/lib/multivm/src/versions/vm_latest/implementation/statistics.rs index 92604479a88..6af9ad041fe 100644 --- a/core/lib/multivm/src/versions/vm_latest/implementation/statistics.rs +++ b/core/lib/multivm/src/versions/vm_latest/implementation/statistics.rs @@ -1,12 +1,12 @@ use zk_evm_1_4_0::aux_structures::Timestamp; use zksync_state::WriteStorage; - -use crate::HistoryMode; use zksync_types::U256; -use crate::interface::{VmExecutionStatistics, VmMemoryMetrics}; -use crate::vm_latest::tracers::DefaultExecutionTracer; -use crate::vm_latest::vm::Vm; +use crate::{ + interface::{VmExecutionStatistics, VmMemoryMetrics}, + vm_latest::{tracers::DefaultExecutionTracer, vm::Vm}, + HistoryMode, +}; /// Module responsible for observing the VM behavior, i.e. calculating the statistics of the VM runs /// or reporting the VM memory usage. diff --git a/core/lib/multivm/src/versions/vm_latest/implementation/tx.rs b/core/lib/multivm/src/versions/vm_latest/implementation/tx.rs index 6def1da0f5d..326be41c5ee 100644 --- a/core/lib/multivm/src/versions/vm_latest/implementation/tx.rs +++ b/core/lib/multivm/src/versions/vm_latest/implementation/tx.rs @@ -1,13 +1,16 @@ -use crate::vm_latest::constants::BOOTLOADER_HEAP_PAGE; -use crate::vm_latest::implementation::bytecode::{bytecode_to_factory_dep, compress_bytecodes}; -use crate::HistoryMode; use zk_evm_1_4_0::aux_structures::Timestamp; use zksync_state::WriteStorage; -use zksync_types::l1::is_l1_tx_type; -use zksync_types::Transaction; +use zksync_types::{l1::is_l1_tx_type, Transaction}; -use crate::vm_latest::types::internals::TransactionData; -use crate::vm_latest::vm::Vm; +use crate::{ + vm_latest::{ + constants::BOOTLOADER_HEAP_PAGE, + implementation::bytecode::{bytecode_to_factory_dep, compress_bytecodes}, + types::internals::TransactionData, + vm::Vm, + }, + HistoryMode, +}; impl Vm { pub(crate) fn push_raw_transaction( diff --git a/core/lib/multivm/src/versions/vm_latest/mod.rs b/core/lib/multivm/src/versions/vm_latest/mod.rs index 49cd7111f6f..0b4919f83d7 100644 --- a/core/lib/multivm/src/versions/vm_latest/mod.rs +++ b/core/lib/multivm/src/versions/vm_latest/mod.rs @@ -1,15 +1,18 @@ -pub use old_vm::{ - history_recorder::{HistoryDisabled, HistoryEnabled, HistoryMode}, - memory::SimpleMemory, -}; - -pub use oracles::storage::StorageOracle; - -pub use tracers::{ - dispatcher::TracerDispatcher, - traits::{ToTracerPointer, TracerPointer, VmTracer}, +pub use self::{ + bootloader_state::BootloaderState, + old_vm::{ + history_recorder::{HistoryDisabled, HistoryEnabled, HistoryMode}, + memory::SimpleMemory, + }, + oracles::storage::StorageOracle, + tracers::{ + dispatcher::TracerDispatcher, + traits::{ToTracerPointer, TracerPointer, VmTracer}, + }, + types::internals::ZkSyncVmState, + utils::transaction_encoding::TransactionVmExt, + vm::Vm, }; - pub use crate::interface::types::{ inputs::{L1BatchEnv, L2BlockEnv, SystemEnv, TxExecutionMode, VmExecutionMode}, outputs::{ @@ -17,23 +20,15 @@ pub use crate::interface::types::{ Refunds, VmExecutionLogs, VmExecutionResultAndLogs, VmExecutionStatistics, VmMemoryMetrics, }, }; -pub use types::internals::ZkSyncVmState; -pub use utils::transaction_encoding::TransactionVmExt; - -pub use bootloader_state::BootloaderState; - -pub use vm::Vm; mod bootloader_state; +pub mod constants; mod implementation; mod old_vm; mod oracles; +#[cfg(test)] +mod tests; pub(crate) mod tracers; mod types; -mod vm; - -pub mod constants; pub mod utils; - -#[cfg(test)] -mod tests; +mod vm; diff --git a/core/lib/multivm/src/versions/vm_latest/old_vm/event_sink.rs b/core/lib/multivm/src/versions/vm_latest/old_vm/event_sink.rs index 4174d9f4f17..8e7f4d447b4 100644 --- a/core/lib/multivm/src/versions/vm_latest/old_vm/event_sink.rs +++ b/core/lib/multivm/src/versions/vm_latest/old_vm/event_sink.rs @@ -1,9 +1,6 @@ -use crate::vm_latest::old_vm::{ - history_recorder::{AppDataFrameManagerWithHistory, HistoryEnabled, HistoryMode}, - oracles::OracleWithHistory, -}; -use itertools::Itertools; use std::collections::HashMap; + +use itertools::Itertools; use zk_evm_1_4_0::{ abstractions::EventSink, aux_structures::{LogQuery, Timestamp}, @@ -14,6 +11,11 @@ use zk_evm_1_4_0::{ }; use zksync_types::U256; +use crate::vm_latest::old_vm::{ + history_recorder::{AppDataFrameManagerWithHistory, HistoryEnabled, HistoryMode}, + oracles::OracleWithHistory, +}; + #[derive(Debug, Clone, PartialEq, Default)] pub struct InMemoryEventSink { frames_stack: AppDataFrameManagerWithHistory, H>, diff --git a/core/lib/multivm/src/versions/vm_latest/old_vm/history_recorder.rs b/core/lib/multivm/src/versions/vm_latest/old_vm/history_recorder.rs index 7c0490044d6..2253831b745 100644 --- a/core/lib/multivm/src/versions/vm_latest/old_vm/history_recorder.rs +++ b/core/lib/multivm/src/versions/vm_latest/old_vm/history_recorder.rs @@ -5,7 +5,6 @@ use zk_evm_1_4_0::{ vm_state::PrimitiveValue, zkevm_opcode_defs::{self}, }; - use zksync_state::{StoragePtr, WriteStorage}; use zksync_types::{StorageKey, U256}; use zksync_utils::{h256_to_u256, u256_to_h256}; @@ -771,11 +770,14 @@ impl HistoryRecorder, H> { #[cfg(test)] mod tests { - use crate::vm_latest::old_vm::history_recorder::{HistoryRecorder, MemoryWrapper}; - use crate::vm_latest::HistoryDisabled; use zk_evm_1_4_0::{aux_structures::Timestamp, vm_state::PrimitiveValue}; use zksync_types::U256; + use crate::vm_latest::{ + old_vm::history_recorder::{HistoryRecorder, MemoryWrapper}, + HistoryDisabled, + }; + #[test] fn memory_equality() { let mut a: HistoryRecorder = Default::default(); diff --git a/core/lib/multivm/src/versions/vm_latest/old_vm/memory.rs b/core/lib/multivm/src/versions/vm_latest/old_vm/memory.rs index 5694a725d93..5a7592ce965 100644 --- a/core/lib/multivm/src/versions/vm_latest/old_vm/memory.rs +++ b/core/lib/multivm/src/versions/vm_latest/old_vm/memory.rs @@ -1,16 +1,18 @@ -use zk_evm_1_4_0::abstractions::{Memory, MemoryType}; -use zk_evm_1_4_0::aux_structures::{MemoryPage, MemoryQuery, Timestamp}; -use zk_evm_1_4_0::vm_state::PrimitiveValue; -use zk_evm_1_4_0::zkevm_opcode_defs::FatPointer; +use zk_evm_1_4_0::{ + abstractions::{Memory, MemoryType}, + aux_structures::{MemoryPage, MemoryQuery, Timestamp}, + vm_state::PrimitiveValue, + zkevm_opcode_defs::FatPointer, +}; use zksync_types::U256; -use crate::vm_latest::old_vm::history_recorder::{ - FramedStack, HistoryEnabled, HistoryMode, IntFrameManagerWithHistory, MemoryWithHistory, - MemoryWrapper, WithHistory, -}; -use crate::vm_latest::old_vm::oracles::OracleWithHistory; -use crate::vm_latest::old_vm::utils::{ - aux_heap_page_from_base, heap_page_from_base, stack_page_from_base, +use crate::vm_latest::old_vm::{ + history_recorder::{ + FramedStack, HistoryEnabled, HistoryMode, IntFrameManagerWithHistory, MemoryWithHistory, + MemoryWrapper, WithHistory, + }, + oracles::OracleWithHistory, + utils::{aux_heap_page_from_base, heap_page_from_base, stack_page_from_base}, }; #[derive(Debug, Clone, PartialEq)] diff --git a/core/lib/multivm/src/versions/vm_latest/old_vm/oracles/decommitter.rs b/core/lib/multivm/src/versions/vm_latest/old_vm/oracles/decommitter.rs index c679532fa76..4a718917a21 100644 --- a/core/lib/multivm/src/versions/vm_latest/old_vm/oracles/decommitter.rs +++ b/core/lib/multivm/src/versions/vm_latest/old_vm/oracles/decommitter.rs @@ -1,23 +1,19 @@ -use std::collections::HashMap; -use std::fmt::Debug; +use std::{collections::HashMap, fmt::Debug}; -use crate::vm_latest::old_vm::history_recorder::{ - HistoryEnabled, HistoryMode, HistoryRecorder, WithHistory, -}; - -use zk_evm_1_4_0::abstractions::MemoryType; -use zk_evm_1_4_0::aux_structures::Timestamp; use zk_evm_1_4_0::{ - abstractions::{DecommittmentProcessor, Memory}, - aux_structures::{DecommittmentQuery, MemoryIndex, MemoryLocation, MemoryPage, MemoryQuery}, + abstractions::{DecommittmentProcessor, Memory, MemoryType}, + aux_structures::{ + DecommittmentQuery, MemoryIndex, MemoryLocation, MemoryPage, MemoryQuery, Timestamp, + }, }; - use zksync_state::{ReadStorage, StoragePtr}; use zksync_types::U256; -use zksync_utils::bytecode::bytecode_len_in_words; -use zksync_utils::{bytes_to_be_words, u256_to_h256}; +use zksync_utils::{bytecode::bytecode_len_in_words, bytes_to_be_words, u256_to_h256}; use super::OracleWithHistory; +use crate::vm_latest::old_vm::history_recorder::{ + HistoryEnabled, HistoryMode, HistoryRecorder, WithHistory, +}; /// The main job of the DecommiterOracle is to implement the DecommittmentProcessor trait - that is /// used by the VM to 'load' bytecodes into memory. diff --git a/core/lib/multivm/src/versions/vm_latest/old_vm/oracles/precompile.rs b/core/lib/multivm/src/versions/vm_latest/old_vm/oracles/precompile.rs index ed3621fc497..92b88e40fc9 100644 --- a/core/lib/multivm/src/versions/vm_latest/old_vm/oracles/precompile.rs +++ b/core/lib/multivm/src/versions/vm_latest/old_vm/oracles/precompile.rs @@ -1,14 +1,11 @@ use zk_evm_1_4_0::{ - abstractions::Memory, - abstractions::PrecompileCyclesWitness, - abstractions::PrecompilesProcessor, + abstractions::{Memory, PrecompileCyclesWitness, PrecompilesProcessor}, aux_structures::{LogQuery, MemoryQuery, Timestamp}, zk_evm_abstractions::precompiles::DefaultPrecompilesProcessor, }; -use crate::vm_latest::old_vm::history_recorder::{HistoryEnabled, HistoryMode, HistoryRecorder}; - use super::OracleWithHistory; +use crate::vm_latest::old_vm::history_recorder::{HistoryEnabled, HistoryMode, HistoryRecorder}; /// Wrap of DefaultPrecompilesProcessor that store queue /// of timestamp when precompiles are called to be executed. diff --git a/core/lib/multivm/src/versions/vm_latest/old_vm/utils.rs b/core/lib/multivm/src/versions/vm_latest/old_vm/utils.rs index afaa19cac87..1dbe82a81d4 100644 --- a/core/lib/multivm/src/versions/vm_latest/old_vm/utils.rs +++ b/core/lib/multivm/src/versions/vm_latest/old_vm/utils.rs @@ -1,22 +1,19 @@ -use crate::vm_latest::old_vm::memory::SimpleMemory; - -use crate::vm_latest::types::internals::ZkSyncVmState; -use crate::vm_latest::HistoryMode; - -use zk_evm_1_4_0::zkevm_opcode_defs::decoding::{ - AllowedPcOrImm, EncodingModeProduction, VmEncodingMode, -}; -use zk_evm_1_4_0::zkevm_opcode_defs::RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER; use zk_evm_1_4_0::{ aux_structures::{MemoryPage, Timestamp}, vm_state::PrimitiveValue, - zkevm_opcode_defs::FatPointer, + zkevm_opcode_defs::{ + decoding::{AllowedPcOrImm, EncodingModeProduction, VmEncodingMode}, + FatPointer, RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER, + }, }; use zksync_state::WriteStorage; use zksync_system_constants::L1_GAS_PER_PUBDATA_BYTE; - use zksync_types::{Address, U256}; +use crate::vm_latest::{ + old_vm::memory::SimpleMemory, types::internals::ZkSyncVmState, HistoryMode, +}; + #[derive(Debug, Clone)] pub(crate) enum VmExecutionResult { Ok(Vec), diff --git a/core/lib/multivm/src/versions/vm_latest/oracles/storage.rs b/core/lib/multivm/src/versions/vm_latest/oracles/storage.rs index beec2fa086f..60516083d29 100644 --- a/core/lib/multivm/src/versions/vm_latest/oracles/storage.rs +++ b/core/lib/multivm/src/versions/vm_latest/oracles/storage.rs @@ -1,28 +1,30 @@ use std::collections::HashMap; -use crate::vm_latest::old_vm::history_recorder::{ - AppDataFrameManagerWithHistory, HashMapHistoryEvent, HistoryEnabled, HistoryMode, - HistoryRecorder, StorageWrapper, VectorHistoryEvent, WithHistory, -}; -use crate::vm_latest::old_vm::oracles::OracleWithHistory; - -use zk_evm_1_4_0::abstractions::RefundedAmounts; -use zk_evm_1_4_0::zkevm_opcode_defs::system_params::INITIAL_STORAGE_WRITE_PUBDATA_BYTES; use zk_evm_1_4_0::{ - abstractions::{RefundType, Storage as VmStorageOracle}, + abstractions::{RefundType, RefundedAmounts, Storage as VmStorageOracle}, aux_structures::{LogQuery, Timestamp}, + zkevm_opcode_defs::system_params::INITIAL_STORAGE_WRITE_PUBDATA_BYTES, }; - use zksync_state::{StoragePtr, WriteStorage}; -use zksync_types::utils::storage_key_for_eth_balance; -use zksync_types::writes::compression::compress_with_best_strategy; -use zksync_types::writes::{BYTES_PER_DERIVED_KEY, BYTES_PER_ENUMERATION_INDEX}; use zksync_types::{ + utils::storage_key_for_eth_balance, + writes::{ + compression::compress_with_best_strategy, BYTES_PER_DERIVED_KEY, + BYTES_PER_ENUMERATION_INDEX, + }, AccountTreeId, Address, StorageKey, StorageLogQuery, StorageLogQueryType, BOOTLOADER_ADDRESS, U256, }; use zksync_utils::u256_to_h256; +use crate::vm_latest::old_vm::{ + history_recorder::{ + AppDataFrameManagerWithHistory, HashMapHistoryEvent, HistoryEnabled, HistoryMode, + HistoryRecorder, StorageWrapper, VectorHistoryEvent, WithHistory, + }, + oracles::OracleWithHistory, +}; + // While the storage does not support different shards, it was decided to write the // code of the StorageOracle with the shard parameters in mind. pub(crate) fn triplet_to_storage_key(_shard_id: u8, address: Address, key: U256) -> StorageKey { diff --git a/core/lib/multivm/src/versions/vm_latest/tests/bootloader.rs b/core/lib/multivm/src/versions/vm_latest/tests/bootloader.rs index b2763f358be..78fb964f722 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/bootloader.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/bootloader.rs @@ -1,15 +1,17 @@ use zksync_types::U256; -use crate::interface::{Halt, TxExecutionMode, VmExecutionMode, VmInterface}; -use crate::vm_latest::constants::BOOTLOADER_HEAP_PAGE; -use crate::vm_latest::tests::tester::VmTesterBuilder; -use crate::vm_latest::tests::utils::{ - get_bootloader, verify_required_memory, BASE_SYSTEM_CONTRACTS, +use crate::{ + interface::{ExecutionResult, Halt, TxExecutionMode, VmExecutionMode, VmInterface}, + vm_latest::{ + constants::BOOTLOADER_HEAP_PAGE, + tests::{ + tester::VmTesterBuilder, + utils::{get_bootloader, verify_required_memory, BASE_SYSTEM_CONTRACTS}, + }, + HistoryEnabled, + }, }; -use crate::interface::ExecutionResult; -use crate::vm_latest::HistoryEnabled; - #[test] fn test_dummy_bootloader() { let mut base_system_contracts = BASE_SYSTEM_CONTRACTS.clone(); diff --git a/core/lib/multivm/src/versions/vm_latest/tests/bytecode_publishing.rs b/core/lib/multivm/src/versions/vm_latest/tests/bytecode_publishing.rs index e574a881d91..a0c10addff9 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/bytecode_publishing.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/bytecode_publishing.rs @@ -1,10 +1,16 @@ use zksync_types::event::extract_long_l2_to_l1_messages; use zksync_utils::bytecode::compress_bytecode; -use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface}; -use crate::vm_latest::tests::tester::{DeployContractsTx, TxType, VmTesterBuilder}; -use crate::vm_latest::tests::utils::read_test_contract; -use crate::vm_latest::HistoryEnabled; +use crate::{ + interface::{TxExecutionMode, VmExecutionMode, VmInterface}, + vm_latest::{ + tests::{ + tester::{DeployContractsTx, TxType, VmTesterBuilder}, + utils::read_test_contract, + }, + HistoryEnabled, + }, +}; #[test] fn test_bytecode_publishing() { diff --git a/core/lib/multivm/src/versions/vm_latest/tests/call_tracer.rs b/core/lib/multivm/src/versions/vm_latest/tests/call_tracer.rs index e5b1ce15fcd..2f8f37e081b 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/call_tracer.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/call_tracer.rs @@ -1,13 +1,21 @@ -use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface}; -use crate::tracers::CallTracer; -use crate::vm_latest::constants::BLOCK_GAS_LIMIT; -use crate::vm_latest::tests::tester::VmTesterBuilder; -use crate::vm_latest::tests::utils::{read_max_depth_contract, read_test_contract}; -use crate::vm_latest::{HistoryEnabled, ToTracerPointer}; -use once_cell::sync::OnceCell; use std::sync::Arc; + +use once_cell::sync::OnceCell; use zksync_types::{Address, Execute}; +use crate::{ + interface::{TxExecutionMode, VmExecutionMode, VmInterface}, + tracers::CallTracer, + vm_latest::{ + constants::BLOCK_GAS_LIMIT, + tests::{ + tester::VmTesterBuilder, + utils::{read_max_depth_contract, read_test_contract}, + }, + HistoryEnabled, ToTracerPointer, + }, +}; + // This test is ultra slow, so it's ignored by default. #[test] #[ignore] diff --git a/core/lib/multivm/src/versions/vm_latest/tests/default_aa.rs b/core/lib/multivm/src/versions/vm_latest/tests/default_aa.rs index b31e32270d9..7c951e31321 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/default_aa.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/default_aa.rs @@ -1,13 +1,21 @@ use zksync_system_constants::L2_ETH_TOKEN_ADDRESS; -use zksync_types::system_contracts::{DEPLOYMENT_NONCE_INCREMENT, TX_NONCE_INCREMENT}; - -use zksync_types::{get_code_key, get_known_code_key, get_nonce_key, AccountTreeId, U256}; +use zksync_types::{ + get_code_key, get_known_code_key, get_nonce_key, + system_contracts::{DEPLOYMENT_NONCE_INCREMENT, TX_NONCE_INCREMENT}, + AccountTreeId, U256, +}; use zksync_utils::u256_to_h256; -use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface}; -use crate::vm_latest::tests::tester::{DeployContractsTx, TxType, VmTesterBuilder}; -use crate::vm_latest::tests::utils::{get_balance, read_test_contract, verify_required_storage}; -use crate::vm_latest::HistoryEnabled; +use crate::{ + interface::{TxExecutionMode, VmExecutionMode, VmInterface}, + vm_latest::{ + tests::{ + tester::{DeployContractsTx, TxType, VmTesterBuilder}, + utils::{get_balance, read_test_contract, verify_required_storage}, + }, + HistoryEnabled, + }, +}; #[test] fn test_default_aa_interaction() { diff --git a/core/lib/multivm/src/versions/vm_latest/tests/gas_limit.rs b/core/lib/multivm/src/versions/vm_latest/tests/gas_limit.rs index 6bebffeacee..533d9ec660e 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/gas_limit.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/gas_limit.rs @@ -1,13 +1,13 @@ -use zksync_types::fee::Fee; -use zksync_types::Execute; +use zksync_types::{fee::Fee, Execute}; -use crate::vm_latest::constants::{ - BOOTLOADER_HEAP_PAGE, TX_DESCRIPTION_OFFSET, TX_GAS_LIMIT_OFFSET, +use crate::{ + interface::{TxExecutionMode, VmInterface}, + vm_latest::{ + constants::{BOOTLOADER_HEAP_PAGE, TX_DESCRIPTION_OFFSET, TX_GAS_LIMIT_OFFSET}, + tests::tester::VmTesterBuilder, + HistoryDisabled, + }, }; -use crate::vm_latest::tests::tester::VmTesterBuilder; - -use crate::interface::{TxExecutionMode, VmInterface}; -use crate::vm_latest::HistoryDisabled; /// Checks that `TX_GAS_LIMIT_OFFSET` constant is correct. #[test] diff --git a/core/lib/multivm/src/versions/vm_latest/tests/get_used_contracts.rs b/core/lib/multivm/src/versions/vm_latest/tests/get_used_contracts.rs index 688711d5a9c..b82057bef8b 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/get_used_contracts.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/get_used_contracts.rs @@ -1,19 +1,23 @@ use std::collections::{HashMap, HashSet}; use itertools::Itertools; - -use crate::HistoryMode; use zksync_state::WriteStorage; use zksync_system_constants::CONTRACT_DEPLOYER_ADDRESS; use zksync_test_account::Account; use zksync_types::{Execute, U256}; -use zksync_utils::bytecode::hash_bytecode; -use zksync_utils::h256_to_u256; - -use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface}; -use crate::vm_latest::tests::tester::{TxType, VmTesterBuilder}; -use crate::vm_latest::tests::utils::{read_test_contract, BASE_SYSTEM_CONTRACTS}; -use crate::vm_latest::{HistoryDisabled, Vm}; +use zksync_utils::{bytecode::hash_bytecode, h256_to_u256}; + +use crate::{ + interface::{TxExecutionMode, VmExecutionMode, VmInterface}, + vm_latest::{ + tests::{ + tester::{TxType, VmTesterBuilder}, + utils::{read_test_contract, BASE_SYSTEM_CONTRACTS}, + }, + HistoryDisabled, Vm, + }, + HistoryMode, +}; #[test] fn test_get_used_contracts() { diff --git a/core/lib/multivm/src/versions/vm_latest/tests/is_write_initial.rs b/core/lib/multivm/src/versions/vm_latest/tests/is_write_initial.rs index d40f9109dcb..d5a6679502b 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/is_write_initial.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/is_write_initial.rs @@ -1,10 +1,16 @@ use zksync_state::ReadStorage; use zksync_types::get_nonce_key; -use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface}; -use crate::vm_latest::tests::tester::{Account, TxType, VmTesterBuilder}; -use crate::vm_latest::tests::utils::read_test_contract; -use crate::vm_latest::HistoryDisabled; +use crate::{ + interface::{TxExecutionMode, VmExecutionMode, VmInterface}, + vm_latest::{ + tests::{ + tester::{Account, TxType, VmTesterBuilder}, + utils::read_test_contract, + }, + HistoryDisabled, + }, +}; #[test] fn test_is_write_initial_behaviour() { diff --git a/core/lib/multivm/src/versions/vm_latest/tests/l1_tx_execution.rs b/core/lib/multivm/src/versions/vm_latest/tests/l1_tx_execution.rs index 5c1bdbad58a..4f61dd90fad 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/l1_tx_execution.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/l1_tx_execution.rs @@ -1,16 +1,23 @@ use zksync_system_constants::BOOTLOADER_ADDRESS; -use zksync_types::l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}; -use zksync_types::storage_writes_deduplicator::StorageWritesDeduplicator; -use zksync_types::{get_code_key, get_known_code_key, U256}; +use zksync_types::{ + get_code_key, get_known_code_key, + l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}, + storage_writes_deduplicator::StorageWritesDeduplicator, + U256, +}; use zksync_utils::u256_to_h256; -use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface}; -use crate::vm_latest::tests::tester::{TxType, VmTesterBuilder}; -use crate::vm_latest::tests::utils::{ - read_test_contract, verify_required_storage, BASE_SYSTEM_CONTRACTS, +use crate::{ + interface::{TxExecutionMode, VmExecutionMode, VmInterface}, + vm_latest::{ + tests::{ + tester::{TxType, VmTesterBuilder}, + utils::{read_test_contract, verify_required_storage, BASE_SYSTEM_CONTRACTS}, + }, + types::internals::TransactionData, + HistoryEnabled, + }, }; -use crate::vm_latest::types::internals::TransactionData; -use crate::vm_latest::HistoryEnabled; #[test] fn test_l1_tx_execution() { diff --git a/core/lib/multivm/src/versions/vm_latest/tests/l2_blocks.rs b/core/lib/multivm/src/versions/vm_latest/tests/l2_blocks.rs index 4fd4e0207d4..81939d402ff 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/l2_blocks.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/l2_blocks.rs @@ -3,23 +3,11 @@ //! The description for each of the tests can be found in the corresponding `.yul` file. //! -use crate::interface::{ - ExecutionResult, Halt, L2BlockEnv, TxExecutionMode, VmExecutionMode, VmInterface, -}; -use crate::vm_latest::constants::{ - BOOTLOADER_HEAP_PAGE, TX_OPERATOR_L2_BLOCK_INFO_OFFSET, TX_OPERATOR_SLOTS_PER_L2_BLOCK_INFO, -}; -use crate::vm_latest::tests::tester::default_l1_batch; -use crate::vm_latest::tests::tester::VmTesterBuilder; -use crate::vm_latest::utils::l2_blocks::get_l2_block_hash_key; -use crate::vm_latest::{HistoryEnabled, Vm}; -use crate::HistoryMode; use zk_evm_1_4_0::aux_structures::Timestamp; use zksync_state::WriteStorage; use zksync_system_constants::REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE; -use zksync_types::block::pack_block_info; use zksync_types::{ - block::{legacy_miniblock_hash, miniblock_hash}, + block::{legacy_miniblock_hash, miniblock_hash, pack_block_info}, AccountTreeId, Execute, ExecuteTransactionCommon, L1BatchNumber, L1TxCommonData, MiniblockNumber, StorageKey, Transaction, H160, H256, SYSTEM_CONTEXT_ADDRESS, SYSTEM_CONTEXT_BLOCK_INFO_POSITION, SYSTEM_CONTEXT_CURRENT_L2_BLOCK_INFO_POSITION, @@ -27,6 +15,20 @@ use zksync_types::{ }; use zksync_utils::{h256_to_u256, u256_to_h256}; +use crate::{ + interface::{ExecutionResult, Halt, L2BlockEnv, TxExecutionMode, VmExecutionMode, VmInterface}, + vm_latest::{ + constants::{ + BOOTLOADER_HEAP_PAGE, TX_OPERATOR_L2_BLOCK_INFO_OFFSET, + TX_OPERATOR_SLOTS_PER_L2_BLOCK_INFO, + }, + tests::tester::{default_l1_batch, VmTesterBuilder}, + utils::l2_blocks::get_l2_block_hash_key, + HistoryEnabled, Vm, + }, + HistoryMode, +}; + fn get_l1_noop() -> Transaction { Transaction { common_data: ExecuteTransactionCommon::L1(L1TxCommonData { diff --git a/core/lib/multivm/src/versions/vm_latest/tests/nonce_holder.rs b/core/lib/multivm/src/versions/vm_latest/tests/nonce_holder.rs index dedaae5c933..2de5e23bdd2 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/nonce_holder.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/nonce_holder.rs @@ -1,12 +1,19 @@ use zksync_types::{Execute, Nonce}; -use crate::interface::VmRevertReason; -use crate::interface::{ExecutionResult, Halt, TxRevertReason, VmExecutionMode}; -use crate::interface::{TxExecutionMode, VmInterface}; -use crate::vm_latest::tests::tester::{Account, VmTesterBuilder}; -use crate::vm_latest::tests::utils::read_nonce_holder_tester; -use crate::vm_latest::types::internals::TransactionData; -use crate::vm_latest::HistoryEnabled; +use crate::{ + interface::{ + ExecutionResult, Halt, TxExecutionMode, TxRevertReason, VmExecutionMode, VmInterface, + VmRevertReason, + }, + vm_latest::{ + tests::{ + tester::{Account, VmTesterBuilder}, + utils::read_nonce_holder_tester, + }, + types::internals::TransactionData, + HistoryEnabled, + }, +}; pub enum NonceHolderTestMode { SetValueUnderNonce, diff --git a/core/lib/multivm/src/versions/vm_latest/tests/refunds.rs b/core/lib/multivm/src/versions/vm_latest/tests/refunds.rs index 9d4afcdb317..dc1f4fe55bc 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/refunds.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/refunds.rs @@ -1,9 +1,14 @@ -use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface}; -use crate::vm_latest::tests::tester::{DeployContractsTx, TxType, VmTesterBuilder}; -use crate::vm_latest::tests::utils::read_test_contract; - -use crate::vm_latest::types::internals::TransactionData; -use crate::vm_latest::HistoryEnabled; +use crate::{ + interface::{TxExecutionMode, VmExecutionMode, VmInterface}, + vm_latest::{ + tests::{ + tester::{DeployContractsTx, TxType, VmTesterBuilder}, + utils::read_test_contract, + }, + types::internals::TransactionData, + HistoryEnabled, + }, +}; #[test] fn test_predetermined_refunded_gas() { diff --git a/core/lib/multivm/src/versions/vm_latest/tests/require_eip712.rs b/core/lib/multivm/src/versions/vm_latest/tests/require_eip712.rs index 1ad6f351206..c03e5fe6421 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/require_eip712.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/require_eip712.rs @@ -1,22 +1,24 @@ use std::convert::TryInto; use ethabi::Token; - -use zksync_eth_signer::raw_ethereum_tx::TransactionParameters; -use zksync_eth_signer::EthereumSigner; +use zksync_eth_signer::{raw_ethereum_tx::TransactionParameters, EthereumSigner}; use zksync_system_constants::L2_ETH_TOKEN_ADDRESS; -use zksync_types::fee::Fee; -use zksync_types::l2::L2Tx; -use zksync_types::transaction_request::TransactionRequest; -use zksync_types::utils::storage_key_for_standard_token_balance; use zksync_types::{ - AccountTreeId, Address, Eip712Domain, Execute, L2ChainId, Nonce, Transaction, U256, + fee::Fee, l2::L2Tx, transaction_request::TransactionRequest, + utils::storage_key_for_standard_token_balance, AccountTreeId, Address, Eip712Domain, Execute, + L2ChainId, Nonce, Transaction, U256, }; -use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface}; -use crate::vm_latest::tests::tester::{Account, VmTester, VmTesterBuilder}; -use crate::vm_latest::tests::utils::read_many_owners_custom_account_contract; -use crate::vm_latest::HistoryDisabled; +use crate::{ + interface::{TxExecutionMode, VmExecutionMode, VmInterface}, + vm_latest::{ + tests::{ + tester::{Account, VmTester, VmTesterBuilder}, + utils::read_many_owners_custom_account_contract, + }, + HistoryDisabled, + }, +}; impl VmTester { pub(crate) fn get_eth_balance(&mut self, address: Address) -> U256 { diff --git a/core/lib/multivm/src/versions/vm_latest/tests/rollbacks.rs b/core/lib/multivm/src/versions/vm_latest/tests/rollbacks.rs index 343d30dcd95..23c1ab49ad9 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/rollbacks.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/rollbacks.rs @@ -1,21 +1,22 @@ use ethabi::Token; - -use zksync_contracts::get_loadnext_contract; -use zksync_contracts::test_contracts::LoadnextContractExecutionParams; - +use zksync_contracts::{get_loadnext_contract, test_contracts::LoadnextContractExecutionParams}; use zksync_state::WriteStorage; use zksync_types::{get_nonce_key, Execute, U256}; -use crate::interface::dyn_tracers::vm_1_4_0::DynTracer; -use crate::interface::tracer::{TracerExecutionStatus, TracerExecutionStopReason}; -use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface, VmInterfaceHistoryEnabled}; -use crate::vm_latest::tests::tester::{ - DeployContractsTx, TransactionTestInfo, TxModifier, TxType, VmTesterBuilder, -}; -use crate::vm_latest::tests::utils::read_test_contract; -use crate::vm_latest::types::internals::ZkSyncVmState; -use crate::vm_latest::{ - BootloaderState, HistoryEnabled, HistoryMode, SimpleMemory, ToTracerPointer, VmTracer, +use crate::{ + interface::{ + dyn_tracers::vm_1_4_0::DynTracer, + tracer::{TracerExecutionStatus, TracerExecutionStopReason}, + TxExecutionMode, VmExecutionMode, VmInterface, VmInterfaceHistoryEnabled, + }, + vm_latest::{ + tests::{ + tester::{DeployContractsTx, TransactionTestInfo, TxModifier, TxType, VmTesterBuilder}, + utils::read_test_contract, + }, + types::internals::ZkSyncVmState, + BootloaderState, HistoryEnabled, HistoryMode, SimpleMemory, ToTracerPointer, VmTracer, + }, }; #[test] diff --git a/core/lib/multivm/src/versions/vm_latest/tests/simple_execution.rs b/core/lib/multivm/src/versions/vm_latest/tests/simple_execution.rs index 9f0c855b459..a864538524a 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/simple_execution.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/simple_execution.rs @@ -1,6 +1,10 @@ -use crate::interface::{ExecutionResult, VmExecutionMode, VmInterface}; -use crate::vm_latest::tests::tester::{TxType, VmTesterBuilder}; -use crate::vm_latest::HistoryDisabled; +use crate::{ + interface::{ExecutionResult, VmExecutionMode, VmInterface}, + vm_latest::{ + tests::tester::{TxType, VmTesterBuilder}, + HistoryDisabled, + }, +}; #[test] fn estimate_fee() { diff --git a/core/lib/multivm/src/versions/vm_latest/tests/tester/inner_state.rs b/core/lib/multivm/src/versions/vm_latest/tests/tester/inner_state.rs index 4767f934479..b82e995c2db 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/tester/inner_state.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/tester/inner_state.rs @@ -1,15 +1,19 @@ use std::collections::HashMap; -use zk_evm_1_4_0::aux_structures::Timestamp; -use zk_evm_1_4_0::vm_state::VmLocalState; +use zk_evm_1_4_0::{aux_structures::Timestamp, vm_state::VmLocalState}; use zksync_state::WriteStorage; - use zksync_types::{StorageKey, StorageLogQuery, StorageValue, U256}; -use crate::vm_latest::old_vm::event_sink::InMemoryEventSink; -use crate::vm_latest::old_vm::history_recorder::{AppDataFrameManagerWithHistory, HistoryRecorder}; -use crate::vm_latest::{HistoryEnabled, HistoryMode, SimpleMemory, Vm}; -use crate::HistoryMode as CommonHistoryMode; +use crate::{ + vm_latest::{ + old_vm::{ + event_sink::InMemoryEventSink, + history_recorder::{AppDataFrameManagerWithHistory, HistoryRecorder}, + }, + HistoryEnabled, HistoryMode, SimpleMemory, Vm, + }, + HistoryMode as CommonHistoryMode, +}; #[derive(Clone, Debug)] pub(crate) struct ModifiedKeysMap(HashMap); diff --git a/core/lib/multivm/src/versions/vm_latest/tests/tester/transaction_test_info.rs b/core/lib/multivm/src/versions/vm_latest/tests/tester/transaction_test_info.rs index 6fdfa7955e0..114f80d1a21 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/tester/transaction_test_info.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/tester/transaction_test_info.rs @@ -1,12 +1,12 @@ use zksync_types::{ExecuteTransactionCommon, Transaction}; -use crate::interface::{ - CurrentExecutionState, ExecutionResult, Halt, TxRevertReason, VmExecutionMode, - VmExecutionResultAndLogs, +use crate::{ + interface::{ + CurrentExecutionState, ExecutionResult, Halt, TxRevertReason, VmExecutionMode, + VmExecutionResultAndLogs, VmInterface, VmInterfaceHistoryEnabled, VmRevertReason, + }, + vm_latest::{tests::tester::vm_tester::VmTester, HistoryEnabled}, }; -use crate::interface::{VmInterface, VmInterfaceHistoryEnabled, VmRevertReason}; -use crate::vm_latest::tests::tester::vm_tester::VmTester; -use crate::vm_latest::HistoryEnabled; #[derive(Debug, Clone)] pub(crate) enum TxModifier { diff --git a/core/lib/multivm/src/versions/vm_latest/tests/tester/vm_tester.rs b/core/lib/multivm/src/versions/vm_latest/tests/tester/vm_tester.rs index cbf009d5b02..6218a391824 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/tester/vm_tester.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/tester/vm_tester.rs @@ -1,28 +1,31 @@ use std::marker::PhantomData; + use zksync_contracts::BaseSystemContracts; use zksync_state::{InMemoryStorage, StoragePtr, StorageView, WriteStorage}; - -use zksync_types::block::legacy_miniblock_hash; -use zksync_types::helpers::unix_timestamp_ms; -use zksync_types::utils::{deployed_address_create, storage_key_for_eth_balance}; use zksync_types::{ - get_code_key, get_is_account_key, Address, L1BatchNumber, L2ChainId, MiniblockNumber, Nonce, - ProtocolVersionId, U256, + block::legacy_miniblock_hash, + get_code_key, get_is_account_key, + helpers::unix_timestamp_ms, + utils::{deployed_address_create, storage_key_for_eth_balance}, + Address, L1BatchNumber, L2ChainId, MiniblockNumber, Nonce, ProtocolVersionId, U256, }; -use zksync_utils::bytecode::hash_bytecode; -use zksync_utils::u256_to_h256; - -use crate::vm_latest::constants::BLOCK_GAS_LIMIT; - -use crate::interface::{ - L1BatchEnv, L2Block, L2BlockEnv, SystemEnv, TxExecutionMode, VmExecutionMode, VmInterface, +use zksync_utils::{bytecode::hash_bytecode, u256_to_h256}; + +use crate::{ + interface::{ + L1BatchEnv, L2Block, L2BlockEnv, SystemEnv, TxExecutionMode, VmExecutionMode, VmInterface, + }, + vm_latest::{ + constants::BLOCK_GAS_LIMIT, + tests::{ + tester::{Account, TxType}, + utils::read_test_contract, + }, + utils::l2_blocks::load_last_l2_block, + Vm, + }, + HistoryMode, }; -use crate::vm_latest::tests::tester::Account; -use crate::vm_latest::tests::tester::TxType; -use crate::vm_latest::tests::utils::read_test_contract; -use crate::vm_latest::utils::l2_blocks::load_last_l2_block; -use crate::vm_latest::Vm; -use crate::HistoryMode; pub(crate) type InMemoryStorageView = StorageView; diff --git a/core/lib/multivm/src/versions/vm_latest/tests/tracing_execution_error.rs b/core/lib/multivm/src/versions/vm_latest/tests/tracing_execution_error.rs index f55eadecde6..f02de899b03 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/tracing_execution_error.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/tracing_execution_error.rs @@ -1,12 +1,15 @@ use zksync_types::{Execute, H160}; -use crate::interface::TxExecutionMode; -use crate::interface::{TxRevertReason, VmRevertReason}; -use crate::vm_latest::tests::tester::{ExpectedError, TransactionTestInfo, VmTesterBuilder}; -use crate::vm_latest::tests::utils::{ - get_execute_error_calldata, read_error_contract, BASE_SYSTEM_CONTRACTS, +use crate::{ + interface::{TxExecutionMode, TxRevertReason, VmRevertReason}, + vm_latest::{ + tests::{ + tester::{ExpectedError, TransactionTestInfo, VmTesterBuilder}, + utils::{get_execute_error_calldata, read_error_contract, BASE_SYSTEM_CONTRACTS}, + }, + HistoryEnabled, + }, }; -use crate::vm_latest::HistoryEnabled; #[test] fn test_tracing_of_execution_errors() { diff --git a/core/lib/multivm/src/versions/vm_latest/tests/upgrade.rs b/core/lib/multivm/src/versions/vm_latest/tests/upgrade.rs index 65780114e9a..b5c493ca707 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/upgrade.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/upgrade.rs @@ -1,28 +1,28 @@ use zk_evm_1_4_0::aux_structures::Timestamp; - -use zksync_types::{ - ethabi::Contract, - Execute, COMPLEX_UPGRADER_ADDRESS, CONTRACT_DEPLOYER_ADDRESS, CONTRACT_FORCE_DEPLOYER_ADDRESS, - REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE, - {ethabi::Token, Address, ExecuteTransactionCommon, Transaction, H256, U256}, - {get_code_key, get_known_code_key, H160}, -}; - -use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256, u256_to_h256}; - use zksync_contracts::{deployer_contract, load_contract, load_sys_contract, read_bytecode}; use zksync_state::WriteStorage; use zksync_test_account::TxType; - -use crate::interface::{ - ExecutionResult, Halt, TxExecutionMode, VmExecutionMode, VmInterface, VmInterfaceHistoryEnabled, +use zksync_types::{ + ethabi::{Contract, Token}, + get_code_key, get_known_code_key, + protocol_version::ProtocolUpgradeTxCommonData, + Address, Execute, ExecuteTransactionCommon, Transaction, COMPLEX_UPGRADER_ADDRESS, + CONTRACT_DEPLOYER_ADDRESS, CONTRACT_FORCE_DEPLOYER_ADDRESS, H160, H256, + REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE, U256, }; -use crate::vm_latest::tests::tester::VmTesterBuilder; -use crate::vm_latest::tests::utils::verify_required_storage; -use crate::vm_latest::HistoryEnabled; -use zksync_types::protocol_version::ProtocolUpgradeTxCommonData; +use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256, u256_to_h256}; use super::utils::read_test_contract; +use crate::{ + interface::{ + ExecutionResult, Halt, TxExecutionMode, VmExecutionMode, VmInterface, + VmInterfaceHistoryEnabled, + }, + vm_latest::{ + tests::{tester::VmTesterBuilder, utils::verify_required_storage}, + HistoryEnabled, + }, +}; /// In this test we ensure that the requirements for protocol upgrade transactions are enforced by the bootloader: /// - This transaction must be the only one in block diff --git a/core/lib/multivm/src/versions/vm_latest/tests/utils.rs b/core/lib/multivm/src/versions/vm_latest/tests/utils.rs index e30f0b9f39a..90bc8c2aef2 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/utils.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/utils.rs @@ -1,18 +1,17 @@ use ethabi::Contract; use once_cell::sync::Lazy; - -use crate::vm_latest::tests::tester::InMemoryStorageView; use zksync_contracts::{ load_contract, read_bytecode, read_zbin_bytecode, BaseSystemContracts, SystemContractCode, }; use zksync_state::{StoragePtr, WriteStorage}; -use zksync_types::utils::storage_key_for_standard_token_balance; -use zksync_types::{AccountTreeId, Address, StorageKey, H256, U256}; -use zksync_utils::bytecode::hash_bytecode; -use zksync_utils::{bytes_to_be_words, h256_to_u256, u256_to_h256}; +use zksync_types::{ + utils::storage_key_for_standard_token_balance, AccountTreeId, Address, StorageKey, H256, U256, +}; +use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256, u256_to_h256}; -use crate::vm_latest::types::internals::ZkSyncVmState; -use crate::vm_latest::HistoryMode; +use crate::vm_latest::{ + tests::tester::InMemoryStorageView, types::internals::ZkSyncVmState, HistoryMode, +}; pub(crate) static BASE_SYSTEM_CONTRACTS: Lazy = Lazy::new(BaseSystemContracts::load_from_disk); diff --git a/core/lib/multivm/src/versions/vm_latest/tracers/default_tracers.rs b/core/lib/multivm/src/versions/vm_latest/tracers/default_tracers.rs index 9582e6e1053..0e18d989af6 100644 --- a/core/lib/multivm/src/versions/vm_latest/tracers/default_tracers.rs +++ b/core/lib/multivm/src/versions/vm_latest/tracers/default_tracers.rs @@ -1,8 +1,8 @@ -use std::fmt::{Debug, Formatter}; -use std::marker::PhantomData; +use std::{ + fmt::{Debug, Formatter}, + marker::PhantomData, +}; -use crate::interface::tracer::{TracerExecutionStopReason, VmExecutionStopReason}; -use crate::interface::{Halt, VmExecutionMode}; use zk_evm_1_4_0::{ tracing::{ AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, @@ -14,23 +14,30 @@ use zk_evm_1_4_0::{ use zksync_state::{StoragePtr, WriteStorage}; use zksync_types::Timestamp; -use crate::interface::traits::tracers::dyn_tracers::vm_1_4_0::DynTracer; -use crate::interface::types::tracer::TracerExecutionStatus; -use crate::vm_latest::bootloader_state::utils::apply_l2_block; -use crate::vm_latest::bootloader_state::BootloaderState; -use crate::vm_latest::constants::BOOTLOADER_HEAP_PAGE; -use crate::vm_latest::old_vm::history_recorder::HistoryMode; -use crate::vm_latest::old_vm::memory::SimpleMemory; -use crate::vm_latest::tracers::dispatcher::TracerDispatcher; -use crate::vm_latest::tracers::utils::{ - computational_gas_price, gas_spent_on_bytecodes_and_long_messages_this_opcode, - print_debug_if_needed, VmHook, -}; -use crate::vm_latest::tracers::{RefundsTracer, ResultTracer}; -use crate::vm_latest::types::internals::ZkSyncVmState; -use crate::vm_latest::VmTracer; - use super::PubdataTracer; +use crate::{ + interface::{ + tracer::{TracerExecutionStopReason, VmExecutionStopReason}, + traits::tracers::dyn_tracers::vm_1_4_0::DynTracer, + types::tracer::TracerExecutionStatus, + Halt, VmExecutionMode, + }, + vm_latest::{ + bootloader_state::{utils::apply_l2_block, BootloaderState}, + constants::BOOTLOADER_HEAP_PAGE, + old_vm::{history_recorder::HistoryMode, memory::SimpleMemory}, + tracers::{ + dispatcher::TracerDispatcher, + utils::{ + computational_gas_price, gas_spent_on_bytecodes_and_long_messages_this_opcode, + print_debug_if_needed, VmHook, + }, + RefundsTracer, ResultTracer, + }, + types::internals::ZkSyncVmState, + VmTracer, + }, +}; /// Default tracer for the VM. It manages the other tracers execution and stop the vm when needed. pub(crate) struct DefaultExecutionTracer { diff --git a/core/lib/multivm/src/versions/vm_latest/tracers/dispatcher.rs b/core/lib/multivm/src/versions/vm_latest/tracers/dispatcher.rs index b75277670dc..5ee5c8ab0c1 100644 --- a/core/lib/multivm/src/versions/vm_latest/tracers/dispatcher.rs +++ b/core/lib/multivm/src/versions/vm_latest/tracers/dispatcher.rs @@ -1,13 +1,18 @@ -use crate::interface::dyn_tracers::vm_1_4_0::DynTracer; -use crate::interface::tracer::{TracerExecutionStatus, VmExecutionStopReason}; -use crate::vm_latest::{ - BootloaderState, HistoryMode, SimpleMemory, TracerPointer, VmTracer, ZkSyncVmState, -}; use zk_evm_1_4_0::tracing::{ AfterDecodingData, AfterExecutionData, BeforeExecutionData, VmLocalStateData, }; use zksync_state::{StoragePtr, WriteStorage}; +use crate::{ + interface::{ + dyn_tracers::vm_1_4_0::DynTracer, + tracer::{TracerExecutionStatus, VmExecutionStopReason}, + }, + vm_latest::{ + BootloaderState, HistoryMode, SimpleMemory, TracerPointer, VmTracer, ZkSyncVmState, + }, +}; + /// Tracer dispatcher is a tracer that can dispatch calls to multiple tracers. pub struct TracerDispatcher { tracers: Vec>, diff --git a/core/lib/multivm/src/versions/vm_latest/tracers/pubdata_tracer.rs b/core/lib/multivm/src/versions/vm_latest/tracers/pubdata_tracer.rs index 59a9d8eb452..388b5ef209e 100644 --- a/core/lib/multivm/src/versions/vm_latest/tracers/pubdata_tracer.rs +++ b/core/lib/multivm/src/versions/vm_latest/tracers/pubdata_tracer.rs @@ -1,9 +1,9 @@ use std::marker::PhantomData; + use zk_evm_1_4_0::{ aux_structures::Timestamp, tracing::{BeforeExecutionData, VmLocalStateData}, }; - use zksync_state::{StoragePtr, WriteStorage}; use zksync_types::{ event::{ @@ -14,24 +14,24 @@ use zksync_types::{ zkevm_test_harness::witness::sort_storage_access::sort_storage_access_queries, AccountTreeId, StorageKey, L1_MESSENGER_ADDRESS, }; -use zksync_utils::u256_to_h256; -use zksync_utils::{h256_to_u256, u256_to_bytes_be}; +use zksync_utils::{h256_to_u256, u256_to_bytes_be, u256_to_h256}; -use crate::vm_latest::{ - old_vm::{history_recorder::HistoryMode, memory::SimpleMemory}, - types::internals::pubdata::PubdataInput, -}; -use crate::{vm_latest::constants::BOOTLOADER_HEAP_PAGE, vm_latest::StorageOracle}; - -use crate::interface::dyn_tracers::vm_1_4_0::DynTracer; -use crate::interface::tracer::{TracerExecutionStatus, TracerExecutionStopReason}; -use crate::interface::types::inputs::L1BatchEnv; -use crate::vm_latest::tracers::{traits::VmTracer, utils::VmHook}; -use crate::vm_latest::types::internals::ZkSyncVmState; -use crate::vm_latest::utils::logs::collect_events_and_l1_system_logs_after_timestamp; use crate::{ - interface::VmExecutionMode, - vm_latest::bootloader_state::{utils::apply_pubdata_to_memory, BootloaderState}, + interface::{ + dyn_tracers::vm_1_4_0::DynTracer, + tracer::{TracerExecutionStatus, TracerExecutionStopReason}, + types::inputs::L1BatchEnv, + VmExecutionMode, + }, + vm_latest::{ + bootloader_state::{utils::apply_pubdata_to_memory, BootloaderState}, + constants::BOOTLOADER_HEAP_PAGE, + old_vm::{history_recorder::HistoryMode, memory::SimpleMemory}, + tracers::{traits::VmTracer, utils::VmHook}, + types::internals::{pubdata::PubdataInput, ZkSyncVmState}, + utils::logs::collect_events_and_l1_system_logs_after_timestamp, + StorageOracle, + }, }; /// Tracer responsible for collecting information about refunds. diff --git a/core/lib/multivm/src/versions/vm_latest/tracers/refunds.rs b/core/lib/multivm/src/versions/vm_latest/tracers/refunds.rs index f3e6c336684..e852fba1dac 100644 --- a/core/lib/multivm/src/versions/vm_latest/tracers/refunds.rs +++ b/core/lib/multivm/src/versions/vm_latest/tracers/refunds.rs @@ -1,9 +1,6 @@ use std::marker::PhantomData; -use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; -use crate::interface::traits::tracers::dyn_tracers::vm_1_4_0::DynTracer; -use crate::interface::types::tracer::TracerExecutionStatus; -use crate::interface::{L1BatchEnv, Refunds}; +use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; use zk_evm_1_4_0::{ aux_structures::Timestamp, tracing::{BeforeExecutionData, VmLocalStateData}, @@ -16,24 +13,29 @@ use zksync_types::{ l2_to_l1_log::L2ToL1Log, L1BatchNumber, U256, }; -use zksync_utils::bytecode::bytecode_len_in_bytes; -use zksync_utils::{ceil_div_u256, u256_to_h256}; - -use crate::vm_latest::constants::{ - BOOTLOADER_HEAP_PAGE, OPERATOR_REFUNDS_OFFSET, TX_GAS_LIMIT_OFFSET, -}; -use crate::vm_latest::old_vm::{ - events::merge_events, history_recorder::HistoryMode, memory::SimpleMemory, - utils::eth_price_per_pubdata_byte, -}; - -use crate::vm_latest::bootloader_state::BootloaderState; -use crate::vm_latest::tracers::utils::gas_spent_on_bytecodes_and_long_messages_this_opcode; -use crate::vm_latest::tracers::{ - traits::VmTracer, - utils::{get_vm_hook_params, VmHook}, +use zksync_utils::{bytecode::bytecode_len_in_bytes, ceil_div_u256, u256_to_h256}; + +use crate::{ + interface::{ + traits::tracers::dyn_tracers::vm_1_4_0::DynTracer, types::tracer::TracerExecutionStatus, + L1BatchEnv, Refunds, + }, + vm_latest::{ + bootloader_state::BootloaderState, + constants::{BOOTLOADER_HEAP_PAGE, OPERATOR_REFUNDS_OFFSET, TX_GAS_LIMIT_OFFSET}, + old_vm::{ + events::merge_events, history_recorder::HistoryMode, memory::SimpleMemory, + utils::eth_price_per_pubdata_byte, + }, + tracers::{ + traits::VmTracer, + utils::{ + gas_spent_on_bytecodes_and_long_messages_this_opcode, get_vm_hook_params, VmHook, + }, + }, + types::internals::ZkSyncVmState, + }, }; -use crate::vm_latest::types::internals::ZkSyncVmState; /// Tracer responsible for collecting information about refunds. #[derive(Debug, Clone)] diff --git a/core/lib/multivm/src/versions/vm_latest/tracers/result_tracer.rs b/core/lib/multivm/src/versions/vm_latest/tracers/result_tracer.rs index 7e6e08a0a49..b3412587725 100644 --- a/core/lib/multivm/src/versions/vm_latest/tracers/result_tracer.rs +++ b/core/lib/multivm/src/versions/vm_latest/tracers/result_tracer.rs @@ -1,27 +1,29 @@ use std::marker::PhantomData; + use zk_evm_1_4_0::{ tracing::{AfterDecodingData, BeforeExecutionData, VmLocalStateData}, vm_state::{ErrorFlags, VmLocalState}, zkevm_opcode_defs::FatPointer, }; use zksync_state::{StoragePtr, WriteStorage}; - -use crate::interface::{ - tracer::VmExecutionStopReason, traits::tracers::dyn_tracers::vm_1_4_0::DynTracer, - types::tracer::TracerExecutionStopReason, ExecutionResult, Halt, TxRevertReason, - VmExecutionMode, VmRevertReason, -}; use zksync_types::U256; -use crate::vm_latest::{ - constants::{BOOTLOADER_HEAP_PAGE, RESULT_SUCCESS_FIRST_SLOT}, - old_vm::utils::{vm_may_have_ended_inner, VmExecutionResult}, - tracers::{ - traits::VmTracer, - utils::{get_vm_hook_params, read_pointer, VmHook}, +use crate::{ + interface::{ + tracer::VmExecutionStopReason, traits::tracers::dyn_tracers::vm_1_4_0::DynTracer, + types::tracer::TracerExecutionStopReason, ExecutionResult, Halt, TxRevertReason, + VmExecutionMode, VmRevertReason, + }, + vm_latest::{ + constants::{BOOTLOADER_HEAP_PAGE, RESULT_SUCCESS_FIRST_SLOT}, + old_vm::utils::{vm_may_have_ended_inner, VmExecutionResult}, + tracers::{ + traits::VmTracer, + utils::{get_vm_hook_params, read_pointer, VmHook}, + }, + types::internals::ZkSyncVmState, + BootloaderState, HistoryMode, SimpleMemory, }, - types::internals::ZkSyncVmState, - BootloaderState, HistoryMode, SimpleMemory, }; #[derive(Debug, Clone)] diff --git a/core/lib/multivm/src/versions/vm_latest/tracers/traits.rs b/core/lib/multivm/src/versions/vm_latest/tracers/traits.rs index a3970541bac..68307b3f286 100644 --- a/core/lib/multivm/src/versions/vm_latest/tracers/traits.rs +++ b/core/lib/multivm/src/versions/vm_latest/tracers/traits.rs @@ -1,11 +1,16 @@ -use crate::interface::dyn_tracers::vm_1_4_0::DynTracer; -use crate::interface::tracer::{TracerExecutionStatus, VmExecutionStopReason}; use zksync_state::WriteStorage; -use crate::vm_latest::bootloader_state::BootloaderState; -use crate::vm_latest::old_vm::history_recorder::HistoryMode; -use crate::vm_latest::old_vm::memory::SimpleMemory; -use crate::vm_latest::types::internals::ZkSyncVmState; +use crate::{ + interface::{ + dyn_tracers::vm_1_4_0::DynTracer, + tracer::{TracerExecutionStatus, VmExecutionStopReason}, + }, + vm_latest::{ + bootloader_state::BootloaderState, + old_vm::{history_recorder::HistoryMode, memory::SimpleMemory}, + types::internals::ZkSyncVmState, + }, +}; pub type TracerPointer = Box>; diff --git a/core/lib/multivm/src/versions/vm_latest/tracers/utils.rs b/core/lib/multivm/src/versions/vm_latest/tracers/utils.rs index 52ff84f8c3c..93710586fda 100644 --- a/core/lib/multivm/src/versions/vm_latest/tracers/utils.rs +++ b/core/lib/multivm/src/versions/vm_latest/tracers/utils.rs @@ -1,10 +1,10 @@ -use zk_evm_1_4_0::aux_structures::MemoryPage; -use zk_evm_1_4_0::zkevm_opcode_defs::{FarCallABI, FarCallForwardPageType}; use zk_evm_1_4_0::{ + aux_structures::MemoryPage, tracing::{BeforeExecutionData, VmLocalStateData}, - zkevm_opcode_defs::{FatPointer, LogOpcode, Opcode, UMAOpcode}, + zkevm_opcode_defs::{ + FarCallABI, FarCallForwardPageType, FatPointer, LogOpcode, Opcode, UMAOpcode, + }, }; - use zksync_system_constants::{ ECRECOVER_PRECOMPILE_ADDRESS, KECCAK256_PRECOMPILE_ADDRESS, KNOWN_CODES_STORAGE_ADDRESS, L1_MESSENGER_ADDRESS, SHA256_PRECOMPILE_ADDRESS, @@ -12,12 +12,16 @@ use zksync_system_constants::{ use zksync_types::U256; use zksync_utils::u256_to_h256; -use crate::vm_latest::constants::{ - BOOTLOADER_HEAP_PAGE, VM_HOOK_PARAMS_COUNT, VM_HOOK_PARAMS_START_POSITION, VM_HOOK_POSITION, +use crate::vm_latest::{ + constants::{ + BOOTLOADER_HEAP_PAGE, VM_HOOK_PARAMS_COUNT, VM_HOOK_PARAMS_START_POSITION, VM_HOOK_POSITION, + }, + old_vm::{ + history_recorder::HistoryMode, + memory::SimpleMemory, + utils::{aux_heap_page_from_base, heap_page_from_base}, + }, }; -use crate::vm_latest::old_vm::history_recorder::HistoryMode; -use crate::vm_latest::old_vm::memory::SimpleMemory; -use crate::vm_latest::old_vm::utils::{aux_heap_page_from_base, heap_page_from_base}; #[derive(Clone, Debug, Copy)] pub(crate) enum VmHook { diff --git a/core/lib/multivm/src/versions/vm_latest/types/internals/pubdata.rs b/core/lib/multivm/src/versions/vm_latest/types/internals/pubdata.rs index e246bceeac5..fd00b333c72 100644 --- a/core/lib/multivm/src/versions/vm_latest/types/internals/pubdata.rs +++ b/core/lib/multivm/src/versions/vm_latest/types/internals/pubdata.rs @@ -1,5 +1,5 @@ -use zksync_types::ethabi; use zksync_types::{ + ethabi, event::L1MessengerL2ToL1Log, writes::{compress_state_diffs, StateDiffRecord}, }; diff --git a/core/lib/multivm/src/versions/vm_latest/types/internals/transaction_data.rs b/core/lib/multivm/src/versions/vm_latest/types/internals/transaction_data.rs index 3c7b9bcac03..f5b97ca9793 100644 --- a/core/lib/multivm/src/versions/vm_latest/types/internals/transaction_data.rs +++ b/core/lib/multivm/src/versions/vm_latest/types/internals/transaction_data.rs @@ -1,15 +1,15 @@ use std::convert::TryInto; -use zksync_types::ethabi::{encode, Address, Token}; -use zksync_types::fee::{encoding_len, Fee}; -use zksync_types::l1::is_l1_tx_type; -use zksync_types::l2::L2Tx; -use zksync_types::transaction_request::{PaymasterParams, TransactionRequest}; + use zksync_types::{ - l2::TransactionType, Bytes, Execute, ExecuteTransactionCommon, L2ChainId, L2TxCommonData, - Nonce, Transaction, H256, U256, + ethabi::{encode, Address, Token}, + fee::{encoding_len, Fee}, + l1::is_l1_tx_type, + l2::{L2Tx, TransactionType}, + transaction_request::{PaymasterParams, TransactionRequest}, + Bytes, Execute, ExecuteTransactionCommon, L2ChainId, L2TxCommonData, Nonce, Transaction, H256, + U256, }; -use zksync_utils::address_to_h256; -use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256}; +use zksync_utils::{address_to_h256, bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256}; use crate::vm_latest::utils::overhead::{get_amortized_overhead, OverheadCoefficients}; @@ -303,9 +303,10 @@ impl TryInto for TransactionData { #[cfg(test)] mod tests { - use super::*; use zksync_types::fee::encoding_len; + use super::*; + #[test] fn test_consistency_with_encoding_length() { let transaction = TransactionData { diff --git a/core/lib/multivm/src/versions/vm_latest/types/internals/vm_state.rs b/core/lib/multivm/src/versions/vm_latest/types/internals/vm_state.rs index 0c519a324c0..f65785dcfe5 100644 --- a/core/lib/multivm/src/versions/vm_latest/types/internals/vm_state.rs +++ b/core/lib/multivm/src/versions/vm_latest/types/internals/vm_state.rs @@ -1,34 +1,40 @@ use zk_evm_1_4_0::{ - aux_structures::MemoryPage, - aux_structures::Timestamp, + aux_structures::{MemoryPage, Timestamp}, block_properties::BlockProperties, vm_state::{CallStackEntry, PrimitiveValue, VmState}, witness_trace::DummyTracer, zkevm_opcode_defs::{ system_params::{BOOTLOADER_MAX_MEMORY, INITIAL_FRAME_FORMAL_EH_LOCATION}, - FatPointer, BOOTLOADER_CALLDATA_PAGE, + FatPointer, BOOTLOADER_BASE_PAGE, BOOTLOADER_CALLDATA_PAGE, BOOTLOADER_CODE_PAGE, + STARTING_BASE_PAGE, STARTING_TIMESTAMP, }, }; - -use crate::interface::{L1BatchEnv, L2Block, SystemEnv}; -use zk_evm_1_4_0::zkevm_opcode_defs::{ - BOOTLOADER_BASE_PAGE, BOOTLOADER_CODE_PAGE, STARTING_BASE_PAGE, STARTING_TIMESTAMP, -}; use zksync_state::{StoragePtr, WriteStorage}; use zksync_system_constants::BOOTLOADER_ADDRESS; -use zksync_types::block::legacy_miniblock_hash; -use zksync_types::{zkevm_test_harness::INITIAL_MONOTONIC_CYCLE_COUNTER, Address, MiniblockNumber}; +use zksync_types::{ + block::legacy_miniblock_hash, zkevm_test_harness::INITIAL_MONOTONIC_CYCLE_COUNTER, Address, + MiniblockNumber, +}; use zksync_utils::h256_to_u256; -use crate::vm_latest::bootloader_state::BootloaderState; -use crate::vm_latest::constants::BOOTLOADER_HEAP_PAGE; -use crate::vm_latest::old_vm::{ - event_sink::InMemoryEventSink, history_recorder::HistoryMode, memory::SimpleMemory, - oracles::decommitter::DecommitterOracle, oracles::precompile::PrecompilesProcessorWithHistory, +use crate::{ + interface::{L1BatchEnv, L2Block, SystemEnv}, + vm_latest::{ + bootloader_state::BootloaderState, + constants::BOOTLOADER_HEAP_PAGE, + old_vm::{ + event_sink::InMemoryEventSink, + history_recorder::HistoryMode, + memory::SimpleMemory, + oracles::{ + decommitter::DecommitterOracle, precompile::PrecompilesProcessorWithHistory, + }, + }, + oracles::storage::StorageOracle, + types::l1_batch::bootloader_initial_memory, + utils::l2_blocks::{assert_next_block, load_last_l2_block}, + }, }; -use crate::vm_latest::oracles::storage::StorageOracle; -use crate::vm_latest::types::l1_batch::bootloader_initial_memory; -use crate::vm_latest::utils::l2_blocks::{assert_next_block, load_last_l2_block}; pub type ZkSyncVmState = VmState< StorageOracle, diff --git a/core/lib/multivm/src/versions/vm_latest/types/l1_batch.rs b/core/lib/multivm/src/versions/vm_latest/types/l1_batch.rs index 631f1436cc3..6f16e95f8d7 100644 --- a/core/lib/multivm/src/versions/vm_latest/types/l1_batch.rs +++ b/core/lib/multivm/src/versions/vm_latest/types/l1_batch.rs @@ -1,7 +1,8 @@ -use crate::interface::L1BatchEnv; use zksync_types::U256; use zksync_utils::{address_to_u256, h256_to_u256}; +use crate::interface::L1BatchEnv; + const OPERATOR_ADDRESS_SLOT: usize = 0; const PREV_BLOCK_HASH_SLOT: usize = 1; const NEW_BLOCK_TIMESTAMP_SLOT: usize = 2; diff --git a/core/lib/multivm/src/versions/vm_latest/utils/l2_blocks.rs b/core/lib/multivm/src/versions/vm_latest/utils/l2_blocks.rs index 3d5f58094e0..5dd26c4c027 100644 --- a/core/lib/multivm/src/versions/vm_latest/utils/l2_blocks.rs +++ b/core/lib/multivm/src/versions/vm_latest/utils/l2_blocks.rs @@ -1,15 +1,17 @@ -use crate::interface::{L2Block, L2BlockEnv}; use zksync_state::{ReadStorage, StoragePtr}; use zksync_system_constants::{ SYSTEM_CONTEXT_ADDRESS, SYSTEM_CONTEXT_CURRENT_L2_BLOCK_HASHES_POSITION, SYSTEM_CONTEXT_CURRENT_L2_BLOCK_INFO_POSITION, SYSTEM_CONTEXT_CURRENT_TX_ROLLING_HASH_POSITION, SYSTEM_CONTEXT_STORED_L2_BLOCK_HASHES, }; -use zksync_types::block::unpack_block_info; -use zksync_types::web3::signing::keccak256; -use zksync_types::{AccountTreeId, MiniblockNumber, StorageKey, H256, U256}; +use zksync_types::{ + block::unpack_block_info, web3::signing::keccak256, AccountTreeId, MiniblockNumber, StorageKey, + H256, U256, +}; use zksync_utils::{h256_to_u256, u256_to_h256}; +use crate::interface::{L2Block, L2BlockEnv}; + pub(crate) fn get_l2_block_hash_key(block_number: u32) -> StorageKey { let position = h256_to_u256(SYSTEM_CONTEXT_CURRENT_L2_BLOCK_HASHES_POSITION) + U256::from(block_number % SYSTEM_CONTEXT_STORED_L2_BLOCK_HASHES); diff --git a/core/lib/multivm/src/versions/vm_latest/utils/logs.rs b/core/lib/multivm/src/versions/vm_latest/utils/logs.rs index a2b7f548684..b7fa07956a9 100644 --- a/core/lib/multivm/src/versions/vm_latest/utils/logs.rs +++ b/core/lib/multivm/src/versions/vm_latest/utils/logs.rs @@ -2,8 +2,11 @@ use zksync_state::WriteStorage; use zksync_types::{l2_to_l1_log::L2ToL1Log, Timestamp, VmEvent}; use crate::{ - interface::L1BatchEnv, vm_latest::old_vm::events::merge_events, - vm_latest::old_vm::history_recorder::HistoryMode, vm_latest::types::internals::ZkSyncVmState, + interface::L1BatchEnv, + vm_latest::{ + old_vm::{events::merge_events, history_recorder::HistoryMode}, + types::internals::ZkSyncVmState, + }, }; pub(crate) fn collect_events_and_l1_system_logs_after_timestamp( diff --git a/core/lib/multivm/src/versions/vm_latest/utils/overhead.rs b/core/lib/multivm/src/versions/vm_latest/utils/overhead.rs index c977267db8f..38aaede8d4b 100644 --- a/core/lib/multivm/src/versions/vm_latest/utils/overhead.rs +++ b/core/lib/multivm/src/versions/vm_latest/utils/overhead.rs @@ -1,12 +1,12 @@ -use crate::vm_latest::constants::{ - BLOCK_OVERHEAD_GAS, BLOCK_OVERHEAD_PUBDATA, BOOTLOADER_TX_ENCODING_SPACE, -}; use zk_evm_1_4_0::zkevm_opcode_defs::system_params::MAX_TX_ERGS_LIMIT; use zksync_system_constants::{MAX_L2_TX_GAS_LIMIT, MAX_TXS_IN_BLOCK}; -use zksync_types::l1::is_l1_tx_type; -use zksync_types::U256; +use zksync_types::{l1::is_l1_tx_type, U256}; use zksync_utils::ceil_div_u256; +use crate::vm_latest::constants::{ + BLOCK_OVERHEAD_GAS, BLOCK_OVERHEAD_PUBDATA, BOOTLOADER_TX_ENCODING_SPACE, +}; + /// Derives the overhead for processing transactions in a block. pub fn derive_overhead( gas_limit: u32, diff --git a/core/lib/multivm/src/versions/vm_latest/utils/transaction_encoding.rs b/core/lib/multivm/src/versions/vm_latest/utils/transaction_encoding.rs index 9aecef6367e..86c49a3eb15 100644 --- a/core/lib/multivm/src/versions/vm_latest/utils/transaction_encoding.rs +++ b/core/lib/multivm/src/versions/vm_latest/utils/transaction_encoding.rs @@ -1,6 +1,7 @@ -use crate::vm_latest::types::internals::TransactionData; use zksync_types::Transaction; +use crate::vm_latest::types::internals::TransactionData; + /// Extension for transactions, specific for VM. Required for bypassing the orphan rule pub trait TransactionVmExt { /// Get the size of the transaction in tokens. diff --git a/core/lib/multivm/src/versions/vm_latest/vm.rs b/core/lib/multivm/src/versions/vm_latest/vm.rs index 20d74e39093..159f50a89ee 100644 --- a/core/lib/multivm/src/versions/vm_latest/vm.rs +++ b/core/lib/multivm/src/versions/vm_latest/vm.rs @@ -1,21 +1,25 @@ -use crate::HistoryMode; use zksync_state::{StoragePtr, WriteStorage}; -use zksync_types::l2_to_l1_log::{SystemL2ToL1Log, UserL2ToL1Log}; -use zksync_types::{event::extract_l2tol1logs_from_l1_messenger, Transaction}; +use zksync_types::{ + event::extract_l2tol1logs_from_l1_messenger, + l2_to_l1_log::{SystemL2ToL1Log, UserL2ToL1Log}, + Transaction, +}; use zksync_utils::bytecode::CompressedBytecodeInfo; -use crate::vm_latest::old_vm::events::merge_events; -use crate::vm_latest::old_vm::history_recorder::HistoryEnabled; - -use crate::interface::{ - BootloaderMemory, CurrentExecutionState, L1BatchEnv, L2BlockEnv, SystemEnv, VmExecutionMode, - VmExecutionResultAndLogs, VmInterfaceHistoryEnabled, VmMemoryMetrics, +use crate::{ + interface::{ + BootloaderMemory, BytecodeCompressionError, CurrentExecutionState, L1BatchEnv, L2BlockEnv, + SystemEnv, VmExecutionMode, VmExecutionResultAndLogs, VmInterface, + VmInterfaceHistoryEnabled, VmMemoryMetrics, + }, + vm_latest::{ + bootloader_state::BootloaderState, + old_vm::{events::merge_events, history_recorder::HistoryEnabled}, + tracers::dispatcher::TracerDispatcher, + types::internals::{new_vm_state, VmSnapshot, ZkSyncVmState}, + }, + HistoryMode, }; -use crate::interface::{BytecodeCompressionError, VmInterface}; -use crate::vm_latest::bootloader_state::BootloaderState; -use crate::vm_latest::tracers::dispatcher::TracerDispatcher; - -use crate::vm_latest::types::internals::{new_vm_state, VmSnapshot, ZkSyncVmState}; /// Main entry point for Virtual Machine integration. /// The instance should process only one l1 batch diff --git a/core/lib/multivm/src/versions/vm_m5/errors/vm_revert_reason.rs b/core/lib/multivm/src/versions/vm_m5/errors/vm_revert_reason.rs index 5d1a075f6a5..7cfa8708fc3 100644 --- a/core/lib/multivm/src/versions/vm_m5/errors/vm_revert_reason.rs +++ b/core/lib/multivm/src/versions/vm_m5/errors/vm_revert_reason.rs @@ -1,5 +1,7 @@ -use std::convert::TryFrom; -use std::fmt::{Debug, Display}; +use std::{ + convert::TryFrom, + fmt::{Debug, Display}, +}; use zksync_types::U256; diff --git a/core/lib/multivm/src/versions/vm_m5/event_sink.rs b/core/lib/multivm/src/versions/vm_m5/event_sink.rs index 80ceb8baeaa..0bb1ee498f6 100644 --- a/core/lib/multivm/src/versions/vm_m5/event_sink.rs +++ b/core/lib/multivm/src/versions/vm_m5/event_sink.rs @@ -1,5 +1,5 @@ -use crate::vm_m5::{oracles::OracleWithHistory, utils::collect_log_queries_after_timestamp}; use std::collections::HashMap; + use zk_evm_1_3_1::{ abstractions::EventSink, aux_structures::{LogQuery, Timestamp}, @@ -9,7 +9,10 @@ use zk_evm_1_3_1::{ }, }; -use crate::vm_m5::history_recorder::AppDataFrameManagerWithHistory; +use crate::vm_m5::{ + history_recorder::AppDataFrameManagerWithHistory, oracles::OracleWithHistory, + utils::collect_log_queries_after_timestamp, +}; #[derive(Debug, Default, Clone, PartialEq)] pub struct InMemoryEventSink { diff --git a/core/lib/multivm/src/versions/vm_m5/history_recorder.rs b/core/lib/multivm/src/versions/vm_m5/history_recorder.rs index 896b2261e9c..7a158b4dea7 100644 --- a/core/lib/multivm/src/versions/vm_m5/history_recorder.rs +++ b/core/lib/multivm/src/versions/vm_m5/history_recorder.rs @@ -3,18 +3,17 @@ use std::{ hash::{BuildHasherDefault, Hash, Hasher}, }; -use crate::vm_m5::storage::{Storage, StoragePtr}; - use zk_evm_1_3_1::{ aux_structures::Timestamp, reference_impls::event_sink::ApplicationData, vm_state::PrimitiveValue, zkevm_opcode_defs::{self}, }; - use zksync_types::{StorageKey, U256}; use zksync_utils::{h256_to_u256, u256_to_h256}; +use crate::vm_m5::storage::{Storage, StoragePtr}; + pub type AppDataFrameManagerWithHistory = FrameManagerWithHistory>; pub type MemoryWithHistory = HistoryRecorder; pub type FrameManagerWithHistory = HistoryRecorder>; diff --git a/core/lib/multivm/src/versions/vm_m5/memory.rs b/core/lib/multivm/src/versions/vm_m5/memory.rs index 2c0b317a798..dc58450263e 100644 --- a/core/lib/multivm/src/versions/vm_m5/memory.rs +++ b/core/lib/multivm/src/versions/vm_m5/memory.rs @@ -1,12 +1,16 @@ -use zk_evm_1_3_1::abstractions::{Memory, MemoryType, MEMORY_CELLS_OTHER_PAGES}; -use zk_evm_1_3_1::aux_structures::{MemoryPage, MemoryQuery, Timestamp}; -use zk_evm_1_3_1::vm_state::PrimitiveValue; -use zk_evm_1_3_1::zkevm_opcode_defs::FatPointer; +use zk_evm_1_3_1::{ + abstractions::{Memory, MemoryType, MEMORY_CELLS_OTHER_PAGES}, + aux_structures::{MemoryPage, MemoryQuery, Timestamp}, + vm_state::PrimitiveValue, + zkevm_opcode_defs::FatPointer, +}; use zksync_types::U256; -use crate::vm_m5::history_recorder::{IntFrameManagerWithHistory, MemoryWithHistory}; -use crate::vm_m5::oracles::OracleWithHistory; -use crate::vm_m5::utils::{aux_heap_page_from_base, heap_page_from_base, stack_page_from_base}; +use crate::vm_m5::{ + history_recorder::{IntFrameManagerWithHistory, MemoryWithHistory}, + oracles::OracleWithHistory, + utils::{aux_heap_page_from_base, heap_page_from_base, stack_page_from_base}, +}; #[derive(Debug, Default, Clone, PartialEq)] pub struct SimpleMemory { diff --git a/core/lib/multivm/src/versions/vm_m5/mod.rs b/core/lib/multivm/src/versions/vm_m5/mod.rs index d8231ea502d..fc549761e03 100644 --- a/core/lib/multivm/src/versions/vm_m5/mod.rs +++ b/core/lib/multivm/src/versions/vm_m5/mod.rs @@ -1,5 +1,16 @@ #![allow(clippy::derive_partial_eq_without_eq)] +pub use zk_evm_1_3_1; +pub use zksync_types::vm_trace::VmExecutionTrace; + +pub use self::{ + errors::TxRevertReason, + oracle_tools::OracleTools, + oracles::storage::StorageOracle, + vm::Vm, + vm_instance::{VmBlockResult, VmExecutionResult}, +}; + mod bootloader_state; pub mod errors; pub mod event_sink; @@ -12,24 +23,14 @@ mod pubdata_utils; mod refunds; pub mod storage; pub mod test_utils; +#[cfg(test)] +mod tests; pub mod transaction_data; pub mod utils; +mod vm; pub mod vm_instance; pub mod vm_with_bootloader; -#[cfg(test)] -mod tests; -mod vm; - -pub use errors::TxRevertReason; -pub use oracle_tools::OracleTools; -pub use oracles::storage::StorageOracle; -pub use vm::Vm; -pub use vm_instance::VmBlockResult; -pub use vm_instance::VmExecutionResult; -pub use zk_evm_1_3_1; -pub use zksync_types::vm_trace::VmExecutionTrace; - pub type Word = zksync_types::U256; pub const MEMORY_SIZE: usize = 1 << 16; diff --git a/core/lib/multivm/src/versions/vm_m5/oracle_tools.rs b/core/lib/multivm/src/versions/vm_m5/oracle_tools.rs index 4858a23adb6..32930f31cd7 100644 --- a/core/lib/multivm/src/versions/vm_m5/oracle_tools.rs +++ b/core/lib/multivm/src/versions/vm_m5/oracle_tools.rs @@ -1,15 +1,18 @@ -use crate::vm_m5::memory::SimpleMemory; -use crate::vm_m5::vm_instance::MultiVMSubversion; - use std::fmt::Debug; -use crate::vm_m5::event_sink::InMemoryEventSink; -use crate::vm_m5::oracles::decommitter::DecommitterOracle; -use crate::vm_m5::oracles::precompile::PrecompilesProcessorWithHistory; -use crate::vm_m5::oracles::storage::StorageOracle; -use crate::vm_m5::storage::{Storage, StoragePtr}; use zk_evm_1_3_1::witness_trace::DummyTracer; +use crate::vm_m5::{ + event_sink::InMemoryEventSink, + memory::SimpleMemory, + oracles::{ + decommitter::DecommitterOracle, precompile::PrecompilesProcessorWithHistory, + storage::StorageOracle, + }, + storage::{Storage, StoragePtr}, + vm_instance::MultiVMSubversion, +}; + #[derive(Debug)] pub struct OracleTools { pub storage: StorageOracle, diff --git a/core/lib/multivm/src/versions/vm_m5/oracles/decommitter.rs b/core/lib/multivm/src/versions/vm_m5/oracles/decommitter.rs index 24a18f998df..bc43c72966e 100644 --- a/core/lib/multivm/src/versions/vm_m5/oracles/decommitter.rs +++ b/core/lib/multivm/src/versions/vm_m5/oracles/decommitter.rs @@ -1,20 +1,19 @@ use std::collections::HashMap; -use crate::vm_m5::history_recorder::HistoryRecorder; -use crate::vm_m5::storage::{Storage, StoragePtr}; - -use zk_evm_1_3_1::abstractions::MemoryType; -use zk_evm_1_3_1::aux_structures::Timestamp; use zk_evm_1_3_1::{ - abstractions::{DecommittmentProcessor, Memory}, - aux_structures::{DecommittmentQuery, MemoryIndex, MemoryLocation, MemoryPage, MemoryQuery}, + abstractions::{DecommittmentProcessor, Memory, MemoryType}, + aux_structures::{ + DecommittmentQuery, MemoryIndex, MemoryLocation, MemoryPage, MemoryQuery, Timestamp, + }, }; - use zksync_types::U256; -use zksync_utils::bytecode::bytecode_len_in_words; -use zksync_utils::{bytes_to_be_words, u256_to_h256}; +use zksync_utils::{bytecode::bytecode_len_in_words, bytes_to_be_words, u256_to_h256}; use super::OracleWithHistory; +use crate::vm_m5::{ + history_recorder::HistoryRecorder, + storage::{Storage, StoragePtr}, +}; #[derive(Debug)] pub struct DecommitterOracle { diff --git a/core/lib/multivm/src/versions/vm_m5/oracles/mod.rs b/core/lib/multivm/src/versions/vm_m5/oracles/mod.rs index 31686fa70f6..6b821c68e9d 100644 --- a/core/lib/multivm/src/versions/vm_m5/oracles/mod.rs +++ b/core/lib/multivm/src/versions/vm_m5/oracles/mod.rs @@ -1,11 +1,10 @@ use zk_evm_1_3_1::aux_structures::Timestamp; -// We will discard RAM as soon as the execution of a tx ends, so -// it is ok for now to use SimpleMemory -pub use zk_evm_1_3_1::reference_impls::memory::SimpleMemory as RamOracle; // All the changes to the events in the DB will be applied after the tx is executed, // so fow now it is fine. pub use zk_evm_1_3_1::reference_impls::event_sink::InMemoryEventSink as EventSinkOracle; - +// We will discard RAM as soon as the execution of a tx ends, so +// it is ok for now to use SimpleMemory +pub use zk_evm_1_3_1::reference_impls::memory::SimpleMemory as RamOracle; pub use zk_evm_1_3_1::testing::simple_tracer::NoopTracer; pub mod decommitter; diff --git a/core/lib/multivm/src/versions/vm_m5/oracles/precompile.rs b/core/lib/multivm/src/versions/vm_m5/oracles/precompile.rs index 137a1046d48..41a00b2e8a5 100644 --- a/core/lib/multivm/src/versions/vm_m5/oracles/precompile.rs +++ b/core/lib/multivm/src/versions/vm_m5/oracles/precompile.rs @@ -1,14 +1,11 @@ use zk_evm_1_3_1::{ - abstractions::Memory, - abstractions::PrecompileCyclesWitness, - abstractions::PrecompilesProcessor, + abstractions::{Memory, PrecompileCyclesWitness, PrecompilesProcessor}, aux_structures::{LogQuery, MemoryQuery, Timestamp}, precompiles::DefaultPrecompilesProcessor, }; -use crate::vm_m5::history_recorder::HistoryRecorder; - use super::OracleWithHistory; +use crate::vm_m5::history_recorder::HistoryRecorder; /// Wrap of DefaultPrecompilesProcessor that store queue /// of timestamp when precompiles are called to be executed. diff --git a/core/lib/multivm/src/versions/vm_m5/oracles/storage.rs b/core/lib/multivm/src/versions/vm_m5/oracles/storage.rs index ca2c3ab7514..c81b90f9c9c 100644 --- a/core/lib/multivm/src/versions/vm_m5/oracles/storage.rs +++ b/core/lib/multivm/src/versions/vm_m5/oracles/storage.rs @@ -1,29 +1,28 @@ use std::collections::HashMap; -use crate::vm_m5::storage::{Storage, StoragePtr}; - -use crate::vm_m5::history_recorder::{ - AppDataFrameManagerWithHistory, HashMapHistoryEvent, HistoryRecorder, StorageWrapper, -}; -use crate::vm_m5::vm_instance::MultiVMSubversion; - -use zk_evm_1_3_1::abstractions::RefundedAmounts; -use zk_evm_1_3_1::zkevm_opcode_defs::system_params::INITIAL_STORAGE_WRITE_PUBDATA_BYTES; use zk_evm_1_3_1::{ - abstractions::{RefundType, Storage as VmStorageOracle}, + abstractions::{RefundType, RefundedAmounts, Storage as VmStorageOracle}, aux_structures::{LogQuery, Timestamp}, reference_impls::event_sink::ApplicationData, + zkevm_opcode_defs::system_params::INITIAL_STORAGE_WRITE_PUBDATA_BYTES, }; - -use crate::glue::GlueInto; -use zksync_types::utils::storage_key_for_eth_balance; use zksync_types::{ - AccountTreeId, Address, StorageKey, StorageLogQuery, StorageLogQueryType, BOOTLOADER_ADDRESS, - U256, + utils::storage_key_for_eth_balance, AccountTreeId, Address, StorageKey, StorageLogQuery, + StorageLogQueryType, BOOTLOADER_ADDRESS, U256, }; use zksync_utils::u256_to_h256; use super::OracleWithHistory; +use crate::{ + glue::GlueInto, + vm_m5::{ + history_recorder::{ + AppDataFrameManagerWithHistory, HashMapHistoryEvent, HistoryRecorder, StorageWrapper, + }, + storage::{Storage, StoragePtr}, + vm_instance::MultiVMSubversion, + }, +}; // While the storage does not support different shards, it was decided to write the // code of the StorageOracle with the shard parameters in mind. diff --git a/core/lib/multivm/src/versions/vm_m5/oracles/tracer.rs b/core/lib/multivm/src/versions/vm_m5/oracles/tracer.rs index a9e3c32786a..ac370f832e4 100644 --- a/core/lib/multivm/src/versions/vm_m5/oracles/tracer.rs +++ b/core/lib/multivm/src/versions/vm_m5/oracles/tracer.rs @@ -1,19 +1,8 @@ -use std::fmt::Debug; use std::{ collections::HashSet, - fmt::{self, Display}, + fmt::{self, Debug, Display}, }; -use crate::vm_m5::{ - errors::VmRevertReasonParsingResult, - memory::SimpleMemory, - storage::StoragePtr, - utils::{aux_heap_page_from_base, heap_page_from_base}, - vm_instance::{get_vm_hook_params, VM_HOOK_POSITION}, - vm_with_bootloader::BOOTLOADER_HEAP_PAGE, -}; -// use zk_evm_1_3_1::testing::memory::SimpleMemory; -use crate::vm_m5::storage::Storage; use zk_evm_1_3_1::{ abstractions::{ AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, @@ -26,7 +15,6 @@ use zk_evm_1_3_1::{ LogOpcode, Opcode, RetOpcode, UMAOpcode, }, }; - use zksync_types::{ get_code_key, web3::signing::keccak256, AccountTreeId, Address, StorageKey, ACCOUNT_CODE_STORAGE_ADDRESS, BOOTLOADER_ADDRESS, CONTRACT_DEPLOYER_ADDRESS, H256, @@ -37,6 +25,15 @@ use zksync_utils::{ be_bytes_to_safe_address, h256_to_account_address, u256_to_account_address, u256_to_h256, }; +use crate::vm_m5::{ + errors::VmRevertReasonParsingResult, + memory::SimpleMemory, + storage::{Storage, StoragePtr}, + utils::{aux_heap_page_from_base, heap_page_from_base}, + vm_instance::{get_vm_hook_params, VM_HOOK_POSITION}, + vm_with_bootloader::BOOTLOADER_HEAP_PAGE, +}; + pub trait ExecutionEndTracer: Tracer { // Returns whether the vm execution should stop. fn should_stop_execution(&self) -> bool; diff --git a/core/lib/multivm/src/versions/vm_m5/pubdata_utils.rs b/core/lib/multivm/src/versions/vm_m5/pubdata_utils.rs index 80c1cd2c0e4..63e45edcbb8 100644 --- a/core/lib/multivm/src/versions/vm_m5/pubdata_utils.rs +++ b/core/lib/multivm/src/versions/vm_m5/pubdata_utils.rs @@ -1,16 +1,21 @@ -use crate::vm_m5::oracles::storage::storage_key_of_log; -use crate::vm_m5::storage::Storage; -use crate::vm_m5::utils::collect_storage_log_queries_after_timestamp; -use crate::vm_m5::vm_instance::VmInstance; use std::collections::HashMap; -use zk_evm_1_3_1::aux_structures::Timestamp; -use crate::glue::GlueInto; -use zksync_types::event::{extract_long_l2_to_l1_messages, extract_published_bytecodes}; -use zksync_types::zkevm_test_harness::witness::sort_storage_access::sort_storage_access_queries; -use zksync_types::{StorageKey, PUBLISH_BYTECODE_OVERHEAD, SYSTEM_CONTEXT_ADDRESS}; +use zk_evm_1_3_1::aux_structures::Timestamp; +use zksync_types::{ + event::{extract_long_l2_to_l1_messages, extract_published_bytecodes}, + zkevm_test_harness::witness::sort_storage_access::sort_storage_access_queries, + StorageKey, PUBLISH_BYTECODE_OVERHEAD, SYSTEM_CONTEXT_ADDRESS, +}; use zksync_utils::bytecode::bytecode_len_in_bytes; +use crate::{ + glue::GlueInto, + vm_m5::{ + oracles::storage::storage_key_of_log, storage::Storage, + utils::collect_storage_log_queries_after_timestamp, vm_instance::VmInstance, + }, +}; + impl VmInstance { pub fn pubdata_published(&self, from_timestamp: Timestamp) -> u32 { let storage_writes_pubdata_published = self.pubdata_published_for_writes(from_timestamp); diff --git a/core/lib/multivm/src/versions/vm_m5/refunds.rs b/core/lib/multivm/src/versions/vm_m5/refunds.rs index 8f1b2b44f4d..8e084fd9ee3 100644 --- a/core/lib/multivm/src/versions/vm_m5/refunds.rs +++ b/core/lib/multivm/src/versions/vm_m5/refunds.rs @@ -1,13 +1,13 @@ -use crate::vm_m5::storage::Storage; -use crate::vm_m5::vm_instance::VmInstance; -use crate::vm_m5::vm_with_bootloader::{ - eth_price_per_pubdata_byte, BOOTLOADER_HEAP_PAGE, TX_GAS_LIMIT_OFFSET, -}; use zk_evm_1_3_1::aux_structures::Timestamp; - use zksync_types::U256; use zksync_utils::ceil_div_u256; +use crate::vm_m5::{ + storage::Storage, + vm_instance::VmInstance, + vm_with_bootloader::{eth_price_per_pubdata_byte, BOOTLOADER_HEAP_PAGE, TX_GAS_LIMIT_OFFSET}, +}; + impl VmInstance { pub(crate) fn tx_body_refund( &self, diff --git a/core/lib/multivm/src/versions/vm_m5/storage.rs b/core/lib/multivm/src/versions/vm_m5/storage.rs index d5f448812ca..deb3501b416 100644 --- a/core/lib/multivm/src/versions/vm_m5/storage.rs +++ b/core/lib/multivm/src/versions/vm_m5/storage.rs @@ -1,7 +1,4 @@ -use std::cell::RefCell; -use std::collections::HashMap; -use std::fmt::Debug; -use std::rc::Rc; +use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc}; use zksync_state::{ReadStorage, WriteStorage}; use zksync_types::{StorageKey, StorageValue, H256}; diff --git a/core/lib/multivm/src/versions/vm_m5/test_utils.rs b/core/lib/multivm/src/versions/vm_m5/test_utils.rs index 36c1d60dfda..6920e77b8a8 100644 --- a/core/lib/multivm/src/versions/vm_m5/test_utils.rs +++ b/core/lib/multivm/src/versions/vm_m5/test_utils.rs @@ -12,8 +12,10 @@ use itertools::Itertools; use zk_evm_1_3_1::{ aux_structures::Timestamp, reference_impls::event_sink::ApplicationData, vm_state::VmLocalState, }; -use zksync_contracts::test_contracts::LoadnextContractExecutionParams; -use zksync_contracts::{deployer_contract, get_loadnext_contract, load_contract}; +use zksync_contracts::{ + deployer_contract, get_loadnext_contract, load_contract, + test_contracts::LoadnextContractExecutionParams, +}; use zksync_types::{ ethabi::{Address, Token}, fee::Fee, @@ -26,13 +28,12 @@ use zksync_utils::{ address_to_h256, bytecode::hash_bytecode, h256_to_account_address, u256_to_h256, }; -use crate::vm_m5::storage::Storage; -use crate::vm_m5::vm_instance::VmInstance; -/// The tests here help us with the testing the VM use crate::vm_m5::{ event_sink::InMemoryEventSink, history_recorder::{FrameManager, HistoryRecorder}, memory::SimpleMemory, + storage::Storage, + vm_instance::VmInstance, }; #[derive(Clone, Debug)] diff --git a/core/lib/multivm/src/versions/vm_m5/transaction_data.rs b/core/lib/multivm/src/versions/vm_m5/transaction_data.rs index 819f22a5324..f150db2ebaa 100644 --- a/core/lib/multivm/src/versions/vm_m5/transaction_data.rs +++ b/core/lib/multivm/src/versions/vm_m5/transaction_data.rs @@ -1,10 +1,13 @@ use zk_evm_1_3_1::zkevm_opcode_defs::system_params::{MAX_PUBDATA_PER_BLOCK, MAX_TX_ERGS_LIMIT}; -use zksync_types::ethabi::{encode, Address, Token}; -use zksync_types::fee::encoding_len; -use zksync_types::MAX_TXS_IN_BLOCK; -use zksync_types::{l2::TransactionType, ExecuteTransactionCommon, Transaction, U256}; -use zksync_utils::{address_to_h256, ceil_div_u256}; -use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256}; +use zksync_types::{ + ethabi::{encode, Address, Token}, + fee::encoding_len, + l2::TransactionType, + ExecuteTransactionCommon, Transaction, MAX_TXS_IN_BLOCK, U256, +}; +use zksync_utils::{ + address_to_h256, bytecode::hash_bytecode, bytes_to_be_words, ceil_div_u256, h256_to_u256, +}; use crate::vm_m5::vm_with_bootloader::{ BLOCK_OVERHEAD_GAS, BLOCK_OVERHEAD_PUBDATA, BOOTLOADER_TX_ENCODING_SPACE, diff --git a/core/lib/multivm/src/versions/vm_m5/utils.rs b/core/lib/multivm/src/versions/vm_m5/utils.rs index b8fef994428..09170a8f502 100644 --- a/core/lib/multivm/src/versions/vm_m5/utils.rs +++ b/core/lib/multivm/src/versions/vm_m5/utils.rs @@ -1,10 +1,7 @@ -use crate::vm_m5::{memory::SimpleMemory, vm_with_bootloader::BlockContext}; use once_cell::sync::Lazy; - -use crate::glue::GlueInto; -use zk_evm_1_3_1::block_properties::BlockProperties; use zk_evm_1_3_1::{ aux_structures::{LogQuery, MemoryPage, Timestamp}, + block_properties::BlockProperties, vm_state::PrimitiveValue, zkevm_opcode_defs::FatPointer, }; @@ -13,6 +10,11 @@ use zksync_system_constants::ZKPORTER_IS_AVAILABLE; use zksync_types::{Address, StorageLogQuery, H160, MAX_L2_TX_GAS_LIMIT, U256}; use zksync_utils::h256_to_u256; +use crate::{ + glue::GlueInto, + vm_m5::{memory::SimpleMemory, vm_with_bootloader::BlockContext}, +}; + pub const INITIAL_TIMESTAMP: u32 = 1024; pub const INITIAL_MEMORY_COUNTER: u32 = 2048; pub const INITIAL_CALLDATA_PAGE: u32 = 7; diff --git a/core/lib/multivm/src/versions/vm_m5/vm.rs b/core/lib/multivm/src/versions/vm_m5/vm.rs index 87186bb7f15..67c4f126309 100644 --- a/core/lib/multivm/src/versions/vm_m5/vm.rs +++ b/core/lib/multivm/src/versions/vm_m5/vm.rs @@ -1,21 +1,23 @@ -use crate::interface::{ - BootloaderMemory, BytecodeCompressionError, CurrentExecutionState, FinishedL1Batch, L1BatchEnv, - L2BlockEnv, SystemEnv, TxExecutionMode, VmExecutionMode, VmExecutionResultAndLogs, VmInterface, - VmInterfaceHistoryEnabled, VmMemoryMetrics, -}; - use zksync_state::StoragePtr; -use zksync_types::l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}; -use zksync_types::{Transaction, VmVersion}; -use zksync_utils::bytecode::CompressedBytecodeInfo; -use zksync_utils::{h256_to_u256, u256_to_h256}; - -use crate::glue::history_mode::HistoryMode; -use crate::glue::GlueInto; -use crate::vm_m5::events::merge_events; -use crate::vm_m5::storage::Storage; -use crate::vm_m5::vm_instance::MultiVMSubversion; -use crate::vm_m5::vm_instance::VmInstance; +use zksync_types::{ + l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}, + Transaction, VmVersion, +}; +use zksync_utils::{bytecode::CompressedBytecodeInfo, h256_to_u256, u256_to_h256}; + +use crate::{ + glue::{history_mode::HistoryMode, GlueInto}, + interface::{ + BootloaderMemory, BytecodeCompressionError, CurrentExecutionState, FinishedL1Batch, + L1BatchEnv, L2BlockEnv, SystemEnv, TxExecutionMode, VmExecutionMode, + VmExecutionResultAndLogs, VmInterface, VmInterfaceHistoryEnabled, VmMemoryMetrics, + }, + vm_m5::{ + events::merge_events, + storage::Storage, + vm_instance::{MultiVMSubversion, VmInstance}, + }, +}; #[derive(Debug)] pub struct Vm { diff --git a/core/lib/multivm/src/versions/vm_m5/vm_instance.rs b/core/lib/multivm/src/versions/vm_m5/vm_instance.rs index 5638ed1c023..99a96ded4d4 100644 --- a/core/lib/multivm/src/versions/vm_m5/vm_instance.rs +++ b/core/lib/multivm/src/versions/vm_m5/vm_instance.rs @@ -1,43 +1,52 @@ -use std::convert::TryFrom; -use std::fmt::Debug; - -use zk_evm_1_3_1::aux_structures::Timestamp; -use zk_evm_1_3_1::vm_state::{PrimitiveValue, VmLocalState, VmState}; -use zk_evm_1_3_1::witness_trace::DummyTracer; -use zk_evm_1_3_1::zkevm_opcode_defs::decoding::{ - AllowedPcOrImm, EncodingModeProduction, VmEncodingMode, +use std::{convert::TryFrom, fmt::Debug}; + +use zk_evm_1_3_1::{ + aux_structures::Timestamp, + vm_state::{PrimitiveValue, VmLocalState, VmState}, + witness_trace::DummyTracer, + zkevm_opcode_defs::{ + decoding::{AllowedPcOrImm, EncodingModeProduction, VmEncodingMode}, + definitions::RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER, + }, }; -use zk_evm_1_3_1::zkevm_opcode_defs::definitions::RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER; use zksync_system_constants::MAX_TXS_IN_BLOCK; - -use crate::glue::GlueInto; -use zksync_types::l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}; -use zksync_types::tx::tx_execution_info::TxExecutionStatus; -use zksync_types::vm_trace::VmExecutionTrace; -use zksync_types::{L1BatchNumber, StorageLogQuery, VmEvent, U256}; - -use crate::interface::types::outputs::VmExecutionLogs; -use crate::vm_m5::bootloader_state::BootloaderState; -use crate::vm_m5::errors::{TxRevertReason, VmRevertReason, VmRevertReasonParsingResult}; -use crate::vm_m5::event_sink::InMemoryEventSink; -use crate::vm_m5::events::merge_events; -use crate::vm_m5::memory::SimpleMemory; -use crate::vm_m5::oracles::decommitter::DecommitterOracle; -use crate::vm_m5::oracles::precompile::PrecompilesProcessorWithHistory; -use crate::vm_m5::oracles::storage::StorageOracle; -use crate::vm_m5::oracles::tracer::{ - BootloaderTracer, ExecutionEndTracer, OneTxTracer, PendingRefundTracer, PubdataSpentTracer, - TransactionResultTracer, ValidationError, ValidationTracer, ValidationTracerParams, -}; -use crate::vm_m5::oracles::OracleWithHistory; -use crate::vm_m5::storage::Storage; -use crate::vm_m5::utils::{ - collect_log_queries_after_timestamp, collect_storage_log_queries_after_timestamp, - dump_memory_page_using_primitive_value, precompile_calls_count_after_timestamp, +use zksync_types::{ + l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}, + tx::tx_execution_info::TxExecutionStatus, + vm_trace::VmExecutionTrace, + L1BatchNumber, StorageLogQuery, VmEvent, U256, }; -use crate::vm_m5::vm_with_bootloader::{ - BootloaderJobType, DerivedBlockContext, TxExecutionMode, BOOTLOADER_HEAP_PAGE, - OPERATOR_REFUNDS_OFFSET, + +use crate::{ + glue::GlueInto, + interface::types::outputs::VmExecutionLogs, + vm_m5::{ + bootloader_state::BootloaderState, + errors::{TxRevertReason, VmRevertReason, VmRevertReasonParsingResult}, + event_sink::InMemoryEventSink, + events::merge_events, + memory::SimpleMemory, + oracles::{ + decommitter::DecommitterOracle, + precompile::PrecompilesProcessorWithHistory, + storage::StorageOracle, + tracer::{ + BootloaderTracer, ExecutionEndTracer, OneTxTracer, PendingRefundTracer, + PubdataSpentTracer, TransactionResultTracer, ValidationError, ValidationTracer, + ValidationTracerParams, + }, + OracleWithHistory, + }, + storage::Storage, + utils::{ + collect_log_queries_after_timestamp, collect_storage_log_queries_after_timestamp, + dump_memory_page_using_primitive_value, precompile_calls_count_after_timestamp, + }, + vm_with_bootloader::{ + BootloaderJobType, DerivedBlockContext, TxExecutionMode, BOOTLOADER_HEAP_PAGE, + OPERATOR_REFUNDS_OFFSET, + }, + }, }; pub type ZkSyncVmState = VmState< diff --git a/core/lib/multivm/src/versions/vm_m5/vm_with_bootloader.rs b/core/lib/multivm/src/versions/vm_m5/vm_with_bootloader.rs index 0116660594e..f9ba88fea14 100644 --- a/core/lib/multivm/src/versions/vm_m5/vm_with_bootloader.rs +++ b/core/lib/multivm/src/versions/vm_m5/vm_with_bootloader.rs @@ -12,7 +12,6 @@ use zk_evm_1_3_1::{ }; use zksync_contracts::BaseSystemContracts; use zksync_system_constants::MAX_TXS_IN_BLOCK; - use zksync_types::{ zkevm_test_harness::INITIAL_MONOTONIC_CYCLE_COUNTER, Address, Transaction, BOOTLOADER_ADDRESS, L1_GAS_PER_PUBDATA_BYTE, MAX_GAS_PER_PUBDATA_BYTE, MAX_NEW_FACTORY_DEPS, U256, @@ -21,16 +20,15 @@ use zksync_utils::{ address_to_u256, bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256, misc::ceil_div, }; -use crate::vm_m5::storage::Storage; use crate::vm_m5::{ bootloader_state::BootloaderState, oracles::OracleWithHistory, + storage::Storage, transaction_data::TransactionData, utils::{ code_page_candidate_from_base, heap_page_from_base, BLOCK_GAS_LIMIT, INITIAL_BASE_PAGE, }, - vm_instance::VmInstance, - vm_instance::{MultiVMSubversion, ZkSyncVmState}, + vm_instance::{MultiVMSubversion, VmInstance, ZkSyncVmState}, OracleTools, }; diff --git a/core/lib/multivm/src/versions/vm_m6/errors/vm_revert_reason.rs b/core/lib/multivm/src/versions/vm_m6/errors/vm_revert_reason.rs index 9025ee9f378..fb2341c0b2e 100644 --- a/core/lib/multivm/src/versions/vm_m6/errors/vm_revert_reason.rs +++ b/core/lib/multivm/src/versions/vm_m6/errors/vm_revert_reason.rs @@ -1,5 +1,7 @@ -use std::convert::TryFrom; -use std::fmt::{Debug, Display}; +use std::{ + convert::TryFrom, + fmt::{Debug, Display}, +}; use zksync_types::U256; diff --git a/core/lib/multivm/src/versions/vm_m6/event_sink.rs b/core/lib/multivm/src/versions/vm_m6/event_sink.rs index 41fd22e9eed..2fb5d934e96 100644 --- a/core/lib/multivm/src/versions/vm_m6/event_sink.rs +++ b/core/lib/multivm/src/versions/vm_m6/event_sink.rs @@ -1,9 +1,5 @@ -use crate::vm_m6::{ - history_recorder::{AppDataFrameManagerWithHistory, HistoryEnabled, HistoryMode}, - oracles::OracleWithHistory, - utils::collect_log_queries_after_timestamp, -}; use std::collections::HashMap; + use zk_evm_1_3_1::{ abstractions::EventSink, aux_structures::{LogQuery, Timestamp}, @@ -13,6 +9,12 @@ use zk_evm_1_3_1::{ }, }; +use crate::vm_m6::{ + history_recorder::{AppDataFrameManagerWithHistory, HistoryEnabled, HistoryMode}, + oracles::OracleWithHistory, + utils::collect_log_queries_after_timestamp, +}; + #[derive(Debug, Clone, PartialEq, Default)] pub struct InMemoryEventSink { pub frames_stack: AppDataFrameManagerWithHistory, diff --git a/core/lib/multivm/src/versions/vm_m6/history_recorder.rs b/core/lib/multivm/src/versions/vm_m6/history_recorder.rs index a85279e56c1..7ec8b2fde3b 100644 --- a/core/lib/multivm/src/versions/vm_m6/history_recorder.rs +++ b/core/lib/multivm/src/versions/vm_m6/history_recorder.rs @@ -4,17 +4,16 @@ use std::{ hash::{BuildHasherDefault, Hash, Hasher}, }; -use crate::vm_m6::storage::{Storage, StoragePtr}; - use zk_evm_1_3_1::{ aux_structures::Timestamp, vm_state::PrimitiveValue, zkevm_opcode_defs::{self}, }; - use zksync_types::{StorageKey, U256}; use zksync_utils::{h256_to_u256, u256_to_h256}; +use crate::vm_m6::storage::{Storage, StoragePtr}; + pub type MemoryWithHistory = HistoryRecorder; pub type IntFrameManagerWithHistory = HistoryRecorder, H>; diff --git a/core/lib/multivm/src/versions/vm_m6/memory.rs b/core/lib/multivm/src/versions/vm_m6/memory.rs index 52a3d7f606f..5a5042e5657 100644 --- a/core/lib/multivm/src/versions/vm_m6/memory.rs +++ b/core/lib/multivm/src/versions/vm_m6/memory.rs @@ -1,15 +1,19 @@ -use zk_evm_1_3_1::abstractions::{Memory, MemoryType, MEMORY_CELLS_OTHER_PAGES}; -use zk_evm_1_3_1::aux_structures::{MemoryPage, MemoryQuery, Timestamp}; -use zk_evm_1_3_1::vm_state::PrimitiveValue; -use zk_evm_1_3_1::zkevm_opcode_defs::FatPointer; +use zk_evm_1_3_1::{ + abstractions::{Memory, MemoryType, MEMORY_CELLS_OTHER_PAGES}, + aux_structures::{MemoryPage, MemoryQuery, Timestamp}, + vm_state::PrimitiveValue, + zkevm_opcode_defs::FatPointer, +}; use zksync_types::U256; -use crate::vm_m6::history_recorder::{ - FramedStack, HistoryEnabled, HistoryMode, IntFrameManagerWithHistory, MemoryWithHistory, - MemoryWrapper, WithHistory, +use crate::vm_m6::{ + history_recorder::{ + FramedStack, HistoryEnabled, HistoryMode, IntFrameManagerWithHistory, MemoryWithHistory, + MemoryWrapper, WithHistory, + }, + oracles::OracleWithHistory, + utils::{aux_heap_page_from_base, heap_page_from_base, stack_page_from_base}, }; -use crate::vm_m6::oracles::OracleWithHistory; -use crate::vm_m6::utils::{aux_heap_page_from_base, heap_page_from_base, stack_page_from_base}; #[derive(Debug, Clone, PartialEq, Default)] pub struct SimpleMemory { diff --git a/core/lib/multivm/src/versions/vm_m6/oracle_tools.rs b/core/lib/multivm/src/versions/vm_m6/oracle_tools.rs index 4acc2fe68e5..7ae5e874806 100644 --- a/core/lib/multivm/src/versions/vm_m6/oracle_tools.rs +++ b/core/lib/multivm/src/versions/vm_m6/oracle_tools.rs @@ -1,16 +1,18 @@ -use crate::vm_m6::memory::SimpleMemory; - use std::fmt::Debug; -use crate::vm_m6::event_sink::InMemoryEventSink; -use crate::vm_m6::history_recorder::HistoryMode; -use crate::vm_m6::oracles::{ - decommitter::DecommitterOracle, precompile::PrecompilesProcessorWithHistory, - storage::StorageOracle, -}; -use crate::vm_m6::storage::{Storage, StoragePtr}; use zk_evm_1_3_1::witness_trace::DummyTracer; +use crate::vm_m6::{ + event_sink::InMemoryEventSink, + history_recorder::HistoryMode, + memory::SimpleMemory, + oracles::{ + decommitter::DecommitterOracle, precompile::PrecompilesProcessorWithHistory, + storage::StorageOracle, + }, + storage::{Storage, StoragePtr}, +}; + /// zkEVM requires a bunch of objects implementing given traits to work. /// For example: Storage, Memory, PrecompilerProcessor etc /// (you can find all these traits in zk_evm crate -> src/abstractions/mod.rs) diff --git a/core/lib/multivm/src/versions/vm_m6/oracles/decommitter.rs b/core/lib/multivm/src/versions/vm_m6/oracles/decommitter.rs index 48948827c3d..a1c2a97edf9 100644 --- a/core/lib/multivm/src/versions/vm_m6/oracles/decommitter.rs +++ b/core/lib/multivm/src/versions/vm_m6/oracles/decommitter.rs @@ -1,19 +1,19 @@ use std::collections::HashMap; -use crate::vm_m6::history_recorder::{HistoryEnabled, HistoryMode, HistoryRecorder, WithHistory}; -use crate::vm_m6::storage::{Storage, StoragePtr}; - -use zk_evm_1_3_1::abstractions::MemoryType; -use zk_evm_1_3_1::aux_structures::Timestamp; use zk_evm_1_3_1::{ - abstractions::{DecommittmentProcessor, Memory}, - aux_structures::{DecommittmentQuery, MemoryIndex, MemoryLocation, MemoryPage, MemoryQuery}, + abstractions::{DecommittmentProcessor, Memory, MemoryType}, + aux_structures::{ + DecommittmentQuery, MemoryIndex, MemoryLocation, MemoryPage, MemoryQuery, Timestamp, + }, }; use zksync_types::U256; -use zksync_utils::bytecode::bytecode_len_in_words; -use zksync_utils::{bytes_to_be_words, u256_to_h256}; +use zksync_utils::{bytecode::bytecode_len_in_words, bytes_to_be_words, u256_to_h256}; use super::OracleWithHistory; +use crate::vm_m6::{ + history_recorder::{HistoryEnabled, HistoryMode, HistoryRecorder, WithHistory}, + storage::{Storage, StoragePtr}, +}; /// The main job of the DecommiterOracle is to implement the DecommittmentProcessor trait - that is /// used by the VM to 'load' bytecodes into memory. diff --git a/core/lib/multivm/src/versions/vm_m6/oracles/mod.rs b/core/lib/multivm/src/versions/vm_m6/oracles/mod.rs index d6b00c8500d..2b7aa3a49f7 100644 --- a/core/lib/multivm/src/versions/vm_m6/oracles/mod.rs +++ b/core/lib/multivm/src/versions/vm_m6/oracles/mod.rs @@ -1,11 +1,10 @@ use zk_evm_1_3_1::aux_structures::Timestamp; -// We will discard RAM as soon as the execution of a tx ends, so -// it is ok for now to use SimpleMemory -pub use zk_evm_1_3_1::reference_impls::memory::SimpleMemory as RamOracle; // All the changes to the events in the DB will be applied after the tx is executed, // so fow now it is fine. pub use zk_evm_1_3_1::reference_impls::event_sink::InMemoryEventSink as EventSinkOracle; - +// We will discard RAM as soon as the execution of a tx ends, so +// it is ok for now to use SimpleMemory +pub use zk_evm_1_3_1::reference_impls::memory::SimpleMemory as RamOracle; pub use zk_evm_1_3_1::testing::simple_tracer::NoopTracer; pub mod decommitter; diff --git a/core/lib/multivm/src/versions/vm_m6/oracles/precompile.rs b/core/lib/multivm/src/versions/vm_m6/oracles/precompile.rs index aff382614af..2e236b70267 100644 --- a/core/lib/multivm/src/versions/vm_m6/oracles/precompile.rs +++ b/core/lib/multivm/src/versions/vm_m6/oracles/precompile.rs @@ -1,14 +1,11 @@ use zk_evm_1_3_1::{ - abstractions::Memory, - abstractions::PrecompileCyclesWitness, - abstractions::PrecompilesProcessor, + abstractions::{Memory, PrecompileCyclesWitness, PrecompilesProcessor}, aux_structures::{LogQuery, MemoryQuery, Timestamp}, precompiles::DefaultPrecompilesProcessor, }; -use crate::vm_m6::history_recorder::{HistoryEnabled, HistoryMode, HistoryRecorder}; - use super::OracleWithHistory; +use crate::vm_m6::history_recorder::{HistoryEnabled, HistoryMode, HistoryRecorder}; /// Wrap of DefaultPrecompilesProcessor that store queue /// of timestamp when precompiles are called to be executed. diff --git a/core/lib/multivm/src/versions/vm_m6/oracles/storage.rs b/core/lib/multivm/src/versions/vm_m6/oracles/storage.rs index 45c3bdf50f8..7ceab94bd47 100644 --- a/core/lib/multivm/src/versions/vm_m6/oracles/storage.rs +++ b/core/lib/multivm/src/versions/vm_m6/oracles/storage.rs @@ -1,27 +1,27 @@ use std::collections::HashMap; -use crate::vm_m6::storage::{Storage, StoragePtr}; - -use crate::glue::GlueInto; -use crate::vm_m6::history_recorder::{ - AppDataFrameManagerWithHistory, HashMapHistoryEvent, HistoryEnabled, HistoryMode, - HistoryRecorder, StorageWrapper, WithHistory, -}; - -use zk_evm_1_3_1::abstractions::RefundedAmounts; -use zk_evm_1_3_1::zkevm_opcode_defs::system_params::INITIAL_STORAGE_WRITE_PUBDATA_BYTES; use zk_evm_1_3_1::{ - abstractions::{RefundType, Storage as VmStorageOracle}, + abstractions::{RefundType, RefundedAmounts, Storage as VmStorageOracle}, aux_structures::{LogQuery, Timestamp}, + zkevm_opcode_defs::system_params::INITIAL_STORAGE_WRITE_PUBDATA_BYTES, }; -use zksync_types::utils::storage_key_for_eth_balance; use zksync_types::{ - AccountTreeId, Address, StorageKey, StorageLogQuery, StorageLogQueryType, BOOTLOADER_ADDRESS, - U256, + utils::storage_key_for_eth_balance, AccountTreeId, Address, StorageKey, StorageLogQuery, + StorageLogQueryType, BOOTLOADER_ADDRESS, U256, }; use zksync_utils::u256_to_h256; use super::OracleWithHistory; +use crate::{ + glue::GlueInto, + vm_m6::{ + history_recorder::{ + AppDataFrameManagerWithHistory, HashMapHistoryEvent, HistoryEnabled, HistoryMode, + HistoryRecorder, StorageWrapper, WithHistory, + }, + storage::{Storage, StoragePtr}, + }, +}; // While the storage does not support different shards, it was decided to write the // code of the StorageOracle with the shard parameters in mind. diff --git a/core/lib/multivm/src/versions/vm_m6/oracles/tracer/bootloader.rs b/core/lib/multivm/src/versions/vm_m6/oracles/tracer/bootloader.rs index 81902f330a5..5509cef9083 100644 --- a/core/lib/multivm/src/versions/vm_m6/oracles/tracer/bootloader.rs +++ b/core/lib/multivm/src/versions/vm_m6/oracles/tracer/bootloader.rs @@ -1,12 +1,5 @@ use std::marker::PhantomData; -use crate::vm_m6::history_recorder::HistoryMode; -use crate::vm_m6::memory::SimpleMemory; -use crate::vm_m6::oracles::tracer::{ - utils::gas_spent_on_bytecodes_and_long_messages_this_opcode, ExecutionEndTracer, - PendingRefundTracer, PubdataSpentTracer, StorageInvocationTracer, -}; - use zk_evm_1_3_1::{ abstractions::{ AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, @@ -16,6 +9,15 @@ use zk_evm_1_3_1::{ zkevm_opcode_defs::{Opcode, RetOpcode}, }; +use crate::vm_m6::{ + history_recorder::HistoryMode, + memory::SimpleMemory, + oracles::tracer::{ + utils::gas_spent_on_bytecodes_and_long_messages_this_opcode, ExecutionEndTracer, + PendingRefundTracer, PubdataSpentTracer, StorageInvocationTracer, + }, +}; + /// Tells the VM to end the execution before `ret` from the bootloader if there is no panic or revert. /// Also, saves the information if this `ret` was caused by "out of gas" panic. #[derive(Debug, Clone, Default)] diff --git a/core/lib/multivm/src/versions/vm_m6/oracles/tracer/call.rs b/core/lib/multivm/src/versions/vm_m6/oracles/tracer/call.rs index f2ddd2762ad..1166e7a8cdb 100644 --- a/core/lib/multivm/src/versions/vm_m6/oracles/tracer/call.rs +++ b/core/lib/multivm/src/versions/vm_m6/oracles/tracer/call.rs @@ -1,21 +1,24 @@ -use crate::glue::GlueInto; -use crate::vm_m6::errors::VmRevertReason; -use crate::vm_m6::history_recorder::HistoryMode; -use crate::vm_m6::memory::SimpleMemory; -use std::convert::TryFrom; -use std::marker::PhantomData; -use std::mem; -use zk_evm_1_3_1::abstractions::{ - AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, -}; -use zk_evm_1_3_1::zkevm_opcode_defs::FatPointer; -use zk_evm_1_3_1::zkevm_opcode_defs::{ - FarCallABI, FarCallOpcode, Opcode, RetOpcode, CALL_IMPLICIT_CALLDATA_FAT_PTR_REGISTER, - RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER, +use std::{convert::TryFrom, marker::PhantomData, mem}; + +use zk_evm_1_3_1::{ + abstractions::{ + AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, + }, + zkevm_opcode_defs::{ + FarCallABI, FarCallOpcode, FatPointer, Opcode, RetOpcode, + CALL_IMPLICIT_CALLDATA_FAT_PTR_REGISTER, RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER, + }, }; use zksync_system_constants::CONTRACT_DEPLOYER_ADDRESS; -use zksync_types::vm_trace::{Call, CallType}; -use zksync_types::U256; +use zksync_types::{ + vm_trace::{Call, CallType}, + U256, +}; + +use crate::{ + glue::GlueInto, + vm_m6::{errors::VmRevertReason, history_recorder::HistoryMode, memory::SimpleMemory}, +}; /// NOTE Auto implementing clone for this tracer can cause stack overflow. /// This is because of the stack field which is a Vec with nested vecs inside. @@ -283,10 +286,13 @@ fn filter_near_call(mut call: Call) -> Vec { #[cfg(test)] mod tests { - use crate::glue::GlueInto; - use crate::vm_m6::oracles::tracer::call::{filter_near_call, Call, CallType}; use zk_evm_1_3_1::zkevm_opcode_defs::FarCallOpcode; + use crate::{ + glue::GlueInto, + vm_m6::oracles::tracer::call::{filter_near_call, Call, CallType}, + }; + #[test] fn test_filter_near_calls() { let mut call = Call::default(); diff --git a/core/lib/multivm/src/versions/vm_m6/oracles/tracer/mod.rs b/core/lib/multivm/src/versions/vm_m6/oracles/tracer/mod.rs index 93486f039fa..cdf83345d2f 100644 --- a/core/lib/multivm/src/versions/vm_m6/oracles/tracer/mod.rs +++ b/core/lib/multivm/src/versions/vm_m6/oracles/tracer/mod.rs @@ -1,5 +1,15 @@ -use zk_evm_1_3_1::abstractions::Tracer; -use zk_evm_1_3_1::vm_state::VmLocalState; +use zk_evm_1_3_1::{abstractions::Tracer, vm_state::VmLocalState}; + +pub(crate) use self::transaction_result::TransactionResultTracer; +pub use self::{ + bootloader::BootloaderTracer, + call::CallTracer, + one_tx::OneTxTracer, + validation::{ + ValidationError, ValidationTracer, ValidationTracerParams, ViolatedValidationRule, + }, +}; +use crate::vm_m6::{history_recorder::HistoryMode, memory::SimpleMemory}; mod bootloader; mod call; @@ -8,18 +18,6 @@ mod transaction_result; mod utils; mod validation; -pub use bootloader::BootloaderTracer; -pub use call::CallTracer; -pub use one_tx::OneTxTracer; -pub use validation::{ - ValidationError, ValidationTracer, ValidationTracerParams, ViolatedValidationRule, -}; - -pub(crate) use transaction_result::TransactionResultTracer; - -use crate::vm_m6::history_recorder::HistoryMode; -use crate::vm_m6::memory::SimpleMemory; - pub trait ExecutionEndTracer: Tracer> { // Returns whether the vm execution should stop. fn should_stop_execution(&self) -> bool; diff --git a/core/lib/multivm/src/versions/vm_m6/oracles/tracer/one_tx.rs b/core/lib/multivm/src/versions/vm_m6/oracles/tracer/one_tx.rs index d5fbb78c909..346daba2131 100644 --- a/core/lib/multivm/src/versions/vm_m6/oracles/tracer/one_tx.rs +++ b/core/lib/multivm/src/versions/vm_m6/oracles/tracer/one_tx.rs @@ -1,23 +1,23 @@ +use zk_evm_1_3_1::{ + abstractions::{ + AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, + }, + vm_state::VmLocalState, +}; +use zksync_types::vm_trace::Call; + use super::utils::{computational_gas_price, print_debug_if_needed}; use crate::vm_m6::{ history_recorder::HistoryMode, memory::SimpleMemory, oracles::tracer::{ utils::{gas_spent_on_bytecodes_and_long_messages_this_opcode, VmHook}, - BootloaderTracer, ExecutionEndTracer, PendingRefundTracer, PubdataSpentTracer, + BootloaderTracer, CallTracer, ExecutionEndTracer, PendingRefundTracer, PubdataSpentTracer, + StorageInvocationTracer, }, vm_instance::get_vm_hook_params, }; -use crate::vm_m6::oracles::tracer::{CallTracer, StorageInvocationTracer}; -use zk_evm_1_3_1::{ - abstractions::{ - AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, - }, - vm_state::VmLocalState, -}; -use zksync_types::vm_trace::Call; - /// Allows any opcodes, but tells the VM to end the execution once the tx is over. // Internally depeds on Bootloader's VMHooks to get the notification once the transaction is finished. #[derive(Debug)] diff --git a/core/lib/multivm/src/versions/vm_m6/oracles/tracer/transaction_result.rs b/core/lib/multivm/src/versions/vm_m6/oracles/tracer/transaction_result.rs index a3e4391af24..2ecf484b60a 100644 --- a/core/lib/multivm/src/versions/vm_m6/oracles/tracer/transaction_result.rs +++ b/core/lib/multivm/src/versions/vm_m6/oracles/tracer/transaction_result.rs @@ -7,18 +7,18 @@ use zk_evm_1_3_1::{ }; use zksync_types::{vm_trace, U256}; -use crate::vm_m6::memory::SimpleMemory; -use crate::vm_m6::oracles::tracer::{ - CallTracer, ExecutionEndTracer, PendingRefundTracer, PubdataSpentTracer, - StorageInvocationTracer, -}; -use crate::vm_m6::vm_instance::get_vm_hook_params; use crate::vm_m6::{ history_recorder::HistoryMode, - oracles::tracer::utils::{ - gas_spent_on_bytecodes_and_long_messages_this_opcode, print_debug_if_needed, read_pointer, - VmHook, + memory::SimpleMemory, + oracles::tracer::{ + utils::{ + gas_spent_on_bytecodes_and_long_messages_this_opcode, print_debug_if_needed, + read_pointer, VmHook, + }, + CallTracer, ExecutionEndTracer, PendingRefundTracer, PubdataSpentTracer, + StorageInvocationTracer, }, + vm_instance::get_vm_hook_params, }; #[derive(Debug)] diff --git a/core/lib/multivm/src/versions/vm_m6/oracles/tracer/utils.rs b/core/lib/multivm/src/versions/vm_m6/oracles/tracer/utils.rs index b256575726a..d29476ea4cc 100644 --- a/core/lib/multivm/src/versions/vm_m6/oracles/tracer/utils.rs +++ b/core/lib/multivm/src/versions/vm_m6/oracles/tracer/utils.rs @@ -1,14 +1,9 @@ -use crate::vm_m6::history_recorder::HistoryMode; -use crate::vm_m6::memory::SimpleMemory; -use crate::vm_m6::utils::{aux_heap_page_from_base, heap_page_from_base}; -use crate::vm_m6::vm_instance::{get_vm_hook_params, VM_HOOK_POSITION}; -use crate::vm_m6::vm_with_bootloader::BOOTLOADER_HEAP_PAGE; - -use zk_evm_1_3_1::aux_structures::MemoryPage; -use zk_evm_1_3_1::zkevm_opcode_defs::{FarCallABI, FarCallForwardPageType}; use zk_evm_1_3_1::{ abstractions::{BeforeExecutionData, VmLocalStateData}, - zkevm_opcode_defs::{FatPointer, LogOpcode, Opcode, UMAOpcode}, + aux_structures::MemoryPage, + zkevm_opcode_defs::{ + FarCallABI, FarCallForwardPageType, FatPointer, LogOpcode, Opcode, UMAOpcode, + }, }; use zksync_system_constants::{ ECRECOVER_PRECOMPILE_ADDRESS, KECCAK256_PRECOMPILE_ADDRESS, KNOWN_CODES_STORAGE_ADDRESS, @@ -17,6 +12,14 @@ use zksync_system_constants::{ use zksync_types::U256; use zksync_utils::u256_to_h256; +use crate::vm_m6::{ + history_recorder::HistoryMode, + memory::SimpleMemory, + utils::{aux_heap_page_from_base, heap_page_from_base}, + vm_instance::{get_vm_hook_params, VM_HOOK_POSITION}, + vm_with_bootloader::BOOTLOADER_HEAP_PAGE, +}; + #[derive(Clone, Debug, Copy)] pub(crate) enum VmHook { AccountValidationEntered, diff --git a/core/lib/multivm/src/versions/vm_m6/oracles/tracer/validation.rs b/core/lib/multivm/src/versions/vm_m6/oracles/tracer/validation.rs index 13a0badd442..e75a9f34a4b 100644 --- a/core/lib/multivm/src/versions/vm_m6/oracles/tracer/validation.rs +++ b/core/lib/multivm/src/versions/vm_m6/oracles/tracer/validation.rs @@ -1,16 +1,4 @@ -use std::fmt; -use std::fmt::Display; -use std::{collections::HashSet, marker::PhantomData}; - -use crate::vm_m6::{ - errors::VmRevertReasonParsingResult, - history_recorder::HistoryMode, - memory::SimpleMemory, - oracles::tracer::{ - utils::{computational_gas_price, print_debug_if_needed, VmHook}, - ExecutionEndTracer, PendingRefundTracer, PubdataSpentTracer, - }, -}; +use std::{collections::HashSet, fmt, fmt::Display, marker::PhantomData}; use zk_evm_1_3_1::{ abstractions::{ @@ -18,15 +6,11 @@ use zk_evm_1_3_1::{ }, zkevm_opcode_defs::{ContextOpcode, FarCallABI, LogOpcode, Opcode}, }; - -use crate::vm_m6::oracles::tracer::{utils::get_calldata_page_via_abi, StorageInvocationTracer}; -use crate::vm_m6::storage::{Storage, StoragePtr}; use zksync_system_constants::{ ACCOUNT_CODE_STORAGE_ADDRESS, BOOTLOADER_ADDRESS, CONTRACT_DEPLOYER_ADDRESS, KECCAK256_PRECOMPILE_ADDRESS, L2_ETH_TOKEN_ADDRESS, MSG_VALUE_SIMULATOR_ADDRESS, SYSTEM_CONTEXT_ADDRESS, }; - use zksync_types::{ get_code_key, web3::signing::keccak256, AccountTreeId, Address, StorageKey, H256, U256, }; @@ -34,6 +18,19 @@ use zksync_utils::{ be_bytes_to_safe_address, h256_to_account_address, u256_to_account_address, u256_to_h256, }; +use crate::vm_m6::{ + errors::VmRevertReasonParsingResult, + history_recorder::HistoryMode, + memory::SimpleMemory, + oracles::tracer::{ + utils::{ + computational_gas_price, get_calldata_page_via_abi, print_debug_if_needed, VmHook, + }, + ExecutionEndTracer, PendingRefundTracer, PubdataSpentTracer, StorageInvocationTracer, + }, + storage::{Storage, StoragePtr}, +}; + #[derive(Debug, Clone, Eq, PartialEq, Copy)] #[allow(clippy::enum_variant_names)] pub enum ValidationTracerMode { diff --git a/core/lib/multivm/src/versions/vm_m6/pubdata_utils.rs b/core/lib/multivm/src/versions/vm_m6/pubdata_utils.rs index a823e5f5ae6..33307507f7e 100644 --- a/core/lib/multivm/src/versions/vm_m6/pubdata_utils.rs +++ b/core/lib/multivm/src/versions/vm_m6/pubdata_utils.rs @@ -1,16 +1,21 @@ -use crate::glue::GlueInto; -use crate::vm_m6::history_recorder::HistoryMode; -use crate::vm_m6::oracles::storage::storage_key_of_log; -use crate::vm_m6::storage::Storage; -use crate::vm_m6::utils::collect_storage_log_queries_after_timestamp; -use crate::vm_m6::VmInstance; use std::collections::HashMap; + use zk_evm_1_3_1::aux_structures::Timestamp; -use zksync_types::event::{extract_long_l2_to_l1_messages, extract_published_bytecodes}; -use zksync_types::zkevm_test_harness::witness::sort_storage_access::sort_storage_access_queries; -use zksync_types::{StorageKey, PUBLISH_BYTECODE_OVERHEAD, SYSTEM_CONTEXT_ADDRESS}; +use zksync_types::{ + event::{extract_long_l2_to_l1_messages, extract_published_bytecodes}, + zkevm_test_harness::witness::sort_storage_access::sort_storage_access_queries, + StorageKey, PUBLISH_BYTECODE_OVERHEAD, SYSTEM_CONTEXT_ADDRESS, +}; use zksync_utils::bytecode::bytecode_len_in_bytes; +use crate::{ + glue::GlueInto, + vm_m6::{ + history_recorder::HistoryMode, oracles::storage::storage_key_of_log, storage::Storage, + utils::collect_storage_log_queries_after_timestamp, VmInstance, + }, +}; + impl VmInstance { pub fn pubdata_published(&self, from_timestamp: Timestamp) -> u32 { let storage_writes_pubdata_published = self.pubdata_published_for_writes(from_timestamp); diff --git a/core/lib/multivm/src/versions/vm_m6/refunds.rs b/core/lib/multivm/src/versions/vm_m6/refunds.rs index da16d621911..4b4229b306b 100644 --- a/core/lib/multivm/src/versions/vm_m6/refunds.rs +++ b/core/lib/multivm/src/versions/vm_m6/refunds.rs @@ -1,13 +1,14 @@ -use crate::vm_m6::history_recorder::HistoryMode; -use crate::vm_m6::storage::Storage; -use crate::vm_m6::vm_with_bootloader::{ - eth_price_per_pubdata_byte, BOOTLOADER_HEAP_PAGE, TX_GAS_LIMIT_OFFSET, -}; -use crate::vm_m6::VmInstance; use zk_evm_1_3_1::aux_structures::Timestamp; use zksync_types::U256; use zksync_utils::ceil_div_u256; +use crate::vm_m6::{ + history_recorder::HistoryMode, + storage::Storage, + vm_with_bootloader::{eth_price_per_pubdata_byte, BOOTLOADER_HEAP_PAGE, TX_GAS_LIMIT_OFFSET}, + VmInstance, +}; + impl VmInstance { pub(crate) fn tx_body_refund( &self, diff --git a/core/lib/multivm/src/versions/vm_m6/storage.rs b/core/lib/multivm/src/versions/vm_m6/storage.rs index 5441fc8a296..80f7e016010 100644 --- a/core/lib/multivm/src/versions/vm_m6/storage.rs +++ b/core/lib/multivm/src/versions/vm_m6/storage.rs @@ -1,7 +1,4 @@ -use std::cell::RefCell; -use std::collections::HashMap; -use std::fmt::Debug; -use std::rc::Rc; +use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc}; use zksync_state::{ReadStorage, WriteStorage}; use zksync_types::{get_known_code_key, StorageKey, StorageValue, H256}; diff --git a/core/lib/multivm/src/versions/vm_m6/test_utils.rs b/core/lib/multivm/src/versions/vm_m6/test_utils.rs index 6cce779362d..55e5add1164 100644 --- a/core/lib/multivm/src/versions/vm_m6/test_utils.rs +++ b/core/lib/multivm/src/versions/vm_m6/test_utils.rs @@ -10,8 +10,10 @@ use std::collections::HashMap; use itertools::Itertools; use zk_evm_1_3_1::{aux_structures::Timestamp, vm_state::VmLocalState}; -use zksync_contracts::test_contracts::LoadnextContractExecutionParams; -use zksync_contracts::{deployer_contract, get_loadnext_contract, load_contract}; +use zksync_contracts::{ + deployer_contract, get_loadnext_contract, load_contract, + test_contracts::LoadnextContractExecutionParams, +}; use zksync_types::{ ethabi::{Address, Token}, fee::Fee, @@ -24,14 +26,13 @@ use zksync_utils::{ address_to_h256, bytecode::hash_bytecode, h256_to_account_address, u256_to_h256, }; -use crate::vm_m6::storage::Storage; -/// The tests here help us with the testing the VM use crate::vm_m6::{ event_sink::InMemoryEventSink, history_recorder::{ AppDataFrameManagerWithHistory, HistoryEnabled, HistoryMode, HistoryRecorder, }, memory::SimpleMemory, + storage::Storage, VmInstance, }; diff --git a/core/lib/multivm/src/versions/vm_m6/transaction_data.rs b/core/lib/multivm/src/versions/vm_m6/transaction_data.rs index 6779ce95fc3..136a6d7647a 100644 --- a/core/lib/multivm/src/versions/vm_m6/transaction_data.rs +++ b/core/lib/multivm/src/versions/vm_m6/transaction_data.rs @@ -1,11 +1,14 @@ use zk_evm_1_3_1::zkevm_opcode_defs::system_params::MAX_TX_ERGS_LIMIT; -use zksync_types::ethabi::{encode, Address, Token}; -use zksync_types::fee::encoding_len; -use zksync_types::l1::is_l1_tx_type; -use zksync_types::{l2::TransactionType, ExecuteTransactionCommon, Transaction, U256}; -use zksync_types::{MAX_L2_TX_GAS_LIMIT, MAX_TXS_IN_BLOCK}; -use zksync_utils::{address_to_h256, ceil_div_u256}; -use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256}; +use zksync_types::{ + ethabi::{encode, Address, Token}, + fee::encoding_len, + l1::is_l1_tx_type, + l2::TransactionType, + ExecuteTransactionCommon, Transaction, MAX_L2_TX_GAS_LIMIT, MAX_TXS_IN_BLOCK, U256, +}; +use zksync_utils::{ + address_to_h256, bytecode::hash_bytecode, bytes_to_be_words, ceil_div_u256, h256_to_u256, +}; use crate::vm_m6::vm_with_bootloader::{ BLOCK_OVERHEAD_GAS, BLOCK_OVERHEAD_PUBDATA, BOOTLOADER_TX_ENCODING_SPACE, diff --git a/core/lib/multivm/src/versions/vm_m6/utils.rs b/core/lib/multivm/src/versions/vm_m6/utils.rs index a8ed8b02a52..070d51a6b25 100644 --- a/core/lib/multivm/src/versions/vm_m6/utils.rs +++ b/core/lib/multivm/src/versions/vm_m6/utils.rs @@ -1,15 +1,7 @@ -use crate::vm_m6::history_recorder::HistoryMode; -use crate::vm_m6::{ - memory::SimpleMemory, oracles::tracer::PubdataSpentTracer, vm_with_bootloader::BlockContext, - VmInstance, -}; use once_cell::sync::Lazy; - -use crate::glue::GlueInto; -use crate::vm_m6::storage::Storage; -use zk_evm_1_3_1::block_properties::BlockProperties; use zk_evm_1_3_1::{ aux_structures::{LogQuery, MemoryPage, Timestamp}, + block_properties::BlockProperties, vm_state::PrimitiveValue, zkevm_opcode_defs::FatPointer, }; @@ -18,6 +10,14 @@ use zksync_system_constants::ZKPORTER_IS_AVAILABLE; use zksync_types::{Address, StorageLogQuery, H160, MAX_L2_TX_GAS_LIMIT, U256}; use zksync_utils::h256_to_u256; +use crate::{ + glue::GlueInto, + vm_m6::{ + history_recorder::HistoryMode, memory::SimpleMemory, oracles::tracer::PubdataSpentTracer, + storage::Storage, vm_with_bootloader::BlockContext, VmInstance, + }, +}; + pub const INITIAL_TIMESTAMP: u32 = 1024; pub const INITIAL_MEMORY_COUNTER: u32 = 2048; pub const INITIAL_CALLDATA_PAGE: u32 = 7; diff --git a/core/lib/multivm/src/versions/vm_m6/vm.rs b/core/lib/multivm/src/versions/vm_m6/vm.rs index 2937b621a9a..e82d51d2bf3 100644 --- a/core/lib/multivm/src/versions/vm_m6/vm.rs +++ b/core/lib/multivm/src/versions/vm_m6/vm.rs @@ -1,23 +1,24 @@ -use crate::interface::{ - BootloaderMemory, BytecodeCompressionError, CurrentExecutionState, FinishedL1Batch, L1BatchEnv, - L2BlockEnv, SystemEnv, TxExecutionMode, VmExecutionMode, VmExecutionResultAndLogs, VmInterface, - VmInterfaceHistoryEnabled, VmMemoryMetrics, -}; - use std::collections::HashSet; use zksync_state::StoragePtr; -use zksync_types::l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}; -use zksync_types::{Transaction, VmVersion}; -use zksync_utils::bytecode::{hash_bytecode, CompressedBytecodeInfo}; -use zksync_utils::{h256_to_u256, u256_to_h256}; +use zksync_types::{ + l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}, + Transaction, VmVersion, +}; +use zksync_utils::{ + bytecode::{hash_bytecode, CompressedBytecodeInfo}, + h256_to_u256, u256_to_h256, +}; -use crate::glue::history_mode::HistoryMode; -use crate::glue::GlueInto; -use crate::vm_m6::events::merge_events; -use crate::vm_m6::storage::Storage; -use crate::vm_m6::vm_instance::MultiVMSubversion; -use crate::vm_m6::VmInstance; +use crate::{ + glue::{history_mode::HistoryMode, GlueInto}, + interface::{ + BootloaderMemory, BytecodeCompressionError, CurrentExecutionState, FinishedL1Batch, + L1BatchEnv, L2BlockEnv, SystemEnv, TxExecutionMode, VmExecutionMode, + VmExecutionResultAndLogs, VmInterface, VmInterfaceHistoryEnabled, VmMemoryMetrics, + }, + vm_m6::{events::merge_events, storage::Storage, vm_instance::MultiVMSubversion, VmInstance}, +}; #[derive(Debug)] pub struct Vm { diff --git a/core/lib/multivm/src/versions/vm_m6/vm_instance.rs b/core/lib/multivm/src/versions/vm_m6/vm_instance.rs index f15adde2584..379476d7664 100644 --- a/core/lib/multivm/src/versions/vm_m6/vm_instance.rs +++ b/core/lib/multivm/src/versions/vm_m6/vm_instance.rs @@ -1,45 +1,54 @@ -use std::convert::TryFrom; -use std::fmt::Debug; - -use crate::glue::GlueInto; -use zk_evm_1_3_1::aux_structures::Timestamp; -use zk_evm_1_3_1::vm_state::{PrimitiveValue, VmLocalState, VmState}; -use zk_evm_1_3_1::witness_trace::DummyTracer; -use zk_evm_1_3_1::zkevm_opcode_defs::decoding::{ - AllowedPcOrImm, EncodingModeProduction, VmEncodingMode, +use std::{convert::TryFrom, fmt::Debug}; + +use zk_evm_1_3_1::{ + aux_structures::Timestamp, + vm_state::{PrimitiveValue, VmLocalState, VmState}, + witness_trace::DummyTracer, + zkevm_opcode_defs::{ + decoding::{AllowedPcOrImm, EncodingModeProduction, VmEncodingMode}, + definitions::RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER, + }, }; -use zk_evm_1_3_1::zkevm_opcode_defs::definitions::RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER; use zksync_system_constants::MAX_TXS_IN_BLOCK; -use zksync_types::l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}; -use zksync_types::tx::tx_execution_info::TxExecutionStatus; -use zksync_types::vm_trace::{Call, VmExecutionTrace, VmTrace}; -use zksync_types::{L1BatchNumber, StorageLogQuery, VmEvent, H256, U256}; - -use crate::interface::types::outputs::VmExecutionLogs; -use crate::vm_m6::bootloader_state::BootloaderState; -use crate::vm_m6::errors::{TxRevertReason, VmRevertReason, VmRevertReasonParsingResult}; -use crate::vm_m6::event_sink::InMemoryEventSink; -use crate::vm_m6::events::merge_events; -use crate::vm_m6::history_recorder::{HistoryEnabled, HistoryMode}; -use crate::vm_m6::memory::SimpleMemory; -use crate::vm_m6::oracles::decommitter::DecommitterOracle; -use crate::vm_m6::oracles::precompile::PrecompilesProcessorWithHistory; -use crate::vm_m6::oracles::storage::StorageOracle; -use crate::vm_m6::oracles::tracer::{ - BootloaderTracer, ExecutionEndTracer, OneTxTracer, PendingRefundTracer, PubdataSpentTracer, - StorageInvocationTracer, TransactionResultTracer, ValidationError, ValidationTracer, - ValidationTracerParams, +use zksync_types::{ + l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}, + tx::tx_execution_info::TxExecutionStatus, + vm_trace::{Call, VmExecutionTrace, VmTrace}, + L1BatchNumber, StorageLogQuery, VmEvent, H256, U256, }; -use crate::vm_m6::oracles::OracleWithHistory; -use crate::vm_m6::storage::Storage; -use crate::vm_m6::utils::{ - calculate_computational_gas_used, collect_log_queries_after_timestamp, - collect_storage_log_queries_after_timestamp, dump_memory_page_using_primitive_value, - precompile_calls_count_after_timestamp, -}; -use crate::vm_m6::vm_with_bootloader::{ - BootloaderJobType, DerivedBlockContext, TxExecutionMode, BOOTLOADER_HEAP_PAGE, - OPERATOR_REFUNDS_OFFSET, + +use crate::{ + glue::GlueInto, + interface::types::outputs::VmExecutionLogs, + vm_m6::{ + bootloader_state::BootloaderState, + errors::{TxRevertReason, VmRevertReason, VmRevertReasonParsingResult}, + event_sink::InMemoryEventSink, + events::merge_events, + history_recorder::{HistoryEnabled, HistoryMode}, + memory::SimpleMemory, + oracles::{ + decommitter::DecommitterOracle, + precompile::PrecompilesProcessorWithHistory, + storage::StorageOracle, + tracer::{ + BootloaderTracer, ExecutionEndTracer, OneTxTracer, PendingRefundTracer, + PubdataSpentTracer, StorageInvocationTracer, TransactionResultTracer, + ValidationError, ValidationTracer, ValidationTracerParams, + }, + OracleWithHistory, + }, + storage::Storage, + utils::{ + calculate_computational_gas_used, collect_log_queries_after_timestamp, + collect_storage_log_queries_after_timestamp, dump_memory_page_using_primitive_value, + precompile_calls_count_after_timestamp, + }, + vm_with_bootloader::{ + BootloaderJobType, DerivedBlockContext, TxExecutionMode, BOOTLOADER_HEAP_PAGE, + OPERATOR_REFUNDS_OFFSET, + }, + }, }; pub type ZkSyncVmState = VmState< diff --git a/core/lib/multivm/src/versions/vm_m6/vm_with_bootloader.rs b/core/lib/multivm/src/versions/vm_m6/vm_with_bootloader.rs index 998f41275b4..c7d4ee3d45e 100644 --- a/core/lib/multivm/src/versions/vm_m6/vm_with_bootloader.rs +++ b/core/lib/multivm/src/versions/vm_m6/vm_with_bootloader.rs @@ -12,7 +12,6 @@ use zk_evm_1_3_1::{ }; use zksync_contracts::BaseSystemContracts; use zksync_system_constants::MAX_TXS_IN_BLOCK; - use zksync_types::{ zkevm_test_harness::INITIAL_MONOTONIC_CYCLE_COUNTER, Address, Transaction, BOOTLOADER_ADDRESS, L1_GAS_PER_PUBDATA_BYTE, MAX_GAS_PER_PUBDATA_BYTE, MAX_NEW_FACTORY_DEPS, U256, @@ -24,10 +23,10 @@ use zksync_utils::{ misc::ceil_div, }; -use crate::vm_m6::storage::Storage; use crate::vm_m6::{ bootloader_state::BootloaderState, history_recorder::HistoryMode, + storage::Storage, transaction_data::{TransactionData, L1_TX_TYPE}, utils::{ code_page_candidate_from_base, heap_page_from_base, BLOCK_GAS_LIMIT, INITIAL_BASE_PAGE, diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/l2_block.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/l2_block.rs index 56b5b1b6b39..6cd1096b3bd 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/l2_block.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/l2_block.rs @@ -1,11 +1,15 @@ use std::cmp::Ordering; + use zksync_types::{MiniblockNumber, H256}; use zksync_utils::concat_and_hash; -use crate::interface::{L2Block, L2BlockEnv}; -use crate::vm_refunds_enhancement::bootloader_state::snapshot::L2BlockSnapshot; -use crate::vm_refunds_enhancement::bootloader_state::tx::BootloaderTx; -use crate::vm_refunds_enhancement::utils::l2_blocks::l2_block_hash; +use crate::{ + interface::{L2Block, L2BlockEnv}, + vm_refunds_enhancement::{ + bootloader_state::{snapshot::L2BlockSnapshot, tx::BootloaderTx}, + utils::l2_blocks::l2_block_hash, + }, +}; const EMPTY_TXS_ROLLING_HASH: H256 = H256::zero(); diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/state.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/state.rs index 4c8d48bc1a7..d436a2adb0a 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/state.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/state.rs @@ -1,17 +1,22 @@ -use crate::vm_refunds_enhancement::bootloader_state::l2_block::BootloaderL2Block; -use crate::vm_refunds_enhancement::bootloader_state::snapshot::BootloaderStateSnapshot; -use crate::vm_refunds_enhancement::bootloader_state::utils::{apply_l2_block, apply_tx_to_memory}; use std::cmp::Ordering; + use zksync_types::{L2ChainId, U256}; use zksync_utils::bytecode::CompressedBytecodeInfo; -use crate::interface::{BootloaderMemory, L2BlockEnv, TxExecutionMode}; -use crate::vm_refunds_enhancement::{ - constants::TX_DESCRIPTION_OFFSET, types::internals::TransactionData, - utils::l2_blocks::assert_next_block, -}; - use super::tx::BootloaderTx; +use crate::{ + interface::{BootloaderMemory, L2BlockEnv, TxExecutionMode}, + vm_refunds_enhancement::{ + bootloader_state::{ + l2_block::BootloaderL2Block, + snapshot::BootloaderStateSnapshot, + utils::{apply_l2_block, apply_tx_to_memory}, + }, + constants::TX_DESCRIPTION_OFFSET, + types::internals::TransactionData, + utils::l2_blocks::assert_next_block, + }, +}; /// Intermediate bootloader-related VM state. /// /// Required to process transactions one by one (since we intercept the VM execution to execute diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/tx.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/tx.rs index 3bd10e9374b..e7f833e5bad 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/tx.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/tx.rs @@ -1,7 +1,8 @@ -use crate::vm_refunds_enhancement::types::internals::TransactionData; use zksync_types::{L2ChainId, H256, U256}; use zksync_utils::bytecode::CompressedBytecodeInfo; +use crate::vm_refunds_enhancement::types::internals::TransactionData; + /// Information about tx necessary for execution in bootloader. #[derive(Debug, Clone)] pub(super) struct BootloaderTx { diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/utils.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/utils.rs index fed5108d7f3..8adeb3e0b42 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/utils.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/bootloader_state/utils.rs @@ -1,16 +1,19 @@ use zksync_types::U256; -use zksync_utils::bytecode::CompressedBytecodeInfo; -use zksync_utils::{bytes_to_be_words, h256_to_u256}; - -use crate::interface::{BootloaderMemory, TxExecutionMode}; -use crate::vm_refunds_enhancement::bootloader_state::l2_block::BootloaderL2Block; -use crate::vm_refunds_enhancement::constants::{ - BOOTLOADER_TX_DESCRIPTION_OFFSET, BOOTLOADER_TX_DESCRIPTION_SIZE, COMPRESSED_BYTECODES_OFFSET, - OPERATOR_REFUNDS_OFFSET, TX_DESCRIPTION_OFFSET, TX_OPERATOR_L2_BLOCK_INFO_OFFSET, - TX_OPERATOR_SLOTS_PER_L2_BLOCK_INFO, TX_OVERHEAD_OFFSET, TX_TRUSTED_GAS_LIMIT_OFFSET, -}; +use zksync_utils::{bytecode::CompressedBytecodeInfo, bytes_to_be_words, h256_to_u256}; use super::tx::BootloaderTx; +use crate::{ + interface::{BootloaderMemory, TxExecutionMode}, + vm_refunds_enhancement::{ + bootloader_state::l2_block::BootloaderL2Block, + constants::{ + BOOTLOADER_TX_DESCRIPTION_OFFSET, BOOTLOADER_TX_DESCRIPTION_SIZE, + COMPRESSED_BYTECODES_OFFSET, OPERATOR_REFUNDS_OFFSET, TX_DESCRIPTION_OFFSET, + TX_OPERATOR_L2_BLOCK_INFO_OFFSET, TX_OPERATOR_SLOTS_PER_L2_BLOCK_INFO, + TX_OVERHEAD_OFFSET, TX_TRUSTED_GAS_LIMIT_OFFSET, + }, + }, +}; pub(super) fn get_memory_for_compressed_bytecodes( compressed_bytecodes: &[CompressedBytecodeInfo], diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/constants.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/constants.rs index 0dca7a6ce26..82ab754e403 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/constants.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/constants.rs @@ -1,14 +1,12 @@ use zk_evm_1_3_3::aux_structures::MemoryPage; - +pub use zk_evm_1_3_3::zkevm_opcode_defs::system_params::{ + ERGS_PER_CIRCUIT, INITIAL_STORAGE_WRITE_PUBDATA_BYTES, MAX_PUBDATA_PER_BLOCK, +}; use zksync_system_constants::{ L1_GAS_PER_PUBDATA_BYTE, MAX_L2_TX_GAS_LIMIT, MAX_NEW_FACTORY_DEPS, MAX_TXS_IN_BLOCK, USED_BOOTLOADER_MEMORY_WORDS, }; -pub use zk_evm_1_3_3::zkevm_opcode_defs::system_params::{ - ERGS_PER_CIRCUIT, INITIAL_STORAGE_WRITE_PUBDATA_BYTES, MAX_PUBDATA_PER_BLOCK, -}; - use crate::vm_refunds_enhancement::old_vm::utils::heap_page_from_base; /// Max cycles for a single transaction. diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/bytecode.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/bytecode.rs index 4b7e529fc5b..69670f9682b 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/bytecode.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/bytecode.rs @@ -1,13 +1,12 @@ use itertools::Itertools; - -use crate::interface::VmInterface; -use crate::HistoryMode; use zksync_state::{StoragePtr, WriteStorage}; use zksync_types::U256; -use zksync_utils::bytecode::{compress_bytecode, hash_bytecode, CompressedBytecodeInfo}; -use zksync_utils::bytes_to_be_words; +use zksync_utils::{ + bytecode::{compress_bytecode, hash_bytecode, CompressedBytecodeInfo}, + bytes_to_be_words, +}; -use crate::vm_refunds_enhancement::Vm; +use crate::{interface::VmInterface, vm_refunds_enhancement::Vm, HistoryMode}; impl Vm { /// Checks the last transaction has successfully published compressed bytecodes and returns `true` if there is at least one is still unknown. diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/execution.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/execution.rs index 9e55180d66f..a1d81bdce5e 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/execution.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/execution.rs @@ -1,15 +1,20 @@ -use crate::HistoryMode; use zk_evm_1_3_3::aux_structures::Timestamp; use zksync_state::WriteStorage; -use crate::interface::tracer::{TracerExecutionStatus, VmExecutionStopReason}; -use crate::interface::{VmExecutionMode, VmExecutionResultAndLogs}; -use crate::vm_refunds_enhancement::old_vm::utils::{vm_may_have_ended_inner, VmExecutionResult}; -use crate::vm_refunds_enhancement::tracers::dispatcher::TracerDispatcher; -use crate::vm_refunds_enhancement::tracers::{ - traits::VmTracer, DefaultExecutionTracer, RefundsTracer, +use crate::{ + interface::{ + tracer::{TracerExecutionStatus, VmExecutionStopReason}, + VmExecutionMode, VmExecutionResultAndLogs, + }, + vm_refunds_enhancement::{ + old_vm::utils::{vm_may_have_ended_inner, VmExecutionResult}, + tracers::{ + dispatcher::TracerDispatcher, traits::VmTracer, DefaultExecutionTracer, RefundsTracer, + }, + vm::Vm, + }, + HistoryMode, }; -use crate::vm_refunds_enhancement::vm::Vm; impl Vm { pub(crate) fn inspect_inner( diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/gas.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/gas.rs index cce9bfad699..4083e27b0b3 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/gas.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/gas.rs @@ -1,8 +1,9 @@ -use crate::HistoryMode; use zksync_state::WriteStorage; -use crate::vm_refunds_enhancement::tracers::DefaultExecutionTracer; -use crate::vm_refunds_enhancement::vm::Vm; +use crate::{ + vm_refunds_enhancement::{tracers::DefaultExecutionTracer, vm::Vm}, + HistoryMode, +}; impl Vm { /// Returns the amount of gas remaining to the VM. diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/logs.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/logs.rs index b8e8652f301..bded1c19041 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/logs.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/logs.rs @@ -1,14 +1,18 @@ use zk_evm_1_3_3::aux_structures::Timestamp; use zksync_state::WriteStorage; +use zksync_types::{ + l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}, + VmEvent, +}; -use crate::HistoryMode; -use zksync_types::l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}; -use zksync_types::VmEvent; - -use crate::interface::types::outputs::VmExecutionLogs; -use crate::vm_refunds_enhancement::old_vm::events::merge_events; -use crate::vm_refunds_enhancement::old_vm::utils::precompile_calls_count_after_timestamp; -use crate::vm_refunds_enhancement::vm::Vm; +use crate::{ + interface::types::outputs::VmExecutionLogs, + vm_refunds_enhancement::{ + old_vm::{events::merge_events, utils::precompile_calls_count_after_timestamp}, + vm::Vm, + }, + HistoryMode, +}; impl Vm { pub(crate) fn collect_execution_logs_after_timestamp( diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/snapshots.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/snapshots.rs index 972d50e5d76..c34535726c0 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/snapshots.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/snapshots.rs @@ -1,13 +1,14 @@ -use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; - use std::time::Duration; -use crate::vm_latest::HistoryEnabled; +use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; use zk_evm_1_3_3::aux_structures::Timestamp; use zksync_state::WriteStorage; -use crate::vm_refunds_enhancement::{ - old_vm::oracles::OracleWithHistory, types::internals::VmSnapshot, vm::Vm, +use crate::{ + vm_latest::HistoryEnabled, + vm_refunds_enhancement::{ + old_vm::oracles::OracleWithHistory, types::internals::VmSnapshot, vm::Vm, + }, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet, EncodeLabelValue)] diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/statistics.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/statistics.rs index a49ce2a6746..3e9de5de4ec 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/statistics.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/statistics.rs @@ -1,12 +1,12 @@ use zk_evm_1_3_3::aux_structures::Timestamp; use zksync_state::WriteStorage; - -use crate::HistoryMode; use zksync_types::U256; -use crate::interface::{VmExecutionStatistics, VmMemoryMetrics}; -use crate::vm_refunds_enhancement::tracers::DefaultExecutionTracer; -use crate::vm_refunds_enhancement::vm::Vm; +use crate::{ + interface::{VmExecutionStatistics, VmMemoryMetrics}, + vm_refunds_enhancement::{tracers::DefaultExecutionTracer, vm::Vm}, + HistoryMode, +}; /// Module responsible for observing the VM behavior, i.e. calculating the statistics of the VM runs /// or reporting the VM memory usage. diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/tx.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/tx.rs index d6fd4858870..a786e9b0ad7 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/tx.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/implementation/tx.rs @@ -1,15 +1,16 @@ -use crate::vm_refunds_enhancement::constants::BOOTLOADER_HEAP_PAGE; -use crate::vm_refunds_enhancement::implementation::bytecode::{ - bytecode_to_factory_dep, compress_bytecodes, -}; use zk_evm_1_3_3::aux_structures::Timestamp; use zksync_state::WriteStorage; -use zksync_types::l1::is_l1_tx_type; -use zksync_types::Transaction; +use zksync_types::{l1::is_l1_tx_type, Transaction}; -use crate::vm_refunds_enhancement::types::internals::TransactionData; -use crate::vm_refunds_enhancement::vm::Vm; -use crate::HistoryMode; +use crate::{ + vm_refunds_enhancement::{ + constants::BOOTLOADER_HEAP_PAGE, + implementation::bytecode::{bytecode_to_factory_dep, compress_bytecodes}, + types::internals::TransactionData, + vm::Vm, + }, + HistoryMode, +}; impl Vm { pub(crate) fn push_raw_transaction( diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/mod.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/mod.rs index 28a681e5e60..691d453c4b0 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/mod.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/mod.rs @@ -1,30 +1,25 @@ -pub use old_vm::{ - history_recorder::{HistoryDisabled, HistoryEnabled, HistoryMode}, - memory::SimpleMemory, +pub use self::{ + bootloader_state::BootloaderState, + old_vm::{ + history_recorder::{HistoryDisabled, HistoryEnabled, HistoryMode}, + memory::SimpleMemory, + }, + oracles::storage::StorageOracle, + tracers::{ + dispatcher::TracerDispatcher, + traits::{ToTracerPointer, TracerPointer, VmTracer}, + }, + types::internals::ZkSyncVmState, + utils::transaction_encoding::TransactionVmExt, + vm::Vm, }; -pub use oracles::storage::StorageOracle; - -pub use tracers::dispatcher::TracerDispatcher; -pub use tracers::traits::{ToTracerPointer, TracerPointer, VmTracer}; - -pub use utils::transaction_encoding::TransactionVmExt; - -pub use bootloader_state::BootloaderState; -pub use types::internals::ZkSyncVmState; - -pub use vm::Vm; - mod bootloader_state; +pub mod constants; mod implementation; mod old_vm; mod oracles; pub(crate) mod tracers; mod types; -mod vm; - -pub mod constants; pub mod utils; - -// #[cfg(test)] -// mod tests; +mod vm; diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/event_sink.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/event_sink.rs index adbee280a3d..43019cce1ce 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/event_sink.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/event_sink.rs @@ -1,8 +1,5 @@ -use crate::vm_refunds_enhancement::old_vm::{ - history_recorder::{AppDataFrameManagerWithHistory, HistoryEnabled, HistoryMode}, - oracles::OracleWithHistory, -}; use std::collections::HashMap; + use zk_evm_1_3_3::{ abstractions::EventSink, aux_structures::{LogQuery, Timestamp}, @@ -12,6 +9,11 @@ use zk_evm_1_3_3::{ }, }; +use crate::vm_refunds_enhancement::old_vm::{ + history_recorder::{AppDataFrameManagerWithHistory, HistoryEnabled, HistoryMode}, + oracles::OracleWithHistory, +}; + #[derive(Debug, Clone, PartialEq, Default)] pub struct InMemoryEventSink { frames_stack: AppDataFrameManagerWithHistory, H>, diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/history_recorder.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/history_recorder.rs index 44d510b0075..fdab00a199e 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/history_recorder.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/history_recorder.rs @@ -5,7 +5,6 @@ use zk_evm_1_3_3::{ vm_state::PrimitiveValue, zkevm_opcode_defs::{self}, }; - use zksync_state::{StoragePtr, WriteStorage}; use zksync_types::{StorageKey, U256}; use zksync_utils::{h256_to_u256, u256_to_h256}; @@ -771,11 +770,14 @@ impl HistoryRecorder, H> { #[cfg(test)] mod tests { - use crate::vm_refunds_enhancement::old_vm::history_recorder::{HistoryRecorder, MemoryWrapper}; - use crate::vm_refunds_enhancement::HistoryDisabled; use zk_evm_1_3_3::{aux_structures::Timestamp, vm_state::PrimitiveValue}; use zksync_types::U256; + use crate::vm_refunds_enhancement::{ + old_vm::history_recorder::{HistoryRecorder, MemoryWrapper}, + HistoryDisabled, + }; + #[test] fn memory_equality() { let mut a: HistoryRecorder = Default::default(); diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/memory.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/memory.rs index 1ef04da58cb..8568d6c7215 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/memory.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/memory.rs @@ -1,16 +1,18 @@ -use zk_evm_1_3_3::abstractions::{Memory, MemoryType}; -use zk_evm_1_3_3::aux_structures::{MemoryPage, MemoryQuery, Timestamp}; -use zk_evm_1_3_3::vm_state::PrimitiveValue; -use zk_evm_1_3_3::zkevm_opcode_defs::FatPointer; +use zk_evm_1_3_3::{ + abstractions::{Memory, MemoryType}, + aux_structures::{MemoryPage, MemoryQuery, Timestamp}, + vm_state::PrimitiveValue, + zkevm_opcode_defs::FatPointer, +}; use zksync_types::U256; -use crate::vm_refunds_enhancement::old_vm::history_recorder::{ - FramedStack, HistoryEnabled, HistoryMode, IntFrameManagerWithHistory, MemoryWithHistory, - MemoryWrapper, WithHistory, -}; -use crate::vm_refunds_enhancement::old_vm::oracles::OracleWithHistory; -use crate::vm_refunds_enhancement::old_vm::utils::{ - aux_heap_page_from_base, heap_page_from_base, stack_page_from_base, +use crate::vm_refunds_enhancement::old_vm::{ + history_recorder::{ + FramedStack, HistoryEnabled, HistoryMode, IntFrameManagerWithHistory, MemoryWithHistory, + MemoryWrapper, WithHistory, + }, + oracles::OracleWithHistory, + utils::{aux_heap_page_from_base, heap_page_from_base, stack_page_from_base}, }; #[derive(Debug, Clone, PartialEq)] diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/oracles/decommitter.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/oracles/decommitter.rs index a39be0ba93b..6705831dbad 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/oracles/decommitter.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/oracles/decommitter.rs @@ -1,23 +1,19 @@ -use std::collections::HashMap; -use std::fmt::Debug; +use std::{collections::HashMap, fmt::Debug}; -use crate::vm_refunds_enhancement::old_vm::history_recorder::{ - HistoryEnabled, HistoryMode, HistoryRecorder, WithHistory, -}; - -use zk_evm_1_3_3::abstractions::MemoryType; -use zk_evm_1_3_3::aux_structures::Timestamp; use zk_evm_1_3_3::{ - abstractions::{DecommittmentProcessor, Memory}, - aux_structures::{DecommittmentQuery, MemoryIndex, MemoryLocation, MemoryPage, MemoryQuery}, + abstractions::{DecommittmentProcessor, Memory, MemoryType}, + aux_structures::{ + DecommittmentQuery, MemoryIndex, MemoryLocation, MemoryPage, MemoryQuery, Timestamp, + }, }; - use zksync_state::{ReadStorage, StoragePtr}; use zksync_types::U256; -use zksync_utils::bytecode::bytecode_len_in_words; -use zksync_utils::{bytes_to_be_words, u256_to_h256}; +use zksync_utils::{bytecode::bytecode_len_in_words, bytes_to_be_words, u256_to_h256}; use super::OracleWithHistory; +use crate::vm_refunds_enhancement::old_vm::history_recorder::{ + HistoryEnabled, HistoryMode, HistoryRecorder, WithHistory, +}; /// The main job of the DecommiterOracle is to implement the DecommittmentProcessor trait - that is /// used by the VM to 'load' bytecodes into memory. diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/oracles/precompile.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/oracles/precompile.rs index eb3f7b866b1..c59fb188e59 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/oracles/precompile.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/oracles/precompile.rs @@ -1,17 +1,14 @@ use zk_evm_1_3_3::{ - abstractions::Memory, - abstractions::PrecompileCyclesWitness, - abstractions::PrecompilesProcessor, + abstractions::{Memory, PrecompileCyclesWitness, PrecompilesProcessor}, aux_structures::{LogQuery, MemoryQuery, Timestamp}, precompiles::DefaultPrecompilesProcessor, }; +use super::OracleWithHistory; use crate::vm_refunds_enhancement::old_vm::history_recorder::{ HistoryEnabled, HistoryMode, HistoryRecorder, }; -use super::OracleWithHistory; - /// Wrap of DefaultPrecompilesProcessor that store queue /// of timestamp when precompiles are called to be executed. /// Number of precompiles per block is strictly limited, diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/utils.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/utils.rs index 9b4aae851d2..bc4b2c3eff1 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/utils.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/old_vm/utils.rs @@ -1,22 +1,19 @@ -use crate::vm_refunds_enhancement::old_vm::memory::SimpleMemory; - -use crate::vm_refunds_enhancement::types::internals::ZkSyncVmState; -use crate::vm_refunds_enhancement::HistoryMode; - -use zk_evm_1_3_3::zkevm_opcode_defs::decoding::{ - AllowedPcOrImm, EncodingModeProduction, VmEncodingMode, -}; -use zk_evm_1_3_3::zkevm_opcode_defs::RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER; use zk_evm_1_3_3::{ aux_structures::{MemoryPage, Timestamp}, vm_state::PrimitiveValue, - zkevm_opcode_defs::FatPointer, + zkevm_opcode_defs::{ + decoding::{AllowedPcOrImm, EncodingModeProduction, VmEncodingMode}, + FatPointer, RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER, + }, }; use zksync_state::WriteStorage; use zksync_system_constants::L1_GAS_PER_PUBDATA_BYTE; - use zksync_types::{Address, U256}; +use crate::vm_refunds_enhancement::{ + old_vm::memory::SimpleMemory, types::internals::ZkSyncVmState, HistoryMode, +}; + #[derive(Debug, Clone)] pub(crate) enum VmExecutionResult { Ok(Vec), diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/oracles/storage.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/oracles/storage.rs index e054cdbe2a6..b970a8a95f7 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/oracles/storage.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/oracles/storage.rs @@ -1,26 +1,25 @@ use std::collections::HashMap; -use crate::vm_refunds_enhancement::old_vm::history_recorder::{ - AppDataFrameManagerWithHistory, HashMapHistoryEvent, HistoryEnabled, HistoryMode, - HistoryRecorder, StorageWrapper, VectorHistoryEvent, WithHistory, -}; -use crate::vm_refunds_enhancement::old_vm::oracles::OracleWithHistory; - -use zk_evm_1_3_3::abstractions::RefundedAmounts; -use zk_evm_1_3_3::zkevm_opcode_defs::system_params::INITIAL_STORAGE_WRITE_PUBDATA_BYTES; use zk_evm_1_3_3::{ - abstractions::{RefundType, Storage as VmStorageOracle}, + abstractions::{RefundType, RefundedAmounts, Storage as VmStorageOracle}, aux_structures::{LogQuery, Timestamp}, + zkevm_opcode_defs::system_params::INITIAL_STORAGE_WRITE_PUBDATA_BYTES, }; - use zksync_state::{StoragePtr, WriteStorage}; -use zksync_types::utils::storage_key_for_eth_balance; use zksync_types::{ - AccountTreeId, Address, StorageKey, StorageLogQuery, StorageLogQueryType, BOOTLOADER_ADDRESS, - U256, + utils::storage_key_for_eth_balance, AccountTreeId, Address, StorageKey, StorageLogQuery, + StorageLogQueryType, BOOTLOADER_ADDRESS, U256, }; use zksync_utils::u256_to_h256; +use crate::vm_refunds_enhancement::old_vm::{ + history_recorder::{ + AppDataFrameManagerWithHistory, HashMapHistoryEvent, HistoryEnabled, HistoryMode, + HistoryRecorder, StorageWrapper, VectorHistoryEvent, WithHistory, + }, + oracles::OracleWithHistory, +}; + // While the storage does not support different shards, it was decided to write the // code of the StorageOracle with the shard parameters in mind. pub(crate) fn triplet_to_storage_key(_shard_id: u8, address: Address, key: U256) -> StorageKey { diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/default_tracers.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/default_tracers.rs index 51fbf06d855..8e9c0f11aba 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/default_tracers.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/default_tracers.rs @@ -1,11 +1,5 @@ use std::fmt::{Debug, Formatter}; -use crate::interface::dyn_tracers::vm_1_3_3::DynTracer; -use crate::interface::tracer::{ - TracerExecutionStatus, TracerExecutionStopReason, VmExecutionStopReason, -}; -use crate::interface::{Halt, VmExecutionMode}; -use crate::vm_refunds_enhancement::VmTracer; use zk_evm_1_3_3::{ tracing::{ AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, @@ -17,18 +11,28 @@ use zk_evm_1_3_3::{ use zksync_state::{StoragePtr, WriteStorage}; use zksync_types::Timestamp; -use crate::vm_refunds_enhancement::bootloader_state::utils::apply_l2_block; -use crate::vm_refunds_enhancement::bootloader_state::BootloaderState; -use crate::vm_refunds_enhancement::constants::BOOTLOADER_HEAP_PAGE; -use crate::vm_refunds_enhancement::old_vm::history_recorder::HistoryMode; -use crate::vm_refunds_enhancement::old_vm::memory::SimpleMemory; -use crate::vm_refunds_enhancement::tracers::dispatcher::TracerDispatcher; -use crate::vm_refunds_enhancement::tracers::utils::{ - computational_gas_price, gas_spent_on_bytecodes_and_long_messages_this_opcode, - print_debug_if_needed, VmHook, +use crate::{ + interface::{ + dyn_tracers::vm_1_3_3::DynTracer, + tracer::{TracerExecutionStatus, TracerExecutionStopReason, VmExecutionStopReason}, + Halt, VmExecutionMode, + }, + vm_refunds_enhancement::{ + bootloader_state::{utils::apply_l2_block, BootloaderState}, + constants::BOOTLOADER_HEAP_PAGE, + old_vm::{history_recorder::HistoryMode, memory::SimpleMemory}, + tracers::{ + dispatcher::TracerDispatcher, + utils::{ + computational_gas_price, gas_spent_on_bytecodes_and_long_messages_this_opcode, + print_debug_if_needed, VmHook, + }, + RefundsTracer, ResultTracer, + }, + types::internals::ZkSyncVmState, + VmTracer, + }, }; -use crate::vm_refunds_enhancement::tracers::{RefundsTracer, ResultTracer}; -use crate::vm_refunds_enhancement::types::internals::ZkSyncVmState; /// Default tracer for the VM. It manages the other tracers execution and stop the vm when needed. pub(crate) struct DefaultExecutionTracer { diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/dispatcher.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/dispatcher.rs index f2296d205a9..2392c3e51af 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/dispatcher.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/dispatcher.rs @@ -1,13 +1,18 @@ -use crate::interface::dyn_tracers::vm_1_3_3::DynTracer; -use crate::interface::tracer::{TracerExecutionStatus, VmExecutionStopReason}; -use crate::vm_refunds_enhancement::{ - BootloaderState, HistoryMode, SimpleMemory, TracerPointer, VmTracer, ZkSyncVmState, -}; use zk_evm_1_3_3::tracing::{ AfterDecodingData, AfterExecutionData, BeforeExecutionData, VmLocalStateData, }; use zksync_state::{StoragePtr, WriteStorage}; +use crate::{ + interface::{ + dyn_tracers::vm_1_3_3::DynTracer, + tracer::{TracerExecutionStatus, VmExecutionStopReason}, + }, + vm_refunds_enhancement::{ + BootloaderState, HistoryMode, SimpleMemory, TracerPointer, VmTracer, ZkSyncVmState, + }, +}; + /// Tracer dispatcher is a tracer that can dispatch calls to multiple tracers. pub struct TracerDispatcher { tracers: Vec>, diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/refunds.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/refunds.rs index 5256561b5eb..f906cef6230 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/refunds.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/refunds.rs @@ -1,5 +1,4 @@ use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; - use zk_evm_1_3_3::{ aux_structures::Timestamp, tracing::{BeforeExecutionData, VmLocalStateData}, @@ -12,27 +11,27 @@ use zksync_types::{ l2_to_l1_log::L2ToL1Log, L1BatchNumber, U256, }; -use zksync_utils::bytecode::bytecode_len_in_bytes; -use zksync_utils::{ceil_div_u256, u256_to_h256}; - -use crate::interface::{ - dyn_tracers::vm_1_3_3::DynTracer, tracer::TracerExecutionStatus, L1BatchEnv, Refunds, -}; -use crate::vm_refunds_enhancement::constants::{ - BOOTLOADER_HEAP_PAGE, OPERATOR_REFUNDS_OFFSET, TX_GAS_LIMIT_OFFSET, -}; +use zksync_utils::{bytecode::bytecode_len_in_bytes, ceil_div_u256, u256_to_h256}; -use crate::vm_refunds_enhancement::{ - bootloader_state::BootloaderState, - old_vm::{ - events::merge_events, history_recorder::HistoryMode, memory::SimpleMemory, - utils::eth_price_per_pubdata_byte, +use crate::{ + interface::{ + dyn_tracers::vm_1_3_3::DynTracer, tracer::TracerExecutionStatus, L1BatchEnv, Refunds, }, - tracers::{ - traits::VmTracer, - utils::{gas_spent_on_bytecodes_and_long_messages_this_opcode, get_vm_hook_params, VmHook}, + vm_refunds_enhancement::{ + bootloader_state::BootloaderState, + constants::{BOOTLOADER_HEAP_PAGE, OPERATOR_REFUNDS_OFFSET, TX_GAS_LIMIT_OFFSET}, + old_vm::{ + events::merge_events, history_recorder::HistoryMode, memory::SimpleMemory, + utils::eth_price_per_pubdata_byte, + }, + tracers::{ + traits::VmTracer, + utils::{ + gas_spent_on_bytecodes_and_long_messages_this_opcode, get_vm_hook_params, VmHook, + }, + }, + types::internals::ZkSyncVmState, }, - types::internals::ZkSyncVmState, }; /// Tracer responsible for collecting information about refunds. diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/result_tracer.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/result_tracer.rs index c0a8e5d6cc0..1281b416bb4 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/result_tracer.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/result_tracer.rs @@ -4,23 +4,27 @@ use zk_evm_1_3_3::{ zkevm_opcode_defs::FatPointer, }; use zksync_state::{StoragePtr, WriteStorage}; - -use crate::interface::dyn_tracers::vm_1_3_3::DynTracer; -use crate::interface::tracer::{TracerExecutionStopReason, VmExecutionStopReason}; -use crate::interface::{ExecutionResult, Halt, TxRevertReason, VmExecutionMode, VmRevertReason}; use zksync_types::U256; -use crate::vm_refunds_enhancement::bootloader_state::BootloaderState; -use crate::vm_refunds_enhancement::old_vm::{ - history_recorder::HistoryMode, - memory::SimpleMemory, - utils::{vm_may_have_ended_inner, VmExecutionResult}, +use crate::{ + interface::{ + dyn_tracers::vm_1_3_3::DynTracer, + tracer::{TracerExecutionStopReason, VmExecutionStopReason}, + ExecutionResult, Halt, TxRevertReason, VmExecutionMode, VmRevertReason, + }, + vm_refunds_enhancement::{ + bootloader_state::BootloaderState, + constants::{BOOTLOADER_HEAP_PAGE, RESULT_SUCCESS_FIRST_SLOT}, + old_vm::{ + history_recorder::HistoryMode, + memory::SimpleMemory, + utils::{vm_may_have_ended_inner, VmExecutionResult}, + }, + tracers::utils::{get_vm_hook_params, read_pointer, VmHook}, + types::internals::ZkSyncVmState, + VmTracer, + }, }; -use crate::vm_refunds_enhancement::tracers::utils::{get_vm_hook_params, read_pointer, VmHook}; - -use crate::vm_refunds_enhancement::constants::{BOOTLOADER_HEAP_PAGE, RESULT_SUCCESS_FIRST_SLOT}; -use crate::vm_refunds_enhancement::types::internals::ZkSyncVmState; -use crate::vm_refunds_enhancement::VmTracer; #[derive(Debug, Clone)] enum Result { diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/traits.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/traits.rs index 13b295b9fe9..b54819148fa 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/traits.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/traits.rs @@ -1,11 +1,16 @@ -use crate::interface::dyn_tracers::vm_1_3_3::DynTracer; -use crate::interface::tracer::{TracerExecutionStatus, VmExecutionStopReason}; use zksync_state::WriteStorage; -use crate::vm_refunds_enhancement::bootloader_state::BootloaderState; -use crate::vm_refunds_enhancement::old_vm::history_recorder::HistoryMode; -use crate::vm_refunds_enhancement::old_vm::memory::SimpleMemory; -use crate::vm_refunds_enhancement::types::internals::ZkSyncVmState; +use crate::{ + interface::{ + dyn_tracers::vm_1_3_3::DynTracer, + tracer::{TracerExecutionStatus, VmExecutionStopReason}, + }, + vm_refunds_enhancement::{ + bootloader_state::BootloaderState, + old_vm::{history_recorder::HistoryMode, memory::SimpleMemory}, + types::internals::ZkSyncVmState, + }, +}; pub type TracerPointer = Box>; diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/utils.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/utils.rs index 3026afea007..8de2ad181f4 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/utils.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/tracers/utils.rs @@ -5,7 +5,6 @@ use zk_evm_1_3_3::{ FarCallABI, FarCallForwardPageType, FatPointer, LogOpcode, Opcode, UMAOpcode, }, }; - use zksync_system_constants::{ ECRECOVER_PRECOMPILE_ADDRESS, KECCAK256_PRECOMPILE_ADDRESS, KNOWN_CODES_STORAGE_ADDRESS, L1_MESSENGER_ADDRESS, SHA256_PRECOMPILE_ADDRESS, @@ -13,13 +12,15 @@ use zksync_system_constants::{ use zksync_types::U256; use zksync_utils::u256_to_h256; -use crate::vm_refunds_enhancement::constants::{ - BOOTLOADER_HEAP_PAGE, VM_HOOK_PARAMS_COUNT, VM_HOOK_PARAMS_START_POSITION, VM_HOOK_POSITION, -}; -use crate::vm_refunds_enhancement::old_vm::{ - history_recorder::HistoryMode, - memory::SimpleMemory, - utils::{aux_heap_page_from_base, heap_page_from_base}, +use crate::vm_refunds_enhancement::{ + constants::{ + BOOTLOADER_HEAP_PAGE, VM_HOOK_PARAMS_COUNT, VM_HOOK_PARAMS_START_POSITION, VM_HOOK_POSITION, + }, + old_vm::{ + history_recorder::HistoryMode, + memory::SimpleMemory, + utils::{aux_heap_page_from_base, heap_page_from_base}, + }, }; #[derive(Clone, Debug, Copy)] diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/types/internals/transaction_data.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/types/internals/transaction_data.rs index 1ad2ce0f977..4b70a79fdd4 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/types/internals/transaction_data.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/types/internals/transaction_data.rs @@ -1,15 +1,15 @@ use std::convert::TryInto; -use zksync_types::ethabi::{encode, Address, Token}; -use zksync_types::fee::{encoding_len, Fee}; -use zksync_types::l1::is_l1_tx_type; -use zksync_types::l2::L2Tx; -use zksync_types::transaction_request::{PaymasterParams, TransactionRequest}; + use zksync_types::{ - l2::TransactionType, Bytes, Execute, ExecuteTransactionCommon, L2ChainId, L2TxCommonData, - Nonce, Transaction, H256, U256, + ethabi::{encode, Address, Token}, + fee::{encoding_len, Fee}, + l1::is_l1_tx_type, + l2::{L2Tx, TransactionType}, + transaction_request::{PaymasterParams, TransactionRequest}, + Bytes, Execute, ExecuteTransactionCommon, L2ChainId, L2TxCommonData, Nonce, Transaction, H256, + U256, }; -use zksync_utils::address_to_h256; -use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256}; +use zksync_utils::{address_to_h256, bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256}; use crate::vm_refunds_enhancement::utils::overhead::{ get_amortized_overhead, OverheadCoefficients, @@ -305,9 +305,10 @@ impl TryInto for TransactionData { #[cfg(test)] mod tests { - use super::*; use zksync_types::fee::encoding_len; + use super::*; + #[test] fn test_consistency_with_encoding_length() { let transaction = TransactionData { diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/types/internals/vm_state.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/types/internals/vm_state.rs index b656cd09f9b..adeef89466f 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/types/internals/vm_state.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/types/internals/vm_state.rs @@ -1,34 +1,40 @@ use zk_evm_1_3_3::{ - aux_structures::MemoryPage, - aux_structures::Timestamp, + aux_structures::{MemoryPage, Timestamp}, block_properties::BlockProperties, vm_state::{CallStackEntry, PrimitiveValue, VmState}, witness_trace::DummyTracer, zkevm_opcode_defs::{ system_params::{BOOTLOADER_MAX_MEMORY, INITIAL_FRAME_FORMAL_EH_LOCATION}, - FatPointer, BOOTLOADER_CALLDATA_PAGE, + FatPointer, BOOTLOADER_BASE_PAGE, BOOTLOADER_CALLDATA_PAGE, BOOTLOADER_CODE_PAGE, + STARTING_BASE_PAGE, STARTING_TIMESTAMP, }, }; - -use crate::interface::{L1BatchEnv, L2Block, SystemEnv}; -use zk_evm_1_3_3::zkevm_opcode_defs::{ - BOOTLOADER_BASE_PAGE, BOOTLOADER_CODE_PAGE, STARTING_BASE_PAGE, STARTING_TIMESTAMP, -}; use zksync_state::{StoragePtr, WriteStorage}; use zksync_system_constants::BOOTLOADER_ADDRESS; -use zksync_types::block::legacy_miniblock_hash; -use zksync_types::{zkevm_test_harness::INITIAL_MONOTONIC_CYCLE_COUNTER, Address, MiniblockNumber}; +use zksync_types::{ + block::legacy_miniblock_hash, zkevm_test_harness::INITIAL_MONOTONIC_CYCLE_COUNTER, Address, + MiniblockNumber, +}; use zksync_utils::h256_to_u256; -use crate::vm_refunds_enhancement::bootloader_state::BootloaderState; -use crate::vm_refunds_enhancement::constants::BOOTLOADER_HEAP_PAGE; -use crate::vm_refunds_enhancement::old_vm::{ - event_sink::InMemoryEventSink, history_recorder::HistoryMode, memory::SimpleMemory, - oracles::decommitter::DecommitterOracle, oracles::precompile::PrecompilesProcessorWithHistory, +use crate::{ + interface::{L1BatchEnv, L2Block, SystemEnv}, + vm_refunds_enhancement::{ + bootloader_state::BootloaderState, + constants::BOOTLOADER_HEAP_PAGE, + old_vm::{ + event_sink::InMemoryEventSink, + history_recorder::HistoryMode, + memory::SimpleMemory, + oracles::{ + decommitter::DecommitterOracle, precompile::PrecompilesProcessorWithHistory, + }, + }, + oracles::storage::StorageOracle, + types::l1_batch::bootloader_initial_memory, + utils::l2_blocks::{assert_next_block, load_last_l2_block}, + }, }; -use crate::vm_refunds_enhancement::oracles::storage::StorageOracle; -use crate::vm_refunds_enhancement::types::l1_batch::bootloader_initial_memory; -use crate::vm_refunds_enhancement::utils::l2_blocks::{assert_next_block, load_last_l2_block}; pub type ZkSyncVmState = VmState< StorageOracle, diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/types/l1_batch.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/types/l1_batch.rs index 631f1436cc3..6f16e95f8d7 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/types/l1_batch.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/types/l1_batch.rs @@ -1,7 +1,8 @@ -use crate::interface::L1BatchEnv; use zksync_types::U256; use zksync_utils::{address_to_u256, h256_to_u256}; +use crate::interface::L1BatchEnv; + const OPERATOR_ADDRESS_SLOT: usize = 0; const PREV_BLOCK_HASH_SLOT: usize = 1; const NEW_BLOCK_TIMESTAMP_SLOT: usize = 2; diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/utils/l2_blocks.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/utils/l2_blocks.rs index 3d5f58094e0..5dd26c4c027 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/utils/l2_blocks.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/utils/l2_blocks.rs @@ -1,15 +1,17 @@ -use crate::interface::{L2Block, L2BlockEnv}; use zksync_state::{ReadStorage, StoragePtr}; use zksync_system_constants::{ SYSTEM_CONTEXT_ADDRESS, SYSTEM_CONTEXT_CURRENT_L2_BLOCK_HASHES_POSITION, SYSTEM_CONTEXT_CURRENT_L2_BLOCK_INFO_POSITION, SYSTEM_CONTEXT_CURRENT_TX_ROLLING_HASH_POSITION, SYSTEM_CONTEXT_STORED_L2_BLOCK_HASHES, }; -use zksync_types::block::unpack_block_info; -use zksync_types::web3::signing::keccak256; -use zksync_types::{AccountTreeId, MiniblockNumber, StorageKey, H256, U256}; +use zksync_types::{ + block::unpack_block_info, web3::signing::keccak256, AccountTreeId, MiniblockNumber, StorageKey, + H256, U256, +}; use zksync_utils::{h256_to_u256, u256_to_h256}; +use crate::interface::{L2Block, L2BlockEnv}; + pub(crate) fn get_l2_block_hash_key(block_number: u32) -> StorageKey { let position = h256_to_u256(SYSTEM_CONTEXT_CURRENT_L2_BLOCK_HASHES_POSITION) + U256::from(block_number % SYSTEM_CONTEXT_STORED_L2_BLOCK_HASHES); diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/utils/overhead.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/utils/overhead.rs index 6c56515cfd7..ab5149a050f 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/utils/overhead.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/utils/overhead.rs @@ -1,12 +1,12 @@ -use crate::vm_refunds_enhancement::constants::{ - BLOCK_OVERHEAD_GAS, BLOCK_OVERHEAD_PUBDATA, BOOTLOADER_TX_ENCODING_SPACE, -}; use zk_evm_1_3_3::zkevm_opcode_defs::system_params::MAX_TX_ERGS_LIMIT; use zksync_system_constants::{MAX_L2_TX_GAS_LIMIT, MAX_TXS_IN_BLOCK}; -use zksync_types::l1::is_l1_tx_type; -use zksync_types::U256; +use zksync_types::{l1::is_l1_tx_type, U256}; use zksync_utils::ceil_div_u256; +use crate::vm_refunds_enhancement::constants::{ + BLOCK_OVERHEAD_GAS, BLOCK_OVERHEAD_PUBDATA, BOOTLOADER_TX_ENCODING_SPACE, +}; + /// Derives the overhead for processing transactions in a block. pub fn derive_overhead( gas_limit: u32, diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/utils/transaction_encoding.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/utils/transaction_encoding.rs index ab1352c2c75..56052eca813 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/utils/transaction_encoding.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/utils/transaction_encoding.rs @@ -1,6 +1,7 @@ -use crate::vm_refunds_enhancement::types::internals::TransactionData; use zksync_types::Transaction; +use crate::vm_refunds_enhancement::types::internals::TransactionData; + /// Extension for transactions, specific for VM. Required for bypassing the orphan rule pub trait TransactionVmExt { /// Get the size of the transaction in tokens. diff --git a/core/lib/multivm/src/versions/vm_refunds_enhancement/vm.rs b/core/lib/multivm/src/versions/vm_refunds_enhancement/vm.rs index 11eea1206a8..678a467d447 100644 --- a/core/lib/multivm/src/versions/vm_refunds_enhancement/vm.rs +++ b/core/lib/multivm/src/versions/vm_refunds_enhancement/vm.rs @@ -1,20 +1,22 @@ -use crate::HistoryMode; use zksync_state::{StoragePtr, WriteStorage}; -use zksync_types::l2_to_l1_log::UserL2ToL1Log; -use zksync_types::Transaction; +use zksync_types::{l2_to_l1_log::UserL2ToL1Log, Transaction}; use zksync_utils::bytecode::CompressedBytecodeInfo; -use crate::vm_refunds_enhancement::old_vm::events::merge_events; - -use crate::interface::{ - BootloaderMemory, CurrentExecutionState, L1BatchEnv, L2BlockEnv, SystemEnv, VmExecutionMode, - VmExecutionResultAndLogs, VmInterface, VmInterfaceHistoryEnabled, +use crate::{ + interface::{ + BootloaderMemory, BytecodeCompressionError, CurrentExecutionState, L1BatchEnv, L2BlockEnv, + SystemEnv, VmExecutionMode, VmExecutionResultAndLogs, VmInterface, + VmInterfaceHistoryEnabled, VmMemoryMetrics, + }, + vm_latest::HistoryEnabled, + vm_refunds_enhancement::{ + bootloader_state::BootloaderState, + old_vm::events::merge_events, + tracers::dispatcher::TracerDispatcher, + types::internals::{new_vm_state, VmSnapshot, ZkSyncVmState}, + }, + HistoryMode, }; -use crate::interface::{BytecodeCompressionError, VmMemoryMetrics}; -use crate::vm_latest::HistoryEnabled; -use crate::vm_refunds_enhancement::bootloader_state::BootloaderState; -use crate::vm_refunds_enhancement::tracers::dispatcher::TracerDispatcher; -use crate::vm_refunds_enhancement::types::internals::{new_vm_state, VmSnapshot, ZkSyncVmState}; /// Main entry point for Virtual Machine integration. /// The instance should process only one l1 batch diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/l2_block.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/l2_block.rs index fac7cb33d21..8ce851d6699 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/l2_block.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/l2_block.rs @@ -1,11 +1,15 @@ use std::cmp::Ordering; + use zksync_types::{MiniblockNumber, H256}; use zksync_utils::concat_and_hash; -use crate::interface::{L2Block, L2BlockEnv}; -use crate::vm_virtual_blocks::bootloader_state::snapshot::L2BlockSnapshot; -use crate::vm_virtual_blocks::bootloader_state::tx::BootloaderTx; -use crate::vm_virtual_blocks::utils::l2_blocks::l2_block_hash; +use crate::{ + interface::{L2Block, L2BlockEnv}, + vm_virtual_blocks::{ + bootloader_state::{snapshot::L2BlockSnapshot, tx::BootloaderTx}, + utils::l2_blocks::l2_block_hash, + }, +}; const EMPTY_TXS_ROLLING_HASH: H256 = H256::zero(); diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/state.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/state.rs index 2d67121e89b..685b1821fd5 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/state.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/state.rs @@ -1,19 +1,22 @@ -use crate::vm_virtual_blocks::bootloader_state::{ - l2_block::BootloaderL2Block, - snapshot::BootloaderStateSnapshot, - utils::{apply_l2_block, apply_tx_to_memory}, -}; use std::cmp::Ordering; + use zksync_types::{L2ChainId, U256}; use zksync_utils::bytecode::CompressedBytecodeInfo; -use crate::interface::{BootloaderMemory, L2BlockEnv, TxExecutionMode}; -use crate::vm_virtual_blocks::{ - constants::TX_DESCRIPTION_OFFSET, types::internals::TransactionData, - utils::l2_blocks::assert_next_block, -}; - use super::tx::BootloaderTx; +use crate::{ + interface::{BootloaderMemory, L2BlockEnv, TxExecutionMode}, + vm_virtual_blocks::{ + bootloader_state::{ + l2_block::BootloaderL2Block, + snapshot::BootloaderStateSnapshot, + utils::{apply_l2_block, apply_tx_to_memory}, + }, + constants::TX_DESCRIPTION_OFFSET, + types::internals::TransactionData, + utils::l2_blocks::assert_next_block, + }, +}; /// Intermediate bootloader-related VM state. /// /// Required to process transactions one by one (since we intercept the VM execution to execute diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/tx.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/tx.rs index 3b53c918fda..067d62a9fdd 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/tx.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/tx.rs @@ -1,7 +1,8 @@ -use crate::vm_virtual_blocks::types::internals::TransactionData; use zksync_types::{L2ChainId, H256, U256}; use zksync_utils::bytecode::CompressedBytecodeInfo; +use crate::vm_virtual_blocks::types::internals::TransactionData; + /// Information about tx necessary for execution in bootloader. #[derive(Debug, Clone)] pub(super) struct BootloaderTx { diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/utils.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/utils.rs index 6e836ad201d..a3986d6fe46 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/utils.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/bootloader_state/utils.rs @@ -1,16 +1,19 @@ use zksync_types::U256; -use zksync_utils::bytecode::CompressedBytecodeInfo; -use zksync_utils::{bytes_to_be_words, h256_to_u256}; - -use crate::interface::{BootloaderMemory, TxExecutionMode}; -use crate::vm_virtual_blocks::bootloader_state::l2_block::BootloaderL2Block; -use crate::vm_virtual_blocks::constants::{ - BOOTLOADER_TX_DESCRIPTION_OFFSET, BOOTLOADER_TX_DESCRIPTION_SIZE, COMPRESSED_BYTECODES_OFFSET, - OPERATOR_REFUNDS_OFFSET, TX_DESCRIPTION_OFFSET, TX_OPERATOR_L2_BLOCK_INFO_OFFSET, - TX_OPERATOR_SLOTS_PER_L2_BLOCK_INFO, TX_OVERHEAD_OFFSET, TX_TRUSTED_GAS_LIMIT_OFFSET, -}; +use zksync_utils::{bytecode::CompressedBytecodeInfo, bytes_to_be_words, h256_to_u256}; use super::tx::BootloaderTx; +use crate::{ + interface::{BootloaderMemory, TxExecutionMode}, + vm_virtual_blocks::{ + bootloader_state::l2_block::BootloaderL2Block, + constants::{ + BOOTLOADER_TX_DESCRIPTION_OFFSET, BOOTLOADER_TX_DESCRIPTION_SIZE, + COMPRESSED_BYTECODES_OFFSET, OPERATOR_REFUNDS_OFFSET, TX_DESCRIPTION_OFFSET, + TX_OPERATOR_L2_BLOCK_INFO_OFFSET, TX_OPERATOR_SLOTS_PER_L2_BLOCK_INFO, + TX_OVERHEAD_OFFSET, TX_TRUSTED_GAS_LIMIT_OFFSET, + }, + }, +}; pub(super) fn get_memory_for_compressed_bytecodes( compressed_bytecodes: &[CompressedBytecodeInfo], diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/constants.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/constants.rs index 5535be90381..c03260f1b6d 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/constants.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/constants.rs @@ -1,14 +1,12 @@ use zk_evm_1_3_3::aux_structures::MemoryPage; - +pub use zk_evm_1_3_3::zkevm_opcode_defs::system_params::{ + ERGS_PER_CIRCUIT, INITIAL_STORAGE_WRITE_PUBDATA_BYTES, MAX_PUBDATA_PER_BLOCK, +}; use zksync_system_constants::{ L1_GAS_PER_PUBDATA_BYTE, MAX_L2_TX_GAS_LIMIT, MAX_NEW_FACTORY_DEPS, MAX_TXS_IN_BLOCK, USED_BOOTLOADER_MEMORY_WORDS, }; -pub use zk_evm_1_3_3::zkevm_opcode_defs::system_params::{ - ERGS_PER_CIRCUIT, INITIAL_STORAGE_WRITE_PUBDATA_BYTES, MAX_PUBDATA_PER_BLOCK, -}; - use crate::vm_virtual_blocks::old_vm::utils::heap_page_from_base; /// Max cycles for a single transaction. diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/bytecode.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/bytecode.rs index 2ae53a48ef3..570581740ef 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/bytecode.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/bytecode.rs @@ -1,13 +1,12 @@ use itertools::Itertools; - -use crate::interface::VmInterface; -use crate::HistoryMode; use zksync_state::{StoragePtr, WriteStorage}; use zksync_types::U256; -use zksync_utils::bytecode::{compress_bytecode, hash_bytecode, CompressedBytecodeInfo}; -use zksync_utils::bytes_to_be_words; +use zksync_utils::{ + bytecode::{compress_bytecode, hash_bytecode, CompressedBytecodeInfo}, + bytes_to_be_words, +}; -use crate::vm_virtual_blocks::Vm; +use crate::{interface::VmInterface, vm_virtual_blocks::Vm, HistoryMode}; impl Vm { /// Checks the last transaction has successfully published compressed bytecodes and returns `true` if there is at least one is still unknown. diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/execution.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/execution.rs index ac95312019d..2938280d266 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/execution.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/execution.rs @@ -1,16 +1,22 @@ -use crate::interface::tracer::{TracerExecutionStopReason, VmExecutionStopReason}; -use crate::interface::{VmExecutionMode, VmExecutionResultAndLogs}; -use crate::HistoryMode; use zk_evm_1_3_3::aux_structures::Timestamp; use zksync_state::WriteStorage; -use crate::vm_virtual_blocks::old_vm::utils::{vm_may_have_ended_inner, VmExecutionResult}; -use crate::vm_virtual_blocks::tracers::dispatcher::TracerDispatcher; -use crate::vm_virtual_blocks::tracers::{ - traits::{ExecutionEndTracer, VmTracer}, - DefaultExecutionTracer, RefundsTracer, +use crate::{ + interface::{ + tracer::{TracerExecutionStopReason, VmExecutionStopReason}, + VmExecutionMode, VmExecutionResultAndLogs, + }, + vm_virtual_blocks::{ + old_vm::utils::{vm_may_have_ended_inner, VmExecutionResult}, + tracers::{ + dispatcher::TracerDispatcher, + traits::{ExecutionEndTracer, VmTracer}, + DefaultExecutionTracer, RefundsTracer, + }, + vm::Vm, + }, + HistoryMode, }; -use crate::vm_virtual_blocks::vm::Vm; impl Vm { pub(crate) fn inspect_inner( diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/gas.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/gas.rs index 1f06ecb0827..0ca52d2b687 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/gas.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/gas.rs @@ -1,8 +1,9 @@ -use crate::HistoryMode; use zksync_state::WriteStorage; -use crate::vm_virtual_blocks::tracers::DefaultExecutionTracer; -use crate::vm_virtual_blocks::vm::Vm; +use crate::{ + vm_virtual_blocks::{tracers::DefaultExecutionTracer, vm::Vm}, + HistoryMode, +}; impl Vm { /// Returns the amount of gas remaining to the VM. diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/logs.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/logs.rs index a32f3a16572..0d407efd041 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/logs.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/logs.rs @@ -1,14 +1,18 @@ use zk_evm_1_3_3::aux_structures::Timestamp; use zksync_state::WriteStorage; +use zksync_types::{ + l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}, + VmEvent, +}; -use crate::interface::types::outputs::VmExecutionLogs; -use crate::HistoryMode; -use zksync_types::l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}; -use zksync_types::VmEvent; - -use crate::vm_virtual_blocks::old_vm::events::merge_events; -use crate::vm_virtual_blocks::old_vm::utils::precompile_calls_count_after_timestamp; -use crate::vm_virtual_blocks::vm::Vm; +use crate::{ + interface::types::outputs::VmExecutionLogs, + vm_virtual_blocks::{ + old_vm::{events::merge_events, utils::precompile_calls_count_after_timestamp}, + vm::Vm, + }, + HistoryMode, +}; impl Vm { pub(crate) fn collect_execution_logs_after_timestamp( diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/snapshots.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/snapshots.rs index 1a8ad6fefd2..569e1115039 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/snapshots.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/snapshots.rs @@ -1,13 +1,12 @@ -use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; - use std::time::Duration; -use crate::vm_latest::HistoryEnabled; +use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; use zk_evm_1_3_3::aux_structures::Timestamp; use zksync_state::WriteStorage; -use crate::vm_virtual_blocks::{ - old_vm::oracles::OracleWithHistory, types::internals::VmSnapshot, vm::Vm, +use crate::{ + vm_latest::HistoryEnabled, + vm_virtual_blocks::{old_vm::oracles::OracleWithHistory, types::internals::VmSnapshot, vm::Vm}, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet, EncodeLabelValue)] diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/statistics.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/statistics.rs index dd4a5ad55b2..074e8dae56e 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/statistics.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/statistics.rs @@ -1,12 +1,12 @@ use zk_evm_1_3_3::aux_structures::Timestamp; use zksync_state::WriteStorage; - -use crate::interface::{VmExecutionStatistics, VmMemoryMetrics}; -use crate::HistoryMode; use zksync_types::U256; -use crate::vm_virtual_blocks::tracers::DefaultExecutionTracer; -use crate::vm_virtual_blocks::vm::Vm; +use crate::{ + interface::{VmExecutionStatistics, VmMemoryMetrics}, + vm_virtual_blocks::{tracers::DefaultExecutionTracer, vm::Vm}, + HistoryMode, +}; /// Module responsible for observing the VM behavior, i.e. calculating the statistics of the VM runs /// or reporting the VM memory usage. diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/tx.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/tx.rs index bfeeb56e022..72a7dbc65de 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/tx.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/implementation/tx.rs @@ -1,15 +1,16 @@ -use crate::vm_virtual_blocks::constants::BOOTLOADER_HEAP_PAGE; -use crate::vm_virtual_blocks::implementation::bytecode::{ - bytecode_to_factory_dep, compress_bytecodes, -}; -use crate::HistoryMode; use zk_evm_1_3_3::aux_structures::Timestamp; use zksync_state::WriteStorage; -use zksync_types::l1::is_l1_tx_type; -use zksync_types::Transaction; +use zksync_types::{l1::is_l1_tx_type, Transaction}; -use crate::vm_virtual_blocks::types::internals::TransactionData; -use crate::vm_virtual_blocks::vm::Vm; +use crate::{ + vm_virtual_blocks::{ + constants::BOOTLOADER_HEAP_PAGE, + implementation::bytecode::{bytecode_to_factory_dep, compress_bytecodes}, + types::internals::TransactionData, + vm::Vm, + }, + HistoryMode, +}; impl Vm { pub(crate) fn push_raw_transaction( diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/mod.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/mod.rs index 3a7a96e729d..1500e7027b7 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/mod.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/mod.rs @@ -1,30 +1,24 @@ -pub use old_vm::{ - history_recorder::{HistoryDisabled, HistoryEnabled, HistoryMode}, - memory::SimpleMemory, - oracles::storage::StorageOracle, +pub use self::{ + bootloader_state::BootloaderState, + old_vm::{ + history_recorder::{HistoryDisabled, HistoryEnabled, HistoryMode}, + memory::SimpleMemory, + oracles::storage::StorageOracle, + }, + tracers::{ + dispatcher::TracerDispatcher, + traits::{ExecutionEndTracer, ExecutionProcessing, TracerPointer, VmTracer}, + }, + types::internals::ZkSyncVmState, + utils::transaction_encoding::TransactionVmExt, + vm::Vm, }; -pub use tracers::{ - dispatcher::TracerDispatcher, - traits::{ExecutionEndTracer, ExecutionProcessing, TracerPointer, VmTracer}, -}; - -pub use types::internals::ZkSyncVmState; -pub use utils::transaction_encoding::TransactionVmExt; - -pub use bootloader_state::BootloaderState; - -pub use vm::Vm; - mod bootloader_state; +pub mod constants; mod implementation; mod old_vm; pub(crate) mod tracers; mod types; -mod vm; - -pub mod constants; pub mod utils; - -// #[cfg(test)] -// mod tests; +mod vm; diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/event_sink.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/event_sink.rs index 49ec162fd5e..02938594b5c 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/event_sink.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/event_sink.rs @@ -1,8 +1,5 @@ -use crate::vm_virtual_blocks::old_vm::{ - history_recorder::{AppDataFrameManagerWithHistory, HistoryEnabled, HistoryMode}, - oracles::OracleWithHistory, -}; use std::collections::HashMap; + use zk_evm_1_3_3::{ abstractions::EventSink, aux_structures::{LogQuery, Timestamp}, @@ -12,6 +9,11 @@ use zk_evm_1_3_3::{ }, }; +use crate::vm_virtual_blocks::old_vm::{ + history_recorder::{AppDataFrameManagerWithHistory, HistoryEnabled, HistoryMode}, + oracles::OracleWithHistory, +}; + #[derive(Debug, Clone, PartialEq, Default)] pub struct InMemoryEventSink { frames_stack: AppDataFrameManagerWithHistory, H>, diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/history_recorder.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/history_recorder.rs index a38ee177245..ca02739032c 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/history_recorder.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/history_recorder.rs @@ -5,7 +5,6 @@ use zk_evm_1_3_3::{ vm_state::PrimitiveValue, zkevm_opcode_defs::{self}, }; - use zksync_state::{StoragePtr, WriteStorage}; use zksync_types::{StorageKey, U256}; use zksync_utils::{h256_to_u256, u256_to_h256}; @@ -767,11 +766,14 @@ impl HistoryRecorder, H> { #[cfg(test)] mod tests { - use crate::vm_virtual_blocks::old_vm::history_recorder::{HistoryRecorder, MemoryWrapper}; - use crate::vm_virtual_blocks::HistoryDisabled; use zk_evm_1_3_3::{aux_structures::Timestamp, vm_state::PrimitiveValue}; use zksync_types::U256; + use crate::vm_virtual_blocks::{ + old_vm::history_recorder::{HistoryRecorder, MemoryWrapper}, + HistoryDisabled, + }; + #[test] fn memory_equality() { let mut a: HistoryRecorder = Default::default(); diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/memory.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/memory.rs index f1a424c36ae..c78f8a9e779 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/memory.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/memory.rs @@ -1,16 +1,18 @@ -use zk_evm_1_3_3::abstractions::{Memory, MemoryType}; -use zk_evm_1_3_3::aux_structures::{MemoryPage, MemoryQuery, Timestamp}; -use zk_evm_1_3_3::vm_state::PrimitiveValue; -use zk_evm_1_3_3::zkevm_opcode_defs::FatPointer; +use zk_evm_1_3_3::{ + abstractions::{Memory, MemoryType}, + aux_structures::{MemoryPage, MemoryQuery, Timestamp}, + vm_state::PrimitiveValue, + zkevm_opcode_defs::FatPointer, +}; use zksync_types::U256; -use crate::vm_virtual_blocks::old_vm::history_recorder::{ - FramedStack, HistoryEnabled, HistoryMode, IntFrameManagerWithHistory, MemoryWithHistory, - MemoryWrapper, WithHistory, -}; -use crate::vm_virtual_blocks::old_vm::oracles::OracleWithHistory; -use crate::vm_virtual_blocks::old_vm::utils::{ - aux_heap_page_from_base, heap_page_from_base, stack_page_from_base, +use crate::vm_virtual_blocks::old_vm::{ + history_recorder::{ + FramedStack, HistoryEnabled, HistoryMode, IntFrameManagerWithHistory, MemoryWithHistory, + MemoryWrapper, WithHistory, + }, + oracles::OracleWithHistory, + utils::{aux_heap_page_from_base, heap_page_from_base, stack_page_from_base}, }; #[derive(Debug, Clone, PartialEq)] diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/oracles/decommitter.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/oracles/decommitter.rs index 12c3ffd403d..061912f83c9 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/oracles/decommitter.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/oracles/decommitter.rs @@ -1,23 +1,19 @@ -use std::collections::HashMap; -use std::fmt::Debug; +use std::{collections::HashMap, fmt::Debug}; -use crate::vm_virtual_blocks::old_vm::history_recorder::{ - HistoryEnabled, HistoryMode, HistoryRecorder, WithHistory, -}; - -use zk_evm_1_3_3::abstractions::MemoryType; -use zk_evm_1_3_3::aux_structures::Timestamp; use zk_evm_1_3_3::{ - abstractions::{DecommittmentProcessor, Memory}, - aux_structures::{DecommittmentQuery, MemoryIndex, MemoryLocation, MemoryPage, MemoryQuery}, + abstractions::{DecommittmentProcessor, Memory, MemoryType}, + aux_structures::{ + DecommittmentQuery, MemoryIndex, MemoryLocation, MemoryPage, MemoryQuery, Timestamp, + }, }; - use zksync_state::{ReadStorage, StoragePtr}; use zksync_types::U256; -use zksync_utils::bytecode::bytecode_len_in_words; -use zksync_utils::{bytes_to_be_words, u256_to_h256}; +use zksync_utils::{bytecode::bytecode_len_in_words, bytes_to_be_words, u256_to_h256}; use super::OracleWithHistory; +use crate::vm_virtual_blocks::old_vm::history_recorder::{ + HistoryEnabled, HistoryMode, HistoryRecorder, WithHistory, +}; /// The main job of the DecommiterOracle is to implement the DecommittmentProcessor trait - that is /// used by the VM to 'load' bytecodes into memory. diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/oracles/precompile.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/oracles/precompile.rs index 11ddb26d03a..8fd77ef7f87 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/oracles/precompile.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/oracles/precompile.rs @@ -1,17 +1,14 @@ use zk_evm_1_3_3::{ - abstractions::Memory, - abstractions::PrecompileCyclesWitness, - abstractions::PrecompilesProcessor, + abstractions::{Memory, PrecompileCyclesWitness, PrecompilesProcessor}, aux_structures::{LogQuery, MemoryQuery, Timestamp}, precompiles::DefaultPrecompilesProcessor, }; +use super::OracleWithHistory; use crate::vm_virtual_blocks::old_vm::history_recorder::{ HistoryEnabled, HistoryMode, HistoryRecorder, }; -use super::OracleWithHistory; - /// Wrap of DefaultPrecompilesProcessor that store queue /// of timestamp when precompiles are called to be executed. /// Number of precompiles per block is strictly limited, diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/oracles/storage.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/oracles/storage.rs index 70186b78b32..91c293f4ac8 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/oracles/storage.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/oracles/storage.rs @@ -1,26 +1,22 @@ use std::collections::HashMap; -use crate::vm_virtual_blocks::old_vm::history_recorder::{ - AppDataFrameManagerWithHistory, HashMapHistoryEvent, HistoryEnabled, HistoryMode, - HistoryRecorder, StorageWrapper, WithHistory, -}; - -use zk_evm_1_3_3::abstractions::RefundedAmounts; -use zk_evm_1_3_3::zkevm_opcode_defs::system_params::INITIAL_STORAGE_WRITE_PUBDATA_BYTES; use zk_evm_1_3_3::{ - abstractions::{RefundType, Storage as VmStorageOracle}, + abstractions::{RefundType, RefundedAmounts, Storage as VmStorageOracle}, aux_structures::{LogQuery, Timestamp}, + zkevm_opcode_defs::system_params::INITIAL_STORAGE_WRITE_PUBDATA_BYTES, }; - use zksync_state::{StoragePtr, WriteStorage}; -use zksync_types::utils::storage_key_for_eth_balance; use zksync_types::{ - AccountTreeId, Address, StorageKey, StorageLogQuery, StorageLogQueryType, BOOTLOADER_ADDRESS, - U256, + utils::storage_key_for_eth_balance, AccountTreeId, Address, StorageKey, StorageLogQuery, + StorageLogQueryType, BOOTLOADER_ADDRESS, U256, }; use zksync_utils::u256_to_h256; use super::OracleWithHistory; +use crate::vm_virtual_blocks::old_vm::history_recorder::{ + AppDataFrameManagerWithHistory, HashMapHistoryEvent, HistoryEnabled, HistoryMode, + HistoryRecorder, StorageWrapper, WithHistory, +}; // While the storage does not support different shards, it was decided to write the // code of the StorageOracle with the shard parameters in mind. diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/utils.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/utils.rs index 65497778495..7d38ba1058d 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/utils.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/old_vm/utils.rs @@ -1,22 +1,19 @@ -use crate::vm_virtual_blocks::old_vm::memory::SimpleMemory; - -use crate::vm_virtual_blocks::types::internals::ZkSyncVmState; -use crate::vm_virtual_blocks::HistoryMode; - -use zk_evm_1_3_3::zkevm_opcode_defs::decoding::{ - AllowedPcOrImm, EncodingModeProduction, VmEncodingMode, -}; -use zk_evm_1_3_3::zkevm_opcode_defs::RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER; use zk_evm_1_3_3::{ aux_structures::{MemoryPage, Timestamp}, vm_state::PrimitiveValue, - zkevm_opcode_defs::FatPointer, + zkevm_opcode_defs::{ + decoding::{AllowedPcOrImm, EncodingModeProduction, VmEncodingMode}, + FatPointer, RET_IMPLICIT_RETURNDATA_PARAMS_REGISTER, + }, }; use zksync_state::WriteStorage; use zksync_system_constants::L1_GAS_PER_PUBDATA_BYTE; - use zksync_types::{Address, U256}; +use crate::vm_virtual_blocks::{ + old_vm::memory::SimpleMemory, types::internals::ZkSyncVmState, HistoryMode, +}; + #[derive(Debug, Clone)] pub(crate) enum VmExecutionResult { Ok(Vec), diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/default_tracers.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/default_tracers.rs index f394ab5f752..463bdaa4f35 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/default_tracers.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/default_tracers.rs @@ -1,33 +1,37 @@ -use std::fmt::{Debug, Formatter}; -use std::marker::PhantomData; +use std::{ + fmt::{Debug, Formatter}, + marker::PhantomData, +}; -use crate::interface::dyn_tracers::vm_1_3_3::DynTracer; -use crate::interface::tracer::VmExecutionStopReason; -use crate::interface::VmExecutionMode; -use zk_evm_1_3_3::witness_trace::DummyTracer; -use zk_evm_1_3_3::zkevm_opcode_defs::{Opcode, RetOpcode}; use zk_evm_1_3_3::{ tracing::{ AfterDecodingData, AfterExecutionData, BeforeExecutionData, Tracer, VmLocalStateData, }, vm_state::VmLocalState, + witness_trace::DummyTracer, + zkevm_opcode_defs::{Opcode, RetOpcode}, }; use zksync_state::{StoragePtr, WriteStorage}; use zksync_types::Timestamp; -use crate::vm_virtual_blocks::bootloader_state::utils::apply_l2_block; -use crate::vm_virtual_blocks::bootloader_state::BootloaderState; -use crate::vm_virtual_blocks::constants::BOOTLOADER_HEAP_PAGE; -use crate::vm_virtual_blocks::old_vm::history_recorder::HistoryMode; -use crate::vm_virtual_blocks::old_vm::memory::SimpleMemory; -use crate::vm_virtual_blocks::tracers::dispatcher::TracerDispatcher; -use crate::vm_virtual_blocks::tracers::traits::{ExecutionEndTracer, ExecutionProcessing}; -use crate::vm_virtual_blocks::tracers::utils::{ - computational_gas_price, gas_spent_on_bytecodes_and_long_messages_this_opcode, - print_debug_if_needed, VmHook, +use crate::{ + interface::{dyn_tracers::vm_1_3_3::DynTracer, tracer::VmExecutionStopReason, VmExecutionMode}, + vm_virtual_blocks::{ + bootloader_state::{utils::apply_l2_block, BootloaderState}, + constants::BOOTLOADER_HEAP_PAGE, + old_vm::{history_recorder::HistoryMode, memory::SimpleMemory}, + tracers::{ + dispatcher::TracerDispatcher, + traits::{ExecutionEndTracer, ExecutionProcessing}, + utils::{ + computational_gas_price, gas_spent_on_bytecodes_and_long_messages_this_opcode, + print_debug_if_needed, VmHook, + }, + RefundsTracer, ResultTracer, + }, + types::internals::ZkSyncVmState, + }, }; -use crate::vm_virtual_blocks::tracers::{RefundsTracer, ResultTracer}; -use crate::vm_virtual_blocks::types::internals::ZkSyncVmState; /// Default tracer for the VM. It manages the other tracers execution and stop the vm when needed. pub(crate) struct DefaultExecutionTracer { diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/dispatcher.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/dispatcher.rs index 7eb89461eab..b1b5ef418ee 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/dispatcher.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/dispatcher.rs @@ -1,17 +1,18 @@ -use crate::interface::dyn_tracers::vm_1_3_3::DynTracer; -use crate::interface::tracer::VmExecutionStopReason; -use crate::interface::VmExecutionResultAndLogs; -use crate::vm_virtual_blocks::TracerPointer; -use crate::vm_virtual_blocks::{ - BootloaderState, ExecutionEndTracer, ExecutionProcessing, HistoryMode, SimpleMemory, VmTracer, - ZkSyncVmState, -}; - use zk_evm_1_3_3::tracing::{ AfterDecodingData, AfterExecutionData, BeforeExecutionData, VmLocalStateData, }; use zksync_state::{StoragePtr, WriteStorage}; +use crate::{ + interface::{ + dyn_tracers::vm_1_3_3::DynTracer, tracer::VmExecutionStopReason, VmExecutionResultAndLogs, + }, + vm_virtual_blocks::{ + BootloaderState, ExecutionEndTracer, ExecutionProcessing, HistoryMode, SimpleMemory, + TracerPointer, VmTracer, ZkSyncVmState, + }, +}; + impl From> for TracerDispatcher { fn from(value: TracerPointer) -> Self { Self { diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/refunds.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/refunds.rs index 6496e13172a..6051cd7bb7d 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/refunds.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/refunds.rs @@ -1,9 +1,6 @@ -use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; - use std::collections::HashMap; -use crate::interface::dyn_tracers::vm_1_3_3::DynTracer; -use crate::interface::{L1BatchEnv, Refunds, VmExecutionResultAndLogs}; +use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; use zk_evm_1_3_3::{ aux_structures::Timestamp, tracing::{BeforeExecutionData, VmLocalStateData}, @@ -17,23 +14,26 @@ use zksync_types::{ zkevm_test_harness::witness::sort_storage_access::sort_storage_access_queries, L1BatchNumber, StorageKey, U256, }; -use zksync_utils::bytecode::bytecode_len_in_bytes; -use zksync_utils::{ceil_div_u256, u256_to_h256}; - -use crate::vm_virtual_blocks::bootloader_state::BootloaderState; -use crate::vm_virtual_blocks::constants::{ - BOOTLOADER_HEAP_PAGE, OPERATOR_REFUNDS_OFFSET, TX_GAS_LIMIT_OFFSET, -}; -use crate::vm_virtual_blocks::old_vm::{ - events::merge_events, history_recorder::HistoryMode, memory::SimpleMemory, - oracles::storage::storage_key_of_log, utils::eth_price_per_pubdata_byte, -}; -use crate::vm_virtual_blocks::tracers::utils::gas_spent_on_bytecodes_and_long_messages_this_opcode; -use crate::vm_virtual_blocks::tracers::{ - traits::{ExecutionEndTracer, ExecutionProcessing, VmTracer}, - utils::{get_vm_hook_params, VmHook}, +use zksync_utils::{bytecode::bytecode_len_in_bytes, ceil_div_u256, u256_to_h256}; + +use crate::{ + interface::{dyn_tracers::vm_1_3_3::DynTracer, L1BatchEnv, Refunds, VmExecutionResultAndLogs}, + vm_virtual_blocks::{ + bootloader_state::BootloaderState, + constants::{BOOTLOADER_HEAP_PAGE, OPERATOR_REFUNDS_OFFSET, TX_GAS_LIMIT_OFFSET}, + old_vm::{ + events::merge_events, history_recorder::HistoryMode, memory::SimpleMemory, + oracles::storage::storage_key_of_log, utils::eth_price_per_pubdata_byte, + }, + tracers::{ + traits::{ExecutionEndTracer, ExecutionProcessing, VmTracer}, + utils::{ + gas_spent_on_bytecodes_and_long_messages_this_opcode, get_vm_hook_params, VmHook, + }, + }, + types::internals::ZkSyncVmState, + }, }; -use crate::vm_virtual_blocks::types::internals::ZkSyncVmState; /// Tracer responsible for collecting information about refunds. #[derive(Debug, Clone)] diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/result_tracer.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/result_tracer.rs index 1f566fea567..8c6a5d1793f 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/result_tracer.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/result_tracer.rs @@ -4,28 +4,28 @@ use zk_evm_1_3_3::{ zkevm_opcode_defs::FatPointer, }; use zksync_state::{StoragePtr, WriteStorage}; - -use crate::interface::dyn_tracers::vm_1_3_3::DynTracer; -use crate::interface::tracer::VmExecutionStopReason; -use crate::interface::{ - ExecutionResult, Halt, TxRevertReason, VmExecutionMode, VmExecutionResultAndLogs, - VmRevertReason, -}; use zksync_types::U256; -use crate::vm_virtual_blocks::bootloader_state::BootloaderState; -use crate::vm_virtual_blocks::old_vm::{ - history_recorder::HistoryMode, - memory::SimpleMemory, - utils::{vm_may_have_ended_inner, VmExecutionResult}, +use crate::{ + interface::{ + dyn_tracers::vm_1_3_3::DynTracer, tracer::VmExecutionStopReason, ExecutionResult, Halt, + TxRevertReason, VmExecutionMode, VmExecutionResultAndLogs, VmRevertReason, + }, + vm_virtual_blocks::{ + bootloader_state::BootloaderState, + constants::{BOOTLOADER_HEAP_PAGE, RESULT_SUCCESS_FIRST_SLOT}, + old_vm::{ + history_recorder::HistoryMode, + memory::SimpleMemory, + utils::{vm_may_have_ended_inner, VmExecutionResult}, + }, + tracers::{ + traits::{ExecutionEndTracer, ExecutionProcessing, VmTracer}, + utils::{get_vm_hook_params, read_pointer, VmHook}, + }, + types::internals::ZkSyncVmState, + }, }; -use crate::vm_virtual_blocks::tracers::{ - traits::{ExecutionEndTracer, ExecutionProcessing, VmTracer}, - utils::{get_vm_hook_params, read_pointer, VmHook}, -}; -use crate::vm_virtual_blocks::types::internals::ZkSyncVmState; - -use crate::vm_virtual_blocks::constants::{BOOTLOADER_HEAP_PAGE, RESULT_SUCCESS_FIRST_SLOT}; #[derive(Debug, Clone)] enum Result { diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/traits.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/traits.rs index 3045e6f8319..6d8fdab4e66 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/traits.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/traits.rs @@ -1,12 +1,15 @@ -use crate::interface::dyn_tracers::vm_1_3_3::DynTracer; -use crate::interface::tracer::VmExecutionStopReason; -use crate::interface::VmExecutionResultAndLogs; use zksync_state::WriteStorage; -use crate::vm_virtual_blocks::bootloader_state::BootloaderState; -use crate::vm_virtual_blocks::old_vm::history_recorder::HistoryMode; -use crate::vm_virtual_blocks::old_vm::memory::SimpleMemory; -use crate::vm_virtual_blocks::types::internals::ZkSyncVmState; +use crate::{ + interface::{ + dyn_tracers::vm_1_3_3::DynTracer, tracer::VmExecutionStopReason, VmExecutionResultAndLogs, + }, + vm_virtual_blocks::{ + bootloader_state::BootloaderState, + old_vm::{history_recorder::HistoryMode, memory::SimpleMemory}, + types::internals::ZkSyncVmState, + }, +}; pub type TracerPointer = Box>; /// Run tracer for collecting data during the vm execution cycles diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/utils.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/utils.rs index 0ab697f626f..b2358602fe0 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/utils.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/utils.rs @@ -1,10 +1,10 @@ -use zk_evm_1_3_3::aux_structures::MemoryPage; -use zk_evm_1_3_3::zkevm_opcode_defs::{FarCallABI, FarCallForwardPageType}; use zk_evm_1_3_3::{ + aux_structures::MemoryPage, tracing::{BeforeExecutionData, VmLocalStateData}, - zkevm_opcode_defs::{FatPointer, LogOpcode, Opcode, UMAOpcode}, + zkevm_opcode_defs::{ + FarCallABI, FarCallForwardPageType, FatPointer, LogOpcode, Opcode, UMAOpcode, + }, }; - use zksync_system_constants::{ ECRECOVER_PRECOMPILE_ADDRESS, KECCAK256_PRECOMPILE_ADDRESS, KNOWN_CODES_STORAGE_ADDRESS, L1_MESSENGER_ADDRESS, SHA256_PRECOMPILE_ADDRESS, @@ -12,12 +12,16 @@ use zksync_system_constants::{ use zksync_types::U256; use zksync_utils::u256_to_h256; -use crate::vm_virtual_blocks::constants::{ - BOOTLOADER_HEAP_PAGE, VM_HOOK_PARAMS_COUNT, VM_HOOK_PARAMS_START_POSITION, VM_HOOK_POSITION, +use crate::vm_virtual_blocks::{ + constants::{ + BOOTLOADER_HEAP_PAGE, VM_HOOK_PARAMS_COUNT, VM_HOOK_PARAMS_START_POSITION, VM_HOOK_POSITION, + }, + old_vm::{ + history_recorder::HistoryMode, + memory::SimpleMemory, + utils::{aux_heap_page_from_base, heap_page_from_base}, + }, }; -use crate::vm_virtual_blocks::old_vm::history_recorder::HistoryMode; -use crate::vm_virtual_blocks::old_vm::memory::SimpleMemory; -use crate::vm_virtual_blocks::old_vm::utils::{aux_heap_page_from_base, heap_page_from_base}; #[derive(Clone, Debug, Copy)] pub(crate) enum VmHook { diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/types/internals/transaction_data.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/types/internals/transaction_data.rs index add3d829d80..6d2fe36868b 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/types/internals/transaction_data.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/types/internals/transaction_data.rs @@ -1,15 +1,15 @@ use std::convert::TryInto; -use zksync_types::ethabi::{encode, Address, Token}; -use zksync_types::fee::{encoding_len, Fee}; -use zksync_types::l1::is_l1_tx_type; -use zksync_types::l2::L2Tx; -use zksync_types::transaction_request::{PaymasterParams, TransactionRequest}; + use zksync_types::{ - l2::TransactionType, Bytes, Execute, ExecuteTransactionCommon, L2ChainId, L2TxCommonData, - Nonce, Transaction, H256, U256, + ethabi::{encode, Address, Token}, + fee::{encoding_len, Fee}, + l1::is_l1_tx_type, + l2::{L2Tx, TransactionType}, + transaction_request::{PaymasterParams, TransactionRequest}, + Bytes, Execute, ExecuteTransactionCommon, L2ChainId, L2TxCommonData, Nonce, Transaction, H256, + U256, }; -use zksync_utils::address_to_h256; -use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256}; +use zksync_utils::{address_to_h256, bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256}; use crate::vm_virtual_blocks::utils::overhead::{get_amortized_overhead, OverheadCoefficients}; @@ -303,9 +303,10 @@ impl TryInto for TransactionData { #[cfg(test)] mod tests { - use super::*; use zksync_types::fee::encoding_len; + use super::*; + #[test] fn test_consistency_with_encoding_length() { let transaction = TransactionData { diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/types/internals/vm_state.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/types/internals/vm_state.rs index 8784c754fad..5d67982e7b4 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/types/internals/vm_state.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/types/internals/vm_state.rs @@ -1,34 +1,40 @@ use zk_evm_1_3_3::{ - aux_structures::MemoryPage, - aux_structures::Timestamp, + aux_structures::{MemoryPage, Timestamp}, block_properties::BlockProperties, vm_state::{CallStackEntry, PrimitiveValue, VmState}, witness_trace::DummyTracer, zkevm_opcode_defs::{ system_params::{BOOTLOADER_MAX_MEMORY, INITIAL_FRAME_FORMAL_EH_LOCATION}, - FatPointer, BOOTLOADER_CALLDATA_PAGE, + FatPointer, BOOTLOADER_BASE_PAGE, BOOTLOADER_CALLDATA_PAGE, BOOTLOADER_CODE_PAGE, + STARTING_BASE_PAGE, STARTING_TIMESTAMP, }, }; - -use crate::interface::{L1BatchEnv, L2Block, SystemEnv}; -use zk_evm_1_3_3::zkevm_opcode_defs::{ - BOOTLOADER_BASE_PAGE, BOOTLOADER_CODE_PAGE, STARTING_BASE_PAGE, STARTING_TIMESTAMP, -}; use zksync_state::{StoragePtr, WriteStorage}; use zksync_system_constants::BOOTLOADER_ADDRESS; -use zksync_types::block::legacy_miniblock_hash; -use zksync_types::{zkevm_test_harness::INITIAL_MONOTONIC_CYCLE_COUNTER, Address, MiniblockNumber}; +use zksync_types::{ + block::legacy_miniblock_hash, zkevm_test_harness::INITIAL_MONOTONIC_CYCLE_COUNTER, Address, + MiniblockNumber, +}; use zksync_utils::h256_to_u256; -use crate::vm_virtual_blocks::bootloader_state::BootloaderState; -use crate::vm_virtual_blocks::constants::BOOTLOADER_HEAP_PAGE; -use crate::vm_virtual_blocks::old_vm::{ - event_sink::InMemoryEventSink, history_recorder::HistoryMode, memory::SimpleMemory, - oracles::decommitter::DecommitterOracle, oracles::precompile::PrecompilesProcessorWithHistory, - oracles::storage::StorageOracle, +use crate::{ + interface::{L1BatchEnv, L2Block, SystemEnv}, + vm_virtual_blocks::{ + bootloader_state::BootloaderState, + constants::BOOTLOADER_HEAP_PAGE, + old_vm::{ + event_sink::InMemoryEventSink, + history_recorder::HistoryMode, + memory::SimpleMemory, + oracles::{ + decommitter::DecommitterOracle, precompile::PrecompilesProcessorWithHistory, + storage::StorageOracle, + }, + }, + types::l1_batch_env::bootloader_initial_memory, + utils::l2_blocks::{assert_next_block, load_last_l2_block}, + }, }; -use crate::vm_virtual_blocks::types::l1_batch_env::bootloader_initial_memory; -use crate::vm_virtual_blocks::utils::l2_blocks::{assert_next_block, load_last_l2_block}; pub type ZkSyncVmState = VmState< StorageOracle, diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/types/l1_batch_env.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/types/l1_batch_env.rs index 8af706954ed..0e43863b196 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/types/l1_batch_env.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/types/l1_batch_env.rs @@ -1,7 +1,8 @@ -use crate::interface::L1BatchEnv; use zksync_types::U256; use zksync_utils::{address_to_u256, h256_to_u256}; +use crate::interface::L1BatchEnv; + const OPERATOR_ADDRESS_SLOT: usize = 0; const PREV_BLOCK_HASH_SLOT: usize = 1; const NEW_BLOCK_TIMESTAMP_SLOT: usize = 2; diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/utils/l2_blocks.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/utils/l2_blocks.rs index 3d5f58094e0..5dd26c4c027 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/utils/l2_blocks.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/utils/l2_blocks.rs @@ -1,15 +1,17 @@ -use crate::interface::{L2Block, L2BlockEnv}; use zksync_state::{ReadStorage, StoragePtr}; use zksync_system_constants::{ SYSTEM_CONTEXT_ADDRESS, SYSTEM_CONTEXT_CURRENT_L2_BLOCK_HASHES_POSITION, SYSTEM_CONTEXT_CURRENT_L2_BLOCK_INFO_POSITION, SYSTEM_CONTEXT_CURRENT_TX_ROLLING_HASH_POSITION, SYSTEM_CONTEXT_STORED_L2_BLOCK_HASHES, }; -use zksync_types::block::unpack_block_info; -use zksync_types::web3::signing::keccak256; -use zksync_types::{AccountTreeId, MiniblockNumber, StorageKey, H256, U256}; +use zksync_types::{ + block::unpack_block_info, web3::signing::keccak256, AccountTreeId, MiniblockNumber, StorageKey, + H256, U256, +}; use zksync_utils::{h256_to_u256, u256_to_h256}; +use crate::interface::{L2Block, L2BlockEnv}; + pub(crate) fn get_l2_block_hash_key(block_number: u32) -> StorageKey { let position = h256_to_u256(SYSTEM_CONTEXT_CURRENT_L2_BLOCK_HASHES_POSITION) + U256::from(block_number % SYSTEM_CONTEXT_STORED_L2_BLOCK_HASHES); diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/utils/overhead.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/utils/overhead.rs index c17d619b464..79c52ac373b 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/utils/overhead.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/utils/overhead.rs @@ -1,12 +1,12 @@ -use crate::vm_virtual_blocks::constants::{ - BLOCK_OVERHEAD_GAS, BLOCK_OVERHEAD_PUBDATA, BOOTLOADER_TX_ENCODING_SPACE, -}; use zk_evm_1_3_3::zkevm_opcode_defs::system_params::MAX_TX_ERGS_LIMIT; use zksync_system_constants::{MAX_L2_TX_GAS_LIMIT, MAX_TXS_IN_BLOCK}; -use zksync_types::l1::is_l1_tx_type; -use zksync_types::U256; +use zksync_types::{l1::is_l1_tx_type, U256}; use zksync_utils::ceil_div_u256; +use crate::vm_virtual_blocks::constants::{ + BLOCK_OVERHEAD_GAS, BLOCK_OVERHEAD_PUBDATA, BOOTLOADER_TX_ENCODING_SPACE, +}; + /// Derives the overhead for processing transactions in a block. pub fn derive_overhead( gas_limit: u32, diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/utils/transaction_encoding.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/utils/transaction_encoding.rs index b45ec4d1411..5f9c37cbb73 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/utils/transaction_encoding.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/utils/transaction_encoding.rs @@ -1,6 +1,7 @@ -use crate::vm_virtual_blocks::types::internals::TransactionData; use zksync_types::Transaction; +use crate::vm_virtual_blocks::types::internals::TransactionData; + /// Extension for transactions, specific for VM. Required for bypassing the orphan rule pub trait TransactionVmExt { /// Get the size of the transaction in tokens. diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/vm.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/vm.rs index 4110825a260..ed05e951475 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/vm.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/vm.rs @@ -1,21 +1,22 @@ -use crate::interface::{ - BootloaderMemory, BytecodeCompressionError, CurrentExecutionState, L1BatchEnv, L2BlockEnv, - SystemEnv, VmExecutionMode, VmExecutionResultAndLogs, VmInterface, VmInterfaceHistoryEnabled, - VmMemoryMetrics, -}; -use crate::vm_latest::HistoryEnabled; -use crate::HistoryMode; use zksync_state::{StoragePtr, WriteStorage}; -use zksync_types::l2_to_l1_log::UserL2ToL1Log; -use zksync_types::Transaction; +use zksync_types::{l2_to_l1_log::UserL2ToL1Log, Transaction}; use zksync_utils::bytecode::CompressedBytecodeInfo; -use crate::vm_virtual_blocks::old_vm::events::merge_events; - -use crate::vm_virtual_blocks::bootloader_state::BootloaderState; -use crate::vm_virtual_blocks::tracers::dispatcher::TracerDispatcher; - -use crate::vm_virtual_blocks::types::internals::{new_vm_state, VmSnapshot, ZkSyncVmState}; +use crate::{ + interface::{ + BootloaderMemory, BytecodeCompressionError, CurrentExecutionState, L1BatchEnv, L2BlockEnv, + SystemEnv, VmExecutionMode, VmExecutionResultAndLogs, VmInterface, + VmInterfaceHistoryEnabled, VmMemoryMetrics, + }, + vm_latest::HistoryEnabled, + vm_virtual_blocks::{ + bootloader_state::BootloaderState, + old_vm::events::merge_events, + tracers::dispatcher::TracerDispatcher, + types::internals::{new_vm_state, VmSnapshot, ZkSyncVmState}, + }, + HistoryMode, +}; /// Main entry point for Virtual Machine integration. /// The instance should process only one l1 batch diff --git a/core/lib/multivm/src/vm_instance.rs b/core/lib/multivm/src/vm_instance.rs index 6b90da4bd3b..6716aeaf146 100644 --- a/core/lib/multivm/src/vm_instance.rs +++ b/core/lib/multivm/src/vm_instance.rs @@ -1,15 +1,16 @@ -use crate::interface::{ - BootloaderMemory, CurrentExecutionState, FinishedL1Batch, L1BatchEnv, L2BlockEnv, SystemEnv, - VmExecutionMode, VmExecutionResultAndLogs, VmInterface, VmInterfaceHistoryEnabled, - VmMemoryMetrics, -}; - use zksync_state::{StoragePtr, WriteStorage}; use zksync_types::VmVersion; use zksync_utils::bytecode::CompressedBytecodeInfo; -use crate::glue::history_mode::HistoryMode; -use crate::tracers::TracerDispatcher; +use crate::{ + glue::history_mode::HistoryMode, + interface::{ + BootloaderMemory, CurrentExecutionState, FinishedL1Batch, L1BatchEnv, L2BlockEnv, + SystemEnv, VmExecutionMode, VmExecutionResultAndLogs, VmInterface, + VmInterfaceHistoryEnabled, VmMemoryMetrics, + }, + tracers::TracerDispatcher, +}; #[derive(Debug)] pub enum VmInstance { diff --git a/core/lib/object_store/src/file.rs b/core/lib/object_store/src/file.rs index c248fb76595..6f589e83630 100644 --- a/core/lib/object_store/src/file.rs +++ b/core/lib/object_store/src/file.rs @@ -1,8 +1,8 @@ +use std::fmt::Debug; + use async_trait::async_trait; use tokio::{fs, io}; -use std::fmt::Debug; - use crate::raw::{Bucket, ObjectStore, ObjectStoreError}; impl From for ObjectStoreError { diff --git a/core/lib/object_store/src/gcs.rs b/core/lib/object_store/src/gcs.rs index d01fb833b12..1d88aa5237a 100644 --- a/core/lib/object_store/src/gcs.rs +++ b/core/lib/object_store/src/gcs.rs @@ -1,21 +1,23 @@ //! GCS-based [`ObjectStore`] implementation. +use std::{fmt, future::Future, time::Duration}; + use async_trait::async_trait; use google_cloud_auth::{credentials::CredentialsFile, error::Error}; use google_cloud_storage::{ client::{Client, ClientConfig}, - http::objects::{ - delete::DeleteObjectRequest, - download::Range, - get::GetObjectRequest, - upload::{Media, UploadObjectRequest, UploadType}, + http::{ + objects::{ + delete::DeleteObjectRequest, + download::Range, + get::GetObjectRequest, + upload::{Media, UploadObjectRequest, UploadType}, + }, + Error as HttpError, }, - http::Error as HttpError, }; use http::StatusCode; -use std::{fmt, future::Future, time::Duration}; - use crate::{ metrics::GCS_METRICS, raw::{Bucket, ObjectStore, ObjectStoreError}, diff --git a/core/lib/object_store/src/metrics.rs b/core/lib/object_store/src/metrics.rs index 9cd51ba3ed7..f372b5bac1c 100644 --- a/core/lib/object_store/src/metrics.rs +++ b/core/lib/object_store/src/metrics.rs @@ -1,9 +1,9 @@ //! Metrics for the object storage. -use vise::{Buckets, Histogram, LabeledFamily, LatencyObserver, Metrics}; - use std::time::Duration; +use vise::{Buckets, Histogram, LabeledFamily, LatencyObserver, Metrics}; + use crate::Bucket; #[derive(Debug, Metrics)] diff --git a/core/lib/object_store/src/mock.rs b/core/lib/object_store/src/mock.rs index 727ef1e8d53..ac1a2fd7a44 100644 --- a/core/lib/object_store/src/mock.rs +++ b/core/lib/object_store/src/mock.rs @@ -1,10 +1,10 @@ //! Mock implementation of [`ObjectStore`]. +use std::collections::HashMap; + use async_trait::async_trait; use tokio::sync::Mutex; -use std::collections::HashMap; - use crate::raw::{Bucket, ObjectStore, ObjectStoreError}; type BucketMap = HashMap>; diff --git a/core/lib/object_store/src/objects.rs b/core/lib/object_store/src/objects.rs index e5ee186676e..35808bb4686 100644 --- a/core/lib/object_store/src/objects.rs +++ b/core/lib/object_store/src/objects.rs @@ -1,15 +1,17 @@ //! Stored objects. -use zksync_types::aggregated_operations::L1BatchProofForL1; use zksync_types::{ + aggregated_operations::L1BatchProofForL1, proofs::{AggregationRound, PrepareBasicCircuitsJob}, storage::witness_block_state::WitnessBlockState, zkevm_test_harness::{ abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, bellman::bn256::Bn256, encodings::{recursion_request::RecursionRequest, QueueSimulator}, - witness::full_block_artifact::{BlockBasicCircuits, BlockBasicCircuitsPublicInputs}, - witness::oracle::VmWitnessOracle, + witness::{ + full_block_artifact::{BlockBasicCircuits, BlockBasicCircuitsPublicInputs}, + oracle::VmWitnessOracle, + }, LeafAggregationOutputDataWitness, NodeAggregationOutputDataWitness, SchedulerCircuitInstanceWitness, }, diff --git a/core/lib/object_store/src/raw.rs b/core/lib/object_store/src/raw.rs index bf318a61610..c68b4cb978f 100644 --- a/core/lib/object_store/src/raw.rs +++ b/core/lib/object_store/src/raw.rs @@ -1,10 +1,10 @@ -use async_trait::async_trait; - use std::{error, fmt, sync::Arc}; -use crate::{file::FileBackedObjectStore, gcs::GoogleCloudStorage, mock::MockStore}; +use async_trait::async_trait; use zksync_config::configs::object_store::{ObjectStoreConfig, ObjectStoreMode}; +use crate::{file::FileBackedObjectStore, gcs::GoogleCloudStorage, mock::MockStore}; + /// Bucket for [`ObjectStore`] in which objects can be placed. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[non_exhaustive] diff --git a/core/lib/object_store/tests/integration.rs b/core/lib/object_store/tests/integration.rs index dfa659dcf8b..9db2061f17f 100644 --- a/core/lib/object_store/tests/integration.rs +++ b/core/lib/object_store/tests/integration.rs @@ -1,7 +1,6 @@ //! Integration tests for object store. use tokio::fs; - use zksync_object_store::{Bucket, ObjectStoreFactory}; use zksync_types::{ proofs::{PrepareBasicCircuitsJob, StorageLogMetadata}, diff --git a/core/lib/prometheus_exporter/src/lib.rs b/core/lib/prometheus_exporter/src/lib.rs index 25f5915e205..4eda0bebe0e 100644 --- a/core/lib/prometheus_exporter/src/lib.rs +++ b/core/lib/prometheus_exporter/src/lib.rs @@ -1,11 +1,11 @@ +use std::{net::Ipv4Addr, time::Duration}; + use anyhow::Context as _; use metrics_exporter_prometheus::{Matcher, PrometheusBuilder}; use tokio::sync::watch; use vise::MetricsCollection; use vise_exporter::MetricsExporter; -use std::{net::Ipv4Addr, time::Duration}; - fn configure_legacy_exporter(builder: PrometheusBuilder) -> PrometheusBuilder { // in seconds let default_latency_buckets = [0.001, 0.005, 0.025, 0.1, 0.25, 1.0, 5.0, 30.0, 120.0]; diff --git a/core/lib/prover_utils/src/gcs_proof_fetcher.rs b/core/lib/prover_utils/src/gcs_proof_fetcher.rs index 8b59fe67a61..26872701a1f 100644 --- a/core/lib/prover_utils/src/gcs_proof_fetcher.rs +++ b/core/lib/prover_utils/src/gcs_proof_fetcher.rs @@ -1,6 +1,5 @@ use zksync_object_store::{ObjectStore, ObjectStoreError}; -use zksync_types::aggregated_operations::L1BatchProofForL1; -use zksync_types::L1BatchNumber; +use zksync_types::{aggregated_operations::L1BatchProofForL1, L1BatchNumber}; pub async fn load_wrapped_fri_proofs_for_range( from: L1BatchNumber, diff --git a/core/lib/prover_utils/src/region_fetcher.rs b/core/lib/prover_utils/src/region_fetcher.rs index 22a0cedce49..d2c49dd068d 100644 --- a/core/lib/prover_utils/src/region_fetcher.rs +++ b/core/lib/prover_utils/src/region_fetcher.rs @@ -1,8 +1,9 @@ use anyhow::Context as _; use regex::Regex; -use reqwest::header::{HeaderMap, HeaderValue}; -use reqwest::Method; - +use reqwest::{ + header::{HeaderMap, HeaderValue}, + Method, +}; use zksync_config::configs::ProverGroupConfig; use zksync_utils::http_with_retries::send_request_with_retries; diff --git a/core/lib/prover_utils/src/vk_commitment_helper.rs b/core/lib/prover_utils/src/vk_commitment_helper.rs index 05e35a4f7ee..9a6c074b1d2 100644 --- a/core/lib/prover_utils/src/vk_commitment_helper.rs +++ b/core/lib/prover_utils/src/vk_commitment_helper.rs @@ -1,5 +1,6 @@ -use anyhow::Context as _; use std::fs; + +use anyhow::Context as _; use toml_edit::{Document, Item, Value}; pub fn get_toml_formatted_value(string_value: String) -> Item { diff --git a/core/lib/queued_job_processor/src/lib.rs b/core/lib/queued_job_processor/src/lib.rs index d5ed185b256..2966fba49ca 100644 --- a/core/lib/queued_job_processor/src/lib.rs +++ b/core/lib/queued_job_processor/src/lib.rs @@ -1,15 +1,13 @@ -use std::fmt::Debug; -use std::time::{Duration, Instant}; +use std::{ + fmt::Debug, + time::{Duration, Instant}, +}; use anyhow::Context as _; pub use async_trait::async_trait; -use tokio::sync::watch; -use tokio::task::JoinHandle; -use tokio::time::sleep; - -use zksync_utils::panic_extractor::try_extract_panic_message; - +use tokio::{sync::watch, task::JoinHandle, time::sleep}; use vise::{Buckets, Counter, Histogram, LabeledFamily, Metrics}; +use zksync_utils::panic_extractor::try_extract_panic_message; const ATTEMPT_BUCKETS: Buckets = Buckets::exponential(1.0..=64.0, 2.0); diff --git a/core/lib/state/src/cache/metrics.rs b/core/lib/state/src/cache/metrics.rs index 13bc8c94aa9..0e8c8cd8685 100644 --- a/core/lib/state/src/cache/metrics.rs +++ b/core/lib/state/src/cache/metrics.rs @@ -1,9 +1,9 @@ //! General-purpose cache metrics. -use vise::{Buckets, Counter, EncodeLabelValue, Gauge, Histogram, LabeledFamily, Metrics}; - use std::time::Duration; +use vise::{Buckets, Counter, EncodeLabelValue, Gauge, Histogram, LabeledFamily, Metrics}; + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue)] #[metrics(rename_all = "snake_case")] pub(super) enum Method { diff --git a/core/lib/state/src/in_memory.rs b/core/lib/state/src/in_memory.rs index fcb69affea8..6f9fb868045 100644 --- a/core/lib/state/src/in_memory.rs +++ b/core/lib/state/src/in_memory.rs @@ -1,6 +1,5 @@ use std::collections::{hash_map::Entry, BTreeMap, HashMap}; -use crate::ReadStorage; use zksync_types::{ block::DeployedContract, get_code_key, get_known_code_key, get_system_context_init_logs, system_contracts::get_system_smart_contracts, L2ChainId, StorageKey, StorageLog, @@ -8,6 +7,8 @@ use zksync_types::{ }; use zksync_utils::u256_to_h256; +use crate::ReadStorage; + /// Network ID we use by default for in memory storage. pub const IN_MEMORY_STORAGE_DEFAULT_NETWORK_ID: u32 = 270; diff --git a/core/lib/state/src/postgres/metrics.rs b/core/lib/state/src/postgres/metrics.rs index 33e5664bb2b..18fb54cdfa3 100644 --- a/core/lib/state/src/postgres/metrics.rs +++ b/core/lib/state/src/postgres/metrics.rs @@ -1,9 +1,9 @@ //! Metrics for `PostgresStorage`. -use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics}; - use std::time::Duration; +use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics}; + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet, EncodeLabelValue)] #[metrics(label = "stage", rename_all = "snake_case")] pub(super) enum ValuesUpdateStage { diff --git a/core/lib/state/src/postgres/mod.rs b/core/lib/state/src/postgres/mod.rs index 8cc69f7bbbd..7208877abb3 100644 --- a/core/lib/state/src/postgres/mod.rs +++ b/core/lib/state/src/postgres/mod.rs @@ -1,23 +1,22 @@ -use tokio::{runtime::Handle, sync::mpsc}; - use std::{ mem, sync::{Arc, RwLock}, }; +use tokio::{runtime::Handle, sync::mpsc}; use zksync_dal::{ConnectionPool, StorageProcessor}; use zksync_types::{L1BatchNumber, MiniblockNumber, StorageKey, StorageValue, H256}; -mod metrics; -#[cfg(test)] -mod tests; - use self::metrics::{Method, ValuesUpdateStage, CACHE_METRICS, STORAGE_METRICS}; use crate::{ cache::{Cache, CacheValue}, ReadStorage, }; +mod metrics; +#[cfg(test)] +mod tests; + /// Type alias for smart contract source code cache. type FactoryDepsCache = Cache>; diff --git a/core/lib/state/src/postgres/tests.rs b/core/lib/state/src/postgres/tests.rs index 213360bb73d..6514da136d5 100644 --- a/core/lib/state/src/postgres/tests.rs +++ b/core/lib/state/src/postgres/tests.rs @@ -1,13 +1,12 @@ //! Tests for `PostgresStorage`. +use std::{collections::HashMap, mem}; + use rand::{ + rngs::StdRng, seq::{IteratorRandom, SliceRandom}, Rng, SeedableRng, }; - -use rand::rngs::StdRng; -use std::{collections::HashMap, mem}; - use zksync_dal::ConnectionPool; use zksync_types::StorageLog; diff --git a/core/lib/state/src/rocksdb/metrics.rs b/core/lib/state/src/rocksdb/metrics.rs index 81b035811d5..997f4b42ed3 100644 --- a/core/lib/state/src/rocksdb/metrics.rs +++ b/core/lib/state/src/rocksdb/metrics.rs @@ -1,9 +1,9 @@ //! Metrics for `RocksdbStorage`. -use vise::{Buckets, Gauge, Histogram, Metrics}; - use std::time::Duration; +use vise::{Buckets, Gauge, Histogram, Metrics}; + #[derive(Debug, Metrics)] #[metrics(prefix = "server_state_keeper_secondary_storage")] pub(super) struct RocksdbStorageMetrics { diff --git a/core/lib/state/src/rocksdb/mod.rs b/core/lib/state/src/rocksdb/mod.rs index e3748f3acfd..96d22727144 100644 --- a/core/lib/state/src/rocksdb/mod.rs +++ b/core/lib/state/src/rocksdb/mod.rs @@ -19,19 +19,19 @@ //! | Contracts | address (20 bytes) | `Vec` | Contract contents | //! | Factory deps | hash (32 bytes) | `Vec` | Bytecodes for new contracts that a certain contract may deploy. | -use itertools::{Either, Itertools}; use std::{collections::HashMap, convert::TryInto, mem, path::Path, time::Instant}; +use itertools::{Either, Itertools}; use zksync_dal::StorageProcessor; use zksync_storage::{db::NamedColumnFamily, RocksDB}; use zksync_types::{L1BatchNumber, StorageKey, StorageValue, H256, U256}; use zksync_utils::{h256_to_u256, u256_to_h256}; -mod metrics; - use self::metrics::METRICS; use crate::{InMemoryStorage, ReadStorage}; +mod metrics; + fn serialize_block_number(block_number: u32) -> [u8; 4] { block_number.to_le_bytes() } @@ -506,13 +506,13 @@ impl ReadStorage for RocksdbStorage { #[cfg(test)] mod tests { use tempfile::TempDir; + use zksync_dal::ConnectionPool; + use zksync_types::{MiniblockNumber, StorageLog}; use super::*; use crate::test_utils::{ create_l1_batch, create_miniblock, gen_storage_logs, prepare_postgres, }; - use zksync_dal::ConnectionPool; - use zksync_types::{MiniblockNumber, StorageLog}; #[tokio::test] async fn rocksdb_storage_basics() { diff --git a/core/lib/state/src/shadow_storage.rs b/core/lib/state/src/shadow_storage.rs index dea713ba40c..0a2bd0fa43e 100644 --- a/core/lib/state/src/shadow_storage.rs +++ b/core/lib/state/src/shadow_storage.rs @@ -1,7 +1,7 @@ use vise::{Counter, Metrics}; +use zksync_types::{L1BatchNumber, StorageKey, StorageValue, H256}; use crate::ReadStorage; -use zksync_types::{L1BatchNumber, StorageKey, StorageValue, H256}; #[derive(Debug, Metrics)] #[metrics(prefix = "shadow_storage")] diff --git a/core/lib/state/src/storage_view.rs b/core/lib/state/src/storage_view.rs index 8476be78aa9..543b41bc657 100644 --- a/core/lib/state/src/storage_view.rs +++ b/core/lib/state/src/storage_view.rs @@ -1,14 +1,15 @@ -use std::cell::RefCell; -use std::rc::Rc; use std::{ + cell::RefCell, collections::HashMap, fmt, mem, + rc::Rc, time::{Duration, Instant}, }; -use crate::{ReadStorage, WriteStorage}; use zksync_types::{witness_block_state::WitnessBlockState, StorageKey, StorageValue, H256}; +use crate::{ReadStorage, WriteStorage}; + /// Metrics for [`StorageView`]. #[derive(Debug, Default, Clone, Copy)] pub struct StorageViewMetrics { @@ -204,9 +205,10 @@ impl WriteStorage for StorageView { #[cfg(test)] mod test { + use zksync_types::{AccountTreeId, Address, H256}; + use super::*; use crate::InMemoryStorage; - use zksync_types::{AccountTreeId, Address, H256}; #[test] fn test_storage_access() { diff --git a/core/lib/state/src/test_utils.rs b/core/lib/state/src/test_utils.rs index b9a9d81fc54..3a100c50569 100644 --- a/core/lib/state/src/test_utils.rs +++ b/core/lib/state/src/test_utils.rs @@ -1,5 +1,7 @@ //! Shared utils for unit tests. +use std::ops; + use zksync_dal::StorageProcessor; use zksync_types::{ block::{BlockGasCount, L1BatchHeader, MiniblockHeader}, @@ -7,8 +9,6 @@ use zksync_types::{ StorageLog, H256, }; -use std::ops; - pub(crate) async fn prepare_postgres(conn: &mut StorageProcessor<'_>) { if conn.blocks_dal().is_genesis_needed().await.unwrap() { conn.protocol_versions_dal() diff --git a/core/lib/state/src/witness.rs b/core/lib/state/src/witness.rs index 72aab8bbe6e..50e2d9b5407 100644 --- a/core/lib/state/src/witness.rs +++ b/core/lib/state/src/witness.rs @@ -1,9 +1,8 @@ use vise::{Counter, Metrics}; +use zksync_types::{witness_block_state::WitnessBlockState, StorageKey, StorageValue, H256}; use crate::ReadStorage; -use zksync_types::{witness_block_state::WitnessBlockState, StorageKey, StorageValue, H256}; - #[derive(Debug, Metrics)] #[metrics(prefix = "witness_storage")] struct WitnessStorageMetrics { diff --git a/core/lib/storage/src/db.rs b/core/lib/storage/src/db.rs index 617d14d272d..f6237d49950 100644 --- a/core/lib/storage/src/db.rs +++ b/core/lib/storage/src/db.rs @@ -1,8 +1,3 @@ -use rocksdb::{ - properties, BlockBasedOptions, Cache, ColumnFamily, ColumnFamilyDescriptor, DBPinnableSlice, - Direction, IteratorMode, Options, PrefixRange, ReadOptions, WriteOptions, DB, -}; - use std::{ collections::{HashMap, HashSet}, ffi::CStr, @@ -15,6 +10,11 @@ use std::{ time::{Duration, Instant}, }; +use rocksdb::{ + properties, BlockBasedOptions, Cache, ColumnFamily, ColumnFamilyDescriptor, DBPinnableSlice, + Direction, IteratorMode, Options, PrefixRange, ReadOptions, WriteOptions, DB, +}; + use crate::metrics::{RocksdbLabels, RocksdbSizeMetrics, METRICS}; /// Number of active RocksDB instances used to determine if it's safe to exit current process. diff --git a/core/lib/storage/src/metrics.rs b/core/lib/storage/src/metrics.rs index 928e735a30c..47b0a52ee98 100644 --- a/core/lib/storage/src/metrics.rs +++ b/core/lib/storage/src/metrics.rs @@ -1,14 +1,14 @@ //! General-purpose RocksDB metrics. All metrics code in the crate should be in this module. -use once_cell::sync::Lazy; -use vise::{Buckets, Collector, Counter, EncodeLabelSet, Family, Gauge, Histogram, Metrics, Unit}; - use std::{ collections::HashMap, sync::{Mutex, Weak}, time::Duration, }; +use once_cell::sync::Lazy; +use vise::{Buckets, Collector, Counter, EncodeLabelSet, Family, Gauge, Histogram, Metrics, Unit}; + use crate::db::RocksDBInner; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet)] diff --git a/core/lib/test_account/src/lib.rs b/core/lib/test_account/src/lib.rs index 00764df6dc4..5a84c84f4f5 100644 --- a/core/lib/test_account/src/lib.rs +++ b/core/lib/test_account/src/lib.rs @@ -1,21 +1,21 @@ use ethabi::Token; -use zksync_contracts::test_contracts::LoadnextContractExecutionParams; -use zksync_contracts::{deployer_contract, load_contract}; +use zksync_contracts::{ + deployer_contract, load_contract, test_contracts::LoadnextContractExecutionParams, +}; +use zksync_eth_signer::{raw_ethereum_tx::TransactionParameters, EthereumSigner, PrivateKeySigner}; use zksync_system_constants::{ CONTRACT_DEPLOYER_ADDRESS, MAX_GAS_PER_PUBDATA_BYTE, REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE, }; -use zksync_types::fee::Fee; -use zksync_types::l2::L2Tx; -use zksync_types::utils::deployed_address_create; use zksync_types::{ + fee::Fee, + l1::{OpProcessingType, PriorityQueueType}, + l2::L2Tx, + utils::deployed_address_create, Address, Execute, ExecuteTransactionCommon, L1TxCommonData, L2ChainId, Nonce, PackedEthSignature, PriorityOpId, Transaction, H256, U256, }; - -use zksync_eth_signer::{raw_ethereum_tx::TransactionParameters, EthereumSigner, PrivateKeySigner}; -use zksync_types::l1::{OpProcessingType, PriorityQueueType}; - use zksync_utils::bytecode::hash_bytecode; + pub const L1_TEST_GAS_PER_PUBDATA_BYTE: u32 = 800; const BASE_FEE: u64 = 2_000_000_000; diff --git a/core/lib/types/src/aggregated_operations.rs b/core/lib/types/src/aggregated_operations.rs index 8819460f269..006eca562e7 100644 --- a/core/lib/types/src/aggregated_operations.rs +++ b/core/lib/types/src/aggregated_operations.rs @@ -1,12 +1,12 @@ -use codegen::serialize_proof; - use std::{fmt, ops, str::FromStr}; +use codegen::serialize_proof; use serde::{Deserialize, Serialize}; -use zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit; -use zkevm_test_harness::bellman::bn256::Bn256; -use zkevm_test_harness::bellman::plonk::better_better_cs::proof::Proof; -use zkevm_test_harness::witness::oracle::VmWitnessOracle; +use zkevm_test_harness::{ + abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, + bellman::{bn256::Bn256, plonk::better_better_cs::proof::Proof}, + witness::oracle::VmWitnessOracle, +}; use zksync_basic_types::{ethabi::Token, L1BatchNumber}; use crate::{commitment::L1BatchWithMetadata, ProtocolVersionId, U256}; diff --git a/core/lib/types/src/api/mod.rs b/core/lib/types/src/api/mod.rs index 1ad54ce6d1a..73fdf199deb 100644 --- a/core/lib/types/src/api/mod.rs +++ b/core/lib/types/src/api/mod.rs @@ -1,20 +1,21 @@ use chrono::{DateTime, Utc}; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use strum::Display; - use zksync_basic_types::{ web3::types::{Bytes, H160, H256, H64, U256, U64}, L1BatchNumber, }; use zksync_contracts::BaseSystemContractsHashes; -use crate::protocol_version::L1VerifierConfig; pub use crate::transaction_request::{ Eip712Meta, SerializationTransactionError, TransactionRequest, }; -use crate::vm_trace::{Call, CallType}; -use crate::web3::types::{AccessList, Index, H2048}; -use crate::{Address, MiniblockNumber, ProtocolVersionId}; +use crate::{ + protocol_version::L1VerifierConfig, + vm_trace::{Call, CallType}, + web3::types::{AccessList, Index, H2048}, + Address, MiniblockNumber, ProtocolVersionId, +}; pub mod en; diff --git a/core/lib/types/src/block.rs b/core/lib/types/src/block.rs index e61a56d2c91..0aa9d06711c 100644 --- a/core/lib/types/src/block.rs +++ b/core/lib/types/src/block.rs @@ -1,10 +1,9 @@ -use serde::{Deserialize, Serialize}; -use zksync_system_constants::SYSTEM_BLOCK_INFO_BLOCK_NUMBER_MULTIPLIER; - use std::{fmt, ops}; +use serde::{Deserialize, Serialize}; use zksync_basic_types::{H2048, H256, U256}; use zksync_contracts::BaseSystemContractsHashes; +use zksync_system_constants::SYSTEM_BLOCK_INFO_BLOCK_NUMBER_MULTIPLIER; use crate::{ l2_to_l1_log::{SystemL2ToL1Log, UserL2ToL1Log}, diff --git a/core/lib/types/src/circuit.rs b/core/lib/types/src/circuit.rs index 940b4ecf273..05f269c451e 100644 --- a/core/lib/types/src/circuit.rs +++ b/core/lib/types/src/circuit.rs @@ -1,5 +1,4 @@ -use zkevm_test_harness::geometry_config::get_geometry_config; -use zkevm_test_harness::toolset::GeometryConfig; +use zkevm_test_harness::{geometry_config::get_geometry_config, toolset::GeometryConfig}; pub const LEAF_SPLITTING_FACTOR: usize = 50; pub const NODE_SPLITTING_FACTOR: usize = 48; diff --git a/core/lib/types/src/commitment.rs b/core/lib/types/src/commitment.rs index 7925a37d92f..a0e3039a59a 100644 --- a/core/lib/types/src/commitment.rs +++ b/core/lib/types/src/commitment.rs @@ -6,15 +6,14 @@ //! required for the rollup to execute L1 batches, it's needed for the proof generation and the Ethereum //! transactions, thus the calculations are done separately and asynchronously. -use serde::{Deserialize, Serialize}; -use zksync_utils::u256_to_h256; - use std::{collections::HashMap, convert::TryFrom}; +use serde::{Deserialize, Serialize}; use zksync_mini_merkle_tree::MiniMerkleTree; use zksync_system_constants::{ L2_TO_L1_LOGS_TREE_ROOT_KEY, STATE_DIFF_HASH_KEY, ZKPORTER_IS_AVAILABLE, }; +use zksync_utils::u256_to_h256; use crate::{ block::L1BatchHeader, @@ -666,12 +665,15 @@ mod tests { use serde::{Deserialize, Serialize}; use serde_with::serde_as; - use crate::commitment::{ - L1BatchAuxiliaryOutput, L1BatchCommitment, L1BatchMetaParameters, L1BatchPassThroughData, + use crate::{ + commitment::{ + L1BatchAuxiliaryOutput, L1BatchCommitment, L1BatchMetaParameters, + L1BatchPassThroughData, + }, + l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}, + writes::{InitialStorageWrite, RepeatedStorageWrite}, + H256, U256, }; - use crate::l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log}; - use crate::writes::{InitialStorageWrite, RepeatedStorageWrite}; - use crate::{H256, U256}; #[serde_as] #[derive(Debug, Serialize, Deserialize)] diff --git a/core/lib/types/src/contract_verification_api.rs b/core/lib/types/src/contract_verification_api.rs index a7feb5116f2..02a5bef727d 100644 --- a/core/lib/types/src/contract_verification_api.rs +++ b/core/lib/types/src/contract_verification_api.rs @@ -6,9 +6,8 @@ use serde::{ Deserialize, Serialize, }; -use crate::{Address, Bytes}; - pub use crate::Execute as ExecuteData; +use crate::{Address, Bytes}; #[derive(Debug, Clone, Serialize)] #[serde(tag = "codeFormat", content = "sourceCode")] diff --git a/core/lib/types/src/eth_sender.rs b/core/lib/types/src/eth_sender.rs index 847662eaeaa..6c8d268888e 100644 --- a/core/lib/types/src/eth_sender.rs +++ b/core/lib/types/src/eth_sender.rs @@ -1,5 +1,4 @@ -use crate::aggregated_operations::AggregatedActionType; -use crate::{Address, Nonce, H256}; +use crate::{aggregated_operations::AggregatedActionType, Address, Nonce, H256}; #[derive(Clone)] pub struct EthTx { diff --git a/core/lib/types/src/event.rs b/core/lib/types/src/event.rs index 285567c8911..01561912cce 100644 --- a/core/lib/types/src/event.rs +++ b/core/lib/types/src/event.rs @@ -1,3 +1,10 @@ +use std::fmt::Debug; + +use once_cell::sync::Lazy; +use serde::{Deserialize, Serialize}; +use zksync_basic_types::ethabi::Token; +use zksync_utils::{h256_to_account_address, u256_to_bytes_be, u256_to_h256}; + use crate::{ ethabi, l2_to_l1_log::L2ToL1Log, @@ -5,11 +12,6 @@ use crate::{ Address, L1BatchNumber, CONTRACT_DEPLOYER_ADDRESS, H256, KNOWN_CODES_STORAGE_ADDRESS, L1_MESSENGER_ADDRESS, U256, }; -use once_cell::sync::Lazy; -use serde::{Deserialize, Serialize}; -use std::fmt::Debug; -use zksync_basic_types::ethabi::Token; -use zksync_utils::{h256_to_account_address, u256_to_bytes_be, u256_to_h256}; #[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] pub struct VmEvent { @@ -348,13 +350,12 @@ mod tests { }; use zksync_utils::u256_to_h256; - use crate::VmEvent; - use super::{ extract_bytecode_publication_requests_from_l1_messenger, extract_l2tol1logs_from_l1_messenger, L1MessengerBytecodePublicationRequest, L1MessengerL2ToL1Log, }; + use crate::VmEvent; fn create_l2_to_l1_log_sent_value( tx_number: U256, diff --git a/core/lib/types/src/l1/mod.rs b/core/lib/types/src/l1/mod.rs index 75d7f71a883..16ce192bf8b 100644 --- a/core/lib/types/src/l1/mod.rs +++ b/core/lib/types/src/l1/mod.rs @@ -1,14 +1,15 @@ //! Definition of zkSync network priority operations: operations initiated from the L1. -use serde::{Deserialize, Serialize}; use std::convert::TryFrom; +use serde::{Deserialize, Serialize}; use zksync_basic_types::{ ethabi::{decode, ParamType, Token}, Address, L1BlockNumber, Log, PriorityOpId, H160, H256, U256, }; use zksync_utils::u256_to_account_address; +use super::Transaction; use crate::{ helpers::unix_timestamp_ms, l1::error::L1TxParseError, @@ -18,8 +19,6 @@ use crate::{ ExecuteTransactionCommon, PRIORITY_OPERATION_L2_TX_TYPE, PROTOCOL_UPGRADE_TX_TYPE, }; -use super::Transaction; - pub mod error; #[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Copy)] diff --git a/core/lib/types/src/l2/mod.rs b/core/lib/types/src/l2/mod.rs index 4c0632c5553..61a505909b2 100644 --- a/core/lib/types/src/l2/mod.rs +++ b/core/lib/types/src/l2/mod.rs @@ -2,26 +2,25 @@ use std::convert::TryFrom; use num_enum::TryFromPrimitive; use rlp::{Rlp, RlpStream}; +use serde::{Deserialize, Serialize}; use self::error::SignError; -use crate::transaction_request::PaymasterParams; -use crate::LEGACY_TX_TYPE; - use crate::{ - api, tx::primitives::PackedEthSignature, tx::Execute, web3::types::U64, Address, Bytes, - EIP712TypedStructure, Eip712Domain, ExecuteTransactionCommon, InputData, L2ChainId, Nonce, - StructBuilder, Transaction, EIP_1559_TX_TYPE, EIP_2930_TX_TYPE, EIP_712_TX_TYPE, H256, - PRIORITY_OPERATION_L2_TX_TYPE, PROTOCOL_UPGRADE_TX_TYPE, U256, + api, + api::TransactionRequest, + fee::{encoding_len, Fee}, + helpers::unix_timestamp_ms, + transaction_request::PaymasterParams, + tx::{primitives::PackedEthSignature, Execute}, + web3::types::U64, + Address, Bytes, EIP712TypedStructure, Eip712Domain, ExecuteTransactionCommon, InputData, + L2ChainId, Nonce, StructBuilder, Transaction, EIP_1559_TX_TYPE, EIP_2930_TX_TYPE, + EIP_712_TX_TYPE, H256, LEGACY_TX_TYPE, PRIORITY_OPERATION_L2_TX_TYPE, PROTOCOL_UPGRADE_TX_TYPE, + U256, }; -use serde::{Deserialize, Serialize}; - pub mod error; -use crate::api::TransactionRequest; -use crate::fee::{encoding_len, Fee}; -use crate::helpers::unix_timestamp_ms; - #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, TryFromPrimitive)] #[repr(u32)] pub enum TransactionType { @@ -463,13 +462,12 @@ impl EIP712TypedStructure for L2Tx { mod tests { use zksync_basic_types::{Nonce, U256}; + use super::{L2Tx, TransactionType}; use crate::{ api::TransactionRequest, fee::Fee, transaction_request::PaymasterParams, Execute, L2TxCommonData, }; - use super::{L2Tx, TransactionType}; - #[test] fn test_correct_l2_tx_transaction_request_conversion() { // It is a random valid signature diff --git a/core/lib/types/src/l2_to_l1_log.rs b/core/lib/types/src/l2_to_l1_log.rs index 670a2b22e81..335e6e740be 100644 --- a/core/lib/types/src/l2_to_l1_log.rs +++ b/core/lib/types/src/l2_to_l1_log.rs @@ -1,10 +1,10 @@ -use crate::commitment::SerializeCommitment; -use crate::{Address, H256}; use serde::{Deserialize, Serialize}; use zk_evm::reference_impls::event_sink::EventMessage; use zk_evm_1_4_0::reference_impls::event_sink::EventMessage as EventMessage_1_4_0; use zksync_utils::u256_to_h256; +use crate::{commitment::SerializeCommitment, Address, H256}; + #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, Eq)] pub struct L2ToL1Log { pub shard_id: u8, @@ -94,11 +94,12 @@ impl From for L2ToL1Log { #[cfg(test)] mod tests { - use super::L2ToL1Log; use zksync_basic_types::U256; use zksync_system_constants::L1_MESSENGER_ADDRESS; use zksync_utils::u256_to_h256; + use super::L2ToL1Log; + #[test] fn l2_to_l1_log_to_bytes() { let expected_log_bytes = [ diff --git a/core/lib/types/src/lib.rs b/core/lib/types/src/lib.rs index 4715a2f86da..4574824b37f 100644 --- a/core/lib/types/src/lib.rs +++ b/core/lib/types/src/lib.rs @@ -5,33 +5,32 @@ #![allow(clippy::upper_case_acronyms, clippy::derive_partial_eq_without_eq)] +use std::{fmt, fmt::Debug}; + use fee::encoding_len; use serde::{Deserialize, Serialize}; -use std::{fmt, fmt::Debug}; pub use crate::{Nonce, H256, U256, U64}; pub type SerialId = u64; -use crate::l2::TransactionType; -use crate::protocol_version::ProtocolUpgradeTxCommonData; pub use event::{VmEvent, VmEventGroupKey}; pub use l1::L1TxCommonData; pub use l2::L2TxCommonData; pub use protocol_version::{ProtocolUpgrade, ProtocolVersion, ProtocolVersionId}; pub use storage::*; -pub use tx::primitives::*; -pub use tx::Execute; +pub use tx::{primitives::*, Execute}; pub use vm_version::VmVersion; pub use zk_evm::{ aux_structures::{LogQuery, Timestamp}, reference_impls::event_sink::EventMessage, zkevm_opcode_defs::FarCallOpcode, }; - pub use zkevm_test_harness; pub use zksync_basic_types::*; +use crate::{l2::TransactionType, protocol_version::ProtocolUpgradeTxCommonData}; + pub mod aggregated_operations; pub mod block; pub mod circuit; diff --git a/core/lib/types/src/priority_op_onchain_data.rs b/core/lib/types/src/priority_op_onchain_data.rs index a729aa27bf4..559bb996388 100644 --- a/core/lib/types/src/priority_op_onchain_data.rs +++ b/core/lib/types/src/priority_op_onchain_data.rs @@ -1,7 +1,7 @@ -use serde::{Deserialize, Serialize}; - use std::cmp::Ordering; +use serde::{Deserialize, Serialize}; + use crate::{ l1::{OpProcessingType, PriorityQueueType}, H256, U256, diff --git a/core/lib/types/src/proofs.rs b/core/lib/types/src/proofs.rs index b28b81b79fb..0067552c829 100644 --- a/core/lib/types/src/proofs.rs +++ b/core/lib/types/src/proofs.rs @@ -1,25 +1,25 @@ -use std::convert::{TryFrom, TryInto}; -use std::fmt::Debug; -use std::net::IpAddr; -use std::ops::Add; -use std::str::FromStr; +use std::{ + convert::{TryFrom, TryInto}, + fmt::Debug, + net::IpAddr, + ops::Add, + str::FromStr, +}; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, Bytes}; -use zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit; -use zkevm_test_harness::bellman::bn256::Bn256; -use zkevm_test_harness::bellman::plonk::better_better_cs::proof::Proof; -use zkevm_test_harness::encodings::{recursion_request::RecursionRequest, QueueSimulator}; -use zkevm_test_harness::witness::full_block_artifact::{ - BlockBasicCircuits, BlockBasicCircuitsPublicInputs, -}; -use zkevm_test_harness::witness::oracle::VmWitnessOracle; use zkevm_test_harness::{ + abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, + bellman::{bn256::Bn256, plonk::better_better_cs::proof::Proof}, + encodings::{recursion_request::RecursionRequest, QueueSimulator}, + witness::{ + full_block_artifact::{BlockBasicCircuits, BlockBasicCircuitsPublicInputs}, + oracle::VmWitnessOracle, + }, LeafAggregationOutputDataWitness, NodeAggregationOutputDataWitness, SchedulerCircuitInstanceWitness, }; - use zksync_basic_types::{L1BatchNumber, H256, U256}; const HASH_LEN: usize = H256::len_bytes(); diff --git a/core/lib/types/src/protocol_version.rs b/core/lib/types/src/protocol_version.rs index 09a722c72cd..b855cb92fdf 100644 --- a/core/lib/types/src/protocol_version.rs +++ b/core/lib/types/src/protocol_version.rs @@ -1,3 +1,10 @@ +use std::convert::{TryFrom, TryInto}; + +use num_enum::TryFromPrimitive; +use serde::{Deserialize, Serialize}; +use zksync_contracts::BaseSystemContractsHashes; +use zksync_utils::u256_to_account_address; + use crate::{ ethabi::{decode, encode, ParamType, Token}, helpers::unix_timestamp_ms, @@ -8,11 +15,6 @@ use crate::{ Address, Execute, ExecuteTransactionCommon, Log, Transaction, TransactionType, VmVersion, H256, PROTOCOL_UPGRADE_TX_TYPE, U256, }; -use num_enum::TryFromPrimitive; -use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; -use zksync_contracts::BaseSystemContractsHashes; -use zksync_utils::u256_to_account_address; #[repr(u16)] #[derive( diff --git a/core/lib/types/src/prover_server_api/mod.rs b/core/lib/types/src/prover_server_api/mod.rs index dc226f11d26..fdbbd57624f 100644 --- a/core/lib/types/src/prover_server_api/mod.rs +++ b/core/lib/types/src/prover_server_api/mod.rs @@ -1,10 +1,11 @@ use serde::{Deserialize, Serialize}; - use zksync_basic_types::L1BatchNumber; -use crate::aggregated_operations::L1BatchProofForL1; -use crate::proofs::PrepareBasicCircuitsJob; -use crate::protocol_version::{FriProtocolVersionId, L1VerifierConfig}; +use crate::{ + aggregated_operations::L1BatchProofForL1, + proofs::PrepareBasicCircuitsJob, + protocol_version::{FriProtocolVersionId, L1VerifierConfig}, +}; #[derive(Debug, Serialize, Deserialize)] pub struct ProofGenerationData { diff --git a/core/lib/types/src/storage/log.rs b/core/lib/types/src/storage/log.rs index aa295a2bade..11756f7175a 100644 --- a/core/lib/types/src/storage/log.rs +++ b/core/lib/types/src/storage/log.rs @@ -1,7 +1,6 @@ -use serde::{Deserialize, Serialize}; - use std::mem; +use serde::{Deserialize, Serialize}; use zk_evm::aux_structures::{LogQuery, Timestamp}; use zksync_basic_types::AccountTreeId; use zksync_utils::u256_to_h256; diff --git a/core/lib/types/src/storage/witness_block_state.rs b/core/lib/types/src/storage/witness_block_state.rs index 2ba57a9aea0..63ee1ba1c56 100644 --- a/core/lib/types/src/storage/witness_block_state.rs +++ b/core/lib/types/src/storage/witness_block_state.rs @@ -1,7 +1,9 @@ -use crate::{StorageKey, StorageValue}; -use serde::{Deserialize, Serialize}; use std::collections::HashMap; +use serde::{Deserialize, Serialize}; + +use crate::{StorageKey, StorageValue}; + /// Storage data used during Witness Generation. #[derive(Debug, Default, Serialize, Deserialize)] pub struct WitnessBlockState { diff --git a/core/lib/types/src/storage/writes/compression.rs b/core/lib/types/src/storage/writes/compression.rs index a325801b8a8..cd0a174fa76 100644 --- a/core/lib/types/src/storage/writes/compression.rs +++ b/core/lib/types/src/storage/writes/compression.rs @@ -210,9 +210,10 @@ pub fn compress_with_best_strategy(prev_value: U256, new_value: U256) -> Vec #[cfg(test)] mod tests { - use super::*; use std::ops::{Add, BitAnd, Shr, Sub}; + use super::*; + #[test] fn test_compress_addition() { let initial_val = U256::from(255438218); diff --git a/core/lib/types/src/storage/writes/mod.rs b/core/lib/types/src/storage/writes/mod.rs index 54393f41785..22400964bf4 100644 --- a/core/lib/types/src/storage/writes/mod.rs +++ b/core/lib/types/src/storage/writes/mod.rs @@ -1,10 +1,10 @@ use std::convert::TryInto; -use crate::H256; use serde::{Deserialize, Serialize}; use zksync_basic_types::{Address, U256}; pub(crate) use self::compression::{compress_with_best_strategy, COMPRESSION_VERSION_NUMBER}; +use crate::H256; pub mod compression; @@ -184,12 +184,13 @@ fn prepend_header(compressed_state_diffs: Vec) -> Vec { #[cfg(test)] mod tests { - use std::ops::{Add, Sub}; - use std::str::FromStr; + use std::{ + ops::{Add, Sub}, + str::FromStr, + }; use super::*; - use crate::commitment::serialize_commitments; - use crate::{H256, U256}; + use crate::{commitment::serialize_commitments, H256, U256}; #[test] fn calculate_hash_for_storage_writes() { diff --git a/core/lib/types/src/storage_writes_deduplicator.rs b/core/lib/types/src/storage_writes_deduplicator.rs index 42ce67e6375..14a5413ee6a 100644 --- a/core/lib/types/src/storage_writes_deduplicator.rs +++ b/core/lib/types/src/storage_writes_deduplicator.rs @@ -2,9 +2,11 @@ use std::collections::HashMap; use zksync_utils::u256_to_h256; -use crate::tx::tx_execution_info::DeduplicatedWritesMetrics; -use crate::writes::compression::compress_with_best_strategy; -use crate::{AccountTreeId, StorageKey, StorageLogQuery, StorageLogQueryType, U256}; +use crate::{ + tx::tx_execution_info::DeduplicatedWritesMetrics, + writes::compression::compress_with_best_strategy, AccountTreeId, StorageKey, StorageLogQuery, + StorageLogQueryType, U256, +}; #[derive(Debug, Clone, Copy, PartialEq, Default)] pub struct ModifiedSlot { @@ -219,9 +221,8 @@ impl StorageWritesDeduplicator { mod tests { use zk_evm::aux_structures::{LogQuery, Timestamp}; - use crate::H160; - use super::*; + use crate::H160; fn storage_log_query( key: U256, diff --git a/core/lib/types/src/system_contracts.rs b/core/lib/types/src/system_contracts.rs index 430d8d4701d..7e896b83bc2 100644 --- a/core/lib/types/src/system_contracts.rs +++ b/core/lib/types/src/system_contracts.rs @@ -1,5 +1,6 @@ use std::path::PathBuf; +use once_cell::sync::Lazy; use zksync_basic_types::{AccountTreeId, Address, U256}; use zksync_contracts::{read_sys_contract_bytecode, ContractLanguage, SystemContractsRepo}; use zksync_system_constants::{ @@ -13,7 +14,6 @@ use crate::{ L1_MESSENGER_ADDRESS, L2_ETH_TOKEN_ADDRESS, MSG_VALUE_SIMULATOR_ADDRESS, NONCE_HOLDER_ADDRESS, SHA256_PRECOMPILE_ADDRESS, SYSTEM_CONTEXT_ADDRESS, }; -use once_cell::sync::Lazy; // Note, that in the NONCE_HOLDER_ADDRESS's storage the nonces of accounts // are stored in the following form: diff --git a/core/lib/types/src/transaction_request.rs b/core/lib/types/src/transaction_request.rs index 85194902e32..e66c2495afe 100644 --- a/core/lib/types/src/transaction_request.rs +++ b/core/lib/types/src/transaction_request.rs @@ -1,17 +1,15 @@ -// Built-in uses use std::convert::{TryFrom, TryInto}; -// External uses use rlp::{DecoderError, Rlp, RlpStream}; use serde::{Deserialize, Serialize}; use thiserror::Error; use zksync_basic_types::H256; - use zksync_system_constants::{MAX_GAS_PER_PUBDATA_BYTE, USED_BOOTLOADER_MEMORY_BYTES}; -use zksync_utils::bytecode::{hash_bytecode, validate_bytecode, InvalidBytecodeError}; -use zksync_utils::{concat_and_hash, u256_to_h256}; +use zksync_utils::{ + bytecode::{hash_bytecode, validate_bytecode, InvalidBytecodeError}, + concat_and_hash, u256_to_h256, +}; -// Local uses use super::{EIP_1559_TX_TYPE, EIP_2930_TX_TYPE, EIP_712_TX_TYPE}; use crate::{ fee::Fee, @@ -947,13 +945,14 @@ pub fn validate_factory_deps( #[cfg(test)] mod tests { + use secp256k1::SecretKey; + use super::*; use crate::web3::{ api::Namespace, transports::test::TestTransport, types::{TransactionParameters, H256, U256}, }; - use secp256k1::SecretKey; #[tokio::test] async fn decode_real_tx() { diff --git a/core/lib/types/src/tx/execute.rs b/core/lib/types/src/tx/execute.rs index e33dff694fe..50340230cb9 100644 --- a/core/lib/types/src/tx/execute.rs +++ b/core/lib/types/src/tx/execute.rs @@ -1,8 +1,9 @@ -use crate::{web3::ethabi, Address, EIP712TypedStructure, StructBuilder, H256, U256}; use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use zksync_utils::ZeroPrefixHexSerde; +use crate::{web3::ethabi, Address, EIP712TypedStructure, StructBuilder, H256, U256}; + /// `Execute` transaction executes a previously deployed smart contract in the L2 rollup. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[serde(rename_all = "camelCase")] diff --git a/core/lib/types/src/tx/mod.rs b/core/lib/types/src/tx/mod.rs index 71f188f3217..1371fa74ee7 100644 --- a/core/lib/types/src/tx/mod.rs +++ b/core/lib/types/src/tx/mod.rs @@ -5,19 +5,18 @@ //! with metadata (such as fees and/or signatures) for L1 and L2 separately. use std::fmt::Debug; + use zksync_basic_types::{Address, H256}; use zksync_utils::bytecode::CompressedBytecodeInfo; +use self::tx_execution_info::TxExecutionStatus; +pub use self::{execute::Execute, tx_execution_info::ExecutionMetrics}; +use crate::{vm_trace::Call, Transaction}; + pub mod execute; pub mod primitives; pub mod tx_execution_info; -pub use self::execute::Execute; -use crate::vm_trace::Call; -use crate::Transaction; -pub use tx_execution_info::ExecutionMetrics; -use tx_execution_info::TxExecutionStatus; - #[derive(Debug, Clone, PartialEq)] pub struct TransactionExecutionResult { pub transaction: Transaction, diff --git a/core/lib/types/src/tx/primitives/eip712_signature/member_types.rs b/core/lib/types/src/tx/primitives/eip712_signature/member_types.rs index cc4906ef7e8..aecece572dd 100644 --- a/core/lib/types/src/tx/primitives/eip712_signature/member_types.rs +++ b/core/lib/types/src/tx/primitives/eip712_signature/member_types.rs @@ -1,9 +1,10 @@ -use crate::tx::primitives::eip712_signature::typed_structure::{ - EncodedStructureMember, StructMember, -}; -use crate::web3::signing::keccak256; use zksync_basic_types::{Address, H256, U256}; +use crate::{ + tx::primitives::eip712_signature::typed_structure::{EncodedStructureMember, StructMember}, + web3::signing::keccak256, +}; + impl StructMember for String { const MEMBER_TYPE: &'static str = "string"; const IS_REFERENCE_TYPE: bool = false; diff --git a/core/lib/types/src/tx/primitives/eip712_signature/struct_builder.rs b/core/lib/types/src/tx/primitives/eip712_signature/struct_builder.rs index f6189f504df..2093042b9f7 100644 --- a/core/lib/types/src/tx/primitives/eip712_signature/struct_builder.rs +++ b/core/lib/types/src/tx/primitives/eip712_signature/struct_builder.rs @@ -1,5 +1,6 @@ -use serde_json::Value; use std::collections::{BTreeMap, VecDeque}; + +use serde_json::Value; use zksync_basic_types::H256; use crate::tx::primitives::eip712_signature::typed_structure::{ diff --git a/core/lib/types/src/tx/primitives/eip712_signature/tests.rs b/core/lib/types/src/tx/primitives/eip712_signature/tests.rs index 70ae415531c..8bfd14b45c4 100644 --- a/core/lib/types/src/tx/primitives/eip712_signature/tests.rs +++ b/core/lib/types/src/tx/primitives/eip712_signature/tests.rs @@ -1,13 +1,20 @@ -use crate::tx::primitives::eip712_signature::{ - struct_builder::StructBuilder, - typed_structure::{EIP712TypedStructure, Eip712Domain}, -}; -use crate::tx::primitives::{eip712_signature::utils::get_eip712_json, PackedEthSignature}; -use crate::web3::signing::keccak256; -use serde::Serialize; use std::str::FromStr; + +use serde::Serialize; use zksync_basic_types::{Address, H256, U256}; +use crate::{ + tx::primitives::{ + eip712_signature::{ + struct_builder::StructBuilder, + typed_structure::{EIP712TypedStructure, Eip712Domain}, + utils::get_eip712_json, + }, + PackedEthSignature, + }, + web3::signing::keccak256, +}; + #[derive(Clone, Serialize)] struct Person { name: String, diff --git a/core/lib/types/src/tx/primitives/eip712_signature/typed_structure.rs b/core/lib/types/src/tx/primitives/eip712_signature/typed_structure.rs index 28e9d27f0a6..daf1c9698ee 100644 --- a/core/lib/types/src/tx/primitives/eip712_signature/typed_structure.rs +++ b/core/lib/types/src/tx/primitives/eip712_signature/typed_structure.rs @@ -1,11 +1,11 @@ -use crate::web3::signing::keccak256; use serde::{Deserialize, Serialize}; use serde_json::Value; -use crate::tx::primitives::eip712_signature::struct_builder::{ - EncodeBuilder, StructBuilder, TypeBuilder, +use crate::{ + tx::primitives::eip712_signature::struct_builder::{EncodeBuilder, StructBuilder, TypeBuilder}, + web3::signing::keccak256, + L2ChainId, H256, U256, }; -use crate::{L2ChainId, H256, U256}; #[derive(Debug, Clone)] pub struct EncodedStructureMember { diff --git a/core/lib/types/src/tx/primitives/eip712_signature/utils.rs b/core/lib/types/src/tx/primitives/eip712_signature/utils.rs index 57db7894321..f338c017e2b 100644 --- a/core/lib/types/src/tx/primitives/eip712_signature/utils.rs +++ b/core/lib/types/src/tx/primitives/eip712_signature/utils.rs @@ -1,7 +1,8 @@ +use serde_json::{Map, Value}; + use crate::tx::primitives::eip712_signature::typed_structure::{ EIP712TypedStructure, Eip712Domain, }; -use serde_json::{Map, Value}; /// Formats the data that needs to be signed in json according to the standard eip-712. /// Compatible with `eth_signTypedData` RPC call. diff --git a/core/lib/types/src/tx/primitives/packed_eth_signature.rs b/core/lib/types/src/tx/primitives/packed_eth_signature.rs index 32564829ad8..c165f6a36b2 100644 --- a/core/lib/types/src/tx/primitives/packed_eth_signature.rs +++ b/core/lib/types/src/tx/primitives/packed_eth_signature.rs @@ -1,6 +1,3 @@ -use crate::tx::primitives::eip712_signature::typed_structure::{ - EIP712TypedStructure, Eip712Domain, -}; use ethereum_types_old::H256 as ParityCryptoH256; use parity_crypto::{ publickey::{ @@ -14,6 +11,10 @@ use thiserror::Error; use zksync_basic_types::{Address, H256}; use zksync_utils::ZeroPrefixHexSerde; +use crate::tx::primitives::eip712_signature::typed_structure::{ + EIP712TypedStructure, Eip712Domain, +}; + /// Struct used for working with Ethereum signatures created using eth_sign (using geth, ethers.js, etc) /// message is serialized as 65 bytes long `0x` prefixed string. /// diff --git a/core/lib/types/src/tx/tx_execution_info.rs b/core/lib/types/src/tx/tx_execution_info.rs index 0f72172f529..d19757ee970 100644 --- a/core/lib/types/src/tx/tx_execution_info.rs +++ b/core/lib/types/src/tx/tx_execution_info.rs @@ -1,14 +1,15 @@ -use crate::fee::TransactionExecutionMetrics; -use crate::l2_to_l1_log::L2ToL1Log; +use std::ops::{Add, AddAssign}; + use crate::{ commitment::SerializeCommitment, + fee::TransactionExecutionMetrics, + l2_to_l1_log::L2ToL1Log, writes::{ InitialStorageWrite, RepeatedStorageWrite, BYTES_PER_DERIVED_KEY, BYTES_PER_ENUMERATION_INDEX, }, ProtocolVersionId, }; -use std::ops::{Add, AddAssign}; #[derive(Debug, Clone, Copy, Eq, PartialEq)] pub enum TxExecutionStatus { diff --git a/core/lib/types/src/utils.rs b/core/lib/types/src/utils.rs index 617179c4936..7828f2d1262 100644 --- a/core/lib/types/src/utils.rs +++ b/core/lib/types/src/utils.rs @@ -1,11 +1,11 @@ -use crate::system_contracts::DEPLOYMENT_NONCE_INCREMENT; -use crate::L2_ETH_TOKEN_ADDRESS; -use crate::{web3::signing::keccak256, AccountTreeId, StorageKey, U256}; - use zksync_basic_types::{Address, H256}; - use zksync_utils::{address_to_h256, u256_to_h256}; +use crate::{ + system_contracts::DEPLOYMENT_NONCE_INCREMENT, web3::signing::keccak256, AccountTreeId, + StorageKey, L2_ETH_TOKEN_ADDRESS, U256, +}; + /// Transforms the *full* account nonce into an *account* nonce. /// Full nonce is a composite one: it includes both account nonce (number of transactions /// initiated by the account) and deployer nonce (number of smart contracts deployed by the @@ -79,10 +79,11 @@ pub fn deployed_address_create(sender: Address, deploy_nonce: U256) -> Address { #[cfg(test)] mod tests { + use std::str::FromStr; + use crate::{ utils::storage_key_for_standard_token_balance, AccountTreeId, Address, StorageKey, H256, }; - use std::str::FromStr; #[test] fn test_storage_key_for_eth_token() { diff --git a/core/lib/types/src/vk_transform.rs b/core/lib/types/src/vk_transform.rs index dfa022fb7c1..b19fdaef692 100644 --- a/core/lib/types/src/vk_transform.rs +++ b/core/lib/types/src/vk_transform.rs @@ -1,5 +1,5 @@ -use crate::{ethabi::Token, H256}; use std::str::FromStr; + use zkevm_test_harness::{ abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, bellman::{ @@ -14,6 +14,8 @@ use zkevm_test_harness::{ }, }; +use crate::{ethabi::Token, H256}; + /// Calculates commitment for vk from L1 verifier contract. pub fn l1_vk_commitment(token: Token) -> H256 { let vk = vk_from_token(token); diff --git a/core/lib/types/src/vm_trace.rs b/core/lib/types/src/vm_trace.rs index 6b37848dc5a..d3a94d51fa5 100644 --- a/core/lib/types/src/vm_trace.rs +++ b/core/lib/types/src/vm_trace.rs @@ -1,12 +1,16 @@ -use crate::{Address, U256}; +use std::{ + collections::{HashMap, HashSet}, + fmt, + fmt::Display, +}; + use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use std::collections::{HashMap, HashSet}; -use std::fmt; -use std::fmt::Display; use zk_evm::zkevm_opcode_defs::FarCallOpcode; use zksync_system_constants::BOOTLOADER_ADDRESS; use zksync_utils::u256_to_h256; +use crate::{Address, U256}; + #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub enum VmTrace { ExecutionTrace(VmExecutionTrace), diff --git a/core/lib/utils/src/bytecode.rs b/core/lib/utils/src/bytecode.rs index 4a9d1cd2475..c533642d240 100644 --- a/core/lib/utils/src/bytecode.rs +++ b/core/lib/utils/src/bytecode.rs @@ -1,8 +1,10 @@ +use std::{collections::HashMap, convert::TryInto}; + use itertools::Itertools; -use std::collections::HashMap; -use std::convert::TryInto; -use zksync_basic_types::ethabi::{encode, Token}; -use zksync_basic_types::H256; +use zksync_basic_types::{ + ethabi::{encode, Token}, + H256, +}; use crate::bytes_to_chunks; diff --git a/core/lib/utils/src/convert.rs b/core/lib/utils/src/convert.rs index 973b28cc613..cc4699448e6 100644 --- a/core/lib/utils/src/convert.rs +++ b/core/lib/utils/src/convert.rs @@ -1,3 +1,5 @@ +use std::convert::TryInto; + use bigdecimal::BigDecimal; use num::{ bigint::ToBigInt, @@ -5,7 +7,6 @@ use num::{ traits::{sign::Signed, Pow}, BigUint, }; -use std::convert::TryInto; use zksync_basic_types::{Address, H256, U256}; pub fn u256_to_big_decimal(value: U256) -> BigDecimal { @@ -170,10 +171,12 @@ pub fn u256_to_bytes_be(value: &U256) -> Vec { #[cfg(test)] mod test { - use super::*; - use num::BigInt; use std::str::FromStr; + use num::BigInt; + + use super::*; + #[test] fn test_ratio_to_big_decimal() { let ratio = Ratio::from_integer(BigUint::from(0u32)); diff --git a/core/lib/utils/src/http_with_retries.rs b/core/lib/utils/src/http_with_retries.rs index 61742769fd6..15973ee6b2a 100644 --- a/core/lib/utils/src/http_with_retries.rs +++ b/core/lib/utils/src/http_with_retries.rs @@ -1,5 +1,4 @@ -use reqwest::header::HeaderMap; -use reqwest::{Client, Error, Method, Response}; +use reqwest::{header::HeaderMap, Client, Error, Method, Response}; use tokio::time::{sleep, Duration}; #[derive(Debug)] diff --git a/core/lib/utils/src/misc.rs b/core/lib/utils/src/misc.rs index 468e953f83b..887413a6f45 100644 --- a/core/lib/utils/src/misc.rs +++ b/core/lib/utils/src/misc.rs @@ -1,5 +1,4 @@ -use zksync_basic_types::web3::signing::keccak256; -use zksync_basic_types::{H256, U256}; +use zksync_basic_types::{web3::signing::keccak256, H256, U256}; pub const fn ceil_div(a: u64, b: u64) -> u64 { if a == 0 { diff --git a/core/lib/vlog/src/lib.rs b/core/lib/vlog/src/lib.rs index 2c6702ede96..1ea573148c4 100644 --- a/core/lib/vlog/src/lib.rs +++ b/core/lib/vlog/src/lib.rs @@ -1,18 +1,14 @@ //! This module contains the observability subsystem. //! It is responsible for providing a centralized interface for consistent observability configuration. -use std::backtrace::Backtrace; -use std::borrow::Cow; -use std::panic::PanicInfo; +use std::{backtrace::Backtrace, borrow::Cow, panic::PanicInfo}; +// Temporary re-export of `sentry::capture_message` aiming to simplify the transition from `vlog` to using +// crates directly. +pub use sentry::{capture_message, Level as AlertLevel}; use sentry::{types::Dsn, ClientInitGuard}; use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt}; -/// Temporary re-export of `sentry::capture_message` aiming to simplify the transition from `vlog` to using -/// crates directly. -pub use sentry::capture_message; -pub use sentry::Level as AlertLevel; - /// Specifies the format of the logs in stdout. #[derive(Debug, Clone, Copy, Default)] pub enum LogFormat { diff --git a/core/lib/web3_decl/src/namespaces/debug.rs b/core/lib/web3_decl/src/namespaces/debug.rs index 7db44f27527..02e75e946b7 100644 --- a/core/lib/web3_decl/src/namespaces/debug.rs +++ b/core/lib/web3_decl/src/namespaces/debug.rs @@ -1,8 +1,10 @@ -use crate::types::H256; use jsonrpsee::{core::RpcResult, proc_macros::rpc}; +use zksync_types::{ + api::{BlockId, BlockNumber, DebugCall, ResultDebugCall, TracerConfig}, + transaction_request::CallRequest, +}; -use zksync_types::api::{BlockId, BlockNumber, DebugCall, ResultDebugCall, TracerConfig}; -use zksync_types::transaction_request::CallRequest; +use crate::types::H256; #[cfg_attr( all(feature = "client", feature = "server"), diff --git a/core/lib/web3_decl/src/namespaces/eth.rs b/core/lib/web3_decl/src/namespaces/eth.rs index f92f2a56239..861478bf4bf 100644 --- a/core/lib/web3_decl/src/namespaces/eth.rs +++ b/core/lib/web3_decl/src/namespaces/eth.rs @@ -1,20 +1,14 @@ -// External uses use jsonrpsee::{core::RpcResult, proc_macros::rpc}; - -// Workspace uses -use crate::types::{ - Block, Bytes, FeeHistory, Filter, FilterChanges, Index, Log, SyncState, TransactionReceipt, - U256, U64, -}; - use zksync_types::{ - api::Transaction, - api::{BlockIdVariant, BlockNumber, TransactionVariant}, + api::{BlockIdVariant, BlockNumber, Transaction, TransactionVariant}, transaction_request::CallRequest, Address, H256, }; -// Local uses +use crate::types::{ + Block, Bytes, FeeHistory, Filter, FilterChanges, Index, Log, SyncState, TransactionReceipt, + U256, U64, +}; #[cfg_attr( all(feature = "client", feature = "server"), diff --git a/core/lib/web3_decl/src/namespaces/mod.rs b/core/lib/web3_decl/src/namespaces/mod.rs index 996cb27267c..26e610c1644 100644 --- a/core/lib/web3_decl/src/namespaces/mod.rs +++ b/core/lib/web3_decl/src/namespaces/mod.rs @@ -6,16 +6,13 @@ pub mod net; pub mod web3; pub mod zks; -// Server trait re-exports. -#[cfg(feature = "server")] -pub use self::{ - debug::DebugNamespaceServer, en::EnNamespaceServer, eth::EthNamespaceServer, - net::NetNamespaceServer, web3::Web3NamespaceServer, zks::ZksNamespaceServer, -}; - -// Client trait re-exports. #[cfg(feature = "client")] pub use self::{ debug::DebugNamespaceClient, en::EnNamespaceClient, eth::EthNamespaceClient, net::NetNamespaceClient, web3::Web3NamespaceClient, zks::ZksNamespaceClient, }; +#[cfg(feature = "server")] +pub use self::{ + debug::DebugNamespaceServer, en::EnNamespaceServer, eth::EthNamespaceServer, + net::NetNamespaceServer, web3::Web3NamespaceServer, zks::ZksNamespaceServer, +}; diff --git a/core/lib/web3_decl/src/namespaces/zks.rs b/core/lib/web3_decl/src/namespaces/zks.rs index d3bf43b9a97..e7ee1dffa9f 100644 --- a/core/lib/web3_decl/src/namespaces/zks.rs +++ b/core/lib/web3_decl/src/namespaces/zks.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use bigdecimal::BigDecimal; use jsonrpsee::{core::RpcResult, proc_macros::rpc}; - use zksync_types::{ api::{ BlockDetails, BridgeAddresses, L1BatchDetails, L2ToL1LogProof, Proof, ProtocolVersion, diff --git a/core/lib/web3_decl/src/types.rs b/core/lib/web3_decl/src/types.rs index 7abe34637d6..61a3e10397c 100644 --- a/core/lib/web3_decl/src/types.rs +++ b/core/lib/web3_decl/src/types.rs @@ -5,16 +5,15 @@ //! //! These "extensions" are required to provide more zkSync-specific information while remaining Web3-compilant. -use itertools::unfold; -use rlp::Rlp; -use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; - use core::{ convert::{TryFrom, TryInto}, fmt, marker::PhantomData, }; +use itertools::unfold; +use rlp::Rlp; +use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; pub use zksync_types::{ api::{Block, BlockNumber, Log, TransactionReceipt, TransactionRequest}, vm_trace::{ContractSourceDebugInfo, VmDebugTrace, VmExecutionStep}, @@ -350,9 +349,10 @@ pub enum PubSubResult { #[cfg(test)] mod tests { - use super::*; use zksync_types::api::{BlockId, BlockIdVariant}; + use super::*; + #[test] fn get_block_number_serde() { let test_vector = &[ diff --git a/core/lib/zksync_core/src/api_server/contract_verification/api_decl.rs b/core/lib/zksync_core/src/api_server/contract_verification/api_decl.rs index 5f9730d458e..553f6f2ad45 100644 --- a/core/lib/zksync_core/src/api_server/contract_verification/api_decl.rs +++ b/core/lib/zksync_core/src/api_server/contract_verification/api_decl.rs @@ -1,5 +1,4 @@ use actix_web::web; - use zksync_dal::connection::ConnectionPool; #[derive(Debug, Clone)] diff --git a/core/lib/zksync_core/src/api_server/contract_verification/api_impl.rs b/core/lib/zksync_core/src/api_server/contract_verification/api_impl.rs index d107483db01..81c9f7e264c 100644 --- a/core/lib/zksync_core/src/api_server/contract_verification/api_impl.rs +++ b/core/lib/zksync_core/src/api_server/contract_verification/api_impl.rs @@ -3,7 +3,6 @@ use actix_web::{ HttpResponse, Result as ActixResult, }; use serde::Serialize; - use zksync_types::{contract_verification_api::VerificationIncomingRequest, Address}; use super::{api_decl::RestApi, metrics::METRICS}; diff --git a/core/lib/zksync_core/src/api_server/contract_verification/metrics.rs b/core/lib/zksync_core/src/api_server/contract_verification/metrics.rs index 1e114f68ff6..4947e48b094 100644 --- a/core/lib/zksync_core/src/api_server/contract_verification/metrics.rs +++ b/core/lib/zksync_core/src/api_server/contract_verification/metrics.rs @@ -1,9 +1,9 @@ //! Metrics for contract verification. -use vise::{Buckets, Histogram, LabeledFamily, Metrics}; - use std::time::Duration; +use vise::{Buckets, Histogram, LabeledFamily, Metrics}; + #[derive(Debug, Metrics)] #[metrics(prefix = "api_contract_verification")] pub(super) struct ContractVerificationMetrics { diff --git a/core/lib/zksync_core/src/api_server/contract_verification/mod.rs b/core/lib/zksync_core/src/api_server/contract_verification/mod.rs index 5b59fafa917..a1bf980a49a 100644 --- a/core/lib/zksync_core/src/api_server/contract_verification/mod.rs +++ b/core/lib/zksync_core/src/api_server/contract_verification/mod.rs @@ -1,22 +1,18 @@ use std::{net::SocketAddr, time::Duration}; use actix_cors::Cors; -use actix_web::{ - dev::Server, - {web, App, HttpResponse, HttpServer}, -}; +use actix_web::{dev::Server, web, App, HttpResponse, HttpServer}; use tokio::{sync::watch, task::JoinHandle}; - use zksync_config::configs::api::ContractVerificationApiConfig; use zksync_dal::connection::ConnectionPool; use zksync_utils::panic_notify::{spawn_panic_handler, ThreadPanicNotify}; +use self::api_decl::RestApi; + mod api_decl; mod api_impl; mod metrics; -use self::api_decl::RestApi; - fn start_server(api: RestApi, bind_to: SocketAddr, threads: usize) -> Server { HttpServer::new(move || { let api = api.clone(); diff --git a/core/lib/zksync_core/src/api_server/execution_sandbox/apply.rs b/core/lib/zksync_core/src/api_server/execution_sandbox/apply.rs index 36ede77abdb..f0488f71190 100644 --- a/core/lib/zksync_core/src/api_server/execution_sandbox/apply.rs +++ b/core/lib/zksync_core/src/api_server/execution_sandbox/apply.rs @@ -8,11 +8,11 @@ use std::time::{Duration, Instant}; -use multivm::vm_latest::{constants::BLOCK_GAS_LIMIT, HistoryDisabled}; - -use multivm::interface::VmInterface; -use multivm::interface::{L1BatchEnv, L2BlockEnv, SystemEnv}; -use multivm::VmInstance; +use multivm::{ + interface::{L1BatchEnv, L2BlockEnv, SystemEnv, VmInterface}, + vm_latest::{constants::BLOCK_GAS_LIMIT, HistoryDisabled}, + VmInstance, +}; use zksync_dal::{ConnectionPool, SqlxError, StorageProcessor}; use zksync_state::{PostgresStorage, ReadStorage, StorageView, WriteStorage}; use zksync_system_constants::{ diff --git a/core/lib/zksync_core/src/api_server/execution_sandbox/error.rs b/core/lib/zksync_core/src/api_server/execution_sandbox/error.rs index 59e874ade90..c5928cfd847 100644 --- a/core/lib/zksync_core/src/api_server/execution_sandbox/error.rs +++ b/core/lib/zksync_core/src/api_server/execution_sandbox/error.rs @@ -1,6 +1,5 @@ -use thiserror::Error; - use multivm::interface::{Halt, TxRevertReason}; +use thiserror::Error; #[derive(Debug, Error)] pub(crate) enum SandboxExecutionError { diff --git a/core/lib/zksync_core/src/api_server/execution_sandbox/execute.rs b/core/lib/zksync_core/src/api_server/execution_sandbox/execute.rs index 9621adae2d8..c900dd4e5a5 100644 --- a/core/lib/zksync_core/src/api_server/execution_sandbox/execute.rs +++ b/core/lib/zksync_core/src/api_server/execution_sandbox/execute.rs @@ -1,13 +1,13 @@ //! Implementation of "executing" methods, e.g. `eth_call`. +use multivm::{ + interface::{TxExecutionMode, VmExecutionMode, VmExecutionResultAndLogs, VmInterface}, + tracers::StorageInvocations, + vm_latest::constants::ETH_CALL_GAS_LIMIT, + MultiVMTracer, +}; use tracing::{span, Level}; - -use multivm::interface::{TxExecutionMode, VmExecutionMode, VmExecutionResultAndLogs, VmInterface}; -use multivm::tracers::StorageInvocations; -use multivm::vm_latest::constants::ETH_CALL_GAS_LIMIT; -use multivm::MultiVMTracer; use zksync_dal::ConnectionPool; - use zksync_types::{ fee::TransactionExecutionMetrics, l2::L2Tx, ExecuteTransactionCommon, Nonce, PackedEthSignature, Transaction, U256, diff --git a/core/lib/zksync_core/src/api_server/execution_sandbox/mod.rs b/core/lib/zksync_core/src/api_server/execution_sandbox/mod.rs index 67feced9d5e..461be71c089 100644 --- a/core/lib/zksync_core/src/api_server/execution_sandbox/mod.rs +++ b/core/lib/zksync_core/src/api_server/execution_sandbox/mod.rs @@ -1,21 +1,13 @@ -use std::sync::Arc; -use std::time::Duration; -use tokio::runtime::Handle; +use std::{sync::Arc, time::Duration}; +use multivm::vm_latest::utils::fee::derive_base_fee_and_gas_per_pubdata; +use tokio::runtime::Handle; use zksync_dal::{ConnectionPool, SqlxError, StorageProcessor}; use zksync_state::{PostgresStorage, PostgresStorageCaches, ReadStorage, StorageView}; use zksync_system_constants::PUBLISH_BYTECODE_OVERHEAD; use zksync_types::{api, AccountTreeId, L2ChainId, MiniblockNumber, U256}; use zksync_utils::bytecode::{compress_bytecode, hash_bytecode}; -// Note: keep the modules private, and instead re-export functions that make public interface. -mod apply; -mod error; -mod execute; -mod tracers; -mod validate; -mod vm_metrics; - use self::vm_metrics::SandboxStage; pub(super) use self::{ error::SandboxExecutionError, @@ -24,7 +16,14 @@ pub(super) use self::{ vm_metrics::{SubmitTxStage, SANDBOX_METRICS}, }; use super::tx_sender::MultiVMBaseSystemContracts; -use multivm::vm_latest::utils::fee::derive_base_fee_and_gas_per_pubdata; + +// Note: keep the modules private, and instead re-export functions that make public interface. +mod apply; +mod error; +mod execute; +mod tracers; +mod validate; +mod vm_metrics; /// Permit to invoke VM code. /// diff --git a/core/lib/zksync_core/src/api_server/execution_sandbox/tracers.rs b/core/lib/zksync_core/src/api_server/execution_sandbox/tracers.rs index 9f987a150da..719f6da0b4a 100644 --- a/core/lib/zksync_core/src/api_server/execution_sandbox/tracers.rs +++ b/core/lib/zksync_core/src/api_server/execution_sandbox/tracers.rs @@ -1,9 +1,7 @@ -use multivm::tracers::CallTracer; -use multivm::vm_latest::HistoryMode; -use multivm::{MultiVMTracer, MultiVmTracerPointer}; -use once_cell::sync::OnceCell; - use std::sync::Arc; + +use multivm::{tracers::CallTracer, vm_latest::HistoryMode, MultiVMTracer, MultiVmTracerPointer}; +use once_cell::sync::OnceCell; use zksync_state::WriteStorage; use zksync_types::vm_trace::Call; diff --git a/core/lib/zksync_core/src/api_server/execution_sandbox/validate.rs b/core/lib/zksync_core/src/api_server/execution_sandbox/validate.rs index 4b9e13084ef..df70d02fe44 100644 --- a/core/lib/zksync_core/src/api_server/execution_sandbox/validate.rs +++ b/core/lib/zksync_core/src/api_server/execution_sandbox/validate.rs @@ -1,12 +1,14 @@ -use multivm::interface::{ExecutionResult, VmExecutionMode, VmInterface}; -use multivm::MultiVMTracer; use std::collections::HashSet; -use multivm::tracers::{ - validator::{ValidationError, ValidationTracer, ValidationTracerParams}, - StorageInvocations, +use multivm::{ + interface::{ExecutionResult, VmExecutionMode, VmInterface}, + tracers::{ + validator::{ValidationError, ValidationTracer, ValidationTracerParams}, + StorageInvocations, + }, + vm_latest::HistoryDisabled, + MultiVMTracer, }; -use multivm::vm_latest::HistoryDisabled; use zksync_dal::{ConnectionPool, StorageProcessor}; use zksync_types::{l2::L2Tx, Transaction, TRUSTED_ADDRESS_SLOTS, TRUSTED_TOKEN_SLOTS, U256}; diff --git a/core/lib/zksync_core/src/api_server/execution_sandbox/vm_metrics.rs b/core/lib/zksync_core/src/api_server/execution_sandbox/vm_metrics.rs index 138d06a3a7c..6842fe438f8 100644 --- a/core/lib/zksync_core/src/api_server/execution_sandbox/vm_metrics.rs +++ b/core/lib/zksync_core/src/api_server/execution_sandbox/vm_metrics.rs @@ -1,12 +1,13 @@ -use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics}; - use std::time::Duration; use multivm::interface::{VmExecutionResultAndLogs, VmMemoryMetrics}; +use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics}; use zksync_state::StorageViewMetrics; -use zksync_types::event::{extract_long_l2_to_l1_messages, extract_published_bytecodes}; -use zksync_types::fee::TransactionExecutionMetrics; -use zksync_types::storage_writes_deduplicator::StorageWritesDeduplicator; +use zksync_types::{ + event::{extract_long_l2_to_l1_messages, extract_published_bytecodes}, + fee::TransactionExecutionMetrics, + storage_writes_deduplicator::StorageWritesDeduplicator, +}; use zksync_utils::bytecode::bytecode_len_in_bytes; use crate::metrics::InteractionType; diff --git a/core/lib/zksync_core/src/api_server/healthcheck.rs b/core/lib/zksync_core/src/api_server/healthcheck.rs index 74495f3439c..58444c30dc9 100644 --- a/core/lib/zksync_core/src/api_server/healthcheck.rs +++ b/core/lib/zksync_core/src/api_server/healthcheck.rs @@ -1,8 +1,7 @@ -use axum::{extract::State, http::StatusCode, routing::get, Json, Router}; -use tokio::sync::watch; - use std::{collections::HashSet, net::SocketAddr, sync::Arc, time::Duration}; +use axum::{extract::State, http::StatusCode, routing::get, Json, Router}; +use tokio::sync::watch; use zksync_health_check::{AppHealth, CheckHealth}; type SharedHealthchecks = Arc<[Box]>; diff --git a/core/lib/zksync_core/src/api_server/tree/metrics.rs b/core/lib/zksync_core/src/api_server/tree/metrics.rs index e6b552468d8..d185861d07c 100644 --- a/core/lib/zksync_core/src/api_server/tree/metrics.rs +++ b/core/lib/zksync_core/src/api_server/tree/metrics.rs @@ -1,9 +1,9 @@ //! Metrics for the Merkle tree API. -use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics, Unit}; - use std::time::Duration; +use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics, Unit}; + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "method", rename_all = "snake_case")] pub(super) enum MerkleTreeApiMethod { diff --git a/core/lib/zksync_core/src/api_server/tree/mod.rs b/core/lib/zksync_core/src/api_server/tree/mod.rs index 7b4c9086ac6..00a5fd28554 100644 --- a/core/lib/zksync_core/src/api_server/tree/mod.rs +++ b/core/lib/zksync_core/src/api_server/tree/mod.rs @@ -1,5 +1,7 @@ //! Primitive Merkle tree API used internally to fetch proofs. +use std::{fmt, future::Future, net::SocketAddr, pin::Pin}; + use anyhow::Context as _; use async_trait::async_trait; use axum::{ @@ -10,19 +12,16 @@ use axum::{ }; use serde::{Deserialize, Serialize}; use tokio::sync::watch; - -use std::{fmt, future::Future, net::SocketAddr, pin::Pin}; - use zksync_merkle_tree::NoVersionError; use zksync_types::{L1BatchNumber, H256, U256}; +use self::metrics::{MerkleTreeApiMethod, API_METRICS}; +use crate::metadata_calculator::{AsyncTreeReader, MerkleTreeInfo}; + mod metrics; #[cfg(test)] mod tests; -use self::metrics::{MerkleTreeApiMethod, API_METRICS}; -use crate::metadata_calculator::{AsyncTreeReader, MerkleTreeInfo}; - #[derive(Debug, Serialize, Deserialize)] struct TreeProofsRequest { l1_batch_number: L1BatchNumber, diff --git a/core/lib/zksync_core/src/api_server/tree/tests.rs b/core/lib/zksync_core/src/api_server/tree/tests.rs index 2f90b9fabdf..11161805633 100644 --- a/core/lib/zksync_core/src/api_server/tree/tests.rs +++ b/core/lib/zksync_core/src/api_server/tree/tests.rs @@ -1,9 +1,8 @@ //! Tests for the Merkle tree API. -use tempfile::TempDir; - use std::net::Ipv4Addr; +use tempfile::TempDir; use zksync_dal::ConnectionPool; use super::*; 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 12c73800415..3766c8a4ee1 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 @@ -1,27 +1,23 @@ //! Helper module to submit transactions into the zkSync Network. -// External uses +use std::{cmp, num::NonZeroU32, sync::Arc, time::Instant}; + use governor::{ clock::MonotonicClock, middleware::NoOpMiddleware, state::{InMemoryState, NotKeyed}, Quota, RateLimiter, }; - -// Built-in uses -use std::{cmp, num::NonZeroU32, sync::Arc, time::Instant}; - -// Workspace uses - -use multivm::interface::VmExecutionResultAndLogs; -use multivm::vm_latest::{ - constants::{BLOCK_GAS_LIMIT, MAX_PUBDATA_PER_BLOCK}, - utils::{ - fee::derive_base_fee_and_gas_per_pubdata, - overhead::{derive_overhead, OverheadCoefficients}, +use multivm::{ + interface::VmExecutionResultAndLogs, + vm_latest::{ + constants::{BLOCK_GAS_LIMIT, MAX_PUBDATA_PER_BLOCK}, + utils::{ + fee::derive_base_fee_and_gas_per_pubdata, + overhead::{derive_overhead, OverheadCoefficients}, + }, }, }; - use zksync_config::configs::{api::Web3JsonRpcConfig, chain::StateKeeperConfig}; use zksync_contracts::BaseSystemContracts; use zksync_dal::{transactions_dal::L2TxSubmissionResult, ConnectionPool}; @@ -29,26 +25,24 @@ use zksync_state::PostgresStorageCaches; use zksync_types::{ fee::{Fee, TransactionExecutionMetrics}, get_code_key, get_intrinsic_constants, - l2::error::TxCheckError::TxDuplication, - l2::L2Tx, + l2::{error::TxCheckError::TxDuplication, L2Tx}, utils::storage_key_for_eth_balance, AccountTreeId, Address, ExecuteTransactionCommon, L2ChainId, Nonce, PackedEthSignature, ProtocolVersionId, Transaction, H160, H256, MAX_GAS_PER_PUBDATA_BYTE, MAX_L2_TX_GAS_LIMIT, MAX_NEW_FACTORY_DEPS, U256, }; - use zksync_utils::h256_to_u256; -// Local uses -use crate::api_server::{ - execution_sandbox::{ - adjust_l1_gas_price_for_tx, execute_tx_eth_call, execute_tx_with_pending_state, - get_pubdata_for_factory_deps, BlockArgs, SubmitTxStage, TxExecutionArgs, TxSharedArgs, - VmConcurrencyLimiter, VmPermit, SANDBOX_METRICS, - }, - tx_sender::result::ApiCallResult, -}; +pub(super) use self::{proxy::TxProxy, result::SubmitTxError}; use crate::{ + api_server::{ + execution_sandbox::{ + adjust_l1_gas_price_for_tx, execute_tx_eth_call, execute_tx_with_pending_state, + get_pubdata_for_factory_deps, BlockArgs, SubmitTxStage, TxExecutionArgs, TxSharedArgs, + VmConcurrencyLimiter, VmPermit, SANDBOX_METRICS, + }, + tx_sender::result::ApiCallResult, + }, l1_gas_price::L1GasPriceProvider, metrics::{TxStage, APP_METRICS}, state_keeper::seal_criteria::{ConditionalSealer, SealData}, @@ -57,8 +51,6 @@ use crate::{ mod proxy; mod result; -pub(super) use self::{proxy::TxProxy, result::SubmitTxError}; - /// Type alias for the rate limiter implementation. type TxSenderRateLimiter = RateLimiter>; diff --git a/core/lib/zksync_core/src/api_server/tx_sender/proxy.rs b/core/lib/zksync_core/src/api_server/tx_sender/proxy.rs index 4f70b1d5e50..7a4b928a809 100644 --- a/core/lib/zksync_core/src/api_server/tx_sender/proxy.rs +++ b/core/lib/zksync_core/src/api_server/tx_sender/proxy.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use tokio::sync::RwLock; +use tokio::sync::RwLock; use zksync_types::{ api::{BlockId, Transaction, TransactionDetails, TransactionId, TransactionReceipt}, l2::L2Tx, diff --git a/core/lib/zksync_core/src/api_server/tx_sender/result.rs b/core/lib/zksync_core/src/api_server/tx_sender/result.rs index b02049f014e..5b5af7b9cac 100644 --- a/core/lib/zksync_core/src/api_server/tx_sender/result.rs +++ b/core/lib/zksync_core/src/api_server/tx_sender/result.rs @@ -1,10 +1,11 @@ -use crate::api_server::execution_sandbox::SandboxExecutionError; +use multivm::{ + interface::{ExecutionResult, VmExecutionResultAndLogs}, + tracers::validator::ValidationError, +}; use thiserror::Error; +use zksync_types::{l2::error::TxCheckError, U256}; -use multivm::interface::{ExecutionResult, VmExecutionResultAndLogs}; -use multivm::tracers::validator::ValidationError; -use zksync_types::l2::error::TxCheckError; -use zksync_types::U256; +use crate::api_server::execution_sandbox::SandboxExecutionError; #[derive(Debug, Error)] pub enum SubmitTxError { diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/batch_limiter_middleware.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/batch_limiter_middleware.rs index f85325c03bc..0192ffe3a5c 100644 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/batch_limiter_middleware.rs +++ b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/batch_limiter_middleware.rs @@ -1,3 +1,5 @@ +use std::{future::Future, num::NonZeroU32, sync::Arc}; + use futures::{future, FutureExt}; use governor::{ clock::DefaultClock, @@ -12,8 +14,6 @@ use jsonrpc_core::{ use jsonrpc_pubsub::Session; use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; -use std::{future::Future, num::NonZeroU32, sync::Arc}; - /// Configures the rate limiting for the WebSocket API. /// Rate limiting is applied per active connection, e.g. a single connected user may not send more than X requests /// per minute. diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/error.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/error.rs index 4a30961c453..e750d05d9b5 100644 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/error.rs +++ b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/error.rs @@ -1,8 +1,8 @@ +use std::fmt; + use jsonrpc_core::{Error, ErrorCode}; use zksync_web3_decl::error::Web3Error; -use std::fmt; - use crate::api_server::web3::metrics::API_METRICS; pub fn into_jsrpc_error(err: Web3Error) -> Error { diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/debug.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/debug.rs index 3775da78e41..57ae0bb7116 100644 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/debug.rs +++ b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/debug.rs @@ -1,15 +1,15 @@ -// External uses -use crate::api_server::web3::backend_jsonrpc::error::into_jsrpc_error; -use crate::api_server::web3::namespaces::DebugNamespace; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; - use zksync_types::{ api::{BlockId, BlockNumber, DebugCall, ResultDebugCall, TracerConfig}, transaction_request::CallRequest, H256, }; +use crate::api_server::web3::{ + backend_jsonrpc::error::into_jsrpc_error, namespaces::DebugNamespace, +}; + #[rpc] pub trait DebugNamespaceT { #[rpc(name = "debug_traceBlockByNumber")] diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/en.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/en.rs index e75d7caade2..2fc08eafcac 100644 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/en.rs +++ b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/en.rs @@ -1,13 +1,7 @@ -// Built-in uses - -// External uses use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; - -// Workspace uses use zksync_types::{api::en::SyncBlock, MiniblockNumber}; -// Local uses use crate::{ api_server::web3::{backend_jsonrpc::error::into_jsrpc_error, EnNamespace}, l1_gas_price::L1GasPriceProvider, diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/eth.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/eth.rs index 00ba9379ae5..706701cfcf3 100644 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/eth.rs +++ b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/eth.rs @@ -1,10 +1,5 @@ -// Built-in uses - -// External uses use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; - -// Workspace uses use zksync_types::{ api::{ BlockId, BlockIdVariant, BlockNumber, Transaction, TransactionId, TransactionReceipt, @@ -16,9 +11,10 @@ use zksync_types::{ }; use zksync_web3_decl::types::{Block, Filter, FilterChanges, Log}; -// Local uses -use crate::web3::namespaces::EthNamespace; -use crate::{l1_gas_price::L1GasPriceProvider, web3::backend_jsonrpc::error::into_jsrpc_error}; +use crate::{ + l1_gas_price::L1GasPriceProvider, + web3::{backend_jsonrpc::error::into_jsrpc_error, namespaces::EthNamespace}, +}; #[rpc] pub trait EthNamespaceT { diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/net.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/net.rs index 89abd3177c8..4dbd9fb7a75 100644 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/net.rs +++ b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/net.rs @@ -1,13 +1,7 @@ -// Built-in uses - -// External uses use jsonrpc_core::Result; use jsonrpc_derive::rpc; - -// Workspace uses use zksync_types::U256; -// Local uses use crate::web3::namespaces::NetNamespace; #[rpc] diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/zks.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/zks.rs index bf700a64156..48f413fba05 100644 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/zks.rs +++ b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/zks.rs @@ -1,12 +1,8 @@ -// Built-in uses use std::collections::HashMap; -// External uses use bigdecimal::BigDecimal; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; - -// Workspace uses use zksync_types::{ api::{ BlockDetails, BridgeAddresses, L1BatchDetails, L2ToL1LogProof, Proof, ProtocolVersion, @@ -18,9 +14,10 @@ use zksync_types::{ }; use zksync_web3_decl::types::{Filter, Log, Token}; -// Local uses -use crate::web3::namespaces::ZksNamespace; -use crate::{l1_gas_price::L1GasPriceProvider, web3::backend_jsonrpc::error::into_jsrpc_error}; +use crate::{ + l1_gas_price::L1GasPriceProvider, + web3::{backend_jsonrpc::error::into_jsrpc_error, namespaces::ZksNamespace}, +}; #[rpc] pub trait ZksNamespaceT { diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/pub_sub.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/pub_sub.rs index 1b11919abde..e54249f84c3 100644 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/pub_sub.rs +++ b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/pub_sub.rs @@ -2,9 +2,7 @@ use std::sync::Arc; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; -use jsonrpc_pubsub::typed; -use jsonrpc_pubsub::{Session, SubscriptionId}; - +use jsonrpc_pubsub::{typed, Session, SubscriptionId}; use zksync_web3_decl::types::PubSubResult; use super::{super::EthSubscribe, batch_limiter_middleware::RateLimitMetadata}; diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/mod.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/mod.rs index 04f6102066f..2c4f2a3ce91 100644 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/mod.rs +++ b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/mod.rs @@ -3,8 +3,11 @@ //! namespace structures defined in `zksync_core`. use std::error::Error; -use zksync_web3_decl::error::Web3Error; -use zksync_web3_decl::jsonrpsee::types::{error::ErrorCode, ErrorObjectOwned}; + +use zksync_web3_decl::{ + error::Web3Error, + jsonrpsee::types::{error::ErrorCode, ErrorObjectOwned}, +}; pub mod namespaces; diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/namespaces/zks.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/namespaces/zks.rs index 6b6ed67c3c6..93a95790666 100644 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/namespaces/zks.rs +++ b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/namespaces/zks.rs @@ -1,7 +1,6 @@ -use bigdecimal::BigDecimal; - use std::collections::HashMap; +use bigdecimal::BigDecimal; use zksync_types::{ api::{ BlockDetails, BridgeAddresses, L1BatchDetails, L2ToL1LogProof, Proof, ProtocolVersion, diff --git a/core/lib/zksync_core/src/api_server/web3/metrics.rs b/core/lib/zksync_core/src/api_server/web3/metrics.rs index 2df24f9dd60..60d41c6ea32 100644 --- a/core/lib/zksync_core/src/api_server/web3/metrics.rs +++ b/core/lib/zksync_core/src/api_server/web3/metrics.rs @@ -1,18 +1,18 @@ //! Metrics for the JSON-RPC server. -use vise::{ - Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, LabeledFamily, - LatencyObserver, Metrics, Unit, -}; - use std::{ fmt, time::{Duration, Instant}, }; -use super::{ApiTransport, TypedFilter}; +use vise::{ + Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, LabeledFamily, + LatencyObserver, Metrics, Unit, +}; use zksync_types::api; +use super::{ApiTransport, TypedFilter}; + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "scheme", rename_all = "UPPERCASE")] pub(super) enum ApiTransportLabel { diff --git a/core/lib/zksync_core/src/api_server/web3/mod.rs b/core/lib/zksync_core/src/api_server/web3/mod.rs index 2904d5af79d..411c04112c9 100644 --- a/core/lib/zksync_core/src/api_server/web3/mod.rs +++ b/core/lib/zksync_core/src/api_server/web3/mod.rs @@ -1,16 +1,17 @@ +use std::{net::SocketAddr, sync::Arc, time::Duration}; + use anyhow::Context as _; +use chrono::NaiveDateTime; use futures::future; use jsonrpc_core::MetaIoHandler; use jsonrpc_http_server::hyper; use jsonrpc_pubsub::PubSubHandler; use serde::Deserialize; -use tokio::sync::{mpsc, oneshot, watch, Mutex}; +use tokio::{ + sync::{mpsc, oneshot, watch, Mutex}, + task::JoinHandle, +}; use tower_http::{cors::CorsLayer, metrics::InFlightRequestsLayer}; - -use chrono::NaiveDateTime; -use std::{net::SocketAddr, sync::Arc, time::Duration}; -use tokio::task::JoinHandle; - use zksync_dal::{ConnectionPool, StorageProcessor}; use zksync_health_check::{HealthStatus, HealthUpdater, ReactiveHealthCheck}; use zksync_types::{api, MiniblockNumber}; @@ -27,6 +28,23 @@ use zksync_web3_decl::{ types::Filter, }; +use self::{ + backend_jsonrpc::{ + batch_limiter_middleware::{LimitMiddleware, Transport}, + error::internal_error, + namespaces::{ + debug::DebugNamespaceT, en::EnNamespaceT, eth::EthNamespaceT, net::NetNamespaceT, + web3::Web3NamespaceT, zks::ZksNamespaceT, + }, + pub_sub::Web3PubSub, + }, + metrics::API_METRICS, + namespaces::{ + DebugNamespace, EnNamespace, EthNamespace, NetNamespace, Web3Namespace, ZksNamespace, + }, + pubsub::{EthSubscribe, PubSubEvent}, + state::{Filters, InternalApiConfig, RpcState, SealedMiniblockNumber}, +}; use crate::{ api_server::{ execution_sandbox::VmConcurrencyBarrier, tree::TreeApiHttpClient, tx_sender::TxSender, @@ -45,22 +63,6 @@ pub mod state; #[cfg(test)] pub(crate) mod tests; -use self::backend_jsonrpc::{ - batch_limiter_middleware::{LimitMiddleware, Transport}, - error::internal_error, - namespaces::{ - debug::DebugNamespaceT, en::EnNamespaceT, eth::EthNamespaceT, net::NetNamespaceT, - web3::Web3NamespaceT, zks::ZksNamespaceT, - }, - pub_sub::Web3PubSub, -}; -use self::metrics::API_METRICS; -use self::namespaces::{ - DebugNamespace, EnNamespace, EthNamespace, NetNamespace, Web3Namespace, ZksNamespace, -}; -use self::pubsub::{EthSubscribe, PubSubEvent}; -use self::state::{Filters, InternalApiConfig, RpcState, SealedMiniblockNumber}; - /// Timeout for graceful shutdown logic within API servers. const GRACEFUL_SHUTDOWN_TIMEOUT: Duration = Duration::from_secs(5); diff --git a/core/lib/zksync_core/src/api_server/web3/namespaces/debug.rs b/core/lib/zksync_core/src/api_server/web3/namespaces/debug.rs index d59c25ddbe9..76e4f01ee47 100644 --- a/core/lib/zksync_core/src/api_server/web3/namespaces/debug.rs +++ b/core/lib/zksync_core/src/api_server/web3/namespaces/debug.rs @@ -1,9 +1,7 @@ -use multivm::vm_latest::constants::BLOCK_GAS_LIMIT; -use once_cell::sync::OnceCell; use std::sync::Arc; -use multivm::interface::ExecutionResult; - +use multivm::{interface::ExecutionResult, vm_latest::constants::BLOCK_GAS_LIMIT}; +use once_cell::sync::OnceCell; use zksync_dal::ConnectionPool; use zksync_state::PostgresStorageCaches; use zksync_types::{ @@ -15,19 +13,21 @@ use zksync_types::{ }; use zksync_web3_decl::error::Web3Error; -use crate::api_server::{ - execution_sandbox::{ - execute_tx_eth_call, ApiTracer, BlockArgs, TxSharedArgs, VmConcurrencyLimiter, - }, - tx_sender::ApiContracts, - web3::{ - backend_jsonrpc::error::internal_error, - metrics::API_METRICS, - resolve_block, - state::{RpcState, SealedMiniblockNumber}, +use crate::{ + api_server::{ + execution_sandbox::{ + execute_tx_eth_call, ApiTracer, BlockArgs, TxSharedArgs, VmConcurrencyLimiter, + }, + tx_sender::ApiContracts, + web3::{ + backend_jsonrpc::error::internal_error, + metrics::API_METRICS, + resolve_block, + state::{RpcState, SealedMiniblockNumber}, + }, }, + l1_gas_price::L1GasPriceProvider, }; -use crate::l1_gas_price::L1GasPriceProvider; #[derive(Debug, Clone)] pub struct DebugNamespace { diff --git a/core/lib/zksync_core/src/api_server/web3/namespaces/en.rs b/core/lib/zksync_core/src/api_server/web3/namespaces/en.rs index b43f5523938..97c6eb9e768 100644 --- a/core/lib/zksync_core/src/api_server/web3/namespaces/en.rs +++ b/core/lib/zksync_core/src/api_server/web3/namespaces/en.rs @@ -2,7 +2,7 @@ use zksync_types::{api::en::SyncBlock, MiniblockNumber}; use zksync_web3_decl::error::Web3Error; use crate::{ - api_server::{web3::backend_jsonrpc::error::internal_error, web3::state::RpcState}, + api_server::web3::{backend_jsonrpc::error::internal_error, state::RpcState}, l1_gas_price::L1GasPriceProvider, }; 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 9e3a90dde04..7f575c57414 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 @@ -2,7 +2,6 @@ use std::{collections::HashMap, convert::TryInto}; use bigdecimal::{BigDecimal, Zero}; use zksync_dal::StorageProcessor; - use zksync_mini_merkle_tree::MiniMerkleTree; use zksync_types::{ api::{ @@ -25,11 +24,13 @@ use zksync_web3_decl::{ types::{Address, Filter, Log, Token, H256}, }; -use crate::api_server::{ - tree::TreeApiClient, - web3::{backend_jsonrpc::error::internal_error, metrics::API_METRICS, RpcState}, +use crate::{ + api_server::{ + tree::TreeApiClient, + web3::{backend_jsonrpc::error::internal_error, metrics::API_METRICS, RpcState}, + }, + l1_gas_price::L1GasPriceProvider, }; -use crate::l1_gas_price::L1GasPriceProvider; #[derive(Debug)] pub struct ZksNamespace { diff --git a/core/lib/zksync_core/src/api_server/web3/pubsub.rs b/core/lib/zksync_core/src/api_server/web3/pubsub.rs index 946c0744ba4..57e54cad10f 100644 --- a/core/lib/zksync_core/src/api_server/web3/pubsub.rs +++ b/core/lib/zksync_core/src/api_server/web3/pubsub.rs @@ -1,5 +1,7 @@ //! (Largely) backend-agnostic logic for dealing with Web3 subscriptions. +use std::{collections::HashMap, sync::Arc}; + use anyhow::Context as _; use jsonrpc_core::error::{Error, ErrorCode}; use jsonrpc_pubsub::{typed, SubscriptionId}; @@ -8,9 +10,6 @@ use tokio::{ task::JoinHandle, time::{interval, Duration}, }; - -use std::{collections::HashMap, sync::Arc}; - use zksync_dal::ConnectionPool; use zksync_types::{MiniblockNumber, H128, H256}; use zksync_web3_decl::types::{BlockHeader, Log, PubSubFilter, PubSubResult}; diff --git a/core/lib/zksync_core/src/api_server/web3/state.rs b/core/lib/zksync_core/src/api_server/web3/state.rs index ea52b2ae61c..75b41d58b20 100644 --- a/core/lib/zksync_core/src/api_server/web3/state.rs +++ b/core/lib/zksync_core/src/api_server/web3/state.rs @@ -1,5 +1,3 @@ -use zksync_utils::h256_to_u256; - use std::{ collections::HashMap, convert::TryFrom, @@ -10,9 +8,9 @@ use std::{ }, time::{Duration, Instant}, }; + use tokio::sync::Mutex; use vise::GaugeGuard; - use zksync_config::configs::{api::Web3JsonRpcConfig, chain::NetworkConfig, ContractsConfig}; use zksync_dal::ConnectionPool; use zksync_types::{ @@ -23,6 +21,7 @@ use zksync_types::{ AccountTreeId, Address, L1BatchNumber, L1ChainId, L2ChainId, MiniblockNumber, StorageKey, H256, SYSTEM_CONTEXT_ADDRESS, U256, U64, VIRTUIAL_BLOCK_UPGRADE_INFO_POSITION, }; +use zksync_utils::h256_to_u256; use zksync_web3_decl::{ error::Web3Error, types::{Filter, Log}, diff --git a/core/lib/zksync_core/src/api_server/web3/tests/mod.rs b/core/lib/zksync_core/src/api_server/web3/tests/mod.rs index 1bb14df52fa..8743330710c 100644 --- a/core/lib/zksync_core/src/api_server/web3/tests/mod.rs +++ b/core/lib/zksync_core/src/api_server/web3/tests/mod.rs @@ -1,9 +1,8 @@ +use std::{sync::Arc, time::Instant}; + use assert_matches::assert_matches; use async_trait::async_trait; use tokio::sync::watch; - -use std::{sync::Arc, time::Instant}; - use zksync_config::configs::{ api::Web3JsonRpcConfig, chain::{NetworkConfig, StateKeeperConfig}, @@ -23,8 +22,6 @@ use zksync_web3_decl::{ types::FilterChanges, }; -mod ws; - use super::{metrics::ApiTransportLabel, *}; use crate::{ api_server::tx_sender::TxSenderConfig, @@ -32,6 +29,8 @@ use crate::{ state_keeper::tests::create_l2_transaction, }; +mod ws; + const TEST_TIMEOUT: Duration = Duration::from_secs(10); const POLL_INTERVAL: Duration = Duration::from_millis(50); diff --git a/core/lib/zksync_core/src/api_server/web3/tests/ws.rs b/core/lib/zksync_core/src/api_server/web3/tests/ws.rs index 704dfef6700..58fcebeda0d 100644 --- a/core/lib/zksync_core/src/api_server/web3/tests/ws.rs +++ b/core/lib/zksync_core/src/api_server/web3/tests/ws.rs @@ -2,7 +2,6 @@ use async_trait::async_trait; use tokio::sync::watch; - use zksync_config::configs::chain::NetworkConfig; use zksync_dal::ConnectionPool; use zksync_types::{api, Address, L1BatchNumber, H256, U64}; diff --git a/core/lib/zksync_core/src/basic_witness_input_producer/mod.rs b/core/lib/zksync_core/src/basic_witness_input_producer/mod.rs index e4d605d2545..d9295b413fc 100644 --- a/core/lib/zksync_core/src/basic_witness_input_producer/mod.rs +++ b/core/lib/zksync_core/src/basic_witness_input_producer/mod.rs @@ -1,24 +1,22 @@ -use anyhow::Context; -use std::sync::Arc; -use std::time::Instant; +use std::{sync::Arc, time::Instant}; +use anyhow::Context; +use async_trait::async_trait; +use multivm::interface::{L2BlockEnv, VmInterface}; +use tokio::{runtime::Handle, task::JoinHandle}; use zksync_dal::{basic_witness_input_producer_dal::JOB_MAX_ATTEMPT, ConnectionPool}; use zksync_object_store::{ObjectStore, ObjectStoreFactory}; use zksync_queued_job_processor::JobProcessor; -use zksync_types::witness_block_state::WitnessBlockState; -use zksync_types::{L1BatchNumber, L2ChainId}; +use zksync_types::{witness_block_state::WitnessBlockState, L1BatchNumber, L2ChainId}; -use async_trait::async_trait; -use multivm::interface::{L2BlockEnv, VmInterface}; -use tokio::runtime::Handle; -use tokio::task::JoinHandle; +use self::{ + metrics::METRICS, + vm_interactions::{create_vm, execute_tx}, +}; mod metrics; mod vm_interactions; -use self::metrics::METRICS; -use self::vm_interactions::{create_vm, execute_tx}; - /// Component that extracts all data (from DB) necessary to run a Basic Witness Generator. /// Does this by rerunning an entire L1Batch and extracting information from both the VM run and DB. /// This component will upload Witness Inputs to the object store. diff --git a/core/lib/zksync_core/src/basic_witness_input_producer/vm_interactions.rs b/core/lib/zksync_core/src/basic_witness_input_producer/vm_interactions.rs index 464ab1f92d0..e655112fade 100644 --- a/core/lib/zksync_core/src/basic_witness_input_producer/vm_interactions.rs +++ b/core/lib/zksync_core/src/basic_witness_input_producer/vm_interactions.rs @@ -1,15 +1,16 @@ use anyhow::{anyhow, Context}; - -use crate::state_keeper::io::common::load_l1_batch_params; - -use multivm::interface::{VmInterface, VmInterfaceHistoryEnabled}; -use multivm::vm_latest::HistoryEnabled; -use multivm::VmInstance; +use multivm::{ + interface::{VmInterface, VmInterfaceHistoryEnabled}, + vm_latest::HistoryEnabled, + VmInstance, +}; use tokio::runtime::Handle; use zksync_dal::StorageProcessor; use zksync_state::{PostgresStorage, StoragePtr, StorageView, WriteStorage}; use zksync_types::{L1BatchNumber, L2ChainId, Transaction}; +use crate::state_keeper::io::common::load_l1_batch_params; + pub(super) type VmAndStorage<'a> = ( VmInstance>, HistoryEnabled>, StoragePtr>>, diff --git a/core/lib/zksync_core/src/block_reverter/mod.rs b/core/lib/zksync_core/src/block_reverter/mod.rs index 1170af9d5ba..09358ec9abc 100644 --- a/core/lib/zksync_core/src/block_reverter/mod.rs +++ b/core/lib/zksync_core/src/block_reverter/mod.rs @@ -1,27 +1,26 @@ +use std::{path::Path, time::Duration}; + use bitflags::bitflags; use serde::Serialize; use tokio::time::sleep; - -use std::path::Path; -use std::time::Duration; - use zksync_config::{ContractsConfig, ETHSenderConfig}; use zksync_contracts::zksync_contract; use zksync_dal::ConnectionPool; +use zksync_eth_signer::{EthereumSigner, PrivateKeySigner, TransactionParameters}; use zksync_merkle_tree::domain::ZkSyncTree; use zksync_state::RocksdbStorage; use zksync_storage::RocksDB; -use zksync_types::aggregated_operations::AggregatedActionType; -use zksync_types::ethabi::Token; -use zksync_types::web3::{ - contract::{Contract, Options}, - transports::Http, - types::{BlockId, BlockNumber}, - Web3, +use zksync_types::{ + aggregated_operations::AggregatedActionType, + ethabi::Token, + web3::{ + contract::{Contract, Options}, + transports::Http, + types::{BlockId, BlockNumber}, + Web3, + }, + L1BatchNumber, PackedEthSignature, H160, H256, U256, }; -use zksync_types::{L1BatchNumber, PackedEthSignature, H160, H256, U256}; - -use zksync_eth_signer::{EthereumSigner, PrivateKeySigner, TransactionParameters}; bitflags! { pub struct BlockReverterFlags: u32 { diff --git a/core/lib/zksync_core/src/consensus/payload.rs b/core/lib/zksync_core/src/consensus/payload.rs index dbe276196b0..8051d87ca58 100644 --- a/core/lib/zksync_core/src/consensus/payload.rs +++ b/core/lib/zksync_core/src/consensus/payload.rs @@ -1,9 +1,7 @@ use anyhow::Context as _; - use zksync_consensus_roles::validator; use zksync_protobuf::{required, ProtoFmt}; -use zksync_types::api::en::SyncBlock; -use zksync_types::{Address, L1BatchNumber, Transaction, H256}; +use zksync_types::{api::en::SyncBlock, Address, L1BatchNumber, Transaction, H256}; /// L2 block (= miniblock) payload. #[derive(Debug, PartialEq)] diff --git a/core/lib/zksync_core/src/data_fetchers/mod.rs b/core/lib/zksync_core/src/data_fetchers/mod.rs index f04a80c315e..850f2814d5e 100644 --- a/core/lib/zksync_core/src/data_fetchers/mod.rs +++ b/core/lib/zksync_core/src/data_fetchers/mod.rs @@ -9,8 +9,7 @@ //! Every data fetcher is represented by an autonomic routine, which spend most of the time sleeping; //! once in the configurable interval it fetches the data from an API and store it into the database. -use tokio::sync::watch; -use tokio::task::JoinHandle; +use tokio::{sync::watch, task::JoinHandle}; use zksync_config::FetcherConfig; use zksync_dal::ConnectionPool; diff --git a/core/lib/zksync_core/src/data_fetchers/token_list/mock.rs b/core/lib/zksync_core/src/data_fetchers/token_list/mock.rs index c813888cf52..4b2aaefafb8 100644 --- a/core/lib/zksync_core/src/data_fetchers/token_list/mock.rs +++ b/core/lib/zksync_core/src/data_fetchers/token_list/mock.rs @@ -2,16 +2,14 @@ use std::{collections::HashMap, fs::read_to_string, path::PathBuf, str::FromStr} use async_trait::async_trait; use serde::{Deserialize, Serialize}; - -use zksync_types::network::Network; use zksync_types::{ + network::Network, tokens::{TokenMetadata, ETHEREUM_ADDRESS}, Address, }; -use crate::data_fetchers::error::ApiFetchError; - use super::FetcherImpl; +use crate::data_fetchers::error::ApiFetchError; #[derive(Debug, Clone)] pub struct MockTokenListFetcher { diff --git a/core/lib/zksync_core/src/data_fetchers/token_list/mod.rs b/core/lib/zksync_core/src/data_fetchers/token_list/mod.rs index 3981ea8ea40..e213cf89a06 100644 --- a/core/lib/zksync_core/src/data_fetchers/token_list/mod.rs +++ b/core/lib/zksync_core/src/data_fetchers/token_list/mod.rs @@ -15,11 +15,9 @@ use std::{ use async_trait::async_trait; use tokio::sync::watch; - use zksync_config::{configs::fetcher::TokenListSource, FetcherConfig}; use zksync_dal::{ConnectionPool, StorageProcessor}; -use zksync_types::network::Network; -use zksync_types::{tokens::TokenMetadata, Address}; +use zksync_types::{network::Network, tokens::TokenMetadata, Address}; use super::error::{ApiFetchError, ErrorAnalyzer}; diff --git a/core/lib/zksync_core/src/data_fetchers/token_list/one_inch.rs b/core/lib/zksync_core/src/data_fetchers/token_list/one_inch.rs index 1d022e4700d..a21b942b472 100644 --- a/core/lib/zksync_core/src/data_fetchers/token_list/one_inch.rs +++ b/core/lib/zksync_core/src/data_fetchers/token_list/one_inch.rs @@ -3,13 +3,11 @@ use std::{collections::HashMap, str::FromStr}; use async_trait::async_trait; use reqwest::{Client, Url}; use serde::{Deserialize, Serialize}; - use zksync_config::FetcherConfig; use zksync_types::{tokens::TokenMetadata, Address}; -use crate::data_fetchers::error::ApiFetchError; - use super::FetcherImpl; +use crate::data_fetchers::error::ApiFetchError; #[derive(Debug, Clone)] pub struct OneInchTokenListFetcher { diff --git a/core/lib/zksync_core/src/data_fetchers/token_price/coingecko.rs b/core/lib/zksync_core/src/data_fetchers/token_price/coingecko.rs index a046c23ea2d..686410eed08 100644 --- a/core/lib/zksync_core/src/data_fetchers/token_price/coingecko.rs +++ b/core/lib/zksync_core/src/data_fetchers/token_price/coingecko.rs @@ -7,7 +7,6 @@ use itertools::Itertools; use num::{rational::Ratio, BigUint}; use reqwest::{Client, Url}; use serde::{Deserialize, Serialize}; - use zksync_config::FetcherConfig; use zksync_types::{ tokens::{TokenPrice, ETHEREUM_ADDRESS}, @@ -15,9 +14,8 @@ use zksync_types::{ }; use zksync_utils::UnsignedRatioSerializeAsDecimal; -use crate::data_fetchers::error::ApiFetchError; - use super::FetcherImpl; +use crate::data_fetchers::error::ApiFetchError; #[derive(Debug, Clone)] pub struct CoinGeckoFetcher { diff --git a/core/lib/zksync_core/src/data_fetchers/token_price/mock.rs b/core/lib/zksync_core/src/data_fetchers/token_price/mock.rs index 6e5f4893e53..3fde09f65f4 100644 --- a/core/lib/zksync_core/src/data_fetchers/token_price/mock.rs +++ b/core/lib/zksync_core/src/data_fetchers/token_price/mock.rs @@ -8,9 +8,8 @@ use zksync_types::{ Address, }; -use crate::data_fetchers::error::ApiFetchError; - use super::FetcherImpl; +use crate::data_fetchers::error::ApiFetchError; #[derive(Debug, Default, Clone)] pub struct MockPriceFetcher; diff --git a/core/lib/zksync_core/src/data_fetchers/token_price/mod.rs b/core/lib/zksync_core/src/data_fetchers/token_price/mod.rs index 8e7d5575f69..074f8d81aa6 100644 --- a/core/lib/zksync_core/src/data_fetchers/token_price/mod.rs +++ b/core/lib/zksync_core/src/data_fetchers/token_price/mod.rs @@ -3,15 +3,14 @@ use std::{collections::HashMap, time::Duration}; use async_trait::async_trait; - +use bigdecimal::FromPrimitive; +use num::{rational::Ratio, BigUint}; +use tokio::sync::watch; use zksync_config::{configs::fetcher::TokenPriceSource, FetcherConfig}; use zksync_dal::{ConnectionPool, StorageProcessor}; use zksync_types::{tokens::TokenPrice, Address}; use super::error::{ApiFetchError, ErrorAnalyzer}; -use bigdecimal::FromPrimitive; -use num::{rational::Ratio, BigUint}; -use tokio::sync::watch; pub mod coingecko; pub mod mock; 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 4cb40c475f9..43b1e51da10 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 @@ -1,7 +1,6 @@ use std::convert::TryInto; use tokio::sync::watch; - use zksync_config::configs::eth_sender::SenderConfig; use zksync_contracts::BaseSystemContractsHashes; use zksync_dal::{ConnectionPool, StorageProcessor}; @@ -17,13 +16,15 @@ use zksync_types::{ Address, ProtocolVersionId, H256, U256, }; -use crate::eth_sender::{ - metrics::{PubdataKind, METRICS}, - zksync_functions::ZkSyncFunctions, - Aggregator, ETHSenderError, +use crate::{ + eth_sender::{ + metrics::{PubdataKind, METRICS}, + zksync_functions::ZkSyncFunctions, + Aggregator, ETHSenderError, + }, + gas_tracker::agg_l1_batch_base_cost, + metrics::BlockL1Stage, }; -use crate::gas_tracker::agg_l1_batch_base_cost; -use crate::metrics::BlockL1Stage; /// Data queried from L1 using multicall contract. #[derive(Debug)] diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs index 5aab4a2903c..2ef9ea87a7c 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs @@ -1,9 +1,7 @@ +use std::{sync::Arc, time::Duration}; + use anyhow::Context as _; use tokio::sync::watch; - -use std::sync::Arc; -use std::time::Duration; - use zksync_config::configs::eth_sender::SenderConfig; use zksync_dal::{ConnectionPool, StorageProcessor}; use zksync_eth_client::{ @@ -22,8 +20,7 @@ use zksync_types::{ use zksync_utils::time::seconds_since_epoch; use super::{metrics::METRICS, ETHSenderError}; -use crate::l1_gas_price::L1TxParamsProvider; -use crate::metrics::BlockL1Stage; +use crate::{l1_gas_price::L1TxParamsProvider, metrics::BlockL1Stage}; #[derive(Debug)] struct EthFee { diff --git a/core/lib/zksync_core/src/eth_sender/metrics.rs b/core/lib/zksync_core/src/eth_sender/metrics.rs index 950ff8bf6f7..4bce1bf1a1f 100644 --- a/core/lib/zksync_core/src/eth_sender/metrics.rs +++ b/core/lib/zksync_core/src/eth_sender/metrics.rs @@ -1,9 +1,8 @@ //! Metrics for the Ethereum sender component. -use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics}; - use std::{fmt, time::Duration}; +use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics}; use zksync_dal::StorageProcessor; use zksync_types::{aggregated_operations::AggregatedActionType, eth_sender::EthTx}; use zksync_utils::time::seconds_since_epoch; diff --git a/core/lib/zksync_core/src/eth_sender/publish_criterion.rs b/core/lib/zksync_core/src/eth_sender/publish_criterion.rs index 33fd33ad577..85f6a46c960 100644 --- a/core/lib/zksync_core/src/eth_sender/publish_criterion.rs +++ b/core/lib/zksync_core/src/eth_sender/publish_criterion.rs @@ -1,8 +1,7 @@ -use async_trait::async_trait; -use chrono::Utc; - use std::fmt; +use async_trait::async_trait; +use chrono::Utc; use zksync_dal::StorageProcessor; use zksync_types::{ aggregated_operations::AggregatedActionType, commitment::L1BatchWithMetadata, L1BatchNumber, diff --git a/core/lib/zksync_core/src/eth_sender/tests.rs b/core/lib/zksync_core/src/eth_sender/tests.rs index 51166fc794a..01781a424f5 100644 --- a/core/lib/zksync_core/src/eth_sender/tests.rs +++ b/core/lib/zksync_core/src/eth_sender/tests.rs @@ -1,8 +1,7 @@ -use assert_matches::assert_matches; use std::sync::{atomic::Ordering, Arc}; +use assert_matches::assert_matches; use once_cell::sync::Lazy; - use zksync_config::{ configs::eth_sender::{ProofSendingMode, SenderConfig}, ContractsConfig, ETHSenderConfig, GasAdjusterConfig, @@ -23,10 +22,12 @@ use zksync_types::{ Address, L1BatchNumber, L1BlockNumber, ProtocolVersionId, H256, }; -use crate::eth_sender::{ - eth_tx_manager::L1BlockNumbers, Aggregator, ETHSenderError, EthTxAggregator, EthTxManager, +use crate::{ + eth_sender::{ + eth_tx_manager::L1BlockNumbers, Aggregator, ETHSenderError, EthTxAggregator, EthTxManager, + }, + l1_gas_price::GasAdjuster, }; -use crate::l1_gas_price::GasAdjuster; // Alias to conveniently call static methods of ETHSender. type MockEthTxManager = EthTxManager, GasAdjuster>>; diff --git a/core/lib/zksync_core/src/eth_watch/event_processors/governance_upgrades.rs b/core/lib/zksync_core/src/eth_watch/event_processors/governance_upgrades.rs index b43fc6fb050..2f7e2e86b2c 100644 --- a/core/lib/zksync_core/src/eth_watch/event_processors/governance_upgrades.rs +++ b/core/lib/zksync_core/src/eth_watch/event_processors/governance_upgrades.rs @@ -1,15 +1,16 @@ -use crate::eth_watch::{ - client::{Error, EthClient}, - event_processors::EventProcessor, -}; -use std::convert::TryFrom; -use std::time::Instant; +use std::{convert::TryFrom, time::Instant}; + use zksync_dal::StorageProcessor; use zksync_types::{ ethabi::Contract, protocol_version::GovernanceOperation, web3::types::Log, Address, ProtocolUpgrade, ProtocolVersionId, H256, }; +use crate::eth_watch::{ + client::{Error, EthClient}, + event_processors::EventProcessor, +}; + /// Listens to operation events coming from the governance contract and saves new protocol upgrade proposals to the database. #[derive(Debug)] pub struct GovernanceUpgradesEventProcessor { diff --git a/core/lib/zksync_core/src/eth_watch/event_processors/mod.rs b/core/lib/zksync_core/src/eth_watch/event_processors/mod.rs index 84ea1eeb04c..202b7efb586 100644 --- a/core/lib/zksync_core/src/eth_watch/event_processors/mod.rs +++ b/core/lib/zksync_core/src/eth_watch/event_processors/mod.rs @@ -1,7 +1,8 @@ -use crate::eth_watch::client::{Error, EthClient}; use zksync_dal::StorageProcessor; use zksync_types::{web3::types::Log, H256}; +use crate::eth_watch::client::{Error, EthClient}; + pub mod governance_upgrades; pub mod priority_ops; pub mod upgrades; 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 210b540c48e..497cb705ee1 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,4 +1,5 @@ use std::convert::TryFrom; + use zksync_dal::StorageProcessor; use zksync_types::{web3::types::Log, ProtocolUpgrade, ProtocolVersionId, H256}; diff --git a/core/lib/zksync_core/src/eth_watch/metrics.rs b/core/lib/zksync_core/src/eth_watch/metrics.rs index e5166f137ca..c96b8c08483 100644 --- a/core/lib/zksync_core/src/eth_watch/metrics.rs +++ b/core/lib/zksync_core/src/eth_watch/metrics.rs @@ -1,9 +1,9 @@ //! Metrics for Ethereum watcher. -use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; - use std::time::Duration; +use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "stage", rename_all = "snake_case")] pub(super) enum PollStage { diff --git a/core/lib/zksync_core/src/eth_watch/mod.rs b/core/lib/zksync_core/src/eth_watch/mod.rs index fdb629bce28..69f447e7fba 100644 --- a/core/lib/zksync_core/src/eth_watch/mod.rs +++ b/core/lib/zksync_core/src/eth_watch/mod.rs @@ -4,10 +4,9 @@ //! Poll interval is configured using the `ETH_POLL_INTERVAL` constant. //! Number of confirmations is configured using the `CONFIRMATIONS_FOR_ETH_EVENT` environment variable. -use tokio::{sync::watch, task::JoinHandle}; - use std::time::Duration; +use tokio::{sync::watch, task::JoinHandle}; use zksync_config::ETHWatchConfig; use zksync_dal::{ConnectionPool, StorageProcessor}; use zksync_eth_client::EthInterface; @@ -17,12 +16,6 @@ use zksync_types::{ ProtocolVersionId, }; -mod client; -mod event_processors; -mod metrics; -#[cfg(test)] -mod tests; - use self::{ client::{Error, EthClient, EthHttpQueryClient, RETRY_LIMIT}, event_processors::{ @@ -32,6 +25,12 @@ use self::{ metrics::{PollStage, METRICS}, }; +mod client; +mod event_processors; +mod metrics; +#[cfg(test)] +mod tests; + #[derive(Debug)] struct EthWatchState { last_seen_version_id: ProtocolVersionId, diff --git a/core/lib/zksync_core/src/eth_watch/tests.rs b/core/lib/zksync_core/src/eth_watch/tests.rs index d7627a56c13..31c46741929 100644 --- a/core/lib/zksync_core/src/eth_watch/tests.rs +++ b/core/lib/zksync_core/src/eth_watch/tests.rs @@ -1,17 +1,13 @@ -use std::collections::HashMap; -use std::convert::TryInto; -use std::sync::Arc; +use std::{collections::HashMap, convert::TryInto, sync::Arc}; use tokio::sync::RwLock; - use zksync_contracts::{governance_contract, zksync_contract}; use zksync_dal::{ConnectionPool, StorageProcessor}; -use zksync_types::protocol_version::{ProtocolUpgradeTx, ProtocolUpgradeTxCommonData}; -use zksync_types::web3::types::{Address, BlockNumber}; use zksync_types::{ ethabi::{encode, Hash, Token}, l1::{L1Tx, OpProcessingType, PriorityQueueType}, - web3::types::Log, + protocol_version::{ProtocolUpgradeTx, ProtocolUpgradeTxCommonData}, + web3::types::{Address, BlockNumber, Log}, Execute, L1TxCommonData, PriorityOpId, ProtocolUpgrade, ProtocolVersion, ProtocolVersionId, Transaction, H256, U256, }; diff --git a/core/lib/zksync_core/src/genesis.rs b/core/lib/zksync_core/src/genesis.rs index 39a8645767d..01d4628caac 100644 --- a/core/lib/zksync_core/src/genesis.rs +++ b/core/lib/zksync_core/src/genesis.rs @@ -3,14 +3,13 @@ //! setups the required databases, and outputs the data required to initialize a smart contract. use anyhow::Context as _; - use zksync_contracts::BaseSystemContracts; use zksync_dal::StorageProcessor; use zksync_merkle_tree::domain::ZkSyncTree; - use zksync_types::{ - block::DeployedContract, - block::{legacy_miniblock_hash, BlockGasCount, L1BatchHeader, MiniblockHeader}, + block::{ + legacy_miniblock_hash, BlockGasCount, DeployedContract, L1BatchHeader, MiniblockHeader, + }, commitment::{L1BatchCommitment, L1BatchMetadata}, get_code_key, get_system_context_init_logs, protocol_version::{L1VerifierConfig, ProtocolVersion}, @@ -19,8 +18,7 @@ use zksync_types::{ AccountTreeId, Address, L1BatchNumber, L2ChainId, LogQuery, MiniblockNumber, ProtocolVersionId, StorageKey, StorageLog, StorageLogKind, Timestamp, H256, }; -use zksync_utils::{be_words_to_bytes, h256_to_u256}; -use zksync_utils::{bytecode::hash_bytecode, u256_to_h256}; +use zksync_utils::{be_words_to_bytes, bytecode::hash_bytecode, h256_to_u256, u256_to_h256}; use crate::metadata_calculator::L1BatchWithLogs; diff --git a/core/lib/zksync_core/src/house_keeper/blocks_state_reporter.rs b/core/lib/zksync_core/src/house_keeper/blocks_state_reporter.rs index 6ba94cbac6d..190764ec57d 100644 --- a/core/lib/zksync_core/src/house_keeper/blocks_state_reporter.rs +++ b/core/lib/zksync_core/src/house_keeper/blocks_state_reporter.rs @@ -1,5 +1,4 @@ use async_trait::async_trait; - use zksync_dal::ConnectionPool; use zksync_prover_utils::periodic_job::PeriodicJob; use zksync_utils::time::seconds_since_epoch; diff --git a/core/lib/zksync_core/src/house_keeper/fri_proof_compressor_queue_monitor.rs b/core/lib/zksync_core/src/house_keeper/fri_proof_compressor_queue_monitor.rs index 769792b6a58..73c752b6955 100644 --- a/core/lib/zksync_core/src/house_keeper/fri_proof_compressor_queue_monitor.rs +++ b/core/lib/zksync_core/src/house_keeper/fri_proof_compressor_queue_monitor.rs @@ -1,8 +1,7 @@ use async_trait::async_trait; use zksync_dal::ConnectionPool; -use zksync_types::proofs::JobCountStatistics; - use zksync_prover_utils::periodic_job::PeriodicJob; +use zksync_types::proofs::JobCountStatistics; const PROOF_COMPRESSOR_SERVICE_NAME: &str = "proof_compressor"; diff --git a/core/lib/zksync_core/src/house_keeper/fri_scheduler_circuit_queuer.rs b/core/lib/zksync_core/src/house_keeper/fri_scheduler_circuit_queuer.rs index ab9eba1fc66..0adfdb47055 100644 --- a/core/lib/zksync_core/src/house_keeper/fri_scheduler_circuit_queuer.rs +++ b/core/lib/zksync_core/src/house_keeper/fri_scheduler_circuit_queuer.rs @@ -1,6 +1,5 @@ use async_trait::async_trait; use zksync_dal::ConnectionPool; - use zksync_prover_utils::periodic_job::PeriodicJob; #[derive(Debug)] diff --git a/core/lib/zksync_core/src/house_keeper/fri_witness_generator_queue_monitor.rs b/core/lib/zksync_core/src/house_keeper/fri_witness_generator_queue_monitor.rs index 15b56e16553..67f81295b44 100644 --- a/core/lib/zksync_core/src/house_keeper/fri_witness_generator_queue_monitor.rs +++ b/core/lib/zksync_core/src/house_keeper/fri_witness_generator_queue_monitor.rs @@ -2,9 +2,8 @@ use std::collections::HashMap; use async_trait::async_trait; use zksync_dal::ConnectionPool; -use zksync_types::proofs::{AggregationRound, JobCountStatistics}; - use zksync_prover_utils::periodic_job::PeriodicJob; +use zksync_types::proofs::{AggregationRound, JobCountStatistics}; const FRI_WITNESS_GENERATOR_SERVICE_NAME: &str = "fri_witness_generator"; diff --git a/core/lib/zksync_core/src/house_keeper/gpu_prover_queue_monitor.rs b/core/lib/zksync_core/src/house_keeper/gpu_prover_queue_monitor.rs index 7ddb1bd75dd..ab96b52bedc 100644 --- a/core/lib/zksync_core/src/house_keeper/gpu_prover_queue_monitor.rs +++ b/core/lib/zksync_core/src/house_keeper/gpu_prover_queue_monitor.rs @@ -1,6 +1,5 @@ use async_trait::async_trait; use zksync_dal::ConnectionPool; - use zksync_prover_utils::periodic_job::PeriodicJob; #[derive(Debug)] diff --git a/core/lib/zksync_core/src/house_keeper/prover_job_retry_manager.rs b/core/lib/zksync_core/src/house_keeper/prover_job_retry_manager.rs index 4142f1d5766..f7b630475ea 100644 --- a/core/lib/zksync_core/src/house_keeper/prover_job_retry_manager.rs +++ b/core/lib/zksync_core/src/house_keeper/prover_job_retry_manager.rs @@ -2,7 +2,6 @@ use std::time::Duration; use async_trait::async_trait; use zksync_dal::ConnectionPool; - use zksync_prover_utils::periodic_job::PeriodicJob; #[derive(Debug)] diff --git a/core/lib/zksync_core/src/house_keeper/prover_queue_monitor.rs b/core/lib/zksync_core/src/house_keeper/prover_queue_monitor.rs index 5b41ee74ac9..e0f598d5a59 100644 --- a/core/lib/zksync_core/src/house_keeper/prover_queue_monitor.rs +++ b/core/lib/zksync_core/src/house_keeper/prover_queue_monitor.rs @@ -1,9 +1,7 @@ use async_trait::async_trait; use zksync_config::configs::ProverGroupConfig; use zksync_dal::ConnectionPool; -use zksync_prover_utils::circuit_name_to_numeric_index; - -use zksync_prover_utils::periodic_job::PeriodicJob; +use zksync_prover_utils::{circuit_name_to_numeric_index, periodic_job::PeriodicJob}; #[derive(Debug)] pub struct ProverStatsReporter { diff --git a/core/lib/zksync_core/src/house_keeper/waiting_to_queued_fri_witness_job_mover.rs b/core/lib/zksync_core/src/house_keeper/waiting_to_queued_fri_witness_job_mover.rs index 2fd00bcd6f6..1292ee3f44f 100644 --- a/core/lib/zksync_core/src/house_keeper/waiting_to_queued_fri_witness_job_mover.rs +++ b/core/lib/zksync_core/src/house_keeper/waiting_to_queued_fri_witness_job_mover.rs @@ -1,6 +1,5 @@ use async_trait::async_trait; use zksync_dal::ConnectionPool; - use zksync_prover_utils::periodic_job::PeriodicJob; #[derive(Debug)] diff --git a/core/lib/zksync_core/src/house_keeper/waiting_to_queued_witness_job_mover.rs b/core/lib/zksync_core/src/house_keeper/waiting_to_queued_witness_job_mover.rs index c99603676ec..4521b4bfc47 100644 --- a/core/lib/zksync_core/src/house_keeper/waiting_to_queued_witness_job_mover.rs +++ b/core/lib/zksync_core/src/house_keeper/waiting_to_queued_witness_job_mover.rs @@ -1,6 +1,5 @@ use async_trait::async_trait; use zksync_dal::ConnectionPool; - use zksync_prover_utils::periodic_job::PeriodicJob; #[derive(Debug)] diff --git a/core/lib/zksync_core/src/house_keeper/witness_generator_queue_monitor.rs b/core/lib/zksync_core/src/house_keeper/witness_generator_queue_monitor.rs index 40a8e2a6613..da816da3c66 100644 --- a/core/lib/zksync_core/src/house_keeper/witness_generator_queue_monitor.rs +++ b/core/lib/zksync_core/src/house_keeper/witness_generator_queue_monitor.rs @@ -2,9 +2,8 @@ use std::collections::HashMap; use async_trait::async_trait; use zksync_dal::ConnectionPool; -use zksync_types::proofs::{AggregationRound, JobCountStatistics}; - use zksync_prover_utils::periodic_job::PeriodicJob; +use zksync_types::proofs::{AggregationRound, JobCountStatistics}; const WITNESS_GENERATOR_SERVICE_NAME: &str = "witness_generator"; diff --git a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs index 9a8825190ee..dd9806f998c 100644 --- a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs +++ b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs @@ -1,23 +1,22 @@ //! This module determines the fees to pay in txs containing blocks submitted to the L1. -use tokio::sync::watch; - use std::{ collections::VecDeque, sync::{Arc, RwLock}, }; +use tokio::sync::watch; use zksync_config::GasAdjusterConfig; use zksync_eth_client::{types::Error, EthInterface}; +use self::metrics::METRICS; +use super::{L1GasPriceProvider, L1TxParamsProvider}; + pub mod bounded_gas_adjuster; mod metrics; #[cfg(test)] mod tests; -use self::metrics::METRICS; -use super::{L1GasPriceProvider, L1TxParamsProvider}; - /// This component keeps track of the median base_fee from the last `max_base_fee_samples` blocks. /// It is used to adjust the base_fee of transactions sent to L1. #[derive(Debug)] diff --git a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/tests.rs b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/tests.rs index a0c6dac365c..84ace37ecec 100644 --- a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/tests.rs +++ b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/tests.rs @@ -1,9 +1,10 @@ -use super::{GasAdjuster, GasStatisticsInner}; -use std::collections::VecDeque; -use std::sync::Arc; +use std::{collections::VecDeque, sync::Arc}; + use zksync_config::GasAdjusterConfig; use zksync_eth_client::clients::mock::MockEthereum; +use super::{GasAdjuster, GasStatisticsInner}; + /// Check that we compute the median correctly #[test] fn median() { diff --git a/core/lib/zksync_core/src/l1_gas_price/main_node_fetcher.rs b/core/lib/zksync_core/src/l1_gas_price/main_node_fetcher.rs index 2244607a47e..a3f7b92f0e4 100644 --- a/core/lib/zksync_core/src/l1_gas_price/main_node_fetcher.rs +++ b/core/lib/zksync_core/src/l1_gas_price/main_node_fetcher.rs @@ -7,7 +7,6 @@ use std::{ }; use tokio::sync::watch::Receiver; - use zksync_web3_decl::{ jsonrpsee::http_client::{HttpClient, HttpClientBuilder}, namespaces::ZksNamespaceClient, diff --git a/core/lib/zksync_core/src/l1_gas_price/mod.rs b/core/lib/zksync_core/src/l1_gas_price/mod.rs index 45e228d79c5..bab30c03584 100644 --- a/core/lib/zksync_core/src/l1_gas_price/mod.rs +++ b/core/lib/zksync_core/src/l1_gas_price/mod.rs @@ -1,7 +1,6 @@ //! This module determines the fees to pay in txs containing blocks submitted to the L1. -pub use gas_adjuster::bounded_gas_adjuster::BoundedGasAdjuster; -pub use gas_adjuster::GasAdjuster; +pub use gas_adjuster::{bounded_gas_adjuster::BoundedGasAdjuster, GasAdjuster}; pub use main_node_fetcher::MainNodeGasPriceFetcher; pub use singleton::GasAdjusterSingleton; diff --git a/core/lib/zksync_core/src/l1_gas_price/singleton.rs b/core/lib/zksync_core/src/l1_gas_price/singleton.rs index 4808dee548b..0c70ba2466c 100644 --- a/core/lib/zksync_core/src/l1_gas_price/singleton.rs +++ b/core/lib/zksync_core/src/l1_gas_price/singleton.rs @@ -1,11 +1,15 @@ -use crate::l1_gas_price::{BoundedGasAdjuster, GasAdjuster}; -use anyhow::Context as _; use std::sync::Arc; -use tokio::sync::{watch, OnceCell}; -use tokio::task::JoinHandle; + +use anyhow::Context as _; +use tokio::{ + sync::{watch, OnceCell}, + task::JoinHandle, +}; use zksync_config::GasAdjusterConfig; use zksync_eth_client::clients::http::QueryClient; +use crate::l1_gas_price::{BoundedGasAdjuster, GasAdjuster}; + /// Special struct for creating a singleton of `GasAdjuster`. /// This is needed only for running the server. #[derive(Debug)] diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 2389d576173..5406f0bbd89 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -7,7 +7,6 @@ use futures::channel::oneshot; use prometheus_exporter::PrometheusExporterConfig; use temp_config_store::TempConfigStore; use tokio::{sync::watch, task::JoinHandle}; - use zksync_circuit_breaker::{ l1_txs::FailedL1TransactionChecker, replication_lag::ReplicationLagChecker, CircuitBreaker, CircuitBreakerChecker, CircuitBreakerError, @@ -26,9 +25,10 @@ use zksync_config::{ }; use zksync_contracts::{governance_contract, BaseSystemContracts}; use zksync_dal::{healthcheck::ConnectionPoolHealthCheck, ConnectionPool}; -use zksync_eth_client::clients::http::QueryClient; -use zksync_eth_client::EthInterface; -use zksync_eth_client::{clients::http::PKSigningClient, BoundEthInterface}; +use zksync_eth_client::{ + clients::http::{PKSigningClient, QueryClient}, + BoundEthInterface, EthInterface, +}; use zksync_health_check::{CheckHealth, HealthStatus, ReactiveHealthCheck}; use zksync_object_store::{ObjectStore, ObjectStoreFactory}; use zksync_prover_utils::periodic_job::PeriodicJob; @@ -42,6 +42,46 @@ use zksync_types::{ }; use zksync_verification_key_server::get_cached_commitments; +use crate::{ + api_server::{ + contract_verification, + execution_sandbox::{VmConcurrencyBarrier, VmConcurrencyLimiter}, + healthcheck::HealthCheckHandle, + tx_sender::{ApiContracts, TxSender, TxSenderBuilder, TxSenderConfig}, + web3, + web3::{state::InternalApiConfig, ApiServerHandles, Namespace}, + }, + basic_witness_input_producer::BasicWitnessInputProducer, + data_fetchers::run_data_fetchers, + eth_sender::{Aggregator, EthTxAggregator, EthTxManager}, + eth_watch::start_eth_watch, + house_keeper::{ + blocks_state_reporter::L1BatchMetricsReporter, + fri_proof_compressor_job_retry_manager::FriProofCompressorJobRetryManager, + fri_proof_compressor_queue_monitor::FriProofCompressorStatsReporter, + fri_prover_job_retry_manager::FriProverJobRetryManager, + fri_prover_queue_monitor::FriProverStatsReporter, + fri_scheduler_circuit_queuer::SchedulerCircuitQueuer, + fri_witness_generator_jobs_retry_manager::FriWitnessGeneratorJobRetryManager, + fri_witness_generator_queue_monitor::FriWitnessGeneratorStatsReporter, + gpu_prover_queue_monitor::GpuProverQueueMonitor, + prover_job_retry_manager::ProverJobRetryManager, prover_queue_monitor::ProverStatsReporter, + waiting_to_queued_fri_witness_job_mover::WaitingToQueuedFriWitnessJobMover, + waiting_to_queued_witness_job_mover::WaitingToQueuedWitnessJobMover, + witness_generator_queue_monitor::WitnessGeneratorStatsReporter, + }, + l1_gas_price::{GasAdjusterSingleton, L1GasPriceProvider}, + metadata_calculator::{ + MetadataCalculator, MetadataCalculatorConfig, MetadataCalculatorModeConfig, + }, + metrics::{InitStage, APP_METRICS}, + state_keeper::{create_state_keeper, MempoolFetcher, MempoolGuard, MiniblockSealer}, + witness_generator::{ + basic_circuits::BasicWitnessGenerator, leaf_aggregation::LeafAggregationWitnessGenerator, + node_aggregation::NodeAggregationWitnessGenerator, scheduler::SchedulerWitnessGenerator, + }, +}; + pub mod api_server; pub mod basic_witness_input_producer; pub mod block_reverter; @@ -63,47 +103,6 @@ pub mod sync_layer; pub mod temp_config_store; pub mod witness_generator; -use crate::api_server::healthcheck::HealthCheckHandle; -use crate::api_server::tx_sender::{TxSender, TxSenderBuilder, TxSenderConfig}; -use crate::api_server::web3::{state::InternalApiConfig, ApiServerHandles, Namespace}; -use crate::basic_witness_input_producer::BasicWitnessInputProducer; -use crate::eth_sender::{Aggregator, EthTxManager}; -use crate::house_keeper::fri_proof_compressor_job_retry_manager::FriProofCompressorJobRetryManager; -use crate::house_keeper::fri_proof_compressor_queue_monitor::FriProofCompressorStatsReporter; -use crate::house_keeper::fri_prover_job_retry_manager::FriProverJobRetryManager; -use crate::house_keeper::fri_prover_queue_monitor::FriProverStatsReporter; -use crate::house_keeper::fri_scheduler_circuit_queuer::SchedulerCircuitQueuer; -use crate::house_keeper::fri_witness_generator_jobs_retry_manager::FriWitnessGeneratorJobRetryManager; -use crate::house_keeper::fri_witness_generator_queue_monitor::FriWitnessGeneratorStatsReporter; -use crate::house_keeper::{ - blocks_state_reporter::L1BatchMetricsReporter, gpu_prover_queue_monitor::GpuProverQueueMonitor, - prover_job_retry_manager::ProverJobRetryManager, prover_queue_monitor::ProverStatsReporter, - waiting_to_queued_fri_witness_job_mover::WaitingToQueuedFriWitnessJobMover, - waiting_to_queued_witness_job_mover::WaitingToQueuedWitnessJobMover, - witness_generator_queue_monitor::WitnessGeneratorStatsReporter, -}; -use crate::l1_gas_price::{GasAdjusterSingleton, L1GasPriceProvider}; -use crate::metadata_calculator::{ - MetadataCalculator, MetadataCalculatorConfig, MetadataCalculatorModeConfig, -}; -use crate::state_keeper::{create_state_keeper, MempoolFetcher, MempoolGuard, MiniblockSealer}; -use crate::witness_generator::{ - basic_circuits::BasicWitnessGenerator, leaf_aggregation::LeafAggregationWitnessGenerator, - node_aggregation::NodeAggregationWitnessGenerator, scheduler::SchedulerWitnessGenerator, -}; -use crate::{ - api_server::{ - contract_verification, - execution_sandbox::{VmConcurrencyBarrier, VmConcurrencyLimiter}, - tx_sender::ApiContracts, - web3, - }, - data_fetchers::run_data_fetchers, - eth_sender::EthTxAggregator, - eth_watch::start_eth_watch, - metrics::{InitStage, APP_METRICS}, -}; - /// Inserts the initial information about zkSync tokens into the database. pub async fn genesis_init( postgres_config: &PostgresConfig, diff --git a/core/lib/zksync_core/src/metadata_calculator/helpers.rs b/core/lib/zksync_core/src/metadata_calculator/helpers.rs index 9ae936febfe..790beca3070 100644 --- a/core/lib/zksync_core/src/metadata_calculator/helpers.rs +++ b/core/lib/zksync_core/src/metadata_calculator/helpers.rs @@ -1,9 +1,5 @@ //! Various helpers for the metadata calculator. -use serde::{Deserialize, Serialize}; -#[cfg(test)] -use tokio::sync::mpsc; - use std::{ collections::BTreeMap, future::Future, @@ -11,6 +7,9 @@ use std::{ time::Duration, }; +use serde::{Deserialize, Serialize}; +#[cfg(test)] +use tokio::sync::mpsc; use zksync_config::configs::database::MerkleTreeMode; use zksync_dal::StorageProcessor; use zksync_health_check::{Health, HealthStatus}; @@ -327,7 +326,6 @@ impl L1BatchWithLogs { #[cfg(test)] mod tests { use tempfile::TempDir; - use zksync_dal::ConnectionPool; use zksync_types::{proofs::PrepareBasicCircuitsJob, L2ChainId, StorageKey, StorageLog}; diff --git a/core/lib/zksync_core/src/metadata_calculator/metrics.rs b/core/lib/zksync_core/src/metadata_calculator/metrics.rs index f8ef8f85b64..da4995bdbf9 100644 --- a/core/lib/zksync_core/src/metadata_calculator/metrics.rs +++ b/core/lib/zksync_core/src/metadata_calculator/metrics.rs @@ -1,11 +1,10 @@ //! Metrics for `MetadataCalculator`. +use std::time::{Duration, Instant}; + use vise::{ Buckets, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, LatencyObserver, Metrics, }; - -use std::time::{Duration, Instant}; - use zksync_types::block::L1BatchHeader; use zksync_utils::time::seconds_since_epoch; diff --git a/core/lib/zksync_core/src/metadata_calculator/mod.rs b/core/lib/zksync_core/src/metadata_calculator/mod.rs index 7289347fec0..31b39a90952 100644 --- a/core/lib/zksync_core/src/metadata_calculator/mod.rs +++ b/core/lib/zksync_core/src/metadata_calculator/mod.rs @@ -1,10 +1,9 @@ //! This module applies updates to the ZkSyncTree, calculates metadata for sealed blocks, and //! stores them in the DB. -use tokio::sync::watch; - use std::time::Duration; +use tokio::sync::watch; use zksync_config::configs::{ chain::OperationsManagerConfig, database::{MerkleTreeConfig, MerkleTreeMode}, @@ -19,12 +18,6 @@ use zksync_types::{ H256, }; -mod helpers; -mod metrics; -#[cfg(test)] -pub(crate) mod tests; -mod updater; - pub(crate) use self::helpers::{AsyncTreeReader, L1BatchWithLogs, MerkleTreeInfo}; use self::{ helpers::Delayer, @@ -33,6 +26,12 @@ use self::{ }; use crate::gas_tracker::commit_gas_count_for_l1_batch; +mod helpers; +mod metrics; +#[cfg(test)] +pub(crate) mod tests; +mod updater; + /// Part of [`MetadataCalculator`] related to the operation mode of the Merkle tree. #[derive(Debug, Clone, Copy)] pub enum MetadataCalculatorModeConfig<'a> { diff --git a/core/lib/zksync_core/src/metadata_calculator/tests.rs b/core/lib/zksync_core/src/metadata_calculator/tests.rs index 5e86db6087b..85d179fe3b0 100644 --- a/core/lib/zksync_core/src/metadata_calculator/tests.rs +++ b/core/lib/zksync_core/src/metadata_calculator/tests.rs @@ -1,10 +1,9 @@ +use std::{future::Future, ops, panic, path::Path, time::Duration}; + use assert_matches::assert_matches; use itertools::Itertools; use tempfile::TempDir; use tokio::sync::{mpsc, watch}; - -use std::{future::Future, ops, panic, path::Path, time::Duration}; - use zksync_config::configs::{chain::OperationsManagerConfig, database::MerkleTreeConfig}; use zksync_contracts::BaseSystemContracts; use zksync_dal::{ConnectionPool, StorageProcessor}; diff --git a/core/lib/zksync_core/src/metadata_calculator/updater.rs b/core/lib/zksync_core/src/metadata_calculator/updater.rs index ed38dae14ed..87127947fbd 100644 --- a/core/lib/zksync_core/src/metadata_calculator/updater.rs +++ b/core/lib/zksync_core/src/metadata_calculator/updater.rs @@ -1,11 +1,10 @@ //! Tree updater trait and its implementations. +use std::{ops, time::Instant}; + use anyhow::Context as _; use futures::{future, FutureExt}; use tokio::sync::watch; - -use std::{ops, time::Instant}; - use zksync_commitment_utils::{bootloader_initial_content_commitment, events_queue_commitment}; use zksync_config::configs::database::MerkleTreeMode; use zksync_dal::{ConnectionPool, StorageProcessor}; diff --git a/core/lib/zksync_core/src/metrics.rs b/core/lib/zksync_core/src/metrics.rs index 539cbbbb2fb..0206c264759 100644 --- a/core/lib/zksync_core/src/metrics.rs +++ b/core/lib/zksync_core/src/metrics.rs @@ -1,9 +1,8 @@ //! Application-wide metrics. -use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics}; - use std::{fmt, time::Duration}; +use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics}; use zksync_dal::transactions_dal::L2TxSubmissionResult; use zksync_types::{aggregated_operations::AggregatedActionType, proofs::AggregationRound}; diff --git a/core/lib/zksync_core/src/proof_data_handler/mod.rs b/core/lib/zksync_core/src/proof_data_handler/mod.rs index 898ac4652ba..f1227d8298c 100644 --- a/core/lib/zksync_core/src/proof_data_handler/mod.rs +++ b/core/lib/zksync_core/src/proof_data_handler/mod.rs @@ -1,8 +1,7 @@ -use crate::proof_data_handler::request_processor::RequestProcessor; -use anyhow::Context as _; -use axum::extract::Path; -use axum::{routing::post, Json, Router}; use std::net::SocketAddr; + +use anyhow::Context as _; +use axum::{extract::Path, routing::post, Json, Router}; use tokio::sync::watch; use zksync_config::{ configs::{proof_data_handler::ProtocolVersionLoadingMode, ProofDataHandlerConfig}, @@ -16,6 +15,8 @@ use zksync_types::{ H256, }; +use crate::proof_data_handler::request_processor::RequestProcessor; + mod request_processor; fn fri_l1_verifier_config(contracts_config: &ContractsConfig) -> L1VerifierConfig { diff --git a/core/lib/zksync_core/src/proof_data_handler/request_processor.rs b/core/lib/zksync_core/src/proof_data_handler/request_processor.rs index 866990b31c9..5a3302ee926 100644 --- a/core/lib/zksync_core/src/proof_data_handler/request_processor.rs +++ b/core/lib/zksync_core/src/proof_data_handler/request_processor.rs @@ -1,26 +1,27 @@ -use axum::extract::Path; -use axum::response::Response; -use axum::{http::StatusCode, response::IntoResponse, Json}; -use std::convert::TryFrom; -use std::sync::Arc; +use std::{convert::TryFrom, sync::Arc}; + +use axum::{ + extract::Path, + http::StatusCode, + response::{IntoResponse, Response}, + Json, +}; use zksync_config::configs::{ proof_data_handler::ProtocolVersionLoadingMode, ProofDataHandlerConfig, }; -use zksync_types::commitment::serialize_commitments; -use zksync_types::web3::signing::keccak256; -use zksync_utils::u256_to_h256; - use zksync_dal::{ConnectionPool, SqlxError}; use zksync_object_store::{ObjectStore, ObjectStoreError}; -use zksync_types::protocol_version::FriProtocolVersionId; use zksync_types::{ - protocol_version::L1VerifierConfig, + commitment::serialize_commitments, + protocol_version::{FriProtocolVersionId, L1VerifierConfig}, prover_server_api::{ ProofGenerationData, ProofGenerationDataRequest, ProofGenerationDataResponse, SubmitProofRequest, SubmitProofResponse, }, + web3::signing::keccak256, L1BatchNumber, H256, }; +use zksync_utils::u256_to_h256; #[derive(Clone)] pub(crate) struct RequestProcessor { diff --git a/core/lib/zksync_core/src/reorg_detector/mod.rs b/core/lib/zksync_core/src/reorg_detector/mod.rs index 16137d40af6..cd399716c20 100644 --- a/core/lib/zksync_core/src/reorg_detector/mod.rs +++ b/core/lib/zksync_core/src/reorg_detector/mod.rs @@ -4,8 +4,10 @@ use tokio::sync::watch; use zksync_dal::ConnectionPool; use zksync_types::{L1BatchNumber, MiniblockNumber}; use zksync_web3_decl::{ - jsonrpsee::core::Error as RpcError, - jsonrpsee::http_client::{HttpClient, HttpClientBuilder}, + jsonrpsee::{ + core::Error as RpcError, + http_client::{HttpClient, HttpClientBuilder}, + }, namespaces::{EthNamespaceClient, ZksNamespaceClient}, RpcResult, }; diff --git a/core/lib/zksync_core/src/state_keeper/batch_executor/mod.rs b/core/lib/zksync_core/src/state_keeper/batch_executor/mod.rs index 389677b0439..2267792297f 100644 --- a/core/lib/zksync_core/src/state_keeper/batch_executor/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/batch_executor/mod.rs @@ -1,13 +1,6 @@ -use async_trait::async_trait; -use once_cell::sync::OnceCell; -use tokio::{ - sync::{mpsc, oneshot}, - task::JoinHandle, -}; - -use multivm::MultiVMTracer; use std::{fmt, sync::Arc}; +use async_trait::async_trait; use multivm::{ interface::{ ExecutionResult, FinishedL1Batch, Halt, L1BatchEnv, L2BlockEnv, SystemEnv, VmExecutionMode, @@ -15,16 +8,18 @@ use multivm::{ }, tracers::CallTracer, vm_latest::HistoryEnabled, - VmInstance, + MultiVMTracer, VmInstance, +}; +use once_cell::sync::OnceCell; +use tokio::{ + sync::{mpsc, oneshot}, + task::JoinHandle, }; use zksync_dal::ConnectionPool; use zksync_state::{RocksdbStorage, StorageView, WriteStorage}; use zksync_types::{vm_trace::Call, witness_block_state::WitnessBlockState, Transaction, U256}; use zksync_utils::bytecode::CompressedBytecodeInfo; -#[cfg(test)] -mod tests; - use crate::{ gas_tracker::{gas_count_from_metrics, gas_count_from_tx_and_metrics}, metrics::{InteractionType, TxStage, APP_METRICS}, @@ -34,6 +29,9 @@ use crate::{ }, }; +#[cfg(test)] +mod tests; + /// Representation of a transaction executed in the virtual machine. #[derive(Debug, Clone)] pub(crate) enum TxExecutionResult { diff --git a/core/lib/zksync_core/src/state_keeper/batch_executor/tests/mod.rs b/core/lib/zksync_core/src/state_keeper/batch_executor/tests/mod.rs index 05a8220bb83..362afe20437 100644 --- a/core/lib/zksync_core/src/state_keeper/batch_executor/tests/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/batch_executor/tests/mod.rs @@ -1,15 +1,13 @@ use assert_matches::assert_matches; - use zksync_dal::ConnectionPool; +use zksync_test_account::Account; use zksync_types::PriorityOpId; -mod tester; - use self::tester::Tester; use super::TxExecutionResult; use crate::state_keeper::batch_executor::tests::tester::{AccountLoadNextExecutable, TestConfig}; -use zksync_test_account::Account; +mod tester; /// Ensures that the transaction was executed successfully. fn assert_executed(execution_result: &TxExecutionResult) { diff --git a/core/lib/zksync_core/src/state_keeper/batch_executor/tests/tester.rs b/core/lib/zksync_core/src/state_keeper/batch_executor/tests/tester.rs index cd72f3eeb07..6417c65a5f8 100644 --- a/core/lib/zksync_core/src/state_keeper/batch_executor/tests/tester.rs +++ b/core/lib/zksync_core/src/state_keeper/batch_executor/tests/tester.rs @@ -1,11 +1,11 @@ //! Testing harness for the batch executor. //! Contains helper functionality to initialize test context and perform tests without too much boilerplate. +use multivm::{ + interface::{L1BatchEnv, SystemEnv}, + vm_latest::constants::INITIAL_STORAGE_WRITE_PUBDATA_BYTES, +}; use tempfile::TempDir; - -use multivm::interface::{L1BatchEnv, SystemEnv}; -use multivm::vm_latest::constants::INITIAL_STORAGE_WRITE_PUBDATA_BYTES; - use zksync_config::configs::chain::StateKeeperConfig; use zksync_contracts::{get_loadnext_contract, test_contracts::LoadnextContractExecutionParams}; use zksync_dal::ConnectionPool; @@ -19,10 +19,12 @@ use zksync_types::{ }; use zksync_utils::u256_to_h256; -use crate::genesis::create_genesis_l1_batch; -use crate::state_keeper::{ - batch_executor::BatchExecutorHandle, - tests::{default_l1_batch_env, default_system_env, BASE_SYSTEM_CONTRACTS}, +use crate::{ + genesis::create_genesis_l1_batch, + state_keeper::{ + batch_executor::BatchExecutorHandle, + tests::{default_l1_batch_env, default_system_env, BASE_SYSTEM_CONTRACTS}, + }, }; const DEFAULT_GAS_PER_PUBDATA: u32 = 100; diff --git a/core/lib/zksync_core/src/state_keeper/extractors.rs b/core/lib/zksync_core/src/state_keeper/extractors.rs index e542b5b0959..e31020734f5 100644 --- a/core/lib/zksync_core/src/state_keeper/extractors.rs +++ b/core/lib/zksync_core/src/state_keeper/extractors.rs @@ -1,13 +1,12 @@ //! Pure functions that convert data as required by the state keeper. -use chrono::{DateTime, TimeZone, Utc}; - use std::{ convert::TryFrom, fmt, time::{Duration, Instant}, }; +use chrono::{DateTime, TimeZone, Utc}; use zksync_dal::StorageProcessor; use zksync_types::{L1BatchNumber, U256}; use zksync_utils::h256_to_u256; diff --git a/core/lib/zksync_core/src/state_keeper/io/common.rs b/core/lib/zksync_core/src/state_keeper/io/common.rs index c99508322ef..857c7618d11 100644 --- a/core/lib/zksync_core/src/state_keeper/io/common.rs +++ b/core/lib/zksync_core/src/state_keeper/io/common.rs @@ -1,7 +1,9 @@ use std::time::Duration; -use multivm::interface::{L1BatchEnv, L2BlockEnv, SystemEnv, TxExecutionMode}; -use multivm::vm_latest::constants::BLOCK_GAS_LIMIT; +use multivm::{ + interface::{L1BatchEnv, L2BlockEnv, SystemEnv, TxExecutionMode}, + vm_latest::constants::BLOCK_GAS_LIMIT, +}; use zksync_contracts::BaseSystemContracts; use zksync_dal::StorageProcessor; use zksync_types::{ diff --git a/core/lib/zksync_core/src/state_keeper/io/mempool.rs b/core/lib/zksync_core/src/state_keeper/io/mempool.rs index 1d3ad506df6..f5a4df1c333 100644 --- a/core/lib/zksync_core/src/state_keeper/io/mempool.rs +++ b/core/lib/zksync_core/src/state_keeper/io/mempool.rs @@ -1,5 +1,3 @@ -use async_trait::async_trait; - use std::{ cmp, collections::HashMap, @@ -7,9 +5,11 @@ use std::{ time::{Duration, Instant}, }; -use multivm::interface::{FinishedL1Batch, L1BatchEnv, SystemEnv}; -use multivm::vm_latest::utils::fee::derive_base_fee_and_gas_per_pubdata; - +use async_trait::async_trait; +use multivm::{ + interface::{FinishedL1Batch, L1BatchEnv, SystemEnv}, + vm_latest::utils::fee::derive_base_fee_and_gas_per_pubdata, +}; use zksync_config::configs::chain::StateKeeperConfig; use zksync_dal::ConnectionPool; use zksync_mempool::L2TxFilter; @@ -526,7 +526,6 @@ impl MempoolIO { #[cfg(test)] mod tests { use tokio::time::timeout_at; - use zksync_utils::time::seconds_since_epoch; use super::*; diff --git a/core/lib/zksync_core/src/state_keeper/io/mod.rs b/core/lib/zksync_core/src/state_keeper/io/mod.rs index 313c363418d..d1366858116 100644 --- a/core/lib/zksync_core/src/state_keeper/io/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/io/mod.rs @@ -1,13 +1,11 @@ -use async_trait::async_trait; -use tokio::sync::{mpsc, oneshot}; - use std::{ fmt, time::{Duration, Instant}, }; +use async_trait::async_trait; use multivm::interface::{FinishedL1Batch, L1BatchEnv, SystemEnv}; - +use tokio::sync::{mpsc, oneshot}; use zksync_dal::ConnectionPool; use zksync_types::{ block::MiniblockExecutionData, protocol_version::ProtocolUpgradeTx, @@ -15,10 +13,6 @@ use zksync_types::{ Transaction, }; -pub(crate) mod common; -pub(crate) mod mempool; -pub(crate) mod seal_logic; - pub(crate) use self::mempool::MempoolIO; use super::{ metrics::{MiniblockQueueStage, MINIBLOCK_METRICS}, @@ -26,6 +20,9 @@ use super::{ updates::{MiniblockSealCommand, UpdatesManager}, }; +pub(crate) mod common; +pub(crate) mod mempool; +pub(crate) mod seal_logic; #[cfg(test)] mod tests; diff --git a/core/lib/zksync_core/src/state_keeper/io/seal_logic.rs b/core/lib/zksync_core/src/state_keeper/io/seal_logic.rs index 4501be62f78..e152709cff5 100644 --- a/core/lib/zksync_core/src/state_keeper/io/seal_logic.rs +++ b/core/lib/zksync_core/src/state_keeper/io/seal_logic.rs @@ -1,26 +1,21 @@ //! This module is a source-of-truth on what is expected to be done when sealing a block. //! It contains the logic of the block sealing, which is used by both the mempool-based and external node IO. -use itertools::Itertools; use std::{ collections::HashMap, time::{Duration, Instant}, }; +use itertools::Itertools; use multivm::interface::{FinishedL1Batch, L1BatchEnv}; -use zksync_dal::blocks_dal::ConsensusBlockFields; -use zksync_dal::StorageProcessor; +use zksync_dal::{blocks_dal::ConsensusBlockFields, StorageProcessor}; use zksync_system_constants::ACCOUNT_CODE_STORAGE_ADDRESS; use zksync_types::{ - block::unpack_block_info, - l2_to_l1_log::{SystemL2ToL1Log, UserL2ToL1Log}, - CURRENT_VIRTUAL_BLOCK_INFO_POSITION, SYSTEM_CONTEXT_ADDRESS, -}; -use zksync_types::{ - block::{L1BatchHeader, MiniblockHeader}, + block::{unpack_block_info, L1BatchHeader, MiniblockHeader}, event::{extract_added_tokens, extract_long_l2_to_l1_messages}, l1::L1Tx, l2::L2Tx, + l2_to_l1_log::{SystemL2ToL1Log, UserL2ToL1Log}, protocol_version::ProtocolUpgradeTx, storage_writes_deduplicator::{ModifiedSlot, StorageWritesDeduplicator}, tx::{ @@ -30,7 +25,7 @@ use zksync_types::{ zkevm_test_harness::witness::sort_storage_access::sort_storage_access_queries, AccountTreeId, Address, ExecuteTransactionCommon, L1BatchNumber, L1BlockNumber, LogQuery, MiniblockNumber, StorageKey, StorageLog, StorageLogQuery, StorageValue, Transaction, VmEvent, - H256, + CURRENT_VIRTUAL_BLOCK_INFO_POSITION, H256, SYSTEM_CONTEXT_ADDRESS, }; // TODO (SMA-1206): use seconds instead of milliseconds. use zksync_utils::{h256_to_u256, time::millis_since_epoch, u256_to_h256}; diff --git a/core/lib/zksync_core/src/state_keeper/io/tests/mod.rs b/core/lib/zksync_core/src/state_keeper/io/tests/mod.rs index 2b924554f27..ef8c5424854 100644 --- a/core/lib/zksync_core/src/state_keeper/io/tests/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/io/tests/mod.rs @@ -1,7 +1,6 @@ -use futures::FutureExt; - use std::time::Duration; +use futures::FutureExt; use multivm::vm_latest::utils::fee::derive_base_fee_and_gas_per_pubdata; use zksync_contracts::BaseSystemContractsHashes; use zksync_dal::ConnectionPool; @@ -12,22 +11,19 @@ use zksync_types::{ }; use zksync_utils::time::seconds_since_epoch; -use crate::state_keeper::tests::{create_l1_batch_metadata, default_l1_batch_env}; - +use self::tester::Tester; use crate::state_keeper::{ io::{MiniblockParams, MiniblockSealer, StateKeeperIO}, mempool_actor::l2_tx_filter, tests::{ - create_execution_result, create_transaction, create_updates_manager, - default_vm_block_result, Query, + create_execution_result, create_l1_batch_metadata, create_transaction, + create_updates_manager, default_l1_batch_env, default_vm_block_result, Query, }, updates::{MiniblockSealCommand, MiniblockUpdates, UpdatesManager}, }; mod tester; -use self::tester::Tester; - /// Ensure that MempoolIO.filter is correctly initialized right after mempool initialization. #[tokio::test] async fn test_filter_initialization() { diff --git a/core/lib/zksync_core/src/state_keeper/io/tests/tester.rs b/core/lib/zksync_core/src/state_keeper/io/tests/tester.rs index 875bf89e048..5528ae9f206 100644 --- a/core/lib/zksync_core/src/state_keeper/io/tests/tester.rs +++ b/core/lib/zksync_core/src/state_keeper/io/tests/tester.rs @@ -1,14 +1,13 @@ //! Testing harness for the IO. -use multivm::vm_latest::constants::BLOCK_GAS_LIMIT; use std::{sync::Arc, time::Duration}; -use zksync_object_store::ObjectStoreFactory; -use zksync_config::configs::chain::StateKeeperConfig; -use zksync_config::GasAdjusterConfig; +use multivm::vm_latest::constants::BLOCK_GAS_LIMIT; +use zksync_config::{configs::chain::StateKeeperConfig, GasAdjusterConfig}; use zksync_contracts::BaseSystemContracts; use zksync_dal::ConnectionPool; use zksync_eth_client::clients::mock::MockEthereum; +use zksync_object_store::ObjectStoreFactory; use zksync_types::{ block::{L1BatchHeader, MiniblockHeader}, protocol_version::L1VerifierConfig, diff --git a/core/lib/zksync_core/src/state_keeper/keeper.rs b/core/lib/zksync_core/src/state_keeper/keeper.rs index 761e186e7ae..3cc153120c2 100644 --- a/core/lib/zksync_core/src/state_keeper/keeper.rs +++ b/core/lib/zksync_core/src/state_keeper/keeper.rs @@ -1,10 +1,11 @@ -use anyhow::Context as _; -use tokio::sync::watch; - -use std::convert::Infallible; -use std::time::{Duration, Instant}; +use std::{ + convert::Infallible, + time::{Duration, Instant}, +}; +use anyhow::Context as _; use multivm::interface::{Halt, L1BatchEnv, SystemEnv}; +use tokio::sync::watch; use zksync_types::{ block::MiniblockExecutionData, l2::TransactionType, protocol_version::ProtocolUpgradeTx, storage_writes_deduplicator::StorageWritesDeduplicator, Transaction, diff --git a/core/lib/zksync_core/src/state_keeper/mempool_actor.rs b/core/lib/zksync_core/src/state_keeper/mempool_actor.rs index 2c369d35a0f..4797ed0006c 100644 --- a/core/lib/zksync_core/src/state_keeper/mempool_actor.rs +++ b/core/lib/zksync_core/src/state_keeper/mempool_actor.rs @@ -1,8 +1,7 @@ -use tokio::sync::watch; - use std::{sync::Arc, time::Duration}; use multivm::vm_latest::utils::fee::derive_base_fee_and_gas_per_pubdata; +use tokio::sync::watch; use zksync_config::configs::chain::MempoolConfig; use zksync_dal::ConnectionPool; use zksync_mempool::L2TxFilter; diff --git a/core/lib/zksync_core/src/state_keeper/metrics.rs b/core/lib/zksync_core/src/state_keeper/metrics.rs index 72b89c4a2b8..8daccb5a3aa 100644 --- a/core/lib/zksync_core/src/state_keeper/metrics.rs +++ b/core/lib/zksync_core/src/state_keeper/metrics.rs @@ -1,15 +1,14 @@ //! General-purpose state keeper metrics. -use vise::{ - Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, LatencyObserver, - Metrics, -}; - use std::{ sync::{Mutex, Weak}, time::Duration, }; +use vise::{ + Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, LatencyObserver, + Metrics, +}; use zksync_mempool::MempoolStore; use super::seal_criteria::SealResolution; diff --git a/core/lib/zksync_core/src/state_keeper/mod.rs b/core/lib/zksync_core/src/state_keeper/mod.rs index 5ec395267df..ee71a93bcf4 100644 --- a/core/lib/zksync_core/src/state_keeper/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/mod.rs @@ -1,15 +1,25 @@ -use tokio::sync::watch; -use zksync_object_store::ObjectStore; - use std::sync::Arc; +use tokio::sync::watch; use zksync_config::{ configs::chain::{MempoolConfig, NetworkConfig, StateKeeperConfig}, ContractsConfig, DBConfig, }; use zksync_dal::ConnectionPool; +use zksync_object_store::ObjectStore; use zksync_system_constants::MAX_TXS_IN_BLOCK; +use self::io::MempoolIO; +pub use self::{ + batch_executor::{L1BatchExecutorBuilder, MainBatchExecutorBuilder}, + io::{MiniblockSealer, MiniblockSealerHandle}, + keeper::ZkSyncStateKeeper, +}; +pub(crate) use self::{ + mempool_actor::MempoolFetcher, seal_criteria::ConditionalSealer, types::MempoolGuard, +}; +use crate::l1_gas_price::L1GasPriceProvider; + mod batch_executor; pub(crate) mod extractors; pub(crate) mod io; @@ -22,18 +32,6 @@ pub(crate) mod tests; pub(crate) mod types; pub(crate) mod updates; -pub use self::{ - batch_executor::{L1BatchExecutorBuilder, MainBatchExecutorBuilder}, - io::{MiniblockSealer, MiniblockSealerHandle}, - keeper::ZkSyncStateKeeper, -}; -pub(crate) use self::{ - mempool_actor::MempoolFetcher, seal_criteria::ConditionalSealer, types::MempoolGuard, -}; - -use self::io::MempoolIO; -use crate::l1_gas_price::L1GasPriceProvider; - #[allow(clippy::too_many_arguments)] pub(crate) async fn create_state_keeper( contracts_config: &ContractsConfig, diff --git a/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/geometry_seal_criteria.rs b/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/geometry_seal_criteria.rs index 1ec0c66e4d7..9f99554e58a 100644 --- a/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/geometry_seal_criteria.rs +++ b/core/lib/zksync_core/src/state_keeper/seal_criteria/criteria/geometry_seal_criteria.rs @@ -1,5 +1,6 @@ -use multivm::vm_latest::constants::{ERGS_PER_CIRCUIT, MAX_CYCLES_FOR_TX}; use std::fmt; + +use multivm::vm_latest::constants::{ERGS_PER_CIRCUIT, MAX_CYCLES_FOR_TX}; use zksync_config::configs::chain::StateKeeperConfig; use zksync_types::{ circuit::{GEOMETRY_CONFIG, SCHEDULER_UPPER_BOUND}, diff --git a/core/lib/zksync_core/src/state_keeper/tests/mod.rs b/core/lib/zksync_core/src/state_keeper/tests/mod.rs index c5841fd8b1b..06411ecaa55 100644 --- a/core/lib/zksync_core/src/state_keeper/tests/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/tests/mod.rs @@ -1,5 +1,3 @@ -use once_cell::sync::Lazy; - use std::{ sync::{ atomic::{AtomicBool, AtomicU64, Ordering}, @@ -8,11 +6,14 @@ use std::{ time::Instant, }; -use multivm::interface::{ - CurrentExecutionState, ExecutionResult, FinishedL1Batch, L1BatchEnv, L2BlockEnv, Refunds, - SystemEnv, TxExecutionMode, VmExecutionResultAndLogs, VmExecutionStatistics, +use multivm::{ + interface::{ + CurrentExecutionState, ExecutionResult, FinishedL1Batch, L1BatchEnv, L2BlockEnv, Refunds, + SystemEnv, TxExecutionMode, VmExecutionResultAndLogs, VmExecutionStatistics, + }, + vm_latest::{constants::BLOCK_GAS_LIMIT, VmExecutionLogs}, }; -use multivm::vm_latest::{constants::BLOCK_GAS_LIMIT, VmExecutionLogs}; +use once_cell::sync::Lazy; use zksync_config::configs::chain::StateKeeperConfig; use zksync_contracts::{BaseSystemContracts, BaseSystemContractsHashes}; use zksync_system_constants::ZKPORTER_IS_AVAILABLE; @@ -28,24 +29,26 @@ use zksync_types::{ StorageLogQuery, StorageLogQueryType, Timestamp, Transaction, H256, U256, }; -mod tester; - pub(crate) use self::tester::TestBatchExecutorBuilder; use self::tester::{ bootloader_tip_out_of_gas, pending_batch_data, random_tx, rejected_exec, successful_exec, successful_exec_with_metrics, TestScenario, }; -use crate::gas_tracker::l1_batch_base_cost; -use crate::state_keeper::{ - keeper::POLL_WAIT_DURATION, - seal_criteria::{ - criteria::{GasCriterion, SlotsCriterion}, - ConditionalSealer, +use crate::{ + gas_tracker::l1_batch_base_cost, + state_keeper::{ + keeper::POLL_WAIT_DURATION, + seal_criteria::{ + criteria::{GasCriterion, SlotsCriterion}, + ConditionalSealer, + }, + types::ExecutionMetricsForCriteria, + updates::UpdatesManager, }, - types::ExecutionMetricsForCriteria, - updates::UpdatesManager, }; +mod tester; + pub(super) static BASE_SYSTEM_CONTRACTS: Lazy = Lazy::new(BaseSystemContracts::load_from_disk); diff --git a/core/lib/zksync_core/src/state_keeper/tests/tester.rs b/core/lib/zksync_core/src/state_keeper/tests/tester.rs index 8d0d1fb047e..a2dc7f05c5e 100644 --- a/core/lib/zksync_core/src/state_keeper/tests/tester.rs +++ b/core/lib/zksync_core/src/state_keeper/tests/tester.rs @@ -1,6 +1,3 @@ -use async_trait::async_trait; -use tokio::sync::{mpsc, watch}; - use std::{ collections::{HashMap, HashSet, VecDeque}, convert::TryInto, @@ -8,11 +5,15 @@ use std::{ time::{Duration, Instant}, }; -use multivm::interface::{ - ExecutionResult, FinishedL1Batch, L1BatchEnv, L2BlockEnv, SystemEnv, TxExecutionMode, - VmExecutionResultAndLogs, +use async_trait::async_trait; +use multivm::{ + interface::{ + ExecutionResult, FinishedL1Batch, L1BatchEnv, L2BlockEnv, SystemEnv, TxExecutionMode, + VmExecutionResultAndLogs, + }, + vm_latest::constants::BLOCK_GAS_LIMIT, }; -use multivm::vm_latest::constants::BLOCK_GAS_LIMIT; +use tokio::sync::{mpsc, watch}; use zksync_types::{ block::MiniblockExecutionData, protocol_version::ProtocolUpgradeTx, witness_block_state::WitnessBlockState, Address, L1BatchNumber, L2ChainId, MiniblockNumber, diff --git a/core/lib/zksync_core/src/state_keeper/updates/l1_batch_updates.rs b/core/lib/zksync_core/src/state_keeper/updates/l1_batch_updates.rs index fdaa0b036f9..584a0c835e7 100644 --- a/core/lib/zksync_core/src/state_keeper/updates/l1_batch_updates.rs +++ b/core/lib/zksync_core/src/state_keeper/updates/l1_batch_updates.rs @@ -1,9 +1,12 @@ +use zksync_types::{ + block::BlockGasCount, + priority_op_onchain_data::PriorityOpOnchainData, + tx::{tx_execution_info::ExecutionMetrics, TransactionExecutionResult}, + ExecuteTransactionCommon, +}; + use super::miniblock_updates::MiniblockUpdates; use crate::gas_tracker::new_block_gas_count; -use zksync_types::block::BlockGasCount; -use zksync_types::priority_op_onchain_data::PriorityOpOnchainData; -use zksync_types::tx::tx_execution_info::ExecutionMetrics; -use zksync_types::{tx::TransactionExecutionResult, ExecuteTransactionCommon}; #[derive(Debug, Clone, PartialEq)] pub struct L1BatchUpdates { @@ -44,6 +47,7 @@ impl L1BatchUpdates { #[cfg(test)] mod tests { + use multivm::vm_latest::TransactionVmExt; use zksync_types::{ProtocolVersionId, H256}; use super::*; @@ -51,7 +55,6 @@ mod tests { gas_tracker::new_block_gas_count, state_keeper::tests::{create_execution_result, create_transaction}, }; - use multivm::vm_latest::TransactionVmExt; #[test] fn apply_miniblock_with_empty_tx() { diff --git a/core/lib/zksync_core/src/state_keeper/updates/miniblock_updates.rs b/core/lib/zksync_core/src/state_keeper/updates/miniblock_updates.rs index d0a4f035f51..0c8591a2898 100644 --- a/core/lib/zksync_core/src/state_keeper/updates/miniblock_updates.rs +++ b/core/lib/zksync_core/src/state_keeper/updates/miniblock_updates.rs @@ -1,18 +1,21 @@ -use multivm::interface::{ExecutionResult, L2BlockEnv, VmExecutionResultAndLogs}; -use multivm::vm_latest::TransactionVmExt; use std::collections::HashMap; -use zksync_types::l2_to_l1_log::{SystemL2ToL1Log, UserL2ToL1Log}; +use multivm::{ + interface::{ExecutionResult, L2BlockEnv, VmExecutionResultAndLogs}, + vm_latest::TransactionVmExt, +}; use zksync_types::{ block::{legacy_miniblock_hash, miniblock_hash, BlockGasCount}, event::extract_bytecodes_marked_as_known, - tx::tx_execution_info::TxExecutionStatus, - tx::{ExecutionMetrics, TransactionExecutionResult}, + l2_to_l1_log::{SystemL2ToL1Log, UserL2ToL1Log}, + tx::{tx_execution_info::TxExecutionStatus, ExecutionMetrics, TransactionExecutionResult}, vm_trace::Call, MiniblockNumber, ProtocolVersionId, StorageLogQuery, Transaction, VmEvent, H256, }; -use zksync_utils::bytecode::{hash_bytecode, CompressedBytecodeInfo}; -use zksync_utils::concat_and_hash; +use zksync_utils::{ + bytecode::{hash_bytecode, CompressedBytecodeInfo}, + concat_and_hash, +}; #[derive(Debug, Clone, PartialEq)] pub struct MiniblockUpdates { @@ -168,9 +171,10 @@ impl MiniblockUpdates { #[cfg(test)] mod tests { + use multivm::vm_latest::TransactionVmExt; + use super::*; use crate::state_keeper::tests::{create_execution_result, create_transaction}; - use multivm::vm_latest::TransactionVmExt; #[test] fn apply_empty_l2_tx() { diff --git a/core/lib/zksync_core/src/state_keeper/updates/mod.rs b/core/lib/zksync_core/src/state_keeper/updates/mod.rs index 3f09f7be30b..c34164557b5 100644 --- a/core/lib/zksync_core/src/state_keeper/updates/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/updates/mod.rs @@ -1,22 +1,19 @@ use multivm::interface::{L1BatchEnv, VmExecutionResultAndLogs}; - use zksync_contracts::BaseSystemContractsHashes; use zksync_dal::blocks_dal::ConsensusBlockFields; -use zksync_types::vm_trace::Call; use zksync_types::{ block::BlockGasCount, storage_writes_deduplicator::StorageWritesDeduplicator, - tx::tx_execution_info::ExecutionMetrics, Address, L1BatchNumber, MiniblockNumber, - ProtocolVersionId, Transaction, + tx::tx_execution_info::ExecutionMetrics, vm_trace::Call, Address, L1BatchNumber, + MiniblockNumber, ProtocolVersionId, Transaction, }; use zksync_utils::bytecode::CompressedBytecodeInfo; -pub mod l1_batch_updates; -pub mod miniblock_updates; - pub(crate) use self::{l1_batch_updates::L1BatchUpdates, miniblock_updates::MiniblockUpdates}; - use super::io::MiniblockParams; +pub mod l1_batch_updates; +pub mod miniblock_updates; + /// Most of the information needed to seal the l1 batch/mini-block is contained within the VM, /// things that are not captured there are accumulated externally. /// `MiniblockUpdates` keeps updates for the pending mini-block. diff --git a/core/lib/zksync_core/src/sync_layer/batch_status_updater.rs b/core/lib/zksync_core/src/sync_layer/batch_status_updater.rs index 8e7ebe7a985..8924fa5c5db 100644 --- a/core/lib/zksync_core/src/sync_layer/batch_status_updater.rs +++ b/core/lib/zksync_core/src/sync_layer/batch_status_updater.rs @@ -1,8 +1,7 @@ -use chrono::{DateTime, Utc}; -use tokio::sync::watch::Receiver; - use std::time::Duration; +use chrono::{DateTime, Utc}; +use tokio::sync::watch::Receiver; use zksync_dal::ConnectionPool; use zksync_types::{ aggregated_operations::AggregatedActionType, api::BlockDetails, L1BatchNumber, MiniblockNumber, diff --git a/core/lib/zksync_core/src/sync_layer/client.rs b/core/lib/zksync_core/src/sync_layer/client.rs index 5d4f61a4f2a..a13fba2d65c 100644 --- a/core/lib/zksync_core/src/sync_layer/client.rs +++ b/core/lib/zksync_core/src/sync_layer/client.rs @@ -1,10 +1,9 @@ //! Client abstractions for syncing between the external node and the main node. -use anyhow::Context as _; -use async_trait::async_trait; - use std::{collections::HashMap, convert::TryInto, fmt}; +use anyhow::Context as _; +use async_trait::async_trait; use zksync_contracts::{BaseSystemContracts, BaseSystemContractsHashes, SystemContractCode}; use zksync_system_constants::ACCOUNT_CODE_STORAGE_ADDRESS; use zksync_types::{ diff --git a/core/lib/zksync_core/src/sync_layer/external_io.rs b/core/lib/zksync_core/src/sync_layer/external_io.rs index 4e870b95674..d751cdc8d01 100644 --- a/core/lib/zksync_core/src/sync_layer/external_io.rs +++ b/core/lib/zksync_core/src/sync_layer/external_io.rs @@ -1,8 +1,7 @@ -use async_trait::async_trait; -use futures::future; - use std::{collections::HashMap, convert::TryInto, iter::FromIterator, time::Duration}; +use async_trait::async_trait; +use futures::future; use multivm::interface::{FinishedL1Batch, L1BatchEnv, SystemEnv}; use zksync_contracts::{BaseSystemContracts, SystemContractCode}; use zksync_dal::ConnectionPool; diff --git a/core/lib/zksync_core/src/sync_layer/fetcher.rs b/core/lib/zksync_core/src/sync_layer/fetcher.rs index 3adbc8920bf..2989b6b70a3 100644 --- a/core/lib/zksync_core/src/sync_layer/fetcher.rs +++ b/core/lib/zksync_core/src/sync_layer/fetcher.rs @@ -1,8 +1,7 @@ -use anyhow::Context as _; -use tokio::sync::watch; - use std::time::Duration; +use anyhow::Context as _; +use tokio::sync::watch; use zksync_dal::{blocks_dal::ConsensusBlockFields, StorageProcessor}; use zksync_types::{ api::en::SyncBlock, Address, L1BatchNumber, MiniblockNumber, ProtocolVersionId, diff --git a/core/lib/zksync_core/src/sync_layer/genesis.rs b/core/lib/zksync_core/src/sync_layer/genesis.rs index 4f7501fb0c3..77678a3b412 100644 --- a/core/lib/zksync_core/src/sync_layer/genesis.rs +++ b/core/lib/zksync_core/src/sync_layer/genesis.rs @@ -1,5 +1,4 @@ use anyhow::Context as _; - use zksync_dal::StorageProcessor; use zksync_types::{ block::DeployedContract, protocol_version::L1VerifierConfig, diff --git a/core/lib/zksync_core/src/sync_layer/gossip/buffered/mod.rs b/core/lib/zksync_core/src/sync_layer/gossip/buffered/mod.rs index 41ca50e1cf2..5f2308930a3 100644 --- a/core/lib/zksync_core/src/sync_layer/gossip/buffered/mod.rs +++ b/core/lib/zksync_core/src/sync_layer/gossip/buffered/mod.rs @@ -1,9 +1,8 @@ //! Buffered [`BlockStore`] implementation. -use async_trait::async_trait; - use std::{collections::BTreeMap, ops, time::Instant}; +use async_trait::async_trait; #[cfg(test)] use zksync_concurrency::ctx::channel; use zksync_concurrency::{ @@ -13,14 +12,14 @@ use zksync_concurrency::{ use zksync_consensus_roles::validator::{BlockNumber, FinalBlock}; use zksync_consensus_storage::{BlockStore, StorageError, StorageResult, WriteBlockStore}; -#[cfg(test)] -mod tests; - use super::{ metrics::{BlockResponseKind, METRICS}, utils::MissingBlockNumbers, }; +#[cfg(test)] +mod tests; + /// [`BlockStore`] variation that upholds additional invariants as to how blocks are processed. /// /// The invariants are as follows: diff --git a/core/lib/zksync_core/src/sync_layer/gossip/buffered/tests.rs b/core/lib/zksync_core/src/sync_layer/gossip/buffered/tests.rs index 62c81bca7ca..c5fd860ab87 100644 --- a/core/lib/zksync_core/src/sync_layer/gossip/buffered/tests.rs +++ b/core/lib/zksync_core/src/sync_layer/gossip/buffered/tests.rs @@ -1,12 +1,11 @@ //! Tests for buffered storage. +use std::{iter, ops}; + use assert_matches::assert_matches; use async_trait::async_trait; use rand::{rngs::StdRng, seq::SliceRandom, Rng}; use test_casing::test_casing; - -use std::{iter, ops}; - use zksync_concurrency::{ ctx::{self, channel}, scope, diff --git a/core/lib/zksync_core/src/sync_layer/gossip/conversions.rs b/core/lib/zksync_core/src/sync_layer/gossip/conversions.rs index 00c6c651452..616a4283c73 100644 --- a/core/lib/zksync_core/src/sync_layer/gossip/conversions.rs +++ b/core/lib/zksync_core/src/sync_layer/gossip/conversions.rs @@ -1,6 +1,6 @@ //! Conversion logic between server and consensus types. -use anyhow::Context as _; +use anyhow::Context as _; use zksync_consensus_roles::validator::{BlockHeader, BlockNumber, FinalBlock}; use zksync_dal::blocks_dal::ConsensusBlockFields; use zksync_types::{api::en, MiniblockNumber, ProtocolVersionId}; diff --git a/core/lib/zksync_core/src/sync_layer/gossip/metrics.rs b/core/lib/zksync_core/src/sync_layer/gossip/metrics.rs index f67c150b99c..73caf510269 100644 --- a/core/lib/zksync_core/src/sync_layer/gossip/metrics.rs +++ b/core/lib/zksync_core/src/sync_layer/gossip/metrics.rs @@ -1,9 +1,9 @@ //! Metrics for gossip-powered syncing. -use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics, Unit}; - use std::time::Duration; +use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics, Unit}; + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "kind", rename_all = "snake_case")] pub(super) enum BlockResponseKind { diff --git a/core/lib/zksync_core/src/sync_layer/gossip/mod.rs b/core/lib/zksync_core/src/sync_layer/gossip/mod.rs index 2ec9ca5b60e..9d769ab65f3 100644 --- a/core/lib/zksync_core/src/sync_layer/gossip/mod.rs +++ b/core/lib/zksync_core/src/sync_layer/gossip/mod.rs @@ -1,15 +1,17 @@ //! Consensus adapter for EN synchronization logic. -use anyhow::Context as _; -use tokio::sync::watch; - use std::sync::Arc; +use anyhow::Context as _; +use tokio::sync::watch; use zksync_concurrency::{ctx, scope}; use zksync_consensus_executor::{Executor, ExecutorConfig}; use zksync_consensus_roles::node; use zksync_dal::ConnectionPool; +use self::{buffered::Buffered, storage::PostgresBlockStorage}; +use super::{fetcher::FetcherCursor, sync_action::ActionQueueSender}; + mod buffered; mod conversions; mod metrics; @@ -18,9 +20,6 @@ mod storage; mod tests; mod utils; -use self::{buffered::Buffered, storage::PostgresBlockStorage}; -use super::{fetcher::FetcherCursor, sync_action::ActionQueueSender}; - /// Starts fetching L2 blocks using peer-to-peer gossip network. pub async fn run_gossip_fetcher( pool: ConnectionPool, diff --git a/core/lib/zksync_core/src/sync_layer/gossip/storage/mod.rs b/core/lib/zksync_core/src/sync_layer/gossip/storage/mod.rs index db36f71d35c..1e35d17daaf 100644 --- a/core/lib/zksync_core/src/sync_layer/gossip/storage/mod.rs +++ b/core/lib/zksync_core/src/sync_layer/gossip/storage/mod.rs @@ -1,10 +1,9 @@ //! Storage implementation based on DAL. -use anyhow::Context as _; -use async_trait::async_trait; - use std::ops; +use anyhow::Context as _; +use async_trait::async_trait; use zksync_concurrency::{ ctx, sync::{self, watch, Mutex}, @@ -12,13 +11,9 @@ use zksync_concurrency::{ }; use zksync_consensus_roles::validator::{BlockNumber, FinalBlock}; use zksync_consensus_storage::{BlockStore, StorageError, StorageResult}; -use zksync_dal::blocks_dal::ConsensusBlockFields; -use zksync_dal::{ConnectionPool, StorageProcessor}; +use zksync_dal::{blocks_dal::ConsensusBlockFields, ConnectionPool, StorageProcessor}; use zksync_types::{api::en::SyncBlock, Address, MiniblockNumber}; -#[cfg(test)] -mod tests; - use super::{buffered::ContiguousBlockStore, conversions::sync_block_to_consensus_block}; use crate::{ consensus, @@ -28,6 +23,9 @@ use crate::{ }, }; +#[cfg(test)] +mod tests; + #[derive(Debug)] struct CursorWithCachedBlock { inner: FetcherCursor, diff --git a/core/lib/zksync_core/src/sync_layer/gossip/storage/tests.rs b/core/lib/zksync_core/src/sync_layer/gossip/storage/tests.rs index cfd14f78411..c7e53f6456e 100644 --- a/core/lib/zksync_core/src/sync_layer/gossip/storage/tests.rs +++ b/core/lib/zksync_core/src/sync_layer/gossip/storage/tests.rs @@ -1,7 +1,6 @@ //! Tests for Postgres storage implementation. use rand::{thread_rng, Rng}; - use zksync_concurrency::{scope, testonly::abort_on_panic}; use zksync_consensus_roles::validator; use zksync_types::L2ChainId; diff --git a/core/lib/zksync_core/src/sync_layer/gossip/tests.rs b/core/lib/zksync_core/src/sync_layer/gossip/tests.rs index ddb97484968..338fc9016f4 100644 --- a/core/lib/zksync_core/src/sync_layer/gossip/tests.rs +++ b/core/lib/zksync_core/src/sync_layer/gossip/tests.rs @@ -1,16 +1,14 @@ //! Tests for consensus adapters for EN synchronization logic. -use assert_matches::assert_matches; -use test_casing::{test_casing, Product}; - use std::ops; +use assert_matches::assert_matches; +use test_casing::{test_casing, Product}; use zksync_concurrency::{ctx, scope, testonly::abort_on_panic, time}; use zksync_consensus_executor::testonly::FullValidatorConfig; use zksync_consensus_roles::validator::{self, FinalBlock}; use zksync_consensus_storage::{InMemoryStorage, WriteBlockStore}; -use zksync_dal::blocks_dal::ConsensusBlockFields; -use zksync_dal::{ConnectionPool, StorageProcessor}; +use zksync_dal::{blocks_dal::ConsensusBlockFields, ConnectionPool, StorageProcessor}; use zksync_types::{ api::en::SyncBlock, Address, L1BatchNumber, MiniblockNumber, ProtocolVersionId, H256, }; diff --git a/core/lib/zksync_core/src/sync_layer/metrics.rs b/core/lib/zksync_core/src/sync_layer/metrics.rs index c3082c51052..3a431294b25 100644 --- a/core/lib/zksync_core/src/sync_layer/metrics.rs +++ b/core/lib/zksync_core/src/sync_layer/metrics.rs @@ -1,9 +1,9 @@ //! Metrics for the synchronization layer of external node. -use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics}; - use std::time::Duration; +use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics}; + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] #[metrics(label = "stage", rename_all = "snake_case")] pub(super) enum FetchStage { diff --git a/core/lib/zksync_core/src/sync_layer/tests.rs b/core/lib/zksync_core/src/sync_layer/tests.rs index 10582c7d9f9..3c76e05d93f 100644 --- a/core/lib/zksync_core/src/sync_layer/tests.rs +++ b/core/lib/zksync_core/src/sync_layer/tests.rs @@ -1,14 +1,13 @@ //! High-level sync layer tests. -use async_trait::async_trait; -use tokio::{sync::watch, task::JoinHandle}; - use std::{ collections::{HashMap, VecDeque}, iter, time::{Duration, Instant}, }; +use async_trait::async_trait; +use tokio::{sync::watch, task::JoinHandle}; use zksync_config::configs::chain::NetworkConfig; use zksync_contracts::{BaseSystemContractsHashes, SystemContractCode}; use zksync_dal::{ConnectionPool, StorageProcessor}; diff --git a/core/lib/zksync_core/src/witness_generator/basic_circuits.rs b/core/lib/zksync_core/src/witness_generator/basic_circuits.rs index c700d59120a..e4d8b01357d 100644 --- a/core/lib/zksync_core/src/witness_generator/basic_circuits.rs +++ b/core/lib/zksync_core/src/witness_generator/basic_circuits.rs @@ -1,7 +1,3 @@ -use async_trait::async_trait; -use rand::Rng; -use serde::{Deserialize, Serialize}; - use std::{ collections::{hash_map::DefaultHasher, HashMap, HashSet}, hash::{Hash, Hasher}, @@ -9,9 +5,12 @@ use std::{ time::Instant, }; +use async_trait::async_trait; use multivm::vm_latest::{ constants::MAX_CYCLES_FOR_TX, HistoryDisabled, SimpleMemory, StorageOracle as VmStorageOracle, }; +use rand::Rng; +use serde::{Deserialize, Serialize}; use zksync_config::configs::{ witness_generator::BasicWitnessGeneratorDataSource, WitnessGeneratorConfig, }; @@ -23,12 +22,14 @@ use zksync_system_constants::BOOTLOADER_ADDRESS; use zksync_types::{ circuit::GEOMETRY_CONFIG, proofs::{AggregationRound, BasicCircuitWitnessGeneratorInput, PrepareBasicCircuitsJob}, - zkevm_test_harness::toolset::GeometryConfig, zkevm_test_harness::{ abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, bellman::bn256::Bn256, - witness::full_block_artifact::{BlockBasicCircuits, BlockBasicCircuitsPublicInputs}, - witness::oracle::VmWitnessOracle, + toolset::GeometryConfig, + witness::{ + full_block_artifact::{BlockBasicCircuits, BlockBasicCircuitsPublicInputs}, + oracle::VmWitnessOracle, + }, SchedulerCircuitInstanceWitness, }, Address, L1BatchNumber, ProtocolVersionId, H256, U256, USED_BOOTLOADER_MEMORY_BYTES, diff --git a/core/lib/zksync_core/src/witness_generator/leaf_aggregation.rs b/core/lib/zksync_core/src/witness_generator/leaf_aggregation.rs index 4c9201b65f6..94082c42158 100644 --- a/core/lib/zksync_core/src/witness_generator/leaf_aggregation.rs +++ b/core/lib/zksync_core/src/witness_generator/leaf_aggregation.rs @@ -1,7 +1,6 @@ -use async_trait::async_trait; - use std::{collections::HashMap, time::Instant}; +use async_trait::async_trait; use zksync_config::configs::WitnessGeneratorConfig; use zksync_dal::ConnectionPool; use zksync_object_store::{ObjectStore, ObjectStoreFactory}; @@ -10,10 +9,12 @@ use zksync_types::{ circuit::LEAF_SPLITTING_FACTOR, proofs::{AggregationRound, PrepareLeafAggregationCircuitsJob, WitnessGeneratorJobMetadata}, zkevm_test_harness::{ - abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, bellman::bn256::Bn256, - bellman::plonk::better_better_cs::setup::VerificationKey, - encodings::recursion_request::RecursionRequest, encodings::QueueSimulator, witness, - witness::oracle::VmWitnessOracle, LeafAggregationOutputDataWitness, + abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, + bellman::{bn256::Bn256, plonk::better_better_cs::setup::VerificationKey}, + encodings::{recursion_request::RecursionRequest, QueueSimulator}, + witness, + witness::oracle::VmWitnessOracle, + LeafAggregationOutputDataWitness, }, L1BatchNumber, ProtocolVersionId, }; diff --git a/core/lib/zksync_core/src/witness_generator/mod.rs b/core/lib/zksync_core/src/witness_generator/mod.rs index 18b23866056..2fa941f0bda 100644 --- a/core/lib/zksync_core/src/witness_generator/mod.rs +++ b/core/lib/zksync_core/src/witness_generator/mod.rs @@ -38,10 +38,9 @@ //! Note that the very first input table (`basic_circuit_witness_jobs` (TODO SMA-1362: will be renamed from `witness_inputs`)) //! is populated by the tree (as the input artifact for the `WitnessGeneratorJobType::BasicCircuits` is the merkle proofs) -use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; - use std::{fmt, time::Duration}; +use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; use zksync_types::proofs::AggregationRound; pub mod basic_circuits; diff --git a/core/lib/zksync_core/src/witness_generator/node_aggregation.rs b/core/lib/zksync_core/src/witness_generator/node_aggregation.rs index 6d884563c9d..8ca86be00a5 100644 --- a/core/lib/zksync_core/src/witness_generator/node_aggregation.rs +++ b/core/lib/zksync_core/src/witness_generator/node_aggregation.rs @@ -1,7 +1,6 @@ -use async_trait::async_trait; - use std::{collections::HashMap, env, time::Instant}; +use async_trait::async_trait; use zksync_config::configs::WitnessGeneratorConfig; use zksync_dal::ConnectionPool; use zksync_object_store::{ObjectStore, ObjectStoreFactory}; @@ -13,8 +12,7 @@ use zksync_types::{ proofs::{AggregationRound, PrepareNodeAggregationCircuitJob, WitnessGeneratorJobMetadata}, zkevm_test_harness::{ abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, - bellman::bn256::Bn256, - bellman::plonk::better_better_cs::setup::VerificationKey, + bellman::{bn256::Bn256, plonk::better_better_cs::setup::VerificationKey}, ff::to_hex, witness::{ self, diff --git a/core/lib/zksync_core/src/witness_generator/precalculated_merkle_paths_provider.rs b/core/lib/zksync_core/src/witness_generator/precalculated_merkle_paths_provider.rs index 96705de7e91..73f714d7314 100644 --- a/core/lib/zksync_core/src/witness_generator/precalculated_merkle_paths_provider.rs +++ b/core/lib/zksync_core/src/witness_generator/precalculated_merkle_paths_provider.rs @@ -1,9 +1,13 @@ use serde::{Deserialize, Serialize}; -use zksync_types::proofs::{PrepareBasicCircuitsJob, StorageLogMetadata}; -use zksync_types::zkevm_test_harness::blake2::Blake2s256; -use zksync_types::zkevm_test_harness::witness::tree::BinaryHasher; -use zksync_types::zkevm_test_harness::witness::tree::{ - BinarySparseStorageTree, EnumeratedBinaryLeaf, LeafQuery, ZkSyncStorageLeaf, +use zksync_types::{ + proofs::{PrepareBasicCircuitsJob, StorageLogMetadata}, + zkevm_test_harness::{ + blake2::Blake2s256, + witness::tree::{ + BinaryHasher, BinarySparseStorageTree, EnumeratedBinaryLeaf, LeafQuery, + ZkSyncStorageLeaf, + }, + }, }; #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] diff --git a/core/lib/zksync_core/src/witness_generator/scheduler.rs b/core/lib/zksync_core/src/witness_generator/scheduler.rs index ae8c2daff73..a0f1b6b6d7a 100644 --- a/core/lib/zksync_core/src/witness_generator/scheduler.rs +++ b/core/lib/zksync_core/src/witness_generator/scheduler.rs @@ -1,7 +1,6 @@ -use async_trait::async_trait; - use std::{collections::HashMap, slice, time::Instant}; +use async_trait::async_trait; use zksync_config::configs::WitnessGeneratorConfig; use zksync_dal::ConnectionPool; use zksync_object_store::{ObjectStore, ObjectStoreFactory}; diff --git a/core/lib/zksync_core/src/witness_generator/storage_oracle.rs b/core/lib/zksync_core/src/witness_generator/storage_oracle.rs index 112b4eb5988..f0b3203686f 100644 --- a/core/lib/zksync_core/src/witness_generator/storage_oracle.rs +++ b/core/lib/zksync_core/src/witness_generator/storage_oracle.rs @@ -1,7 +1,7 @@ -use zksync_types::zkevm_test_harness::zk_evm::abstractions::{ - RefundType, RefundedAmounts, Storage, +use zksync_types::{ + zkevm_test_harness::zk_evm::abstractions::{RefundType, RefundedAmounts, Storage}, + LogQuery, Timestamp, }; -use zksync_types::{LogQuery, Timestamp}; #[derive(Debug)] pub(super) struct StorageOracle { diff --git a/core/lib/zksync_core/src/witness_generator/tests.rs b/core/lib/zksync_core/src/witness_generator/tests.rs index 38a77331fa3..fb7b285b119 100644 --- a/core/lib/zksync_core/src/witness_generator/tests.rs +++ b/core/lib/zksync_core/src/witness_generator/tests.rs @@ -1,7 +1,11 @@ -use crate::witness_generator::precalculated_merkle_paths_provider::PrecalculatedMerklePathsProvider; use std::convert::TryInto; -use zksync_types::proofs::StorageLogMetadata; -use zksync_types::zkevm_test_harness::witness::tree::{BinarySparseStorageTree, ZkSyncStorageLeaf}; + +use zksync_types::{ + proofs::StorageLogMetadata, + zkevm_test_harness::witness::tree::{BinarySparseStorageTree, ZkSyncStorageLeaf}, +}; + +use crate::witness_generator::precalculated_merkle_paths_provider::PrecalculatedMerklePathsProvider; #[test] fn test_filter_renumerate_all_first_writes() { diff --git a/core/lib/zksync_core/src/witness_generator/utils.rs b/core/lib/zksync_core/src/witness_generator/utils.rs index 2135eddb3cc..35f5fd431ce 100644 --- a/core/lib/zksync_core/src/witness_generator/utils.rs +++ b/core/lib/zksync_core/src/witness_generator/utils.rs @@ -1,8 +1,12 @@ use zksync_object_store::{CircuitKey, ObjectStore}; -use zksync_types::zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit; -use zksync_types::zkevm_test_harness::bellman::bn256::Bn256; -use zksync_types::zkevm_test_harness::witness::oracle::VmWitnessOracle; -use zksync_types::{proofs::AggregationRound, L1BatchNumber}; +use zksync_types::{ + proofs::AggregationRound, + zkevm_test_harness::{ + abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, bellman::bn256::Bn256, + witness::oracle::VmWitnessOracle, + }, + L1BatchNumber, +}; pub async fn save_prover_input_artifacts( block_number: L1BatchNumber, diff --git a/core/tests/cross_external_nodes_checker/src/checker.rs b/core/tests/cross_external_nodes_checker/src/checker.rs index 61421816c60..be1dbd6faf6 100644 --- a/core/tests/cross_external_nodes_checker/src/checker.rs +++ b/core/tests/cross_external_nodes_checker/src/checker.rs @@ -7,7 +7,6 @@ use std::{ use serde_json::Value; use tokio::{sync::watch::Receiver, time::sleep}; - use zksync_types::{ api::{BlockDetails, BlockNumber, L1BatchDetails}, web3::types::U64, @@ -15,15 +14,17 @@ use zksync_types::{ }; use zksync_utils::wait_for_tasks::wait_for_tasks; use zksync_web3_decl::{ - jsonrpsee::core::Error, - jsonrpsee::http_client::{HttpClient, HttpClientBuilder}, + jsonrpsee::{ + core::Error, + http_client::{HttpClient, HttpClientBuilder}, + }, namespaces::{EnNamespaceClient, EthNamespaceClient, ZksNamespaceClient}, types::FilterBuilder, RpcResult, }; -use crate::config::{CheckerConfig, RpcMode}; use crate::{ + config::{CheckerConfig, RpcMode}, divergence::{Divergence, DivergenceDetails}, helpers::compare_json, }; diff --git a/core/tests/cross_external_nodes_checker/src/config.rs b/core/tests/cross_external_nodes_checker/src/config.rs index 6273b3405a0..636a4fd9ae5 100644 --- a/core/tests/cross_external_nodes_checker/src/config.rs +++ b/core/tests/cross_external_nodes_checker/src/config.rs @@ -116,9 +116,10 @@ fn default_subscription_duration() -> Option { #[cfg(test)] mod tests { - use super::*; use std::env; + use super::*; + #[test] fn success() { let config = r#" diff --git a/core/tests/cross_external_nodes_checker/src/divergence.rs b/core/tests/cross_external_nodes_checker/src/divergence.rs index 7f18f5fa605..18c910349f7 100644 --- a/core/tests/cross_external_nodes_checker/src/divergence.rs +++ b/core/tests/cross_external_nodes_checker/src/divergence.rs @@ -1,4 +1,5 @@ use std::fmt; + use zksync_types::{web3::types::U64, MiniblockNumber}; #[derive(Debug, Clone)] diff --git a/core/tests/cross_external_nodes_checker/src/helpers.rs b/core/tests/cross_external_nodes_checker/src/helpers.rs index 14843e55868..6247b5e8c8a 100644 --- a/core/tests/cross_external_nodes_checker/src/helpers.rs +++ b/core/tests/cross_external_nodes_checker/src/helpers.rs @@ -1,7 +1,7 @@ +use std::{collections::HashMap, future::Future, time::Duration}; + use futures::channel::oneshot; use serde_json::{Map, Value}; -use std::future::Future; -use std::{collections::HashMap, time::Duration}; use tokio::time::sleep; /// Sets up an interrupt handler and returns a future that resolves once an interrupt signal is received. @@ -132,9 +132,10 @@ impl ExponentialBackoff { #[cfg(test)] mod tests { - use super::*; use serde_json::json; + use super::*; + #[test] fn test_same_json() { let json1 = json!({ diff --git a/core/tests/cross_external_nodes_checker/src/main.rs b/core/tests/cross_external_nodes_checker/src/main.rs index 45192fe20fa..7199c1cbd32 100644 --- a/core/tests/cross_external_nodes_checker/src/main.rs +++ b/core/tests/cross_external_nodes_checker/src/main.rs @@ -1,4 +1,8 @@ -extern crate core; +use tokio::sync::watch; +use zksync_utils::wait_for_tasks::wait_for_tasks; + +use self::{checker::Checker, pubsub_checker::PubSubChecker}; +use crate::{config::CheckerConfig, helpers::setup_sigint_handler}; mod checker; mod config; @@ -6,13 +10,6 @@ mod divergence; mod helpers; mod pubsub_checker; -use crate::config::CheckerConfig; -use crate::helpers::setup_sigint_handler; -use checker::Checker; -use pubsub_checker::PubSubChecker; -use tokio::sync::watch; -use zksync_utils::wait_for_tasks::wait_for_tasks; - #[tokio::main] async fn main() -> anyhow::Result<()> { #[allow(deprecated)] // TODO (QIT-21): Use centralized configuration approach. diff --git a/core/tests/cross_external_nodes_checker/src/pubsub_checker.rs b/core/tests/cross_external_nodes_checker/src/pubsub_checker.rs index 78860210297..8a3bc765ace 100644 --- a/core/tests/cross_external_nodes_checker/src/pubsub_checker.rs +++ b/core/tests/cross_external_nodes_checker/src/pubsub_checker.rs @@ -1,14 +1,10 @@ -use crate::{ - config::CheckerConfig, - divergence::{Divergence, DivergenceDetails}, - helpers::{compare_json, ExponentialBackoff}, -}; -use anyhow::Context as _; use std::{ collections::HashMap, sync::Arc, time::{Duration, Instant}, }; + +use anyhow::Context as _; use tokio::{ select, spawn, sync::{watch::Receiver, Mutex as TokioMutex}, @@ -28,6 +24,12 @@ use zksync_web3_decl::{ types::{BlockHeader, PubSubResult}, }; +use crate::{ + config::CheckerConfig, + divergence::{Divergence, DivergenceDetails}, + helpers::{compare_json, ExponentialBackoff}, +}; + const MAX_RETRIES: u32 = 6; const GRACE_PERIOD: Duration = Duration::from_secs(60); const SUBSCRIPTION_TIMEOUT: Duration = Duration::from_secs(120); diff --git a/core/tests/loadnext/src/account/api_request_executor.rs b/core/tests/loadnext/src/account/api_request_executor.rs index e1e09004d4e..18d25a1da9c 100644 --- a/core/tests/loadnext/src/account/api_request_executor.rs +++ b/core/tests/loadnext/src/account/api_request_executor.rs @@ -2,7 +2,6 @@ use std::time::Instant; use rand::seq::IteratorRandom; use regex::Regex; - use zksync::{ error::{ClientError, RpcError}, types::FilterBuilder, diff --git a/core/tests/loadnext/src/account/mod.rs b/core/tests/loadnext/src/account/mod.rs index 14aa23b5031..42afd28d87e 100644 --- a/core/tests/loadnext/src/account/mod.rs +++ b/core/tests/loadnext/src/account/mod.rs @@ -1,18 +1,16 @@ -use futures::{channel::mpsc, SinkExt}; use std::{ collections::VecDeque, sync::Arc, time::{Duration, Instant}, }; -use tokio::sync::RwLock; +use futures::{channel::mpsc, SinkExt}; +use tokio::sync::RwLock; use zksync::{error::ClientError, operations::SyncTransactionHandle, HttpClient}; +use zksync_contracts::test_contracts::LoadnextContractExecutionParams; use zksync_types::{api::TransactionReceipt, Address, Nonce, H256, U256, U64}; use zksync_web3_decl::jsonrpsee::core::Error as CoreError; -use zksync_contracts::test_contracts::LoadnextContractExecutionParams; - -use crate::utils::format_gwei; use crate::{ account::tx_command_executor::SubmitResult, account_pool::{AddressPool, TestWallet}, @@ -20,6 +18,7 @@ use crate::{ config::{LoadtestConfig, RequestLimiters}, constants::{MAX_L1_TRANSACTIONS, POLLING_INTERVAL}, report::{Report, ReportBuilder, ReportLabel}, + utils::format_gwei, }; mod api_request_executor; diff --git a/core/tests/loadnext/src/account/pubsub_executor.rs b/core/tests/loadnext/src/account/pubsub_executor.rs index 2dec5dbd8c6..d3c9d7144f1 100644 --- a/core/tests/loadnext/src/account/pubsub_executor.rs +++ b/core/tests/loadnext/src/account/pubsub_executor.rs @@ -1,9 +1,7 @@ -use futures::{stream, TryStreamExt}; - use std::time::{Duration, Instant}; -use zksync::error::ClientError; -use zksync::types::PubSubFilterBuilder; +use futures::{stream, TryStreamExt}; +use zksync::{error::ClientError, types::PubSubFilterBuilder}; use zksync_web3_decl::{ jsonrpsee::{ core::client::{Subscription, SubscriptionClientT}, diff --git a/core/tests/loadnext/src/account/tx_command_executor.rs b/core/tests/loadnext/src/account/tx_command_executor.rs index 9fb8631fdc1..f1ace035547 100644 --- a/core/tests/loadnext/src/account/tx_command_executor.rs +++ b/core/tests/loadnext/src/account/tx_command_executor.rs @@ -1,12 +1,13 @@ use std::time::Instant; -use zksync::web3::ethabi; -use zksync::EthNamespaceClient; + use zksync::{ error::ClientError, ethereum::PriorityOpHolder, utils::{ get_approval_based_paymaster_input, get_approval_based_paymaster_input_for_estimation, }, + web3::ethabi, + EthNamespaceClient, }; use zksync_eth_client::EthInterface; use zksync_system_constants::MAX_L1_TRANSACTION_GAS_LIMIT; @@ -16,14 +17,13 @@ use zksync_types::{ Address, H256, U256, }; -use crate::account::ExecutionType; -use crate::utils::format_gwei; use crate::{ - account::AccountLifespan, + account::{AccountLifespan, ExecutionType}, command::{IncorrectnessModifier, TxCommand, TxType}, constants::{ETH_CONFIRMATION_TIMEOUT, ETH_POLLING_INTERVAL}, corrupted_tx::Corrupted, report::ReportLabel, + utils::format_gwei, }; #[derive(Debug)] diff --git a/core/tests/loadnext/src/account_pool.rs b/core/tests/loadnext/src/account_pool.rs index e4ded62dcf1..730a6d07b48 100644 --- a/core/tests/loadnext/src/account_pool.rs +++ b/core/tests/loadnext/src/account_pool.rs @@ -3,7 +3,6 @@ use std::{collections::VecDeque, convert::TryFrom, str::FromStr, sync::Arc, time use once_cell::sync::OnceCell; use rand::Rng; use tokio::time::timeout; - use zksync::{signer::Signer, HttpClient, HttpClientBuilder, Wallet, ZksNamespaceClient}; use zksync_eth_signer::PrivateKeySigner; use zksync_types::{tx::primitives::PackedEthSignature, Address, L2ChainId, H256}; diff --git a/core/tests/loadnext/src/command/api.rs b/core/tests/loadnext/src/command/api.rs index 1e520d7c195..76ed5db5747 100644 --- a/core/tests/loadnext/src/command/api.rs +++ b/core/tests/loadnext/src/command/api.rs @@ -1,6 +1,5 @@ use num::Integer; use rand::RngCore; - use zksync::EthNamespaceClient; use zksync_types::api; diff --git a/core/tests/loadnext/src/command/tx_command.rs b/core/tests/loadnext/src/command/tx_command.rs index 945a7ca16bb..84e07d1f0d2 100644 --- a/core/tests/loadnext/src/command/tx_command.rs +++ b/core/tests/loadnext/src/command/tx_command.rs @@ -1,7 +1,6 @@ use once_cell::sync::OnceCell; use rand::Rng; use static_assertions::const_assert; - use zksync_types::{Address, U256}; use crate::{ diff --git a/core/tests/loadnext/src/config.rs b/core/tests/loadnext/src/config.rs index d62f4cdb63e..b31cb5d3d8a 100644 --- a/core/tests/loadnext/src/config.rs +++ b/core/tests/loadnext/src/config.rs @@ -1,12 +1,9 @@ +use std::{path::PathBuf, time::Duration}; + use serde::Deserialize; use tokio::sync::Semaphore; - -use std::path::PathBuf; -use std::time::Duration; - use zksync_contracts::test_contracts::LoadnextContractExecutionParams; -use zksync_types::network::Network; -use zksync_types::{Address, L2ChainId, H160}; +use zksync_types::{network::Network, Address, L2ChainId, H160}; use crate::fs_utils::read_tokens; diff --git a/core/tests/loadnext/src/corrupted_tx.rs b/core/tests/loadnext/src/corrupted_tx.rs index c3ada60472e..c51b0c88d02 100644 --- a/core/tests/loadnext/src/corrupted_tx.rs +++ b/core/tests/loadnext/src/corrupted_tx.rs @@ -1,13 +1,13 @@ use async_trait::async_trait; - use zksync::signer::Signer; -use zksync_eth_signer::{error::SignerError, EthereumSigner}; -use zksync_types::{Address, EIP712TypedStructure, Eip712Domain, PackedEthSignature, H256}; +use zksync_eth_signer::{ + error::SignerError, raw_ethereum_tx::TransactionParameters, EthereumSigner, +}; +use zksync_types::{ + fee::Fee, l2::L2Tx, Address, EIP712TypedStructure, Eip712Domain, PackedEthSignature, H256, +}; use crate::command::IncorrectnessModifier; -use zksync_eth_signer::raw_ethereum_tx::TransactionParameters; -use zksync_types::fee::Fee; -use zksync_types::l2::L2Tx; /// Trait that exists solely to extend the signed zkSync transaction interface, providing the ability /// to modify transaction in a way that will make it invalid. @@ -94,14 +94,14 @@ impl EthereumSigner for CorruptedSigner { #[cfg(test)] mod tests { - use super::*; use zksync_eth_signer::PrivateKeySigner; - use zksync_types::fee::Fee; - use zksync_types::L2ChainId; use zksync_types::{ - tokens::ETHEREUM_ADDRESS, tx::primitives::PackedEthSignature, Address, Nonce, H256, + fee::Fee, tokens::ETHEREUM_ADDRESS, tx::primitives::PackedEthSignature, Address, L2ChainId, + Nonce, H256, }; + use super::*; + const AMOUNT: u64 = 100; const FEE: u64 = 100; const NONCE: Nonce = Nonce(1); diff --git a/core/tests/loadnext/src/executor.rs b/core/tests/loadnext/src/executor.rs index 08d1ce47d6a..5c64f1b61be 100644 --- a/core/tests/loadnext/src/executor.rs +++ b/core/tests/loadnext/src/executor.rs @@ -1,14 +1,15 @@ -use anyhow::anyhow; -use futures::{channel::mpsc, future, SinkExt}; - use std::sync::Arc; -use zksync::ethereum::{PriorityOpHolder, DEFAULT_PRIORITY_FEE}; -use zksync::utils::{ - get_approval_based_paymaster_input, get_approval_based_paymaster_input_for_estimation, +use anyhow::anyhow; +use futures::{channel::mpsc, future, SinkExt}; +use zksync::{ + ethereum::{PriorityOpHolder, DEFAULT_PRIORITY_FEE}, + utils::{ + get_approval_based_paymaster_input, get_approval_based_paymaster_input_for_estimation, + }, + web3::{contract::Options, types::TransactionReceipt}, + EthNamespaceClient, EthereumProvider, ZksNamespaceClient, }; -use zksync::web3::{contract::Options, types::TransactionReceipt}; -use zksync::{EthNamespaceClient, EthereumProvider, ZksNamespaceClient}; use zksync_eth_client::{BoundEthInterface, EthInterface}; use zksync_eth_signer::PrivateKeySigner; use zksync_system_constants::MAX_L1_TRANSACTION_GAS_LIMIT; @@ -17,14 +18,14 @@ use zksync_types::{ REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE, U256, U64, }; -use crate::report::ReportBuilder; -use crate::utils::format_eth; use crate::{ account::AccountLifespan, account_pool::AccountPool, config::{ExecutionConfig, LoadtestConfig, RequestLimiters}, constants::*, + report::ReportBuilder, report_collector::{LoadtestResult, ReportCollector}, + utils::format_eth, }; /// Executor is the entity capable of running the loadtest flow. diff --git a/core/tests/loadnext/src/fs_utils.rs b/core/tests/loadnext/src/fs_utils.rs index d5b92b3c7a9..9fee9916f91 100644 --- a/core/tests/loadnext/src/fs_utils.rs +++ b/core/tests/loadnext/src/fs_utils.rs @@ -1,14 +1,10 @@ //! Utilities used for reading tokens, contracts bytecode and ABI from the //! filesystem. -use std::fs::File; -use std::io::BufReader; -use std::path::Path; +use std::{fs::File, io::BufReader, path::Path}; use serde::Deserialize; - -use zksync_types::network::Network; -use zksync_types::{ethabi::Contract, Address}; +use zksync_types::{ethabi::Contract, network::Network, Address}; /// A token stored in `etc/tokens/{network}.json` files. #[derive(Debug, Deserialize)] @@ -93,9 +89,10 @@ pub fn loadnext_contract(path: &Path) -> anyhow::Result { #[cfg(test)] mod tests { - use super::*; use std::path::PathBuf; + use super::*; + #[test] fn check_read_test_contract() { let test_contracts_path = { diff --git a/core/tests/loadnext/src/main.rs b/core/tests/loadnext/src/main.rs index 5d35c4e7f79..595532706c7 100644 --- a/core/tests/loadnext/src/main.rs +++ b/core/tests/loadnext/src/main.rs @@ -4,19 +4,17 @@ //! Without required variables provided, test is launched in the localhost/development mode with some hard-coded //! values to check the local zkSync deployment. -use tokio::sync::watch; - use std::time::Duration; -use prometheus_exporter::PrometheusExporterConfig; -use zksync_config::configs::api::PrometheusConfig; - use loadnext::{ command::TxType, config::{ExecutionConfig, LoadtestConfig}, executor::Executor, report_collector::LoadtestResult, }; +use prometheus_exporter::PrometheusExporterConfig; +use tokio::sync::watch; +use zksync_config::configs::api::PrometheusConfig; #[tokio::main] async fn main() -> anyhow::Result<()> { diff --git a/core/tests/loadnext/src/report.rs b/core/tests/loadnext/src/report.rs index 0ea86a49de0..e6c6bfdb551 100644 --- a/core/tests/loadnext/src/report.rs +++ b/core/tests/loadnext/src/report.rs @@ -2,8 +2,8 @@ use std::time::Duration; use zksync_types::Address; -use crate::account::ExecutionType; use crate::{ + account::ExecutionType, all::All, command::{ApiRequest, ApiRequestType, SubscriptionType, TxCommand, TxType}, }; diff --git a/core/tests/loadnext/src/report_collector/mod.rs b/core/tests/loadnext/src/report_collector/mod.rs index a7798e0bea7..6a7a5de39ba 100644 --- a/core/tests/loadnext/src/report_collector/mod.rs +++ b/core/tests/loadnext/src/report_collector/mod.rs @@ -1,8 +1,8 @@ +use std::time::{Duration, Instant}; + use futures::{channel::mpsc::Receiver, StreamExt}; use operation_results_collector::OperationResultsCollector; -use std::time::{Duration, Instant}; - use crate::{ report::{ActionType, Report, ReportLabel}, report_collector::metrics_collector::MetricsCollector, diff --git a/core/tests/loadnext/src/report_collector/operation_results_collector.rs b/core/tests/loadnext/src/report_collector/operation_results_collector.rs index 63f2bb7dbf9..ab460af839b 100644 --- a/core/tests/loadnext/src/report_collector/operation_results_collector.rs +++ b/core/tests/loadnext/src/report_collector/operation_results_collector.rs @@ -1,7 +1,7 @@ -use crate::report::{ActionType, ReportLabel}; - use std::{fmt, time::Duration}; +use crate::report::{ActionType, ReportLabel}; + /// Collector that analyzes the outcomes of the performed operations. /// Currently it's solely capable of deciding whether test was failed or not. /// API requests are counted separately. diff --git a/core/tests/loadnext/src/rng.rs b/core/tests/loadnext/src/rng.rs index 4d5ab84c714..3612a7c2a84 100644 --- a/core/tests/loadnext/src/rng.rs +++ b/core/tests/loadnext/src/rng.rs @@ -1,7 +1,6 @@ use std::convert::TryInto; use rand::{rngs::SmallRng, seq::SliceRandom, thread_rng, RngCore, SeedableRng}; - use zksync::web3::signing::keccak256; use zksync_types::H256; diff --git a/core/tests/loadnext/src/utils.rs b/core/tests/loadnext/src/utils.rs index 3f528e97e34..95f61c8cee8 100644 --- a/core/tests/loadnext/src/utils.rs +++ b/core/tests/loadnext/src/utils.rs @@ -1,4 +1,5 @@ use std::ops::Div; + use zksync_types::U256; pub fn format_eth(value: U256) -> String { diff --git a/core/tests/vm-benchmark/benches/diy_benchmark.rs b/core/tests/vm-benchmark/benches/diy_benchmark.rs index 8f5b6cd685b..b99837d8eab 100644 --- a/core/tests/vm-benchmark/benches/diy_benchmark.rs +++ b/core/tests/vm-benchmark/benches/diy_benchmark.rs @@ -1,5 +1,6 @@ -use criterion::black_box; use std::time::{Duration, Instant}; + +use criterion::black_box; use vm_benchmark_harness::{cut_to_allowed_bytecode_size, get_deploy_tx, BenchmarkingVm}; fn main() { diff --git a/core/tests/vm-benchmark/harness/src/lib.rs b/core/tests/vm-benchmark/harness/src/lib.rs index b7da44aed92..00da5bcca9f 100644 --- a/core/tests/vm-benchmark/harness/src/lib.rs +++ b/core/tests/vm-benchmark/harness/src/lib.rs @@ -1,9 +1,12 @@ -use multivm::interface::{ - L2BlockEnv, TxExecutionMode, VmExecutionMode, VmExecutionResultAndLogs, VmInterface, +use std::{cell::RefCell, rc::Rc}; + +use multivm::{ + interface::{ + L2BlockEnv, TxExecutionMode, VmExecutionMode, VmExecutionResultAndLogs, VmInterface, + }, + vm_latest::{constants::BLOCK_GAS_LIMIT, HistoryEnabled, Vm}, }; -use multivm::vm_latest::{constants::BLOCK_GAS_LIMIT, HistoryEnabled, Vm}; use once_cell::sync::Lazy; -use std::{cell::RefCell, rc::Rc}; use zksync_contracts::{deployer_contract, BaseSystemContracts}; use zksync_state::{InMemoryStorage, StorageView}; use zksync_system_constants::ethereum::MAX_GAS_PER_PUBDATA_BYTE; @@ -133,9 +136,10 @@ pub fn get_deploy_tx(code: &[u8]) -> Transaction { #[cfg(test)] mod tests { - use crate::*; use zksync_contracts::read_bytecode; + use crate::*; + #[test] fn can_deploy_contract() { let test_contract = read_bytecode( diff --git a/core/tests/vm-benchmark/src/compare_iai_results.rs b/core/tests/vm-benchmark/src/compare_iai_results.rs index d67d7238683..d903d727117 100644 --- a/core/tests/vm-benchmark/src/compare_iai_results.rs +++ b/core/tests/vm-benchmark/src/compare_iai_results.rs @@ -1,6 +1,5 @@ -use std::collections::HashMap; -use std::fs::File; -use std::io::BufReader; +use std::{collections::HashMap, fs::File, io::BufReader}; + use vm_benchmark::parse_iai::parse_iai; fn main() { diff --git a/core/tests/vm-benchmark/src/find_slowest.rs b/core/tests/vm-benchmark/src/find_slowest.rs index 947f944541c..2bc2a894d2d 100644 --- a/core/tests/vm-benchmark/src/find_slowest.rs +++ b/core/tests/vm-benchmark/src/find_slowest.rs @@ -2,6 +2,7 @@ use std::{ io::Write, time::{Duration, Instant}, }; + use vm_benchmark_harness::*; fn main() { diff --git a/core/tests/vm-benchmark/src/iai_results_to_prometheus.rs b/core/tests/vm-benchmark/src/iai_results_to_prometheus.rs index dc3c8f6d98f..396d59948a8 100644 --- a/core/tests/vm-benchmark/src/iai_results_to_prometheus.rs +++ b/core/tests/vm-benchmark/src/iai_results_to_prometheus.rs @@ -1,4 +1,5 @@ use std::io::BufReader; + use vm_benchmark::parse_iai::IaiResult; fn main() { diff --git a/core/tests/vm-benchmark/src/with_prometheus.rs b/core/tests/vm-benchmark/src/with_prometheus.rs index e9d4f2e57ed..1fcf5652c6d 100644 --- a/core/tests/vm-benchmark/src/with_prometheus.rs +++ b/core/tests/vm-benchmark/src/with_prometheus.rs @@ -1,6 +1,7 @@ -use metrics_exporter_prometheus::PrometheusBuilder; use std::time::Duration; +use metrics_exporter_prometheus::PrometheusBuilder; + pub fn with_prometheus(f: F) { println!("Pushing results to Prometheus"); diff --git a/infrastructure/zk/src/fmt.ts b/infrastructure/zk/src/fmt.ts index fa8b5e79691..896ef28dbbd 100644 --- a/infrastructure/zk/src/fmt.ts +++ b/infrastructure/zk/src/fmt.ts @@ -50,7 +50,12 @@ async function prettierSystemContracts(check: boolean = false) { export async function rustfmt(check: boolean = false) { process.chdir(process.env.ZKSYNC_HOME as string); - const command = check ? 'cargo fmt -- --check' : 'cargo fmt'; + + // We rely on a supposedly undocumented bug/feature of `rustfmt` that allows us to use unstable features on stable Rust. + // Please note that this only works with CLI flags, and if you happened to visit this place after things suddenly stopped working, + // it is certainly possible that the feature was deemed a bug and was fixed. Then welp. + const config = '--config imports_granularity=Crate --config group_imports=StdExternalCrate'; + const command = check ? `cargo fmt -- --check ${config}` : `cargo fmt -- ${config}`; await utils.spawn(command); process.chdir('./prover'); await utils.spawn(command); diff --git a/prover/Cargo.lock b/prover/Cargo.lock index 95ff42d7052..d6ea72d2c8b 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -971,12 +971,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5241cd7938b1b415942e943ea96f615953d500b50347b505b0b507080bad5a6f" -[[package]] -name = "const-oid" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" - [[package]] name = "const-oid" version = "0.9.5" @@ -1245,16 +1239,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -[[package]] -name = "crypto-bigint" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" -dependencies = [ - "generic-array", - "subtle", -] - [[package]] name = "crypto-bigint" version = "0.4.9" @@ -1454,24 +1438,13 @@ dependencies = [ "uuid", ] -[[package]] -name = "der" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6919815d73839e7ad218de758883aae3a257ba6759ce7a9992501efbb53d705c" -dependencies = [ - "const-oid 0.7.1", - "crypto-bigint 0.3.2", - "pem-rfc7468", -] - [[package]] name = "der" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" dependencies = [ - "const-oid 0.9.5", + "const-oid", "zeroize", ] @@ -1481,7 +1454,8 @@ version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" dependencies = [ - "const-oid 0.9.5", + "const-oid", + "pem-rfc7468", "zeroize", ] @@ -2186,9 +2160,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "google-cloud-auth" -version = "0.11.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "644f40175857d0b8d7b6cad6cd9594284da5041387fa2ddff30ab6d8faef65eb" +checksum = "af1087f1fbd2dd3f58c17c7574ddd99cd61cbbbc2c4dc81114b8687209b196cb" dependencies = [ "async-trait", "base64 0.21.5", @@ -2208,9 +2182,9 @@ dependencies = [ [[package]] name = "google-cloud-metadata" -version = "0.3.2" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96e4ad0802d3f416f62e7ce01ac1460898ee0efc98f8b45cd4aab7611607012f" +checksum = "cc279bfb50487d7bcd900e8688406475fc750fe474a835b2ab9ade9eb1fc90e2" dependencies = [ "reqwest", "thiserror", @@ -2219,11 +2193,12 @@ dependencies = [ [[package]] name = "google-cloud-storage" -version = "0.12.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "215abab97e07d144428425509c1dad07e57ea72b84b21bcdb6a8a5f12a5c4932" +checksum = "ac04b29849ebdeb9fb008988cc1c4d1f0c9d121b4c7f1ddeb8061df124580e93" dependencies = [ "async-stream", + "async-trait", "base64 0.21.5", "bytes", "futures-util", @@ -2233,10 +2208,10 @@ dependencies = [ "hex", "once_cell", "percent-encoding", + "pkcs8 0.10.2", "regex", "reqwest", - "ring 0.16.20", - "rsa", + "ring 0.17.5", "serde", "serde_json", "sha2 0.10.8", @@ -2811,9 +2786,6 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin 0.5.2", -] [[package]] name = "lazycell" @@ -3323,23 +3295,6 @@ dependencies = [ "serde", ] -[[package]] -name = "num-bigint-dig" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" -dependencies = [ - "byteorder", - "lazy_static", - "libm", - "num-integer", - "num-iter", - "num-traits", - "rand 0.8.5", - "smallvec", - "zeroize", -] - [[package]] name = "num-complex" version = "0.3.1" @@ -3801,9 +3756,9 @@ dependencies = [ [[package]] name = "pem-rfc7468" -version = "0.3.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01de5d978f34aa4b2296576379fcc416034702fd94117c56ffd8a1a767cefb30" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" dependencies = [ "base64ct", ] @@ -3901,28 +3856,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkcs1" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a78f66c04ccc83dd4486fd46c33896f4e17b24a7a3a6400dedc48ed0ddd72320" -dependencies = [ - "der 0.5.1", - "pkcs8 0.8.0", - "zeroize", -] - -[[package]] -name = "pkcs8" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cabda3fb821068a9a4fab19a683eac3af12edf0f34b94a8be53c4972b8149d0" -dependencies = [ - "der 0.5.1", - "spki 0.5.4", - "zeroize", -] - [[package]] name = "pkcs8" version = "0.9.0" @@ -4808,26 +4741,6 @@ dependencies = [ "librocksdb-sys", ] -[[package]] -name = "rsa" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cf22754c49613d2b3b119f0e5d46e34a2c628a937e3024b8762de4e7d8c710b" -dependencies = [ - "byteorder", - "digest 0.10.7", - "num-bigint-dig", - "num-integer", - "num-iter", - "num-traits", - "pkcs1", - "pkcs8 0.8.0", - "rand_core 0.6.4", - "smallvec", - "subtle", - "zeroize", -] - [[package]] name = "rustc-demangle" version = "0.1.23" @@ -5515,16 +5428,6 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -[[package]] -name = "spki" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d01ac02a6ccf3e07db148d2be087da624fea0221a16152ed01f0496a6b0a27" -dependencies = [ - "base64ct", - "der 0.5.1", -] - [[package]] name = "spki" version = "0.6.0" @@ -7168,6 +7071,7 @@ dependencies = [ "itertools 0.10.5", "num 0.3.1", "once_cell", + "prost", "rand 0.8.5", "serde", "serde_json", @@ -7178,8 +7082,11 @@ dependencies = [ "tracing", "url", "vise", + "zksync_consensus_roles", "zksync_contracts", "zksync_health_check", + "zksync_protobuf", + "zksync_protobuf_build", "zksync_system_constants", "zksync_types", "zksync_utils", @@ -7539,7 +7446,6 @@ dependencies = [ "num_enum", "once_cell", "parity-crypto", - "prost", "rlp", "serde", "serde_json", diff --git a/prover/circuit_synthesizer/src/circuit_synthesizer.rs b/prover/circuit_synthesizer/src/circuit_synthesizer.rs index 55da03949a7..96a164c69c1 100644 --- a/prover/circuit_synthesizer/src/circuit_synthesizer.rs +++ b/prover/circuit_synthesizer/src/circuit_synthesizer.rs @@ -1,34 +1,40 @@ -use std::option::Option; -use std::time::Duration; -use std::time::Instant; +use std::{ + option::Option, + time::{Duration, Instant}, +}; use anyhow::Context as _; use local_ip_address::local_ip; -use prover_service::prover::{Prover, ProvingAssembly}; -use prover_service::remote_synth::serialize_job; -use tokio::task::JoinHandle; -use tokio::time::sleep; -use zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit; -use zkevm_test_harness::bellman::plonk::better_better_cs::cs::Circuit; -use zkevm_test_harness::pairing::bn256::Bn256; -use zkevm_test_harness::witness::oracle::VmWitnessOracle; - -use crate::metrics::METRICS; -use zksync_config::configs::prover_group::ProverGroupConfig; -use zksync_config::configs::CircuitSynthesizerConfig; -use zksync_config::ProverConfigs; +use prover_service::{ + prover::{Prover, ProvingAssembly}, + remote_synth::serialize_job, +}; +use tokio::{task::JoinHandle, time::sleep}; +use zkevm_test_harness::{ + abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, + bellman::plonk::better_better_cs::cs::Circuit, pairing::bn256::Bn256, + witness::oracle::VmWitnessOracle, +}; +use zksync_config::{ + configs::{prover_group::ProverGroupConfig, CircuitSynthesizerConfig}, + ProverConfigs, +}; use zksync_dal::ConnectionPool; use zksync_env_config::FromEnv; use zksync_object_store::{CircuitKey, ObjectStore, ObjectStoreError, ObjectStoreFactory}; use zksync_prover_fri_utils::socket_utils::send_assembly; -use zksync_prover_utils::numeric_index_to_circuit_name; -use zksync_prover_utils::region_fetcher::{get_region, get_zone}; +use zksync_prover_utils::{ + numeric_index_to_circuit_name, + region_fetcher::{get_region, get_zone}, +}; use zksync_queued_job_processor::{async_trait, JobProcessor}; use zksync_types::{ proofs::{GpuProverInstanceStatus, SocketAddress}, protocol_version::L1VerifierConfig, }; +use crate::metrics::METRICS; + #[derive(thiserror::Error, Debug)] pub enum CircuitSynthesizerError { #[error("InvalidaGroupCircuits: {0}")] diff --git a/prover/circuit_synthesizer/src/main.rs b/prover/circuit_synthesizer/src/main.rs index 5592885dcdd..a4ac19e18d7 100644 --- a/prover/circuit_synthesizer/src/main.rs +++ b/prover/circuit_synthesizer/src/main.rs @@ -1,8 +1,7 @@ use anyhow::Context as _; use prometheus_exporter::PrometheusExporterConfig; use structopt::StructOpt; -use tokio::{sync::oneshot, sync::watch}; - +use tokio::sync::{oneshot, watch}; use zksync_config::configs::{ AlertsConfig, CircuitSynthesizerConfig, ObjectStoreConfig, PostgresConfig, ProverGroupConfig, }; diff --git a/prover/circuit_synthesizer/src/metrics.rs b/prover/circuit_synthesizer/src/metrics.rs index b9ee5b10c15..78049d6cf78 100644 --- a/prover/circuit_synthesizer/src/metrics.rs +++ b/prover/circuit_synthesizer/src/metrics.rs @@ -1,4 +1,5 @@ use std::time::Duration; + use vise::{Buckets, Histogram, LabeledFamily, Metrics}; #[derive(Debug, Metrics)] diff --git a/prover/proof_fri_compressor/src/compressor.rs b/prover/proof_fri_compressor/src/compressor.rs index f0f8efc6102..b4346305b9f 100644 --- a/prover/proof_fri_compressor/src/compressor.rs +++ b/prover/proof_fri_compressor/src/compressor.rs @@ -1,30 +1,37 @@ +use std::time::Instant; + use anyhow::Context as _; use async_trait::async_trait; -use std::time::Instant; use tokio::task::JoinHandle; - -use crate::metrics::METRICS; use zkevm_test_harness::proof_wrapper_utils::{wrap_proof, WrapperConfig}; use zksync_dal::ConnectionPool; use zksync_object_store::ObjectStore; -use zksync_prover_fri_types::circuit_definitions::boojum::field::goldilocks::GoldilocksField; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::{ - ZkSyncRecursionLayerProof, ZkSyncRecursionLayerStorageType, +use zksync_prover_fri_types::{ + circuit_definitions::{ + boojum::field::goldilocks::GoldilocksField, + circuit_definitions::recursion_layer::{ + ZkSyncRecursionLayerProof, ZkSyncRecursionLayerStorageType, + }, + zkevm_circuits::scheduler::block_header::BlockAuxilaryOutputWitness, + }, + get_current_pod_name, AuxOutputWitnessWrapper, FriProofWrapper, }; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::scheduler::block_header::BlockAuxilaryOutputWitness; -use zksync_prover_fri_types::{get_current_pod_name, AuxOutputWitnessWrapper, FriProofWrapper}; use zksync_queued_job_processor::JobProcessor; -use zksync_types::aggregated_operations::L1BatchProofForL1; -use zksync_types::zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncVerificationKey; -use zksync_types::zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::{ - ZkSyncCircuit, ZkSyncProof, +use zksync_types::{ + aggregated_operations::L1BatchProofForL1, + zkevm_test_harness::{ + abstract_zksync_circuit::concrete_circuits::{ + ZkSyncCircuit, ZkSyncProof, ZkSyncVerificationKey, + }, + bellman::{bn256::Bn256, plonk::better_better_cs::proof::Proof}, + witness::oracle::VmWitnessOracle, + }, + L1BatchNumber, }; -use zksync_types::zkevm_test_harness::bellman::bn256::Bn256; -use zksync_types::zkevm_test_harness::bellman::plonk::better_better_cs::proof::Proof; -use zksync_types::zkevm_test_harness::witness::oracle::VmWitnessOracle; -use zksync_types::L1BatchNumber; use zksync_vk_setup_data_server_fri::{get_recursive_layer_vk_for_circuit_type, get_snark_vk}; +use crate::metrics::METRICS; + pub struct ProofCompressor { blob_store: Box, pool: ConnectionPool, diff --git a/prover/proof_fri_compressor/src/main.rs b/prover/proof_fri_compressor/src/main.rs index c8396803339..04f2935ead0 100644 --- a/prover/proof_fri_compressor/src/main.rs +++ b/prover/proof_fri_compressor/src/main.rs @@ -1,11 +1,9 @@ -use anyhow::Context as _; -use std::env; -use structopt::StructOpt; -use tokio::{sync::oneshot, sync::watch}; - -use std::time::Duration; +use std::{env, time::Duration}; +use anyhow::Context as _; use prometheus_exporter::PrometheusExporterConfig; +use structopt::StructOpt; +use tokio::sync::{oneshot, watch}; use zksync_config::configs::{FriProofCompressorConfig, PostgresConfig}; use zksync_dal::ConnectionPool; use zksync_env_config::{object_store::ProverObjectStoreConfig, FromEnv}; diff --git a/prover/proof_fri_compressor/src/metrics.rs b/prover/proof_fri_compressor/src/metrics.rs index 5891da2f416..724da6d73b8 100644 --- a/prover/proof_fri_compressor/src/metrics.rs +++ b/prover/proof_fri_compressor/src/metrics.rs @@ -1,4 +1,5 @@ use std::time::Duration; + use vise::{Buckets, Histogram, Metrics}; #[derive(Debug, Metrics)] diff --git a/prover/prover/src/artifact_provider.rs b/prover/prover/src/artifact_provider.rs index 8ee065be5a5..9af365d95f4 100644 --- a/prover/prover/src/artifact_provider.rs +++ b/prover/prover/src/artifact_provider.rs @@ -1,8 +1,10 @@ +use std::io::Read; + use anyhow::Context as _; use prover_service::ArtifactProvider; -use std::io::Read; -use zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncVerificationKey; -use zkevm_test_harness::pairing::bn256::Bn256; +use zkevm_test_harness::{ + abstract_zksync_circuit::concrete_circuits::ZkSyncVerificationKey, pairing::bn256::Bn256, +}; use zksync_setup_key_server::get_setup_for_circuit_type; use zksync_verification_key_server::get_vk_for_circuit_type; diff --git a/prover/prover/src/metrics.rs b/prover/prover/src/metrics.rs index 4544ae9bfa7..ab18c59bcf7 100644 --- a/prover/prover/src/metrics.rs +++ b/prover/prover/src/metrics.rs @@ -1,4 +1,5 @@ use std::time::Duration; + use vise::{Buckets, Counter, Histogram, LabeledFamily, Metrics}; const PROVER_LATENCY_BUCKETS: Buckets = Buckets::values(&[ diff --git a/prover/prover/src/prover.rs b/prover/prover/src/prover.rs index 1885d815332..efb570050b5 100644 --- a/prover/prover/src/prover.rs +++ b/prover/prover/src/prover.rs @@ -1,21 +1,21 @@ -use anyhow::Context as _; use std::{env, time::Duration}; +use anyhow::Context as _; use prover_service::{ JobReporter, JobResult::{self, Failure, ProofGenerated}, }; use tokio::runtime::Handle; -use zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncProof; -use zkevm_test_harness::pairing::bn256::Bn256; - -use crate::metrics::METRICS; +use zkevm_test_harness::{ + abstract_zksync_circuit::concrete_circuits::ZkSyncProof, pairing::bn256::Bn256, +}; use zksync_config::{PostgresConfig, ProverConfig}; -use zksync_dal::ConnectionPool; -use zksync_dal::StorageProcessor; +use zksync_dal::{ConnectionPool, StorageProcessor}; use zksync_object_store::{Bucket, ObjectStore, ObjectStoreFactory}; use zksync_types::proofs::ProverJobMetadata; +use crate::metrics::METRICS; + #[derive(Debug)] pub struct ProverReporter { rt_handle: Handle, diff --git a/prover/prover/src/prover_params.rs b/prover/prover/src/prover_params.rs index 558e9058ed6..fc59b88ddf7 100644 --- a/prover/prover/src/prover_params.rs +++ b/prover/prover/src/prover_params.rs @@ -1,7 +1,6 @@ use std::time::Duration; use prover_service::Params; - use zksync_config::ProverConfig; #[derive(Debug)] diff --git a/prover/prover/src/run.rs b/prover/prover/src/run.rs index 9342cd554e6..9784b2f1b66 100644 --- a/prover/prover/src/run.rs +++ b/prover/prover/src/run.rs @@ -1,11 +1,10 @@ -use anyhow::Context as _; use std::{env, future::Future, sync::Arc, time::Instant}; -use tokio::sync::{oneshot, Mutex}; +use anyhow::Context as _; use local_ip_address::local_ip; -use queues::Buffer; - use prometheus_exporter::PrometheusExporterConfig; +use queues::Buffer; +use tokio::sync::{oneshot, Mutex}; use zksync_config::{ configs::{ api::PrometheusConfig, prover_group::ProverGroupConfig, AlertsConfig, ObjectStoreConfig, @@ -19,12 +18,11 @@ use zksync_prover_utils::region_fetcher::{get_region, get_zone}; use zksync_types::proofs::{GpuProverInstanceStatus, SocketAddress}; use zksync_utils::wait_for_tasks::wait_for_tasks; -use crate::artifact_provider::ProverArtifactProvider; -use crate::metrics::METRICS; -use crate::prover::ProverReporter; -use crate::prover_params::ProverParams; -use crate::socket_listener::incoming_socket_listener; -use crate::synthesized_circuit_provider::SynthesizedCircuitProvider; +use crate::{ + artifact_provider::ProverArtifactProvider, metrics::METRICS, prover::ProverReporter, + prover_params::ProverParams, socket_listener::incoming_socket_listener, + synthesized_circuit_provider::SynthesizedCircuitProvider, +}; async fn graceful_shutdown() -> anyhow::Result> { let postgres_config = PostgresConfig::from_env().context("PostgresConfig::from_env()")?; diff --git a/prover/prover/src/socket_listener.rs b/prover/prover/src/socket_listener.rs index d8dbaff74dc..95a369e7078 100644 --- a/prover/prover/src/socket_listener.rs +++ b/prover/prover/src/socket_listener.rs @@ -1,15 +1,18 @@ -use crate::synthesized_circuit_provider::SharedAssemblyQueue; -use queues::IsQueue; -use std::net::{IpAddr, SocketAddr}; -use std::time::Instant; -use zksync_dal::ConnectionPool; -use zksync_types::proofs::{GpuProverInstanceStatus, SocketAddress}; +use std::{ + net::{IpAddr, SocketAddr}, + time::Instant, +}; use anyhow::Context as _; +use queues::IsQueue; use tokio::{ io::copy, net::{TcpListener, TcpStream}, }; +use zksync_dal::ConnectionPool; +use zksync_types::proofs::{GpuProverInstanceStatus, SocketAddress}; + +use crate::synthesized_circuit_provider::SharedAssemblyQueue; #[allow(clippy::too_many_arguments)] pub async fn incoming_socket_listener( diff --git a/prover/prover/src/synthesized_circuit_provider.rs b/prover/prover/src/synthesized_circuit_provider.rs index 3c6939dc6aa..e1cec64162b 100644 --- a/prover/prover/src/synthesized_circuit_provider.rs +++ b/prover/prover/src/synthesized_circuit_provider.rs @@ -1,16 +1,16 @@ -use std::io::Cursor; -use std::io::Read; -use std::sync::Arc; -use tokio::sync::Mutex; +use std::{ + io::{Cursor, Read}, + sync::Arc, +}; use prover_service::RemoteSynthesizer; use queues::{Buffer, IsQueue}; - -use crate::metrics::METRICS; -use tokio::runtime::Handle; +use tokio::{runtime::Handle, sync::Mutex}; use zksync_dal::ConnectionPool; use zksync_types::proofs::SocketAddress; +use crate::metrics::METRICS; + pub type SharedAssemblyQueue = Arc>>>; pub struct SynthesizedCircuitProvider { diff --git a/prover/prover_fri/src/gpu_prover_job_processor.rs b/prover/prover_fri/src/gpu_prover_job_processor.rs index 9d7eda1202a..b56388bce05 100644 --- a/prover/prover_fri/src/gpu_prover_job_processor.rs +++ b/prover/prover_fri/src/gpu_prover_job_processor.rs @@ -1,39 +1,42 @@ #[cfg(feature = "gpu")] pub mod gpu_prover { - use std::collections::HashMap; - use std::{sync::Arc, time::Instant}; + use std::{collections::HashMap, sync::Arc, time::Instant}; use anyhow::Context as _; + use shivini::{gpu_prove_from_external_witness_data, ProverContext}; use tokio::task::JoinHandle; - use zksync_prover_fri_types::circuit_definitions::base_layer_proof_config; - use zksync_prover_fri_types::circuit_definitions::boojum::algebraic_props::round_function::AbsorptionModeOverwrite; - use zksync_prover_fri_types::circuit_definitions::boojum::algebraic_props::sponge::GoldilocksPoseidon2Sponge; - use zksync_prover_fri_types::circuit_definitions::boojum::cs::implementations::pow::NoPow; - - use zksync_prover_fri_types::circuit_definitions::boojum::cs::implementations::transcript::GoldilocksPoisedon2Transcript; - use zksync_prover_fri_types::circuit_definitions::boojum::worker::Worker; - use zksync_prover_fri_types::circuit_definitions::circuit_definitions::base_layer::ZkSyncBaseLayerProof; - use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::ZkSyncRecursionLayerProof; - use zksync_prover_fri_types::WitnessVectorArtifacts; - - use crate::metrics::METRICS; - use zksync_config::configs::fri_prover_group::FriProverGroupConfig; - use zksync_config::configs::FriProverConfig; + use zksync_config::configs::{fri_prover_group::FriProverGroupConfig, FriProverConfig}; use zksync_dal::ConnectionPool; use zksync_env_config::FromEnv; use zksync_object_store::ObjectStore; - use zksync_prover_fri_types::{CircuitWrapper, FriProofWrapper, ProverServiceDataKey}; + use zksync_prover_fri_types::{ + circuit_definitions::{ + base_layer_proof_config, + boojum::{ + algebraic_props::{ + round_function::AbsorptionModeOverwrite, sponge::GoldilocksPoseidon2Sponge, + }, + cs::implementations::{pow::NoPow, transcript::GoldilocksPoisedon2Transcript}, + worker::Worker, + }, + circuit_definitions::{ + base_layer::ZkSyncBaseLayerProof, recursion_layer::ZkSyncRecursionLayerProof, + }, + }, + CircuitWrapper, FriProofWrapper, ProverServiceDataKey, WitnessVectorArtifacts, + }; use zksync_queued_job_processor::{async_trait, JobProcessor}; use zksync_types::{basic_fri_types::CircuitIdRoundTuple, proofs::SocketAddress}; - use zksync_vk_setup_data_server_fri::get_setup_data_for_circuit_type; - use { - shivini::gpu_prove_from_external_witness_data, shivini::ProverContext, - zksync_vk_setup_data_server_fri::GoldilocksGpuProverSetupData, + use zksync_vk_setup_data_server_fri::{ + get_setup_data_for_circuit_type, GoldilocksGpuProverSetupData, }; - use crate::utils::{ - get_setup_data_key, save_proof, setup_metadata_to_setup_data_key, verify_proof, - GpuProverJob, ProverArtifacts, SharedWitnessVectorQueue, + use crate::{ + metrics::METRICS, + utils::{ + get_setup_data_key, save_proof, setup_metadata_to_setup_data_key, verify_proof, + GpuProverJob, ProverArtifacts, SharedWitnessVectorQueue, + }, }; type DefaultTranscript = GoldilocksPoisedon2Transcript; diff --git a/prover/prover_fri/src/main.rs b/prover/prover_fri/src/main.rs index ab0994a3648..ff59fdbabfc 100644 --- a/prover/prover_fri/src/main.rs +++ b/prover/prover_fri/src/main.rs @@ -1,13 +1,16 @@ #![feature(generic_const_exprs)] -use anyhow::Context as _; use std::future::Future; -use tokio::sync::oneshot; -use tokio::sync::watch::Receiver; -use tokio::task::JoinHandle; +use anyhow::Context as _; +use local_ip_address::local_ip; use prometheus_exporter::PrometheusExporterConfig; -use zksync_config::configs::fri_prover_group::FriProverGroupConfig; -use zksync_config::configs::{FriProverConfig, PostgresConfig, ProverGroupConfig}; +use tokio::{ + sync::{oneshot, watch::Receiver}, + task::JoinHandle, +}; +use zksync_config::configs::{ + fri_prover_group::FriProverGroupConfig, FriProverConfig, PostgresConfig, ProverGroupConfig, +}; use zksync_dal::ConnectionPool; use zksync_env_config::{ object_store::{ProverObjectStoreConfig, PublicObjectStoreConfig}, @@ -15,22 +18,20 @@ use zksync_env_config::{ }; use zksync_object_store::{ObjectStore, ObjectStoreFactory}; use zksync_prover_fri_utils::get_all_circuit_id_round_tuples_for; - -use local_ip_address::local_ip; use zksync_prover_utils::region_fetcher::get_zone; use zksync_queued_job_processor::JobProcessor; -use zksync_types::basic_fri_types::CircuitIdRoundTuple; -use zksync_types::proofs::GpuProverInstanceStatus; -use zksync_types::proofs::SocketAddress; +use zksync_types::{ + basic_fri_types::CircuitIdRoundTuple, + proofs::{GpuProverInstanceStatus, SocketAddress}, +}; use zksync_utils::wait_for_tasks::wait_for_tasks; mod gpu_prover_job_processor; +mod metrics; mod prover_job_processor; mod socket_listener; mod utils; -mod metrics; - async fn graceful_shutdown(port: u16) -> anyhow::Result> { let postgres_config = PostgresConfig::from_env().context("PostgresConfig::from_env()")?; let pool = ConnectionPool::singleton(postgres_config.prover_url()?) @@ -170,9 +171,10 @@ async fn get_prover_tasks( pool: ConnectionPool, circuit_ids_for_round_to_be_proven: Vec, ) -> anyhow::Result>>> { - use crate::prover_job_processor::{load_setup_data_cache, Prover}; use zksync_vk_setup_data_server_fri::commitment_utils::get_cached_commitments; + use crate::prover_job_processor::{load_setup_data_cache, Prover}; + let vk_commitments = get_cached_commitments(); tracing::info!( @@ -203,9 +205,10 @@ async fn get_prover_tasks( pool: ConnectionPool, circuit_ids_for_round_to_be_proven: Vec, ) -> anyhow::Result>>> { + use std::sync::Arc; + use gpu_prover_job_processor::gpu_prover; use socket_listener::gpu_socket_listener; - use std::sync::Arc; use tokio::sync::Mutex; use zksync_prover_fri_types::queue::FixedSizeQueue; diff --git a/prover/prover_fri/src/metrics.rs b/prover/prover_fri/src/metrics.rs index 27ddce54d6c..f6f7adb817d 100644 --- a/prover/prover_fri/src/metrics.rs +++ b/prover/prover_fri/src/metrics.rs @@ -1,4 +1,5 @@ use std::time::Duration; + use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, LabeledFamily, Metrics}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet)] diff --git a/prover/prover_fri/src/prover_job_processor.rs b/prover/prover_fri/src/prover_job_processor.rs index 30beae5bc82..dbe4bee0c86 100644 --- a/prover/prover_fri/src/prover_job_processor.rs +++ b/prover/prover_fri/src/prover_job_processor.rs @@ -1,31 +1,27 @@ -use std::collections::HashMap; -use std::{sync::Arc, time::Instant}; +use std::{collections::HashMap, sync::Arc, time::Instant}; use anyhow::Context as _; use tokio::task::JoinHandle; -use zksync_prover_fri_types::circuit_definitions::aux_definitions::witness_oracle::VmWitnessOracle; -use zksync_prover_fri_types::circuit_definitions::boojum::cs::implementations::pow::NoPow; -use zksync_prover_fri_types::circuit_definitions::boojum::field::goldilocks::GoldilocksField; -use zksync_prover_fri_types::circuit_definitions::boojum::worker::Worker; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::base_layer::{ - ZkSyncBaseLayerCircuit, ZkSyncBaseLayerProof, -}; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::{ - ZkSyncRecursionLayerProof, ZkSyncRecursiveLayerCircuit, -}; -use zksync_prover_fri_types::circuit_definitions::{ - base_layer_proof_config, recursion_layer_proof_config, ZkSyncDefaultRoundFunction, -}; - use zkevm_test_harness::prover_utils::{prove_base_layer_circuit, prove_recursion_layer_circuit}; - -use crate::metrics::{CircuitLabels, Layer, METRICS}; -use zksync_config::configs::fri_prover_group::FriProverGroupConfig; -use zksync_config::configs::FriProverConfig; +use zksync_config::configs::{fri_prover_group::FriProverGroupConfig, FriProverConfig}; use zksync_dal::ConnectionPool; use zksync_env_config::FromEnv; use zksync_object_store::ObjectStore; -use zksync_prover_fri_types::{CircuitWrapper, FriProofWrapper, ProverJob, ProverServiceDataKey}; +use zksync_prover_fri_types::{ + circuit_definitions::{ + aux_definitions::witness_oracle::VmWitnessOracle, + base_layer_proof_config, + boojum::{ + cs::implementations::pow::NoPow, field::goldilocks::GoldilocksField, worker::Worker, + }, + circuit_definitions::{ + base_layer::{ZkSyncBaseLayerCircuit, ZkSyncBaseLayerProof}, + recursion_layer::{ZkSyncRecursionLayerProof, ZkSyncRecursiveLayerCircuit}, + }, + recursion_layer_proof_config, ZkSyncDefaultRoundFunction, + }, + CircuitWrapper, FriProofWrapper, ProverJob, ProverServiceDataKey, +}; use zksync_prover_fri_utils::fetch_next_circuit; use zksync_queued_job_processor::{async_trait, JobProcessor}; use zksync_types::{basic_fri_types::CircuitIdRoundTuple, protocol_version::L1VerifierConfig}; @@ -33,8 +29,12 @@ use zksync_vk_setup_data_server_fri::{ get_cpu_setup_data_for_circuit_type, GoldilocksProverSetupData, }; -use crate::utils::{ - get_setup_data_key, save_proof, setup_metadata_to_setup_data_key, verify_proof, ProverArtifacts, +use crate::{ + metrics::{CircuitLabels, Layer, METRICS}, + utils::{ + get_setup_data_key, save_proof, setup_metadata_to_setup_data_key, verify_proof, + ProverArtifacts, + }, }; pub enum SetupLoadMode { diff --git a/prover/prover_fri/src/socket_listener.rs b/prover/prover_fri/src/socket_listener.rs index e9ecbd1e60b..653fb4eb8da 100644 --- a/prover/prover_fri/src/socket_listener.rs +++ b/prover/prover_fri/src/socket_listener.rs @@ -1,27 +1,28 @@ #[cfg(feature = "gpu")] pub mod gpu_socket_listener { + use std::{net::SocketAddr, time::Instant}; + + use anyhow::Context as _; use shivini::synthesis_utils::{ init_base_layer_cs_for_repeated_proving, init_recursive_layer_cs_for_repeated_proving, }; - use std::net::SocketAddr; - use std::time::Instant; - use zksync_dal::ConnectionPool; - use zksync_types::proofs::AggregationRound; - use zksync_types::proofs::{GpuProverInstanceStatus, SocketAddress}; - use zksync_vk_setup_data_server_fri::{ - get_finalization_hints, get_round_for_recursive_circuit_type, - }; - - use crate::metrics::METRICS; - use crate::utils::{GpuProverJob, ProvingAssembly, SharedWitnessVectorQueue}; - use anyhow::Context as _; - use tokio::sync::watch; use tokio::{ io::copy, net::{TcpListener, TcpStream}, + sync::watch, }; + use zksync_dal::ConnectionPool; use zksync_object_store::bincode; use zksync_prover_fri_types::{CircuitWrapper, ProverServiceDataKey, WitnessVectorArtifacts}; + use zksync_types::proofs::{AggregationRound, GpuProverInstanceStatus, SocketAddress}; + use zksync_vk_setup_data_server_fri::{ + get_finalization_hints, get_round_for_recursive_circuit_type, + }; + + use crate::{ + metrics::METRICS, + utils::{GpuProverJob, ProvingAssembly, SharedWitnessVectorQueue}, + }; pub(crate) struct SocketListener { address: SocketAddress, diff --git a/prover/prover_fri/src/utils.rs b/prover/prover_fri/src/utils.rs index c67ee9149f1..d86adbf4e89 100644 --- a/prover/prover_fri/src/utils.rs +++ b/prover/prover_fri/src/utils.rs @@ -1,33 +1,35 @@ #![cfg_attr(not(feature = "gpu"), allow(unused_imports))] -use std::sync::Arc; -use std::time::Instant; -use zksync_prover_fri_types::circuit_definitions::boojum::config::ProvingCSConfig; -use zksync_prover_fri_types::circuit_definitions::boojum::cs::implementations::reference_cs::CSReferenceAssembly; +use std::{sync::Arc, time::Instant}; use tokio::sync::Mutex; use zkevm_test_harness::prover_utils::{verify_base_layer_proof, verify_recursion_layer_proof}; use zksync_dal::StorageProcessor; use zksync_object_store::ObjectStore; -use zksync_prover_fri_types::circuit_definitions::boojum::algebraic_props::round_function::AbsorptionModeOverwrite; -use zksync_prover_fri_types::circuit_definitions::boojum::algebraic_props::sponge::GoldilocksPoseidon2Sponge; -use zksync_prover_fri_types::circuit_definitions::boojum::cs::implementations::pow::NoPow; -use zksync_prover_fri_types::circuit_definitions::boojum::cs::implementations::proof::Proof; -use zksync_prover_fri_types::circuit_definitions::boojum::cs::implementations::verifier::VerificationKey; -use zksync_prover_fri_types::circuit_definitions::boojum::field::goldilocks::{ - GoldilocksExt2, GoldilocksField, -}; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::{ - ZkSyncRecursionLayerProof, ZkSyncRecursionLayerStorageType, -}; -use zksync_prover_fri_types::queue::FixedSizeQueue; use zksync_prover_fri_types::{ + circuit_definitions::{ + boojum::{ + algebraic_props::{ + round_function::AbsorptionModeOverwrite, sponge::GoldilocksPoseidon2Sponge, + }, + config::ProvingCSConfig, + cs::implementations::{ + pow::NoPow, proof::Proof, reference_cs::CSReferenceAssembly, + verifier::VerificationKey, + }, + field::goldilocks::{GoldilocksExt2, GoldilocksField}, + }, + circuit_definitions::recursion_layer::{ + ZkSyncRecursionLayerProof, ZkSyncRecursionLayerStorageType, + }, + }, + queue::FixedSizeQueue, CircuitWrapper, FriProofWrapper, ProverServiceDataKey, WitnessVectorArtifacts, }; use zksync_prover_fri_utils::get_base_layer_circuit_id_for_recursive_layer; +use zksync_types::{basic_fri_types::CircuitIdRoundTuple, proofs::AggregationRound, L1BatchNumber}; use crate::metrics::METRICS; -use zksync_types::{basic_fri_types::CircuitIdRoundTuple, proofs::AggregationRound, L1BatchNumber}; pub type F = GoldilocksField; pub type H = GoldilocksPoseidon2Sponge; diff --git a/prover/prover_fri/tests/basic_test.rs b/prover/prover_fri/tests/basic_test.rs index 133598d66db..89089ac8249 100644 --- a/prover/prover_fri/tests/basic_test.rs +++ b/prover/prover_fri/tests/basic_test.rs @@ -1,16 +1,13 @@ -use anyhow::Context as _; use std::sync::Arc; -use zksync_config::configs::FriProverConfig; -use zksync_config::ObjectStoreConfig; +use anyhow::Context as _; +use serde::Serialize; +use zksync_config::{configs::FriProverConfig, ObjectStoreConfig}; use zksync_env_config::FromEnv; use zksync_object_store::{bincode, FriCircuitKey, ObjectStoreFactory}; -use zksync_types::proofs::AggregationRound; -use zksync_types::L1BatchNumber; - -use serde::Serialize; use zksync_prover_fri::prover_job_processor::Prover; use zksync_prover_fri_types::{CircuitWrapper, ProverJob, ProverServiceDataKey}; +use zksync_types::{proofs::AggregationRound, L1BatchNumber}; use zksync_vk_setup_data_server_fri::generate_cpu_base_layer_setup_data; fn compare_serialized(expected: &T, actual: &T) { diff --git a/prover/prover_fri_gateway/src/api_data_fetcher.rs b/prover/prover_fri_gateway/src/api_data_fetcher.rs index 339a7bec9e6..f56a9af4cc8 100644 --- a/prover/prover_fri_gateway/src/api_data_fetcher.rs +++ b/prover/prover_fri_gateway/src/api_data_fetcher.rs @@ -1,14 +1,14 @@ use std::time::Duration; -use crate::metrics::METRICS; use async_trait::async_trait; use reqwest::Client; use serde::{de::DeserializeOwned, Serialize}; -use tokio::sync::watch; -use tokio::time::sleep; +use tokio::{sync::watch, time::sleep}; use zksync_dal::ConnectionPool; use zksync_object_store::ObjectStore; +use crate::metrics::METRICS; + /// The path to the API endpoint that returns the next proof generation data. pub(crate) const PROOF_GENERATION_DATA_PATH: &str = "/proof_generation_data"; diff --git a/prover/prover_fri_gateway/src/main.rs b/prover/prover_fri_gateway/src/main.rs index 3a3f8b42ae0..15329ce955a 100644 --- a/prover/prover_fri_gateway/src/main.rs +++ b/prover/prover_fri_gateway/src/main.rs @@ -1,9 +1,7 @@ use anyhow::Context as _; -use reqwest::Client; -use tokio::{sync::oneshot, sync::watch}; - -use crate::api_data_fetcher::{PeriodicApiStruct, PROOF_GENERATION_DATA_PATH, SUBMIT_PROOF_PATH}; use prometheus_exporter::PrometheusExporterConfig; +use reqwest::Client; +use tokio::sync::{oneshot, watch}; use zksync_config::configs::{FriProverGatewayConfig, PostgresConfig}; use zksync_dal::ConnectionPool; use zksync_env_config::{object_store::ProverObjectStoreConfig, FromEnv}; @@ -11,6 +9,8 @@ use zksync_object_store::ObjectStoreFactory; use zksync_types::prover_server_api::{ProofGenerationDataRequest, SubmitProofRequest}; use zksync_utils::wait_for_tasks::wait_for_tasks; +use crate::api_data_fetcher::{PeriodicApiStruct, PROOF_GENERATION_DATA_PATH, SUBMIT_PROOF_PATH}; + mod api_data_fetcher; mod metrics; mod proof_gen_data_fetcher; diff --git a/prover/prover_fri_gateway/src/proof_gen_data_fetcher.rs b/prover/prover_fri_gateway/src/proof_gen_data_fetcher.rs index 1f00c7f7429..a25d447ad22 100644 --- a/prover/prover_fri_gateway/src/proof_gen_data_fetcher.rs +++ b/prover/prover_fri_gateway/src/proof_gen_data_fetcher.rs @@ -1,5 +1,4 @@ use async_trait::async_trait; - use zksync_types::prover_server_api::{ ProofGenerationData, ProofGenerationDataRequest, ProofGenerationDataResponse, }; diff --git a/prover/prover_fri_gateway/src/proof_submitter.rs b/prover/prover_fri_gateway/src/proof_submitter.rs index 86b2e4004b3..78c7a6a6d8e 100644 --- a/prover/prover_fri_gateway/src/proof_submitter.rs +++ b/prover/prover_fri_gateway/src/proof_submitter.rs @@ -1,8 +1,9 @@ use async_trait::async_trait; use zksync_dal::fri_proof_compressor_dal::ProofCompressionJobStatus; - -use zksync_types::prover_server_api::{SubmitProofRequest, SubmitProofResponse}; -use zksync_types::L1BatchNumber; +use zksync_types::{ + prover_server_api::{SubmitProofRequest, SubmitProofResponse}, + L1BatchNumber, +}; use crate::api_data_fetcher::{PeriodicApi, PeriodicApiStruct}; diff --git a/prover/prover_fri_types/src/lib.rs b/prover/prover_fri_types/src/lib.rs index 9e84c02f057..c244cb99f5a 100644 --- a/prover/prover_fri_types/src/lib.rs +++ b/prover/prover_fri_types/src/lib.rs @@ -1,24 +1,20 @@ -pub mod queue; +use std::env; pub use circuit_definitions; -use std::env; +use circuit_definitions::{ + aux_definitions::witness_oracle::VmWitnessOracle, + boojum::{cs::implementations::witness::WitnessVec, field::goldilocks::GoldilocksField}, + circuit_definitions::{ + base_layer::{ZkSyncBaseLayerCircuit, ZkSyncBaseLayerProof}, + recursion_layer::{ZkSyncRecursionLayerProof, ZkSyncRecursiveLayerCircuit}, + }, + zkevm_circuits::scheduler::block_header::BlockAuxilaryOutputWitness, + ZkSyncDefaultRoundFunction, +}; +use zksync_object_store::{serialize_using_bincode, Bucket, FriCircuitKey, StoredObject}; +use zksync_types::{proofs::AggregationRound, L1BatchNumber}; -use circuit_definitions::aux_definitions::witness_oracle::VmWitnessOracle; -use circuit_definitions::boojum::cs::implementations::witness::WitnessVec; -use circuit_definitions::boojum::field::goldilocks::GoldilocksField; -use circuit_definitions::circuit_definitions::base_layer::ZkSyncBaseLayerCircuit; -use circuit_definitions::circuit_definitions::base_layer::ZkSyncBaseLayerProof; -use circuit_definitions::circuit_definitions::recursion_layer::ZkSyncRecursionLayerProof; -use circuit_definitions::circuit_definitions::recursion_layer::ZkSyncRecursiveLayerCircuit; -use circuit_definitions::zkevm_circuits::scheduler::block_header::BlockAuxilaryOutputWitness; -use circuit_definitions::ZkSyncDefaultRoundFunction; - -use zksync_object_store::serialize_using_bincode; -use zksync_object_store::Bucket; -use zksync_object_store::FriCircuitKey; -use zksync_object_store::StoredObject; -use zksync_types::proofs::AggregationRound; -use zksync_types::L1BatchNumber; +pub mod queue; #[derive(serde::Serialize, serde::Deserialize, Clone)] #[allow(clippy::large_enum_variant)] diff --git a/prover/prover_fri_utils/src/lib.rs b/prover/prover_fri_utils/src/lib.rs index f0edcd07902..eee7293b591 100644 --- a/prover/prover_fri_utils/src/lib.rs +++ b/prover/prover_fri_utils/src/lib.rs @@ -2,18 +2,21 @@ use std::time::Instant; use zksync_dal::StorageProcessor; use zksync_object_store::{FriCircuitKey, ObjectStore}; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::base_circuit_type_into_recursive_leaf_circuit_type; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::ZkSyncRecursionLayerStorageType; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::scheduler::aux::BaseLayerCircuitType; -use zksync_types::basic_fri_types::CircuitIdRoundTuple; - use zksync_prover_fri_types::{ + circuit_definitions::{ + circuit_definitions::recursion_layer::{ + base_circuit_type_into_recursive_leaf_circuit_type, ZkSyncRecursionLayerStorageType, + }, + zkevm_circuits::scheduler::aux::BaseLayerCircuitType, + }, get_current_pod_name, CircuitWrapper, ProverJob, ProverServiceDataKey, }; +use zksync_types::{ + basic_fri_types::CircuitIdRoundTuple, proofs::AggregationRound, + protocol_version::L1VerifierConfig, +}; use crate::metrics::{CircuitLabels, PROVER_FRI_UTILS_METRICS}; -use zksync_types::proofs::AggregationRound; -use zksync_types::protocol_version::L1VerifierConfig; pub mod metrics; pub mod socket_utils; diff --git a/prover/prover_fri_utils/src/metrics.rs b/prover/prover_fri_utils/src/metrics.rs index 767e2c25fc1..acb48bacb3e 100644 --- a/prover/prover_fri_utils/src/metrics.rs +++ b/prover/prover_fri_utils/src/metrics.rs @@ -1,4 +1,5 @@ use std::time::Duration; + use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics}; use zksync_types::proofs::AggregationRound; diff --git a/prover/prover_fri_utils/src/socket_utils.rs b/prover/prover_fri_utils/src/socket_utils.rs index 14e31e56f00..c0c5ddcbcb9 100644 --- a/prover/prover_fri_utils/src/socket_utils.rs +++ b/prover/prover_fri_utils/src/socket_utils.rs @@ -1,9 +1,9 @@ -use std::io::copy; -use std::io::ErrorKind; -use std::io::Read; -use std::net::SocketAddr; -use std::net::TcpStream; -use std::time::{Duration, Instant}; +use std::{ + io::{copy, ErrorKind, Read}, + net::{SocketAddr, TcpStream}, + time::{Duration, Instant}, +}; + use zksync_types::proofs::SocketAddress; pub fn send_assembly( diff --git a/prover/setup_key_generator_and_server/src/lib.rs b/prover/setup_key_generator_and_server/src/lib.rs index a2e4f0998f8..34b4896cefe 100644 --- a/prover/setup_key_generator_and_server/src/lib.rs +++ b/prover/setup_key_generator_and_server/src/lib.rs @@ -1,18 +1,20 @@ -use anyhow::Context as _; -use std::fs::File; -use std::io::Read; -use std::path::Path; - -use zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit; -use zkevm_test_harness::bellman::bn256::Bn256; -use zkevm_test_harness::witness::oracle::VmWitnessOracle; -use zkevm_test_harness::witness::recursive_aggregation::padding_aggregations; -use zkevm_test_harness::witness::vk_set_generator::circuits_for_vk_generation; -use zksync_types::circuit::GEOMETRY_CONFIG; +use std::{fs::File, io::Read, path::Path}; +use anyhow::Context as _; +use zkevm_test_harness::{ + abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, + bellman::bn256::Bn256, + witness::{ + oracle::VmWitnessOracle, recursive_aggregation::padding_aggregations, + vk_set_generator::circuits_for_vk_generation, + }, +}; use zksync_config::ProverConfigs; use zksync_env_config::FromEnv; -use zksync_types::circuit::{LEAF_SPLITTING_FACTOR, NODE_SPLITTING_FACTOR, SCHEDULER_UPPER_BOUND}; +use zksync_types::circuit::{ + GEOMETRY_CONFIG, LEAF_SPLITTING_FACTOR, NODE_SPLITTING_FACTOR, SCHEDULER_UPPER_BOUND, +}; + pub fn get_setup_for_circuit_type(circuit_type: u8) -> anyhow::Result> { let filepath = get_setup_key_file_path(circuit_type).context("get_setup_key_file_path()")?; tracing::info!("Fetching setup key from path: {}", filepath); diff --git a/prover/setup_key_generator_and_server/src/main.rs b/prover/setup_key_generator_and_server/src/main.rs index ea56a15aed7..9eee0aa5c09 100644 --- a/prover/setup_key_generator_and_server/src/main.rs +++ b/prover/setup_key_generator_and_server/src/main.rs @@ -1,12 +1,13 @@ #![cfg_attr(not(feature = "gpu"), allow(unused_imports))] +use std::{env, fs::File}; + use anyhow::Context as _; -use std::env; -use std::fs::File; use structopt::StructOpt; -use zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit; -use zkevm_test_harness::bellman::bn256::Bn256; -use zkevm_test_harness::witness::oracle::VmWitnessOracle; +use zkevm_test_harness::{ + abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, bellman::bn256::Bn256, + witness::oracle::VmWitnessOracle, +}; use zksync_setup_key_server::{get_circuits_for_vk, get_setup_key_write_file_path}; #[cfg(feature = "gpu")] diff --git a/prover/vk_setup_data_generator_server_fri/src/commitment_utils.rs b/prover/vk_setup_data_generator_server_fri/src/commitment_utils.rs index d04943dd1d6..d6efbb29c71 100644 --- a/prover/vk_setup_data_generator_server_fri/src/commitment_utils.rs +++ b/prover/vk_setup_data_generator_server_fri/src/commitment_utils.rs @@ -1,16 +1,21 @@ -use crate::get_recursive_layer_vk_for_circuit_type; -use crate::utils::get_leaf_vk_params; +use std::str::FromStr; + use anyhow::Context as _; use once_cell::sync::Lazy; -use std::str::FromStr; use structopt::lazy_static::lazy_static; use zkevm_test_harness::witness::recursive_aggregation::{ compute_leaf_vks_and_params_commitment, compute_node_vk_commitment, }; -use zksync_prover_fri_types::circuit_definitions::boojum::field::goldilocks::GoldilocksField; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::ZkSyncRecursionLayerStorageType; -use zksync_types::protocol_version::{L1VerifierConfig, VerifierParams}; -use zksync_types::H256; +use zksync_prover_fri_types::circuit_definitions::{ + boojum::field::goldilocks::GoldilocksField, + circuit_definitions::recursion_layer::ZkSyncRecursionLayerStorageType, +}; +use zksync_types::{ + protocol_version::{L1VerifierConfig, VerifierParams}, + H256, +}; + +use crate::{get_recursive_layer_vk_for_circuit_type, utils::get_leaf_vk_params}; lazy_static! { // TODO: do not initialize a static const with data read in runtime. diff --git a/prover/vk_setup_data_generator_server_fri/src/lib.rs b/prover/vk_setup_data_generator_server_fri/src/lib.rs index 75125aa8150..19fab9af470 100644 --- a/prover/vk_setup_data_generator_server_fri/src/lib.rs +++ b/prover/vk_setup_data_generator_server_fri/src/lib.rs @@ -1,62 +1,65 @@ #![feature(generic_const_exprs)] #![feature(allocator_api)] +use std::{fs, fs::File, io::Read}; + use anyhow::Context as _; use circuit_definitions::circuit_definitions::aux_layer::{ ZkSyncCompressionLayerStorageType, ZkSyncSnarkWrapperVK, }; -use std::fs; -use std::fs::File; -use std::io::Read; -use zksync_prover_fri_types::circuit_definitions::aux_definitions::witness_oracle::VmWitnessOracle; -use zksync_prover_fri_types::circuit_definitions::boojum::algebraic_props::round_function::AbsorptionModeOverwrite; -use zksync_prover_fri_types::circuit_definitions::boojum::algebraic_props::sponge::GenericAlgebraicSponge; - -use zksync_prover_fri_types::circuit_definitions::boojum::cs::implementations::hints::{ - DenseVariablesCopyHint, DenseWitnessCopyHint, -}; -use zksync_prover_fri_types::circuit_definitions::boojum::cs::implementations::polynomial_storage::{ - SetupBaseStorage, SetupStorage, -}; -use zksync_prover_fri_types::circuit_definitions::boojum::cs::implementations::setup::FinalizationHintsForProver; -use zksync_prover_fri_types::circuit_definitions::boojum::cs::implementations::verifier::VerificationKey; -use zksync_prover_fri_types::circuit_definitions::boojum::cs::oracle::merkle_tree::MerkleTreeWithCap; -use zksync_prover_fri_types::circuit_definitions::boojum::cs::oracle::TreeHasher; -use zksync_prover_fri_types::circuit_definitions::boojum::field::goldilocks::GoldilocksField; -use zksync_prover_fri_types::circuit_definitions::boojum::field::{PrimeField, SmallField}; - -use zksync_prover_fri_types::circuit_definitions::boojum::field::traits::field_like::PrimeFieldLikeVectorized; -use zksync_prover_fri_types::circuit_definitions::boojum::implementations::poseidon2::Poseidon2Goldilocks; -use zksync_prover_fri_types::circuit_definitions::boojum::worker::Worker; - -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::base_layer::{ - ZkSyncBaseLayerCircuit, ZkSyncBaseLayerVerificationKey, -}; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::{ - ZkSyncRecursionLayerStorageType, ZkSyncRecursionLayerVerificationKey, -}; -use zksync_prover_fri_types::circuit_definitions::{ - ZkSyncDefaultRoundFunction, BASE_LAYER_CAP_SIZE, BASE_LAYER_FRI_LDE_FACTOR, -}; - -use serde::de::DeserializeOwned; -use serde::{Deserialize, Serialize}; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; use zkevm_test_harness::prover_utils::create_base_layer_setup_data; use zksync_config::configs::FriProverConfig; use zksync_env_config::FromEnv; -use zksync_types::proofs::AggregationRound; -use zksync_types::zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit; -use zksync_types::zkevm_test_harness::bellman::bn256::Bn256; -use zksync_types::zkevm_test_harness::bellman::plonk::better_better_cs::setup::VerificationKey as SnarkVerificationKey; -use zksync_types::zkevm_test_harness::witness::oracle::VmWitnessOracle as SnarkWitnessOracle; +use zksync_prover_fri_types::{ + circuit_definitions::{ + aux_definitions::witness_oracle::VmWitnessOracle, + boojum::{ + algebraic_props::{ + round_function::AbsorptionModeOverwrite, sponge::GenericAlgebraicSponge, + }, + cs::{ + implementations::{ + hints::{DenseVariablesCopyHint, DenseWitnessCopyHint}, + polynomial_storage::{SetupBaseStorage, SetupStorage}, + setup::FinalizationHintsForProver, + verifier::VerificationKey, + }, + oracle::{merkle_tree::MerkleTreeWithCap, TreeHasher}, + }, + field::{ + goldilocks::GoldilocksField, traits::field_like::PrimeFieldLikeVectorized, + PrimeField, SmallField, + }, + implementations::poseidon2::Poseidon2Goldilocks, + worker::Worker, + }, + circuit_definitions::{ + base_layer::{ZkSyncBaseLayerCircuit, ZkSyncBaseLayerVerificationKey}, + recursion_layer::{ + ZkSyncRecursionLayerStorageType, ZkSyncRecursionLayerVerificationKey, + }, + }, + ZkSyncDefaultRoundFunction, BASE_LAYER_CAP_SIZE, BASE_LAYER_FRI_LDE_FACTOR, + }, + ProverServiceDataKey, +}; +use zksync_types::{ + proofs::AggregationRound, + zkevm_test_harness::{ + abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit, + bellman::{ + bn256::Bn256, plonk::better_better_cs::setup::VerificationKey as SnarkVerificationKey, + }, + witness::oracle::VmWitnessOracle as SnarkWitnessOracle, + }, +}; +#[cfg(feature = "gpu")] +use {shivini::cs::GpuSetup, std::alloc::Global}; pub mod commitment_utils; pub mod utils; -use zksync_prover_fri_types::ProverServiceDataKey; -#[cfg(feature = "gpu")] -use {shivini::cs::GpuSetup, std::alloc::Global}; - #[derive(Debug, Serialize, Deserialize)] #[serde( bound = "F: serde::Serialize + serde::de::DeserializeOwned, P: serde::Serialize + serde::de::DeserializeOwned" diff --git a/prover/vk_setup_data_generator_server_fri/src/main.rs b/prover/vk_setup_data_generator_server_fri/src/main.rs index 6d2e1d0712a..158a4390a96 100644 --- a/prover/vk_setup_data_generator_server_fri/src/main.rs +++ b/prover/vk_setup_data_generator_server_fri/src/main.rs @@ -1,17 +1,19 @@ #![feature(generic_const_exprs)] + use anyhow::Context as _; use circuit_definitions::circuit_definitions::recursion_layer::ZkSyncRecursionLayerVerificationKey; -use zkevm_test_harness::compute_setups::{ - generate_base_layer_vks_and_proofs, generate_recursive_layer_vks_and_proofs, +use zkevm_test_harness::{ + compute_setups::{generate_base_layer_vks_and_proofs, generate_recursive_layer_vks_and_proofs}, + data_source::{in_memory_data_source::InMemoryDataSource, SetupDataSource}, + proof_wrapper_utils::{get_wrapper_setup_and_vk_from_scheduler_vk, WrapperConfig}, }; -use zkevm_test_harness::data_source::in_memory_data_source::InMemoryDataSource; -use zkevm_test_harness::data_source::SetupDataSource; -use zkevm_test_harness::proof_wrapper_utils::{ - get_wrapper_setup_and_vk_from_scheduler_vk, WrapperConfig, +use zksync_prover_fri_types::{ + circuit_definitions::{ + circuit_definitions::recursion_layer::ZkSyncRecursionLayerStorageType, + zkevm_circuits::scheduler::aux::BaseLayerCircuitType, + }, + ProverServiceDataKey, }; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::ZkSyncRecursionLayerStorageType; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::scheduler::aux::BaseLayerCircuitType; -use zksync_prover_fri_types::ProverServiceDataKey; use zksync_types::proofs::AggregationRound; use zksync_vk_setup_data_server_fri::{ get_round_for_recursive_circuit_type, save_base_layer_vk, save_finalization_hints, diff --git a/prover/vk_setup_data_generator_server_fri/src/setup_data_generator.rs b/prover/vk_setup_data_generator_server_fri/src/setup_data_generator.rs index 354594a556a..5df4b75b3a6 100644 --- a/prover/vk_setup_data_generator_server_fri/src/setup_data_generator.rs +++ b/prover/vk_setup_data_generator_server_fri/src/setup_data_generator.rs @@ -1,28 +1,28 @@ use anyhow::Context as _; -use zksync_prover_fri_types::circuit_definitions::aux_definitions::witness_oracle::VmWitnessOracle; -use zksync_prover_fri_types::circuit_definitions::boojum::field::goldilocks::GoldilocksField; -use zksync_prover_fri_types::circuit_definitions::boojum::worker::Worker; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::base_layer::ZkSyncBaseLayerCircuit; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::ZkSyncRecursiveLayerCircuit; -use zksync_prover_fri_types::circuit_definitions::{ - ZkSyncDefaultRoundFunction, BASE_LAYER_CAP_SIZE, BASE_LAYER_FRI_LDE_FACTOR, -}; - use structopt::StructOpt; -use zkevm_test_harness::geometry_config::get_geometry_config; -use zkevm_test_harness::prover_utils::create_recursive_layer_setup_data; -use zksync_types::proofs::AggregationRound; -use zksync_vk_setup_data_server_fri::generate_cpu_base_layer_setup_data; -use zksync_vk_setup_data_server_fri::utils::{ - get_basic_circuits, get_leaf_circuits, get_node_circuit, get_scheduler_circuit, CYCLE_LIMIT, +use zkevm_test_harness::{ + geometry_config::get_geometry_config, prover_utils::create_recursive_layer_setup_data, }; +use zksync_prover_fri_types::{ + circuit_definitions::{ + aux_definitions::witness_oracle::VmWitnessOracle, + boojum::{field::goldilocks::GoldilocksField, worker::Worker}, + circuit_definitions::{ + base_layer::ZkSyncBaseLayerCircuit, recursion_layer::ZkSyncRecursiveLayerCircuit, + }, + ZkSyncDefaultRoundFunction, BASE_LAYER_CAP_SIZE, BASE_LAYER_FRI_LDE_FACTOR, + }, + ProverServiceDataKey, +}; +use zksync_types::proofs::AggregationRound; use zksync_vk_setup_data_server_fri::{ - get_finalization_hints, get_recursive_layer_vk_for_circuit_type, - get_round_for_recursive_circuit_type, save_setup_data, GoldilocksProverSetupData, - ProverSetupData, + generate_cpu_base_layer_setup_data, get_finalization_hints, + get_recursive_layer_vk_for_circuit_type, get_round_for_recursive_circuit_type, save_setup_data, + utils::{ + get_basic_circuits, get_leaf_circuits, get_node_circuit, get_scheduler_circuit, CYCLE_LIMIT, + }, + GoldilocksProverSetupData, ProverSetupData, }; - -use zksync_prover_fri_types::ProverServiceDataKey; #[cfg(feature = "gpu")] use { shivini::cs::setup::GpuSetup, shivini::ProverContext, diff --git a/prover/vk_setup_data_generator_server_fri/src/tests.rs b/prover/vk_setup_data_generator_server_fri/src/tests.rs index 46cdc94562b..3d6a203ed97 100644 --- a/prover/vk_setup_data_generator_server_fri/src/tests.rs +++ b/prover/vk_setup_data_generator_server_fri/src/tests.rs @@ -1,9 +1,13 @@ use proptest::prelude::*; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::{ - base_circuit_type_into_recursive_leaf_circuit_type, ZkSyncRecursionLayerStorageType, +use zksync_prover_fri_types::{ + circuit_definitions::{ + circuit_definitions::recursion_layer::{ + base_circuit_type_into_recursive_leaf_circuit_type, ZkSyncRecursionLayerStorageType, + }, + zkevm_circuits::scheduler::aux::BaseLayerCircuitType, + }, + ProverServiceDataKey, }; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::scheduler::aux::BaseLayerCircuitType; -use zksync_prover_fri_types::ProverServiceDataKey; use zksync_types::proofs::AggregationRound; use zksync_vk_setup_data_server_fri::{ get_base_layer_vk_for_circuit_type, get_base_path, get_file_path, get_finalization_hints, diff --git a/prover/vk_setup_data_generator_server_fri/src/utils.rs b/prover/vk_setup_data_generator_server_fri/src/utils.rs index 03c0fb4a210..01b40de3394 100644 --- a/prover/vk_setup_data_generator_server_fri/src/utils.rs +++ b/prover/vk_setup_data_generator_server_fri/src/utils.rs @@ -1,57 +1,74 @@ -use crate::{ - get_base_layer_vk_for_circuit_type, get_base_path, get_recursive_layer_vk_for_circuit_type, -}; -use zksync_prover_fri_types::circuit_definitions::aux_definitions::witness_oracle::VmWitnessOracle; -use zksync_prover_fri_types::circuit_definitions::boojum::field::goldilocks::{GoldilocksExt2, GoldilocksField}; -use zksync_prover_fri_types::circuit_definitions::boojum::gadgets::queue::full_state_queue::FullStateCircuitQueueRawWitness; -use zksync_prover_fri_types::circuit_definitions::boojum::gadgets::recursion::recursive_tree_hasher::CircuitGoldilocksPoseidon2Sponge; -use zksync_prover_fri_types::circuit_definitions::boojum::gadgets::traits::allocatable::CSAllocatable; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::base_layer::ZkSyncBaseLayerCircuit; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::leaf_layer::ZkSyncLeafLayerRecursiveCircuit; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::node_layer::ZkSyncNodeLayerRecursiveCircuit; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::scheduler::SchedulerCircuit; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::{ - base_circuit_type_into_recursive_leaf_circuit_type, ZkSyncRecursionLayerStorageType, - ZkSyncRecursionProof, ZkSyncRecursiveLayerCircuit, RECURSION_ARITY, SCHEDULER_CAPACITY, -}; -use zksync_prover_fri_types::circuit_definitions::zk_evm::bytecode_to_code_hash; -use zksync_prover_fri_types::circuit_definitions::zk_evm::testing::storage::InMemoryStorage; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::recursion::leaf_layer::input::RecursionLeafParametersWitness; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::recursion::leaf_layer::input::{ - RecursionLeafInput, RecursionLeafInstanceWitness, -}; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::recursion::leaf_layer::LeafLayerRecursionConfig; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::recursion::node_layer::input::{ - RecursionNodeInput, RecursionNodeInstanceWitness, -}; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::recursion::node_layer::NodeLayerRecursionConfig; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::scheduler::aux::BaseLayerCircuitType; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::scheduler::input::SchedulerCircuitInstanceWitness; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::scheduler::SchedulerConfig; -use zksync_prover_fri_types::circuit_definitions::{ - base_layer_proof_config, recursion_layer_proof_config, zk_evm, ZkSyncDefaultRoundFunction, +use std::{ + collections::{HashMap, VecDeque}, + fs, }; + use anyhow::Context as _; use itertools::Itertools; -use std::collections::{HashMap, VecDeque}; -use std::fs; -use zkevm_test_harness::compute_setups::{ - generate_base_layer_vks_and_proofs, generate_recursive_layer_vks_and_proofs, +use zkevm_test_harness::{ + compute_setups::{generate_base_layer_vks_and_proofs, generate_recursive_layer_vks_and_proofs}, + data_source::{in_memory_data_source::InMemoryDataSource, BlockDataSource}, + ethereum_types::{Address, U256}, + external_calls::run, + helper::artifact_utils::{save_predeployed_contracts, TestArtifact}, + sha3::{Digest, Keccak256}, + toolset::GeometryConfig, + witness::{ + full_block_artifact::{ + BlockBasicCircuits, BlockBasicCircuitsPublicCompactFormsWitnesses, + BlockBasicCircuitsPublicInputs, + }, + recursive_aggregation::compute_leaf_params, + tree::{BinarySparseStorageTree, ZKSyncTestingTree}, + }, }; -use zkevm_test_harness::data_source::BlockDataSource; -use zkevm_test_harness::ethereum_types::{Address, U256}; -use zkevm_test_harness::external_calls::run; -use zkevm_test_harness::helper::artifact_utils::{save_predeployed_contracts, TestArtifact}; -use zkevm_test_harness::sha3::{Digest, Keccak256}; -use zkevm_test_harness::toolset::GeometryConfig; -use zkevm_test_harness::witness::full_block_artifact::{ - BlockBasicCircuits, BlockBasicCircuitsPublicCompactFormsWitnesses, - BlockBasicCircuitsPublicInputs, +use zksync_prover_fri_types::circuit_definitions::{ + aux_definitions::witness_oracle::VmWitnessOracle, + base_layer_proof_config, + boojum::{ + field::goldilocks::{GoldilocksExt2, GoldilocksField}, + gadgets::{ + queue::full_state_queue::FullStateCircuitQueueRawWitness, + recursion::recursive_tree_hasher::CircuitGoldilocksPoseidon2Sponge, + traits::allocatable::CSAllocatable, + }, + }, + circuit_definitions::{ + base_layer::ZkSyncBaseLayerCircuit, + recursion_layer::{ + base_circuit_type_into_recursive_leaf_circuit_type, + leaf_layer::ZkSyncLeafLayerRecursiveCircuit, + node_layer::ZkSyncNodeLayerRecursiveCircuit, scheduler::SchedulerCircuit, + ZkSyncRecursionLayerStorageType, ZkSyncRecursionProof, ZkSyncRecursiveLayerCircuit, + RECURSION_ARITY, SCHEDULER_CAPACITY, + }, + }, + recursion_layer_proof_config, zk_evm, + zk_evm::{bytecode_to_code_hash, testing::storage::InMemoryStorage}, + zkevm_circuits::{ + recursion::{ + leaf_layer::{ + input::{ + RecursionLeafInput, RecursionLeafInstanceWitness, + RecursionLeafParametersWitness, + }, + LeafLayerRecursionConfig, + }, + node_layer::{ + input::{RecursionNodeInput, RecursionNodeInstanceWitness}, + NodeLayerRecursionConfig, + }, + }, + scheduler::{ + aux::BaseLayerCircuitType, input::SchedulerCircuitInstanceWitness, SchedulerConfig, + }, + }, + ZkSyncDefaultRoundFunction, }; -use zkevm_test_harness::witness::recursive_aggregation::compute_leaf_params; -use zkevm_test_harness::witness::tree::{BinarySparseStorageTree, ZKSyncTestingTree}; -use zkevm_test_harness::data_source::in_memory_data_source::InMemoryDataSource; +use crate::{ + get_base_layer_vk_for_circuit_type, get_base_path, get_recursive_layer_vk_for_circuit_type, +}; pub const CYCLE_LIMIT: usize = 20000; diff --git a/prover/vk_setup_data_generator_server_fri/src/vk_generator.rs b/prover/vk_setup_data_generator_server_fri/src/vk_generator.rs index 2a94b53eb63..2b633bc6d08 100644 --- a/prover/vk_setup_data_generator_server_fri/src/vk_generator.rs +++ b/prover/vk_setup_data_generator_server_fri/src/vk_generator.rs @@ -1,23 +1,26 @@ use anyhow::Context as _; -use zkevm_test_harness::geometry_config::get_geometry_config; -use zkevm_test_harness::prover_utils::{ - create_base_layer_setup_data, create_recursive_layer_setup_data, +use zkevm_test_harness::{ + geometry_config::get_geometry_config, + prover_utils::{create_base_layer_setup_data, create_recursive_layer_setup_data}, }; -use zksync_prover_fri_types::circuit_definitions::boojum::worker::Worker; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::base_layer::ZkSyncBaseLayerVerificationKey; -use zksync_prover_fri_types::circuit_definitions::{ - BASE_LAYER_CAP_SIZE, BASE_LAYER_FRI_LDE_FACTOR, +use zksync_prover_fri_types::{ + circuit_definitions::{ + boojum::worker::Worker, + circuit_definitions::{ + base_layer::ZkSyncBaseLayerVerificationKey, + recursion_layer::ZkSyncRecursionLayerVerificationKey, + }, + BASE_LAYER_CAP_SIZE, BASE_LAYER_FRI_LDE_FACTOR, + }, + ProverServiceDataKey, }; -use zksync_vk_setup_data_server_fri::utils::{get_basic_circuits, get_leaf_circuits, CYCLE_LIMIT}; +use zksync_types::proofs::AggregationRound; use zksync_vk_setup_data_server_fri::{ get_round_for_recursive_circuit_type, save_base_layer_vk, save_finalization_hints, save_recursive_layer_vk, + utils::{get_basic_circuits, get_leaf_circuits, CYCLE_LIMIT}, }; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::ZkSyncRecursionLayerVerificationKey; -use zksync_prover_fri_types::ProverServiceDataKey; -use zksync_types::proofs::AggregationRound; - #[allow(dead_code)] fn main() -> anyhow::Result<()> { tracing::info!("starting vk generator"); diff --git a/prover/witness_generator/src/basic_circuits.rs b/prover/witness_generator/src/basic_circuits.rs index 963ec034b26..b883c4bb35a 100644 --- a/prover/witness_generator/src/basic_circuits.rs +++ b/prover/witness_generator/src/basic_circuits.rs @@ -1,54 +1,61 @@ -use std::hash::Hash; -use std::sync::Arc; use std::{ collections::{hash_map::DefaultHasher, HashMap, HashSet}, - hash::Hasher, + hash::{Hash, Hasher}, + sync::Arc, time::Instant, }; use anyhow::Context as _; use async_trait::async_trait; -use zksync_prover_fri_types::circuit_definitions::ZkSyncDefaultRoundFunction; -use rand::Rng; -use serde::{Deserialize, Serialize}; -use zksync_prover_fri_types::circuit_definitions::boojum::field::goldilocks::{GoldilocksExt2, GoldilocksField}; -use zksync_prover_fri_types::circuit_definitions::boojum::gadgets::recursion::recursive_tree_hasher::CircuitGoldilocksPoseidon2Sponge; -use zkevm_test_harness::geometry_config::get_geometry_config; -use zkevm_test_harness::toolset::GeometryConfig; -use zkevm_test_harness::witness::full_block_artifact::{ - BlockBasicCircuits, BlockBasicCircuitsPublicCompactFormsWitnesses, - BlockBasicCircuitsPublicInputs, -}; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::scheduler::block_header::BlockAuxilaryOutputWitness; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::scheduler::input::SchedulerCircuitInstanceWitness; -use zksync_prover_fri_types::{AuxOutputWitnessWrapper, get_current_pod_name}; - -use crate::metrics::WITNESS_GENERATOR_METRICS; -use crate::storage_oracle::StorageOracle; use multivm::vm_latest::{ constants::MAX_CYCLES_FOR_TX, HistoryDisabled, StorageOracle as VmStorageOracle, }; +use rand::Rng; +use serde::{Deserialize, Serialize}; +use zkevm_test_harness::{ + geometry_config::get_geometry_config, + toolset::GeometryConfig, + witness::full_block_artifact::{ + BlockBasicCircuits, BlockBasicCircuitsPublicCompactFormsWitnesses, + BlockBasicCircuitsPublicInputs, + }, +}; use zksync_config::configs::FriWitnessGeneratorConfig; -use zksync_dal::fri_witness_generator_dal::FriWitnessJobStatus; -use zksync_dal::ConnectionPool; +use zksync_dal::{fri_witness_generator_dal::FriWitnessJobStatus, ConnectionPool}; use zksync_object_store::{ Bucket, ClosedFormInputKey, ObjectStore, ObjectStoreFactory, StoredObject, }; +use zksync_prover_fri_types::{ + circuit_definitions::{ + boojum::{ + field::goldilocks::{GoldilocksExt2, GoldilocksField}, + gadgets::recursion::recursive_tree_hasher::CircuitGoldilocksPoseidon2Sponge, + }, + zkevm_circuits::scheduler::{ + block_header::BlockAuxilaryOutputWitness, input::SchedulerCircuitInstanceWitness, + }, + ZkSyncDefaultRoundFunction, + }, + get_current_pod_name, AuxOutputWitnessWrapper, +}; use zksync_prover_fri_utils::get_recursive_layer_circuit_id_for_base_layer; use zksync_queued_job_processor::JobProcessor; use zksync_state::{PostgresStorage, StorageView}; -use zksync_types::proofs::AggregationRound; -use zksync_types::protocol_version::FriProtocolVersionId; use zksync_types::{ - proofs::{BasicCircuitWitnessGeneratorInput, PrepareBasicCircuitsJob}, + proofs::{AggregationRound, BasicCircuitWitnessGeneratorInput, PrepareBasicCircuitsJob}, + protocol_version::FriProtocolVersionId, Address, L1BatchNumber, BOOTLOADER_ADDRESS, H256, U256, }; use zksync_utils::{bytes_to_chunks, h256_to_u256, u256_to_h256}; -use crate::precalculated_merkle_paths_provider::PrecalculatedMerklePathsProvider; -use crate::utils::{ - expand_bootloader_contents, save_base_prover_input_artifacts, ClosedFormInputWrapper, - SchedulerPartialInputWrapper, +use crate::{ + metrics::WITNESS_GENERATOR_METRICS, + precalculated_merkle_paths_provider::PrecalculatedMerklePathsProvider, + storage_oracle::StorageOracle, + utils::{ + expand_bootloader_contents, save_base_prover_input_artifacts, ClosedFormInputWrapper, + SchedulerPartialInputWrapper, + }, }; pub struct BasicCircuitArtifacts { diff --git a/prover/witness_generator/src/leaf_aggregation.rs b/prover/witness_generator/src/leaf_aggregation.rs index d90520a19e6..f190aeb2164 100644 --- a/prover/witness_generator/src/leaf_aggregation.rs +++ b/prover/witness_generator/src/leaf_aggregation.rs @@ -1,36 +1,46 @@ -use zkevm_test_harness::witness::recursive_aggregation::{ - compute_leaf_params, create_leaf_witnesses, -}; - -use anyhow::Context as _; use std::time::Instant; +use anyhow::Context as _; use async_trait::async_trait; -use zksync_prover_fri_types::circuit_definitions::boojum::field::goldilocks::GoldilocksField; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::base_layer::{ - ZkSyncBaseLayerClosedFormInput, ZkSyncBaseLayerProof, ZkSyncBaseLayerVerificationKey, +use zkevm_test_harness::witness::recursive_aggregation::{ + compute_leaf_params, create_leaf_witnesses, +}; +use zksync_config::configs::FriWitnessGeneratorConfig; +use zksync_dal::ConnectionPool; +use zksync_object_store::{ClosedFormInputKey, ObjectStore, ObjectStoreFactory}; +use zksync_prover_fri_types::{ + circuit_definitions::{ + boojum::field::goldilocks::GoldilocksField, + circuit_definitions::{ + base_layer::{ + ZkSyncBaseLayerClosedFormInput, ZkSyncBaseLayerProof, + ZkSyncBaseLayerVerificationKey, + }, + recursion_layer::ZkSyncRecursiveLayerCircuit, + }, + encodings::recursion_request::RecursionQueueSimulator, + zkevm_circuits::recursion::leaf_layer::input::RecursionLeafParametersWitness, + }, + get_current_pod_name, FriProofWrapper, }; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::ZkSyncRecursiveLayerCircuit; -use zksync_prover_fri_types::circuit_definitions::encodings::recursion_request::RecursionQueueSimulator; -use zksync_prover_fri_types::{get_current_pod_name, FriProofWrapper}; use zksync_prover_fri_utils::get_recursive_layer_circuit_id_for_base_layer; +use zksync_queued_job_processor::JobProcessor; +use zksync_types::{ + proofs::{AggregationRound, LeafAggregationJobMetadata}, + protocol_version::FriProtocolVersionId, + L1BatchNumber, +}; use zksync_vk_setup_data_server_fri::{ get_base_layer_vk_for_circuit_type, get_recursive_layer_vk_for_circuit_type, }; -use crate::metrics::WITNESS_GENERATOR_METRICS; -use crate::utils::{ - load_proofs_for_job_ids, save_node_aggregations_artifacts, - save_recursive_layer_prover_input_artifacts, ClosedFormInputWrapper, +use crate::{ + metrics::WITNESS_GENERATOR_METRICS, + utils::{ + load_proofs_for_job_ids, save_node_aggregations_artifacts, + save_recursive_layer_prover_input_artifacts, ClosedFormInputWrapper, + }, }; -use zksync_config::configs::FriWitnessGeneratorConfig; -use zksync_dal::ConnectionPool; -use zksync_object_store::{ClosedFormInputKey, ObjectStore, ObjectStoreFactory}; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::recursion::leaf_layer::input::RecursionLeafParametersWitness; -use zksync_queued_job_processor::JobProcessor; -use zksync_types::proofs::{AggregationRound, LeafAggregationJobMetadata}; -use zksync_types::protocol_version::FriProtocolVersionId; -use zksync_types::L1BatchNumber; pub struct LeafAggregationArtifacts { circuit_id: u8, diff --git a/prover/witness_generator/src/main.rs b/prover/witness_generator/src/main.rs index a8d0bda48f2..c977f216104 100644 --- a/prover/witness_generator/src/main.rs +++ b/prover/witness_generator/src/main.rs @@ -1,37 +1,37 @@ #![feature(generic_const_exprs)] +use std::time::Instant; + use anyhow::{anyhow, Context as _}; use prometheus_exporter::PrometheusExporterConfig; -use std::time::Instant; use structopt::StructOpt; use tokio::sync::watch; -use zksync_config::configs::{FriWitnessGeneratorConfig, PostgresConfig, PrometheusConfig}; -use zksync_config::ObjectStoreConfig; +use zksync_config::{ + configs::{FriWitnessGeneratorConfig, PostgresConfig, PrometheusConfig}, + ObjectStoreConfig, +}; use zksync_dal::ConnectionPool; use zksync_env_config::{object_store::ProverObjectStoreConfig, FromEnv}; use zksync_object_store::ObjectStoreFactory; use zksync_prover_utils::get_stop_signal_receiver; use zksync_queued_job_processor::JobProcessor; -use zksync_types::proofs::AggregationRound; -use zksync_types::web3::futures::StreamExt; +use zksync_types::{proofs::AggregationRound, web3::futures::StreamExt}; use zksync_utils::wait_for_tasks::wait_for_tasks; use zksync_vk_setup_data_server_fri::commitment_utils::get_cached_commitments; -use crate::basic_circuits::BasicWitnessGenerator; -use crate::leaf_aggregation::LeafAggregationWitnessGenerator; -use crate::metrics::SERVER_METRICS; -use crate::node_aggregation::NodeAggregationWitnessGenerator; -use crate::scheduler::SchedulerWitnessGenerator; +use crate::{ + basic_circuits::BasicWitnessGenerator, leaf_aggregation::LeafAggregationWitnessGenerator, + metrics::SERVER_METRICS, node_aggregation::NodeAggregationWitnessGenerator, + scheduler::SchedulerWitnessGenerator, +}; mod basic_circuits; mod leaf_aggregation; +mod metrics; mod node_aggregation; mod precalculated_merkle_paths_provider; mod scheduler; mod storage_oracle; - -mod metrics; - mod utils; #[derive(Debug, StructOpt)] diff --git a/prover/witness_generator/src/metrics.rs b/prover/witness_generator/src/metrics.rs index 3bddefc00c4..f0497dd23a1 100644 --- a/prover/witness_generator/src/metrics.rs +++ b/prover/witness_generator/src/metrics.rs @@ -1,4 +1,5 @@ use std::time::Duration; + use vise::{Buckets, Counter, Family, Gauge, Histogram, LabeledFamily, Metrics}; use zksync_prover_fri_utils::metrics::StageLabel; diff --git a/prover/witness_generator/src/node_aggregation.rs b/prover/witness_generator/src/node_aggregation.rs index 1ae5a255197..be9e5d0d622 100644 --- a/prover/witness_generator/src/node_aggregation.rs +++ b/prover/witness_generator/src/node_aggregation.rs @@ -2,33 +2,41 @@ use std::time::Instant; use anyhow::Context as _; use async_trait::async_trait; -use zksync_prover_fri_types::circuit_definitions::boojum::field::goldilocks::GoldilocksField; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::{ - ZkSyncRecursionLayerProof, ZkSyncRecursionLayerStorageType, - ZkSyncRecursionLayerVerificationKey, ZkSyncRecursiveLayerCircuit, -}; -use zksync_prover_fri_types::circuit_definitions::encodings::recursion_request::RecursionQueueSimulator; - use zkevm_test_harness::witness::recursive_aggregation::{ compute_node_vk_commitment, create_node_witnesses, }; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::recursion::leaf_layer::input::RecursionLeafParametersWitness; -use zksync_vk_setup_data_server_fri::get_recursive_layer_vk_for_circuit_type; -use zksync_vk_setup_data_server_fri::utils::get_leaf_vk_params; - -use crate::metrics::WITNESS_GENERATOR_METRICS; -use crate::utils::{ - load_proofs_for_job_ids, save_node_aggregations_artifacts, - save_recursive_layer_prover_input_artifacts, AggregationWrapper, -}; use zksync_config::configs::FriWitnessGeneratorConfig; use zksync_dal::ConnectionPool; use zksync_object_store::{AggregationsKey, ObjectStore, ObjectStoreFactory}; -use zksync_prover_fri_types::{get_current_pod_name, FriProofWrapper}; +use zksync_prover_fri_types::{ + circuit_definitions::{ + boojum::field::goldilocks::GoldilocksField, + circuit_definitions::recursion_layer::{ + ZkSyncRecursionLayerProof, ZkSyncRecursionLayerStorageType, + ZkSyncRecursionLayerVerificationKey, ZkSyncRecursiveLayerCircuit, + }, + encodings::recursion_request::RecursionQueueSimulator, + zkevm_circuits::recursion::leaf_layer::input::RecursionLeafParametersWitness, + }, + get_current_pod_name, FriProofWrapper, +}; use zksync_queued_job_processor::JobProcessor; -use zksync_types::proofs::NodeAggregationJobMetadata; -use zksync_types::protocol_version::FriProtocolVersionId; -use zksync_types::{proofs::AggregationRound, L1BatchNumber}; +use zksync_types::{ + proofs::{AggregationRound, NodeAggregationJobMetadata}, + protocol_version::FriProtocolVersionId, + L1BatchNumber, +}; +use zksync_vk_setup_data_server_fri::{ + get_recursive_layer_vk_for_circuit_type, utils::get_leaf_vk_params, +}; + +use crate::{ + metrics::WITNESS_GENERATOR_METRICS, + utils::{ + load_proofs_for_job_ids, save_node_aggregations_artifacts, + save_recursive_layer_prover_input_artifacts, AggregationWrapper, + }, +}; pub struct NodeAggregationArtifacts { circuit_id: u8, diff --git a/prover/witness_generator/src/precalculated_merkle_paths_provider.rs b/prover/witness_generator/src/precalculated_merkle_paths_provider.rs index 01bfd78fb28..89f5ca408aa 100644 --- a/prover/witness_generator/src/precalculated_merkle_paths_provider.rs +++ b/prover/witness_generator/src/precalculated_merkle_paths_provider.rs @@ -1,12 +1,9 @@ use serde::{Deserialize, Serialize}; - -use zkevm_test_harness::witness::tree::{BinaryHasher, EnumeratedBinaryLeaf, LeafQuery}; - -use zksync_types::proofs::{PrepareBasicCircuitsJob, StorageLogMetadata}; - use zk_evm::blake2::Blake2s256; -use zkevm_test_harness::witness::tree::BinarySparseStorageTree; -use zkevm_test_harness::witness::tree::ZkSyncStorageLeaf; +use zkevm_test_harness::witness::tree::{ + BinaryHasher, BinarySparseStorageTree, EnumeratedBinaryLeaf, LeafQuery, ZkSyncStorageLeaf, +}; +use zksync_types::proofs::{PrepareBasicCircuitsJob, StorageLogMetadata}; #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct PrecalculatedMerklePathsProvider { diff --git a/prover/witness_generator/src/scheduler.rs b/prover/witness_generator/src/scheduler.rs index 5036aa188ec..921ba68f402 100644 --- a/prover/witness_generator/src/scheduler.rs +++ b/prover/witness_generator/src/scheduler.rs @@ -1,31 +1,37 @@ -use std::convert::TryInto; -use std::time::Instant; +use std::{convert::TryInto, time::Instant}; use anyhow::Context as _; use async_trait::async_trait; -use zksync_prover_fri_types::circuit_definitions::boojum::field::goldilocks::{GoldilocksExt2, GoldilocksField}; -use zksync_prover_fri_types::circuit_definitions::boojum::gadgets::recursion::recursive_tree_hasher::CircuitGoldilocksPoseidon2Sponge; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::scheduler::SchedulerCircuit; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::{ - ZkSyncRecursionLayerStorageType, ZkSyncRecursionLayerVerificationKey, - ZkSyncRecursiveLayerCircuit, SCHEDULER_CAPACITY, -}; -use zksync_prover_fri_types::circuit_definitions::recursion_layer_proof_config; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::scheduler::input::SchedulerCircuitInstanceWitness; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::scheduler::SchedulerConfig; -use zksync_vk_setup_data_server_fri::get_recursive_layer_vk_for_circuit_type; -use zksync_vk_setup_data_server_fri::utils::get_leaf_vk_params; - -use crate::metrics::WITNESS_GENERATOR_METRICS; -use crate::utils::{load_proofs_for_job_ids, SchedulerPartialInputWrapper}; use zksync_config::configs::FriWitnessGeneratorConfig; use zksync_dal::ConnectionPool; use zksync_object_store::{FriCircuitKey, ObjectStore, ObjectStoreFactory}; -use zksync_prover_fri_types::{get_current_pod_name, CircuitWrapper, FriProofWrapper}; +use zksync_prover_fri_types::{ + circuit_definitions::{ + boojum::{ + field::goldilocks::{GoldilocksExt2, GoldilocksField}, + gadgets::recursion::recursive_tree_hasher::CircuitGoldilocksPoseidon2Sponge, + }, + circuit_definitions::recursion_layer::{ + scheduler::SchedulerCircuit, ZkSyncRecursionLayerStorageType, + ZkSyncRecursionLayerVerificationKey, ZkSyncRecursiveLayerCircuit, SCHEDULER_CAPACITY, + }, + recursion_layer_proof_config, + zkevm_circuits::scheduler::{input::SchedulerCircuitInstanceWitness, SchedulerConfig}, + }, + get_current_pod_name, CircuitWrapper, FriProofWrapper, +}; use zksync_queued_job_processor::JobProcessor; -use zksync_types::proofs::AggregationRound; -use zksync_types::protocol_version::FriProtocolVersionId; -use zksync_types::L1BatchNumber; +use zksync_types::{ + proofs::AggregationRound, protocol_version::FriProtocolVersionId, L1BatchNumber, +}; +use zksync_vk_setup_data_server_fri::{ + get_recursive_layer_vk_for_circuit_type, utils::get_leaf_vk_params, +}; + +use crate::{ + metrics::WITNESS_GENERATOR_METRICS, + utils::{load_proofs_for_job_ids, SchedulerPartialInputWrapper}, +}; pub struct SchedulerArtifacts { pub scheduler_circuit: ZkSyncRecursiveLayerCircuit, diff --git a/prover/witness_generator/src/storage_oracle.rs b/prover/witness_generator/src/storage_oracle.rs index a23a08aa6ee..6771a025213 100644 --- a/prover/witness_generator/src/storage_oracle.rs +++ b/prover/witness_generator/src/storage_oracle.rs @@ -1,7 +1,7 @@ -use zksync_types::zkevm_test_harness::zk_evm::abstractions::{ - RefundType, RefundedAmounts, Storage, +use zksync_types::{ + zkevm_test_harness::zk_evm::abstractions::{RefundType, RefundedAmounts, Storage}, + LogQuery, Timestamp, }; -use zksync_types::{LogQuery, Timestamp}; #[derive(Debug)] pub struct StorageOracle { diff --git a/prover/witness_generator/src/tests.rs b/prover/witness_generator/src/tests.rs index 27f5637c0b3..7fd95a7c7d8 100644 --- a/prover/witness_generator/src/tests.rs +++ b/prover/witness_generator/src/tests.rs @@ -1,11 +1,13 @@ -use const_decoder::Decoder::Hex; - use std::iter; -use super::precalculated_merkle_paths_provider::PrecalculatedMerklePathsProvider; +use const_decoder::Decoder::Hex; use zkevm_test_harness::witness::tree::{BinarySparseStorageTree, ZkSyncStorageLeaf}; -use zksync_types::proofs::{PrepareBasicCircuitsJob, StorageLogMetadata}; -use zksync_types::U256; +use zksync_types::{ + proofs::{PrepareBasicCircuitsJob, StorageLogMetadata}, + U256, +}; + +use super::precalculated_merkle_paths_provider::PrecalculatedMerklePathsProvider; // Sample `StorageLogMetadata` entries. Since we cannot allocate in constants, we store // the only Merkle path hash separately. diff --git a/prover/witness_generator/src/utils.rs b/prover/witness_generator/src/utils.rs index 0a70858977f..6efa333a819 100644 --- a/prover/witness_generator/src/utils.rs +++ b/prover/witness_generator/src/utils.rs @@ -1,26 +1,28 @@ -use zksync_prover_fri_types::circuit_definitions::boojum::field::goldilocks::GoldilocksExt2; -use zksync_prover_fri_types::circuit_definitions::boojum::gadgets::recursion::recursive_tree_hasher::CircuitGoldilocksPoseidon2Sponge; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::base_layer::{ - ZkSyncBaseLayerClosedFormInput, +use zkevm_test_harness::{ + boojum::field::goldilocks::GoldilocksField, witness::full_block_artifact::BlockBasicCircuits, }; -use zksync_prover_fri_types::circuit_definitions::circuit_definitions::recursion_layer::{ - ZkSyncRecursiveLayerCircuit, -}; - -use zksync_prover_fri_types::circuit_definitions::encodings::recursion_request::RecursionQueueSimulator; - -use zkevm_test_harness::boojum::field::goldilocks::GoldilocksField; -use zkevm_test_harness::witness::full_block_artifact::BlockBasicCircuits; use zksync_object_store::{ serialize_using_bincode, AggregationsKey, Bucket, ClosedFormInputKey, FriCircuitKey, ObjectStore, StoredObject, }; -use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::scheduler::input::SchedulerCircuitInstanceWitness; -use zksync_prover_fri_types::circuit_definitions::ZkSyncDefaultRoundFunction; -use zksync_prover_fri_types::{CircuitWrapper, FriProofWrapper}; +use zksync_prover_fri_types::{ + circuit_definitions::{ + boojum::{ + field::goldilocks::GoldilocksExt2, + gadgets::recursion::recursive_tree_hasher::CircuitGoldilocksPoseidon2Sponge, + }, + circuit_definitions::{ + base_layer::ZkSyncBaseLayerClosedFormInput, + recursion_layer::ZkSyncRecursiveLayerCircuit, + }, + encodings::recursion_request::RecursionQueueSimulator, + zkevm_circuits::scheduler::input::SchedulerCircuitInstanceWitness, + ZkSyncDefaultRoundFunction, + }, + CircuitWrapper, FriProofWrapper, +}; use zksync_system_constants::USED_BOOTLOADER_MEMORY_BYTES; -use zksync_types::proofs::AggregationRound; -use zksync_types::{L1BatchNumber, U256}; +use zksync_types::{proofs::AggregationRound, L1BatchNumber, U256}; pub fn expand_bootloader_contents(packed: &[(usize, U256)]) -> Vec { let mut result = vec![0u8; USED_BOOTLOADER_MEMORY_BYTES]; diff --git a/prover/witness_generator/tests/basic_test.rs b/prover/witness_generator/tests/basic_test.rs index 1c8d00ff35e..16cce19929d 100644 --- a/prover/witness_generator/tests/basic_test.rs +++ b/prover/witness_generator/tests/basic_test.rs @@ -4,20 +4,20 @@ use serde::Serialize; use zksync_config::ObjectStoreConfig; use zksync_env_config::FromEnv; use zksync_object_store::{AggregationsKey, FriCircuitKey, ObjectStoreFactory}; -use zksync_types::proofs::{ - AggregationRound, LeafAggregationJobMetadata, NodeAggregationJobMetadata, -}; -use zksync_types::L1BatchNumber; - use zksync_prover_fri_types::CircuitWrapper; use zksync_prover_fri_utils::get_recursive_layer_circuit_id_for_base_layer; -use zksync_witness_generator::leaf_aggregation::{ - prepare_leaf_aggregation_job, LeafAggregationWitnessGenerator, +use zksync_types::{ + proofs::{AggregationRound, LeafAggregationJobMetadata, NodeAggregationJobMetadata}, + L1BatchNumber, +}; +use zksync_witness_generator::{ + leaf_aggregation::{prepare_leaf_aggregation_job, LeafAggregationWitnessGenerator}, + node_aggregation, + node_aggregation::NodeAggregationWitnessGenerator, + scheduler, + scheduler::SchedulerWitnessGenerator, + utils::AggregationWrapper, }; -use zksync_witness_generator::node_aggregation::NodeAggregationWitnessGenerator; -use zksync_witness_generator::scheduler::SchedulerWitnessGenerator; -use zksync_witness_generator::utils::AggregationWrapper; -use zksync_witness_generator::{node_aggregation, scheduler}; fn compare_serialized(expected: &T, actual: &T) { let serialized_expected = bincode::serialize(expected).unwrap(); diff --git a/prover/witness_vector_generator/src/generator.rs b/prover/witness_vector_generator/src/generator.rs index ee17e0edaa7..74e25b38988 100644 --- a/prover/witness_vector_generator/src/generator.rs +++ b/prover/witness_vector_generator/src/generator.rs @@ -2,24 +2,27 @@ use std::time::{Duration, Instant}; use anyhow::Context as _; use async_trait::async_trait; -use tokio::task::JoinHandle; - -use crate::metrics::METRICS; -use tokio::time::sleep; +use tokio::{task::JoinHandle, time::sleep}; use zksync_config::configs::FriWitnessVectorGeneratorConfig; use zksync_dal::ConnectionPool; use zksync_object_store::ObjectStore; -use zksync_prover_fri_types::circuit_definitions::boojum::field::goldilocks::GoldilocksField; -use zksync_prover_fri_types::{CircuitWrapper, ProverJob, WitnessVectorArtifacts}; -use zksync_prover_fri_utils::fetch_next_circuit; -use zksync_prover_fri_utils::get_numeric_circuit_id; -use zksync_prover_fri_utils::socket_utils::send_assembly; +use zksync_prover_fri_types::{ + circuit_definitions::boojum::field::goldilocks::GoldilocksField, CircuitWrapper, ProverJob, + WitnessVectorArtifacts, +}; +use zksync_prover_fri_utils::{ + fetch_next_circuit, get_numeric_circuit_id, socket_utils::send_assembly, +}; use zksync_queued_job_processor::JobProcessor; -use zksync_types::basic_fri_types::CircuitIdRoundTuple; -use zksync_types::proofs::{GpuProverInstanceStatus, SocketAddress}; -use zksync_types::protocol_version::L1VerifierConfig; +use zksync_types::{ + basic_fri_types::CircuitIdRoundTuple, + proofs::{GpuProverInstanceStatus, SocketAddress}, + protocol_version::L1VerifierConfig, +}; use zksync_vk_setup_data_server_fri::get_finalization_hints; +use crate::metrics::METRICS; + pub struct WitnessVectorGenerator { blob_store: Box, pool: ConnectionPool, diff --git a/prover/witness_vector_generator/src/main.rs b/prover/witness_vector_generator/src/main.rs index 7c1aa8e0b89..1358680d3a1 100644 --- a/prover/witness_vector_generator/src/main.rs +++ b/prover/witness_vector_generator/src/main.rs @@ -3,12 +3,10 @@ use anyhow::Context as _; use prometheus_exporter::PrometheusExporterConfig; use structopt::StructOpt; -use tokio::{sync::oneshot, sync::watch}; - -use crate::generator::WitnessVectorGenerator; -use zksync_config::configs::fri_prover_group::FriProverGroupConfig; +use tokio::sync::{oneshot, watch}; use zksync_config::configs::{ - FriProverConfig, FriWitnessVectorGeneratorConfig, PostgresConfig, ProverGroupConfig, + fri_prover_group::FriProverGroupConfig, FriProverConfig, FriWitnessVectorGeneratorConfig, + PostgresConfig, ProverGroupConfig, }; use zksync_dal::ConnectionPool; use zksync_env_config::{object_store::ProverObjectStoreConfig, FromEnv}; @@ -19,6 +17,8 @@ use zksync_queued_job_processor::JobProcessor; use zksync_utils::wait_for_tasks::wait_for_tasks; use zksync_vk_setup_data_server_fri::commitment_utils::get_cached_commitments; +use crate::generator::WitnessVectorGenerator; + mod generator; mod metrics; diff --git a/prover/witness_vector_generator/src/metrics.rs b/prover/witness_vector_generator/src/metrics.rs index 4bc11ff401b..7c8284244b6 100644 --- a/prover/witness_vector_generator/src/metrics.rs +++ b/prover/witness_vector_generator/src/metrics.rs @@ -1,4 +1,5 @@ use std::time::Duration; + use vise::{Buckets, Histogram, LabeledFamily, Metrics}; #[derive(Debug, Metrics)] diff --git a/prover/witness_vector_generator/tests/basic_test.rs b/prover/witness_vector_generator/tests/basic_test.rs index 5ed0769d416..648b1ee4d9e 100644 --- a/prover/witness_vector_generator/tests/basic_test.rs +++ b/prover/witness_vector_generator/tests/basic_test.rs @@ -1,7 +1,7 @@ use std::fs; + use zksync_prover_fri_types::{CircuitWrapper, ProverJob, ProverServiceDataKey}; -use zksync_types::proofs::AggregationRound; -use zksync_types::L1BatchNumber; +use zksync_types::{proofs::AggregationRound, L1BatchNumber}; use zksync_witness_vector_generator::generator::WitnessVectorGenerator; #[test] diff --git a/sdk/zksync-rs/src/ethereum/mod.rs b/sdk/zksync-rs/src/ethereum/mod.rs index 3371c720149..ac91e358983 100644 --- a/sdk/zksync-rs/src/ethereum/mod.rs +++ b/sdk/zksync-rs/src/ethereum/mod.rs @@ -1,32 +1,34 @@ //! Utilities for the on-chain operations, such as `Deposit` and `FullExit`. -use core::{convert::TryFrom, time::Duration}; +use std::{ + convert::TryFrom, + time::{Duration, Instant}, +}; + use serde_json::{Map, Value}; -use std::time::Instant; +use zksync_eth_client::{ + clients::http::SigningClient, types::Error, BoundEthInterface, EthInterface, +}; +use zksync_eth_signer::EthereumSigner; use zksync_types::{ api::BridgeAddresses, + l1::L1Tx, + network::Network, web3::{ contract::{tokens::Tokenize, Options}, ethabi, transports::Http, types::{TransactionReceipt, H160, H256, U256}, }, - L1ChainId, REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE, + Address, L1ChainId, L1TxCommonData, REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE, }; use zksync_web3_decl::namespaces::{EthNamespaceClient, ZksNamespaceClient}; -use zksync_eth_client::{ - clients::http::SigningClient, types::Error, BoundEthInterface, EthInterface, -}; -use zksync_eth_signer::EthereumSigner; -use zksync_types::network::Network; -use zksync_types::{l1::L1Tx, Address, L1TxCommonData}; - -use crate::web3::ethabi::Bytes; use crate::{ error::ClientError, operations::SyncTransactionHandle, utils::{is_token_eth, load_contract}, + web3::ethabi::Bytes, }; const IERC20_INTERFACE: &str = include_str!("../abi/IERC20.json"); diff --git a/sdk/zksync-rs/src/lib.rs b/sdk/zksync-rs/src/lib.rs index 4ee03e8ff9d..aa4a158ef06 100644 --- a/sdk/zksync-rs/src/lib.rs +++ b/sdk/zksync-rs/src/lib.rs @@ -1,18 +1,15 @@ +pub use zksync_types::{self, network::Network, web3}; +pub use zksync_web3_decl::{ + jsonrpsee::http_client::*, + namespaces::{EthNamespaceClient, NetNamespaceClient, Web3NamespaceClient, ZksNamespaceClient}, + types, +}; + +pub use crate::{ethereum::EthereumProvider, wallet::Wallet}; + pub mod error; pub mod ethereum; pub mod operations; pub mod signer; pub mod utils; pub mod wallet; - -pub use crate::{ethereum::EthereumProvider, wallet::Wallet}; -pub use zksync_types::network::Network; - -pub use zksync_types; -pub use zksync_types::web3; - -pub use zksync_web3_decl::{ - jsonrpsee::http_client::*, - namespaces::{EthNamespaceClient, NetNamespaceClient, Web3NamespaceClient, ZksNamespaceClient}, - types, -}; diff --git a/sdk/zksync-rs/src/operations/mod.rs b/sdk/zksync-rs/src/operations/mod.rs index a59bd57a2dd..36a0d2b29b8 100644 --- a/sdk/zksync-rs/src/operations/mod.rs +++ b/sdk/zksync-rs/src/operations/mod.rs @@ -2,10 +2,9 @@ use std::time::{Duration, Instant}; -use crate::{error::ClientError, EthNamespaceClient}; -use zksync_types::l2::L2Tx; use zksync_types::{ api::{BlockNumber, TransactionReceipt}, + l2::L2Tx, Bytes, L2ChainId, H256, }; @@ -15,6 +14,7 @@ pub use self::{ transfer::{create_transfer_calldata, TransferBuilder}, withdraw::WithdrawBuilder, }; +use crate::{error::ClientError, EthNamespaceClient}; mod deploy_contract; mod execute_contract; diff --git a/sdk/zksync-rs/src/operations/transfer.rs b/sdk/zksync-rs/src/operations/transfer.rs index 85d90c61fd2..f0f7525e8f6 100644 --- a/sdk/zksync-rs/src/operations/transfer.rs +++ b/sdk/zksync-rs/src/operations/transfer.rs @@ -1,13 +1,14 @@ use zksync_eth_signer::EthereumSigner; -use zksync_types::L2_ETH_TOKEN_ADDRESS; -use zksync_types::{fee::Fee, l2::L2Tx, Address, Nonce, U256}; +use zksync_types::{fee::Fee, l2::L2Tx, Address, Nonce, L2_ETH_TOKEN_ADDRESS, U256}; -use crate::ethereum::ierc20_contract; -use crate::web3::contract::tokens::Tokenize; -use crate::zksync_types::{transaction_request::PaymasterParams, Execute, L2TxCommonData}; use crate::{ - error::ClientError, operations::SyncTransactionHandle, wallet::Wallet, EthNamespaceClient, - ZksNamespaceClient, + error::ClientError, + ethereum::ierc20_contract, + operations::SyncTransactionHandle, + wallet::Wallet, + web3::contract::tokens::Tokenize, + zksync_types::{transaction_request::PaymasterParams, Execute, L2TxCommonData}, + EthNamespaceClient, ZksNamespaceClient, }; pub struct TransferBuilder<'a, S: EthereumSigner, P> { diff --git a/sdk/zksync-rs/src/operations/withdraw.rs b/sdk/zksync-rs/src/operations/withdraw.rs index 0037deacd63..a580a0c35e0 100644 --- a/sdk/zksync-rs/src/operations/withdraw.rs +++ b/sdk/zksync-rs/src/operations/withdraw.rs @@ -1,9 +1,7 @@ use zksync_eth_signer::EthereumSigner; - -use zksync_types::l2::L2Tx; use zksync_types::{ - fee::Fee, tokens::ETHEREUM_ADDRESS, transaction_request::PaymasterParams, web3::ethabi, - Address, Nonce, L2_ETH_TOKEN_ADDRESS, U256, + fee::Fee, l2::L2Tx, tokens::ETHEREUM_ADDRESS, transaction_request::PaymasterParams, + web3::ethabi, Address, Nonce, L2_ETH_TOKEN_ADDRESS, U256, }; use crate::{ diff --git a/sdk/zksync-rs/src/signer.rs b/sdk/zksync-rs/src/signer.rs index 0c92a354ce5..445c5172ff6 100644 --- a/sdk/zksync-rs/src/signer.rs +++ b/sdk/zksync-rs/src/signer.rs @@ -1,15 +1,12 @@ -// Built-in imports use std::fmt::Debug; -// Workspace uses + use zksync_eth_signer::{error::SignerError, EthereumSigner}; -use zksync_types::L2_ETH_TOKEN_ADDRESS; use zksync_types::{ fee::Fee, l2::L2Tx, transaction_request::PaymasterParams, Address, Eip712Domain, L2ChainId, - Nonce, PackedEthSignature, U256, + Nonce, PackedEthSignature, L2_ETH_TOKEN_ADDRESS, U256, }; -// Local imports -use crate::operations::create_transfer_calldata; -use crate::types::TransactionRequest; + +use crate::{operations::create_transfer_calldata, types::TransactionRequest}; fn signing_failed_error(err: impl ToString) -> SignerError { SignerError::SigningFailed(err.to_string()) diff --git a/sdk/zksync-rs/src/utils.rs b/sdk/zksync-rs/src/utils.rs index c97fe42d47e..5137dbca6db 100644 --- a/sdk/zksync-rs/src/utils.rs +++ b/sdk/zksync-rs/src/utils.rs @@ -1,7 +1,6 @@ use std::str::FromStr; use num::BigUint; - use zksync_types::{transaction_request::PaymasterParams, Address, U256}; use crate::web3::ethabi::{Contract, Token}; diff --git a/sdk/zksync-rs/src/wallet.rs b/sdk/zksync-rs/src/wallet.rs index 7d665b4f42e..dd2cdf14208 100644 --- a/sdk/zksync-rs/src/wallet.rs +++ b/sdk/zksync-rs/src/wallet.rs @@ -1,23 +1,22 @@ use zksync_eth_signer::EthereumSigner; -use zksync_types::transaction_request::CallRequest; use zksync_types::{ api::{BlockIdVariant, BlockNumber, TransactionRequest}, l2::L2Tx, tokens::ETHEREUM_ADDRESS, + transaction_request::CallRequest, Address, Bytes, Eip712Domain, U256, }; - use zksync_web3_decl::{ jsonrpsee::http_client::{HttpClient, HttpClientBuilder}, namespaces::{EthNamespaceClient, NetNamespaceClient, Web3NamespaceClient, ZksNamespaceClient}, }; -use crate::web3::contract::tokens::Tokenizable; use crate::{ error::ClientError, ethereum::{ierc20_contract, EthereumProvider}, operations::*, signer::Signer, + web3::contract::tokens::Tokenizable, }; #[derive(Debug)]