fixes Decoder template adding missing check #81
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Decoder template misses a check, generating a R1CS constraint system that admits multiple outputs for the same input. For example, in case it is instantiated with w = 2 then the generated constraint system
admits multiple solutions for the input inp = 1:
The proposed solution adds the missing check satisfying the same specification for the template.
However, as adding the check increments the number of non-linear constraints, the proposed solution also defines a new template (Decoder_strict) that can be used to optimize the number of non-linear constraints when the only solutions that are valid are the ones where success == 1. This condition appears in the template Multiplexer that represents the main use of Decoder in the circomlib.
The template Decoder_strict satisfies the following specification:
for i in 0..w: out[i] = 1 if i = inp, else out[i] = 0
The number of constraints after compiling using --O2 of each one of the templates is: