Skip to content

Commit 41d69c7

Browse files
Use correct data type for new parameter
1 parent 00ec82c commit 41d69c7

File tree

8 files changed

+40
-186
lines changed

8 files changed

+40
-186
lines changed

hint_accountant/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![forbid(unsafe_code)]
33
use std::fs::{self, File};
44
use std::io::BufReader;
5+
use std::rc::Rc;
56

67
use cairo_vm::stdlib::collections::{HashMap, HashSet};
78
use cairo_vm::{
@@ -69,7 +70,7 @@ fn run() {
6970
&ap_tracking_data,
7071
&reference_ids,
7172
&references,
72-
&HashMap::default(),
73+
Rc::default(),
7374
)
7475
.expect("this implementation is infallible");
7576
matches!(

vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use super::{
2323
pack::*,
2424
},
2525
};
26-
use crate::serde::deserialize_program::Identifier;
2726
use crate::Felt252;
2827
use crate::{
2928
hint_processor::builtin_hint_processor::secp::secp_utils::{SECP256R1_ALPHA, SECP256R1_P},
@@ -133,7 +132,7 @@ pub struct HintProcessorData {
133132
pub code: String,
134133
pub ap_tracking: ApTracking,
135134
pub ids_data: HashMap<String, HintReference>,
136-
pub identifiers: HashMap<String, Identifier>,
135+
pub constants: Rc<HashMap<String, Felt252>>,
137136
}
138137

139138
impl HintProcessorData {
@@ -142,7 +141,7 @@ impl HintProcessorData {
142141
code,
143142
ap_tracking: ApTracking::default(),
144143
ids_data,
145-
identifiers: HashMap::new(),
144+
constants: Rc::default(),
146145
}
147146
}
148147
}
@@ -270,7 +269,7 @@ impl HintProcessorLogic for BuiltinHintProcessor {
270269
vm,
271270
&hint_data.ids_data,
272271
&hint_data.ap_tracking,
273-
&hint_data.identifiers,
272+
&hint_data.constants,
274273
),
275274
hint_code::UNSIGNED_DIV_REM => {
276275
unsigned_div_rem(vm, &hint_data.ids_data, &hint_data.ap_tracking)

vm/src/hint_processor/builtin_hint_processor/math_utils.rs

Lines changed: 19 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use crate::{
22
hint_processor::builtin_hint_processor::hint_utils::get_constant_from_var_name,
33
math_utils::signed_felt,
4-
serde::deserialize_program::Identifier,
54
stdlib::{boxed::Box, collections::HashMap, prelude::*},
6-
types::{errors::math_errors::MathError, program::Program},
5+
types::errors::math_errors::MathError,
76
};
87
use lazy_static::lazy_static;
98
use num_traits::{Signed, Zero};
@@ -385,17 +384,16 @@ pub fn split_felt(
385384
vm: &mut VirtualMachine,
386385
ids_data: &HashMap<String, HintReference>,
387386
ap_tracking: &ApTracking,
388-
identifiers: &HashMap<String, Identifier>,
387+
constants: &HashMap<String, Felt252>,
389388
) -> Result<(), HintError> {
390389
let assert = |b: bool, msg: &str| {
391390
b.then_some(())
392391
.ok_or_else(|| HintError::AssertionFailed(msg.to_string().into_boxed_str()))
393392
};
394393
let bound = pow2_const(128);
395394

396-
let constants = Program::extract_constants(identifiers).unwrap();
397-
let max_high = get_constant_from_var_name("MAX_HIGH", &constants)?;
398-
let max_low = get_constant_from_var_name("MAX_LOW", &constants)?;
395+
let max_high = get_constant_from_var_name("MAX_HIGH", constants)?;
396+
let max_low = get_constant_from_var_name("MAX_LOW", constants)?;
399397

400398
assert(
401399
max_high < &bound && max_low < &bound,
@@ -756,6 +754,7 @@ pub fn split_xx(
756754
#[cfg(test)]
757755
mod tests {
758756
use super::*;
757+
use crate::stdlib::rc::Rc;
759758
use crate::{felt_hex, felt_str};
760759
use core::ops::Neg;
761760

@@ -2067,31 +2066,10 @@ mod tests {
20672066
),
20682067
]);
20692068
let identifiers = HashMap::from([
2070-
(
2071-
"MAX_LOW".to_string(),
2072-
Identifier {
2073-
pc: None,
2074-
type_: Some("const".to_string()),
2075-
value: Some(Felt252::ZERO),
2076-
full_name: None,
2077-
members: None,
2078-
cairo_type: None,
2079-
size: None,
2080-
destination: None,
2081-
},
2082-
),
2069+
("MAX_LOW".to_string(), Felt252::ZERO),
20832070
(
20842071
"MAX_HIGH".to_string(),
2085-
Identifier {
2086-
pc: None,
2087-
type_: Some("const".to_string()),
2088-
value: Some(felt_str!("10633823966279327296825105735305134080")),
2089-
full_name: None,
2090-
members: None,
2091-
cairo_type: None,
2092-
size: None,
2093-
destination: None,
2094-
},
2072+
felt_str!("10633823966279327296825105735305134080"),
20952073
),
20962074
]);
20972075
//Execute the hint
@@ -2131,31 +2109,10 @@ mod tests {
21312109
let ids_data = ids_data!["low"];
21322110

21332111
let identifiers = HashMap::from([
2134-
(
2135-
"MAX_LOW".to_string(),
2136-
Identifier {
2137-
pc: None,
2138-
type_: Some("const".to_string()),
2139-
value: Some(Felt252::ZERO),
2140-
full_name: None,
2141-
members: None,
2142-
cairo_type: None,
2143-
size: None,
2144-
destination: None,
2145-
},
2146-
),
2112+
("MAX_LOW".to_string(), Felt252::ZERO),
21472113
(
21482114
"MAX_HIGH".to_string(),
2149-
Identifier {
2150-
pc: None,
2151-
type_: Some("const".to_string()),
2152-
value: Some(felt_str!("10633823966279327296825105735305134080")),
2153-
full_name: None,
2154-
members: None,
2155-
cairo_type: None,
2156-
size: None,
2157-
destination: None,
2158-
},
2115+
felt_str!("10633823966279327296825105735305134080"),
21592116
),
21602117
]);
21612118

@@ -2200,31 +2157,10 @@ mod tests {
22002157
]);
22012158

22022159
let identifiers = HashMap::from([
2203-
(
2204-
"MAX_LOW".to_string(),
2205-
Identifier {
2206-
pc: None,
2207-
type_: Some("const".to_string()),
2208-
value: Some(Felt252::ZERO),
2209-
full_name: None,
2210-
members: None,
2211-
cairo_type: None,
2212-
size: None,
2213-
destination: None,
2214-
},
2215-
),
2160+
("MAX_LOW".to_string(), Felt252::ZERO),
22162161
(
22172162
"MAX_HIGH".to_string(),
2218-
Identifier {
2219-
pc: None,
2220-
type_: Some("const".to_string()),
2221-
value: Some(felt_str!("10633823966279327296825105735305134080")),
2222-
full_name: None,
2223-
members: None,
2224-
cairo_type: None,
2225-
size: None,
2226-
destination: None,
2227-
},
2163+
felt_str!("10633823966279327296825105735305134080"),
22282164
),
22292165
]);
22302166

@@ -2274,31 +2210,10 @@ mod tests {
22742210
]);
22752211

22762212
let identifiers = HashMap::from([
2277-
(
2278-
"MAX_LOW".to_string(),
2279-
Identifier {
2280-
pc: None,
2281-
type_: Some("const".to_string()),
2282-
value: Some(Felt252::ZERO),
2283-
full_name: None,
2284-
members: None,
2285-
cairo_type: None,
2286-
size: None,
2287-
destination: None,
2288-
},
2289-
),
2213+
("MAX_LOW".to_string(), Felt252::ZERO),
22902214
(
22912215
"MAX_HIGH".to_string(),
2292-
Identifier {
2293-
pc: None,
2294-
type_: Some("const".to_string()),
2295-
value: Some(felt_str!("10633823966279327296825105735305134080")),
2296-
full_name: None,
2297-
members: None,
2298-
cairo_type: None,
2299-
size: None,
2300-
destination: None,
2301-
},
2216+
felt_str!("10633823966279327296825105735305134080"),
23022217
),
23032218
]);
23042219

@@ -2342,31 +2257,10 @@ mod tests {
23422257
),
23432258
]);
23442259
let identifiers = HashMap::from([
2345-
(
2346-
"MAX_LOW".to_string(),
2347-
Identifier {
2348-
pc: None,
2349-
type_: Some("const".to_string()),
2350-
value: Some(Felt252::ZERO),
2351-
full_name: None,
2352-
members: None,
2353-
cairo_type: None,
2354-
size: None,
2355-
destination: None,
2356-
},
2357-
),
2260+
("MAX_LOW".to_string(), Felt252::ZERO),
23582261
(
23592262
"MAX_HIGH".to_string(),
2360-
Identifier {
2361-
pc: None,
2362-
type_: Some("const".to_string()),
2363-
value: Some(felt_str!("10633823966279327296825105735305134080")),
2364-
full_name: None,
2365-
members: None,
2366-
cairo_type: None,
2367-
size: None,
2368-
destination: None,
2369-
},
2263+
felt_str!("10633823966279327296825105735305134080"),
23702264
),
23712265
]);
23722266
//Execute the hint
@@ -2442,32 +2336,8 @@ mod tests {
24422336
]);
24432337

