@@ -45,6 +45,8 @@ pub enum OsLoggerError {
45
45
CallStackEmpty ,
46
46
#[ error( "SyscallTrace should be finalized only once." ) ]
47
47
DoubleFinalize ,
48
+ #[ error( "No transaction should exit without entering." ) ]
49
+ ExitBeforeEnter ,
48
50
#[ error( "Failed to fetch identifier data for struct {0}." ) ]
49
51
InnerBuiltinPtrsIdentifierMissing ( String ) ,
50
52
#[ error( "No transaction should call another transaction." ) ]
@@ -60,6 +62,8 @@ pub enum OsLoggerError {
60
62
{self_ptr}, {enter_ptr}."
61
63
) ]
62
64
RangeCheckNotInSameSegment { self_ptr : Relocatable , enter_ptr : Relocatable } ,
65
+ #[ error( "All Syscalls should end when exiting a transaction." ) ]
66
+ RemainingSyscalls ,
63
67
#[ error( "SyscallTrace should be finalized before accessing resources." ) ]
64
68
ResourceAccessBeforeFinalize ,
65
69
#[ error( "The {0} syscall is not supposed to have an inner syscall." ) ]
@@ -180,10 +184,10 @@ impl ResourceFinalizer for OsTransactionTrace {
180
184
}
181
185
}
182
186
183
- impl TryFrom < OsTransactionTrace > for String {
187
+ impl TryFrom < & OsTransactionTrace > for String {
184
188
type Error = OsLoggerError ;
185
189
186
- fn try_from ( trace : OsTransactionTrace ) -> OsLoggerResult < Self > {
190
+ fn try_from ( trace : & OsTransactionTrace ) -> OsLoggerResult < Self > {
187
191
let resources = trace. get_resources ( ) ?;
188
192
let builtins = if !resources. builtin_instance_counter . is_empty ( ) {
189
193
format ! ( "\n \t Builtins: {:?}" , resources. builtin_instance_counter)
@@ -487,4 +491,32 @@ impl OsLogger {
487
491
self . log ( & format ! ( "Entering {tx_type:?}: {tx_hash}." ) , true ) ;
488
492
Ok ( ( ) )
489
493
}
494
+
495
+ pub fn exit_tx (
496
+ & mut self ,
497
+ n_steps : usize ,
498
+ range_check_ptr : Relocatable ,
499
+ ids_data : & HashMap < String , HintReference > ,
500
+ vm : & VirtualMachine ,
501
+ ap_tracking : & ApTracking ,
502
+ os_program : & Program ,
503
+ ) -> OsLoggerResult < ( ) > {
504
+ let mut current_tx = self . current_tx . take ( ) . ok_or ( OsLoggerError :: ExitBeforeEnter ) ?;
505
+
506
+ // Sanity check.
507
+ if !self . syscall_stack . is_empty ( ) {
508
+ return Err ( OsLoggerError :: RemainingSyscalls ) ;
509
+ }
510
+
511
+ let enter_resources_counter =
512
+ self . resource_counter_stack . pop ( ) . ok_or ( OsLoggerError :: CallStackEmpty ) ?;
513
+ let exit_resources_counter =
514
+ ResourceCounter :: new ( n_steps, range_check_ptr, ids_data, vm, ap_tracking, os_program) ?;
515
+
516
+ current_tx
517
+ . finalize_resources ( exit_resources_counter. sub_counter ( & enter_resources_counter) ?) ?;
518
+ self . log ( & format ! ( "Exiting {}." , String :: try_from( & current_tx) ?) , false ) ;
519
+ self . txs . push ( current_tx) ;
520
+ Ok ( ( ) )
521
+ }
490
522
}
0 commit comments