Skip to content
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 sha2 primitive #689

Merged
merged 13 commits into from Jun 5, 2023
Merged

feat: add sha2 primitive #689

merged 13 commits into from Jun 5, 2023

Conversation

ivokub
Copy link
Collaborator

@ivokub ivokub commented May 15, 2023

This PR adds sha2-256 into gnark. In order to do this, we added:

  • primitive for automatically constructing lookup tables for functions (logderivprecomp). This primitive first constructs the whole table for all 8-bit inputs and then replaces all function computations by table lookup.
  • bitslice package - for splitting native variables at variable locations. I want to extend this package for partitioning the inputs into bit groups.
  • added BinaryHasher interfaces which is better for byte array inputs (and renamed current Hash to FieldHasher to indicate that it works for native field elements)
  • implemented sha2 permutation function using precomputed lookups
  • implemented sha2 hash function using sha2 permutation.
  • refactored keccakf permutation to use precomputed lookups.

This PR touches a lot of areas. If it seems it is better to split then I can.

NB! I wouldn't say everything is polished yet, but want to get out of the way so that could start receiving feedback and starting to integrate.

@ivokub ivokub added new feature zk-evm P1: High Issue priority: high labels May 15, 2023
@ivokub ivokub self-assigned this May 15, 2023
@ivokub
Copy link
Collaborator Author

ivokub commented May 25, 2023

Performance:

blocks 1  bytes 55   constraints R1CS 152256 SCS 592937
blocks 2  bytes 119  constraints R1CS 172083 SCS 660254
blocks 3  bytes 183  constraints R1CS 191911 SCS 727571
blocks 4  bytes 247  constraints R1CS 211738 SCS 794887
blocks 5  bytes 311  constraints R1CS 231566 SCS 862204
blocks 6  bytes 375  constraints R1CS 251393 SCS 929520
blocks 7  bytes 439  constraints R1CS 271220 SCS 996836
blocks 8  bytes 503  constraints R1CS 291049 SCS 1064152
blocks 9  bytes 567  constraints R1CS 310876 SCS 1131468
blocks 10 bytes 631  constraints R1CS 330703 SCS 1198784
blocks 11 bytes 695  constraints R1CS 350531 SCS 1266100
blocks 12 bytes 759  constraints R1CS 370359 SCS 1333416
blocks 13 bytes 823  constraints R1CS 390186 SCS 1400732
blocks 14 bytes 887  constraints R1CS 410013 SCS 1468048
blocks 15 bytes 951  constraints R1CS 429842 SCS 1535364
blocks 16 bytes 1015 constraints R1CS 449668 SCS 1602680
blocks 17 bytes 1079 constraints R1CS 469496 SCS 1669996
blocks 18 bytes 1143 constraints R1CS 489324 SCS 1737312
blocks 19 bytes 1207 constraints R1CS 509151 SCS 1804628
blocks 20 bytes 1271 constraints R1CS 528979 SCS 1871944

@ivokub
Copy link
Collaborator Author

ivokub commented Jun 5, 2023

@ThomasPiellard - can you have a look? Is it better if I split the PR up into smaller PRs? I guess it may introduce many changes.

@ivokub ivokub merged commit 6ec0af7 into develop Jun 5, 2023
5 checks passed
@ivokub ivokub deleted the feat/sha2b branch June 5, 2023 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants