0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

circom+snarkjsのセットアップ

Last updated at Posted at 2025-09-01

実行環境

  • コマンドプロンプト

1. Circomのインストール

Circomのcloneとbuild

git clone https://github.com/iden3/circom.git
cd circom
cargo build --release
cargo install --path circom
cd ../

2. プロジェクトの準備

プロジェクトの準備とcircomlib, snarkjsのインストール

npm init -y
npm i circomlib
npm i snarkjs

必要なフォルダを作成

<PJ>に好きな名前を入れる

set PJ=<PJ>
mkdir build\%PJ%\json
mkdir build\%PJ%\zkey

ptauファイルのダウンロード

以下のサイトからptauファイルをダウンロードする
ファイルはプロジェクトディレクトリに置く

3. 回路の作成

任意の回路を作成

build/%PJ%/%PJ%.circomに保存する
下の回路はa+b=10であることを証明する

pragma circom 2.0.0;

template Add10() {
  signal input a;
  signal input b;
  signal output out;

  out <== a + b;
  out === 10;
}

component main = Add10();

inputをjson形式で作成

build/%PJ%/json/配下に保存する

{
    "a": 4,
    "b": 6
}

回路のコンパイル

circom ./build/%PJ%/%PJ%.circom --wasm --r1cs -o ./build/%PJ%

証明キー(zkey)の生成

ptauファイルの名前はダウンロードしたものに合わせる

npx snarkjs groth16 setup ./build/%PJ%/%PJ%.r1cs ppot_0080_14.ptau ./build/%PJ%/zkey/%PJ%.zkey

4. 証明の生成と検証

witness生成

node ./build/%PJ%/%PJ%_js/generate_witness.js ./build/%PJ%/%PJ%_js/%PJ%.wasm ./build/%PJ%/json/input.json ./build/%PJ%/witness.wtns

証明の生成

snarkjs groth16 prove ./build/%PJ%/zkey/%PJ%.zkey ./build/%PJ%/witness.wtns ./build/%PJ%/json/proof.json ./build/%PJ%/json/public.json

検証鍵の生成

npx snarkjs zkey export verificationkey ./build/%PJ%/zkey/%PJ%.zkey ./build/%PJ%/json/verification_key.json

証明の検証

snarkjs groth16 verify ./build/%PJ%/json/verification_key.json ./build/%PJ%/json/public.json ./build/%PJ%/json/proof.json

5. 参考記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?