var和signal之间的差异? #45
Answered
by
lkiversonlk
Xor0v0
asked this question in
Q&A(提问题在隔壁~)
-
var和signal之间的差异?为了搞清楚两者之间的差异,我阅读circom官方文档,希望大佬指正我的理解并解答困惑:
template IsZero () {
signal input in;
signal output out;
var inv; // 官方文档是写的signal inv;
inv <-- in != 0 ? 1/in : 0;
out <== -inv * in + 1;
// out*in === 0; 因为 inv 不可修改,无需考虑inv被恶意prover修改的情况。
} |
Beta Was this translation helpful? Give feedback.
Answered by
lkiversonlk
Mar 6, 2023
Replies: 2 comments 1 reply
-
var你可以理解成一个占位符,方便你写circom,最后约束系统里如果用到需要展开成原来的样子。
这么写最后你就有一个约束是:
但是这个约束不正确,因为约束力只能有+,*运算 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Xor0v0
-
补充一下,var的赋值应该用“=”,“<--”只适用于signal。将var用于constraint的时候,要保证var的运算满足quadratic constraints。 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var你可以理解成一个占位符,方便你写circom,最后约束系统里如果用到需要展开成原来的样子。
这么写最后你就有一个约束是:
但是这个约束不正确,因为约束力只能有+,*运算