General Aliascheck template - #148
Open
clararod9 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR introduces an improved version of the Aliascheck() template. This implementation overcomes two major limitations of the current circomlib implementation:
Flexibility: the current version of the Aliascheck template only works for the bn128 finite field and produces incorrect results if it is applied to other finite fields. While there are other implementations of the Aliascheck template for other finite fields, this PR introduces the first generalized implementation that can be applied to any finite field.
Performance: the new template significantly reduces the number of non-linear R1CS constraints required, lowering circuit compilation and proving costs.
The reductions obtained for the goldilocks and bn128 primes are the following:
Non-linear constraints
Intuition:
To verify that an input$x$ is valid and cannot be used in an alias attack, we must ensure that $x \le p - 1$ . Instead of performing this check bit-by-bit, we decompose $C = p - 1$ into its Run-Length Encoding (RLE) of contiguous identical bits. Then, let $n$ be the number of blocks $C$ , we split the bits of the input in the same $n$ blocks, and we get $C_0,...,C_{n-1}$ from $C$ and $B_0,...,B_{n-1}$ from the input. We then perform comparisons on these blocks:
Block comparison
If$C_i$ is a block of 1's: We compute the sum of the bits of the input block $B_i$ . We check if all bits are 1 by comparing whether the sum equals the block length. If so, the block $B_i$ matches the corresponding block $C_i$ . Otherwise, it is smaller.
If$C_i$ is a block of 0's in $C$ : We compute the sum of the bits of the input in that block. We check if all bits are 0 by comparing whether the sum is zero. If so, the block $B_i$ matches the corresponding block $C_i$ . If not, it is greater.
Optimization: If a block is only 1 bit long, we evaluate the bit directly.
Chain comparison
We aggregate the comparison results of the blocks backwards from the LSB to the MSB. Let n be the number of blocks of$C$ . Then for all i in {0..m-1} the signal accum[i] is 0 if and only if $B_0,...,B_i$ is smaller than or equal to $C_0,...,C_i$ .
We encode this as follows:
Number of non-linear constraints
The number of non-linear constraints in the template depends on the number of blocks in the decomposition of$p - 1$ . We can compute it as follows:
where$C_{\text{NL}}$ is the number of non-linear constraints in the R1CS system, $B_{\text{size}>1}$ is the number of blocks in the decomposition of $p - 1$ with a size greater than 1, and $B$ is the total number of blocks in the decomposition.