Try   HackMD

Groth16 Verification Gas cost

Analytical:

TLDR: For

β„“ public inputs, on-chain G16 verification costs
β‰ˆ(181+6Γ—β„“)
kgas

Estimation:

Circuit with

vk=(P=Ξ±β‹…g,Q=Ξ²β‹…h,{Sj}j=0,β€¦β„“βˆ’1,h,D=Ξ΄β‹…h)
Proof
Ο€=(A,B,C)∈G1Γ—G2Γ—G1
and public inputs
xβ†’=(x0,…xβ„“βˆ’1)∈Frβ„“

G16.Verify(Ο€,xβ†’,vk)∈{0,1} is computed using:

  • On-curve + in subgroup point checks: (gas cost omitted for now)
  • 1 MSM of size
    β„“
    : public input term
    F=βˆ‘j=0β„“βˆ’1xjβ‹…Sj
  • Pairing check (4 Miller loops, 1 final exp.):
    e(A,B)=?e(P,Q)e(F,h)e(C,D)

In terms of gas fees that's

  • 6,150Γ—β„“
    (MSM) +
    34,000Γ—4+45,000
    (Pairing)
    β‰ˆ181+6β„“
    kgas, thanks to EIP 1108
  • So 3 public inputs
    β‰ˆ
    200k gas
  • Assuming 20gwei/gas, $2000/ETH that's about $8 to verify a proof that has 3 public inputs, and about $0.25 per additional public input.

TODO: The actual cost will be somewhat higher due to checking curve points. I don't think it's more than 10% higher but we should check against some actual smart contracts

Empirical:

TODO