Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Relocatable instead of &MaybeRelocatable in get_range #867

Merged
merged 3 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
4 changes: 2 additions & 2 deletions src/hint_processor/builtin_hint_processor/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(elm_ptr, elm_size)
.map_err(VirtualMachineError::Memory)?;

if set_ptr > set_end_ptr {
Expand All @@ -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(set_ptr + i, elm_size)
.map_err(VirtualMachineError::Memory)?;

if set_iter == elm {
Expand Down
12 changes: 3 additions & 9 deletions src/vm/vm_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Option<Cow<MaybeRelocatable>>>, MemoryError> {
self.segments.memory.get_range(addr, size)
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions src/vm/vm_memory/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,13 @@ impl Memory {

pub fn get_range(
&self,
addr: &MaybeRelocatable,
addr: Relocatable,
size: usize,
) -> Result<Vec<Option<Cow<MaybeRelocatable>>>, 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)
Expand Down Expand Up @@ -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)
);
}
Expand All @@ -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)
);
}
Expand Down