Cointime

Download App
iOS & Android

ZKP Series: Pseudonym Input Vulnerability in Circom’s Verification Contract Has Been Replicated

Overview

Earlier, a double-spending vulnerability in a zero-knowledge proof verification contract on Semaphore was uncovered by the Russian developer, Poma. As a matter of curiosity, my intention is to replicate the vulnerability’s PoC initially. However, due to the vulnerability code being old and the project being relatively complex, I opted to create a straightforward PoC to replicate the vulnerability.

Introduction

The foundation of Zero Knowledge Proof (ZKP) technology lies in an algorithm called a “proof system”. By performing a series of computations on the message, the algorithm produces a proof to demonstrate the genuineness of the message. The recipient can confirm the message’s authenticity by verifying the proof alone, without requiring additional information.

There are various implementation schemes for ZKP technology, which we discussed in our earlier article “Technical Features of ZKP Mainstream Implementation Schemes”. In this experiment, the Circom platform is employed, which utilizes Groth16 and PlonK as its proof system. During development, developers can select either system. The development framework generates proof parameters and verification contracts automatically without circuit modification.

In simpler terms, Circom creates witness data and attestation data on the client side and submits them to the contract. The verifier.sol contract verifies the submitted data to confirm whether the proof adheres to the specified rules. This approach enables rapid, efficient, and secure verification while safeguarding the message’s content and privacy.

Vulnerability Analysis

1. There isn’t much to discuss, so let’s proceed straight to the problematic code. Please refer to the “verifyHash” function in the image below. The code enclosed in the red box indicates whether specific witness data has been utilized. This method is commonly employed to prevent double spending. However, the vulnerability has arisen in the witness data “hash1”. Normally, a particular set of proof data should only correspond to a set of “hash1” values for verification purposes.

2. The “verify” function in the “verifier.sol” contract carries out elliptic curve computation verification on the input value via the “scalar_mul()” function. This function conducts calculations on elliptic curves utilizing the input parameters and matches the resulting value against the value specified in the provided proof. The function thereby confirms whether the input value is legitimate or not.

3. In a Solidity smart contract, encoding Fq necessitates the usage of the uint256 type. However, as the maximum value of uint256 is larger than the q value, several distinct integers may correspond to the same Fq value following the modulo operation. For example, “s” and “s+q” indicate the same point, namely the “sth” point. Similarly, “s+2q” and so on are also aliases for point “s”. This phenomenon is known as “Input Aliasing”, whereby these integers serve as pseudonyms for one another.

The “q” value mentioned here pertains to the cyclic group’s order, which signifies the number of values within the same Fq that can be input with numerous large integers. In essence, even if a q value is added to the hash, it can still satisfy the verification criterion. Within the uint256 type’s scope, a maximum of uint256_max/q distinct integers can indicate the same point. This signifies that a set of proofs can have up to 5 hash1 values that match and can pass the contract’s verification.

Vulnerability Recurrence

1. Develop a basic circuit that inputs two data sets and produces a witness data, i.e., “hash1,” utilized in the contract.

2. Compile the circuit to create “circuit_final.zkey”, “circuit.wasm”, and “verifier.sol”. Afterward, generate a collection of proofs, a standard hash, and a corrupted hash.

3. Subsequently, deploy the contract and employ the “checkHash” generated earlier to conduct a verification process. The verification successfully passes.

4. Next, apply the identical witness data and the previously generated “attackHash”. It is discovered that the verification is also successful. This demonstrates that a set of proofs can feature several matching hashes that meet the contract’s verification criteria. Thus, the Circom verification contract input pseudonym vulnerability has been effectively replicated.

Solutions to Vulnerabilities

The vulnerability arises from a set of proofs that can have at most 5 hash values that match and meet the contract’s verification requirements. Thus, the bug fix is straightforward: restricting all input hashes to a value less than “q”.

Summary

Input pseudonym vulnerability is a frequently encountered vulnerability in zero-knowledge proof and cryptography implementation. Its fundamental cause lies in the value being equivalent to the remainder within the finite field. Therefore, developers must focus on the verification group’s order when creating cryptography.

Get the latest news here: Cointime channel — https://t.me/cointime_en

Comments

All Comments

