Skip to content

Instantly share code, notes, and snippets.

@jbaylina
Created May 30, 2021 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbaylina/4051109710fdf326067e58294b6c691a to your computer and use it in GitHub Desktop.
Save jbaylina/4051109710fdf326067e58294b6c691a to your computer and use it in GitHub Desktop.
Explain how to write conditions in circom
// 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