zkevm-circuits
zkevm-circuits copied to clipboard
Reduce halo2 calls to Circuit::synthesize
After a debugging session I noticed that the layouter.assign_region method of a Circuit is being called 6 times. My guess is the following:
- One iteration per phase (we have 3 phases implemented) by a Circuit::synthesize call
- On each phase, the layouter may do multiple phases, by calling layouter.assign_region each time.
While debugging I was observing 2 assign_region calls per each phase, but the circuit was using the SimpleFloorPlanner, which is supposed to do only 1 pass, so maybe my guess is wrong. Nevertheless the layouter.assign_region methods were called 6 times, which seems a lot.
I wonder if we could find a way to reduce this, specially considering that our circuits are single region, and that we can easily predict the number of rows they'll take before calling assign_region.
@hero78119 found the exact place where the SimpleFloorPlanner calls the assignment twice: https://github.com/privacy-scaling-explorations/halo2/blob/818febb61da16c76e43469f626e87d01e98db309/halo2_proofs/src/circuit/floor_planner/single_pass.rs#L93-L114
@ed255 You can check the work that we did at Scroll. We're currently working on splitting the original large region into hundreds of "sub"-regions and then synthesize them in parallel. https://github.com/scroll-tech/zkevm-circuits/issues/552
For example, we are able to reduce the synthesis time of state circuit of degree 20 from 170s to about 7s.