lambdaclass / cairo-vm

cairo-vm is a Rust implementation of the Cairo VM. Cairo (CPU Algebraic Intermediate Representation) is a programming language for writing provable programs, where one party can prove to another that a certain computation was executed correctly without the need for this party to re-execute the same program.
https://lambdaclass.github.io/cairo-vm
Apache License 2.0
488 stars 133 forks source link

Handle fn get_integer_from_reference when offset2 is an immediate #1689

Closed pefontana closed 3 months ago

pefontana commented 3 months ago

We saw a case where the offset2 is an immediate

HintReference { 
  offset1: Reference(FP, -4, true), 
  offset2: Immediate(Felt(FieldElement { value: UnsignedInteger { limbs: [5440000, 0, 0, 320000] } })), 
  dereference: false, 
  ap_tracking_data: None, 
  cairo_type: Some("felt") 
}

We should modify thefn get_integer_from_reference so it can handle the cases where offset2 is an immediate

star-gazer111 commented 3 months ago

Hi, can you please share some more details regarding the issue? I am up for tackling it.

shyamjayakannan commented 3 months ago

Hi @pefontana. Do you mean adding lines for offset2 similar to the ones below that handle offset1? And if so, should we return with the immediate offset2 value only if offset1 is not immediate or is there an order of precedence? https://github.com/lambdaclass/cairo-vm/blob/ec00e31ec5ed412d520957edef8b3441db82d133/vm/src/hint_processor/hint_processor_utils.rs#L40-L42

fmoletta commented 3 months ago

Hello, some more context on this issue, the pre-deserailized reference shown on the issue is cast([fp + (-4)] + (-10000), so the correct behaviour in this case would be to compute both offsets and add them