24442338
let identifiers = HashMap::from([
2445-
(
2446-
"a.MAX_LOW".to_string(),
2447-
Identifier {
2448-
pc: None,
2449-
type_: Some("const".to_string()),
2450-
value: Some(Felt252::from(-1)),
2451-
full_name: None,
2452-
members: None,
2453-
cairo_type: None,
2454-
size: None,
2455-
destination: None,
2456-
},
2457-
),
2458-
(
2459-
"a.MAX_HIGH".to_string(),
2460-
Identifier {
2461-
pc: None,
2462-
type_: Some("const".to_string()),
2463-
value: Some(Felt252::from(-1)),
2464-
full_name: None,
2465-
members: None,
2466-
cairo_type: None,
2467-
size: None,
2468-
destination: None,
2469-
},
2470-
),
2339+
("a.MAX_LOW".to_string(), Felt252::from(-1)),
2340+
("a.MAX_HIGH".to_string(), Felt252::from(-1)),
24712341
]);
24722342

24732343
//Execute the hint
@@ -2511,32 +2381,8 @@ mod tests {
25112381
]);
25122382

25132383
let identifiers = HashMap::from([
2514-
(
2515-
"MAX_LOW".to_string(),
2516-
Identifier {
2517-
pc: None,
2518-
type_: Some("const".to_string()),
2519-
value: Some(Felt252::ZERO),
2520-
full_name: None,
2521-
members: None,
2522-
cairo_type: None,
2523-
size: None,
2524-
destination: None,
2525-
},
2526-
),
2527-
(
2528-
"MAX_HIGH".to_string(),
2529-
Identifier {
2530-
pc: None,
2531-
type_: Some("const".to_string()),
2532-
value: Some(Felt252::ZERO),
2533-
full_name: None,
2534-
members: None,
2535-
cairo_type: None,
2536-
size: None,
2537-
destination: None,
2538-
},
2539-
),
2384+
("MAX_LOW".to_string(), Felt252::ZERO),
2385+
("MAX_HIGH".to_string(), Felt252::ZERO),
25402386
]);
25412387

