CVE-2024-45040: Github.com/consensys/gnark Gnark Commitments To Private Witnesses Vulnerability

HIGH
Advisory Identifier: GHSA-9xcg-3q8v-7fq6
CVSS 5.9
CWE-200
Published
Advisory Summary

CVE-2024-45040 is a HIGH (CVSS 5.9) gnark commitments to private witnesses vulnerability (CWE-200: Exposure of Sensitive Information to an Unauthorized Actor) affecting Github.com/consensys/gnark libraries in the Go ecosystem. The issue involves gnark commitments to private witnesses in groth16 as implemented break zero-knowledge property. Remediation is available by upgrading affected packages to version 0.11.0.

CVE-2024-45040 at a Glance

CVE Identifier CVE-2024-45040
GHSA Identifier GHSA-9xcg-3q8v-7fq6
Severity HIGH
CVSS v3.1 Base Score 5.9
CWE Classification CWE-200: Exposure of Sensitive Information to an Unauthorized Actor
Affected Product Github.com/consensys/gnark
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 5.9

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity None (I:N)
Availability None (A:N)

How to Fix CVE-2024-45040

To remediate this vulnerability, upgrade all affected Github.com/consensys/gnark dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

github.com/consensys/gnark fixed: 0.11.0
Upgrade github.com/consensys/gnark to 0.11.0
github.com/consensys/gnark fixed: 0.11.0
Upgrade github.com/consensys/gnark to 0.11.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for github.com/consensys/gnark

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-45040, inspect your project dependencies for Github.com/consensys/gnark:

inspect dependencies for github.com/consensys/gnark

Analyze the terminal output to locate any version of Github.com/consensys/gnark in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.11.0), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-200: Exposure of Sensitive Information to an Unauthorized Actor, where the product exposes sensitive information to an actor that is not explicitly authorized to have access to that information. In Github.com/consensys/gnark, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

