feat: Add sha512 precompiles#179
Merged
Merged
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
adr1anh
previously approved these changes
Sep 30, 2024
Contributor
adr1anh
left a comment
There was a problem hiding this comment.
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 |
Contributor
There was a problem hiding this comment.
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( |
Contributor
There was a problem hiding this comment.
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( |
Contributor
There was a problem hiding this comment.
We could also use an Add4 gadget
Not very useful considering it will almost always overflow. Can be added back if necessary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 counterpartsFixedRotateRight64OperationandFixedShiftRight64Operation: 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.