Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] field shift op bug #64

Open
Dreamerryao opened this issue Aug 19, 2022 · 0 comments
Open

[bug] field shift op bug #64

Dreamerryao opened this issue Aug 19, 2022 · 0 comments

Comments

@Dreamerryao
Copy link

In the shift operation, bit length is compared to partition, but this is not reasonable.
For example, let p = 17, a = 5 and b = 6. Then run the following code, which will shift the 5 six bits to the left, but we're still looking for a rightward shift.
Therefore, we should use p/2 as our criterion, as described in the circom documentation.
image

Existing implementation:

shr(a, b) {
        if (b.lt(this.bitLength)) {
            return a.shiftRight(b);
        } else {
            const nb = this.p.minus(b);
            if (nb.lt(this.bitLength)) {
                return this.shl(a, nb);
            } else {
                return bigInt.zero;
            }
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant