-
Notifications
You must be signed in to change notification settings - Fork 6
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 sha512 precompiles #179
Conversation
These versions are essentially just copies of their 32-bit counterparts, made to work with a Word64 type. It's not as nice as a fully generic version
Also add Xor64 operation, fix typo in Add64, add simple test
8fd3df0
to
2d76929
Compare
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.
There are a few things that could be optimized, but that can be done at a later time. Nice work!
local.is_real, | ||
); | ||
let reduced_prev_i = local.i_mem.prev_value().reduce::<AB>(); | ||
builder |
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.
We should be able to trust i
since it's coming from the Rust code that calls compress
); | ||
|
||
// Calculate temp1 := h + S1 + ch + k[i] + w[i]. | ||
Add64Operation::<AB::F>::eval( |
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.
Just making a note, but the Add
operation does not need to range check the inputs since we can assume they are bytes (either as an XOR result or because they come from the ZKVM)
); | ||
|
||
// Calculate temp1 := h + S1 + ch + k[i] + w[i]. | ||
Add64Operation::<AB::F>::eval( |
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.
We could also use an Add4
gadget
Not very useful considering it will almost always overflow. Can be added back if necessary.
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.
LGTM
Companion PR: argumentcomputer/RustCrypto-hashes#1 and argumentcomputer/zk-light-clients#256
This PR adds two new syscalls, for SHA-512 extend and compress operations.
Due to the large amount of byte lookups performed per instruction, these instructions all perform a single iteration of the main loop of its corresponding iteration. This means the library code must call these in a loop to perform the entire operation (see the companion PR for how that is done).
Additionally, this PR adds the following types and operations geared towards 64-bit words:
Word64<T>
, the 64-bit variant ofWord<T>
Add64Operation
,Xor64Operation
,And64Operation
,Not64Operation
: trivial 64-bit variants of their 32-bit counterpartsFixedRotateRight64Operation
andFixedShiftRight64Operation
: the 64-bit counterpart to the 32-bit operations. Required minor changes compared to the 32-bit versionIt should be possible to make the above types more generic in the future (for example, making
Word<T>
generic over the word width), but this would make the PR modify much more of the codebase than it does, just for minor type changes around these operations. Making new operations based on the existing ones is the simpler option that makes it clear where and how these operations are used.