Recommended for you

  • Blast DEX Thruster receives $7.5 million in seed round funding

    The decentralized trading protocol Thruster based on Blast raised $7.5 million in seed funding led by Pantera Capital, bringing Thruster's valuation to $70 million. Angel investors include Santiago Santos, Frax founder Sam Kazemian, Pendle founder TN Lee, Stacked founder Alex Lin, Renzo founder Kratik Lodha, and Axelar founder Georgios Vlachos also participated in this round of funding.

  • Hong Kong Treasury Secretary: Will submit a draft bill on stablecoin and virtual asset over-the-counter trading services to the Legislative Council

    According to a report by Caixin, Hong Kong Financial Secretary Paul Chan Mo-po introduced the expenditure budget and work focus for the fiscal year 2024-25, stating that a variety of central bank digital currency cross-border networks (mBridge) are expected to be launched this year, with the first phase of services focusing on settling cross-border transactions for enterprises using various central bank digital currencies. In addition, the "digital renminbi" will also expand its pilot scope in Hong Kong, further improving cross-border payment efficiency and user experience. In terms of virtual assets, the government is promoting a series of measures to strengthen regulation and promote the stable and responsible development of the virtual asset market in Hong Kong. Specifically, the Hong Kong Monetary Authority launched a stablecoin sandbox in March this year, allowing institutions interested in issuing stablecoins to conduct testing within a controlled range. The government has also consulted the public on the regulation of fiat-backed stablecoin issuers and virtual asset over-the-counter trading services, and is considering the feedback received. Depending on the progress of preparatory work, the draft legislation will be submitted to the Legislative Council as soon as possible.

  • Three men and women arrested for laundering more than 1.8 billion yuan from virtual currency trading platforms and bank accounts

    Hong Kong Customs broke up a money laundering syndicate and arrested three local suspects who are suspected of using virtual currency trading platforms and multiple local bank accounts opened by companies to process over 1.8 billion yuan of funds with unknown sources. Customs officials targeted the three suspects based on intelligence and launched a wealth investigation, discovering that the three individuals conducted over 1,000 suspicious transactions between June 2021 and July 2022 through the opening of multiple local companies and bank accounts, including the transfer of funds from virtual currency trading platforms, involving more than 1.8 billion yuan.

  • BTC halving countdown only 1 day left

    According to Ouke Cloud Chain data, there is only 1 day and 17 hours left until the BTC halving countdown, which is expected to occur on 2024/04/20. The current block reward is 6.25 BTC, and after the halving, the block reward will be 3.125 BTC. There are currently 253 remaining blocks, the current network hashrate is 587.96 EH/s, the network mining difficulty is 83.95 T, and the average block time is 9.94 min.

  • The total open interest of BTC options is $21.24 billion, and the open interest of ETH options is $9.42 billion.

    According to Coinglass data, the nominal value of open BTC option positions on the entire network is $21.24 billion, and the nominal value of open ETH option positions is $9.42 billion.

  • CZ launches testnet course on Giggle Academy

    CZ, the former CEO of Binance, announced the test network course of the recently launched education project Giggle Academy. CZ shared a video clip on his X account, which involved a course in an installable Android software package (Apk).

  • After the Bitcoin halving, new mining output will be reduced from 900 to 450 per day

    According to HODL15Capital's monitoring, after the halving of Bitcoin, its newly mined output will be reduced from 900 coins per day to 450 coins per day. Based on the current price, purchasing all of these new outputs would cost approximately $28 million.

  • BTC breaks through $62,000, and the intraday decline narrows to 2.96%

    According to market data, BTC has broken through $62,000 and is currently trading at $62,008.36. The intraday decline has narrowed to 2.96%, and the market is experiencing large fluctuations, so please be prepared for risk control.

  • Shanghai Municipal Party Committee Secretary: Welcome Standard Chartered to establish more new institutions, new businesses and new platforms such as blockchain in Shanghai

    Chen Jinong, the Secretary of the Shanghai Municipal Party Committee, met with Weihao Si, the Chairman of the Board of Directors of Standard Chartered Bank, and Mark William D'Arcy, the Executive Director, and some members of the Board of Directors yesterday morning. Chen Jinong stated that he welcomes Standard Chartered Bank to leverage its own advantages, strengthen strategic connections, place more new institutions, businesses, and platforms such as wealth management and blockchain in Shanghai, focus on deepening pragmatic cooperation in technology finance, green finance, digital finance, and create more application scenarios, and provide comprehensive and professional service support for enterprises to go abroad.

  • An introduction to Composable Culture, what it is and why it matters

    The current landscape of emerging technologies like blockchain, web3, ai-related solutions and others is paving the way for what I see as the rise of composable culture (or modular culture as one of my peers said1). While I have been hinting the concept in my writings before, an explanation of why an there should be an umbrella term, what are it’s characteristics and advantages is needed.