# GHSA-7p92-x423-vwj6: Plonk verifier KZG multi point verification

> A flaw in the Plonk verifier allows attackers to forge valid proofs by exploiting weak randomness, bypassing verification checks in Go applications.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 17 Oct 2023
- **Also known as:** GO-2023-2119

## What is GHSA-7p92-x423-vwj6?

GHSA-7p92-x423-vwj6 is a vulnerability in github.com/consensys/gnark, published on 17 Oct 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

### Impact

The vulnerability allows a third party to derive a valid proof from a valid initial tuple {proof, public_inputs}, corresponding to the same public inputs as the initial proof. It is due to a randomness being generated using a small part of the scratch memory describing the state, allowing for degrees of freedom in the transcript.

Note that the impact is limited to the PlonK verifier smart contract.

### Patches

We still use a hash function on some data to have a pseudo rng, but instead of hashing the first 32 bytes of the state (
` let random := mod(keccak256(state, 0x20), r_mod)` )

we hash the whole state at this point of the verifier as if it was a Fiat Shamir transcript:
```
        mstore(mPtr, mload(add(state, STATE_FOLDED_DIGESTS_X)))
        mstore(add(mPtr, 0x20), mload(add(state, STATE_FOLDED_DIGESTS_Y)))
        mstore(add(mPtr, 0x40), calldataload(add(aproof, PROOF_BATCH_OPENING_AT_ZETA_X)))
        mstore(add(mPtr, 0x60), calldataload(add(aproof, PROOF_BATCH_OPENING_AT_ZETA_Y)))
        mstore(add(mPtr, 0x80), calldataload(add(aproof, PROOF_GRAND_PRODUCT_COMMITMENT_X)))
        mstore(add(mPtr, 0xa0), calldataload(add(aproof, PROOF_GRAND_PRODUCT_COMMITMENT_Y)))
        mstore(add(mPtr, 0xc0), calldataload(add(aproof, PROOF_OPENING_AT_ZETA_OMEGA_X)))
        mstore(add(mPtr, 0xe0), calldataload(add(aproof, PROOF_OPENING_AT_ZETA_OMEGA_Y)))
        mstore(add(mPtr, 0x100), mload(add(state, STATE_ZETA)))
        mstore(add(mPtr, 0x120), mload(add(state, STATE_GAMMA_KZG)))
        let random := staticcall(gas(), 0x2, mPtr, 0x140, mPtr, 0x20)
```

### Workarounds

In the function `batch_verify_multi_points`, the variable `random` (corresponding to `u` in the paper, step 12 of the [plonk](https://eprint.iacr.org/2019/953.pdf) verification process) should depend on `state_folded_digests_x`, `state_folded_digests_y`, `proof_grand_product_commitment_x`, `proof_grand_product_commitment_y` and `state_zeta` (by hashing those values for instance).

## Which versions are affected by GHSA-7p92-x423-vwj6?

3 open source packages ship an affected version, including github.com/consensys/gnark.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/consensys/gnark` | Go | All versions | 0.9.1 |
| `github.com/consensys/gnark` | Go | All versions | 0.9.1 |
| `github.com/consensys/gnark` | Go | All versions | 0.9.1 |

## How do I fix GHSA-7p92-x423-vwj6?

Upgrade github.com/consensys/gnark to 0.9.1 or later.

## Is GHSA-7p92-x423-vwj6 being exploited?

There is no known exploitation of GHSA-7p92-x423-vwj6 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-7p92-x423-vwj6 and fix it if it is affected.

What it is: GHSA-7p92-x423-vwj6 is a vulnerability in github.com/consensys/gnark, published on 17 Oct 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-7p92-x423-vwj6 in the wild and no public exploit code.

Affected packages and fixed versions:
- github.com/consensys/gnark (Go): affected all versions; fixed in 0.9.1
- github.com/consensys/gnark (Go): affected all versions; fixed in 0.9.1
- github.com/consensys/gnark (Go): affected all versions; fixed in 0.9.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-7p92-x423-vwj6/ (Markdown: https://insights.sbomify.com/GHSA-7p92-x423-vwj6/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-7p92-x423-vwj6

---
From sbomify Insights: https://insights.sbomify.com/GHSA-7p92-x423-vwj6/
Summaries are generated and may contain mistakes; the official description above is the record.
