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

Crash on long loops #22

Open
akokoshn opened this issue Sep 6, 2023 · 2 comments
Open

Crash on long loops #22

akokoshn opened this issue Sep 6, 2023 · 2 comments
Assignees

Comments

@akokoshn
Copy link

akokoshn commented Sep 6, 2023

profiling_assignment_table call crash in case of huge assigment argument.

Issue observe on loop size ~ 200000 iteration.

Loop cpp example:

#include <cstddef>
[[circuit]] int func(const int num) {
    int x = 1;
    for (int i = 0; i < num; i++) {
        x++;
    }
    return x;
}

IR execution log:

_Z4funci:
 	%1:
 		icmp (0 %0 ) -> %2
 		br
 	%5:
 		phi (%9 0 ) -> %6
 		phi (%8 1 ) -> %7
 		add (%7 1 ) -> %8
 		add (%6 1 ) -> %9 // increment loop iterator, add var "var_2_35_witness" = 1 
 		icmp (%9 %0 ) -> %10
 		br
 		    Add new var: var_2_35_witness = 1 - incremented loop terator
 		phi (%9 0 ) -> %6
 		phi (%8 1 ) -> %7
 		add (%7 1 ) -> %8
 		add (%6 1 ) -> %9 // increment loop iterator, add var "var_2_71_witness" = 2
 		icmp (%9 %0 ) -> %10
 		br
 		    Add new var: var_2_71_witness = 2
 	%3:
 		phi (1 %8 ) -> %4
 		ret
 		    res = 3
 		    stack: [ var_0_0_public_input var_0_2_public_input var_0_33_witness var_0_3_public_input var_2_70_witness var_2_35_witness var_2_34_witness var_2_70_witness var_2_71_witness var_0_105_witness ]

@akokoshn
Copy link
Author

akokoshn commented Sep 6, 2023

The reason is passing assigment as value.
Solution - passing as reference.
change: #23 merged

@akokoshn akokoshn moved this from New to In progress in zkLLVM + Proof Market Toolchain Sep 6, 2023
@akokoshn
Copy link
Author

akokoshn commented Sep 9, 2023

On loops > 1000000 iterations crash hapeens when try std::vector::resize() (zk::snark::basic_padding())
The problem is - resize() doesn't throw std::bad_alloc.

@akokoshn akokoshn moved this from In progress to New in zkLLVM + Proof Market Toolchain Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants