Skip to content

[Bug] Incorrect LessThan bit-widths when comparing against constants #289

@Mag041108

Description

@Mag041108

File: packages/circuits/helpers/reveal-substring.circom
Commit: 800b9a1

LessThan(n) requires inputs to be in [0, 2^n − 1] (it Num2Bits-decomposes the inputs).
The code compute n = log2Ceil(x) as the minimal bitlength, and x is one of the input of LessThan. But when x is powers of two, this can cause overflow.

For example,
signal isSubstringStartIndexValid <== LessThan(log2Ceil(maxLength))([substringStartIndex, maxLength]);
Here, n = log2Ceil(maxLength), and x = maxLength. If maxLength is a power of two, i.e., x = 2^n, then LessThan can only receive inputs within the range [0, 2^n - 1]. However, since x = 2^n is also an input to LessThan, this creates an overflow issue.

Fix: choose n so that the maximum possible input is strictly less than 2^n. In above case, you can fix the problem with n = log2Ceil(maxLength + 1).

Same problem also exists in isSubstringLengthValid and isSumValid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions