In certain proof systems, the "trusted" setup phase can pose significant risks if specific values are not properly discarded during the production of the common reference string (CRS).
These parameters are often referred to as "toxic waste" due to the fact that possessing these values enables anyone to forge proofs for invalid inputs.
With such a fraud proof, a verifier could mistakenly accept it, even if potentially invalid inputs were used to generate the proof. The situation becomes especially dangerous if it is produced by a malicious prover.
In this demo, we will use the Groth16 proving system, implemented using arkworks, as an example to show how fraud proofs can be generated using this so-called toxic waste.
After cloning this repo, you can test the functionality with the following unit tests.
- Simple square and add circuit
cargo test --test fraud_proof -- --nocapture
- MiMC circuit
cargo test --test fraud_mimc -- --nocapture
In src/verifier.rs
, the verification process is as below
pub fn verify_proof_with_prepared_inputs(
pvk: &PreparedVerifyingKey<E>,
proof: &Proof<E>,
prepared_inputs: &E::G1,
) -> R1CSResult<bool> {
let qap = E::multi_miller_loop(
[
<E::G1Affine as Into<E::G1Prepared>>::into(proof.a),
prepared_inputs.into_affine().into(),
proof.c.into(),
],
[
proof.b.into(),
pvk.gamma_g2_neg_pc.clone(),
pvk.delta_g2_neg_pc.clone(),
],
);
let test = E::final_exponentiation(qap).ok_or(SynthesisError::UnexpectedIdentity)?;
Ok(test.0 == pvk.alpha_g1_beta_g2)
That is, the pairing format can recognized as
(G1 elements)[
proof.a,
gamma^{-1} * (beta * a_i + alpha * b_i + c_i) * H, H is the generator of E::G1
proof_c
],
(G2 elements)[
proof_b,
-gamma,
-delta
]
Recall the verification process in the Groth16 paper
,
The Arkworks implementation of Groth16
modifies the equation as follows. This modification enables the verifier to precompute and store the pairng result of
The goal is to create a proof that will always be accepted by verifier regardless of the witnesses and inputs used.
We can see that the correctness of inputs is constrained by the pairing term
To achieve this, my implementation for generating fraud proofs ensures the following
- It produces
$[α]_1 · [β]_2$ in the pairing result. - It offsets
$\bigg[\sum_{i=0}^{l} \dfrac{a_i · (βu_i(x) + αv_i(x) + w_i(x)}{γ}\bigg]_1 · [-γ]_2$ in the pairing result. - It remains indistinguishable from a valid proof.
Therefore, the construction of fraud proof can be summarized as below
- Simulate the leakage of toxic waste by appending them into proving key.
- Recover the generator of
$G_1$ using the toxic waste and CRS. - Construct A_{Fake}, B_{Fake}, and C_{Fake} with the toxic waste and the restored generator.