mirror of
https://github.com/factorgroup/nightmarket.git
synced 2026-01-13 23:48:17 -05:00
33 lines
837 B
Plaintext
33 lines
837 B
Plaintext
pragma circom 2.0.3;
|
|
|
|
include "calculateTotal.circom";
|
|
|
|
template QuinSelector(choices) {
|
|
signal input in[choices];
|
|
signal input index;
|
|
signal output out;
|
|
|
|
// Ensure that index < choices
|
|
component lessThan = LessThan(4);
|
|
lessThan.in[0] <== index;
|
|
lessThan.in[1] <== choices;
|
|
lessThan.out === 1;
|
|
|
|
component calcTotal = CalculateTotal(choices);
|
|
component eqs[choices];
|
|
|
|
// For each item, check whether its index equals the input index.
|
|
for (var i = 0; i < choices; i ++) {
|
|
eqs[i] = IsEqual();
|
|
eqs[i].in[0] <== i;
|
|
eqs[i].in[1] <== index;
|
|
|
|
// eqs[i].out is 1 if the index matches. As such, at most one input to
|
|
// calcTotal is not 0.
|
|
calcTotal.in[i] <== eqs[i].out * in[i];
|
|
}
|
|
|
|
// Returns 0 + 0 + 0 + item
|
|
out <== calcTotal.out;
|
|
}
|