기본 콘텐츠로 건너뛰기

snarkjs 예제로 영지식 증명 시작하기 (1)

snarkjs 예제로 영지식 증명 시작하기 (1)

snarkjs README.md 문서를 따라하면서 작성한 문서입니다.

실습 환경:

  • Windows 11
  • Node.js v20.18.0
  • circom compiler 2.1.9
  • snarkjs@0.7.5

1. 소프트웨어 설치

  1. Downloads 페이지에서 circom Windows binary를 클릭하고 파일 circom-windows-amd64.exe 를 원하는 디렉토리에 저장합니다. 파일 크기는 약 10MB입니다. 여기서는 파일 이름을 circom.exe로 바꾸고 아래 경로에 저장합니다.
    C:\DevTools\circom.exe
    
  2. snarkjs를 설치합니다.
    npm install -g snarkjs
    

2. 신뢰 설정 - Powers of Tau

  1. “powers of tau” ceremony 시작

    snarkjs powersoftau new bn128 14 pot14_0000.ptau -v
    
  2. 첫 번째 기여

    snarkjs powersoftau contribute pot14_0000.ptau pot14_0001.ptau --name="First contribution" -v
    
  3. 두 번째 기여

    snarkjs powersoftau contribute pot14_0001.ptau pot14_0002.ptau --name="Second contribution" -v -e="some random text"
    
  4. 세 번째 기여

    snarkjs powersoftau export challenge pot14_0002.ptau challenge_0003
    snarkjs powersoftau challenge contribute bn128 challenge_0003 response_0003 -e="some random text"
    snarkjs powersoftau import response pot14_0002.ptau response_0003 pot14_0003.ptau -n="Third contribution name"
    
  5. 프로토콜 검증

    snarkjs powersoftau verify pot14_0003.ptau
    
  6. 무작위 비콘 적용

    snarkjs powersoftau beacon pot14_0003.ptau pot14_beacon.ptau 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 10 -n="Final Beacon"
    

3. 회로 생성

  1. 회로 파일 작성

    pragma circom 2.0.0;
    
    template Multiplier(n) {
        signal input a;
        signal input b;
        signal output c;
    
        signal int[n];
    
        int[0] <== a*a + b;
        for (var i=1; i<n; i++) {
            int[i] <== int[i-1]*int[i-1] + b;
        }
    
        c <== int[n-1];
    }
    
    component main = Multiplier(1000);
    
  2. 컴파일

    circom --r1cs --wasm --c --sym --inspect circuit.circom
    

4. 신뢰 설정 - Phase 2

  1. Phase 2 준비

    snarkjs powersoftau prepare phase2 pot14_beacon.ptau pot14_final.ptau -v
    
  2. 마지막 ptau 검증

    snarkjs powersoftau verify pot14_final.ptau
    
  3. .r1cs 파일과 연관된 .zkey 파일 생성

    snarkjs groth16 setup circuit.r1cs pot14_final.ptau circuit_0000.zkey
    
  4. ceremony의 phase 2에 기여

    snarkjs zkey contribute circuit_0000.zkey circuit_0001.zkey --name="1st Contributor Name" -v
    
  5. 두 번째 기여

    snarkjs zkey contribute circuit_0001.zkey circuit_0002.zkey --name="Second contribution Name" -v -e="Another random entropy"
    
  6. 세 번째 기여

    snarkjs zkey export bellman circuit_0002.zkey  challenge_phase2_0003
    snarkjs zkey bellman contribute bn128 challenge_phase2_0003 response_phase2_0003 -e="some random text"
    snarkjs zkey import bellman circuit_0002.zkey response_phase2_0003 circuit_0003.zkey -n="Third contribution name"
    
  7. 무작위 비콘 적용

    snarkjs zkey beacon circuit_0003.zkey circuit_final.zkey 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 10 -n="Final Beacon phase2"
    
  8. 검증키 내보내기

    snarkjs zkey export verificationkey circuit_final.zkey verification_key.json
    

5. 증명 생성 및 검증

  1. input.json 작성

    {"a": "3", "b": "11"}
    
  2. witness 계산

    snarkjs wtns calculate circuit_js/circuit.wasm input.json witness.wtns
    
  3. 증명 생성

    snarkjs groth16 prove circuit_final.zkey witness.wtns proof.json public.json
    
  4. 증명 검증

    snarkjs groth16 verify verification_key.json public.json proof.json
    

Written with StackEdit.

댓글

이 블로그의 인기 게시물

Llama 3.2로 문장 생성 및 챗팅 완성 실습