This report concerns the Groth16 prover when used with commitments (as in `frontend.Committer`). To simplify exposition of the issue, I will focus on the case of a single commitment, to only private witnesses. But the issue should be present whenever commitments are used that include private witnesses. > The commitment to private witnesses `w_i` is computed as ``` c = sum_i w_i * b_i ``` where `b_i` would be `ProvingKey.CommitmentKeys[0].Basis[i]` in the code. While this is a binding commitment, it is not hiding. In practice, an adversary will know the points `b_i`, as they are part of the proving key, and can verify correctness of a guess for the values of `w_i` by computing `c'` as the right hand side of the above formula, and checking whether `c'` is equal to `c`. I attach a proof of concept that demonstrates this. This breaks the perfect zero-knowledge property of Groth16, so the Groth16 scheme using commitments to private witnesses as implemented by gnark fails to be a zk-SNARK. The code indicates that the extension to Groth16 given by the commitments follows the paper "Recursion over Public-Coin Interactive Proof Systems; Faster Hash Verification" by Alexandre Belling, Azam Soleimanian, and Olivier Begassat. In that paper, it seems that commitments are applied to what were originally public inputs, which are moved to private witnesses for efficiency reasons. In any case, that paper does not discuss any hiding/privacy/zero-knowledge properties of their protocols. So for the use-cases envisioned by that paper, having the commitment not be hiding and losing zero-knowledge of Groth16 might be adequate. However, the documentation by gnark does not make clear that committing to private witnesses loses the zero-knowledge property. The documentation for `frontend.Committer` does not mention this, and the following snippet from `std/multicommit/doc_test.go`, where private witness variables are named `Secrets` and are committed, seems to actively suggest that committed witnesses are still private. ```go // MultipleCommitmentCircuit is an example circuit showing usage of multiple // independent commitments in-circuit. type MultipleCommitmentsCircuit struct { Secrets [4]frontend.Variable } func (c *MultipleCommitmentsCircuit) Define(api frontend.API) error { // first callback receives first unique commitment derived from the root commitment multicommit.WithCommitment(api, func(api frontend.API, commitment frontend.Variable) error { // compute (X-s[0]) * (X-s[1]) for a random X res := api.Mul(api.Sub(commitment, c.Secrets[0]), api.Sub(commitment, c.Secrets[1])) api.AssertIsDifferent(res, 0) return nil }, c.Secrets[:2]...) // ... ``` Thus it seems to me that the intention likely was (and users will be expecting) that gnark's implementation of Groth16 with these commitments should still have zero-knowledge and that the commitments should be hiding. The way to fix this is likely to adjust the commitment to be hiding the way that is done in the LegoSNARK paper (https://eprint.iacr.org/2019/142.pdf). To expand: First, let me fix some notation. Currently, the verifying key has two points on G2 used for checking the proof of knowledge for the commitment: `g` and `g'=-1/σ * g` (in the code: `VerifyingKey.CommitmentKey.G` and `VerifyingKey.CommitmentKey.GRootSigmaNeg`). The commitment itself is then `c = sum_i w_i * b_i`, where `b_i` are on G1, and the proof of knowledge associated to `c` is calculated as `pok = sum_i w_i * b'_i`, where `b'_i = σ*b_i` (in the code `b_i` and `b'_i` are `ProvingKey.CommitmentKeys.Basis[0][i]` and `ProvingKey.CommitmentKeys.BasisExpSigma[0][i]`). The proof of knowledge is then verified by checking `e(c, g) + e(pok, g') = 0` (I am using additive notation throughout here). The Groth16 proof is verified by checking ``` e(Krs, -[δ]₂) + e(c, -[γ]₂) + e(term involving public inputs, -[γ]₂) + other terms = 0 ``` The construction ccGro16 from the LegoSNARK paper (page 73 in https://eprint.iacr.org/2019/142.pdf) is a similar construction. They do not have a proof of knowledge accompanying the commitment because they are considering the case where there are no public inputs. However, they claim that their scheme is zero-knowledge, and the crucial difference for this is that their commitment has an extra blinding term as is usual for Pedersen commitments. Concretely, it is of the form: ``` c_new = sum_i w_i * b_i + v*[η/γ]₁ ``` where `[η/γ]₁` is a new element of G1 that is part of the proving key, with `η` a new toxic waste field element. The value of `v` is randomly chosen by the prover. When adding this additional term to `c`, then to make the proof verification still succeeds, the proof point `Krs` is changed accordingly: ``` Krs_new = Krs_old - v*[η/δ]₁ ``` where `[η/δ]₁` is another new element of G1 that is part of the proving key. As `e([η/γ]₁, -[γ]₂) = e([η/δ]₁, -[δ]₂)`, the contributions from the new terms cancel each other in the proof verification pairing check. This modification should ensure that the commitment is hiding. The proof of knowledge would also need to be adapted accordingly, with ``` pok = sum_i w_i * b'_i + v*[σ*η/γ]₁ ``` where `[σ*η/γ]₁` is another point of G1 to add to the proving key. ### Impact The vulnerability affects only Groth16 proofs with commitments. Notably, PLONK proofs are not affected. The vulnerability affects the zero-knowledge property of the proofs - in case the witness (secret or internal) values are small, then the attacker may be able to enumerate all possible choices to deduce the actual value. If the possible choices for the variables to be committed is large or there are many values committed, then it would be computationally infeasible to enumerate all valid choices. It doesn't affect the completeness/soundness of the proofs. ### Patches The vulnerability has been fixed in https://github.com/Consensys/gnark/pull/1245. Corresponding commit on the master branch https://github.com/Consensys/gnark/commit/afda68a38acca37becb8ba6d8982d03fee9559a0. The patch to fix the issue is to add additional randomized value to the list of committed value at proving time to mask the rest of the values which were committed. ### Workarounds The user can manually commit to a randomized value.

CVE-2024-45040 Affected Github.com/consensys/gnark Versions

2 component(s)
Fixed Versions:
0.11.0
Product / Package Ecosystem Affected Versions Fixed Version
github.com/consensys/gnark
Go
< 0.11.0
0.11.0
github.com/consensys/gnark
Go
< 0.11.0
0.11.0

References

Frequently Asked Questions

What is CVE-2024-45040?
CVE-2024-45040 is a security vulnerability in Github.com/consensys/gnark involving gnark commitments to private witnesses in Groth16 as implemented break zero-knowledge property under CWE-200: Exposure of Sensitive Information to an Unauthorized Actor.
Which Github.com/consensys/gnark versions are affected?
Affected versions include releases prior to 0.11.0 across affected packages: github.com/consensys/gnark.
What version fixes CVE-2024-45040?
Upgrading to 0.11.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/consensys/gnark affected?
Yes, github.com/consensys/gnark is affected in releases prior to 0.11.0. Upgrade your dependency to 0.11.0 or later.
What is the CVSS score of CVE-2024-45040?
CVE-2024-45040 has a CVSS v3.1 base score of 5.9 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N.
What CWE is associated with CVE-2024-45040?
CVE-2024-45040 is classified under CWE-200: Exposure of Sensitive Information to an Unauthorized Actor (The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information.).
How can I check Go dependencies for CVE-2024-45040?
Run the dependency tree command: 'inspect dependencies for github.com/consensys/gnark'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-9xcg-3q8v-7fq6",
  "modified" : "2024-11-18T16:27:10Z",
  "published" : "2024-09-06T19:40:01Z",
  "aliases" : [ "CVE-2024-45040" ],
  "summary" : "gnark commitments to private witnesses in Groth16 as implemented break zero-knowledge property",
  "details" : "\nThis report concerns the Groth16 prover when used with commitments (as in `frontend.Committer`). To simplify exposition of the issue, I will focus on the case of a single commitment, to only private witnesses. But the issue should be present whenever commitments are used that include private witnesses.\n>\nThe commitment to private witnesses `w_i` is computed as\n```\nc = sum_i w_i * b_i\n```\nwhere `b_i` would be `ProvingKey.CommitmentKeys[0].Basis[i]` in the code.\n\nWhile this is a binding commitment, it is not hiding. In practice, an adversary will know the points `b_i`, as they are part of the proving key, and can verify correctness of a guess for the values of `w_i` by computing `c'` as the right hand side of the above formula, and checking whether `c'` is equal to `c`. I attach a proof of concept that demonstrates this.\n\nThis breaks the perfect zero-knowledge property of Groth16, so the Groth16 scheme using commitments to private witnesses as implemented by gnark fails to be a zk-SNARK.\n\nThe code indicates that the extension to Groth16 given by the commitments follows the paper \"Recursion over Public-Coin Interactive Proof Systems; Faster Hash Verification\" by Alexandre Belling, Azam Soleimanian, and Olivier Begassat. In that paper, it seems that commitments are applied to what were originally public inputs, which are moved to private witnesses for efficiency reasons. In any case, that paper does not discuss any hiding/privacy/zero-knowledge properties of their protocols.\n\nSo for the use-cases envisioned by that paper, having the commitment not be hiding and losing zero-knowledge of Groth16 might be adequate. However, the documentation by gnark does not make clear that committing to private witnesses loses the zero-knowledge property. The documentation for `frontend.Committer` does not mention this, and the following snippet from `std/multicommit/doc_test.go`, where private witness variables are named `Secrets` and are committed, seems to actively suggest that committed witnesses are still private.\n```go\n// MultipleCommitmentCircuit is an example circuit showing usage of multiple\n// independent commitments in-circuit.\ntype MultipleCommitmentsCircuit struct {\n    Secrets [4]frontend.Variable\n}\n\nfunc (c *MultipleCommitmentsCircuit) Define(api frontend.API) error {\n    // first callback receives first unique commitment derived from the root commitment\n    multicommit.WithCommitment(api, func(api frontend.API, commitment frontend.Variable) error {\n        // compute (X-s[0]) * (X-s[1]) for a random X\n        res := api.Mul(api.Sub(commitment, c.Secrets[0]), api.Sub(commitment, c.Secrets[1]))\n        api.AssertIsDifferent(res, 0)\n        return nil\n    }, c.Secrets[:2]...)\n   // ...\n```\n\nThus it seems to me that the intention likely was (and users will be expecting) that gnark's implementation of Groth16 with these commitments should still have zero-knowledge and that the commitments should be hiding.\n\nThe way to fix this is likely to adjust the commitment to be hiding the way that is done in the LegoSNARK paper (https://eprint.iacr.org/2019/142.pdf). To expand:\n\nFirst, let me fix some notation.\n\nCurrently, the verifying key has two points on G2 used for checking the proof of knowledge for the commitment: `g` and `g'=-1/σ * g` (in the code: `VerifyingKey.CommitmentKey.G` and `VerifyingKey.CommitmentKey.GRootSigmaNeg`).\nThe commitment itself is then `c = sum_i w_i * b_i`, where `b_i` are on G1, and the proof of knowledge associated to `c` is calculated as `pok = sum_i w_i * b'_i`, where `b'_i = σ*b_i` (in the code `b_i` and `b'_i` are `ProvingKey.CommitmentKeys.Basis[0][i]` and `ProvingKey.CommitmentKeys.BasisExpSigma[0][i]`). The proof of knowledge is then verified by checking `e(c, g) + e(pok, g') = 0` (I am using additive notation throughout here).\n\nThe Groth16 proof is verified by checking\n```\ne(Krs, -[δ]₂) + e(c, -[γ]₂) + e(term involving public inputs, -[γ]₂) + other terms = 0\n```\n\nThe construction ccGro16 from the LegoSNARK paper (page 73 in https://eprint.iacr.org/2019/142.pdf) is a similar construction. They do not have a proof of knowledge accompanying the commitment because they are considering the case where there are no public inputs. However, they claim that their scheme is zero-knowledge, and the crucial difference for this is that their commitment has an extra blinding term as is usual for Pedersen commitments. Concretely, it is of the form:\n```\nc_new = sum_i w_i * b_i + v*[η/γ]₁\n```\nwhere `[η/γ]₁` is a new element of G1 that is part of the proving key, with `η` a new toxic waste field element. The value of `v` is randomly chosen by the prover.\n\nWhen adding this additional term to `c`, then to make the proof verification still succeeds, the proof point `Krs` is changed accordingly:\n```\nKrs_new = Krs_old -  v*[η/δ]₁\n```\nwhere `[η/δ]₁` is another new element of G1 that is part of the proving key. As `e([η/γ]₁, -[γ]₂) = e([η/δ]₁, -[δ]₂)`, the contributions from the new terms cancel each other in the proof verification pairing check.\n\nThis modification should ensure that the commitment is hiding.\n\nThe proof of knowledge would also need to be adapted accordingly, with\n```\npok = sum_i w_i * b'_i + v*[σ*η/γ]₁\n```\nwhere `[σ*η/γ]₁` is another point of G1 to add to the proving key.\n\n\n### Impact\n\nThe vulnerability affects only Groth16 proofs with commitments. Notably, PLONK proofs are not affected.\n\nThe vulnerability affects the zero-knowledge property of the proofs - in case the witness (secret or internal) values are small, then the attacker may be able to enumerate all possible choices to deduce the actual value. If the possible choices for the variables to be committed is large or there are many values committed, then it would be computationally infeasible to enumerate all valid choices.\n\nIt doesn't affect the completeness/soundness of the proofs.\n\n### Patches\n\nThe vulnerability has been fixed in https://github.com/Consensys/gnark/pull/1245. Corresponding commit on the master branch https://github.com/Consensys/gnark/commit/afda68a38acca37becb8ba6d8982d03fee9559a0.\n\nThe patch to fix the issue is to add additional randomized value to the list of committed value at proving time to mask the rest of the values which were committed.\n\n### Workarounds\n\nThe user can manually commit to a randomized value.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:H/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/consensys/gnark"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.11.0"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/consensys/gnark"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.11.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/Consensys/gnark/security/advisories/GHSA-9xcg-3q8v-7fq6"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-45040"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Consensys/gnark/pull/1245"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Consensys/gnark/commit/afda68a38acca37becb8ba6d8982d03fee9559a0"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/Consensys/gnark"
  }, {
    "type" : "WEB",
    "url" : "https://pkg.go.dev/vuln/GO-2024-3123"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-200" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-09-06T19:40:01Z",
    "nvd_published_at" : "2024-09-06T13:15:04Z"
  }
}