grapevine-sonobe/circom/node_modules/circomlib/circuits/switcher.circom
circom/node_modules/circomlib/circuits/switcher.circomRaw
1/*
2 Copyright 2018 0KIMS association.
3
4 This file is part of circom (Zero Knowledge Circuit Compiler).
5
6 circom is a free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 circom is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with circom. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20/*
21 Assume sel is binary.
22
23 If sel == 0 then outL = L and outR=R
24 If sel == 1 then outL = R and outR=L
25
26 */
27
28pragma circom 2.0.0;
29
30template Switcher() {
31 signal input sel;
32 signal input L;
33 signal input R;
34 signal output outL;
35 signal output outR;
36
37 signal aux;
38
39 aux <== (R-L)*sel; // We create aux in order to have only one multiplication
40 outL <== aux + L;
41 outR <== -aux + R;
42}