【零知识证明】构建snark电路时出现问题解决方案(circom2)

1.1 电路

pragma circom  2.0.0;

// f(x,y) = x^2 * y + x * y^2 + 17

// Signal Definition: 
// 1、所有的输入都是信号
// 2、每次将两个信号相乘时,都需要定义一个新的信号
// 3、一次只能占用两个信号来获取一个新的信号
// 4、所有的输出都是信号

// 模版
template F() {

    // Declaration of signals.
    signal input x;
    signal input y;
    signal output o;

    signal m1 <== x * x;
    signal m2 <== m1 * y;

    signal m3 <== y * y;
    signal m4 <== m3 * x;

    o <== m2 + m4 + 17;

}

//组装
component main = F();

1.2 问题

编译发现出错:

Error: Parse error on line 1:
// f(x,y) =om  2.0.0;
----------------^
Expecting 'EOF', 'function', 'IDENTIFIER', '(', ')', 'template', ',', 'if', 'else', 'for', ';', 'while', 'do', 'compute', 'return', 'include', '{', '}', '==>', '-->', '===', '?', ':', '||', '&&', '|', '^', '&', '==', '!=', '<=', '>=', '<', '>', '<<', '>>', '+', '-', '*', '/', '\\', '%', '**', '++', '--', '!', '~', 'DECNUMBER', 'HEXNUMBER', 'var', 'signal', 'component', '[', ']', got '.'
    at Parser.parseError (D:\node\node_global\node_modules\circom\parser\jaz.js:620:21)
    at Parser.parse (D:\node\node_global\node_modules\circom\parser\jaz.js:687:22)
    at constructionPhase (D:\node\node_global\node_modules\circom\src\construction_phase.js:79:22)
    at compile (D:\node\node_global\node_modules\circom\src\compiler.js:71:5)
    at run (D:\node\node_global\node_modules\circom\cli.js:119:11)
    at Object.<anonymous> (D:\node\node_global\node_modules\circom\cli.js:140:1)
    at Module._compile (node:internal/modules/cjs/loader:1356:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Module.load (node:internal/modules/cjs/loader:1197:32)
    at Module._load (node:internal/modules/cjs/loader:1013:12)
Parse error on line 1:
// f(x,y) =om  2.0.0;
----------------^
Expecting 'EOF', 'function', 'IDENTIFIER', '(', ')', 'template', ',', 'if', 'else', 'for', ';', 'while', 'do', 'compute', 'return', 'include', '{', '}', '==>', '-->', '===', '?', ':', '||', '&&', '|', '^', '&', '==', '!=', '<=', '>=', '<', '>', '<<', '>>', '+', '-', '*', '/', '\\', '%', '**', '++', '--', '!', '~', 'DECNUMBER', 'HEXNUMBER', 'var', 'signal', 'component', '[', ']', got '.'

1.3 解决方案

删除通过 "npm install circom -g" 安装的circom

使用以下内容进行安装circom:Installation - Circom 2 Documentation

步骤如下:

删除之前安装的circom,删除之后先克隆circom存储库,在命令行输入

git clone https://github.com/iden3/circom.git

 进入circom目录,使用cargo build进行编译:

cargo build --release

成功之后如图:

 接着按如下方式安装此二进制文件(注意:运行此命令时,请确保您仍在 circom 目录中):

cargo install --path circom

成功后如图所示:
 再次编译就会成功

  • 24
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

神通广大白居易

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值