cairo-vm icon indicating copy to clipboard operation
cairo-vm copied to clipboard

Inconsistent offset calculation

Open petscheit opened this issue 8 months ago • 0 comments

Describe the bug Consider the following example:

func hash_full_transcript_and_get_Z_4_LIMBS{poseidon_ptr: PoseidonBuiltin*}(
    limbs_ptr: felt*, n: felt
) -> (_s0: felt, _s1: felt, _s2: felt) {
    alloc_locals;
    local BASE = 2 ** 96;

    // n = 768 & N_LIMBS = 4
    local offset = n * N_LIMBS;
    let elements_end_correct = &limbs_ptr[offset];
    let elements_end = &limbs_ptr[n * N_LIMBS];


//...more code here
}

Both references should point to the same relocatable offset. However, when I print these relocatables I get different values:

elements_end: Relocatable { segment_index: 6, offset: 31300 }
elements_end_correct: Relocatable { segment_index: 6, offset: 33604 }

The starting offset in this case is 30532

so: 30532 + (4 * 768) = 33604

and 30532 + 768 = 31300

For some reason the * 4 is not applied

To Reproduce Hard to reproduce, as this is running deep in the extension field circuit in garaga

Expected behavior A clear and concise description of what you expected to happen.

What version/commit are you on? Upgraded to the latest version: v2.0.0

Additional context this seems related to #1918

petscheit avatar Mar 06 '25 10:03 petscheit