Skip to content

Commit

Permalink
refactor: remove duplicate function get_val
Browse files Browse the repository at this point in the history
  • Loading branch information
zmalatrax committed Jul 30, 2024
1 parent 37ea729 commit 0ec47da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
16 changes: 8 additions & 8 deletions vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,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 @@ -1138,10 +1138,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
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

0 comments on commit 0ec47da

Please sign in to comment.