-
👋🏻👋🏻👋🏻 In my struggle coding life, I frequently encounter the need to understand and implement right shift operations, as in the examples '1111 >> 3 = 1' or '1101 >> 2 = 3'. However, in the context of Halo2 and its decompose circuit : , I'm puzzled about a specific line of code: z = (z - chunk) * Assigned::from(F::from(1u64 << LOOKUP_NUM_BITS)).invert(); In this case, why isn't the right shift operator ('>>') used instead? I mean z = (z - chunk) >> F::from(1u64 << LOOKUP_NUM_BITS) is much more clear, right ? Additionally, why can't we simply use the modulo operator ('%') to achieve bit shifting? My core problem is : I know some finite field operations may not work in circuits, what is the rule? I know we can use multiplication, addition, But I don't know when I can use left shift, right shift, modular operation |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Because |
Beta Was this translation helpful? Give feedback.
Because
<<
is not overloaded in Finite Field, actually onlyAdd, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign
are overloaded in theField
trait. Ref: https://github.com/zkcrypto/ff/blob/e853770f4843e47cd5e07330140b5bd1cdfc9f11/src/lib.rs#L41