From ccb3ceb2e288a1ff48aed41167fe56aba50612f1 Mon Sep 17 00:00:00 2001 From: Federica Date: Wed, 1 Mar 2023 14:25:57 -0300 Subject: [PATCH 1/3] Use Relocatable in get_range --- src/vm/vm_core.rs | 12 +++--------- src/vm/vm_memory/memory.rs | 8 ++++---- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/vm/vm_core.rs b/src/vm/vm_core.rs index 2f3da0c991..ded48bb2b0 100644 --- a/src/vm/vm_core.rs +++ b/src/vm/vm_core.rs @@ -856,7 +856,7 @@ impl VirtualMachine { ///Gets n elements from memory starting from addr (n being size) pub fn get_range( &self, - addr: &MaybeRelocatable, + addr: Relocatable, size: usize, ) -> Result>>, MemoryError> { self.segments.memory.get_range(addr, size) @@ -3750,10 +3750,7 @@ mod tests { Some(Cow::Borrowed(&value2)), Some(Cow::Borrowed(&value3)), ]; - assert_eq!( - vm.get_range(&MaybeRelocatable::from((1, 0)), 3), - Ok(expected_vec) - ); + assert_eq!(vm.get_range(Relocatable::from((1, 0)), 3), Ok(expected_vec)); } #[test] @@ -3771,10 +3768,7 @@ mod tests { None, Some(Cow::Borrowed(&value3)), ]; - assert_eq!( - vm.get_range(&MaybeRelocatable::from((1, 0)), 4), - Ok(expected_vec) - ); + assert_eq!(vm.get_range(Relocatable::from((1, 0)), 4), Ok(expected_vec)); } #[test] diff --git a/src/vm/vm_memory/memory.rs b/src/vm/vm_memory/memory.rs index 2b47909f45..31fe92cdea 100644 --- a/src/vm/vm_memory/memory.rs +++ b/src/vm/vm_memory/memory.rs @@ -245,13 +245,13 @@ impl Memory { pub fn get_range( &self, - addr: &MaybeRelocatable, + addr: Relocatable, size: usize, ) -> Result>>, MemoryError> { let mut values = Vec::new(); for i in 0..size { - values.push(self.get(&addr.add_usize(i))); + values.push(self.get(&(addr + i))); } Ok(values) @@ -872,7 +872,7 @@ mod memory_tests { Some(Cow::Borrowed(&value3)), ]; assert_eq!( - memory.get_range(&MaybeRelocatable::from((1, 0)), 3), + memory.get_range(Relocatable::from((1, 0)), 3), Ok(expected_vec) ); } @@ -892,7 +892,7 @@ mod memory_tests { Some(Cow::Borrowed(&value3)), ]; assert_eq!( - memory.get_range(&MaybeRelocatable::from((1, 0)), 4), + memory.get_range(Relocatable::from((1, 0)), 4), Ok(expected_vec) ); } From 3ebf755feacebabbf55de559bd949fd242419919 Mon Sep 17 00:00:00 2001 From: Federica Date: Wed, 1 Mar 2023 15:45:21 -0300 Subject: [PATCH 2/3] Fix --- .../builtin_hint_processor/cairo_keccak/keccak_hints.rs | 2 +- src/hint_processor/builtin_hint_processor/set.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs b/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs index c1dcd3ea9d..983ddcc339 100644 --- a/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs +++ b/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs @@ -145,7 +145,7 @@ pub fn block_permutation( let keccak_state_size_felts = keccak_state_size_felts.to_usize().unwrap(); let values = vm .get_range( - &MaybeRelocatable::RelocatableValue(keccak_ptr.sub_usize(keccak_state_size_felts)?), + keccak_ptr.sub_usize(keccak_state_size_felts)?, keccak_state_size_felts, ) .map_err(HintError::Memory)?; diff --git a/src/hint_processor/builtin_hint_processor/set.rs b/src/hint_processor/builtin_hint_processor/set.rs index a7d249fead..7c31d8f332 100644 --- a/src/hint_processor/builtin_hint_processor/set.rs +++ b/src/hint_processor/builtin_hint_processor/set.rs @@ -6,7 +6,7 @@ use crate::{ hint_processor_definition::HintReference, }, serde::deserialize_program::ApTracking, - types::relocatable::MaybeRelocatable, + types::relocatable::{MaybeRelocatable, Relocatable}, vm::{ errors::{hint_errors::HintError, vm_errors::VirtualMachineError}, vm_core::VirtualMachine, @@ -32,7 +32,7 @@ pub fn set_add( Err(VirtualMachineError::ValueNotPositive(Felt::new(elm_size)))?; } let elm = vm - .get_range(&MaybeRelocatable::from(elm_ptr), elm_size) + .get_range(Relocatable::from(elm_ptr), elm_size) .map_err(VirtualMachineError::Memory)?; if set_ptr > set_end_ptr { @@ -46,7 +46,7 @@ pub fn set_add( for i in (0..range_limit).step_by(elm_size) { let set_iter = vm - .get_range(&MaybeRelocatable::from(set_ptr + i), elm_size) + .get_range(Relocatable::from(set_ptr + i), elm_size) .map_err(VirtualMachineError::Memory)?; if set_iter == elm { From 4845ab736d810e2ce55760a5f26c0c41a0ed2d77 Mon Sep 17 00:00:00 2001 From: Federica Date: Wed, 1 Mar 2023 15:46:30 -0300 Subject: [PATCH 3/3] Clippy --- src/hint_processor/builtin_hint_processor/set.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hint_processor/builtin_hint_processor/set.rs b/src/hint_processor/builtin_hint_processor/set.rs index 7c31d8f332..bc48466936 100644 --- a/src/hint_processor/builtin_hint_processor/set.rs +++ b/src/hint_processor/builtin_hint_processor/set.rs @@ -6,7 +6,7 @@ use crate::{ hint_processor_definition::HintReference, }, serde::deserialize_program::ApTracking, - types::relocatable::{MaybeRelocatable, Relocatable}, + types::relocatable::MaybeRelocatable, vm::{ errors::{hint_errors::HintError, vm_errors::VirtualMachineError}, vm_core::VirtualMachine, @@ -32,7 +32,7 @@ pub fn set_add( Err(VirtualMachineError::ValueNotPositive(Felt::new(elm_size)))?; } let elm = vm - .get_range(Relocatable::from(elm_ptr), elm_size) + .get_range(elm_ptr, elm_size) .map_err(VirtualMachineError::Memory)?; if set_ptr > set_end_ptr { @@ -46,7 +46,7 @@ pub fn set_add( for i in (0..range_limit).step_by(elm_size) { let set_iter = vm - .get_range(Relocatable::from(set_ptr + i), elm_size) + .get_range(set_ptr + i, elm_size) .map_err(VirtualMachineError::Memory)?; if set_iter == elm {