File tree 4 files changed +28
-7
lines changed
4 files changed +28
-7
lines changed Original file line number Diff line number Diff line change 2
2
3
3
#### Upcoming Changes
4
4
5
+ * feat: implement VirtualMachine::is_accessed [ #2024 ] ( https://github.com/lambdaclass/cairo-vm/pull/2024 )
6
+
5
7
* fix: Keep None values in memory segments for the prover input info [ #2021 ] ( https://github.com/lambdaclass/cairo-vm/pull/2021 )
6
8
7
9
* refactor: Clap attribute macros from #[ clap(...)] to #[ arg(...)] and #[ command(...)] in v4.x [ #2003 ] (https://github.com/lambdaclass/cairo-vm/pull/2003 )
Original file line number Diff line number Diff line change @@ -971,6 +971,10 @@ impl VirtualMachine {
971
971
self . segments . memory . mem_eq ( lhs, rhs, len)
972
972
}
973
973
974
+ pub fn is_accessed ( & self , addr : & Relocatable ) -> Result < bool , MemoryError > {
975
+ self . segments . is_accessed ( addr)
976
+ }
977
+
974
978
///Gets `n_ret` return values from memory
975
979
pub fn get_return_values ( & self , n_ret : usize ) -> Result < Vec < MaybeRelocatable > , MemoryError > {
976
980
let addr = ( self . run_context . get_ap ( ) - n_ret)
Original file line number Diff line number Diff line change @@ -244,13 +244,7 @@ impl Memory {
244
244
{
245
245
let relocatable: Relocatable = key. try_into ( ) . ok ( ) ?;
246
246
247
- let data = if relocatable. segment_index . is_negative ( ) {
248
- & self . temp_data
249
- } else {
250
- & self . data
251
- } ;
252
- let ( i, j) = from_relocatable_to_indexes ( relocatable) ;
253
- let value = data. get ( i) ?. get ( j) ?. get_value ( ) ?;
247
+ let value = self . get_cell ( relocatable) ?. get_value ( ) ?;
254
248
Some ( Cow :: Owned ( self . relocate_value ( & value) . ok ( ) ?. into_owned ( ) ) )
255
249
}
256
250
@@ -648,6 +642,23 @@ impl Memory {
648
642
Ok ( values)
649
643
}
650
644
645
+ fn get_cell ( & self , addr : Relocatable ) -> Option < & MemoryCell > {
646
+ let ( i, j) = from_relocatable_to_indexes ( addr) ;
647
+ let data = if addr. segment_index < 0 {
648
+ & self . temp_data
649
+ } else {
650
+ & self . data
651
+ } ;
652
+ data. get ( i) ?. get ( j)
653
+ }
654
+
655
+ pub fn is_accessed ( & self , addr : & Relocatable ) -> Result < bool , MemoryError > {
656
+ Ok ( self
657
+ . get_cell ( * addr)
658
+ . ok_or ( MemoryError :: UnknownMemoryCell ( Box :: new ( * addr) ) ) ?
659
+ . is_accessed ( ) )
660
+ }
661
+
651
662
pub fn mark_as_accessed ( & mut self , addr : Relocatable ) {
652
663
let ( i, j) = from_relocatable_to_indexes ( addr) ;
653
664
let data = if addr. segment_index < 0 {
Original file line number Diff line number Diff line change @@ -200,6 +200,10 @@ impl MemorySegmentManager {
200
200
}
201
201
}
202
202
203
+ pub fn is_accessed ( & self , addr : & Relocatable ) -> Result < bool , MemoryError > {
204
+ self . memory . is_accessed ( addr)
205
+ }
206
+
203
207
/// Counts the memory holes (aka unaccessed memory cells) in memory
204
208
/// # Parameters
205
209
/// - `builtin_segment_indexes`: Set representing the segments indexes of the builtins initialized in the VM, except for the output builtin.
You can’t perform that action at this time.
0 commit comments