@@ -20,6 +20,7 @@ use apollo_consensus_orchestrator::cende::{
2020} ;
2121use apollo_consensus_orchestrator:: fee_market:: FeeMarketInfo ;
2222use apollo_infra_utils:: compile_time_cargo_manifest_dir;
23+ use apollo_starknet_os_program:: PROGRAM_HASHES ;
2324use blockifier:: abi:: constants:: STORED_BLOCK_HASH_BUFFER ;
2425use blockifier:: blockifier:: config:: TransactionExecutorConfig ;
2526use blockifier:: blockifier:: transaction_executor:: TransactionExecutor ;
@@ -99,6 +100,9 @@ use starknet_api::transaction::fields::{
99100 ResourceBounds ,
100101 Tip ,
101102 TransactionSignature ,
103+ PROOF_VERSION ,
104+ VIRTUAL_OS_OUTPUT_VERSION ,
105+ VIRTUAL_SNOS ,
102106} ;
103107use starknet_api:: transaction:: {
104108 CalculateContractAddress ,
@@ -110,7 +114,7 @@ use starknet_api::transaction::{
110114 TransactionOffsetInBlock ,
111115 TransactionVersion ,
112116} ;
113- use starknet_api:: { calldata, contract_address} ;
117+ use starknet_api:: { calldata, contract_address, proof_facts } ;
114118use starknet_committer:: block_committer:: input:: StateDiff ;
115119use starknet_committer:: db:: facts_db:: FactsDb ;
116120use starknet_committer:: db:: forest_trait:: StorageInitializer ;
@@ -594,6 +598,46 @@ impl BlobFactory {
594598 calldata : & [ Felt ] ,
595599 with_fee_charge : bool ,
596600 should_revert : bool ,
601+ ) {
602+ self . make_operator_invoke_tx_with_proof (
603+ address,
604+ function_name,
605+ calldata,
606+ with_fee_charge,
607+ should_revert,
608+ ProofFacts :: default ( ) ,
609+ )
610+ }
611+
612+ /// Same as [Self::make_operator_invoke_tx], but with virtual SNOS proof facts.
613+ fn make_operator_proof_tx (
614+ & mut self ,
615+ address : ContractAddress ,
616+ function_name : & str ,
617+ calldata : & [ Felt ] ,
618+ with_fee_charge : bool ,
619+ should_revert : bool ,
620+ ) {
621+ self . make_operator_invoke_tx_with_proof (
622+ address,
623+ function_name,
624+ calldata,
625+ with_fee_charge,
626+ should_revert,
627+ self . make_snos_proof_facts ( ) ,
628+ ) ;
629+ }
630+
631+ /// Utility method to share code between invokes with and without proofs. Should not be called
632+ /// directly, use [Self::make_operator_invoke_tx] or [Self::make_operator_proof_tx] instead.
633+ fn make_operator_invoke_tx_with_proof (
634+ & mut self ,
635+ address : ContractAddress ,
636+ function_name : & str ,
637+ calldata : & [ Felt ] ,
638+ with_fee_charge : bool ,
639+ should_revert : bool ,
640+ proof_facts : ProofFacts ,
597641 ) {
598642 let nonce = self . nonce_manager . next ( * OPERATOR_ADDRESS ) ;
599643 let resource_bounds = if with_fee_charge {
@@ -613,7 +657,7 @@ impl BlobFactory {
613657 fee_data_availability_mode : DataAvailabilityMode :: L1 ,
614658 account_deployment_data : AccountDeploymentData :: default ( ) ,
615659 paymaster_data : PaymasterData :: default ( ) ,
616- proof_facts : ProofFacts :: default ( ) ,
660+ proof_facts,
617661 } ;
618662 let tx_hash = rpc_tx_unsigned
619663 . calculate_transaction_hash ( & CHAIN_ID , & TransactionVersion :: THREE )
@@ -632,6 +676,37 @@ impl BlobFactory {
632676 self . next_txs . push ( TxData { executable : executable. into ( ) , internal, should_revert } ) ;
633677 }
634678
679+ /// Constructs valid SNOS proof facts referencing the hash of the retrospective block.
680+ fn make_snos_proof_facts ( & self ) -> ProofFacts {
681+ let block_context = self . next_block_context ( ) ;
682+ let retrospective_block_number = block_context
683+ . block_info ( )
684+ . block_number
685+ . 0
686+ . checked_sub ( STORED_BLOCK_HASH_BUFFER )
687+ . unwrap_or_else ( || {
688+ panic ! (
689+ "The current block number must be at least {STORED_BLOCK_HASH_BUFFER} blocks \
690+ ahead of the first block."
691+ )
692+ } ) ;
693+ let retrospective_block_hash =
694+ self . blocks [ usize:: try_from ( retrospective_block_number) . unwrap ( ) ] . block_hash ;
695+ let config_hash = OsChainInfo :: from ( & self . chain_info )
696+ . compute_virtual_os_config_hash ( )
697+ . expect ( "Failed to compute virtual OS config hash" ) ;
698+ proof_facts ! [
699+ PROOF_VERSION ,
700+ VIRTUAL_SNOS ,
701+ PROGRAM_HASHES . virtual_os,
702+ VIRTUAL_OS_OUTPUT_VERSION ,
703+ Felt :: from( retrospective_block_number) ,
704+ retrospective_block_hash. 0 ,
705+ config_hash,
706+ Felt :: ZERO , // l2_to_l1_messages_segment_size
707+ ]
708+ }
709+
635710 fn make_operator_deploy_tx (
636711 & mut self ,
637712 contract_to_deploy : FeatureContract ,
@@ -957,6 +1032,14 @@ async fn test_make_data() {
9571032 false , // should not revert
9581033 ) ;
9591034 blob_factory. close_block ( ) . await ;
1035+ blob_factory. make_operator_proof_tx (
1036+ test_contract_address_0,
1037+ "test_storage_read_write" ,
1038+ & [ Felt :: from ( 0x4000u32 ) , Felt :: from ( 0x4000u32 ) ] ,
1039+ true , // charge fee
1040+ false , // should not revert
1041+ ) ;
1042+ blob_factory. close_block ( ) . await ;
9601043 blob_factory. make_operator_invoke_tx (
9611044 test_contract_address_0,
9621045 "catch_write_revert_panic" ,
0 commit comments