scipr-lab / libsnark

C++ library for zkSNARKs
Other
1.82k stars 582 forks source link

A limitation of libsnark may cause "Segmentation fault" #170

Open youwenbusi opened 4 years ago

youwenbusi commented 4 years ago

When I used libsnark to build a small gadget and writed a test file for it, I encountered a problem of "Segmentation fault". I used gdb to trace that fault and found that it was caused by the function : r1cs_constraint_system::swap_AB_if_beneficial(). More specifically, it caused by the statement :libff::bit_vector touched_by_A(this->num_variables() + 1, false), touched_by_B(this->num_variables() + 1, false). The statement applies two arrays with the length of num_variables in the gatget. Thus if we design a gadget with a large numble of variables, this statement will cause a "Segmentation fault". I have tested it in my machine(Linux ubuntu 4.4.0-21-generic ,Total Memory 4 GB) that if there are more than 300000 variables, it will run into that problrm. If this function is necessary for making proof, it should be writed with the function "malloc()" or others to allocated memory dynamically to support more complicated gadget.