기본 콘텐츠로 건너뛰기

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.

댓글

이 블로그의 인기 게시물

Windows에 AMP와 MediaWiki 설치하기

1. 들어가기     AMP는 Apache + MySQL +  Perl/PHP/Python에 대한 줄임말이다. LAMP (Linux + AMP)라고 하여 Linux에 설치하는 것으로 많이 소개하고 있지만 Windows에서도 간편하게 설치하여 사용할 수 있다.       이 글은 Windows 7에 Apache + MySQL + PHP를 설치하고 그 기반에서 MediaWiki를 설치하여 실행하는 과정을 간략히 정리한 것이다. 2. MySQL     * 버전 5.6.12     1) 다운로드         http://dev.mysql.com/downloads/installer/         MySQL Installer 5.6.12         Windows (x86, 32-bit), MSI Installer         (mysql-installer-web-community-5.6.12.0.msi)     2) 다운로드한 MSI 파일을 더블클릭하여 설치를 진행한다.           설치 위치:                   C:\Program Files\MySQL               선택 사항:                       Install MySQL Products             Choosing a Se...

MATLAB Rutime 설치하기

MATLAB Rutime 설치하기 미설치시 에러 MATLAB Runtime 을 설치하지 않은 환경에서 MATLAB 응용프로그램이나 공유 라이브러리를 사용하려고 하면 아래와 같은 에러 메시지가 표시될 것입니다. 처리되지 않은 예외: System.TypeInitializationException: 'MathWorks.MATLAB.NET.Utility.MWMCR'의 형식 이니셜라이저에서 예 외를 Throw했습니다. ---> System.TypeInitializationException: 'MathWorks.MATLAB.NET.Arrays.MWArray'의 형식 이니셜라이저에서 예외를 Throw했습니다. ---> System.DllNotFoundException: DLL 'mclmcrrt9_3.dll'을(를) 로드할 수 없습니다. 지정된 모듈을 찾을 수 없습니다. (예외가 발생한 HRESULT: 0x8007007E) 위치: MathWorks.MATLAB.NET.Arrays.MWArray.mclmcrInitialize2(Int32 primaryMode) 위치: MathWorks.MATLAB.NET.Arrays.MWArray..cctor() --- 내부 예외 스택 추적의 끝 --- 위치: MathWorks.MATLAB.NET.Utility.MWMCR..cctor() --- 내부 예외 스택 추적의 끝 --- 위치: MathWorks.MATLAB.NET.Utility.MWMCR.processExiting(Exception exception) 해결 방법 이 문제를 해결하기 위해서는 MATLAB Runtime 을 설치해야 합니다. 여러 가지 방법으로 MATLAB Runtime 을 설치할 수 있습니다. MATLAB 이 설치되어 있는 경우에는 MATLAB 설치 폴더 아래에 있는 MATLAB Runtime 설치 프로그램을 실행하여 설치합니다. ...

Wi-Fi 카드 2.4GHz로만 동작시키기

Wi-Fi 카드 2.4GHz로만 동작시키기 별도의 Wi-Fi AP 장치를 두지 않고 아래와 같은 기기들로만 Wi-Fi 네트워크를 구성하고자 할 때 주변 기기들이 2.4GHz만 지원하기 때문에 PC에서 실행하는 AP가 항상 2.4GHz를 사용하도록 Wi-Fi 카드를 설정해 주어야 합니다. 기기 Wi-Fi 카드 주파수 대역 Wi-Fi Direct 지원 PC (Windows 10) 2.4GHz, 5GHz O 주변 기기들 2.4GHz X Wi-Fi 카드별 주파수 대역 선택 방법 Windows 시작 메뉴에서 설정 을 클릭합니다. Windows 설정 화면에서 네트워크 및 인터넷 을 클릭합니다. 설정 화면의 왼쪽 메뉴바에서 Wi-Fi 를 클릭합니다. 화면 오른쪽 관련 설정 구역에 있는 어댑터 옵션 변경 을 클릭합니다. 설정을 바꾸고자 하는 Wi-Fi 카드 항목을 선택하고 마우스 오른쪽을 누른 다음 속성 메뉴를 클릭합니다. 대화상자의 네트워킹 탭 화면에 있는 구성 버튼을 클릭합니다. 장치 속성 대화상자의 고급 탭 화면으로 이동합니다. 제시되는 속성 항목들은 제품별로 다르며 자세한 사항은 아래의 제품별 설명을 참고하여 값을 설정하시기 바랍니다. Intel Dual Band Wireless-AC 7265 기술 사양 주파수 대역: 2.4GHz, 5GHz 무선 표준: 802.11ac 주파수 대역 선택 장치 속성 대화상자에서 아래와 같이 선택합니다. Wireless Mode 1. 802.11a => 5GHz 4. 802.11b/g => 2.4GHz (이 항목 선택) 6. 802.11a/b/g => 2.4GHz, 5GHz Intel Dual Band Wireless-AC 8265 기술 사양 주파수 대역: 2.4GHz, 5GHz 무선 표준: 802.11ac 주파수 대역 선택 장치 속성 대화상자에서 아래와 같이 ...