Skip to content

support left shift or right shift operator#241

Closed
Lynette7 wants to merge 2 commits into
zksecurity:mainfrom
Lynette7:feat/support-left-shift-or-right-shift-operator
Closed

support left shift or right shift operator#241
Lynette7 wants to merge 2 commits into
zksecurity:mainfrom
Lynette7:feat/support-left-shift-or-right-shift-operator

Conversation

@Lynette7
Copy link
Copy Markdown

@Lynette7 Lynette7 commented Dec 8, 2024

Resolves #181

To implement right-shift and left-shift operators, here are the changes I've made:

  • Added token recognition for << and >> in the lexer
  • Extended Op2 enum to include RightShift and LeftShift
  • Updated the parser to recognize and handle bit shift tokens
  • Modified type checker to support the shift operations
  • Implemented circuit writer logic for bit shifts using field arithmetic
  • Implemented bit shift operations for field elements, supporting constant value shifts and cell variable shifts with constant shift amounts
  • Added bitwise shift operations using logical shift right (Lshr) and shift left (Shl) in circuit IR generation

@katat
Copy link
Copy Markdown
Contributor

katat commented Dec 10, 2024

Thanks for addressing this.

I realized this feature can be complicated to support in the constraint level, because the unit in that level is finite field. It makes sense to support logical shifting in finite field, but that can be confusing from user perspective since they might assume they are arithmetic shifting.

Therefore, I think for now we can just make it support in the hint function. That is the feature can be implemented in the ir.rs, which is based on Circ term.

Also please add tests in the examples.

@katat
Copy link
Copy Markdown
Contributor

katat commented Jan 6, 2025

This feature for hint functions has been implemented in another PR #253
Thanks a lot for attempting this!

@katat katat closed this Jan 6, 2025
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

Successfully merging this pull request may close these issues.

Support << left shift or >> right shift operator

2 participants