Finding bugs in large ZK circuits with CIVER
The COSTA research group has started a new collaboration with the ZisK development team to apply CIVER to verify the determinism of the recursion/aggregation circuits of ZisK.
CIVER has already been able to find vulnerabilities in several projects in production (see [1] for details).
The size of these ZisK circuits ranges from one million to over five million constraints, so verifying them and finding bugs is very challenging. Other tools have shown to be unable to handle circuits of this size at once.
Using CIVER we have detected two subtle bugs which compromise the soundness of ZisK. Thanks to using CIVER these bugs have been detected in the development process and will not reach the production phase. CIVER has been able to spot the problematic components and provide a buggy instance.
Verifying circuits with CIVER
CIVER [1] is a tool that can verify weak safety [2], also known as determinism, which means there is a single valid output for any given inputs. When this property is not satisfied it means that the circuit is underconstrained, as all non expected values that are valid for the outputs should be restricted. CIVER can verify weak safety of circuits defined using the DSL circom, but can also verify circuits given as a constraints system (in R1CS format, PLONK, ACIR, …). CIVER modularly analyses the circuit to increase scalability and to find the problematic part of the circuit.
When the circuit is provided in the circom language, it uses the structure of the circuit definition to modularly check all the components. CIVER can also check Pre/Postconditions defined on circom programs, as well as verify circom's tag specifications. CIVER has been integrated in the circom compiler and can handle full circom programs.
When CIVER is applied to non-circom circuits powerful clustering techniques are applied in order to break the circuit into smaller components that are then handled modularly.
Details about the bugs
The first bug was detected in a circom template called Num2Ternary(n) that transforms an input number to its ternary form (i.e. in base 3) using n values in {0..2} expressed in binary form.
The second bug was detected in a template called SignFp, which given an input number computes the .
The Num2Ternary bug
The circom code of this template is as follows:
Note that the output is an array of size n of arrays of two bits, but is the value in the decimal version of .
The problem with this circuit is that although the intended behavior would be that the values of all numbers in are (in its binary form) in the domain , no constraint prevents these values to take the value since its binarization with 2 bits allows this situation. For instance, taking the generated constraints are essentially:
Then, since is also also allowed for , can take as well. As a result, the circuit become nondeterministic and, for instance, for we have two solutions:
- , and the rest all zeros,which is the expected one, and
- , and the rest all zeros, which is not expected.
CIVER was able to produce a counter example showing this bug.
The issue can be found here.
The SignFp bug:
This is a more critical bug, since for every input the circuit is not deterministic.
The code of SignFp is the following:
Here the problem is that for instance, for , then the output can be both or , since can take or respectively (assuming is the field division). But a closer analysis, searching for more solutions using CIVER we have realised that, in fact the bug affects to any input as both assignments to sign work:
- If is even:
- (expected solution)
- (alternative solution)
(Recall that is the field division.)
- If is odd:
- (expected solution)
- (alternative solution)
The issue can be found here.
Full ZisK recursion/aggregation verification
The full verification of the recursion/aggregation circuits is not finished yet. When done, a complete public report will be delivered.
References
[1] Miguel Isabel, Clara Rodríguez-Núñez, Albert Rubio. Scalable verification of zero-knowledge protocols. 2024 IEEE Symposium on Security and Privacy (SP). DOI:10.1109/SP54263.2024.00133
[2] Marta Bellés-Muñoz, Miguel Isabel, Jose Luis Muñoz-Tapia, Albert Rubio, Jordi Baylina.
Circom: A Circuit Description Language for Building Zero-Knowledge Applications. IEEE Transactions on Dependable and Secure Computing, 2022. DOI:10.1109/TDSC.2022.3232813
Finding bugs in large ZK circuits with CIVER
The COSTA research group has started a new collaboration with the ZisK development team to apply CIVER to verify the determinism of the recursion/aggregation circuits of ZisK.
CIVER has already been able to find vulnerabilities in several projects in production (see [1] for details).
The size of these ZisK circuits ranges from one million to over five million constraints, so verifying them and finding bugs is very challenging. Other tools have shown to be unable to handle circuits of this size at once.
Using CIVER we have detected two subtle bugs which compromise the soundness of ZisK. Thanks to using CIVER these bugs have been detected in the development process and will not reach the production phase. CIVER has been able to spot the problematic components and provide a buggy instance.
Verifying circuits with CIVER
CIVER [1] is a tool that can verify weak safety [2], also known as determinism, which means there is a single valid output for any given inputs. When this property is not satisfied it means that the circuit is underconstrained, as all non expected values that are valid for the outputs should be restricted. CIVER can verify weak safety of circuits defined using the DSL circom, but can also verify circuits given as a constraints system (in R1CS format, PLONK, ACIR, …). CIVER modularly analyses the circuit to increase scalability and to find the problematic part of the circuit.
When the circuit is provided in the circom language, it uses the structure of the circuit definition to modularly check all the components. CIVER can also check Pre/Postconditions defined on circom programs, as well as verify circom's tag specifications. CIVER has been integrated in the circom compiler and can handle full circom programs.
When CIVER is applied to non-circom circuits powerful clustering techniques are applied in order to break the circuit into smaller components that are then handled modularly.
Details about the bugs
The first bug was detected in a circom template called Num2Ternary(n) that transforms an input number to its ternary form (i.e. in base 3) using n values in {0..2} expressed in binary form. computes the .
The second bug was detected in a template called SignFp, which given an input number
The Num2Ternary bug
The circom code of this template is as follows:
Note that the output is an array of size n of arrays of two bits, but is the value in the decimal version of .
The problem with this circuit is that although the intended behavior would be that the values of all numbers in are (in its binary form) in the domain , no constraint prevents these values to take the value since its binarization with 2 bits allows this situation. For instance, taking the generated constraints are essentially:
Then, since is also also allowed for , can take as well. As a result, the circuit become nondeterministic and, for instance, for we have two solutions:
CIVER was able to produce a counter example showing this bug.
The issue can be found here.
The SignFp bug:
This is a more critical bug, since for every input the circuit is not deterministic.
The code of SignFp is the following:
Here the problem is that for instance, for , then the output can be both or , since can take or respectively (assuming is the field division). But a closer analysis, searching for more solutions using CIVER we have realised that, in fact the bug affects to any input as both assignments to sign work:
(Recall that
The issue can be found here.
Full ZisK recursion/aggregation verification
The full verification of the recursion/aggregation circuits is not finished yet. When done, a complete public report will be delivered.
References
[1] Miguel Isabel, Clara Rodríguez-Núñez, Albert Rubio. Scalable verification of zero-knowledge protocols. 2024 IEEE Symposium on Security and Privacy (SP). DOI:10.1109/SP54263.2024.00133
[2] Marta Bellés-Muñoz, Miguel Isabel, Jose Luis Muñoz-Tapia, Albert Rubio, Jordi Baylina.
Circom: A Circuit Description Language for Building Zero-Knowledge Applications. IEEE Transactions on Dependable and Secure Computing, 2022. DOI:10.1109/TDSC.2022.3232813