25422388
//Execute the hint

vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use super::hint_processor_utils::*;
99
use crate::any_box;
1010
use crate::hint_processor::cairo_1_hint_processor::dict_manager::DictSquashExecScope;
1111
use crate::hint_processor::hint_processor_definition::HintReference;
12-
use crate::serde::deserialize_program::Identifier;
1312
use crate::stdlib::{boxed::Box, collections::HashMap, prelude::*};
1413
use crate::types::relocatable::{MaybeRelocatable, Relocatable};
1514
use crate::vm::runners::cairo_runner::ResourceTracker;
@@ -31,6 +30,7 @@ use cairo_lang_casm::{
3130
};
3231
use core::any::Any;
3332
use core::ops::Shl;
33+
use std::rc::Rc;
3434

3535
use num_bigint::{BigInt, BigUint};
3636
use num_integer::{ExtendedGcd, Integer};
@@ -1265,7 +1265,7 @@ impl HintProcessorLogic for Cairo1HintProcessor {
12651265
//List of all references (key corresponds to element of the previous dictionary)
12661266
_references: &[HintReference],
12671267
// Identifiers stored in the hint's program.
1268-
_identifiers: &HashMap<String, Identifier>,
1268+
_constants: Rc<HashMap<String, Felt252>>,
12691269
) -> Result<Box<dyn Any>, VirtualMachineError> {
12701270
let data = hint_code.parse().ok().and_then(|x: usize| self.hints.get(&x).cloned())
12711271
.ok_or_else(|| VirtualMachineError::CompileHintFail(

vm/src/hint_processor/hint_processor_definition.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
use std::rc::Rc;
2+
13
use crate::stdlib::{any::Any, boxed::Box, collections::HashMap, prelude::*};
24

35
use crate::any_box;
6+
use crate::serde::deserialize_program::ApTracking;
47
use crate::serde::deserialize_program::OffsetValue;
58
use crate::serde::deserialize_program::Reference;
6-
use crate::serde::deserialize_program::{ApTracking, Identifier};
79
use crate::types::exec_scope::ExecutionScopes;
810
use crate::types::instruction::Register;
911
use crate::types::relocatable::Relocatable;
@@ -44,13 +46,13 @@ pub trait HintProcessorLogic {
4446
//List of all references (key corresponds to element of the previous dictionary)
4547
references: &[HintReference],
4648
// Identifiers stored in the hint's program.
47-
identifiers: &HashMap<String, Identifier>,
49+
constants: Rc<HashMap<String, Felt252>>,
4850
) -> Result<Box<dyn Any>, VirtualMachineError> {
4951
Ok(any_box!(HintProcessorData {
5052
code: hint_code.to_string(),
5153
ap_tracking: ap_tracking_data.clone(),
5254
ids_data: get_ids_data(reference_ids, references)?,
53-
identifiers: identifiers.clone(),
55+
constants: constants.clone(),
5456
}))
5557
}
5658

0 commit comments

Comments
 (0)