This repository was archived by the owner on Apr 18, 2025. It is now read-only.
forked from privacy-ethereum/zkevm-circuits
-
Notifications
You must be signed in to change notification settings - Fork 386
[FEAT] precompile-sha256 #1032
Merged
Merged
[FEAT] precompile-sha256 #1032
Changes from 39 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
7320dc5
init table16 with generic refactoring
noel2004 944cf7c
update cargo
noel2004 215a1a2
add required cfgs
noel2004 55eec01
add benchmarking
noel2004 c1ea6b8
customable bench
noel2004 ab5b2fa
fmt
noel2004 fe5a433
config gates for sha256 circuit
noel2004 d0b63a6
Merge remote-tracking branch 'origin/develop' into feat/sha256
noel2004 70ceb47
complete sha256 circuit
noel2004 4795760
induce SHA256 in bus mapping
noel2004 152c567
better challenge spec
noel2004 b8379ea
integrate sha256 circuit into super
noel2004 bef157b
readme (wip)
noel2004 4adf228
complete precompile and sha256 table
noel2004 89505b0
clippies
noel2004 85732d2
fmt
noel2004 8d90619
better tests
noel2004 a51e117
fix issues and better printing for circuit layout
noel2004 1c14779
refine and fix issues
noel2004 8b125f1
fix digest in table16
noel2004 edef428
fix layout, clippy and fmt
noel2004 635beae
complete sha256 table
noel2004 c8a3f6d
fix rw
noel2004 08d3039
fix rlc on padding
noel2004 4af8e0e
Merge remote-tracking branch 'origin/develop' into feat/sha256
noel2004 5db7d69
clippy and fmt
noel2004 2b43069
more tests
noel2004 7992f8d
test added
noel2004 f11f6cc
sha256: update row cost per block
noel2004 ac0d3fb
update readme (wip)
noel2004 c4b1898
lookup input len
noel2004 41298f7
enable sha256
noel2004 f7740de
Merge remote-tracking branch 'origin/develop' into feat/sha256
noel2004 da3027c
more tests cases
noel2004 8fb408e
refactoring aux data
noel2004 abeb61a
fmt
noel2004 e8e2c71
fix precompile call test
noel2004 e600ff5
fix another callop test
noel2004 a748453
Merge remote-tracking branch 'origin/develop' into feat/sha256
noel2004 fc94e67
+ update bench to circuit-sha256,
noel2004 f3f497d
Merge remote-tracking branch 'origin/develop' into feat/sha256
noel2004 0a4c056
fix vk issue, add more test
noel2004 e3d1333
trivial fixs
noel2004 9649214
Merge remote-tracking branch 'origin/develop' into feat/sha256
noel2004 ff0bf52
Merge remote-tracking branch 'origin/develop' into feat/sha256
noel2004 88e419c
move sha256 circuit into zkevm-circuits
noel2004 2d9914e
purge unused sha256 dir
noel2004 5af254a
Merge remote-tracking branch 'origin/develop' into feat/sha256
noel2004 c526f09
bump halo2 version
noel2004 05d3747
fix blank comment
noel2004 9d5661c
Merge remote-tracking branch 'origin/develop' into feat/sha256
noel2004 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| [package] | ||
| name = "sha256" | ||
| version.workspace = true | ||
| edition.workspace = true | ||
| license.workspace = true | ||
|
|
||
| [features] | ||
| dev-graph = ["halo2_proofs/dev-graph", "halo2_gadgets/dev-graph", "plotters"] | ||
|
|
||
| [dependencies] | ||
| halo2curves = { git = "https://github.com/scroll-tech/halo2curves.git", branch = "0.3.1-derive-serde" } | ||
| halo2_gadgets = { git = "https://github.com/scroll-tech/halo2.git", branch = "develop", features = ["unstable"] } | ||
| halo2_proofs.workspace = true | ||
| itertools.workspace = true | ||
| num-bigint.workspace = true | ||
| num-traits.workspace = true | ||
| plotters = { version = "0.3.0", optional = true } | ||
| eth-types = { path = "../eth-types" } | ||
| lazy_static.workspace = true | ||
| log.workspace = true | ||
| env_logger.workspace = true | ||
|
|
||
| [dev-dependencies] | ||
| pretty_assertions.workspace = true | ||
| rand.workspace = true | ||
| criterion = "0.3" | ||
|
|
||
| [[bench]] | ||
| name = "sha256" | ||
| harness = false |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # SHA256 Circuit with lookup table | ||
|
|
||
| This circuit use a forking of `table16` in `halo2-gadget`, with some patches: | ||
|
|
||
| + Make all code generic for `Field` trait so it also work with `bn254` curve | ||
| + Fix the digest exporting part, output correct digest (the final state ⊕ init state) with correct constraint (rows for 512-bit block increased from **2102** -> **2114**) | ||
|
|
||
| The witness in table16 is then exported to an extra region so the rlc of input and digest can be calculated and form the lookup table for SHA256 precompile in zkevm-circuit. To achieve this, we have induced several cols and assigned them with two region: `input` and `digest`. As following table shows: | ||
|
|
||
|
|
||
| input region: | ||
|
|
||
| | | inherit_s_finaal | |inherit_counter|iitnher_rlc| | | |inherit_padding |padding_size| | ||
| |----------|------------------|-----------|-----------|-----------|------------|-------------|---------|-----------------|------------| | ||
| |s_begin | s_final (0 or 1) | |0/inherit_cnt|0/inherit_rlc| | | s_output|0/inherit_padding| | | ||
| |s_enable | s_final (cont.) | s_u16 (1) | counter | bytes_rlc | trans_byte | copied_data | 0 |padding | | | ||
| |s_enable | s_final (cont.) | s_u16 (0) | | bytes_rlc | trans_byte | | 0 |padding | | | ||
| |.... | | ||
| |s_last | s_final (cont.) | s_u16 (0) | counter | bytes_rlc | | | |padding |bit_size | | ||
|
|
||
|
|
||
| digest region: | ||
|
|
||
| | | input s_final | bytes | 0 | | | | s_output| 1 | | ||
| |----------|------------------|-----------|-----------|-----------|------------|-------------|---------|-----------| | ||
| |s_enable | s_final (cont.) | s_u16 (1) | counter | bytes_rlc | trans_byte | copied_data | init_iv |padding (fixed 1)| | ||
| |s_enable | s_final (cont.) | s_u16 (0) | | bytes_rlc | trans_byte | export_state| 0 | | ||
| |.... | | ||
| | | s_final (cont.) | s_u16 (0) | | hash_rlc | | inher_input_rlc| 1 ... | | ||
|
|
||
|
|
||
|
|
||
| Each input region catch a 512-bit block, in the form of 16x 32bit integers assigned in cells inside the `message schedule` region of table16. The cells in last row (enabled by `s_last` selector) would be connected by equality constraint to the first row of next input region for the next 512-bit block. cells in the `s_final` col is identify to be 0 or 1 in the same input region. | ||
|
|
||
| The last row of `input region` is constrainted equal to the first row in digest region |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| sha256_assets |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.