diff --git a/.github/scripts/gateway.sh b/.github/scripts/gateway.sh deleted file mode 100755 index ed9e8a32dc8..00000000000 --- a/.github/scripts/gateway.sh +++ /dev/null @@ -1,50 +0,0 @@ -sudo rm -rf ./volumes && zk_supervisor clean containers && zk_inception up -o false - -zk_inception ecosystem init --deploy-paymaster --deploy-erc20 \ - --deploy-ecosystem --l1-rpc-url=http://localhost:8545 \ - --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ - --server-db-name=zksync_server_localhost_era \ - --prover-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ - --prover-db-name=zksync_prover_localhost_era \ - --ignore-prerequisites --observability=false --skip-submodules-checkout \ - --chain era \ - # --skip-contract-compilation-override \ - -zk_inception chain create \ - --chain-name gateway \ - --chain-id 505 \ - --prover-mode no-proofs \ - --wallet-creation localhost \ - --l1-batch-commit-data-generator-mode rollup \ - --base-token-address 0x0000000000000000000000000000000000000001 \ - --base-token-price-nominator 1 \ - --base-token-price-denominator 1 \ - --set-as-default false \ - --ignore-prerequisites --skip-submodules-checkout --skip-contract-compilation-override - -zk_inception chain init \ - --deploy-paymaster \ - --l1-rpc-url=http://localhost:8545 \ - --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ - --server-db-name=zksync_server_localhost_gateway \ - --prover-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ - --prover-db-name=zksync_prover_localhost_gateway \ - --chain gateway --skip-submodules-checkout - -zk_inception chain convert-to-gateway --chain gateway --ignore-prerequisites - -zk_inception server --ignore-prerequisites --chain gateway &> ./gateway.log & - -sleep 20 - -zk_inception chain migrate-to-gateway --chain era --gateway-chain-name gateway - -zk_inception chain migrate-from-gateway --chain era --gateway-chain-name gateway - -zk_inception chain migrate-to-gateway --chain era --gateway-chain-name gateway - -zk_inception server --ignore-prerequisites --chain era &> ./rollup.log & - -sleep 20 - -zk_supervisor test integration --no-deps --ignore-prerequisites --chain era diff --git a/bin/last_chain_id b/bin/last_chain_id deleted file mode 100644 index 900731ffd51..00000000000 --- a/bin/last_chain_id +++ /dev/null @@ -1 +0,0 @@ -64 diff --git a/bin/start_sync_layer_gateway.sh b/bin/start_sync_layer_gateway.sh deleted file mode 100755 index 0815c9affa3..00000000000 --- a/bin/start_sync_layer_gateway.sh +++ /dev/null @@ -1,22 +0,0 @@ -set -euox pipefail - -zk -zk env dev -zk config compile -zk down -rm -rf "$ZKSYNC_HOME"db/* -rm -f gateway_server.log -mkdir -p "$ZKSYNC_HOME"volumes/postgres -mkdir -p "$ZKSYNC_HOME"volumes/reth/data -zk init -- --should-check-postgres false --skip-submodules-checkout - -zk server &>gateway_server.log & -sleep 5 - -#Prepare the server to be the synclayer -zk dev2 supply-rich-wallets -zk contract build --zkSync -zk contract prepare-sync-layer -zk contract register-sync-layer-counterpart - -sleep 360000; diff --git a/bin/start_sync_layer_l3_chain.sh b/bin/start_sync_layer_l3_chain.sh deleted file mode 100755 index 87b07817848..00000000000 --- a/bin/start_sync_layer_l3_chain.sh +++ /dev/null @@ -1,30 +0,0 @@ -set -euox pipefail - - -CHAIN_ID=$( last_chain_id - -DIFF=$((CHAIN_ID * 100)) -CHAIN_ID=$((CHAIN_ID + 1000)) - -rm -f l3_server_pre_gateway.log - -#Prepare launch sync-layer based chain -zk env dev -zk config prepare-l1-hyperchain --env-name test-chain --chain-id $CHAIN_ID -zk env test-chain -zk config compile test-chain --diff $DIFF -zk init hyper -- --skip-contract-compilation -zk server --time-to-live 40 &>l3_server_pre_gateway.log -sleep 40 - -export ETH_SENDER_SENDER_TX_AGGREGATION_PAUSED=true -zk server --time-to-live 20 - -zk contract migrate-to-sync-layer -zk contract prepare-sync-layer-validators -zk contract update-config-for-sync-layer - -export ETH_SENDER_SENDER_TX_AGGREGATION_PAUSED=false -zk server diff --git a/core/lib/basic_types/src/vm_version.rs b/core/lib/basic_types/src/vm_version.rs deleted file mode 100644 index 47034ebd8a7..00000000000 --- a/core/lib/basic_types/src/vm_version.rs +++ /dev/null @@ -1,23 +0,0 @@ -#[derive(Debug, Clone, Copy)] -pub enum VmVersion { - M5WithoutRefunds, - M5WithRefunds, - M6Initial, - M6BugWithCompressionFixed, - Vm1_3_2, - VmVirtualBlocks, - VmVirtualBlocksRefundsEnhancement, - VmBoojumIntegration, - Vm1_4_1, - Vm1_4_2, - Vm1_5_0SmallBootloaderMemory, - Vm1_5_0IncreasedBootloaderMemory, - VmSyncLayer, -} - -impl VmVersion { - /// Returns the latest supported VM version. - pub const fn latest() -> VmVersion { - Self::VmSyncLayer - } -} diff --git a/core/lib/multivm/src/versions/shadow/tests.rs b/core/lib/multivm/src/versions/shadow/tests.rs index 78fd29809a9..0909c53923b 100644 --- a/core/lib/multivm/src/versions/shadow/tests.rs +++ b/core/lib/multivm/src/versions/shadow/tests.rs @@ -3,7 +3,7 @@ use std::{collections::HashSet, rc::Rc}; use zksync_types::{writes::StateDiffRecord, StorageKey, Transaction, H256, U256}; -use zksync_vm_interface::pubdata::PubdataBuilder; +use zksync_vm_interface::pubdata::{PubdataBuilder, PubdataInput}; use super::ShadowedFastVm; use crate::{ @@ -120,11 +120,30 @@ impl TestedVm for ShadowedFastVm { }); } - fn push_transaction_with_refund(&mut self, tx: Transaction, refund: u64) { - self.get_mut("push_transaction_with_refund", |r| match r { - ShadowMut::Main(vm) => vm.push_transaction_with_refund(tx.clone(), refund), - ShadowMut::Shadow(vm) => vm.push_transaction_with_refund(tx.clone(), refund), - }); + fn push_transaction_with_refund_and_compression( + &mut self, + tx: Transaction, + refund: u64, + compression: bool, + ) { + self.get_mut( + "push_transaction_with_refund_and_compression", + |r| match r { + ShadowMut::Main(vm) => { + vm.push_transaction_with_refund_and_compression(tx.clone(), refund, compression) + } + ShadowMut::Shadow(vm) => { + vm.push_transaction_with_refund_and_compression(tx.clone(), refund, compression) + } + }, + ); + } + + fn pubdata_input(&self) -> PubdataInput { + self.get("pubdata_input", |r| match r { + ShadowRef::Main(vm) => vm.pubdata_input(), + ShadowRef::Shadow(vm) => vm.pubdata_input(), + }) } } @@ -234,6 +253,15 @@ impl TestedVm for ShadowedFastVm { // } // } // +// mod l1_messenger { +// use crate::versions::testonly::l1_messenger::*; +// +// #[test] +// fn rollup_da_output_hash_match() { +// test_rollup_da_output_hash_match::(); +// } +// } +// // mod l1_tx_execution { // use crate::versions::testonly::l1_tx_execution::*; // diff --git a/core/lib/multivm/src/versions/testonly/l1_messenger.rs b/core/lib/multivm/src/versions/testonly/l1_messenger.rs new file mode 100644 index 00000000000..5f72560d9fd --- /dev/null +++ b/core/lib/multivm/src/versions/testonly/l1_messenger.rs @@ -0,0 +1,166 @@ +// TODO: move to shared tests + +use std::rc::Rc; + +use ethabi::Token; +use zksync_contracts::{l1_messenger_contract, l2_rollup_da_validator_bytecode}; +use zksync_test_account::TxType; +use zksync_types::{ + web3::keccak256, Address, Execute, ProtocolVersionId, L1_MESSENGER_ADDRESS, U256, +}; +use zksync_utils::{address_to_h256, u256_to_h256}; + +use super::{read_test_contract, ContractToDeploy, TestedVm, VmTesterBuilder}; +use crate::{ + interface::{ + pubdata::{PubdataBuilder, PubdataInput}, + InspectExecutionMode, TxExecutionMode, VmInterfaceExt, + }, + pubdata_builders::RollupPubdataBuilder, + vm_latest::constants::ZK_SYNC_BYTES_PER_BLOB, +}; + +const L2_DA_VALIDATOR_OUTPUT_HASH_KEY: usize = 5; +const USED_L2_DA_VALIDATOR_ADDRESS_KEY: usize = 6; + +fn encoded_uncompressed_state_diffs(input: &PubdataInput) -> Vec { + let mut result = vec![]; + for state_diff in input.state_diffs.iter() { + result.extend(state_diff.encode_padded()); + } + result +} + +fn compose_header_for_l1_commit_rollup(input: PubdataInput) -> Vec { + // The preimage under the hash `l2DAValidatorOutputHash` is expected to be in the following format: + // - First 32 bytes are the hash of the uncompressed state diff. + // - Then, there is a 32-byte hash of the full pubdata. + // - Then, there is the 1-byte number of blobs published. + // - Then, there are linear hashes of the published blobs, 32 bytes each. + + let mut full_header = vec![]; + + let uncompressed_state_diffs = encoded_uncompressed_state_diffs(&input); + let uncompressed_state_diffs_hash = keccak256(&uncompressed_state_diffs); + full_header.extend(uncompressed_state_diffs_hash); + + let pubdata_builder = RollupPubdataBuilder::new(Address::zero()); + let mut full_pubdata = + pubdata_builder.settlement_layer_pubdata(&input, ProtocolVersionId::latest()); + let full_pubdata_hash = keccak256(&full_pubdata); + full_header.extend(full_pubdata_hash); + + // Now, we need to calculate the linear hashes of the blobs. + // Firstly, let's pad the pubdata to the size of the blob. + if full_pubdata.len() % ZK_SYNC_BYTES_PER_BLOB != 0 { + let padding = + vec![0u8; ZK_SYNC_BYTES_PER_BLOB - full_pubdata.len() % ZK_SYNC_BYTES_PER_BLOB]; + full_pubdata.extend(padding); + } + full_header.push((full_pubdata.len() / ZK_SYNC_BYTES_PER_BLOB) as u8); + + full_pubdata + .chunks(ZK_SYNC_BYTES_PER_BLOB) + .for_each(|chunk| { + full_header.extend(keccak256(chunk)); + }); + + full_header +} + +pub(crate) fn test_rollup_da_output_hash_match() { + // In this test, we check whether the L2 DA output hash is as expected. + + let l2_da_validator_address = Address::repeat_byte(0x12); + let mut vm = VmTesterBuilder::new() + .with_empty_in_memory_storage() + .with_execution_mode(TxExecutionMode::VerifyExecute) + .with_rich_accounts(1) + .with_custom_contracts(vec![ContractToDeploy { + bytecode: l2_rollup_da_validator_bytecode(), + address: l2_da_validator_address, + is_account: false, + is_funded: false, + }]) + .build::(); + + let account = &mut vm.rich_accounts[0]; + + // Firstly, deploy tx. It should publish the bytecode of the "test contract" + let counter = read_test_contract(); + + let tx = account.get_deploy_tx(&counter, None, TxType::L2).tx; + // We do not use compression here, to have the bytecode published in full. + vm.vm + .push_transaction_with_refund_and_compression(tx, 0, false); + let result = vm.vm.execute(InspectExecutionMode::OneTx); + assert!(!result.result.is_failed(), "Transaction wasn't successful"); + + // Then, we call the l1 messenger to also send an L2->L1 message. + let l1_messenger_contract = l1_messenger_contract(); + let encoded_data = l1_messenger_contract + .function("sendToL1") + .unwrap() + .encode_input(&[Token::Bytes(vec![])]) + .unwrap(); + + let tx = account.get_l2_tx_for_execute( + Execute { + contract_address: Some(L1_MESSENGER_ADDRESS), + calldata: encoded_data, + value: U256::zero(), + factory_deps: vec![], + }, + None, + ); + vm.vm.push_transaction(tx); + let result = vm.vm.execute(InspectExecutionMode::OneTx); + assert!(!result.result.is_failed(), "Transaction wasn't successful"); + + let pubdata_builder = RollupPubdataBuilder::new(l2_da_validator_address); + let batch_result = vm.vm.finish_batch(Rc::new(pubdata_builder)); + assert!( + !batch_result.block_tip_execution_result.result.is_failed(), + "Transaction wasn't successful {:?}", + batch_result.block_tip_execution_result.result + ); + let pubdata_input = vm.vm.pubdata_input(); + + // Just to double check that the test makes sense. + assert!(!pubdata_input.user_logs.is_empty()); + assert!(!pubdata_input.l2_to_l1_messages.is_empty()); + assert!(!pubdata_input.published_bytecodes.is_empty()); + assert!(!pubdata_input.state_diffs.is_empty()); + + let expected_header: Vec = compose_header_for_l1_commit_rollup(pubdata_input); + + let l2_da_validator_output_hash = batch_result + .block_tip_execution_result + .logs + .system_l2_to_l1_logs + .iter() + .find(|log| log.0.key == u256_to_h256(L2_DA_VALIDATOR_OUTPUT_HASH_KEY.into())) + .unwrap() + .0 + .value; + + assert_eq!( + l2_da_validator_output_hash, + keccak256(&expected_header).into() + ); + + let l2_used_da_validator_address = batch_result + .block_tip_execution_result + .logs + .system_l2_to_l1_logs + .iter() + .find(|log| log.0.key == u256_to_h256(USED_L2_DA_VALIDATOR_ADDRESS_KEY.into())) + .unwrap() + .0 + .value; + + assert_eq!( + l2_used_da_validator_address, + address_to_h256(&l2_da_validator_address) + ); +} diff --git a/core/lib/multivm/src/versions/testonly/mod.rs b/core/lib/multivm/src/versions/testonly/mod.rs index eece1d475bb..faa05168172 100644 --- a/core/lib/multivm/src/versions/testonly/mod.rs +++ b/core/lib/multivm/src/versions/testonly/mod.rs @@ -42,6 +42,7 @@ pub(super) mod default_aa; pub(super) mod gas_limit; pub(super) mod get_used_contracts; pub(super) mod is_write_initial; +pub(super) mod l1_messenger; pub(super) mod l1_tx_execution; pub(super) mod l2_blocks; pub(super) mod nonce_holder; diff --git a/core/lib/multivm/src/versions/testonly/refunds.rs b/core/lib/multivm/src/versions/testonly/refunds.rs index edab843be4f..cd779f49bf0 100644 --- a/core/lib/multivm/src/versions/testonly/refunds.rs +++ b/core/lib/multivm/src/versions/testonly/refunds.rs @@ -56,8 +56,11 @@ pub(crate) fn test_predetermined_refunded_gas() { .build::(); assert_eq!(account.address(), vm.rich_accounts[0].address()); - vm.vm - .push_transaction_with_refund(tx.clone(), result.refunds.gas_refunded); + vm.vm.push_transaction_with_refund_and_compression( + tx.clone(), + result.refunds.gas_refunded, + true, + ); let result_with_predefined_refunds = vm .vm @@ -112,7 +115,7 @@ pub(crate) fn test_predetermined_refunded_gas() { let changed_operator_suggested_refund = result.refunds.gas_refunded + 1000; vm.vm - .push_transaction_with_refund(tx, changed_operator_suggested_refund); + .push_transaction_with_refund_and_compression(tx, changed_operator_suggested_refund, true); let result = vm .vm .finish_batch(default_pubdata_builder()) diff --git a/core/lib/multivm/src/versions/testonly/tester/mod.rs b/core/lib/multivm/src/versions/testonly/tester/mod.rs index 716b9386235..c45d0a6b470 100644 --- a/core/lib/multivm/src/versions/testonly/tester/mod.rs +++ b/core/lib/multivm/src/versions/testonly/tester/mod.rs @@ -8,7 +8,8 @@ use zksync_types::{ Address, L1BatchNumber, StorageKey, Transaction, H256, U256, }; use zksync_vm_interface::{ - pubdata::PubdataBuilder, CurrentExecutionState, InspectExecutionMode, VmExecutionResultAndLogs, + pubdata::{PubdataBuilder, PubdataInput}, + CurrentExecutionState, InspectExecutionMode, VmExecutionResultAndLogs, VmInterfaceHistoryEnabled, }; @@ -226,6 +227,14 @@ pub(crate) trait TestedVm: /// Same as `start_new_l2_block`, but should skip consistency checks (to verify they are performed by the bootloader). fn push_l2_block_unchecked(&mut self, block: L2BlockEnv); - /// Pushes a transaction with predefined refund value. - fn push_transaction_with_refund(&mut self, tx: Transaction, refund: u64); + /// Pushes a transaction with predefined refund value and compression. + fn push_transaction_with_refund_and_compression( + &mut self, + tx: Transaction, + refund: u64, + compression: bool, + ); + + /// Returns pubdata input. + fn pubdata_input(&self) -> PubdataInput; } diff --git a/core/lib/multivm/src/versions/vm_fast/tests/l1_messenger.rs b/core/lib/multivm/src/versions/vm_fast/tests/l1_messenger.rs new file mode 100644 index 00000000000..0bd01c7de13 --- /dev/null +++ b/core/lib/multivm/src/versions/vm_fast/tests/l1_messenger.rs @@ -0,0 +1,6 @@ +use crate::{versions::testonly::l1_messenger::test_rollup_da_output_hash_match, vm_fast::Vm}; + +#[test] +fn rollup_da_output_hash_match() { + test_rollup_da_output_hash_match::>(); +} diff --git a/core/lib/multivm/src/versions/vm_fast/tests/mod.rs b/core/lib/multivm/src/versions/vm_fast/tests/mod.rs index b29ca6ed7f8..4ed1f35d3fb 100644 --- a/core/lib/multivm/src/versions/vm_fast/tests/mod.rs +++ b/core/lib/multivm/src/versions/vm_fast/tests/mod.rs @@ -4,8 +4,9 @@ use zksync_types::{writes::StateDiffRecord, StorageKey, Transaction, H160, H256, use zksync_utils::h256_to_u256; use zksync_vm2::interface::{Event, HeapId, StateInterface}; use zksync_vm_interface::{ - pubdata::PubdataBuilder, storage::ReadStorage, CurrentExecutionState, L2BlockEnv, - VmExecutionMode, VmExecutionResultAndLogs, VmInterface, + pubdata::{PubdataBuilder, PubdataInput}, + storage::ReadStorage, + CurrentExecutionState, L2BlockEnv, VmExecutionMode, VmExecutionResultAndLogs, VmInterface, }; use super::Vm; @@ -24,6 +25,7 @@ use crate::{ // mod gas_limit; // mod get_used_contracts; // mod is_write_initial; +// mod l1_messenger; // mod l1_tx_execution; // mod l2_blocks; // mod nonce_holder; @@ -158,7 +160,16 @@ impl TestedVm for Vm> { self.bootloader_state.push_l2_block(block); } - fn push_transaction_with_refund(&mut self, tx: Transaction, refund: u64) { - self.push_transaction_inner(tx, refund, true); + fn push_transaction_with_refund_and_compression( + &mut self, + tx: Transaction, + refund: u64, + compression: bool, + ) { + self.push_transaction_inner(tx, refund, compression); + } + + fn pubdata_input(&self) -> PubdataInput { + todo!() } } diff --git a/core/lib/multivm/src/versions/vm_latest/tests/l1_messenger.rs b/core/lib/multivm/src/versions/vm_latest/tests/l1_messenger.rs index fcb718c7349..f1dade9dd8e 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/l1_messenger.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/l1_messenger.rs @@ -1,156 +1,9 @@ -// // TODO: move to shared tests -// -// use ethabi::Token; -// use zksync_contracts::l1_messenger_contract; -// use zksync_types::{web3::keccak256, Execute, L1_MESSENGER_ADDRESS, U256}; -// use zksync_utils::{address_to_h256, u256_to_h256}; -// -// use crate::{ -// interface::{TxExecutionMode, VmExecutionMode, VmInterface, VmInterfaceExt, pubdata::{PubdataInput, PubdataBuilder}}, -// vm_latest::{ -// constants::ZK_SYNC_BYTES_PER_BLOB, -// tests::{ -// tester::{DeployContractsTx, TxType, VmTesterBuilder}, -// utils::read_test_contract, -// }, -// HistoryEnabled, -// }, -// pubdata_builders::RollupPubdataBuilder -// }; -// -// pub(crate) const L2_DA_VALIDATOR_OUTPUT_HASH_KEY: usize = 5; -// pub(crate) const USED_L2_DA_VALIDATOR_ADDRESS_KEY: usize = 6; -// -// pub(crate) fn encoded_uncompressed_state_diffs(input: &PubdataInput) -> Vec { -// let mut result = vec![]; -// for state_diff in input.state_diffs.iter() { -// result.extend(state_diff.encode_padded()); -// } -// result -// } -// -// pub fn compose_header_for_l1_commit_rollup(input: PubdataInput) -> Vec { -// // The preimage under the hash `l2DAValidatorOutputHash` is expected to be in the following format: -// // - First 32 bytes are the hash of the uncompressed state diff. -// // - Then, there is a 32-byte hash of the full pubdata. -// // - Then, there is the 1-byte number of blobs published. -// // - Then, there are linear hashes of the published blobs, 32 bytes each. -// -// let mut full_header = vec![]; -// -// let uncompressed_state_diffs = encoded_uncompressed_state_diffs(&input); -// let uncompressed_state_diffs_hash = keccak256(&uncompressed_state_diffs); -// full_header.extend(uncompressed_state_diffs_hash); -// -// let mut full_pubdata = RollupPubdataBuilder::new().build_pubdata(input, false); -// let full_pubdata_hash = keccak256(&full_pubdata); -// full_header.extend(full_pubdata_hash); -// -// // Now, we need to calculate the linear hashes of the blobs. -// // Firstly, let's pad the pubdata to the size of the blob. -// if full_pubdata.len() % ZK_SYNC_BYTES_PER_BLOB != 0 { -// let padding = -// vec![0u8; ZK_SYNC_BYTES_PER_BLOB - full_pubdata.len() % ZK_SYNC_BYTES_PER_BLOB]; -// full_pubdata.extend(padding); -// } -// full_header.push((full_pubdata.len() / ZK_SYNC_BYTES_PER_BLOB) as u8); -// -// full_pubdata -// .chunks(ZK_SYNC_BYTES_PER_BLOB) -// .for_each(|chunk| { -// full_header.extend(keccak256(chunk)); -// }); -// -// full_header -// } -// -// #[test] -// fn test_publish_and_clear_state() { -// // In this test, we check whether the L2 DA output hash is as expected. -// // We will publish 320kb worth of pubdata. -// // It should produce 3 blobs. -// -// let mut vm = VmTesterBuilder::new(HistoryEnabled) -// .with_empty_in_memory_storage() -// .with_execution_mode(TxExecutionMode::VerifyExecute) -// .with_random_rich_accounts(1) -// .build(); -// -// let account = &mut vm.rich_accounts[0]; -// -// // Firstly, deploy tx. It should publish the bytecode of the "test contract" -// let counter = read_test_contract(); -// -// let DeployContractsTx { tx, .. } = account.get_deploy_tx(&counter, None, TxType::L2); -// // We do not use compression here, to have the bytecode published in full. -// vm.vm.push_transaction_with_compression(tx, false); -// let result = vm.vm.execute(VmExecutionMode::OneTx); -// assert!(!result.result.is_failed(), "Transaction wasn't successful"); -// -// // Then, we call the l1 messenger to also send an L2->L1 message. -// let l1_messenger_contract = l1_messenger_contract(); -// let encoded_data = l1_messenger_contract -// .function("sendToL1") -// .unwrap() -// .encode_input(&[Token::Bytes(vec![])]) -// .unwrap(); -// -// let tx = account.get_l2_tx_for_execute( -// Execute { -// contract_address: Some(L1_MESSENGER_ADDRESS), -// calldata: encoded_data, -// value: U256::zero(), -// factory_deps: vec![], -// }, -// None, -// ); -// vm.vm.push_transaction(tx); -// let result = vm.vm.execute(VmExecutionMode::OneTx); -// assert!(!result.result.is_failed(), "Transaction wasn't successful"); -// -// let batch_result = vm.vm.execute(VmExecutionMode::Batch); -// if batch_result.result.is_failed() { -// panic!("Batch execution failed: {:?}", batch_result.result); -// } -// assert!( -// !batch_result.result.is_failed(), -// "Transaction wasn't successful" -// ); -// let pubdata_input = vm.vm.bootloader_state.get_pubdata_information().clone(); -// -// // Just to double check that the test makes sense. -// assert!(!pubdata_input.user_logs.is_empty()); -// assert!(!pubdata_input.l2_to_l1_messages.is_empty()); -// assert!(!pubdata_input.published_bytecodes.is_empty()); -// assert!(!pubdata_input.state_diffs.is_empty()); -// -// let expected_header: Vec = compose_header_for_l1_commit_rollup(pubdata_input); -// -// let l2_da_validator_output_hash = batch_result -// .logs -// .system_l2_to_l1_logs -// .iter() -// .find(|log| log.0.key == u256_to_h256(L2_DA_VALIDATOR_OUTPUT_HASH_KEY.into())) -// .unwrap() -// .0 -// .value; -// -// assert_eq!( -// l2_da_validator_output_hash, -// keccak256(&expected_header).into() -// ); -// -// let l2_used_da_validator_address = batch_result -// .logs -// .system_l2_to_l1_logs -// .iter() -// .find(|log| log.0.key == u256_to_h256(USED_L2_DA_VALIDATOR_ADDRESS_KEY.into())) -// .unwrap() -// .0 -// .value; -// -// assert_eq!( -// l2_used_da_validator_address, -// address_to_h256(&vm.vm.system_env.pubdata_params.l2_da_validator_address) -// ); -// } +use crate::{ + versions::testonly::l1_messenger::test_rollup_da_output_hash_match, + vm_latest::{HistoryEnabled, Vm}, +}; + +#[test] +fn rollup_da_output_hash_match() { + test_rollup_da_output_hash_match::>(); +} diff --git a/core/lib/multivm/src/versions/vm_latest/tests/mod.rs b/core/lib/multivm/src/versions/vm_latest/tests/mod.rs index 9d75aba9208..3303b709af5 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/mod.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/mod.rs @@ -10,7 +10,7 @@ use zk_evm_1_5_0::{ }; use zksync_types::{writes::StateDiffRecord, StorageKey, StorageValue, Transaction, H256, U256}; use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256}; -use zksync_vm_interface::pubdata::PubdataBuilder; +use zksync_vm_interface::pubdata::{PubdataBuilder, PubdataInput}; use super::{HistoryEnabled, Vm}; use crate::{ @@ -181,10 +181,19 @@ impl TestedVm for TestedLatestVm { self.bootloader_state.push_l2_block(block); } - fn push_transaction_with_refund(&mut self, tx: Transaction, refund: u64) { + fn push_transaction_with_refund_and_compression( + &mut self, + tx: Transaction, + refund: u64, + compression: bool, + ) { let tx = TransactionData::new(tx, false); let overhead = tx.overhead_gas(); - self.push_raw_transaction(tx, overhead, refund, true) + self.push_raw_transaction(tx, overhead, refund, compression) + } + + fn pubdata_input(&self) -> PubdataInput { + self.bootloader_state.get_pubdata_information().clone() } } diff --git a/core/lib/vm_interface/src/pubdata/mod.rs b/core/lib/vm_interface/src/pubdata/mod.rs index f901687b5fa..c0b6e744dfc 100644 --- a/core/lib/vm_interface/src/pubdata/mod.rs +++ b/core/lib/vm_interface/src/pubdata/mod.rs @@ -13,7 +13,7 @@ use zksync_types::{ /// bytes32 value; /// } /// ``` -#[derive(Debug, Default, Clone, PartialEq)] +#[derive(Debug, Default, Clone, PartialEq, Eq)] pub struct L1MessengerL2ToL1Log { pub l2_shard_id: u8, pub is_service: bool, @@ -63,7 +63,7 @@ impl From for L2ToL1Log { } /// Struct based on which the pubdata blob is formed -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, Eq, PartialEq)] pub struct PubdataInput { pub user_logs: Vec, pub l2_to_l1_messages: Vec>,