Cointime

Download App
iOS & Android

ZKP Series: Principles and Implementation of Extensibility Attacks on Groth16 Proofs

Preface

In our previous article, we reviewed the technical features of mainstream ZKP implementation solutions and mentioned the potential extensibility risks associated with certain ZKP algorithms. In this article, we will continue to demonstrate the attack principles and defense methods from a practical perspective.

Vulnerability Overview

Extensibility attacks on ZKP refer to the ability of an adversary to generate a new valid proof without knowledge of the witness, given an existing valid proof.

Not all proof systems are susceptible to extensibility attacks. In fact, this problem currently exists mainly in the Groth16 proof system. So why do we still insist on using Groth16, given that there are so many other proof systems available? The truth is that the proofs generated by Groth16 are extremely small in size and very fast to verify. In the context of blockchain, where computational costs are high, using Groth16 seems to be the most ideal choice.

What risks does extensibility vulnerability bring? Let’s imagine a deposit system that uses ZKP proofs submitted by users to verify their identity. Once verified, users can make withdrawals. Since the verification process of this system is public, anyone can obtain the proof. If the proof value itself is used as a withdrawal record and the proof is obtained and transformed, it can be used for multiple withdrawals. The exploitation of this vulnerability depends on the specific scenario, but we can see that extensibility vulnerability primarily brings the risk of double-spending.

Mathematical Principles

To understand the attack principles, we first need to understand the algorithm, which requires some knowledge of cryptography. Interested readers can find information on the Groth16 algorithm on their own. Here, we will focus on the root cause of the vulnerability: the verification function.

Let’s take a look at the formula for the verification function:

Without going into a detailed explanation of each individual variable, it may be difficult to fully comprehend the formula’s meaning. However, an extensive introduction is not necessarily required. By simply remembering the “A * B” on the left side of the formula, we can begin to unravel its intricacies and apply mathematical magic. The following incantation is all it takes:

This is just one of the simpler construction methods, and there is another construction method, which we will not elaborate on here, as we have already gathered what we needed.

Implementation

With the above formula, we can execute the extension of Groth16 proofs in implementation. To forge a proof for a target object, we can obtain its proof, for example:

{  pi_a: [    '17566212007750634279332191898019870443899908963707812937725971557556988121113',    '13653824972036797689593667463260040326059024360787769597142078414930263663703',    '1'  ],  pi_b: [    [      '14906111038352923510344648516413952434168552622848767570599399834157918236589',      '15289017543994496306320102143103349779456992442925111629326024552687168229256'    ],    [      '18841235948006283310515755114762069779103481848435391875780416574913227842443',      '6835281862874020275059416795628130939104366467185014410026268177455413514889'    ],    [ '1', '0' ]  ],  pi_c: [    '21641806348662631815866837255154640732047306895903168385641666607914783128458',    '2082587994352117459125871298218148663854896572836176277773049196516560449682',    '1'  ],  protocol: 'groth16',  curve: 'bn128'}

Let’s take a look at a proof like this: pi_a, pi_b, pi_c are the A, B, C described in the formula above. This proof uses the BN128 curve, so we need to find a development library that supports the BN128 curve. Here, we choose ffjavascript, which is a finite field library based on JavaScript that supports the BN128 and BLS12381 curves.

First, we arbitrarily construct an element on the field and its inverse element:

const X = F.e("123456");const invX = F.inv(X);

Then, we multiply them together separately. The core code is as follows:

const A = curve.G1.fromObject(proof.pi_a);const B = curve.G2.fromObect(proof.pi_b);new_pi_a = curve.G1.timesScalar(A, X);  //A'=x*Anew_pi_b = curve.G2.timesScalar(B, invX);  //B'=x^{-1}*B

Finally, we replace the original proof with new_pi_a and new_pi_b to obtain a new proof:

{  pi_a: [    '6515337738552169645617263495374285821912767490069335826295120714428977813009',    '10671874016637483602721966808912960491553808325993800847672325376634242358838',    '1'  ],  pi_b: [    [      '20523135654483520737281403147507843211011765855706506084021355785019229409285',      '4032527486736971273144842057682931136787425732029780739716144011227563817375'    ],    [      '9389285843105460816015935120908213706233585149018458753845466963847282799614',      '7207137211649923819130654483456848273137049778520784010268635580504303221849'    ],    [ '1', '0' ]  ],  pi_c: [    '21641806348662631815866837255154640732047306895903168385641666607914783128458',    '2082587994352117459125871298218148663854896572836176277773049196516560449682',    '1'  ],  protocol: 'groth16',  curve: 'bn128'}

By this point, we have successfully constructed a new proof. When we place this proof into the verification function, we can see that it can pass the verification.

Prevention

How can we prevent Groth16 extensibility attacks? Here are four methods:

  1. Sign the proof, and have the verifier validate the signature along with the proof.
  2. Add nullifier values in the public inputs of the circuit, as TornadoCash does, to ensure that a proof can only correspond to a public input once.
  3. Add the identity information of the prover (such as Ethereum’s msg.sender) to the public inputs of the circuit, allowing the verifier to verify the prover’s identity.
  4. Use other proof systems, as discussed in our previous article.

Conclusion

In conclusion, Groth16 is vulnerable to extensibility attacks, as new proofs can be forged through simple calculations. In practice, it is important to take measures to prevent double-spending attacks.

Comments

All Comments

Recommended for you

  • Hong Kong’s virtual asset ETF market has established a mature structure including exchanges, market makers, primary and secondary custodians, etc.

    Wang Long, Chairman of the Greater Bay Area Financial Professionals Association, pointed out in an article published in Ta Kung Pao entitled "Web3.0 Promotes Diversification of Financial Products" that although Hong Kong's ETF market is still in its development stage compared to the United States, it has established a mature architecture, including exchanges, market makers, primary and secondary custodians, etc. The Hong Kong Securities and Futures Commission has approved six virtual asset spot ETFs and 14 virtual asset spot ETFs, including Hong Kong dollars, US dollars, and renminbi categories, for trading on platforms holding the Hong Kong Securities and Futures Commission license. Nowadays, more and more global investors are paying attention to how to invest in virtual assets, and both the United States and Hong Kong, China have approved the listing of ETF funds for virtual assets, and the investment scale is rapidly increasing.

  • Bloomberg ETF Analyst: XRP ETF may be the next exchange-traded fund product to be launched

    Bloomberg ETF analyst James Seyffart forwarded market news on X platform, stating that during the Bitcoin 2024 conference, Discover Crypto CEO Joshua Jake was interviewed and he said that XRP ETF could be the next possible exchange-traded fund product to launch.

  • Hong Kong's financial industry may study launching stablecoin trading desks and institutional custody services

    Hong Kong Monetary Authority recently announced the list of participants in the stablecoin issuer sandbox, including JD Coin Chain, Circle Coin Innovation, Standard Chartered Bank, Anni Group, Hong Kong Telecom and other institutions. Research reports released by Zeng Shengjun, a researcher at the Greater Bay Area Financial Research Institute of the Shenzhen Branch of Bank of China, and Guan Zhenqiu, a researcher at the Hong Kong Financial Research Institute of Bank of China, analyzed that the Hong Kong dollar stablecoin can improve the efficiency and inclusiveness of the Hong Kong financial system. Its stability, free convertibility, high security, high open source and cross-border mobility can provide support for a wider range of financial innovations.

  • Bitcoin scaling network Mezo completes $7.5 million in financing, led by Ledger Cathay Fund

    Bitcoin scaling network Mezo has completed a $7.5 million financing round, with Ledger Cathay Fund leading the investment and Mantle EcoFund ecosystem projects from ArkStream Capital, Aquarius Fund, Flowdesk, GSR, Origin Protocol, and Bybit participating. This round of financing brings its total funding to $30 million.The new funds will be used for Mezo's plan to expand the adoption of its network, including integrating more products into its network, such as its Bitcoin staking platform Acre.

  • As of July 25, BlackRock IBIT held more than 338,000 bitcoins, an increase of more than 1,092 bitcoins from the previous day.

    BlackRock's official update on the Bitcoin ETF shows that as of July 25th, the market value of IBIT has reached $21,890,121,436.41, and the position has increased to 338,128.5551 BTC, an increase of 1,092.7881 BTC from the previous trading day.

  • The U.S. core PCE price index rose 0.2% in June, compared with expectations of 0.1% and the previous value of 0.10%.

    The US core PCE price index for June was 0.2%, exceeding expectations of 0.1% and the previous value of 0.10%; the US core PCE price index for June recorded a year-on-year increase of 2.6%, higher than expected. The US core PCE price index for June recorded a monthly rate of 0.1%, unchanged from the previous month and in line with expectations.

  • LayerPixel Completes $2 Million Seed Round Led by Kenetic Capital

    LayerPixel, a DeFi solution based on TON, announced the completion of a $2 million seed round of financing, led by Kenetic Capital, with participation from Foresight Ventures, Waterdrip Capital, VentureSouq, Web3 Port Foundation, Microcosm Research, TMM Club, and dozens of angel investors. It is reported that this funding will help LayerPixel accelerate the development and integration of its DeFi solution suite in the Telegram Mini App ecosystem, fundamentally changing the way users interact with decentralized finance in the Telegram environment.

  • Grayscale GBTC holdings are approximately 271,200 BTC, and the number of ETHE shares in circulation has fallen below 300 million

    Official data from Grayscale shows that as of July 25th, Grayscale GBTC holds 271,212.2467 BTC, a decrease of 410.3257 BTC from the previous trading day, with an asset management scale (non-GAAP) of $17,542,084,056.48 and a circulation share of 306,180,100 shares; Grayscale ETHE holds 2,391,684.2607 ETH, a decrease of 97,390.7166 ETH from the previous trading day, with an asset management scale (non-GAAP) of $7,468,775,526.14 and a circulation share of 282,168,500 shares; Grayscale ETH holds 310,308.0733 ETH, an increase of 13,663.3797 ETH from the previous trading day, with an asset management scale (non-GAAP) of $969,033,154.46 and a circulation share of 329,308,500 shares.

  • US Senator Withdraws Support for Elizabeth Warren's Anti-Crypto Bill

    On July 24th local time, Republican Senator Roger Marshall withdrew his support for the "Digital Asset Anti-Money Laundering Act," which he and Democratic Senator Elizabeth Warren jointly formulated for 2022, aimed at regulating the cryptocurrency industry under existing anti-money laundering and anti-terrorism financing frameworks. Currently, according to the official congressional record on the bill, there are still 18 senators supporting the bill.

  • Web3 startups raised $3.7 billion in funding in the first half of 2024, showing signs of recovery

    According to the latest report from Crunchbase, Web3 startups raised $3.7 billion in the first half of 2024. Although this number decreased by 18% compared to the first half of 2023, it increased by 42% compared to the second half of last year. Quarterly, Web3 startups raised over $2 billion in the second quarter of 2024, slightly higher than the $1.8 billion raised in the first quarter, but down 18% from the $2.2 billion raised in the same period last year. However, after eight consecutive quarters of decline, Web3 startups have seen two consecutive quarters of funding increases. In addition, although the total amount of funding has increased, there have been few large financing rounds, with only seven rounds raising over $50 million.