7.1high
gnark vulnerable to unsoundness in variable comparison/non-unique binary decomposition
- Severity
- 7.1high CVSS:3.1 by GitHub_M
- Exploit likelihood
- 0.23% (higher than 15% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-498w-5j49-vqjgGO-2023-2098
Description
gnark is a zk-SNARK library that offers a high-level API to design circuits. Prior to version 0.9.0, for some in-circuit values, it is possible to construct two valid decomposition to bits. In addition to the canonical decomposition of `a`, for small values there exists a second decomposition for `a+r` (where `r` is the modulus the values are being reduced by). The second decomposition was possible due to overflowing the field where the values are defined. Upgrading to version 0.9.0 should fix the issue without needing to change the calls to value comparison methods.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| Consensys gnark | < 0.9.0, before 0.9.0 | CVE List, NVD |
| github.com/consensys/gnark (Go) | before 0.9.0 | GitHub Advisory Database, Go Vulnerability Database |
All scores
| GitHub_M | 7.1high CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:C/C:N/I:H/A:N |
| GitHub | 5.5medium CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N |
| NVD | 5.5medium CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N |
Classification
What each source says
CVE List
gnark is a zk-SNARK library that offers a high-level API to design circuits. Prior to version 0.9.0, for some in-circuit values, it is possible to construct two valid decomposition to bits. In addition to the canonical decomposition of `a`, for small values there exists a second decomposition for `a+r` (where `r` is the modulus the values are being reduced by). The second decomposition was possible due to overflowing the field where the values are defined. Upgrading to version 0.9.0 should fix the issue without needing to change the calls to value comparison methods.
GitHub Advisory Database
Impact
For some in-circuit values, it is possible to construct two valid decomposition to bits. In addition to the canonical decomposition of a, for small values there exists a second decomposition for a+r (where r is the modulus the values are being reduced by). The second decomposition was possible due to overflowing the field where the values are defined.
Internally, the comparison methods frontend.API.Cmp and frontend.API.IsLess used binary decomposition and checked the bitwise differences. This allows a malicious prover to construct a valid proof for a statement a < b even if a > b.
The issue impacts all users using API.Cmp or API.IsLess methods. Additionally, it impacts the users using bits.ToBinary or API.ToBinary methods if full-width decomposition is requested (the default behaviour if no options are given).
The issues does not impact comparison methods in field emulation (package std/math/emulated) and dedicated comparison package (std/math/cmp).
Patches
Fix has been implemented in pull request #835 and merged in commit 59a4087261a6c73f13e80d695c17b398c3d0934f to master branch. The release v0.9.0 and onwards include the fix.
The fix added additional comparison of the decomposed bit-vector to the modulus of the in-circuit values.
Workarounds
Upgrading to version v0.9.0 should fix the issue without needing to change the calls to value comparison methods.
Alternatively, users can use the std/math/cmp gadget, which additionally allows to bound the number of bits being compared, making the comparisons more efficient if the bound on the absolute difference of the values is known.
References
- https://github.com/Consensys/gnark/pull/835
- https://github.com/zkopru-network/zkopru/issues/116
- https://github.com/iden3/circomlib/pull/48
Acknowledgement
The vulnerability was reported by Marcin Kostrzewa @ Reilabs.
Go Vulnerability Database
Unsoundness in variable comparison / non-unique binary decomposition in github.com/consensys/gnark
NVD (es)
gnark es una librería zk-SNARK que ofrece una API de alto nivel para diseñar circuitos. Antes de la versión 0.9.0, para algunos valores en el circuito, era posible construir dos descomposición válida en bits. Además de la descomposición canónica de "a", para valores pequeños existe una segunda descomposición para "a+r" (donde "r" es el módulo por el que se reducen los valores). La segunda descomposición fue posible debido al desbordamiento del campo donde se definen los valores. La actualización a la versión 0.9.0 debería solucionar el problema sin necesidad de cambiar las llamadas a los métodos de comparación de valores.
References
| https://github.com/Consensys/gnark/security/advisories/GHSA-498w-5j49-vqjg | mitigation, patch, third-party-advisory, web | |
| https://github.com/zkopru-network/zkopru/issues/116 | not-applicable, report, web | |
| https://github.com/Consensys/gnark/commit/59a4087261a6c73f13e80d695c17b398c3d0934f | fix, patch, web | |
| https://nvd.nist.gov/vuln/detail/CVE-2023-44378 | advisory | |
| https://github.com/Consensys/gnark/pull/835 | fix, web | |
| https://github.com/Consensys/gnark | package | |
| https://github.com/advisories/GHSA-498w-5j49-vqjg | advisory | |
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2023-44378 changed 2024-09-19 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-498w-5j49-vqjg changed 2026-09-10 | CC-BY-4.0 |
| Go Vulnerability Database | GO-2023-2098 changed 2024-05-20 | CC-BY-4.0 |
| NVD | CVE-2023-44378 changed 2026-06-17 | Public domain |