Skip to content

Commit f721e83

Browse files
Remove constants parameter
1 parent abf34d4 commit f721e83

File tree

8 files changed

+25
-57
lines changed

8 files changed

+25
-57
lines changed

hint_accountant/src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ fn run() {
5252
}
5353
let mut vm = VirtualMachine::new(false, false);
5454
let mut hint_executor = BuiltinHintProcessor::new_empty();
55-
let (ap_tracking_data, reference_ids, references, mut exec_scopes, constants) = (
55+
let (ap_tracking_data, reference_ids, references, mut exec_scopes) = (
5656
ApTracking::default(),
5757
HashMap::new(),
5858
Vec::new(),
5959
ExecutionScopes::new(),
60-
HashMap::new(),
6160
);
6261
let missing_hints: HashSet<_> = whitelists
6362
.into_iter()
@@ -74,7 +73,7 @@ fn run() {
7473
)
7574
.expect("this implementation is infallible");
7675
matches!(
77-
hint_executor.execute_hint(&mut vm, &mut exec_scopes, &hint_data, &constants,),
76+
hint_executor.execute_hint(&mut vm, &mut exec_scopes, &hint_data),
7877
Err(HintError::UnknownHint(_)),
7978
)
8079
})

vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ impl HintProcessorLogic for BuiltinHintProcessor {
189189
vm: &mut VirtualMachine,
190190
exec_scopes: &mut ExecutionScopes,
191191
hint_data: &Box<dyn Any>,
192-
_constants: &HashMap<String, Felt252>,
193192
) -> Result<(), HintError> {
194193
let hint_data = hint_data
195194
.downcast_ref::<HintProcessorData>()
@@ -1451,24 +1450,14 @@ mod tests {
14511450
let hint_data =
14521451
HintProcessorData::new_default(String::from("enter_scope_custom_a"), HashMap::new());
14531452
assert_matches!(
1454-
hint_processor.execute_hint(
1455-
&mut vm,
1456-
exec_scopes,
1457-
&any_box!(hint_data),
1458-
&HashMap::new(),
1459-
),
1453+
hint_processor.execute_hint(&mut vm, exec_scopes, &any_box!(hint_data),),
14601454
Ok(())
14611455
);
14621456
assert_eq!(exec_scopes.data.len(), 2);
14631457
let hint_data =
14641458
HintProcessorData::new_default(String::from("enter_scope_custom_a"), HashMap::new());
14651459
assert_matches!(
1466-
hint_processor.execute_hint(
1467-
&mut vm,
1468-
exec_scopes,
1469-
&any_box!(hint_data),
1470-
&HashMap::new(),
1471-
),
1460+
hint_processor.execute_hint(&mut vm, exec_scopes, &any_box!(hint_data),),
14721461
Ok(())
14731462
);
14741463
assert_eq!(exec_scopes.data.len(), 3);

vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,8 +1285,6 @@ impl HintProcessorLogic for Cairo1HintProcessor {
12851285
exec_scopes: &mut ExecutionScopes,
12861286
//Data structure that can be downcasted to the structure generated by compile_hint
12871287
hint_data: &Box<dyn Any>,
1288-
//Constant values extracted from the program specification.
1289-
_constants: &HashMap<String, Felt252>,
12901288
) -> Result<(), HintError> {
12911289
let hints: &Vec<Hint> = hint_data.downcast_ref().ok_or(HintError::WrongHintData)?;
12921290
for hint in hints {

vm/src/hint_processor/hint_processor_definition.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ pub trait HintProcessorLogic {
2929
exec_scopes: &mut ExecutionScopes,
3030
//Data structure that can be downcasted to the structure generated by compile_hint
3131
hint_data: &Box<dyn Any>,
32-
//Constant values extracted from the program specification.
33-
constants: &HashMap<String, Felt252>,
3432
) -> Result<(), HintError>;
3533

3634
//Transforms hint data outputed by the VM into whichever format will be later used by execute_hint
@@ -67,10 +65,8 @@ pub trait HintProcessorLogic {
6765
exec_scopes: &mut ExecutionScopes,
6866
//Data structure that can be downcasted to the structure generated by compile_hint
6967
hint_data: &Box<dyn Any>,
70-
//Constant values extracted from the program specification.
71-
constants: &HashMap<String, Felt252>,
7268
) -> Result<HintExtension, HintError> {
73-
self.execute_hint(vm, exec_scopes, hint_data, constants)?;
69+
self.execute_hint(vm, exec_scopes, hint_data)?;
7470
Ok(HintExtension::default())
7571
}
7672
}

vm/src/tests/run_deprecated_contract_class_simplified.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ impl HintProcessorLogic for SimplifiedOsHintProcessor {
8282
_exec_scopes: &mut crate::types::exec_scope::ExecutionScopes,
8383
//Data structure that can be downcasted to the structure generated by compile_hint
8484
_hint_data: &Box<dyn core::any::Any>,
85-
//Constant values extracted from the program specification.
86-
_constants: &HashMap<String, Felt252>,
8785
) -> Result<(), crate::vm::errors::hint_errors::HintError> {
8886
// Empty impl as we are using `execute_hint_extensive` instead for this case
8987
Ok(())
@@ -95,19 +93,15 @@ impl HintProcessorLogic for SimplifiedOsHintProcessor {
9593
exec_scopes: &mut crate::types::exec_scope::ExecutionScopes,
9694
//Data structure that can be downcasted to the structure generated by compile_hint
9795
hint_data: &Box<dyn core::any::Any>,
98-
//Constant values extracted from the program specification.
99-
constants: &HashMap<String, Felt252>,
10096
) -> Result<
10197
crate::hint_processor::hint_processor_definition::HintExtension,
10298
crate::vm::errors::hint_errors::HintError,
10399
> {
104100
// First attempt to execute with builtin hint processor
105-
match self.builtin_hint_processor.execute_hint_extensive(
106-
vm,
107-
exec_scopes,
108-
hint_data,
109-
constants,
110-
) {
101+
match self
102+
.builtin_hint_processor
103+
.execute_hint_extensive(vm, exec_scopes, hint_data)
104+
{
111105
Err(HintError::UnknownHint(_)) => {}
112106
res => return res,
113107
}

vm/src/utils.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -478,38 +478,23 @@ pub mod test_utils {
478478
let constants: &HashMap<String, Felt252> = $constants;
479479
hint_data.constants = crate::stdlib::rc::Rc::new(constants.clone());
480480
let mut hint_processor = BuiltinHintProcessor::new_empty();
481-
hint_processor.execute_hint(
482-
&mut $vm,
483-
$exec_scopes,
484-
&any_box!(hint_data),
485-
&HashMap::default(),
486-
)
481+
hint_processor.execute_hint(&mut $vm, $exec_scopes, &any_box!(hint_data))
487482
}};
488483
($vm:expr, $ids_data:expr, $hint_code:expr, $exec_scopes:expr) => {{
489484
let hint_data = HintProcessorData::new_default(
490485
crate::stdlib::string::ToString::to_string($hint_code),
491486
$ids_data,
492487
);
493488
let mut hint_processor = BuiltinHintProcessor::new_empty();
494-
hint_processor.execute_hint(
495-
&mut $vm,
496-
$exec_scopes,
497-
&any_box!(hint_data),
498-
&crate::stdlib::collections::HashMap::new(),
499-
)
489+
hint_processor.execute_hint(&mut $vm, $exec_scopes, &any_box!(hint_data))
500490
}};
501491
($vm:expr, $ids_data:expr, $hint_code:expr) => {{
502492
let hint_data = HintProcessorData::new_default(
503493
crate::stdlib::string::ToString::to_string($hint_code),
504494
$ids_data,
505495
);
506496
let mut hint_processor = BuiltinHintProcessor::new_empty();
507-
hint_processor.execute_hint(
508-
&mut $vm,
509-
exec_scopes_ref!(),
510-
&any_box!(hint_data),
511-
&crate::stdlib::collections::HashMap::new(),
512-
)
497+
hint_processor.execute_hint(&mut $vm, exec_scopes_ref!(), &any_box!(hint_data))
513498
}};
514499
}
515500
pub(crate) use run_hint;

vm/src/vm/runners/cairo_runner.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ impl CairoRunner {
709709
.unwrap_or(&[]),
710710
#[cfg(feature = "extensive_hints")]
711711
&mut hint_ranges,
712+
#[cfg(feature = "test_utils")]
712713
&self.program.constants,
713714
)?;
714715

@@ -765,6 +766,7 @@ impl CairoRunner {
765766
hint_data,
766767
#[cfg(feature = "extensive_hints")]
767768
&mut hint_ranges,
769+
#[cfg(feature = "test_utils")]
768770
&self.program.constants,
769771
)?;
770772
}

vm/src/vm/vm_core.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,10 @@ impl VirtualMachine {
526526
hint_processor: &mut dyn HintProcessor,
527527
exec_scopes: &mut ExecutionScopes,
528528
hint_datas: &[Box<dyn Any>],
529-
constants: &HashMap<String, Felt252>,
530529
) -> Result<(), VirtualMachineError> {
531530
for (hint_index, hint_data) in hint_datas.iter().enumerate() {
532531
hint_processor
533-
.execute_hint(self, exec_scopes, hint_data, constants)
532+
.execute_hint(self, exec_scopes, hint_data)
534533
.map_err(|err| VirtualMachineError::Hint(Box::new((hint_index, err))))?
535534
}
536535
Ok(())
@@ -543,7 +542,6 @@ impl VirtualMachine {
543542
exec_scopes: &mut ExecutionScopes,
544543
hint_datas: &mut Vec<Box<dyn Any>>,
545544
hint_ranges: &mut HashMap<Relocatable, HintRange>,
546-
constants: &HashMap<String, Felt252>,
547545
) -> Result<(), VirtualMachineError> {
548546
// Check if there is a hint range for the current pc
549547
if let Some((s, l)) = hint_ranges.get(&self.run_context.pc) {
@@ -556,7 +554,6 @@ impl VirtualMachine {
556554
self,
557555
exec_scopes,
558556
hint_datas.get(idx).ok_or(VirtualMachineError::Unexpected)?,
559-
constants,
560557
)
561558
.map_err(|err| VirtualMachineError::Hint(Box::new((idx - s, err))))?;
562559
// Update the hint_ranges & hint_datas with the hints added by the executed hint
@@ -617,15 +614,14 @@ impl VirtualMachine {
617614
#[cfg(feature = "extensive_hints")] hint_datas: &mut Vec<Box<dyn Any>>,
618615
#[cfg(not(feature = "extensive_hints"))] hint_datas: &[Box<dyn Any>],
619616
#[cfg(feature = "extensive_hints")] hint_ranges: &mut HashMap<Relocatable, HintRange>,
620-
constants: &HashMap<String, Felt252>,
617+
#[cfg(feature = "test_utils")] constants: &HashMap<String, Felt252>,
621618
) -> Result<(), VirtualMachineError> {
622619
self.step_hint(
623620
hint_processor,
624621
exec_scopes,
625622
hint_datas,
626623
#[cfg(feature = "extensive_hints")]
627624
hint_ranges,
628-
constants,
629625
)?;
630626

631627
#[cfg(feature = "test_utils")]
@@ -3271,6 +3267,7 @@ mod tests {
32713267
&mut Vec::new(),
32723268
#[cfg(feature = "extensive_hints")]
32733269
&mut HashMap::new(),
3270+
#[cfg(feature = "test_utils")]
32743271
&HashMap::new(),
32753272
),
32763273
Ok(())
@@ -3508,6 +3505,7 @@ mod tests {
35083505
&mut Vec::new(),
35093506
#[cfg(feature = "extensive_hints")]
35103507
&mut HashMap::new(),
3508+
#[cfg(feature = "test_utils")]
35113509
&HashMap::new(),
35123510
),
35133511
Ok(())
@@ -3592,6 +3590,7 @@ mod tests {
35923590
&mut Vec::new(),
35933591
#[cfg(feature = "extensive_hints")]
35943592
&mut HashMap::new(),
3593+
#[cfg(feature = "test_utils")]
35953594
&HashMap::new()
35963595
),
35973596
Ok(())
@@ -3701,6 +3700,7 @@ mod tests {
37013700
&mut Vec::new(),
37023701
#[cfg(feature = "extensive_hints")]
37033702
&mut HashMap::new(),
3703+
#[cfg(feature = "test_utils")]
37043704
&HashMap::new()
37053705
),
37063706
Ok(())
@@ -3724,6 +3724,7 @@ mod tests {
37243724
&mut Vec::new(),
37253725
#[cfg(feature = "extensive_hints")]
37263726
&mut HashMap::new(),
3727+
#[cfg(feature = "test_utils")]
37273728
&HashMap::new()
37283729
),
37293730
Ok(())
@@ -3748,6 +3749,7 @@ mod tests {
37483749
&mut Vec::new(),
37493750
#[cfg(feature = "extensive_hints")]
37503751
&mut HashMap::new(),
3752+
#[cfg(feature = "test_utils")]
37513753
&HashMap::new()
37523754
),
37533755
Ok(())
@@ -4325,6 +4327,7 @@ mod tests {
43254327
Relocatable::from((0, 0)),
43264328
(0_usize, NonZeroUsize::new(1).unwrap())
43274329
)]),
4330+
#[cfg(feature = "test_utils")]
43284331
&HashMap::new(),
43294332
),
43304333
Ok(())
@@ -5348,6 +5351,7 @@ mod tests {
53485351
&mut Vec::new(),
53495352
#[cfg(feature = "extensive_hints")]
53505353
&mut HashMap::new(),
5354+
#[cfg(feature = "test_utils")]
53515355
&HashMap::new()
53525356
),
53535357
Ok(())
@@ -5435,6 +5439,7 @@ mod tests {
54355439
&mut Vec::new(),
54365440
#[cfg(feature = "extensive_hints")]
54375441
&mut HashMap::new(),
5442+
#[cfg(feature = "test_utils")]
54385443
&HashMap::new()
54395444
),
54405445
Ok(())

0 commit comments

Comments
 (0)