-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add bit_ror util #1375
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
feat: add bit_ror util #1375
Conversation
DavePearce
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My opinion on this, is that I understand why you've done it this way. However, adding two new functions bit_shr64 and bit_shl64 is definitely not ideal when it could be done directly with a single function bit_ror64.
The structure of bit_ror64 follows that of bit_shr, except that we don't discard the shifted bits. Specifically, consider this:
fn bit_shr256_u6(word u256, n u6) -> (res u256) {
var b u1
var m u5
var msw u256
var lsw u32
;; decompoise shift
b,m = n
;;
if b!=0 goto apply
res = bit_shr256_u5(word,m)
return
apply:
msw, lsw = word
res = bit_shr256_u5(msw,m)
return
}
Here, the lsw is simply discarded when, in fact, we need to put it back "on the top". Very roughly it would be something like this:
msw, lsw = word
res = bit_ror64_u5((2^32*lsw) + msw,m)
return
💯 I refactored |
DavePearce
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions around unnecessary carry lines, but otherwise looks good.
bit_ror64is tested on all test vectors generated by theror.gofrom the issueIt now uses the same recursion as for
bit_shrNote
Adds u64 rotate-right
bit_ror64zkasm routine with tests and vectors, and fixes a comment typo inbit_shl.testdata/asm/util/bit_ror64.zkasmimplementingbit_ror64(u64 rotate-right) via recursive bit decomposition (u5→u1) with word-split handling.testdata/asm/util/bit_ror64.accepts.pkg/test/assembly_util_test.goto runasm/util/bit_ror64(BLS12_377).testdata/asm/util/bit_shl.zkasm.Written by Cursor Bugbot for commit bcf4b73. This will update automatically on new commits. Configure here.