From 9d2918e5972dbcfb9e435add2043df4ff2c5cc97 Mon Sep 17 00:00:00 2001 From: clararod9 Date: Thu, 6 Oct 2022 14:56:52 +0200 Subject: [PATCH 1/2] fixes decoder adding missing check --- circuits/multiplexer.circom | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/circuits/multiplexer.circom b/circuits/multiplexer.circom index 848e31e4..b26922e1 100644 --- a/circuits/multiplexer.circom +++ b/circuits/multiplexer.circom @@ -62,6 +62,8 @@ function log2(a) { pragma circom 2.0.0; +include "comparators.circom"; + template EscalarProduct(w) { signal input in1[w]; signal input in2[w]; @@ -80,15 +82,17 @@ template Decoder(w) { signal output out[w]; signal output success; var lc=0; + + component checkZero[w]; for (var i=0; i success; - success * (success -1) === 0; } From 47b2c4ec776c0a0845fedc00e9dfccaf2ba7ff08 Mon Sep 17 00:00:00 2001 From: clararod9 Date: Sat, 8 Oct 2022 10:45:14 +0200 Subject: [PATCH 2/2] improving decoder, adding decoder_strict --- circuits/multiplexer.circom | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/circuits/multiplexer.circom b/circuits/multiplexer.circom index b26922e1..68c7549e 100644 --- a/circuits/multiplexer.circom +++ b/circuits/multiplexer.circom @@ -77,6 +77,13 @@ template EscalarProduct(w) { out <== lc; } +// in case inp >= w then witness = 0, in other case witness = 1, out[i] = 1 if i = inp and 0 otherwise +/* +Specification: + - Success := w < inp + - for i in 0..w: out[i] = 1 if i = inp, else out[i] = 0 +*/ + template Decoder(w) { signal input inp; signal output out[w]; @@ -95,12 +102,34 @@ template Decoder(w) { lc ==> success; } +// in case inp >= w does not accept any solution -> does not generate witness +/* +Specification: + In case inp < w: + - for i in 0..w: out[i] = 1 if i = inp, else out[i] = 0 + If w >= inp => the sysetm of constraints does not have any solution +*/ +template Decoder_strict(w) { + signal input inp; + signal output out[w]; + var lc=0; + + for (var i=0; i out[j]; } - dec.success === 1; } +