@@ -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." ) ]
@@ -179,10 +183,10 @@ impl ResourceFinalizer for OsTransactionTrace {
179
183
}
180
184
}
181
185
182
- impl TryFrom < OsTransactionTrace > for String {
186
+ impl TryFrom < & OsTransactionTrace > for String {
183
187
type Error = OsLoggerError ;
184
188
185
- fn try_from ( trace : OsTransactionTrace ) -> OsLoggerResult < Self > {
189
+ fn try_from ( trace : & OsTransactionTrace ) -> OsLoggerResult < Self > {
186
190
let resources = trace. get_resources ( ) ?;
187
191
let builtins = if !resources. builtin_instance_counter . is_empty ( ) {
188
192
format ! ( "\n \t Builtins: {:?}" , resources. builtin_instance_counter)
@@ -345,7 +349,6 @@ pub struct OsLogger {
345
349
current_tx : Option < OsTransactionTrace > ,
346
350
tab_count : usize ,
347
351
syscall_stack : Vec < SyscallTrace > ,
348
- #[ allow( dead_code) ]
349
352
txs : Vec < OsTransactionTrace > ,
350
353
resource_counter_stack : Vec < ResourceCounter > ,
351
354
}
@@ -492,4 +495,32 @@ impl OsLogger {
492
495
self . log ( & format ! ( "Entering {tx_type:?}: {tx_hash}." ) , true ) ;
493
496
Ok ( ( ) )
494
497
}
498
+
499
+ pub fn exit_tx (
500
+ & mut self ,
501
+ n_steps : usize ,
502
+ range_check_ptr : Relocatable ,
503
+ ids_data : & HashMap < String , HintReference > ,
504
+ vm : & VirtualMachine ,
505
+ ap_tracking : & ApTracking ,
506
+ os_program : & Program ,
507
+ ) -> OsLoggerResult < ( ) > {
508
+ let mut current_tx = self . current_tx . take ( ) . ok_or ( OsLoggerError :: ExitBeforeEnter ) ?;
509
+
510
+ // Sanity check.
511
+ if !self . syscall_stack . is_empty ( ) {
512
+ return Err ( OsLoggerError :: RemainingSyscalls ) ;
513
+ }
514
+
515
+ let enter_resources_counter =
516
+ self . resource_counter_stack . pop ( ) . ok_or ( OsLoggerError :: CallStackEmpty ) ?;
517
+ let exit_resources_counter =
518
+ ResourceCounter :: new ( n_steps, range_check_ptr, ids_data, vm, ap_tracking, os_program) ?;
519
+
520
+ current_tx
521
+ . finalize_resources ( exit_resources_counter. sub_counter ( & enter_resources_counter) ?) ?;
522
+ self . log ( & format ! ( "Exiting {}." , String :: try_from( & current_tx) ?) , false ) ;
523
+ self . txs . push ( current_tx) ;
524
+ Ok ( ( ) )
525
+ }
495
526
}
0 commit comments