Skip to content

Commit 66e952b

Browse files
committed
Dereference pointer and get integer
1 parent 58f831b commit 66e952b

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

crates/dry_hint_processor/src/output.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::HashMap;
2+
use std::borrow::Cow;
23

34
use cairo_vm::{
45
hint_processor::{
@@ -8,11 +9,11 @@ use cairo_vm::{
89
},
910
hint_processor_utils::felt_to_usize,
1011
},
11-
types::{
12-
exec_scope::ExecutionScopes,
13-
relocatable::MaybeRelocatable,
12+
types::{exec_scope::ExecutionScopes, relocatable::MaybeRelocatable},
13+
vm::{
14+
errors::{hint_errors::HintError, memory_errors::MemoryError},
15+
vm_core::VirtualMachine,
1416
},
15-
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
1617
Felt252,
1718
};
1819
use hints::vars;
@@ -59,12 +60,22 @@ impl CustomHintProcessor {
5960
.into_iter()
6061
.map(|value| {
6162
match value {
62-
MaybeRelocatable::Int(felt) => Ok(felt),
63+
MaybeRelocatable::Int(felt) => {
64+
println!("hit reloacatable int: {}", felt);
65+
Ok(felt)
66+
},
6367
MaybeRelocatable::RelocatableValue(relocatable) => {
64-
let segment_index = Felt252::from(relocatable.segment_index);
65-
let offset = Felt252::from(relocatable.offset);
66-
let two_to_64 = Felt252::from(2u64).pow(64u128);
67-
Ok(segment_index * two_to_64 + offset)
68+
println!(
69+
"hit relocatable, dereferencing: segment_index={}, offset={}",
70+
relocatable.segment_index, relocatable.offset
71+
);
72+
73+
// Deref pointer and expect an integer at that address
74+
let inner: Cow<'_, Felt252> = vm
75+
.get_integer(relocatable)
76+
.map_err(HintError::Memory)?;
77+
78+
Ok(inner.into_owned())
6879
}
6980
}
7081
})
@@ -81,4 +92,4 @@ impl CustomHintProcessor {
8192

8293
Ok(())
8394
}
84-
}
95+
}

0 commit comments

Comments
 (0)