@@ -6,7 +6,7 @@ use crate::{definitions::transaction_type::TransactionType, transaction::error::
6
6
7
7
#[ derive( Debug , Clone ) ]
8
8
pub struct OsResources {
9
- _execute_syscalls : HashMap < String , ExecutionResources > ,
9
+ execute_syscalls : HashMap < String , ExecutionResources > ,
10
10
execute_txs_inner : HashMap < TransactionType , ExecutionResources > ,
11
11
}
12
12
@@ -16,22 +16,22 @@ impl Default for OsResources {
16
16
(
17
17
TransactionType :: InvokeFunction ,
18
18
ExecutionResources {
19
- n_steps : 2839 ,
19
+ n_steps : 3363 ,
20
20
n_memory_holes : 0 ,
21
21
builtin_instance_counter : HashMap :: from ( [
22
22
( "pedersen_builtin" . to_string ( ) , 16 ) ,
23
- ( "range_check_builtin" . to_string ( ) , 70 ) ,
23
+ ( "range_check_builtin" . to_string ( ) , 80 ) ,
24
24
] ) ,
25
25
} ,
26
26
) ,
27
27
(
28
28
TransactionType :: Declare ,
29
29
ExecutionResources {
30
- n_steps : 2336 ,
30
+ n_steps : 2703 ,
31
31
n_memory_holes : 0 ,
32
32
builtin_instance_counter : HashMap :: from ( [
33
33
( "pedersen_builtin" . to_string ( ) , 15 ) ,
34
- ( "range_check_builtin" . to_string ( ) , 57 ) ,
34
+ ( "range_check_builtin" . to_string ( ) , 63 ) ,
35
35
] ) ,
36
36
} ,
37
37
) ,
@@ -46,11 +46,11 @@ impl Default for OsResources {
46
46
(
47
47
TransactionType :: DeployAccount ,
48
48
ExecutionResources {
49
- n_steps : 3098 ,
49
+ n_steps : 3612 ,
50
50
n_memory_holes : 0 ,
51
51
builtin_instance_counter : HashMap :: from ( [
52
52
( "pedersen_builtin" . to_string ( ) , 23 ) ,
53
- ( "range_check_builtin" . to_string ( ) , 74 ) ,
53
+ ( "range_check_builtin" . to_string ( ) , 83 ) ,
54
54
] ) ,
55
55
} ,
56
56
) ,
@@ -67,22 +67,237 @@ impl Default for OsResources {
67
67
) ,
68
68
] ) ;
69
69
70
+ let execute_syscalls = HashMap :: from ( [
71
+ (
72
+ "call_contract" . to_string ( ) ,
73
+ ExecutionResources {
74
+ n_steps : 690 ,
75
+ n_memory_holes : 0 ,
76
+ builtin_instance_counter : HashMap :: from ( [ (
77
+ "range_check_builtin" . to_string ( ) ,
78
+ 19 ,
79
+ ) ] ) ,
80
+ } ,
81
+ ) ,
82
+ (
83
+ "delegate_call" . to_string ( ) ,
84
+ ExecutionResources {
85
+ n_steps : 712 ,
86
+ n_memory_holes : 0 ,
87
+ builtin_instance_counter : HashMap :: from ( [ (
88
+ "range_check_builtin" . to_string ( ) ,
89
+ 19 ,
90
+ ) ] ) ,
91
+ } ,
92
+ ) ,
93
+ (
94
+ "delegate_l1_handler" . to_string ( ) ,
95
+ ExecutionResources {
96
+ n_steps : 691 ,
97
+ n_memory_holes : 0 ,
98
+ builtin_instance_counter : HashMap :: from ( [ (
99
+ "range_check_builtin" . to_string ( ) ,
100
+ 15 ,
101
+ ) ] ) ,
102
+ } ,
103
+ ) ,
104
+ (
105
+ "deploy" . to_string ( ) ,
106
+ ExecutionResources {
107
+ n_steps : 936 ,
108
+ n_memory_holes : 0 ,
109
+ builtin_instance_counter : HashMap :: from ( [
110
+ ( "range_check_builtin" . to_string ( ) , 18 ) ,
111
+ ( "pedersen_builtin" . to_string ( ) , 7 ) ,
112
+ ] ) ,
113
+ } ,
114
+ ) ,
115
+ (
116
+ "library_call" . to_string ( ) ,
117
+ ExecutionResources {
118
+ n_steps : 679 ,
119
+ n_memory_holes : 0 ,
120
+ builtin_instance_counter : HashMap :: from ( [ (
121
+ "range_check_builtin" . to_string ( ) ,
122
+ 19 ,
123
+ ) ] ) ,
124
+ } ,
125
+ ) ,
126
+ (
127
+ "emit_event" . to_string ( ) ,
128
+ ExecutionResources {
129
+ n_steps : 19 ,
130
+ n_memory_holes : 0 ,
131
+ builtin_instance_counter : HashMap :: new ( ) ,
132
+ } ,
133
+ ) ,
134
+ (
135
+ "get_block_hash" . to_string ( ) ,
136
+ ExecutionResources {
137
+ n_steps : 44 ,
138
+ n_memory_holes : 0 ,
139
+ builtin_instance_counter : HashMap :: new ( ) ,
140
+ } ,
141
+ ) ,
142
+ (
143
+ "get_block_number" . to_string ( ) ,
144
+ ExecutionResources {
145
+ n_steps : 40 ,
146
+ n_memory_holes : 0 ,
147
+ builtin_instance_counter : HashMap :: new ( ) ,
148
+ } ,
149
+ ) ,
150
+ (
151
+ "get_block_timestamp" . to_string ( ) ,
152
+ ExecutionResources {
153
+ n_steps : 38 ,
154
+ n_memory_holes : 0 ,
155
+ builtin_instance_counter : HashMap :: new ( ) ,
156
+ } ,
157
+ ) ,
158
+ (
159
+ "get_caller_address" . to_string ( ) ,
160
+ ExecutionResources {
161
+ n_steps : 32 ,
162
+ n_memory_holes : 0 ,
163
+ builtin_instance_counter : HashMap :: new ( ) ,
164
+ } ,
165
+ ) ,
166
+ (
167
+ "get_contract_address" . to_string ( ) ,
168
+ ExecutionResources {
169
+ n_steps : 36 ,
170
+ n_memory_holes : 0 ,
171
+ builtin_instance_counter : HashMap :: new ( ) ,
172
+ } ,
173
+ ) ,
174
+ (
175
+ "get_execution_info" . to_string ( ) ,
176
+ ExecutionResources {
177
+ n_steps : 29 ,
178
+ n_memory_holes : 0 ,
179
+ builtin_instance_counter : HashMap :: new ( ) ,
180
+ } ,
181
+ ) ,
182
+ (
183
+ "get_sequencer_address" . to_string ( ) ,
184
+ ExecutionResources {
185
+ n_steps : 34 ,
186
+ n_memory_holes : 0 ,
187
+ builtin_instance_counter : HashMap :: new ( ) ,
188
+ } ,
189
+ ) ,
190
+ (
191
+ "get_tx_info" . to_string ( ) ,
192
+ ExecutionResources {
193
+ n_steps : 29 ,
194
+ n_memory_holes : 0 ,
195
+ builtin_instance_counter : HashMap :: new ( ) ,
196
+ } ,
197
+ ) ,
198
+ (
199
+ "get_tx_signature" . to_string ( ) ,
200
+ ExecutionResources {
201
+ n_steps : 44 ,
202
+ n_memory_holes : 0 ,
203
+ builtin_instance_counter : HashMap :: new ( ) ,
204
+ } ,
205
+ ) ,
206
+ (
207
+ "library_call_l1_handler" . to_string ( ) ,
208
+ ExecutionResources {
209
+ n_steps : 658 ,
210
+ n_memory_holes : 0 ,
211
+ builtin_instance_counter : HashMap :: from ( [ (
212
+ "range_check_builtin" . to_string ( ) ,
213
+ 15 ,
214
+ ) ] ) ,
215
+ } ,
216
+ ) ,
217
+ (
218
+ "replace_class" . to_string ( ) ,
219
+ ExecutionResources {
220
+ n_steps : 73 ,
221
+ n_memory_holes : 0 ,
222
+ builtin_instance_counter : HashMap :: new ( ) ,
223
+ } ,
224
+ ) ,
225
+ (
226
+ "send_message_to_l1" . to_string ( ) ,
227
+ ExecutionResources {
228
+ n_steps : 84 ,
229
+ n_memory_holes : 0 ,
230
+ builtin_instance_counter : HashMap :: new ( ) ,
231
+ } ,
232
+ ) ,
233
+ (
234
+ "storage_read" . to_string ( ) ,
235
+ ExecutionResources {
236
+ n_steps : 44 ,
237
+ n_memory_holes : 0 ,
238
+ builtin_instance_counter : HashMap :: new ( ) ,
239
+ } ,
240
+ ) ,
241
+ (
242
+ "storage_write" . to_string ( ) ,
243
+ ExecutionResources {
244
+ n_steps : 46 ,
245
+ n_memory_holes : 0 ,
246
+ builtin_instance_counter : HashMap :: new ( ) ,
247
+ } ,
248
+ ) ,
249
+ ] ) ;
250
+
70
251
OsResources {
71
- _execute_syscalls : HashMap :: new ( ) ,
252
+ execute_syscalls ,
72
253
execute_txs_inner,
73
254
}
74
255
}
75
256
}
76
257
77
258
pub fn get_additional_os_resources (
78
- _syscall_counter : HashMap < String , u64 > ,
259
+ syscall_counter : HashMap < String , u64 > ,
79
260
tx_type : & TransactionType ,
80
261
) -> Result < ExecutionResources , TransactionError > {
81
262
let os_resources = OsResources :: default ( ) ;
82
263
83
- Ok ( os_resources
264
+ let mut additional_os_resources = ExecutionResources :: default ( ) ;
265
+
266
+ for ( syscall, count) in syscall_counter {
267
+ let syscall_resources = & os_resources
268
+ . execute_syscalls
269
+ . get ( & syscall)
270
+ . ok_or_else ( || TransactionError :: ResourcesError ) ?
271
+ . clone ( )
272
+ * count as usize ;
273
+
274
+ additional_os_resources += & syscall_resources;
275
+ }
276
+
277
+ additional_os_resources += & os_resources
84
278
. execute_txs_inner
85
279
. get ( tx_type)
86
280
. ok_or_else ( || TransactionError :: NoneTransactionType ( * tx_type, os_resources. clone ( ) ) ) ?
87
- . clone ( ) )
281
+ . clone ( ) ;
282
+
283
+ Ok ( additional_os_resources)
284
+ }
285
+
286
+ #[ test]
287
+ fn get_additional_os_resources_test ( ) {
288
+ let syscall_counter = HashMap :: from ( [ ( "storage_read" . into ( ) , 2 ) , ( "storage_write" . into ( ) , 3 ) ] ) ;
289
+
290
+ let tx_type = TransactionType :: InvokeFunction ;
291
+
292
+ let additional_os_resources = get_additional_os_resources ( syscall_counter, & tx_type) . unwrap ( ) ;
293
+ let expected_additional_os_resources = ExecutionResources {
294
+ n_steps : 3589 ,
295
+ n_memory_holes : 0 ,
296
+ builtin_instance_counter : HashMap :: from ( [
297
+ ( "range_check_builtin" . to_string ( ) , 80 ) ,
298
+ ( "pedersen_builtin" . to_string ( ) , 16 ) ,
299
+ ] ) ,
300
+ } ;
301
+
302
+ assert_eq ! ( additional_os_resources, expected_additional_os_resources) ;
88
303
}
0 commit comments