Llama 3.2로 문장 생성 및 챗팅 완성 실습 Running Meta Llama on Linux 문서의 내용을 참고하여 Llama 3.2 1B 모델로 다음 두 가지 기능을 실습합니다. 문장 완성 챗팅 완성 실습 환경 Ubuntu 20.04.6 LTS Python 3.12.7 Llama3.2-1B, Llama3.2-1B-Instruct rustc 1.83.0 NVIDIA RTX 4090 24GB 프로그램 준비 실습에서 사용할 wget , md5sum 설치 sudo apt-get install wget sudo apt-get install md5sum NVIDIA GPU 설치 여부 확인 nvidia-smi 실습 디렉토리 만들기 mkdir llama3-demo cd llama3-demo git clone https://github.com/meta-llama/llama3.git Python 3.10 이상의 버전으로 가상환경 만들고 활성화 python -m venv llama-venv . llama-venv/bin/activate Rust 컴파일러 설치 How To Install Rust on Ubuntu 20.04 문서를 참고하여 Rust 컴파일러를 설치합니다. curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh 위 명령을 실행하면 아래와 같이 세 가지 선택 옵션이 나타나는데 그냥 엔터를 쳐서 1번 옵션으로 진행합니다. ... 1) Proceed with installation (default) 2) Customize installation 3) Cancel installation 아래 명령을 실행하여 현재 쉘에 반영하고 설치된 컴파일러 버전을 확인합니다. source $HOME/.cargo/env rustc --version 의존 라이브러리 설치 pip install ...

Intel MKL 예제를 Microsoft Visual C++로 빌드하기

Intel MKL 예제를 Microsoft Visual C++로 빌드하기 인텔 프로세서 시스템에서 아래의 영역에 해당하는 수학 계산을 빠르게 수행하고자 한다면 Intel MKL 라이브러리를 사용할 수 있습니다. Linear Algebra Fast Fourier Transforms (FFT) Vector Statistics & Data Fitting Vector Math & Miscellaneous Solvers 이 문서는 Intel MKL 이 제공하는 예제 파일을 Microsoft Visual C++ 로 컴파일하고 링크하여 실행 파일을 만드는 과정을 소개합니다. 빌드 환경 다음은 이 문서를 작성하는 과정에서 Intel MKL 예제를 빌드하기 위하여 사용한 환경입니다. 시스템 운영체제: Windows 10 (64비트) 프로세서: Intel Core i7 설치 제품 IDE: Microsoft Visual Studio Community 2019 (version 16) 라이브러리: Intel Math Kernel Library 2019 Update 5 환경 변수 명령 프롬프트 창을 엽니다. 아래 스크립트를 실행하여 환경 변수 INCLUDE , LIB , 그리고 PATH 를 설정합니다. @echo off set CPRO_PATH=C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows set MKLROOT=%CPRO_PATH%\mkl set REDIST=%CPRO_PATH%\redist set INCLUDE=%MKLROOT%\include;%INCLUDE% set LIB=%MKLROOT%\lib\intel64;%LIB% set PATH=%REDIST%\intel64\mkl;%PATH% REM for OpenMP intel thread set LIB=%CPRO_PATH%\compiler\lib...

Hugo로 생성한 정적 웹사이트를 GitHub Pages로 호스팅하기

Hugo로 생성한 정적 웹사이트를 GitHub Pages로 호스팅하기 Hugo 프레임워크에 DocDock 테마를 추가하여 정적 웹사이트를 만들고 이를 GitHub 저장소에 올려서 GitHub Pages 로 호스팅하는 과정을 정리하였습니다. 1. 제품 소개 Hugo 정적 웹사이트를 생성하는 도구. Go 언어로 개발됨. DocDock 기술 문서 작성을 위한 Hugo용 테마. Learn 테마를 기반으로 함. GitHub Pages 정적 웹사이트 호스팅 서비스를 무료로 제공. GitHub 저장소와 직접 연결. 개인, 조직, 프로젝트 유형에 따른 페이지 제공. 사이트 저장 용량은 최대 1GB. 2. Hugo와 DocDock 설치 다음과 같은 환경에서 설치를 진행하고 이 문서를 작성하였습니다. 프로세서: Intel Core i5 (x64 기반) 운영체제: Windows 10 (64 비트) 1) Hugo 설치 Hugo Releases 페이지에서 다음 파일을 다운로드하고 압축을 풉니다. 이 글을 작성하는 시점의 최신 출시는 0.56.0 버전입니다. hugo_x.x.x_Windows-64bit.zip 압축을 푼 폴더를 환경 변수 PATH 에 추가합니다. 2) 새 사이트 생성 사이트를 생성하고자 하는 폴더에서 명령 프롬프트 창을 엽니다. 다음과 같이 명령을 실행하여 새 Hugo 사이트를 생성합니다. C:\Temp>hugo new site quickstart Congratulations! Your new Hugo site is created in C:\Temp\quickstart. Just a few more steps and you're ready to go: 1. Download a theme into the same-named folder. Choose a theme from https://themes.gohugo.io/ or ...