NilFoundation / zkLLVM

Zero-Knowledge Proof Systems Circuit Compiler
https://docs.nil.foundation/zkllvm
278 stars 48 forks source link

Special assigner mode for circuit size estimation #498

Closed nkaskov closed 6 months ago

nkaskov commented 7 months ago

The users want to have a way of estimating the proving time without actually running the prover. The circuit size calculation seems to be the best way.

Sometimes (as in the case of bls12-381), we do not even have the prover, so the circuit size is actually the only way to estimate how big the circuit is.

We need to add a special assigner mode in which different stats of the result circuit will be printed.

Circuit stats to count:

If you understand that we can provide any additional params to estimate the quality of the circuit and proving time - add them to the list above.

As I see it, it makes sense to calculate some (or maybe all) of the circuit stats without actually building the circuit. For example, we can use component's rows_amount instead of actually building the assignment table.

akokoshn commented 7 months ago

Metrics: rows, gates, components, branches.

Short summary:

<component0>: <num used> <rows used> <num gated>
....
Total rows:
Total gates:
Num branches:

Detail statistic (per each call of components):

<component0>: <num used> <rows used> <num gated>
<component0>: <num used> <rows used> <num gated>
<component1>: <num used> <rows used> <num gated>
<component0>: <num used> <rows used> <num gated>
....
akokoshn commented 7 months ago

Example of getting num rows per component:

const auto p = detail::PolicyManager::get_parameters(detail::ManifestReader<ComponentType, ArithmetizationParams>::get_witness(0, args...));
p.witness
p.rows
p.gates

Need modify

struct FlexibleParameters

and

DefaultPolicy::get_parameters(...)