@@ -6,26 +6,17 @@ use zksync_system_constants::{
66 PUBLISH_BYTECODE_OVERHEAD ,
77} ;
88use zksync_types:: {
9+ bytecode:: BytecodeHash ,
910 ethabi,
1011 l2_to_l1_log:: { SystemL2ToL1Log , UserL2ToL1Log } ,
1112 zk_evm_types:: FarCallOpcode ,
1213 Address , L1BatchNumber , StorageLogWithPreviousValue , Transaction , H256 , U256 ,
1314} ;
1415
1516use crate :: {
16- BytecodeCompressionError , CompressedBytecodeInfo , Halt , VmExecutionMetrics ,
17- VmExecutionStatistics , VmRevertReason ,
17+ BytecodeCompressionError , Halt , VmExecutionMetrics , VmExecutionStatistics , VmRevertReason ,
1818} ;
1919
20- const L1_MESSAGE_EVENT_SIGNATURE : H256 = H256 ( [
21- 58 , 54 , 228 , 114 , 145 , 244 , 32 , 31 , 175 , 19 , 127 , 171 , 8 , 29 , 146 , 41 , 91 , 206 , 45 , 83 , 190 ,
22- 44 , 108 , 166 , 139 , 168 , 44 , 127 , 170 , 156 , 226 , 65 ,
23- ] ) ;
24-
25- pub fn bytecode_len_in_bytes ( bytecodehash : H256 ) -> usize {
26- usize:: from ( u16:: from_be_bytes ( [ bytecodehash[ 2 ] , bytecodehash[ 3 ] ] ) ) * 32
27- }
28-
2920/// Event generated by the VM.
3021#[ derive( Default , Debug , Clone , PartialEq ) ]
3122pub struct VmEvent {
@@ -51,6 +42,11 @@ impl VmEvent {
5142 201 , 71 , 34 , 255 , 19 , 234 , 207 , 83 , 84 , 124 , 71 , 65 , 218 , 181 , 34 , 131 , 83 , 160 , 89 , 56 ,
5243 255 , 205 , 213 , 212 , 162 , 213 , 51 , 174 , 14 , 97 , 130 , 135 ,
5344 ] ) ;
45+ /// Long signature of the L1 messenger publication event (`L1MessageSent`).
46+ pub const L1_MESSAGE_EVENT_SIGNATURE : H256 = H256 ( [
47+ 58 , 54 , 228 , 114 , 145 , 244 , 32 , 31 , 175 , 19 , 127 , 171 , 8 , 29 , 146 , 41 , 91 , 206 , 45 , 83 ,
48+ 190 , 44 , 108 , 166 , 139 , 168 , 44 , 127 , 170 , 156 , 226 , 65 ,
49+ ] ) ;
5450
5551 /// Extracts all the "long" L2->L1 messages that were submitted by the L1Messenger contract.
5652 pub fn extract_long_l2_to_l1_messages ( events : & [ Self ] ) -> Vec < Vec < u8 > > {
@@ -60,7 +56,7 @@ impl VmEvent {
6056 // Filter events from the l1 messenger contract that match the expected signature.
6157 event. address == L1_MESSENGER_ADDRESS
6258 && event. indexed_topics . len ( ) == 3
63- && event. indexed_topics [ 0 ] == L1_MESSAGE_EVENT_SIGNATURE
59+ && event. indexed_topics [ 0 ] == Self :: L1_MESSAGE_EVENT_SIGNATURE
6460 } )
6561 . map ( |event| {
6662 let decoded_tokens = ethabi:: decode ( & [ ethabi:: ParamType :: Bytes ] , & event. value )
@@ -174,11 +170,7 @@ impl VmExecutionResultAndLogs {
174170 Self :: mock ( ExecutionResult :: Success { output : vec ! [ ] } )
175171 }
176172
177- pub fn get_execution_metrics ( & self , tx : Option < & Transaction > ) -> VmExecutionMetrics {
178- let contracts_deployed = tx
179- . map ( |tx| tx. execute . factory_deps . len ( ) as u16 )
180- . unwrap_or ( 0 ) ;
181-
173+ pub fn get_execution_metrics ( & self ) -> VmExecutionMetrics {
182174 // We published the data as ABI-encoded `bytes`, so the total length is:
183175 // - message length in bytes, rounded up to a multiple of 32
184176 // - 32 bytes of encoded offset
@@ -190,8 +182,11 @@ impl VmExecutionResultAndLogs {
190182
191183 let published_bytecode_bytes = VmEvent :: extract_published_bytecodes ( & self . logs . events )
192184 . iter ( )
193- . map ( |bytecodehash| {
194- bytecode_len_in_bytes ( * bytecodehash) + PUBLISH_BYTECODE_OVERHEAD as usize
185+ . map ( |& bytecode_hash| {
186+ let len_in_bytes = BytecodeHash :: try_from ( bytecode_hash)
187+ . expect ( "published unparseable bytecode hash" )
188+ . len_in_bytes ( ) ;
189+ len_in_bytes + PUBLISH_BYTECODE_OVERHEAD as usize
195190 } )
196191 . sum ( ) ;
197192
@@ -202,7 +197,6 @@ impl VmExecutionResultAndLogs {
202197 l2_to_l1_logs : self . logs . total_l2_to_l1_logs_count ( ) ,
203198 user_l2_to_l1_logs : self . logs . user_l2_to_l1_logs . len ( ) ,
204199 contracts_used : self . statistics . contracts_used ,
205- contracts_deployed,
206200 vm_events : self . logs . events . len ( ) ,
207201 storage_logs : self . logs . storage_logs . len ( ) ,
208202 total_log_queries : self . statistics . total_log_queries ,
@@ -336,43 +330,33 @@ impl Call {
336330}
337331
338332/// Mid-level transaction execution output returned by a [batch executor](crate::executor::BatchExecutor).
339- #[ derive( Debug , Clone ) ]
340- pub struct BatchTransactionExecutionResult < C = Vec < CompressedBytecodeInfo > > {
333+ #[ derive( Debug ) ]
334+ pub struct BatchTransactionExecutionResult {
341335 /// VM result.
342336 pub tx_result : Box < VmExecutionResultAndLogs > ,
343337 /// Compressed bytecodes used by the transaction.
344- pub compressed_bytecodes : C ,
338+ pub compression_result : Result < ( ) , BytecodeCompressionError > ,
345339 /// Call traces (if requested; otherwise, empty).
346340 pub call_traces : Vec < Call > ,
347341}
348342
349- impl < C > BatchTransactionExecutionResult < C > {
343+ impl BatchTransactionExecutionResult {
350344 pub fn was_halted ( & self ) -> bool {
351345 matches ! ( self . tx_result. result, ExecutionResult :: Halt { .. } )
352346 }
353347}
354348
355349/// Mid-level transaction execution output returned by a [oneshot executor](crate::executor::OneshotExecutor).
356- #[ derive( Debug ) ]
357- pub struct OneshotTransactionExecutionResult {
358- /// VM result.
359- pub tx_result : Box < VmExecutionResultAndLogs > ,
360- /// Result of compressing bytecodes used by the transaction.
361- pub compression_result : Result < ( ) , BytecodeCompressionError > ,
362- /// Call traces (if requested; otherwise, empty).
363- pub call_traces : Vec < Call > ,
364- }
350+ pub type OneshotTransactionExecutionResult = BatchTransactionExecutionResult ;
365351
366- /// High-level transaction execution result used by the API server sandbox etc.
352+ /// High-level transaction execution result used by the state keeper etc.
367353#[ derive( Debug , Clone , PartialEq ) ]
368354pub struct TransactionExecutionResult {
369355 pub transaction : Transaction ,
370356 pub hash : H256 ,
371357 pub execution_info : VmExecutionMetrics ,
372358 pub execution_status : TxExecutionStatus ,
373359 pub refunded_gas : u64 ,
374- pub operator_suggested_refund : u64 ,
375- pub compressed_bytecodes : Vec < CompressedBytecodeInfo > ,
376360 pub call_traces : Vec < Call > ,
377361 pub revert_reason : Option < String > ,
378362}
@@ -436,7 +420,7 @@ mod tests {
436420 ethabi:: ParamType :: Bytes ,
437421 ] ,
438422 ) ;
439- assert_eq ! ( L1_MESSAGE_EVENT_SIGNATURE , expected_signature) ;
423+ assert_eq ! ( VmEvent :: L1_MESSAGE_EVENT_SIGNATURE , expected_signature) ;
440424 }
441425
442426 #[ test]
0 commit comments