Created
May 30, 2021 10:07
-
-
Save jbaylina/4051109710fdf326067e58294b6c691a to your computer and use it in GitHub Desktop.
Explain how to write conditions in circom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// THIS IS BAD | |
template BadExample() { | |
signal input a; | |
signal input b; | |
signal output c; | |
if (a==1) { | |
c <== b*b; | |
} else { | |
c <== b+5; | |
} | |
} | |
component main = BadExample() | |
/// THIS IS GOOD | |
include "node_modules/circomlib/circuits/mux1.circom"; | |
include "node_modules/circomlib/circuits/comparators.circom"; | |
template GoodExample() { | |
signal input a; | |
signal input b; | |
signal output c; | |
component eq1 = IsEqual() | |
eq1.in[0] <== a; | |
eq1.in[1] <== 1; | |
component mux1 = Mux1(); | |
mux1.s <== eq1.out; | |
mux1.c[0] <== b*b; | |
mux1.c[1] <== b+5; | |
c mux1.out; | |
} | |
component main = GoodExample() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment