How to generate constraint on right shift bitwise operator in the circom circuit language?
I'm trying to do the following:
pragma circom 2.0.0;
template MAIN() {
signal input v;
signal output type;
type <== v >> 5;
}
component main = MAIN();
I'm getting the following error:
error[T3001]: Non quadratic constraints are not allowed!
┌─ "/Users/ilia/compiling/main-circom/main.circom":68:5
│
68 │ type <== v >> 5;
│ ^^^^^^^^^^^^^^^ found here
│
= call trace:
->MAIN
I think this has to do with the fact that v >> 5
expression can not be re-expressed as a quadratic expression by the circom compiler.
I struggle to rewrite the expression to be quadratic. It might involve writing assignment and constraint as two separate operations, but I'm not sure what a proper validating constraint would be for a right shift.
In terms of test cases, I expect type
to be $5$ when v
is $168$ for example.
<--
$\endgroup$type <-- v >> 5; type * 32 === v & 0xE0;
but now I get "Non quadratic constraints are not allowed" on thetype * 32 === v & 0xE0
line $\endgroup$& 1
but that's not generic enough I don't think. $\endgroup$signal check; check <-- v & 0xE0; check & 0x1F === 0;
but it's failing with "No quadratic constraints are not allowed!" again $\endgroup$