ZKP Circom (1)

2023-12-09 03:45
文章标签 zkp circom

本文主要是介绍ZKP Circom (1),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

MIT IAP 2023 Modern Zero Knowledge Cryptography

Lecture 2: Circom 1 (Brain Gu)

  • Review zkSNARKs
    在这里插入图片描述

    • Properies
      • zk: hides inputs
      • Succinct: generates short proofs that can be verified quickly
      • Noninteractive: doesn’t require a back-and-forth
      • ARgument of Knowledge: proves you know the input
  • Generate a ZKP for satisfiability of the R1CS

    • x_i + x_j = x_k
    • x_i * x_j = x_k
  • zkSNARKs Example
    在这里插入图片描述

  • zkSNARKs prove constraints

    • Example 1
      在这里插入图片描述

    • Example 2
      在这里插入图片描述

在这里插入图片描述

- A bug in the code: x3 should be constrained to x3 != 0
  • Circom Demo
    • ZKRepl: zkrepl.dev
    • Example 1
pragma circom 2.1.6;template Example() {signal input x1;signal input x2;signal input x3;signal input x4;signal input y1;signal input y2;signal input out;y1 === x1 + x2;y2 === y1 * x3;y2 === out + x4;
}component main {public [out] } = Example();/*
INPUT = {"x1" : "2","x2" : "4","x3" : "8","x4" : "5","y1" : "6","y2" : "48","out": "43"
}
*/
- Output
STDOUT: 
template instances: 1
non-linear constraints: 1
linear constraints: 0
public inputs: 1
public outputs: 0
private inputs: 6
private outputs: 0
wires: 6
labels: 8
Written successfully: ./main.r1cs
Written successfully: ./main.sym
Written successfully: ./main_js/main.wasm
Everything went okay, circom safe
Compiled in 0.32s
ARTIFACTS: 
Finished in 0.43s
main.wasm (34.45KB)
main.js (9.18KB)
main.wtns (0.27KB)
main.r1cs (0.35KB)
main.sym (0.10KB)
PLONK KEYS: 
main.plonk.zkey (13.59KB)
main.plonk.vkey.json (2.00KB)
main.plonk.sol (23.38KB)
main.plonk.html (477.04KB)
  • Example 2: Num2Bits
pragma circom 2.1.6;template Bits4(){ //range checksignal input in;signal bits[4];var bitsum = 0;for (var i = 0; i < 4; i++) {bits[i] <-- (in >> i) & 1;bits[i] * (bits[i] - 1) === 0;bitsum = bitsum + 2 ** i * bits[i];}bitsum === in;
}template Num2Bits() {signal input in;signal input b0;signal input b1;signal input b2;signal input b3;component check = Bits4();check.in <== in;in === 8 * b3 + 4 * b2 + 2 * b1 + b0;b0 * (b0 - 1) === 0;b1 * (b1 - 1) === 0;b2 * (b2 - 1) === 0;b3 * (b3 - 1) === 0;}component main { public [b0, b1, b2, b3] } = Num2Bits();/*
INPUT = {"in" : "11","b0" : "1","b1" : "1","b2" : "0","b3" : "1"
}*/
  • Output
STDOUT: 
template instances: 2
non-linear constraints: 8
linear constraints: 0
public inputs: 4
public outputs: 0
private inputs: 1
private outputs: 0
wires: 8
labels: 11
Written successfully: ./main.r1cs
Written successfully: ./main.sym
Written successfully: ./main_js/main.wasm
Everything went okay, circom safe
Compiled in 1.08s
ARTIFACTS: 
Finished in 1.16s
main.wasm (35.85KB)
main.js (9.18KB)
main.wtns (0.33KB)
main.r1cs (1.57KB)
main.sym (0.19KB)
PLONK KEYS: 
main.plonk.zkey (66.00KB)
main.plonk.vkey.json (2.00KB)
main.plonk.sol (28.36KB)
main.plonk.html (548.77KB)
  • Some improvement
pragma circom 2.1.6;template RangeCheck(nBits){ //range checksignal input in;signal bits[nBits];var bitsum = 0;for (var i = 0; i < nBits; i++) {bits[i] <-- (in >> i) & 1;bits[i] * (bits[i] - 1) === 0;bitsum = bitsum + 2 ** i * bits[i];}bitsum === in;
}template Num2Bits(nBits) {signal input in;signal input b[nBits];component check = RangeCheck(nBits);check.in <== in;var accum = 0;for (var i = 0; i < nBits; i++){accum += (2 ** i) * b[i];}in === accum;for (var i = 0; i < nBits; i++){0 === b[i] * (b[i] - 1);}}component main { public [b] } = Num2Bits(4);/*
INPUT = {"in" : "11","b": ["1","1","0","1"]
}
*/

