Skip to content

Commit 186ae4d

Browse files
Pass identifiers instead of only constants to hint data
1 parent 66d1ed2 commit 186ae4d

File tree

12 files changed

+304
-174
lines changed

12 files changed

+304
-174
lines changed

vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use super::{
2323
pack::*,
2424
},
2525
};
26+
use crate::serde::deserialize_program::Identifier;
2627
use crate::Felt252;
2728
use crate::{
2829
hint_processor::builtin_hint_processor::secp::secp_utils::{SECP256R1_ALPHA, SECP256R1_P},
@@ -132,7 +133,7 @@ pub struct HintProcessorData {
132133
pub code: String,
133134
pub ap_tracking: ApTracking,
134135
pub ids_data: HashMap<String, HintReference>,
135-
pub constants: Rc<HashMap<String, Felt252>>,
136+
pub identifiers: Rc<HashMap<String, Identifier>>,
136137
pub accessible_scopes: Vec<String>,
137138
}
138139

@@ -142,7 +143,7 @@ impl HintProcessorData {
142143
code,
143144
ap_tracking: ApTracking::default(),
144145
ids_data,
145-
constants: Default::default(),
146+
identifiers: Default::default(),
146147
accessible_scopes: Default::default(),
147148
}
148149
}
@@ -195,7 +196,20 @@ impl HintProcessorLogic for BuiltinHintProcessor {
195196
let hint_data = hint_data
196197
.downcast_ref::<HintProcessorData>()
197198
.ok_or(HintError::WrongHintData)?;
198-
let constants = hint_data.constants.as_ref();
199+
200+
let identifiers = hint_data.identifiers.as_ref();
201+
let owned_constants = identifiers
202+
.clone()
203+
.into_iter()
204+
.filter_map(|(key, identifier)| {
205+
if identifier.type_? == "const" {
206+
Some((key, identifier.value?))
207+
} else {
208+
None
209+
}
210+
})
211+
.collect();
212+
let constants = &owned_constants;
199213

200214
if let Some(hint_func) = self.extra_hints.get(&hint_data.code) {
201215
return hint_func.0(

vm/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ pub fn u64_array_to_mayberelocatable_vec(array: &[u64]) -> Vec<MaybeRelocatable>
366366
mod tests {
367367
use super::*;
368368
use crate::stdlib::string::ToString;
369-
370369
use crate::{
371370
any_box,
372371
hint_processor::{
@@ -448,16 +447,19 @@ mod tests {
448447

449448
run_context!(vm, 0, 1, 1);
450449
let ids_data = ids_data!["n_bytes"];
450+
let identifiers = HashMap::from([(
451+
"starkware.cairo.common.cairo_keccak.keccak.KECCAK_FULL_RATE_IN_BYTES".to_string(),
452+
const_identifier(136),
453+
)]);
454+
let accessible_scopes = vec!["starkware.cairo.common.cairo_keccak.keccak".to_string()];
451455
assert_matches!(
452456
run_hint!(
453457
vm,
454458
ids_data,
455459
hint_code,
456460
exec_scopes_ref!(),
457-
&[(KECCAK_FULL_RATE_IN_BYTES_CAIRO_KECCAK, Felt252::from(136))]
458-
.into_iter()
459-
.map(|(k, v)| (k.to_string(), v))
460-
.collect()
461+
identifiers,
462+
accessible_scopes
461463
),
462464
Ok(())
463465
);
@@ -477,16 +479,19 @@ mod tests {
477479
run_context!(vm, 0, 1, 1);
478480

479481
let ids_data = ids_data!["n_bytes"];
482+
let identifiers = HashMap::from([(
483+
"starkware.cairo.common.cairo_keccak.keccak.KECCAK_FULL_RATE_IN_BYTES".to_string(),
484+
const_identifier(136),
485+
)]);
486+
let accessible_scopes = vec!["starkware.cairo.common.cairo_keccak.keccak".to_string()];
480487
assert_matches!(
481488
run_hint!(
482489
vm,
483490
ids_data,
484491
hint_code,
485492
exec_scopes_ref!(),
486-
&[(KECCAK_FULL_RATE_IN_BYTES_CAIRO_KECCAK, Felt252::from(136))]
487-
.into_iter()
488-
.map(|(k, v)| (k.to_string(), v))
489-
.collect()
493+
identifiers,
494+
accessible_scopes
490495
),
491496
Ok(())
492497
);
@@ -505,16 +510,19 @@ mod tests {
505510
run_context!(vm, 0, 1, 1);
506511

507512
let ids_data = ids_data!["n_bytes"];
513+
let identifiers = HashMap::from([(
514+
"starkware.cairo.common.cairo_keccak.keccak.KECCAK_FULL_RATE_IN_BYTES".to_string(),
515+
const_identifier(136),
516+
)]);
517+
let accessible_scopes = vec!["starkware.cairo.common.cairo_keccak.keccak".to_string()];
508518
assert_matches!(
509519
run_hint!(
510520
vm,
511521
ids_data,
512522
hint_code,
513523
exec_scopes_ref!(),
514-
&[(KECCAK_FULL_RATE_IN_BYTES_CAIRO_KECCAK, Felt252::from(136))]
515-
.into_iter()
516-
.map(|(k, v)| (k.to_string(), v))
517-
.collect()
524+
identifiers,
525+
accessible_scopes
518526
),
519527
Ok(())
520528
);

vm/src/hint_processor/builtin_hint_processor/keccak_utils.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,21 @@ mod tests {
357357
vm.segments = segments![((1, 2), 17)];
358358
vm.set_fp(3);
359359
let ids_data = ids_data!["n_words_to_copy", "n_bytes_left", "n_bytes"];
360+
361+
let identifiers = HashMap::from([(
362+
"starkware.cairo.common.builtin_keccak.keccak.BYTES_IN_WORD".to_string(),
363+
const_identifier(8),
364+
)]);
365+
let accessible_scopes = vec!["starkware.cairo.common.builtin_keccak.keccak".to_string()];
366+
360367
assert_matches!(
361368
run_hint!(
362369
vm,
363370
ids_data,
364371
hint_code::SPLIT_N_BYTES,
365372
exec_scopes_ref!(),
366-
&HashMap::from([(String::from(BYTES_IN_WORD), Felt252::from(8))])
373+
identifiers,
374+
accessible_scopes
367375
),
368376
Ok(())
369377
);
@@ -376,13 +384,19 @@ mod tests {
376384
vm.segments = segments![((1, 0), 72057594037927938)];
377385
vm.set_fp(4);
378386
let ids_data = ids_data!["output1", "output1_low", "output1_mid", "output1_high"];
387+
let identifiers = HashMap::from([(
388+
"starkware.cairo.common.builtin_keccak.keccak.BYTES_IN_WORD".to_string(),
389+
const_identifier(8),
390+
)]);
391+
let accessible_scopes = vec!["starkware.cairo.common.builtin_keccak.keccak".to_string()];
379392
assert_matches!(
380393
run_hint!(
381394
vm,
382395
ids_data,
383396
hint_code::SPLIT_OUTPUT_MID_LOW_HIGH,
384397
exec_scopes_ref!(),
385-
&HashMap::from([(String::from(BYTES_IN_WORD), Felt252::from(8))])
398+
identifiers,
399+
accessible_scopes
386400
),
387401
Ok(())
388402
);

0 commit comments

Comments
 (0)