bug: Multiple division assignment failing
Bug Report
Cairo version:
v2.4.4
Current behavior:
When repeating the assignment let value = 1 / 1; 255 times or more in the code, the following error is encountered:
Error: #3585->#3586: Got 'Offset overflow' error while moving [3].
Expected behavior:
There should be no error or limit imposed on the number of times a division assignment can be executed in the code.
Steps to reproduce:
- Clone the repository:
git clone https://github.com/neotheprogramist/cairo-playground - Run the command:
At this stage, the program should work correctly and returnscarb cairo-run1. - Open
src/gen.cairoand uncomment line265. - Run the command again:
This time, the program fails and returns the error:scarb cairo-runError: #3585->#3586: Got 'Offset overflow' error while moving [3].
Related code:
https://github.com/neotheprogramist/cairo-playground
Other information:
The issue does not occur when performing the operation in a loop, regardless the n
let randoms1 = array![rand(), rand(), ..., rand()];
let randoms2 = array![rand(), rand(), ..., rand()];
let mut value = 0;
let mut i = 0;
loop {
if i == n {
break;
}
value = randoms1[i] / randoms2[i];
i += 1;
};
This has nothing to do with the number of divisions happening in the code - this is all about the number of variables you define in the same scope - this division imposes a large AP-change, so you are bound by the number of such changes you perform.
Do you have an actual real world example where you ran into it?
@orizi Yes here I've needed to introduce a loop to do workaround.
In any case - even in generated code - i'd recommend against creating huge blocks of code especially if it creates thousands and thousands of variables that are all usable in the same scope.
@orizi Sure, we've already parsed that and created a loop - let's treat this issue only as a notification that such restriction exists though.
Hi Ori, I'm trying to write some tests for Fq6 (cubic over quadratic) such that I have Fq6 comprised of 3 Fq2 and finally the quadratic Fq2 of 2 Fq (represented by u256).
I have these tests,
#[test]
#[available_gas(5000000)]
fn mul() {
// Having both of these causes this error:
// #24531->#24532: Got 'Offset overflow' error while moving [62].
let a = fq6(34, 645, 20, 55, 140, 105);
let b = fq6(25, 45, 11, 43, 86, 101);
let c = fq6(9, 600, 31, 12, 54, 4);
// Having two of these cause the overflow error
let ab = a * b;
let bc = b * c;
// This line line after the two above causes
// Failed to cast from 63344.
assert(ab * c == a * bc, 'incorrect mul');
}
I move ab and bc computation to separate scope without sharing any vars between them and it works with assert commented out. But of assert I need to share the previous result and I'm not able to avoid the error.
i'm assuming fq6 is huge - can you try adding core::internal::revoke_ap_tracking() as the first statement in it?
Results in same error...
can you add the same for your Mul::mul implementation?
Aah that did it!!!! ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ Thanks so much!!
glad to help - i guess we need to track this and auto add this sort of thing. as you seem to run into it more often lately.