这篇关于ZKP Circom (1)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/472351

相关文章

加密学中的零知识证明(Zero-Knowledge Proof, ZKP)到底是什么?

加密学中的零知识证明(Zero-Knowledge Proof, ZKP)到底是什么? 引言 在加密学的应用中,零知识证明(Zero-Knowledge Proof, ZKP)无疑是一颗璀璨的明星。它不仅挑战了我们对信息验证的传统认知,更在保护隐私的同时确保了数据的真实性,为数字货币、身份验证、安全通信等多个领域带来了革命性的变革。本文将深入探讨零知识证明的原理、关键技术、应用场景以及未来

密码学 | 承诺:Pedersen 承诺 + ZKP

​ 🥑原文:Toward Achieving Anonymous NFT Trading 🥑写在前面:看了篇 22 年 SCI 3 区论文,里面提到在 Pedersen 承诺的揭示阶段可以使用零知识证明,而不必揭示消息明文和随机数。姑且记录一下这个方法。 1 Pedersen 承诺 以下是原文对 Pedersen 承诺的介绍😽 ​一个承诺方案在承诺者 C 和接收者 R 之间进行

组合ZKP代价:探索ZKP中non-native域运算 最新进展

1. 引言 前序博客: 递归证明——cycles of curves是必选项? ‘Foreign field’ 或 ‘non-native field’ 算术在ZKP(zero knowledge proof零知识证明)系统中随处可见。若想使用 ZKP 进行: 布尔运算公钥密码学或 证明组合 则无疑会遇到由于foreign field运算而导致的约束爆炸。 然而,若查看Arkworks等

对话 zkPokerdot | 妙用 ZKP 技术,为链上游戏创造公平竞技场

在数字游戏的领域中,无论是沉浸于传统游戏的虚拟世界,还是探索 Web3 游戏的前沿领域,玩家们都追求拥有一场公平的对决。zkPokerdot 项目应运而生。通过 ZKP 技术,zkPokerdot 为链上游戏提供了一个既去中心化又保障隐私的公平竞技场。zkPokerdot 在 2023 冬季波卡黑客松大赛中崭露头角,在「基于 Polkadot SDK 构建区块链」赛道上赢得了二等奖的荣誉。

Reef:基于正则表达式匹配的ZKP

1. 引言 Sebastian Angel等人2023年论文《Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs》,开源代码实现见: https://github.com/eniac/Reef(Rust) Reef用于committed文档与正则表达式匹配或不匹配。可用于证明: 密码的强度尽管进行了编辑但电子邮件的

ZKP Algorithms for Efficient Cryptographic Operations 1 (MSM Pippenger)

MIT IAP 2023 Modern Zero Knowledge Cryptography课程笔记 Lecture 6: Algorithms for Efficient Cryptographic Operations (Jason Morton) Multi-scalar Multiplication(MSM) Naive: nP = (((P + P) + P) + P)… = (

ZKP Schnorr Protocol

Schnorr Protocol The Schnorr Protocol is a cryptographic protocol used for secure communication and digital signatures. It was originally proposed by Claus-Peter Schnorr in 1989 and has gained attent

ZKP Commitment (1)

MIT IAP 2023 Modern Zero Knowledge Cryptography课程笔记 Lecture 5: Commitment 1 (Ying Tong Lai) Overview: Modern SNARK IOP: Interactive Oracle ProofCommitment SchemeIOP “compiled by” the commitment sch

ZKP Understanding Nova (2) Relaxed R1CS

Understanding Nova Kothapalli, Abhiram, Srinath Setty, and Ioanna Tzialla. “Nova: Recursive zero-knowledge arguments from folding schemes.” Annual International Cryptology Conference. Cham: Springer

ZKP16 Hardware Acceleration of ZKP

ZKP学习笔记 ZK-Learning MOOC课程笔记 Lecture 16: Hardware Acceleration of ZKP (Guest Lecturer: Kelly Olson) The What and Why of Hardware Acceleration Hardware acceleration is the use of dedicated hardware