@@ -40,26 +40,37 @@ use crate::starkware_utils::commitment_tree::update_tree::{DecodeNodeCase, TreeU
40
40
use crate :: utils:: { custom_hint_error, execute_coroutine, get_constant} ;
41
41
42
42
pub const LOAD_NEXT_TX : & str = indoc ! { r#"
43
- tx = next(transactions)
44
- assert tx.tx_type.name in ('INVOKE_FUNCTION', 'L1_HANDLER', 'DEPLOY_ACCOUNT', 'DECLARE'), (
45
- f"Unexpected transaction type: {tx.type.name}."
46
- )
43
+ from src.starkware.starknet.core.os.transaction_hash.transaction_hash import (
44
+ create_resource_bounds_list,
45
+ )
46
+ tx = next(transactions)
47
+ assert tx.tx_type.name in ('INVOKE_FUNCTION', 'L1_HANDLER', 'DEPLOY_ACCOUNT', 'DECLARE'), (
48
+ f"Unexpected transaction type: {tx.type.name}."
49
+ )
47
50
48
- tx_type_bytes = tx.tx_type.name.encode("ascii")
49
- ids.tx_type = int.from_bytes(tx_type_bytes, "big")
50
- execution_helper.os_logger.enter_tx(
51
- tx=tx,
52
- n_steps=current_step,
53
- builtin_ptrs=ids.builtin_ptrs,
54
- range_check_ptr=ids.range_check_ptr,
55
- )
51
+ tx_type_bytes = tx.tx_type.name.encode("ascii")
52
+ ids.tx_type = int.from_bytes(tx_type_bytes, "big")
53
+ execution_helper.os_logger.enter_tx(
54
+ tx=tx,
55
+ n_steps=current_step,
56
+ builtin_ptrs=ids.builtin_ptrs,
57
+ range_check_ptr=ids.range_check_ptr,
58
+ )
59
+
60
+ # Prepare a short callable to save code duplication.
61
+ exit_tx = lambda: execution_helper.os_logger.exit_tx(
62
+ n_steps=current_step,
63
+ builtin_ptrs=ids.builtin_ptrs,
64
+ range_check_ptr=ids.range_check_ptr,
65
+ )
56
66
57
- # Prepare a short callable to save code duplication.
58
- exit_tx = lambda: execution_helper.os_logger.exit_tx(
59
- n_steps=current_step,
60
- builtin_ptrs=ids.builtin_ptrs,
61
- range_check_ptr=ids.range_check_ptr,
62
- )"#
67
+ # Guess the resource bounds.
68
+ if tx.tx_type.name == 'L1_HANDLER' or tx.version < 3:
69
+ ids.resource_bounds = 0
70
+ ids.n_resource_bounds = 0
71
+ else:
72
+ ids.resource_bounds = segments.gen_arg(create_resource_bounds_list(tx.resource_bounds))
73
+ ids.n_resource_bounds = len(tx.resource_bounds)"#
63
74
} ;
64
75
pub fn load_next_tx (
65
76
vm : & mut VirtualMachine ,
@@ -82,8 +93,31 @@ pub fn load_next_tx(
82
93
vm,
83
94
ids_data,
84
95
ap_tracking,
85
- )
96
+ ) ?;
97
+
86
98
// TODO: add logger
99
+
100
+ // Guess the resource bounds
101
+ if tx. r#type == "L1_HANDLER" {
102
+ insert_value_from_var_name ( vars:: ids:: RESOURCE_BOUNDS , 0 , vm, ids_data, ap_tracking) ?;
103
+ insert_value_from_var_name ( vars:: ids:: N_RESOURCE_BOUNDS , 0 , vm, ids_data, ap_tracking) ?;
104
+ } else {
105
+ let resource_bounds_base = vm. add_memory_segment ( ) ;
106
+ let resource_bounds = tx. resource_bounds . ok_or_else ( || {
107
+ HintError :: CustomHint ( "Transaction should have resource bounds" . to_owned ( ) . into_boxed_str ( ) )
108
+ } ) ?;
109
+ let resource_bounds_list = create_resource_bounds_list ( & resource_bounds) ;
110
+ let resource_bounds_list_data = resource_bounds_list. iter ( ) . map ( |felt| {
111
+ MaybeRelocatable :: Int ( * felt)
112
+ } )
113
+ . collect :: < Vec < _ > > ( ) ;
114
+ vm. load_data ( resource_bounds_base, & resource_bounds_list_data[ ..] ) ?;
115
+
116
+ insert_value_from_var_name ( vars:: ids:: RESOURCE_BOUNDS , resource_bounds_base, vm, ids_data, ap_tracking) ?;
117
+ insert_value_from_var_name ( vars:: ids:: N_RESOURCE_BOUNDS , resource_bounds_list_data. len ( ) , vm, ids_data, ap_tracking) ?;
118
+ }
119
+
120
+ Ok ( ( ) )
87
121
}
88
122
89
123
pub const EXIT_TX : & str = "exit_tx()" ;
0 commit comments