Skip to content

Remove duplicated get_val #2065

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

Merged
merged 4 commits into from
Apr 8, 2025
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* refactor: remove duplicated get_val function [#2065](https://github.com/lambdaclass/cairo-vm/pull/2065)

* fix: Always use a normal segment in first SegmentArena segment [#1845](https://github.com/lambdaclass/cairo-vm/pull/1845)

* chore: update cairo-lang dependencies to 2.12.0-dev.0 #[2040](https://github.com/lambdaclass/cairo-vm/pull/2040)
Expand Down
20 changes: 10 additions & 10 deletions vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,10 @@ impl Cairo1HintProcessor {
remainder1: &CellRef,
) -> Result<(), HintError> {
let pow_2_128 = BigUint::from(u128::MAX) + 1u32;
let dividend0 = get_val(vm, dividend0)?.to_biguint();
let dividend1 = get_val(vm, dividend1)?.to_biguint();
let divisor0 = get_val(vm, divisor0)?.to_biguint();
let divisor1 = get_val(vm, divisor1)?.to_biguint();
let dividend0 = res_operand_get_val(vm, dividend0)?.to_biguint();
let dividend1 = res_operand_get_val(vm, dividend1)?.to_biguint();
let divisor0 = res_operand_get_val(vm, divisor0)?.to_biguint();
let divisor1 = res_operand_get_val(vm, divisor1)?.to_biguint();
let dividend: BigUint = dividend0 + dividend1.shl(128);
let divisor = divisor0 + divisor1.shl(128);
let (quotient, remainder) = dividend.div_rem(&divisor);
Expand Down Expand Up @@ -1155,10 +1155,10 @@ impl Cairo1HintProcessor {
t_or_k1: &CellRef,
) -> Result<(), HintError> {
let pow_2_128 = BigInt::from(u128::MAX) + 1u32;
let b0 = get_val(vm, b0)?.to_bigint();
let b1 = get_val(vm, b1)?.to_bigint();
let n0 = get_val(vm, n0)?.to_bigint();
let n1 = get_val(vm, n1)?.to_bigint();
let b0 = res_operand_get_val(vm, b0)?.to_bigint();
let b1 = res_operand_get_val(vm, b1)?.to_bigint();
let n0 = res_operand_get_val(vm, n0)?.to_bigint();
let n1 = res_operand_get_val(vm, n1)?.to_bigint();
let b: BigInt = b0.clone() + b1.clone().shl(128);
let n: BigInt = n0 + n1.shl(128);
let ExtendedGcd {
Expand Down Expand Up @@ -1217,14 +1217,14 @@ impl Cairo1HintProcessor {
n_mul_mods: &ResOperand,
mul_mod_builtin_ptr: &ResOperand,
) -> Result<(), HintError> {
let n_add_mods = get_val(vm, n_add_mods)?;
let n_add_mods = res_operand_get_val(vm, n_add_mods)?;
let n_add_mods =
n_add_mods
.to_usize()
.ok_or(HintError::Math(MathError::Felt252ToUsizeConversion(
Box::from(n_add_mods),
)))?;
let n_mul_mods = get_val(vm, n_mul_mods)?;
let n_mul_mods = res_operand_get_val(vm, n_mul_mods)?;
let n_mul_mods =
n_mul_mods
.to_usize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,6 @@ pub(crate) fn get_mayberelocatable(
})
}

/// Fetches the value of `res_operand` from the vm.
pub(crate) fn get_val(
vm: &VirtualMachine,
res_operand: &ResOperand,
) -> Result<Felt252, VirtualMachineError> {
match res_operand {
ResOperand::Deref(cell) => get_cell_val(vm, cell),
ResOperand::DoubleDeref(cell, offset) => {
get_double_deref_val(vm, cell, &Felt252::from(*offset as i32))
}
ResOperand::Immediate(x) => Ok(Felt252::from(&x.value)),
ResOperand::BinOp(op) => {
let a = get_cell_val(vm, &op.a)?;
let b = match &op.b {
DerefOrImmediate::Deref(cell) => get_cell_val(vm, cell)?,
DerefOrImmediate::Immediate(x) => Felt252::from(&x.value),
};
match op.op {
Operation::Add => Ok(a + b),
Operation::Mul => Ok(a * b),
}
}
}
}

pub(crate) fn cell_ref_to_relocatable(
cell_ref: &CellRef,
vm: &VirtualMachine,
Expand Down
Loading