diff --git a/Cargo.lock b/Cargo.lock index 94799622639..ab7a2d56103 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4875,6 +4875,7 @@ dependencies = [ "apollo_consensus", "apollo_consensus_orchestrator", "apollo_infra_utils", + "apollo_starknet_os_program", "blockifier", "blockifier_test_utils", "expect-test", diff --git a/crates/central_systest_blobs/Cargo.toml b/crates/central_systest_blobs/Cargo.toml index 2926d000b56..f610ef1c52d 100644 --- a/crates/central_systest_blobs/Cargo.toml +++ b/crates/central_systest_blobs/Cargo.toml @@ -13,6 +13,7 @@ apollo_class_manager_types = { workspace = true, features = ["testing"] } apollo_consensus.workspace = true apollo_consensus_orchestrator = { workspace = true, features = ["testing"] } apollo_infra_utils.workspace = true +apollo_starknet_os_program.workspace = true blockifier = { workspace = true, features = ["reexecution", "testing"] } blockifier_test_utils.workspace = true expect-test.workspace = true diff --git a/crates/central_systest_blobs/resources/blob_file_generation b/crates/central_systest_blobs/resources/blob_file_generation index 3cacc0b93c9..ca7bf83ac53 100644 --- a/crates/central_systest_blobs/resources/blob_file_generation +++ b/crates/central_systest_blobs/resources/blob_file_generation @@ -1 +1 @@ -12 \ No newline at end of file +13 \ No newline at end of file diff --git a/crates/central_systest_blobs/resources/preconfirmed_block.json b/crates/central_systest_blobs/resources/preconfirmed_block.json index 9815f198a00..436489c8d03 100644 --- a/crates/central_systest_blobs/resources/preconfirmed_block.json +++ b/crates/central_systest_blobs/resources/preconfirmed_block.json @@ -1,5 +1,5 @@ { - "block_number": 13, + "block_number": 14, "pre_confirmed_block": { "l1_da_mode": "CALLDATA", "l1_data_gas_price": { @@ -17,7 +17,7 @@ "sequencer_address": "0x1000", "starknet_version": "0.14.3", "status": "PRE_CONFIRMED", - "timestamp": 1013, + "timestamp": 1014, "transaction_receipts": [ { "actual_fee": "0xff313", @@ -56,7 +56,7 @@ }, "execution_status": "SUCCEEDED", "l2_to_l1_messages": [], - "transaction_hash": "0x4acc6e7cb93683ae3a42ed499788f2d0143e8c3357315e1ecaad4e65f6dd479", + "transaction_hash": "0x1fa0c5398afa836eb5dff4cf1ddd3cc6d57d1eb8af9b93c74bd23fe67d32c5a", "transaction_index": 0 } ], @@ -66,7 +66,7 @@ "deployed_contracts": [], "migrated_compiled_classes": [], "nonces": { - "0xf99e7cdfbcce0bf14ce17e4c57fd2d12ad1bca5fc8e46a9fbafc36b59a9955": "0xc" + "0xf99e7cdfbcce0bf14ce17e4c57fd2d12ad1bca5fc8e46a9fbafc36b59a9955": "0xd" }, "old_declared_contracts": [], "replaced_classes": [], @@ -74,11 +74,11 @@ "0x6bd1d71a2fb67a567618584ca31da288dbc2e1a8421e4045e05f52c19bfab83": [ { "key": "0x6fba6554adab51d0272b896b6f41768bd0491e5ad59c39fab38e65767974793", - "value": "0xffffffffffffffffffffffff924412b1" + "value": "0xffffffffffffffffffffffff8db86b6b" }, { "key": "0x723973208639b7839ce298f7ffea61e3f9533872defd7abdb91023db4658812", - "value": "0x6dbbed4e" + "value": "0x72479494" } ] } @@ -96,7 +96,7 @@ "0x2000" ], "fee_data_availability_mode": 0, - "nonce": "0xb", + "nonce": "0xc", "nonce_data_availability_mode": 0, "paymaster_data": [], "proof_facts": [], @@ -116,11 +116,11 @@ }, "sender_address": "0xf99e7cdfbcce0bf14ce17e4c57fd2d12ad1bca5fc8e46a9fbafc36b59a9955", "signature": [ - "0x47fc4402ccfebfe5e1a8af95ee4de99932534b43d9161e7024847382c022926", - "0x71c9ccc594f6d54d88b649a51dc167c3df0423d4a3f95a0e1b85f2560e78588" + "0x7635250c4e3d567295d7a2812dacc8f528d838dc1931c0988f7fe0f98fbc356", + "0x4ece213c76134174981d469d96dc69e58890e6bcd5461b817669ed67b927ab5" ], "tip": "0x0", - "transaction_hash": "0x4acc6e7cb93683ae3a42ed499788f2d0143e8c3357315e1ecaad4e65f6dd479", + "transaction_hash": "0x1fa0c5398afa836eb5dff4cf1ddd3cc6d57d1eb8af9b93c74bd23fe67d32c5a", "type": "INVOKE_FUNCTION", "version": "0x3" } diff --git a/crates/central_systest_blobs/src/cende_blob_regression_test.rs b/crates/central_systest_blobs/src/cende_blob_regression_test.rs index 082a545df69..3ccbb63f135 100644 --- a/crates/central_systest_blobs/src/cende_blob_regression_test.rs +++ b/crates/central_systest_blobs/src/cende_blob_regression_test.rs @@ -20,6 +20,7 @@ use apollo_consensus_orchestrator::cende::{ }; use apollo_consensus_orchestrator::fee_market::FeeMarketInfo; use apollo_infra_utils::compile_time_cargo_manifest_dir; +use apollo_starknet_os_program::PROGRAM_HASHES; use blockifier::abi::constants::STORED_BLOCK_HASH_BUFFER; use blockifier::blockifier::config::TransactionExecutorConfig; use blockifier::blockifier::transaction_executor::TransactionExecutor; @@ -99,6 +100,9 @@ use starknet_api::transaction::fields::{ ResourceBounds, Tip, TransactionSignature, + PROOF_VERSION, + VIRTUAL_OS_OUTPUT_VERSION, + VIRTUAL_SNOS, }; use starknet_api::transaction::{ CalculateContractAddress, @@ -110,7 +114,7 @@ use starknet_api::transaction::{ TransactionOffsetInBlock, TransactionVersion, }; -use starknet_api::{calldata, contract_address}; +use starknet_api::{calldata, contract_address, proof_facts}; use starknet_committer::block_committer::input::StateDiff; use starknet_committer::db::facts_db::FactsDb; use starknet_committer::db::forest_trait::StorageInitializer; @@ -594,6 +598,46 @@ impl BlobFactory { calldata: &[Felt], with_fee_charge: bool, should_revert: bool, + ) { + self.make_operator_invoke_tx_with_proof( + address, + function_name, + calldata, + with_fee_charge, + should_revert, + ProofFacts::default(), + ) + } + + /// Same as [Self::make_operator_invoke_tx], but with virtual SNOS proof facts. + fn make_operator_proof_tx( + &mut self, + address: ContractAddress, + function_name: &str, + calldata: &[Felt], + with_fee_charge: bool, + should_revert: bool, + ) { + self.make_operator_invoke_tx_with_proof( + address, + function_name, + calldata, + with_fee_charge, + should_revert, + self.make_snos_proof_facts(), + ); + } + + /// Utility method to share code between invokes with and without proofs. Should not be called + /// directly, use [Self::make_operator_invoke_tx] or [Self::make_operator_proof_tx] instead. + fn make_operator_invoke_tx_with_proof( + &mut self, + address: ContractAddress, + function_name: &str, + calldata: &[Felt], + with_fee_charge: bool, + should_revert: bool, + proof_facts: ProofFacts, ) { let nonce = self.nonce_manager.next(*OPERATOR_ADDRESS); let resource_bounds = if with_fee_charge { @@ -613,7 +657,7 @@ impl BlobFactory { fee_data_availability_mode: DataAvailabilityMode::L1, account_deployment_data: AccountDeploymentData::default(), paymaster_data: PaymasterData::default(), - proof_facts: ProofFacts::default(), + proof_facts, }; let tx_hash = rpc_tx_unsigned .calculate_transaction_hash(&CHAIN_ID, &TransactionVersion::THREE) @@ -632,6 +676,37 @@ impl BlobFactory { self.next_txs.push(TxData { executable: executable.into(), internal, should_revert }); } + /// Constructs valid SNOS proof facts referencing the hash of the retrospective block. + fn make_snos_proof_facts(&self) -> ProofFacts { + let block_context = self.next_block_context(); + let retrospective_block_number = block_context + .block_info() + .block_number + .0 + .checked_sub(STORED_BLOCK_HASH_BUFFER) + .unwrap_or_else(|| { + panic!( + "The current block number must be at least {STORED_BLOCK_HASH_BUFFER} blocks \ + ahead of the first block." + ) + }); + let retrospective_block_hash = + self.blocks[usize::try_from(retrospective_block_number).unwrap()].block_hash; + let config_hash = OsChainInfo::from(&self.chain_info) + .compute_virtual_os_config_hash() + .expect("Failed to compute virtual OS config hash"); + proof_facts![ + PROOF_VERSION, + VIRTUAL_SNOS, + PROGRAM_HASHES.virtual_os, + VIRTUAL_OS_OUTPUT_VERSION, + Felt::from(retrospective_block_number), + retrospective_block_hash.0, + config_hash, + Felt::ZERO, // l2_to_l1_messages_segment_size + ] + } + fn make_operator_deploy_tx( &mut self, contract_to_deploy: FeatureContract, @@ -957,6 +1032,14 @@ async fn test_make_data() { false, // should not revert ); blob_factory.close_block().await; + blob_factory.make_operator_proof_tx( + test_contract_address_0, + "test_storage_read_write", + &[Felt::from(0x4000u32), Felt::from(0x4000u32)], + true, // charge fee + false, // should not revert + ); + blob_factory.close_block().await; blob_factory.make_operator_invoke_tx( test_contract_address_0, "catch_write_revert_panic", diff --git a/crates/starknet_api/src/test_utils.rs b/crates/starknet_api/src/test_utils.rs index ce373e8b934..8e3b7f2e6e2 100644 --- a/crates/starknet_api/src/test_utils.rs +++ b/crates/starknet_api/src/test_utils.rs @@ -165,7 +165,7 @@ macro_rules! compiled_class_hash { /// of felt values. #[macro_export] macro_rules! proof_facts { - ( $( $x:expr ),* ) => { + ( $( $x:expr ),* $(,)?) => { $crate::transaction::fields::ProofFacts(vec![$($x),*].into()) }; }