Skip to content
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

bug: Multiple division assignment failing #4836

Open
neotheprogramist opened this issue Jan 18, 2024 · 10 comments
Open

bug: Multiple division assignment failing #4836

neotheprogramist opened this issue Jan 18, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@neotheprogramist
Copy link
Contributor

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:

  1. Clone the repository:
    git clone https://github.com/neotheprogramist/cairo-playground
    
  2. Run the command:
    scarb cairo-run
    
    At this stage, the program should work correctly and return 1.
  3. Open src/gen.cairo and uncomment line 265.
  4. Run the command again:
    scarb cairo-run
    
    This time, the program fails and returns the error:
    Error: #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;
};
@neotheprogramist neotheprogramist added the bug Something isn't working label Jan 18, 2024
@orizi
Copy link
Collaborator

orizi commented Jan 18, 2024

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?

@neotheprogramist
Copy link
Contributor Author

@orizi
Yes here
I've needed to introduce a loop to do workaround.

@orizi
Copy link
Collaborator

orizi commented Jan 18, 2024

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.

@neotheprogramist
Copy link
Contributor Author

@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.

@shramee
Copy link
Contributor

shramee commented Jan 22, 2024

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.

@orizi
Copy link
Collaborator

orizi commented Jan 22, 2024

i'm assuming fq6 is huge - can you try adding core::internal::revoke_ap_tracking() as the first statement in it?

@shramee
Copy link
Contributor

shramee commented Jan 22, 2024

Results in same error...

@orizi
Copy link
Collaborator

orizi commented Jan 22, 2024

can you add the same for your Mul::mul implementation?

@shramee
Copy link
Contributor

shramee commented Jan 22, 2024

Aah that did it!!!! ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️
Thanks so much!!

image

@orizi
Copy link
Collaborator

orizi commented Jan 22, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants