zkFold / zkfold-base

ZkFold's Base library
https://zkfold.io
MIT License
14 stars 6 forks source link

Linear optimization #272

Open TurtlePU opened 1 week ago

TurtlePU commented 1 week ago

In Plonk, we can express simple linear constraints like $y = k x + b$ while the complete form of a Plonk constraint is

$$a x_1 x_2 + b x_1 + c x_2 + d x_3 + e = 0.$$

Note, however, that linear constraints can be inlined: take $x_1$ in the above to equal $k x' + s$. Then

$$a (k x' + s) x_2 + b (k x' + s) + c x_2 + d x_3 + e = (a k) x' x_2 + (b k) x' + (a s + c) x_2 + d x_3 + (b s + e) = 0,$$

which is also a Plonk constraint. Same is right for $x_2$ and $x_3$.

This way, if $x_1$ is not mentioned in the output of a circuit, it can be removed from the circuit completely. And after #270, we're going to have a lot of these.

vlasin commented 1 week ago

Yes, when I was proposing to do constant optimization, I meant exactly this. Note that it adds an additional assumption about the class of constraints we are using. However, I think it is reasonable to assume that it will always be the case.

TurtlePU commented 1 week ago

Following my suggestion in here, we can run this optimization pass only for constraint systems that support it